2002-01-30 07:46:54 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2006-08-01 03:05:37 +04:00
|
|
|
/* vim: set ts=2 sw=2 et tw=78: */
|
2012-05-21 15:12:37 +04:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2002-01-30 07:46:54 +03:00
|
|
|
|
2013-04-03 04:13:10 +04:00
|
|
|
#include <string.h> // for nullptr, strcmp
|
2002-01-30 07:46:54 +03:00
|
|
|
|
2012-07-13 10:33:42 +04:00
|
|
|
#include "imgIContainer.h" // for imgIContainer, etc
|
2018-01-26 08:06:29 +03:00
|
|
|
#include "mozilla/ComposerCommandsUpdater.h" // for ComposerCommandsUpdater
|
2017-01-05 10:31:56 +03:00
|
|
|
#include "mozilla/FlushType.h" // for FlushType::Frames
|
2017-08-04 16:53:28 +03:00
|
|
|
#include "mozilla/HTMLEditor.h" // for HTMLEditor
|
2012-07-13 10:33:42 +04:00
|
|
|
#include "mozilla/mozalloc.h" // for operator new
|
|
|
|
#include "nsAString.h"
|
|
|
|
#include "nsComponentManagerUtils.h" // for do_CreateInstance
|
2017-04-25 13:22:25 +03:00
|
|
|
#include "nsContentUtils.h"
|
2012-07-13 10:33:42 +04:00
|
|
|
#include "nsDebug.h" // for NS_ENSURE_SUCCESS, etc
|
2002-01-30 07:46:54 +03:00
|
|
|
#include "nsEditingSession.h"
|
2012-07-13 10:33:42 +04:00
|
|
|
#include "nsError.h" // for NS_ERROR_FAILURE, NS_OK, etc
|
|
|
|
#include "nsIChannel.h" // for nsIChannel
|
|
|
|
#include "nsICommandManager.h" // for nsICommandManager
|
|
|
|
#include "nsIContentViewer.h" // for nsIContentViewer
|
|
|
|
#include "nsIController.h" // for nsIController
|
|
|
|
#include "nsIControllerContext.h" // for nsIControllerContext
|
|
|
|
#include "nsIControllers.h" // for nsIControllers
|
|
|
|
#include "nsID.h" // for NS_GET_IID, etc
|
2018-01-26 09:00:49 +03:00
|
|
|
#include "nsHTMLDocument.h" // for nsHTMLDocument
|
2012-07-13 10:33:42 +04:00
|
|
|
#include "nsIDOMWindow.h" // for nsIDOMWindow
|
|
|
|
#include "nsIDocShell.h" // for nsIDocShell
|
2019-01-02 16:05:23 +03:00
|
|
|
#include "mozilla/dom/Document.h" // for Document
|
2012-07-13 10:33:42 +04:00
|
|
|
#include "nsIDocumentStateListener.h"
|
|
|
|
#include "nsIEditor.h" // for nsIEditor
|
|
|
|
#include "nsIHTMLDocument.h" // for nsIHTMLDocument, etc
|
|
|
|
#include "nsIInterfaceRequestorUtils.h" // for do_GetInterface
|
|
|
|
#include "nsIPlaintextEditor.h" // for nsIPlaintextEditor, etc
|
2014-09-26 17:19:56 +04:00
|
|
|
#include "nsIPresShell.h" // for nsIPresShell
|
2012-07-13 10:33:42 +04:00
|
|
|
#include "nsIRefreshURI.h" // for nsIRefreshURI
|
|
|
|
#include "nsIRequest.h" // for nsIRequest
|
|
|
|
#include "nsITimer.h" // for nsITimer, etc
|
|
|
|
#include "nsITransactionManager.h" // for nsITransactionManager
|
|
|
|
#include "nsIWeakReference.h" // for nsISupportsWeakReference, etc
|
|
|
|
#include "nsIWebNavigation.h" // for nsIWebNavigation
|
|
|
|
#include "nsIWebProgress.h" // for nsIWebProgress, etc
|
|
|
|
#include "nsLiteralString.h" // for NS_LITERAL_STRING
|
|
|
|
#include "nsPICommandUpdater.h" // for nsPICommandUpdater
|
|
|
|
#include "nsPIDOMWindow.h" // for nsPIDOMWindow
|
2014-09-26 17:19:56 +04:00
|
|
|
#include "nsPresContext.h" // for nsPresContext
|
2012-07-13 10:33:42 +04:00
|
|
|
#include "nsReadableUtils.h" // for AppendUTF16toUTF8
|
2017-06-20 12:19:05 +03:00
|
|
|
#include "nsStringFwd.h" // for nsString
|
2017-08-04 16:53:28 +03:00
|
|
|
#include "mozilla/dom/Selection.h" // for AutoHideSelectionChanges, etc
|
2016-10-13 17:18:31 +03:00
|
|
|
#include "nsFrameSelection.h" // for nsFrameSelection
|
2018-09-07 16:39:36 +03:00
|
|
|
#include "nsBaseCommandController.h" // for nsBaseCommandController
|
2019-01-11 14:43:39 +03:00
|
|
|
#include "mozilla/dom/LoadURIOptionsBinding.h"
|
2002-01-30 07:46:54 +03:00
|
|
|
|
2012-07-13 10:33:42 +04:00
|
|
|
class nsISupports;
|
|
|
|
class nsIURI;
|
2002-01-30 07:46:54 +03:00
|
|
|
|
2017-08-04 16:53:28 +03:00
|
|
|
using namespace mozilla;
|
|
|
|
using namespace mozilla::dom;
|
|
|
|
|
2002-01-30 07:46:54 +03:00
|
|
|
/*---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
nsEditingSession
|
|
|
|
|
|
|
|
----------------------------------------------------------------------------*/
|
|
|
|
nsEditingSession::nsEditingSession()
|
2011-10-17 18:59:28 +04:00
|
|
|
: mDoneSetup(false),
|
|
|
|
mCanCreateEditor(false),
|
|
|
|
mInteractive(false),
|
|
|
|
mMakeWholeDocumentEditable(true),
|
|
|
|
mDisabledJSAndPlugins(false),
|
|
|
|
mScriptsEnabled(true),
|
|
|
|
mPluginsEnabled(true),
|
|
|
|
mProgressListenerRegistered(false),
|
2005-02-24 00:27:20 +03:00
|
|
|
mImageAnimationMode(0),
|
2002-11-13 02:03:27 +03:00
|
|
|
mEditorFlags(0),
|
|
|
|
mEditorStatus(eEditorOK),
|
|
|
|
mBaseCommandControllerId(0),
|
|
|
|
mDocStateControllerId(0),
|
|
|
|
mHTMLCommandControllerId(0) {}
|
2002-01-30 07:46:54 +03:00
|
|
|
|
|
|
|
/*---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
~nsEditingSession
|
|
|
|
|
|
|
|
----------------------------------------------------------------------------*/
|
|
|
|
nsEditingSession::~nsEditingSession() {
|
2003-02-14 17:56:32 +03:00
|
|
|
// Must cancel previous timer?
|
|
|
|
if (mLoadBlankDocTimer) mLoadBlankDocTimer->Cancel();
|
2002-01-30 07:46:54 +03:00
|
|
|
}
|
|
|
|
|
2015-05-28 18:58:42 +03:00
|
|
|
NS_IMPL_ISUPPORTS(nsEditingSession, nsIEditingSession, nsIWebProgressListener,
|
2014-04-27 11:06:00 +04:00
|
|
|
nsISupportsWeakReference)
|
2002-01-30 07:46:54 +03:00
|
|
|
|
|
|
|
/*---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
MakeWindowEditable
|
|
|
|
|
2002-10-09 06:10:22 +04:00
|
|
|
aEditorType string, "html" "htmlsimple" "text" "textsimple"
|
2015-05-28 18:58:42 +03:00
|
|
|
void makeWindowEditable(in nsIDOMWindow aWindow, in string aEditorType,
|
2007-06-28 06:48:16 +04:00
|
|
|
in boolean aDoAfterUriLoad,
|
|
|
|
in boolean aMakeWholeDocumentEditable,
|
|
|
|
in boolean aInteractive);
|
2002-01-30 07:46:54 +03:00
|
|
|
----------------------------------------------------------------------------*/
|
2002-11-13 02:03:27 +03:00
|
|
|
#define DEFAULT_EDITOR_TYPE "html"
|
|
|
|
|
2002-01-30 07:46:54 +03:00
|
|
|
NS_IMETHODIMP
|
2016-01-30 20:05:36 +03:00
|
|
|
nsEditingSession::MakeWindowEditable(mozIDOMWindowProxy* aWindow,
|
2015-05-28 18:58:42 +03:00
|
|
|
const char* aEditorType,
|
2011-09-29 10:19:26 +04:00
|
|
|
bool aDoAfterUriLoad,
|
|
|
|
bool aMakeWholeDocumentEditable,
|
|
|
|
bool aInteractive) {
|
2002-11-13 02:03:27 +03:00
|
|
|
mEditorType.Truncate();
|
2002-10-09 06:10:22 +04:00
|
|
|
mEditorFlags = 0;
|
|
|
|
|
2016-01-30 20:05:36 +03:00
|
|
|
NS_ENSURE_TRUE(aWindow, NS_ERROR_FAILURE);
|
|
|
|
auto* window = nsPIDOMWindowOuter::From(aWindow);
|
|
|
|
|
2003-01-10 16:13:25 +03:00
|
|
|
// disable plugins
|
2016-01-30 20:05:36 +03:00
|
|
|
nsCOMPtr<nsIDocShell> docShell = window->GetDocShell();
|
2010-06-17 23:41:16 +04:00
|
|
|
NS_ENSURE_TRUE(docShell, NS_ERROR_FAILURE);
|
2003-01-10 16:13:25 +03:00
|
|
|
|
2010-10-15 21:59:00 +04:00
|
|
|
mDocShell = do_GetWeakReference(docShell);
|
2007-06-28 06:48:16 +04:00
|
|
|
mInteractive = aInteractive;
|
2007-07-06 14:45:16 +04:00
|
|
|
mMakeWholeDocumentEditable = aMakeWholeDocumentEditable;
|
2007-06-28 02:29:45 +04:00
|
|
|
|
2007-07-06 14:45:16 +04:00
|
|
|
nsresult rv;
|
2007-06-28 06:48:16 +04:00
|
|
|
if (!mInteractive) {
|
2007-11-12 17:47:03 +03:00
|
|
|
rv = DisableJSAndPlugins(aWindow);
|
2007-06-28 06:48:16 +04:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
}
|
2003-01-10 16:13:25 +03:00
|
|
|
|
2002-11-20 09:23:05 +03:00
|
|
|
// Always remove existing editor
|
2007-11-12 17:47:03 +03:00
|
|
|
TearDownEditorOnWindow(aWindow);
|
2015-05-28 18:58:42 +03:00
|
|
|
|
2002-11-13 02:03:27 +03:00
|
|
|
// Tells embedder that startup is in progress
|
|
|
|
mEditorStatus = eEditorCreationInProgress;
|
|
|
|
|
2002-10-09 06:10:22 +04:00
|
|
|
// temporary to set editor type here. we will need different classes soon.
|
2002-11-13 02:03:27 +03:00
|
|
|
if (!aEditorType) aEditorType = DEFAULT_EDITOR_TYPE;
|
|
|
|
mEditorType = aEditorType;
|
2002-10-09 06:10:22 +04:00
|
|
|
|
2015-05-28 18:58:42 +03:00
|
|
|
// if all this does is setup listeners and I don't need listeners,
|
2003-02-27 17:06:29 +03:00
|
|
|
// can't this step be ignored?? (based on aDoAfterURILoad)
|
2016-01-30 20:05:36 +03:00
|
|
|
rv = PrepareForEditing(window);
|
2015-05-28 18:58:42 +03:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2002-01-30 07:46:54 +03:00
|
|
|
// set the flag on the docShell to say that it's editable
|
2013-02-14 02:39:30 +04:00
|
|
|
rv = docShell->MakeEditable(aDoAfterUriLoad);
|
2015-05-28 18:58:42 +03:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2005-02-25 21:16:20 +03:00
|
|
|
|
2002-11-13 02:03:27 +03:00
|
|
|
// Setup commands common to plaintext and html editors,
|
|
|
|
// including the document creation observers
|
2011-12-24 04:11:30 +04:00
|
|
|
// the first is an editing controller
|
2018-09-07 16:39:36 +03:00
|
|
|
rv = SetupEditorCommandController(
|
|
|
|
nsBaseCommandController::CreateEditingController, aWindow,
|
2007-07-08 11:08:04 +04:00
|
|
|
static_cast<nsIEditingSession*>(this), &mBaseCommandControllerId);
|
2010-06-17 23:27:24 +04:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2002-01-30 07:46:54 +03:00
|
|
|
|
2002-11-20 09:23:05 +03:00
|
|
|
// The second is a controller to monitor doc state,
|
2002-11-13 02:03:27 +03:00
|
|
|
// such as creation and "dirty flag"
|
2018-09-08 19:06:48 +03:00
|
|
|
rv = SetupEditorCommandController(
|
|
|
|
nsBaseCommandController::CreateHTMLEditorDocStateController, aWindow,
|
2007-07-08 11:08:04 +04:00
|
|
|
static_cast<nsIEditingSession*>(this), &mDocStateControllerId);
|
2010-06-17 23:27:24 +04:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2002-11-13 02:03:27 +03:00
|
|
|
|
|
|
|
// aDoAfterUriLoad can be false only when making an existing window editable
|
2016-10-24 05:27:45 +03:00
|
|
|
if (!aDoAfterUriLoad) {
|
2002-01-30 07:46:54 +03:00
|
|
|
rv = SetupEditorOnWindow(aWindow);
|
2002-11-13 02:03:27 +03:00
|
|
|
|
|
|
|
// mEditorStatus is set to the error reason
|
|
|
|
// Since this is used only when editing an existing page,
|
|
|
|
// it IS ok to destroy current editor
|
2016-10-24 05:27:45 +03:00
|
|
|
if (NS_FAILED(rv)) {
|
2007-11-12 17:47:03 +03:00
|
|
|
TearDownEditorOnWindow(aWindow);
|
2016-10-24 05:27:45 +03:00
|
|
|
}
|
2002-01-30 07:46:54 +03:00
|
|
|
}
|
2002-11-13 02:03:27 +03:00
|
|
|
return rv;
|
2002-01-30 07:46:54 +03:00
|
|
|
}
|
|
|
|
|
2007-11-12 17:47:03 +03:00
|
|
|
NS_IMETHODIMP
|
2016-01-30 20:05:36 +03:00
|
|
|
nsEditingSession::DisableJSAndPlugins(mozIDOMWindowProxy* aWindow) {
|
|
|
|
NS_ENSURE_TRUE(aWindow, NS_ERROR_FAILURE);
|
|
|
|
nsIDocShell* docShell = nsPIDOMWindowOuter::From(aWindow)->GetDocShell();
|
2010-06-17 23:41:16 +04:00
|
|
|
NS_ENSURE_TRUE(docShell, NS_ERROR_FAILURE);
|
2007-11-12 17:47:03 +03:00
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool tmp;
|
2007-11-12 17:47:03 +03:00
|
|
|
nsresult rv = docShell->GetAllowJavascript(&tmp);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
mScriptsEnabled = tmp;
|
|
|
|
|
2011-10-17 18:59:28 +04:00
|
|
|
rv = docShell->SetAllowJavascript(false);
|
2007-11-12 17:47:03 +03:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
// Disable plugins in this document:
|
2012-08-20 22:34:32 +04:00
|
|
|
mPluginsEnabled = docShell->PluginsAllowedInCurrentDoc();
|
2007-11-12 17:47:03 +03:00
|
|
|
|
2011-10-17 18:59:28 +04:00
|
|
|
rv = docShell->SetAllowPlugins(false);
|
2007-11-12 17:47:03 +03:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2011-10-17 18:59:28 +04:00
|
|
|
mDisabledJSAndPlugins = true;
|
2007-11-12 17:47:03 +03:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2016-01-30 20:05:36 +03:00
|
|
|
nsEditingSession::RestoreJSAndPlugins(mozIDOMWindowProxy* aWindow) {
|
2015-07-16 00:48:09 +03:00
|
|
|
if (!mDisabledJSAndPlugins) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2008-04-24 01:36:17 +04:00
|
|
|
|
2011-10-17 18:59:28 +04:00
|
|
|
mDisabledJSAndPlugins = false;
|
2007-11-12 17:47:03 +03:00
|
|
|
|
2016-01-30 20:05:36 +03:00
|
|
|
NS_ENSURE_TRUE(aWindow, NS_ERROR_FAILURE);
|
|
|
|
nsIDocShell* docShell = nsPIDOMWindowOuter::From(aWindow)->GetDocShell();
|
2010-06-17 23:41:16 +04:00
|
|
|
NS_ENSURE_TRUE(docShell, NS_ERROR_FAILURE);
|
2007-11-12 17:47:03 +03:00
|
|
|
|
|
|
|
nsresult rv = docShell->SetAllowJavascript(mScriptsEnabled);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
// Disable plugins in this document:
|
|
|
|
return docShell->SetAllowPlugins(mPluginsEnabled);
|
|
|
|
}
|
|
|
|
|
2010-06-05 01:03:50 +04:00
|
|
|
NS_IMETHODIMP
|
2011-09-29 10:19:26 +04:00
|
|
|
nsEditingSession::GetJsAndPluginsDisabled(bool* aResult) {
|
2010-06-05 01:03:50 +04:00
|
|
|
NS_ENSURE_ARG_POINTER(aResult);
|
|
|
|
*aResult = mDisabledJSAndPlugins;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2002-01-30 07:46:54 +03:00
|
|
|
/*---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
WindowIsEditable
|
|
|
|
|
|
|
|
boolean windowIsEditable (in nsIDOMWindow aWindow);
|
|
|
|
----------------------------------------------------------------------------*/
|
2002-11-13 02:03:27 +03:00
|
|
|
NS_IMETHODIMP
|
2016-01-30 20:05:36 +03:00
|
|
|
nsEditingSession::WindowIsEditable(mozIDOMWindowProxy* aWindow,
|
|
|
|
bool* outIsEditable) {
|
|
|
|
NS_ENSURE_STATE(aWindow);
|
|
|
|
nsCOMPtr<nsIDocShell> docShell =
|
|
|
|
nsPIDOMWindowOuter::From(aWindow)->GetDocShell();
|
2013-02-14 02:39:30 +04:00
|
|
|
NS_ENSURE_STATE(docShell);
|
2002-01-30 07:46:54 +03:00
|
|
|
|
2013-02-14 02:39:30 +04:00
|
|
|
return docShell->GetEditable(outIsEditable);
|
2002-01-30 07:46:54 +03:00
|
|
|
}
|
|
|
|
|
2002-11-13 02:03:27 +03:00
|
|
|
// These are MIME types that are automatically parsed as "text/plain"
|
|
|
|
// and thus we can edit them as plaintext
|
|
|
|
// Note: in older versions, we attempted to convert the mimetype of
|
2015-05-28 18:58:42 +03:00
|
|
|
// the network channel for these and "text/xml" to "text/plain",
|
2002-11-13 02:03:27 +03:00
|
|
|
// but further investigation reveals that strategy doesn't work
|
|
|
|
const char* const gSupportedTextTypes[] = {
|
|
|
|
"text/plain",
|
|
|
|
"text/css",
|
|
|
|
"text/rdf",
|
|
|
|
"text/xsl",
|
2005-06-22 04:50:32 +04:00
|
|
|
"text/javascript", // obsolete type
|
|
|
|
"text/ecmascript", // obsolete type
|
|
|
|
"application/javascript",
|
|
|
|
"application/ecmascript",
|
|
|
|
"application/x-javascript", // obsolete type
|
|
|
|
"text/xul", // obsolete type
|
2002-11-13 02:03:27 +03:00
|
|
|
"application/vnd.mozilla.xul+xml",
|
2013-04-03 04:13:10 +04:00
|
|
|
nullptr // IMPORTANT! Null must be at end
|
2002-11-13 02:03:27 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
bool IsSupportedTextType(const char* aMIMEType) {
|
2011-10-17 18:59:28 +04:00
|
|
|
NS_ENSURE_TRUE(aMIMEType, false);
|
2002-11-13 02:03:27 +03:00
|
|
|
|
2016-10-24 05:27:45 +03:00
|
|
|
for (size_t i = 0; gSupportedTextTypes[i]; ++i) {
|
|
|
|
if (!strcmp(gSupportedTextTypes[i], aMIMEType)) {
|
2011-10-17 18:59:28 +04:00
|
|
|
return true;
|
2002-11-13 02:03:27 +03:00
|
|
|
}
|
|
|
|
}
|
2015-05-28 18:58:42 +03:00
|
|
|
|
2011-10-17 18:59:28 +04:00
|
|
|
return false;
|
2002-11-13 02:03:27 +03:00
|
|
|
}
|
|
|
|
|
2002-01-30 07:46:54 +03:00
|
|
|
/*---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
SetupEditorOnWindow
|
|
|
|
|
|
|
|
nsIEditor setupEditorOnWindow (in nsIDOMWindow aWindow);
|
|
|
|
----------------------------------------------------------------------------*/
|
|
|
|
NS_IMETHODIMP
|
2016-01-30 20:05:36 +03:00
|
|
|
nsEditingSession::SetupEditorOnWindow(mozIDOMWindowProxy* aWindow) {
|
2011-10-17 18:59:28 +04:00
|
|
|
mDoneSetup = true;
|
2007-02-13 12:26:09 +03:00
|
|
|
|
2016-01-30 20:05:36 +03:00
|
|
|
NS_ENSURE_TRUE(aWindow, NS_ERROR_FAILURE);
|
|
|
|
auto* window = nsPIDOMWindowOuter::From(aWindow);
|
|
|
|
|
2002-11-13 02:03:27 +03:00
|
|
|
nsresult rv;
|
|
|
|
|
|
|
|
// MIME CHECKING
|
|
|
|
// must get the content type
|
|
|
|
// Note: the doc gets this from the network channel during StartPageLoad,
|
|
|
|
// so we don't have to get it from there ourselves
|
2012-09-02 06:35:17 +04:00
|
|
|
nsAutoCString mimeCType;
|
2002-11-13 02:03:27 +03:00
|
|
|
|
|
|
|
// then lets check the mime type
|
2019-01-02 16:05:23 +03:00
|
|
|
if (RefPtr<Document> doc = window->GetDoc()) {
|
2011-05-28 11:43:53 +04:00
|
|
|
nsAutoString mimeType;
|
2018-01-31 23:18:11 +03:00
|
|
|
doc->GetContentType(mimeType);
|
|
|
|
AppendUTF16toUTF8(mimeType, mimeCType);
|
2011-05-28 11:43:53 +04:00
|
|
|
|
2016-10-24 05:27:45 +03:00
|
|
|
if (IsSupportedTextType(mimeCType.get())) {
|
2011-05-28 11:43:53 +04:00
|
|
|
mEditorType.AssignLiteral("text");
|
|
|
|
mimeCType = "text/plain";
|
2016-10-24 05:27:45 +03:00
|
|
|
} else if (!mimeCType.EqualsLiteral("text/html") &&
|
|
|
|
!mimeCType.EqualsLiteral("application/xhtml+xml")) {
|
2011-05-28 11:43:53 +04:00
|
|
|
// Neither an acceptable text or html type.
|
|
|
|
mEditorStatus = eEditorErrorCantEditMimeType;
|
|
|
|
|
|
|
|
// Turn editor into HTML -- we will load blank page later
|
|
|
|
mEditorType.AssignLiteral("html");
|
|
|
|
mimeCType.AssignLiteral("text/html");
|
2002-11-13 02:03:27 +03:00
|
|
|
}
|
2006-08-16 06:41:47 +04:00
|
|
|
|
|
|
|
// Flush out frame construction to make sure that the subframe's
|
|
|
|
// presshell is set up if it needs to be.
|
2018-08-13 12:05:19 +03:00
|
|
|
doc->FlushPendingNotifications(mozilla::FlushType::Frames);
|
|
|
|
if (mMakeWholeDocumentEditable) {
|
|
|
|
doc->SetEditableFlag(true);
|
|
|
|
nsCOMPtr<nsIHTMLDocument> htmlDocument = do_QueryInterface(doc);
|
|
|
|
if (htmlDocument) {
|
|
|
|
// Enable usage of the execCommand API
|
|
|
|
htmlDocument->SetEditingState(nsIHTMLDocument::eDesignMode);
|
2007-07-06 14:45:16 +04:00
|
|
|
}
|
2006-08-16 06:41:47 +04:00
|
|
|
}
|
2002-11-13 02:03:27 +03:00
|
|
|
}
|
2011-09-29 10:19:26 +04:00
|
|
|
bool needHTMLController = false;
|
2002-11-13 02:03:27 +03:00
|
|
|
|
2016-10-24 05:27:45 +03:00
|
|
|
if (mEditorType.EqualsLiteral("textmail")) {
|
2015-05-28 18:58:42 +03:00
|
|
|
mEditorFlags = nsIPlaintextEditor::eEditorPlaintextMask |
|
|
|
|
nsIPlaintextEditor::eEditorEnableWrapHackMask |
|
2002-11-13 02:03:27 +03:00
|
|
|
nsIPlaintextEditor::eEditorMailMask;
|
2016-10-24 05:27:45 +03:00
|
|
|
} else if (mEditorType.EqualsLiteral("text")) {
|
2015-05-28 18:58:42 +03:00
|
|
|
mEditorFlags = nsIPlaintextEditor::eEditorPlaintextMask |
|
2002-11-13 02:03:27 +03:00
|
|
|
nsIPlaintextEditor::eEditorEnableWrapHackMask;
|
2016-10-24 05:27:45 +03:00
|
|
|
} else if (mEditorType.EqualsLiteral("htmlmail")) {
|
|
|
|
if (mimeCType.EqualsLiteral("text/html")) {
|
2011-10-17 18:59:28 +04:00
|
|
|
needHTMLController = true;
|
2002-11-13 02:03:27 +03:00
|
|
|
mEditorFlags = nsIPlaintextEditor::eEditorMailMask;
|
2016-10-24 05:27:45 +03:00
|
|
|
} else {
|
|
|
|
// Set the flags back to textplain.
|
2015-05-28 18:58:42 +03:00
|
|
|
mEditorFlags = nsIPlaintextEditor::eEditorPlaintextMask |
|
2002-11-13 02:03:27 +03:00
|
|
|
nsIPlaintextEditor::eEditorEnableWrapHackMask;
|
2016-10-24 05:27:45 +03:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// Defaulted to html
|
2011-10-17 18:59:28 +04:00
|
|
|
needHTMLController = true;
|
2002-11-13 02:03:27 +03:00
|
|
|
}
|
|
|
|
|
2007-06-28 06:48:16 +04:00
|
|
|
if (mInteractive) {
|
|
|
|
mEditorFlags |= nsIPlaintextEditor::eEditorAllowInteraction;
|
|
|
|
}
|
|
|
|
|
2002-11-13 02:03:27 +03:00
|
|
|
// make the UI state maintainer
|
2018-01-26 08:38:05 +03:00
|
|
|
mComposerCommandsUpdater = new ComposerCommandsUpdater();
|
2002-11-13 02:03:27 +03:00
|
|
|
|
|
|
|
// now init the state maintainer
|
|
|
|
// This allows notification of error state
|
|
|
|
// even if we don't create an editor
|
2018-01-26 08:38:05 +03:00
|
|
|
rv = mComposerCommandsUpdater->Init(window);
|
2010-06-17 23:27:24 +04:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2002-01-30 07:46:54 +03:00
|
|
|
|
2016-10-24 05:27:45 +03:00
|
|
|
if (mEditorStatus != eEditorCreationInProgress) {
|
2018-01-26 08:38:05 +03:00
|
|
|
mComposerCommandsUpdater->NotifyDocumentCreated();
|
2002-11-13 02:03:27 +03:00
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
2015-05-28 18:58:42 +03:00
|
|
|
// Create editor and do other things
|
2002-11-13 02:03:27 +03:00
|
|
|
// only if we haven't found some error above,
|
2016-01-30 20:05:36 +03:00
|
|
|
nsCOMPtr<nsIDocShell> docShell = window->GetDocShell();
|
2015-05-28 18:58:42 +03:00
|
|
|
NS_ENSURE_TRUE(docShell, NS_ERROR_FAILURE);
|
2016-10-13 17:18:31 +03:00
|
|
|
nsCOMPtr<nsIPresShell> presShell = docShell->GetPresShell();
|
|
|
|
NS_ENSURE_TRUE(presShell, NS_ERROR_FAILURE);
|
2002-11-13 02:03:27 +03:00
|
|
|
|
2007-06-28 06:48:16 +04:00
|
|
|
if (!mInteractive) {
|
|
|
|
// Disable animation of images in this document:
|
2014-09-26 17:19:56 +04:00
|
|
|
nsPresContext* presContext = presShell->GetPresContext();
|
|
|
|
NS_ENSURE_TRUE(presContext, NS_ERROR_FAILURE);
|
2003-02-14 17:56:32 +03:00
|
|
|
|
2014-09-26 17:19:56 +04:00
|
|
|
mImageAnimationMode = presContext->ImageAnimationMode();
|
|
|
|
presContext->SetImageAnimationMode(imgIContainer::kDontAnimMode);
|
2007-06-28 06:48:16 +04:00
|
|
|
}
|
2003-02-14 17:56:32 +03:00
|
|
|
|
2016-10-13 17:18:31 +03:00
|
|
|
// Hide selection changes during initialization, in order to hide this
|
|
|
|
// from web pages.
|
|
|
|
RefPtr<nsFrameSelection> fs = presShell->FrameSelection();
|
|
|
|
NS_ENSURE_TRUE(fs, NS_ERROR_FAILURE);
|
2017-08-04 16:53:28 +03:00
|
|
|
AutoHideSelectionChanges hideSelectionChanges(fs);
|
2016-10-13 17:18:31 +03:00
|
|
|
|
2003-02-14 17:56:32 +03:00
|
|
|
// create and set editor
|
2010-11-19 00:01:12 +03:00
|
|
|
// Try to reuse an existing editor
|
|
|
|
nsCOMPtr<nsIEditor> editor = do_QueryReferent(mExistingEditor);
|
2017-08-04 16:53:28 +03:00
|
|
|
RefPtr<HTMLEditor> htmlEditor = editor ? editor->AsHTMLEditor() : nullptr;
|
|
|
|
MOZ_ASSERT(!editor || htmlEditor);
|
|
|
|
if (htmlEditor) {
|
|
|
|
htmlEditor->PreDestroy(false);
|
2011-03-01 00:04:05 +03:00
|
|
|
} else {
|
2017-08-04 16:53:28 +03:00
|
|
|
htmlEditor = new HTMLEditor();
|
|
|
|
mExistingEditor =
|
|
|
|
do_GetWeakReference(static_cast<nsIEditor*>(htmlEditor.get()));
|
2010-11-19 00:01:12 +03:00
|
|
|
}
|
2002-01-30 07:46:54 +03:00
|
|
|
// set the editor on the docShell. The docShell now owns it.
|
2017-08-04 16:53:28 +03:00
|
|
|
rv = docShell->SetHTMLEditor(htmlEditor);
|
2010-06-17 23:27:24 +04:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2002-11-13 02:03:27 +03:00
|
|
|
|
|
|
|
// setup the HTML editor command controller
|
2016-10-24 05:27:45 +03:00
|
|
|
if (needHTMLController) {
|
2003-04-10 22:44:03 +04:00
|
|
|
// The third controller takes an nsIEditor as the context
|
2018-09-08 08:35:56 +03:00
|
|
|
rv = SetupEditorCommandController(
|
|
|
|
nsBaseCommandController::CreateHTMLEditorController, aWindow,
|
2017-08-04 16:53:28 +03:00
|
|
|
static_cast<nsIEditor*>(htmlEditor), &mHTMLCommandControllerId);
|
2010-06-17 23:27:24 +04:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2002-11-13 02:03:27 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// Set mimetype on editor
|
2017-08-04 16:53:28 +03:00
|
|
|
rv = htmlEditor->SetContentsMIMEType(mimeCType.get());
|
2010-06-17 23:27:24 +04:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2002-11-13 02:03:27 +03:00
|
|
|
|
2002-01-30 07:46:54 +03:00
|
|
|
nsCOMPtr<nsIContentViewer> contentViewer;
|
|
|
|
rv = docShell->GetContentViewer(getter_AddRefs(contentViewer));
|
2010-06-17 23:27:24 +04:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2010-06-17 23:41:16 +04:00
|
|
|
NS_ENSURE_TRUE(contentViewer, NS_ERROR_FAILURE);
|
2002-11-13 02:03:27 +03:00
|
|
|
|
2019-01-02 16:05:23 +03:00
|
|
|
RefPtr<Document> doc = contentViewer->GetDocument();
|
2018-02-07 09:28:04 +03:00
|
|
|
if (NS_WARN_IF(!doc)) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
2002-01-30 07:46:54 +03:00
|
|
|
|
2002-11-13 02:03:27 +03:00
|
|
|
// Set up as a doc state listener
|
|
|
|
// Important! We must have this to broadcast the "obs_documentCreated" message
|
2018-01-26 08:38:05 +03:00
|
|
|
rv = htmlEditor->AddDocumentStateListener(mComposerCommandsUpdater);
|
2010-06-17 23:27:24 +04:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2002-01-30 07:46:54 +03:00
|
|
|
|
2018-02-07 09:28:04 +03:00
|
|
|
rv = htmlEditor->Init(*doc, nullptr /* root content */, nullptr, mEditorFlags,
|
2017-08-04 16:53:28 +03:00
|
|
|
EmptyString());
|
2010-06-17 23:27:24 +04:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2002-01-30 07:46:54 +03:00
|
|
|
|
2017-08-04 16:53:28 +03:00
|
|
|
RefPtr<Selection> selection = htmlEditor->GetSelection();
|
|
|
|
if (NS_WARN_IF(!selection)) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
2002-01-30 07:46:54 +03:00
|
|
|
|
2018-01-26 08:38:05 +03:00
|
|
|
htmlEditor->SetComposerCommandsUpdater(mComposerCommandsUpdater);
|
2002-01-30 07:46:54 +03:00
|
|
|
|
|
|
|
// and as a transaction listener
|
2018-03-23 12:55:56 +03:00
|
|
|
MOZ_ASSERT(mComposerCommandsUpdater);
|
|
|
|
DebugOnly<bool> addedTransactionListener =
|
|
|
|
htmlEditor->AddTransactionListener(*mComposerCommandsUpdater);
|
|
|
|
NS_WARNING_ASSERTION(addedTransactionListener,
|
|
|
|
"Failed to add transaction listener to the editor");
|
2002-11-13 02:03:27 +03:00
|
|
|
|
2003-04-10 22:44:03 +04:00
|
|
|
// Set context on all controllers to be the editor
|
2017-08-04 16:53:28 +03:00
|
|
|
rv = SetEditorOnControllers(aWindow, htmlEditor);
|
2010-06-17 23:27:24 +04:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2002-01-30 07:46:54 +03:00
|
|
|
|
2002-11-13 02:03:27 +03:00
|
|
|
// Everything went fine!
|
|
|
|
mEditorStatus = eEditorOK;
|
|
|
|
|
|
|
|
// This will trigger documentCreation notification
|
2017-08-04 16:53:28 +03:00
|
|
|
return htmlEditor->PostCreate();
|
2002-11-13 02:03:27 +03:00
|
|
|
}
|
2002-01-30 07:46:54 +03:00
|
|
|
|
2008-04-24 01:36:17 +04:00
|
|
|
// Removes all listeners and controllers from aWindow and aEditor.
|
2016-01-30 20:05:36 +03:00
|
|
|
void nsEditingSession::RemoveListenersAndControllers(
|
|
|
|
nsPIDOMWindowOuter* aWindow, HTMLEditor* aHTMLEditor) {
|
2018-01-26 08:38:05 +03:00
|
|
|
if (!mComposerCommandsUpdater || !aHTMLEditor) {
|
2008-04-24 01:36:17 +04:00
|
|
|
return;
|
2016-10-24 05:27:45 +03:00
|
|
|
}
|
2008-04-24 01:36:17 +04:00
|
|
|
|
|
|
|
// Remove all the listeners
|
2018-01-26 08:38:05 +03:00
|
|
|
aHTMLEditor->SetComposerCommandsUpdater(nullptr);
|
|
|
|
aHTMLEditor->RemoveDocumentStateListener(mComposerCommandsUpdater);
|
2018-03-23 12:55:56 +03:00
|
|
|
DebugOnly<bool> removedTransactionListener =
|
|
|
|
aHTMLEditor->RemoveTransactionListener(*mComposerCommandsUpdater);
|
|
|
|
NS_WARNING_ASSERTION(removedTransactionListener,
|
|
|
|
"Failed to remove transaction listener from the editor");
|
2008-04-24 01:36:17 +04:00
|
|
|
|
|
|
|
// Remove editor controllers from the window now that we're not
|
|
|
|
// editing in that window any more.
|
|
|
|
RemoveEditorControllers(aWindow);
|
|
|
|
}
|
|
|
|
|
2002-01-30 07:46:54 +03:00
|
|
|
/*---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
TearDownEditorOnWindow
|
|
|
|
|
2007-11-12 17:47:03 +03:00
|
|
|
void tearDownEditorOnWindow (in nsIDOMWindow aWindow);
|
2002-01-30 07:46:54 +03:00
|
|
|
----------------------------------------------------------------------------*/
|
|
|
|
NS_IMETHODIMP
|
2016-01-30 20:05:36 +03:00
|
|
|
nsEditingSession::TearDownEditorOnWindow(mozIDOMWindowProxy* aWindow) {
|
2011-07-15 01:06:37 +04:00
|
|
|
if (!mDoneSetup) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2005-02-24 00:27:20 +03:00
|
|
|
|
2010-06-18 00:40:48 +04:00
|
|
|
NS_ENSURE_TRUE(aWindow, NS_ERROR_NULL_POINTER);
|
2008-04-24 01:36:17 +04:00
|
|
|
|
2005-02-24 00:27:20 +03:00
|
|
|
// Kill any existing reload timer
|
2016-10-24 05:27:45 +03:00
|
|
|
if (mLoadBlankDocTimer) {
|
2005-02-24 00:27:20 +03:00
|
|
|
mLoadBlankDocTimer->Cancel();
|
2012-07-30 18:20:58 +04:00
|
|
|
mLoadBlankDocTimer = nullptr;
|
2005-02-24 00:27:20 +03:00
|
|
|
}
|
|
|
|
|
2011-10-17 18:59:28 +04:00
|
|
|
mDoneSetup = false;
|
2005-02-24 00:27:20 +03:00
|
|
|
|
2007-11-12 17:47:03 +03:00
|
|
|
// Check if we're turning off editing (from contentEditable or designMode).
|
2016-01-30 20:05:36 +03:00
|
|
|
auto* window = nsPIDOMWindowOuter::From(aWindow);
|
2015-10-27 00:37:32 +03:00
|
|
|
|
2019-01-02 16:05:23 +03:00
|
|
|
RefPtr<Document> doc = window->GetDoc();
|
2015-10-27 00:37:32 +03:00
|
|
|
nsCOMPtr<nsIHTMLDocument> htmlDoc = do_QueryInterface(doc);
|
2011-09-29 10:19:26 +04:00
|
|
|
bool stopEditing = htmlDoc && htmlDoc->IsEditingOn();
|
2016-10-24 05:27:45 +03:00
|
|
|
if (stopEditing) {
|
2016-01-30 20:05:36 +03:00
|
|
|
RemoveWebProgressListener(window);
|
2016-10-24 05:27:45 +03:00
|
|
|
}
|
2002-11-20 09:23:05 +03:00
|
|
|
|
2016-01-30 20:05:36 +03:00
|
|
|
nsCOMPtr<nsIDocShell> docShell = window->GetDocShell();
|
2013-02-14 02:39:30 +04:00
|
|
|
NS_ENSURE_STATE(docShell);
|
2015-05-28 18:58:42 +03:00
|
|
|
|
2017-08-04 16:53:28 +03:00
|
|
|
RefPtr<HTMLEditor> htmlEditor = docShell->GetHTMLEditor();
|
2016-10-24 05:27:45 +03:00
|
|
|
if (stopEditing) {
|
2017-08-07 08:25:52 +03:00
|
|
|
htmlDoc->TearingDownEditor();
|
2016-10-24 05:27:45 +03:00
|
|
|
}
|
2008-02-20 12:54:52 +03:00
|
|
|
|
2018-01-26 08:38:05 +03:00
|
|
|
if (mComposerCommandsUpdater && htmlEditor) {
|
2015-05-28 18:58:42 +03:00
|
|
|
// Null out the editor on the controllers first to prevent their weak
|
2008-04-24 01:36:17 +04:00
|
|
|
// references from pointing to a destroyed editor.
|
2012-07-30 18:20:58 +04:00
|
|
|
SetEditorOnControllers(aWindow, nullptr);
|
2004-02-11 18:40:34 +03:00
|
|
|
}
|
|
|
|
|
2008-04-24 01:36:17 +04:00
|
|
|
// Null out the editor on the docShell to trigger PreDestroy which
|
|
|
|
// needs to happen before document state listeners are removed below.
|
2013-02-14 02:39:30 +04:00
|
|
|
docShell->SetEditor(nullptr);
|
2003-01-22 03:46:38 +03:00
|
|
|
|
2017-08-04 16:53:28 +03:00
|
|
|
RemoveListenersAndControllers(window, htmlEditor);
|
2005-02-24 00:27:20 +03:00
|
|
|
|
2016-10-24 05:27:45 +03:00
|
|
|
if (stopEditing) {
|
2008-04-24 01:36:17 +04:00
|
|
|
// Make things the way they were before we started editing.
|
|
|
|
RestoreJSAndPlugins(aWindow);
|
2016-01-30 20:05:36 +03:00
|
|
|
RestoreAnimationMode(window);
|
2005-02-25 01:52:03 +03:00
|
|
|
|
2016-10-24 05:27:45 +03:00
|
|
|
if (mMakeWholeDocumentEditable) {
|
2011-10-17 18:59:28 +04:00
|
|
|
doc->SetEditableFlag(false);
|
2011-07-15 16:17:56 +04:00
|
|
|
nsCOMPtr<nsIHTMLDocument> htmlDocument = do_QueryInterface(doc);
|
|
|
|
if (htmlDocument) {
|
|
|
|
htmlDocument->SetEditingState(nsIHTMLDocument::eOff);
|
|
|
|
}
|
2007-07-06 14:45:16 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-08-04 16:53:28 +03:00
|
|
|
return NS_OK;
|
2002-01-30 07:46:54 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/*---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
GetEditorForFrame
|
|
|
|
|
|
|
|
nsIEditor getEditorForFrame (in nsIDOMWindow aWindow);
|
|
|
|
----------------------------------------------------------------------------*/
|
2015-05-28 18:58:42 +03:00
|
|
|
NS_IMETHODIMP
|
2016-01-30 20:05:36 +03:00
|
|
|
nsEditingSession::GetEditorForWindow(mozIDOMWindowProxy* aWindow,
|
2002-11-13 02:03:27 +03:00
|
|
|
nsIEditor** outEditor) {
|
2017-08-12 05:44:16 +03:00
|
|
|
if (NS_WARN_IF(!aWindow)) {
|
|
|
|
return NS_ERROR_INVALID_ARG;
|
|
|
|
}
|
|
|
|
nsCOMPtr<nsIEditor> editor = GetHTMLEditorForWindow(aWindow);
|
|
|
|
editor.forget(outEditor);
|
|
|
|
return NS_OK;
|
2002-01-30 07:46:54 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/*---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
OnStateChange
|
|
|
|
|
|
|
|
----------------------------------------------------------------------------*/
|
|
|
|
NS_IMETHODIMP
|
2002-11-13 02:03:27 +03:00
|
|
|
nsEditingSession::OnStateChange(nsIWebProgress* aWebProgress,
|
2012-08-22 19:56:38 +04:00
|
|
|
nsIRequest* aRequest, uint32_t aStateFlags,
|
|
|
|
nsresult aStatus) {
|
2002-11-13 02:03:27 +03:00
|
|
|
#ifdef NOISY_DOC_LOADING
|
|
|
|
nsCOMPtr<nsIChannel> channel(do_QueryInterface(aRequest));
|
2016-10-24 05:27:45 +03:00
|
|
|
if (channel) {
|
2012-09-02 06:35:17 +04:00
|
|
|
nsAutoCString contentType;
|
2002-11-13 02:03:27 +03:00
|
|
|
channel->GetContentType(contentType);
|
2016-10-24 05:27:45 +03:00
|
|
|
if (!contentType.IsEmpty()) {
|
2003-02-27 17:06:29 +03:00
|
|
|
printf(" ++++++ MIMETYPE = %s\n", contentType.get());
|
2016-10-24 05:27:45 +03:00
|
|
|
}
|
2002-11-13 02:03:27 +03:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2002-01-30 07:46:54 +03:00
|
|
|
//
|
|
|
|
// A Request has started...
|
|
|
|
//
|
2016-10-24 05:27:45 +03:00
|
|
|
if (aStateFlags & nsIWebProgressListener::STATE_START) {
|
2002-11-13 02:03:27 +03:00
|
|
|
#ifdef NOISY_DOC_LOADING
|
|
|
|
{
|
2016-10-24 05:27:45 +03:00
|
|
|
nsCOMPtr<nsIChannel> channel(do_QueryInterface(aRequest));
|
|
|
|
if (channel) {
|
|
|
|
nsCOMPtr<nsIURI> uri;
|
|
|
|
channel->GetURI(getter_AddRefs(uri));
|
|
|
|
if (uri) {
|
2017-08-16 07:07:18 +03:00
|
|
|
nsCString spec;
|
2016-10-24 05:27:45 +03:00
|
|
|
uri->GetSpec(spec);
|
|
|
|
printf(" **** STATE_START: CHANNEL URI=%s, flags=%x\n", spec.get(),
|
|
|
|
aStateFlags);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
printf(" STATE_START: NO CHANNEL flags=%x\n", aStateFlags);
|
2002-11-13 02:03:27 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
2002-01-30 07:46:54 +03:00
|
|
|
// Page level notification...
|
2016-10-24 05:27:45 +03:00
|
|
|
if (aStateFlags & nsIWebProgressListener::STATE_IS_NETWORK) {
|
2002-11-13 02:03:27 +03:00
|
|
|
nsCOMPtr<nsIChannel> channel(do_QueryInterface(aRequest));
|
|
|
|
StartPageLoad(channel);
|
|
|
|
#ifdef NOISY_DOC_LOADING
|
|
|
|
printf("STATE_START & STATE_IS_NETWORK flags=%x\n", aStateFlags);
|
|
|
|
#endif
|
2002-01-30 07:46:54 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// Document level notification...
|
2007-12-05 03:28:24 +03:00
|
|
|
if (aStateFlags & nsIWebProgressListener::STATE_IS_DOCUMENT &&
|
|
|
|
!(aStateFlags & nsIWebProgressListener::STATE_RESTORING)) {
|
2006-08-01 03:05:37 +04:00
|
|
|
#ifdef NOISY_DOC_LOADING
|
|
|
|
printf("STATE_START & STATE_IS_DOCUMENT flags=%x\n", aStateFlags);
|
|
|
|
#endif
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool progressIsForTargetDocument =
|
2005-04-06 06:22:45 +04:00
|
|
|
IsProgressForTargetDocument(aWebProgress);
|
|
|
|
|
2016-10-24 05:27:45 +03:00
|
|
|
if (progressIsForTargetDocument) {
|
2016-01-30 20:05:36 +03:00
|
|
|
nsCOMPtr<mozIDOMWindowProxy> window;
|
2005-04-06 06:22:45 +04:00
|
|
|
aWebProgress->GetDOMWindow(getter_AddRefs(window));
|
|
|
|
|
2016-01-30 20:05:36 +03:00
|
|
|
auto* piWindow = nsPIDOMWindowOuter::From(window);
|
2019-01-02 16:05:23 +03:00
|
|
|
RefPtr<Document> doc = piWindow->GetDoc();
|
2018-04-21 19:42:31 +03:00
|
|
|
nsHTMLDocument* htmlDoc =
|
|
|
|
doc && doc->IsHTMLOrXHTML() ? doc->AsHTMLDocument() : nullptr;
|
2016-10-24 05:27:45 +03:00
|
|
|
if (htmlDoc && htmlDoc->IsWriting()) {
|
2005-04-06 06:22:45 +04:00
|
|
|
nsAutoString designMode;
|
2018-01-26 09:00:49 +03:00
|
|
|
htmlDoc->GetDesignMode(designMode);
|
2005-04-06 06:22:45 +04:00
|
|
|
|
2016-10-24 05:27:45 +03:00
|
|
|
if (designMode.EqualsLiteral("on")) {
|
2005-04-06 06:22:45 +04:00
|
|
|
// This notification is for data coming in through
|
|
|
|
// document.open/write/close(), ignore it.
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-10-17 18:59:28 +04:00
|
|
|
mCanCreateEditor = true;
|
2006-08-01 03:05:37 +04:00
|
|
|
StartDocumentLoad(aWebProgress, progressIsForTargetDocument);
|
|
|
|
}
|
2002-01-30 07:46:54 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
//
|
|
|
|
// A Request is being processed
|
|
|
|
//
|
2016-10-24 05:27:45 +03:00
|
|
|
else if (aStateFlags & nsIWebProgressListener::STATE_TRANSFERRING) {
|
|
|
|
if (aStateFlags & nsIWebProgressListener::STATE_IS_DOCUMENT) {
|
2002-01-30 07:46:54 +03:00
|
|
|
// document transfer started
|
|
|
|
}
|
|
|
|
}
|
|
|
|
//
|
|
|
|
// Got a redirection
|
|
|
|
//
|
2016-10-24 05:27:45 +03:00
|
|
|
else if (aStateFlags & nsIWebProgressListener::STATE_REDIRECTING) {
|
|
|
|
if (aStateFlags & nsIWebProgressListener::STATE_IS_DOCUMENT) {
|
2002-01-30 07:46:54 +03:00
|
|
|
// got a redirect
|
|
|
|
}
|
|
|
|
}
|
|
|
|
//
|
2009-06-11 21:47:32 +04:00
|
|
|
// A network or document Request has finished...
|
2002-01-30 07:46:54 +03:00
|
|
|
//
|
2016-10-24 05:27:45 +03:00
|
|
|
else if (aStateFlags & nsIWebProgressListener::STATE_STOP) {
|
2002-11-13 02:03:27 +03:00
|
|
|
#ifdef NOISY_DOC_LOADING
|
|
|
|
{
|
2016-10-24 05:27:45 +03:00
|
|
|
nsCOMPtr<nsIChannel> channel(do_QueryInterface(aRequest));
|
|
|
|
if (channel) {
|
|
|
|
nsCOMPtr<nsIURI> uri;
|
|
|
|
channel->GetURI(getter_AddRefs(uri));
|
|
|
|
if (uri) {
|
2017-08-16 07:07:18 +03:00
|
|
|
nsCString spec;
|
2016-10-24 05:27:45 +03:00
|
|
|
uri->GetSpec(spec);
|
|
|
|
printf(" **** STATE_STOP: CHANNEL URI=%s, flags=%x\n", spec.get(),
|
|
|
|
aStateFlags);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
printf(" STATE_STOP: NO CHANNEL flags=%x\n", aStateFlags);
|
2002-11-13 02:03:27 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
2003-02-27 17:06:29 +03:00
|
|
|
|
2002-01-30 07:46:54 +03:00
|
|
|
// Document level notification...
|
2016-10-24 05:27:45 +03:00
|
|
|
if (aStateFlags & nsIWebProgressListener::STATE_IS_DOCUMENT) {
|
2003-02-27 17:06:29 +03:00
|
|
|
nsCOMPtr<nsIChannel> channel = do_QueryInterface(aRequest);
|
2005-02-24 00:27:20 +03:00
|
|
|
EndDocumentLoad(aWebProgress, channel, aStatus,
|
|
|
|
IsProgressForTargetDocument(aWebProgress));
|
2002-11-13 02:03:27 +03:00
|
|
|
#ifdef NOISY_DOC_LOADING
|
2003-02-27 17:06:29 +03:00
|
|
|
printf("STATE_STOP & STATE_IS_DOCUMENT flags=%x\n", aStateFlags);
|
2002-11-13 02:03:27 +03:00
|
|
|
#endif
|
2002-01-30 07:46:54 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// Page level notification...
|
2016-10-24 05:27:45 +03:00
|
|
|
if (aStateFlags & nsIWebProgressListener::STATE_IS_NETWORK) {
|
2002-11-13 02:03:27 +03:00
|
|
|
nsCOMPtr<nsIChannel> channel = do_QueryInterface(aRequest);
|
2002-01-30 07:46:54 +03:00
|
|
|
(void)EndPageLoad(aWebProgress, channel, aStatus);
|
2002-11-13 02:03:27 +03:00
|
|
|
#ifdef NOISY_DOC_LOADING
|
|
|
|
printf("STATE_STOP & STATE_IS_NETWORK flags=%x\n", aStateFlags);
|
|
|
|
#endif
|
2002-01-30 07:46:54 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
OnProgressChange
|
|
|
|
|
|
|
|
----------------------------------------------------------------------------*/
|
|
|
|
NS_IMETHODIMP
|
2002-11-13 02:03:27 +03:00
|
|
|
nsEditingSession::OnProgressChange(nsIWebProgress* aWebProgress,
|
|
|
|
nsIRequest* aRequest,
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t aCurSelfProgress,
|
|
|
|
int32_t aMaxSelfProgress,
|
|
|
|
int32_t aCurTotalProgress,
|
|
|
|
int32_t aMaxTotalProgress) {
|
2018-06-18 08:43:11 +03:00
|
|
|
MOZ_ASSERT_UNREACHABLE("notification excluded in AddProgressListener(...)");
|
2002-01-30 07:46:54 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
OnLocationChange
|
|
|
|
|
|
|
|
----------------------------------------------------------------------------*/
|
|
|
|
NS_IMETHODIMP
|
2015-05-28 18:58:42 +03:00
|
|
|
nsEditingSession::OnLocationChange(nsIWebProgress* aWebProgress,
|
2011-11-10 18:01:11 +04:00
|
|
|
nsIRequest* aRequest, nsIURI* aURI,
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t aFlags) {
|
2016-01-30 20:05:36 +03:00
|
|
|
nsCOMPtr<mozIDOMWindowProxy> domWindow;
|
2002-11-27 03:35:09 +03:00
|
|
|
nsresult rv = aWebProgress->GetDOMWindow(getter_AddRefs(domWindow));
|
2010-06-17 23:27:24 +04:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2002-11-27 03:35:09 +03:00
|
|
|
|
2016-01-30 20:05:36 +03:00
|
|
|
auto* piWindow = nsPIDOMWindowOuter::From(domWindow);
|
2002-11-27 03:35:09 +03:00
|
|
|
|
2019-01-02 16:05:23 +03:00
|
|
|
RefPtr<Document> doc = piWindow->GetDoc();
|
2010-06-17 23:41:16 +04:00
|
|
|
NS_ENSURE_TRUE(doc, NS_ERROR_FAILURE);
|
2002-11-27 03:35:09 +03:00
|
|
|
|
2004-01-10 02:54:21 +03:00
|
|
|
doc->SetDocumentURI(aURI);
|
2002-11-27 03:35:09 +03:00
|
|
|
|
|
|
|
// Notify the location-changed observer that
|
|
|
|
// the document URL has changed
|
2016-01-30 20:05:36 +03:00
|
|
|
nsIDocShell* docShell = piWindow->GetDocShell();
|
2010-06-17 23:41:16 +04:00
|
|
|
NS_ENSURE_TRUE(docShell, NS_ERROR_FAILURE);
|
2002-11-27 03:35:09 +03:00
|
|
|
|
2016-04-12 11:09:41 +03:00
|
|
|
nsCOMPtr<nsICommandManager> commandManager = docShell->GetCommandManager();
|
2002-11-27 03:35:09 +03:00
|
|
|
nsCOMPtr<nsPICommandUpdater> commandUpdater =
|
|
|
|
do_QueryInterface(commandManager);
|
2010-06-17 23:41:16 +04:00
|
|
|
NS_ENSURE_TRUE(commandUpdater, NS_ERROR_FAILURE);
|
2002-11-27 03:35:09 +03:00
|
|
|
|
|
|
|
return commandUpdater->CommandStatusChanged("obs_documentLocationChanged");
|
2002-01-30 07:46:54 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/*---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
OnStatusChange
|
|
|
|
|
|
|
|
----------------------------------------------------------------------------*/
|
|
|
|
NS_IMETHODIMP
|
2002-11-13 02:03:27 +03:00
|
|
|
nsEditingSession::OnStatusChange(nsIWebProgress* aWebProgress,
|
|
|
|
nsIRequest* aRequest, nsresult aStatus,
|
2014-01-04 19:02:17 +04:00
|
|
|
const char16_t* aMessage) {
|
2018-06-18 08:43:11 +03:00
|
|
|
MOZ_ASSERT_UNREACHABLE("notification excluded in AddProgressListener(...)");
|
2002-01-30 07:46:54 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
OnSecurityChange
|
|
|
|
|
|
|
|
----------------------------------------------------------------------------*/
|
|
|
|
NS_IMETHODIMP
|
2002-11-13 02:03:27 +03:00
|
|
|
nsEditingSession::OnSecurityChange(nsIWebProgress* aWebProgress,
|
2019-01-07 01:45:57 +03:00
|
|
|
nsIRequest* aRequest, uint32_t aState) {
|
|
|
|
MOZ_ASSERT_UNREACHABLE("notification excluded in AddProgressListener(...)");
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
OnContentBlockingEvent
|
|
|
|
|
|
|
|
----------------------------------------------------------------------------*/
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsEditingSession::OnContentBlockingEvent(nsIWebProgress* aWebProgress,
|
|
|
|
nsIRequest* aRequest,
|
|
|
|
uint32_t aEvent) {
|
2018-06-18 08:43:11 +03:00
|
|
|
MOZ_ASSERT_UNREACHABLE("notification excluded in AddProgressListener(...)");
|
2002-01-30 07:46:54 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*---------------------------------------------------------------------------
|
|
|
|
|
2003-02-27 17:06:29 +03:00
|
|
|
IsProgressForTargetDocument
|
2002-01-30 07:46:54 +03:00
|
|
|
|
2003-02-27 17:06:29 +03:00
|
|
|
Check that this notification is for our document.
|
2002-01-30 07:46:54 +03:00
|
|
|
----------------------------------------------------------------------------*/
|
|
|
|
|
2003-02-27 17:06:29 +03:00
|
|
|
bool nsEditingSession::IsProgressForTargetDocument(
|
|
|
|
nsIWebProgress* aWebProgress) {
|
2010-10-15 21:59:00 +04:00
|
|
|
nsCOMPtr<nsIWebProgress> editedWebProgress = do_QueryReferent(mDocShell);
|
|
|
|
return editedWebProgress == aWebProgress;
|
2002-01-30 07:46:54 +03:00
|
|
|
}
|
|
|
|
|
2002-11-13 02:03:27 +03:00
|
|
|
/*---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
GetEditorStatus
|
|
|
|
|
2015-05-28 18:58:42 +03:00
|
|
|
Called during GetCommandStateParams("obs_documentCreated"...)
|
|
|
|
to determine if editor was created and document
|
2002-11-13 02:03:27 +03:00
|
|
|
was loaded successfully
|
|
|
|
----------------------------------------------------------------------------*/
|
|
|
|
NS_IMETHODIMP
|
2012-08-22 19:56:38 +04:00
|
|
|
nsEditingSession::GetEditorStatus(uint32_t* aStatus) {
|
2002-11-13 02:03:27 +03:00
|
|
|
NS_ENSURE_ARG_POINTER(aStatus);
|
|
|
|
*aStatus = mEditorStatus;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2002-01-30 07:46:54 +03:00
|
|
|
/*---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
StartDocumentLoad
|
|
|
|
|
|
|
|
Called on start of load in a single frame
|
|
|
|
----------------------------------------------------------------------------*/
|
2015-05-28 18:58:42 +03:00
|
|
|
nsresult nsEditingSession::StartDocumentLoad(nsIWebProgress* aWebProgress,
|
2011-09-29 10:19:26 +04:00
|
|
|
bool aIsToBeMadeEditable) {
|
2002-01-30 07:46:54 +03:00
|
|
|
#ifdef NOISY_DOC_LOADING
|
2003-02-27 17:06:29 +03:00
|
|
|
printf("======= StartDocumentLoad ========\n");
|
2002-01-30 07:46:54 +03:00
|
|
|
#endif
|
|
|
|
|
2002-11-13 02:03:27 +03:00
|
|
|
NS_ENSURE_ARG_POINTER(aWebProgress);
|
2015-05-28 18:58:42 +03:00
|
|
|
|
2016-10-24 05:27:45 +03:00
|
|
|
if (aIsToBeMadeEditable) {
|
2003-02-27 17:06:29 +03:00
|
|
|
mEditorStatus = eEditorCreationInProgress;
|
2016-10-24 05:27:45 +03:00
|
|
|
}
|
2003-02-27 17:06:29 +03:00
|
|
|
|
2002-01-30 07:46:54 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
EndDocumentLoad
|
|
|
|
|
|
|
|
Called on end of load in a single frame
|
|
|
|
----------------------------------------------------------------------------*/
|
2002-11-13 02:03:27 +03:00
|
|
|
nsresult nsEditingSession::EndDocumentLoad(nsIWebProgress* aWebProgress,
|
2003-02-27 17:06:29 +03:00
|
|
|
nsIChannel* aChannel,
|
|
|
|
nsresult aStatus,
|
2011-09-29 10:19:26 +04:00
|
|
|
bool aIsToBeMadeEditable) {
|
2002-11-13 02:03:27 +03:00
|
|
|
NS_ENSURE_ARG_POINTER(aWebProgress);
|
2015-05-28 18:58:42 +03:00
|
|
|
|
2002-01-30 07:46:54 +03:00
|
|
|
#ifdef NOISY_DOC_LOADING
|
2003-02-27 17:06:29 +03:00
|
|
|
printf("======= EndDocumentLoad ========\n");
|
|
|
|
printf("with status %d, ", aStatus);
|
|
|
|
nsCOMPtr<nsIURI> uri;
|
2017-08-16 07:07:18 +03:00
|
|
|
nsCString spec;
|
2003-02-27 17:06:29 +03:00
|
|
|
if (NS_SUCCEEDED(aChannel->GetURI(getter_AddRefs(uri)))) {
|
|
|
|
uri->GetSpec(spec);
|
|
|
|
printf(" uri %s\n", spec.get());
|
|
|
|
}
|
2002-01-30 07:46:54 +03:00
|
|
|
#endif
|
2003-02-27 17:06:29 +03:00
|
|
|
|
2002-11-27 03:35:09 +03:00
|
|
|
// We want to call the base class EndDocumentLoad,
|
|
|
|
// but avoid some of the stuff
|
2009-05-07 23:21:53 +04:00
|
|
|
// that nsDocShell does (need to refactor).
|
2015-05-28 18:58:42 +03:00
|
|
|
|
2002-01-30 07:46:54 +03:00
|
|
|
// OK, time to make an editor on this document
|
2016-01-30 20:05:36 +03:00
|
|
|
nsCOMPtr<mozIDOMWindowProxy> domWindow;
|
2002-01-30 07:46:54 +03:00
|
|
|
aWebProgress->GetDOMWindow(getter_AddRefs(domWindow));
|
2016-01-30 20:05:36 +03:00
|
|
|
NS_ENSURE_TRUE(domWindow, NS_ERROR_FAILURE);
|
2015-05-28 18:58:42 +03:00
|
|
|
|
|
|
|
// Set the error state -- we will create an editor
|
2002-11-13 02:03:27 +03:00
|
|
|
// anyway and load empty doc later
|
2016-10-24 05:27:45 +03:00
|
|
|
if (aIsToBeMadeEditable && aStatus == NS_ERROR_FILE_NOT_FOUND) {
|
|
|
|
mEditorStatus = eEditorErrorFileNotFound;
|
2003-02-27 17:06:29 +03:00
|
|
|
}
|
2002-11-13 02:03:27 +03:00
|
|
|
|
2016-01-30 20:05:36 +03:00
|
|
|
nsIDocShell* docShell = nsPIDOMWindowOuter::From(domWindow)->GetDocShell();
|
2010-06-17 23:41:16 +04:00
|
|
|
NS_ENSURE_TRUE(docShell, NS_ERROR_FAILURE); // better error handling?
|
2003-02-14 17:56:32 +03:00
|
|
|
|
2003-01-22 03:46:38 +03:00
|
|
|
// cancel refresh from meta tags
|
2003-02-14 17:56:32 +03:00
|
|
|
// we need to make sure that all pages in editor (whether editable or not)
|
|
|
|
// can't refresh contents being edited
|
2003-01-22 03:46:38 +03:00
|
|
|
nsCOMPtr<nsIRefreshURI> refreshURI = do_QueryInterface(docShell);
|
2016-10-24 05:27:45 +03:00
|
|
|
if (refreshURI) {
|
2003-01-22 03:46:38 +03:00
|
|
|
refreshURI->CancelRefreshURITimers();
|
2016-10-24 05:27:45 +03:00
|
|
|
}
|
2003-01-22 03:46:38 +03:00
|
|
|
|
2004-02-10 01:48:53 +03:00
|
|
|
nsresult rv = NS_OK;
|
|
|
|
|
2002-01-30 07:46:54 +03:00
|
|
|
// did someone set the flag to make this shell editable?
|
2016-10-24 05:27:45 +03:00
|
|
|
if (aIsToBeMadeEditable && mCanCreateEditor) {
|
2011-09-29 10:19:26 +04:00
|
|
|
bool makeEditable;
|
2013-02-14 02:39:30 +04:00
|
|
|
docShell->GetEditable(&makeEditable);
|
2015-05-28 18:58:42 +03:00
|
|
|
|
2016-10-24 05:27:45 +03:00
|
|
|
if (makeEditable) {
|
2008-05-06 21:46:55 +04:00
|
|
|
// To keep pre Gecko 1.9 behavior, setup editor always when
|
|
|
|
// mMakeWholeDocumentEditable.
|
2010-11-04 23:44:46 +03:00
|
|
|
bool needsSetup = false;
|
2008-05-06 21:46:55 +04:00
|
|
|
if (mMakeWholeDocumentEditable) {
|
2010-11-04 23:44:46 +03:00
|
|
|
needsSetup = true;
|
2008-05-06 21:46:55 +04:00
|
|
|
} else {
|
|
|
|
// do we already have an editor here?
|
2017-08-04 16:53:28 +03:00
|
|
|
needsSetup = !docShell->GetHTMLEditor();
|
2008-05-06 21:46:55 +04:00
|
|
|
}
|
|
|
|
|
2016-10-24 05:27:45 +03:00
|
|
|
if (needsSetup) {
|
2011-10-17 18:59:28 +04:00
|
|
|
mCanCreateEditor = false;
|
2007-06-28 06:48:16 +04:00
|
|
|
rv = SetupEditorOnWindow(domWindow);
|
2016-10-24 05:27:45 +03:00
|
|
|
if (NS_FAILED(rv)) {
|
2007-06-28 06:48:16 +04:00
|
|
|
// If we had an error, setup timer to load a blank page later
|
2016-10-24 05:27:45 +03:00
|
|
|
if (mLoadBlankDocTimer) {
|
2007-06-28 06:48:16 +04:00
|
|
|
// Must cancel previous timer?
|
|
|
|
mLoadBlankDocTimer->Cancel();
|
2013-04-03 04:13:10 +04:00
|
|
|
mLoadBlankDocTimer = nullptr;
|
2007-06-28 06:48:16 +04:00
|
|
|
}
|
2015-05-28 18:58:42 +03:00
|
|
|
|
2017-09-25 05:57:48 +03:00
|
|
|
rv = NS_NewTimerWithFuncCallback(getter_AddRefs(mLoadBlankDocTimer),
|
2017-06-12 22:34:10 +03:00
|
|
|
nsEditingSession::TimerCallback,
|
|
|
|
static_cast<void*>(mDocShell.get()),
|
|
|
|
10, nsITimer::TYPE_ONE_SHOT,
|
|
|
|
"nsEditingSession::EndDocumentLoad");
|
2017-09-25 05:57:48 +03:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
mEditorStatus = eEditorCreationInProgress;
|
2007-06-28 06:48:16 +04:00
|
|
|
}
|
2002-11-13 02:03:27 +03:00
|
|
|
}
|
2002-01-30 07:46:54 +03:00
|
|
|
}
|
|
|
|
}
|
2002-11-13 02:03:27 +03:00
|
|
|
return rv;
|
2002-01-30 07:46:54 +03:00
|
|
|
}
|
|
|
|
|
2002-11-13 02:03:27 +03:00
|
|
|
void nsEditingSession::TimerCallback(nsITimer* aTimer, void* aClosure) {
|
2010-03-18 19:12:37 +03:00
|
|
|
nsCOMPtr<nsIDocShell> docShell =
|
|
|
|
do_QueryReferent(static_cast<nsIWeakReference*>(aClosure));
|
2016-10-24 05:27:45 +03:00
|
|
|
if (docShell) {
|
2002-11-13 02:03:27 +03:00
|
|
|
nsCOMPtr<nsIWebNavigation> webNav(do_QueryInterface(docShell));
|
2016-10-24 05:27:45 +03:00
|
|
|
if (webNav) {
|
2019-01-11 14:43:39 +03:00
|
|
|
LoadURIOptions loadURIOptions;
|
|
|
|
loadURIOptions.mTriggeringPrincipal =
|
|
|
|
nsContentUtils::GetSystemPrincipal();
|
|
|
|
webNav->LoadURI(NS_LITERAL_STRING("about:blank"), loadURIOptions);
|
2016-10-24 05:27:45 +03:00
|
|
|
}
|
2002-11-13 02:03:27 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-01-30 07:46:54 +03:00
|
|
|
/*---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
StartPageLoad
|
|
|
|
|
|
|
|
Called on start load of the entire page (incl. subframes)
|
|
|
|
----------------------------------------------------------------------------*/
|
2002-11-13 02:03:27 +03:00
|
|
|
nsresult nsEditingSession::StartPageLoad(nsIChannel* aChannel) {
|
|
|
|
#ifdef NOISY_DOC_LOADING
|
|
|
|
printf("======= StartPageLoad ========\n");
|
|
|
|
#endif
|
2002-01-30 07:46:54 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
EndPageLoad
|
|
|
|
|
|
|
|
Called on end load of the entire page (incl. subframes)
|
|
|
|
----------------------------------------------------------------------------*/
|
2002-11-13 02:03:27 +03:00
|
|
|
nsresult nsEditingSession::EndPageLoad(nsIWebProgress* aWebProgress,
|
|
|
|
nsIChannel* aChannel, nsresult aStatus) {
|
2003-02-27 17:06:29 +03:00
|
|
|
#ifdef NOISY_DOC_LOADING
|
|
|
|
printf("======= EndPageLoad ========\n");
|
|
|
|
printf(" with status %d, ", aStatus);
|
|
|
|
nsCOMPtr<nsIURI> uri;
|
2017-08-16 07:07:18 +03:00
|
|
|
nsCString spec;
|
2003-02-27 17:06:29 +03:00
|
|
|
if (NS_SUCCEEDED(aChannel->GetURI(getter_AddRefs(uri)))) {
|
|
|
|
uri->GetSpec(spec);
|
|
|
|
printf("uri %s\n", spec.get());
|
|
|
|
}
|
2015-05-28 18:58:42 +03:00
|
|
|
|
2012-09-02 06:35:17 +04:00
|
|
|
nsAutoCString contentType;
|
2003-02-27 17:06:29 +03:00
|
|
|
aChannel->GetContentType(contentType);
|
2016-10-24 05:27:45 +03:00
|
|
|
if (!contentType.IsEmpty()) {
|
2015-05-28 18:58:42 +03:00
|
|
|
printf(" flags = %d, status = %d, MIMETYPE = %s\n", mEditorFlags,
|
2003-02-27 17:06:29 +03:00
|
|
|
mEditorStatus, contentType.get());
|
2016-10-24 05:27:45 +03:00
|
|
|
}
|
2003-02-27 17:06:29 +03:00
|
|
|
#endif
|
|
|
|
|
2015-05-28 18:58:42 +03:00
|
|
|
// Set the error state -- we will create an editor anyway
|
2002-11-13 02:03:27 +03:00
|
|
|
// and load empty doc later
|
2016-10-24 05:27:45 +03:00
|
|
|
if (aStatus == NS_ERROR_FILE_NOT_FOUND) {
|
2002-11-13 02:03:27 +03:00
|
|
|
mEditorStatus = eEditorErrorFileNotFound;
|
2016-10-24 05:27:45 +03:00
|
|
|
}
|
2002-11-13 02:03:27 +03:00
|
|
|
|
2016-01-30 20:05:36 +03:00
|
|
|
nsCOMPtr<mozIDOMWindowProxy> domWindow;
|
2005-02-24 00:27:20 +03:00
|
|
|
aWebProgress->GetDOMWindow(getter_AddRefs(domWindow));
|
|
|
|
|
2016-01-30 20:05:36 +03:00
|
|
|
nsIDocShell* docShell =
|
|
|
|
domWindow ? nsPIDOMWindowOuter::From(domWindow)->GetDocShell() : nullptr;
|
2010-06-17 23:41:16 +04:00
|
|
|
NS_ENSURE_TRUE(docShell, NS_ERROR_FAILURE);
|
2003-01-22 03:46:38 +03:00
|
|
|
|
2003-02-14 17:56:32 +03:00
|
|
|
// cancel refresh from meta tags
|
|
|
|
// we need to make sure that all pages in editor (whether editable or not)
|
|
|
|
// can't refresh contents being edited
|
2003-01-22 03:46:38 +03:00
|
|
|
nsCOMPtr<nsIRefreshURI> refreshURI = do_QueryInterface(docShell);
|
2016-10-24 05:27:45 +03:00
|
|
|
if (refreshURI) {
|
2003-01-22 03:46:38 +03:00
|
|
|
refreshURI->CancelRefreshURITimers();
|
2016-10-24 05:27:45 +03:00
|
|
|
}
|
2003-01-22 03:46:38 +03:00
|
|
|
|
2003-02-27 17:06:29 +03:00
|
|
|
#if 0
|
|
|
|
// Shouldn't we do this when we want to edit sub-frames?
|
2011-10-17 18:59:28 +04:00
|
|
|
return MakeWindowEditable(domWindow, "html", false, mInteractive);
|
2003-02-27 17:06:29 +03:00
|
|
|
#else
|
2002-01-30 07:46:54 +03:00
|
|
|
return NS_OK;
|
2003-02-27 17:06:29 +03:00
|
|
|
#endif
|
2002-01-30 07:46:54 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/*---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
PrepareForEditing
|
|
|
|
|
|
|
|
Set up this editing session for one or more editors
|
|
|
|
----------------------------------------------------------------------------*/
|
2016-01-30 20:05:36 +03:00
|
|
|
nsresult nsEditingSession::PrepareForEditing(nsPIDOMWindowOuter* aWindow) {
|
2016-10-24 05:27:45 +03:00
|
|
|
if (mProgressListenerRegistered) {
|
2002-01-30 07:46:54 +03:00
|
|
|
return NS_OK;
|
2016-10-24 05:27:45 +03:00
|
|
|
}
|
2015-05-28 18:58:42 +03:00
|
|
|
|
2016-01-30 20:05:36 +03:00
|
|
|
nsIDocShell* docShell = aWindow ? aWindow->GetDocShell() : nullptr;
|
2015-05-28 18:58:42 +03:00
|
|
|
|
2002-01-30 07:46:54 +03:00
|
|
|
// register callback
|
|
|
|
nsCOMPtr<nsIWebProgress> webProgress = do_GetInterface(docShell);
|
2010-06-17 23:41:16 +04:00
|
|
|
NS_ENSURE_TRUE(webProgress, NS_ERROR_FAILURE);
|
2002-01-30 07:46:54 +03:00
|
|
|
|
2005-02-25 21:16:20 +03:00
|
|
|
nsresult rv = webProgress->AddProgressListener(
|
2015-05-28 18:58:42 +03:00
|
|
|
this, (nsIWebProgress::NOTIFY_STATE_NETWORK |
|
2005-02-25 21:16:20 +03:00
|
|
|
nsIWebProgress::NOTIFY_STATE_DOCUMENT |
|
|
|
|
nsIWebProgress::NOTIFY_LOCATION));
|
|
|
|
|
|
|
|
mProgressListenerRegistered = NS_SUCCEEDED(rv);
|
|
|
|
|
|
|
|
return rv;
|
2002-01-30 07:46:54 +03:00
|
|
|
}
|
|
|
|
|
2018-09-07 16:24:34 +03:00
|
|
|
/*---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
SetupEditorCommandController
|
|
|
|
|
|
|
|
Create a command controller, append to controllers,
|
|
|
|
get and return the controller ID, and set the context
|
|
|
|
----------------------------------------------------------------------------*/
|
|
|
|
nsresult nsEditingSession::SetupEditorCommandController(
|
|
|
|
nsEditingSession::ControllerCreatorFn aControllerCreatorFn,
|
|
|
|
mozIDOMWindowProxy* aWindow, nsISupports* aContext,
|
|
|
|
uint32_t* aControllerId) {
|
|
|
|
NS_ENSURE_ARG_POINTER(aControllerCreatorFn);
|
|
|
|
NS_ENSURE_ARG_POINTER(aWindow);
|
|
|
|
NS_ENSURE_ARG_POINTER(aContext);
|
|
|
|
NS_ENSURE_ARG_POINTER(aControllerId);
|
|
|
|
|
|
|
|
auto* piWindow = nsPIDOMWindowOuter::From(aWindow);
|
|
|
|
MOZ_ASSERT(piWindow);
|
|
|
|
|
|
|
|
nsCOMPtr<nsIControllers> controllers;
|
|
|
|
nsresult rv = piWindow->GetControllers(getter_AddRefs(controllers));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
// We only have to create each singleton controller once
|
|
|
|
// We know this has happened once we have a controllerId value
|
|
|
|
if (!*aControllerId) {
|
|
|
|
nsCOMPtr<nsIController> controller = aControllerCreatorFn();
|
|
|
|
NS_ENSURE_TRUE(controller, NS_ERROR_FAILURE);
|
|
|
|
|
|
|
|
// We must insert at head of the list to be sure our
|
|
|
|
// controller is found before other implementations
|
|
|
|
// (e.g., not-implemented versions by browser)
|
|
|
|
rv = controllers->InsertControllerAt(0, controller);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
// Remember the ID for the controller
|
|
|
|
rv = controllers->GetControllerId(controller, aControllerId);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
}
|
|
|
|
|
2003-04-10 22:44:03 +04:00
|
|
|
// Set the context
|
|
|
|
return SetContextOnControllerById(controllers, aContext, *aControllerId);
|
2002-01-30 07:46:54 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/*---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
SetEditorOnControllers
|
|
|
|
|
|
|
|
Set the editor on the controller(s) for this window
|
|
|
|
----------------------------------------------------------------------------*/
|
2004-01-19 23:31:18 +03:00
|
|
|
NS_IMETHODIMP
|
2016-01-30 20:05:36 +03:00
|
|
|
nsEditingSession::SetEditorOnControllers(mozIDOMWindowProxy* aWindow,
|
2002-11-13 02:03:27 +03:00
|
|
|
nsIEditor* aEditor) {
|
2011-07-15 14:31:34 +04:00
|
|
|
NS_ENSURE_TRUE(aWindow, NS_ERROR_NULL_POINTER);
|
2015-05-28 18:58:42 +03:00
|
|
|
|
2016-01-30 20:05:36 +03:00
|
|
|
auto* piWindow = nsPIDOMWindowOuter::From(aWindow);
|
2015-10-27 00:37:32 +03:00
|
|
|
|
2015-05-28 18:58:42 +03:00
|
|
|
nsCOMPtr<nsIControllers> controllers;
|
2015-10-27 00:37:32 +03:00
|
|
|
nsresult rv = piWindow->GetControllers(getter_AddRefs(controllers));
|
2010-06-17 23:27:24 +04:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2002-01-30 07:46:54 +03:00
|
|
|
|
2017-08-04 16:53:28 +03:00
|
|
|
nsCOMPtr<nsISupports> editorAsISupports = static_cast<nsISupports*>(aEditor);
|
2016-10-24 05:27:45 +03:00
|
|
|
if (mBaseCommandControllerId) {
|
2003-04-10 22:44:03 +04:00
|
|
|
rv = SetContextOnControllerById(controllers, editorAsISupports,
|
2005-02-24 00:27:20 +03:00
|
|
|
mBaseCommandControllerId);
|
2010-06-17 23:27:24 +04:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2002-11-13 02:03:27 +03:00
|
|
|
}
|
2002-01-30 07:46:54 +03:00
|
|
|
|
2016-10-24 05:27:45 +03:00
|
|
|
if (mDocStateControllerId) {
|
2003-04-10 22:44:03 +04:00
|
|
|
rv = SetContextOnControllerById(controllers, editorAsISupports,
|
2005-02-24 00:27:20 +03:00
|
|
|
mDocStateControllerId);
|
2010-06-17 23:27:24 +04:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2002-01-30 07:46:54 +03:00
|
|
|
}
|
|
|
|
|
2016-10-24 05:27:45 +03:00
|
|
|
if (mHTMLCommandControllerId) {
|
2003-04-10 22:44:03 +04:00
|
|
|
rv = SetContextOnControllerById(controllers, editorAsISupports,
|
2005-02-24 00:27:20 +03:00
|
|
|
mHTMLCommandControllerId);
|
2016-10-24 05:27:45 +03:00
|
|
|
}
|
2002-11-13 02:03:27 +03:00
|
|
|
|
|
|
|
return rv;
|
2002-01-30 07:46:54 +03:00
|
|
|
}
|
|
|
|
|
2003-04-10 22:44:03 +04:00
|
|
|
nsresult nsEditingSession::SetContextOnControllerById(
|
|
|
|
nsIControllers* aControllers, nsISupports* aContext, uint32_t aID) {
|
2002-11-13 02:03:27 +03:00
|
|
|
NS_ENSURE_ARG_POINTER(aControllers);
|
|
|
|
|
2003-04-10 22:44:03 +04:00
|
|
|
// aContext can be null (when destroying editor)
|
2015-05-28 18:58:42 +03:00
|
|
|
nsCOMPtr<nsIController> controller;
|
2002-11-13 02:03:27 +03:00
|
|
|
aControllers->GetControllerById(aID, getter_AddRefs(controller));
|
2015-05-28 18:58:42 +03:00
|
|
|
|
2002-11-13 02:03:27 +03:00
|
|
|
// ok with nil controller
|
|
|
|
nsCOMPtr<nsIControllerContext> editorController =
|
|
|
|
do_QueryInterface(controller);
|
2010-06-17 23:41:16 +04:00
|
|
|
NS_ENSURE_TRUE(editorController, NS_ERROR_FAILURE);
|
2002-01-30 07:46:54 +03:00
|
|
|
|
2003-04-10 22:44:03 +04:00
|
|
|
return editorController->SetCommandContext(aContext);
|
2002-11-13 02:03:27 +03:00
|
|
|
}
|
2008-04-24 01:36:17 +04:00
|
|
|
|
2016-01-30 20:05:36 +03:00
|
|
|
void nsEditingSession::RemoveEditorControllers(nsPIDOMWindowOuter* aWindow) {
|
2015-05-28 18:58:42 +03:00
|
|
|
// Remove editor controllers from the aWindow, call when we're
|
2008-04-24 01:36:17 +04:00
|
|
|
// tearing down/detaching editor.
|
|
|
|
|
|
|
|
nsCOMPtr<nsIControllers> controllers;
|
2016-01-30 20:05:36 +03:00
|
|
|
if (aWindow) {
|
|
|
|
aWindow->GetControllers(getter_AddRefs(controllers));
|
2015-10-27 00:37:32 +03:00
|
|
|
}
|
2008-04-24 01:36:17 +04:00
|
|
|
|
2016-10-24 05:27:45 +03:00
|
|
|
if (controllers) {
|
2008-04-24 01:36:17 +04:00
|
|
|
nsCOMPtr<nsIController> controller;
|
2016-10-24 05:27:45 +03:00
|
|
|
if (mBaseCommandControllerId) {
|
2008-04-24 01:36:17 +04:00
|
|
|
controllers->GetControllerById(mBaseCommandControllerId,
|
|
|
|
getter_AddRefs(controller));
|
2016-10-24 05:27:45 +03:00
|
|
|
if (controller) {
|
2008-04-24 01:36:17 +04:00
|
|
|
controllers->RemoveController(controller);
|
2016-10-24 05:27:45 +03:00
|
|
|
}
|
2008-04-24 01:36:17 +04:00
|
|
|
}
|
|
|
|
|
2016-10-24 05:27:45 +03:00
|
|
|
if (mDocStateControllerId) {
|
2008-04-24 01:36:17 +04:00
|
|
|
controllers->GetControllerById(mDocStateControllerId,
|
|
|
|
getter_AddRefs(controller));
|
2016-10-24 05:27:45 +03:00
|
|
|
if (controller) {
|
2008-04-24 01:36:17 +04:00
|
|
|
controllers->RemoveController(controller);
|
2016-10-24 05:27:45 +03:00
|
|
|
}
|
2008-04-24 01:36:17 +04:00
|
|
|
}
|
|
|
|
|
2016-10-24 05:27:45 +03:00
|
|
|
if (mHTMLCommandControllerId) {
|
2008-04-24 01:36:17 +04:00
|
|
|
controllers->GetControllerById(mHTMLCommandControllerId,
|
|
|
|
getter_AddRefs(controller));
|
2016-10-24 05:27:45 +03:00
|
|
|
if (controller) {
|
2008-04-24 01:36:17 +04:00
|
|
|
controllers->RemoveController(controller);
|
2016-10-24 05:27:45 +03:00
|
|
|
}
|
2008-04-24 01:36:17 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Clear IDs to trigger creation of new controllers.
|
|
|
|
mBaseCommandControllerId = 0;
|
|
|
|
mDocStateControllerId = 0;
|
|
|
|
mHTMLCommandControllerId = 0;
|
|
|
|
}
|
|
|
|
|
2016-01-30 20:05:36 +03:00
|
|
|
void nsEditingSession::RemoveWebProgressListener(nsPIDOMWindowOuter* aWindow) {
|
|
|
|
nsIDocShell* docShell = aWindow ? aWindow->GetDocShell() : nullptr;
|
2008-04-24 01:36:17 +04:00
|
|
|
nsCOMPtr<nsIWebProgress> webProgress = do_GetInterface(docShell);
|
2016-10-24 05:27:45 +03:00
|
|
|
if (webProgress) {
|
2008-04-24 01:36:17 +04:00
|
|
|
webProgress->RemoveProgressListener(this);
|
2011-10-17 18:59:28 +04:00
|
|
|
mProgressListenerRegistered = false;
|
2008-04-24 01:36:17 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-01-30 20:05:36 +03:00
|
|
|
void nsEditingSession::RestoreAnimationMode(nsPIDOMWindowOuter* aWindow) {
|
2016-10-24 05:27:45 +03:00
|
|
|
if (mInteractive) {
|
|
|
|
return;
|
2008-04-24 01:36:17 +04:00
|
|
|
}
|
2016-10-24 05:27:45 +03:00
|
|
|
|
|
|
|
nsCOMPtr<nsIDocShell> docShell = aWindow ? aWindow->GetDocShell() : nullptr;
|
|
|
|
NS_ENSURE_TRUE_VOID(docShell);
|
|
|
|
nsCOMPtr<nsIPresShell> presShell = docShell->GetPresShell();
|
|
|
|
NS_ENSURE_TRUE_VOID(presShell);
|
|
|
|
nsPresContext* presContext = presShell->GetPresContext();
|
|
|
|
NS_ENSURE_TRUE_VOID(presContext);
|
|
|
|
|
|
|
|
presContext->SetImageAnimationMode(mImageAnimationMode);
|
2008-04-24 01:36:17 +04:00
|
|
|
}
|
|
|
|
|
2016-01-30 20:05:36 +03:00
|
|
|
nsresult nsEditingSession::DetachFromWindow(mozIDOMWindowProxy* aWindow) {
|
2010-06-18 00:40:48 +04:00
|
|
|
NS_ENSURE_TRUE(mDoneSetup, NS_OK);
|
2008-05-01 13:00:11 +04:00
|
|
|
|
2018-01-26 08:38:05 +03:00
|
|
|
NS_ASSERTION(mComposerCommandsUpdater,
|
|
|
|
"mComposerCommandsUpdater should exist.");
|
2008-04-24 01:36:17 +04:00
|
|
|
|
|
|
|
// Kill any existing reload timer
|
2016-10-24 05:27:45 +03:00
|
|
|
if (mLoadBlankDocTimer) {
|
2008-04-24 01:36:17 +04:00
|
|
|
mLoadBlankDocTimer->Cancel();
|
2012-07-30 18:20:58 +04:00
|
|
|
mLoadBlankDocTimer = nullptr;
|
2008-04-24 01:36:17 +04:00
|
|
|
}
|
|
|
|
|
2016-01-30 20:05:36 +03:00
|
|
|
auto* window = nsPIDOMWindowOuter::From(aWindow);
|
|
|
|
|
2008-04-24 01:36:17 +04:00
|
|
|
// Remove controllers, webprogress listener, and otherwise
|
|
|
|
// make things the way they were before we started editing.
|
2016-01-30 20:05:36 +03:00
|
|
|
RemoveEditorControllers(window);
|
|
|
|
RemoveWebProgressListener(window);
|
2008-04-24 01:36:17 +04:00
|
|
|
RestoreJSAndPlugins(aWindow);
|
2016-01-30 20:05:36 +03:00
|
|
|
RestoreAnimationMode(window);
|
2008-04-24 01:36:17 +04:00
|
|
|
|
|
|
|
// Kill our weak reference to our original window, in case
|
|
|
|
// it changes on restore, or otherwise dies.
|
2012-07-30 18:20:58 +04:00
|
|
|
mDocShell = nullptr;
|
2008-04-24 01:36:17 +04:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2016-01-30 20:05:36 +03:00
|
|
|
nsresult nsEditingSession::ReattachToWindow(mozIDOMWindowProxy* aWindow) {
|
2010-06-18 00:40:48 +04:00
|
|
|
NS_ENSURE_TRUE(mDoneSetup, NS_OK);
|
2016-01-30 20:05:36 +03:00
|
|
|
NS_ENSURE_TRUE(aWindow, NS_ERROR_FAILURE);
|
2008-05-01 13:00:11 +04:00
|
|
|
|
2018-01-26 08:38:05 +03:00
|
|
|
NS_ASSERTION(mComposerCommandsUpdater,
|
|
|
|
"mComposerCommandsUpdater should exist.");
|
2008-04-24 01:36:17 +04:00
|
|
|
|
|
|
|
// Imitate nsEditorDocShell::MakeEditable() to reattach the
|
|
|
|
// old editor ot the window.
|
|
|
|
nsresult rv;
|
|
|
|
|
2016-01-30 20:05:36 +03:00
|
|
|
auto* window = nsPIDOMWindowOuter::From(aWindow);
|
|
|
|
nsIDocShell* docShell = window->GetDocShell();
|
2010-10-15 21:59:00 +04:00
|
|
|
NS_ENSURE_TRUE(docShell, NS_ERROR_FAILURE);
|
|
|
|
mDocShell = do_GetWeakReference(docShell);
|
2008-04-24 01:36:17 +04:00
|
|
|
|
|
|
|
// Disable plugins.
|
2016-10-24 05:27:45 +03:00
|
|
|
if (!mInteractive) {
|
2008-04-24 01:36:17 +04:00
|
|
|
rv = DisableJSAndPlugins(aWindow);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Tells embedder that startup is in progress.
|
|
|
|
mEditorStatus = eEditorCreationInProgress;
|
|
|
|
|
|
|
|
// Adds back web progress listener.
|
2016-01-30 20:05:36 +03:00
|
|
|
rv = PrepareForEditing(window);
|
2008-04-24 01:36:17 +04:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
// Setup the command controllers again.
|
2018-09-07 16:39:36 +03:00
|
|
|
rv = SetupEditorCommandController(
|
|
|
|
nsBaseCommandController::CreateEditingController, aWindow,
|
2008-04-24 01:36:17 +04:00
|
|
|
static_cast<nsIEditingSession*>(this), &mBaseCommandControllerId);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2018-09-08 19:06:48 +03:00
|
|
|
rv = SetupEditorCommandController(
|
|
|
|
nsBaseCommandController::CreateHTMLEditorDocStateController, aWindow,
|
2008-04-24 01:36:17 +04:00
|
|
|
static_cast<nsIEditingSession*>(this), &mDocStateControllerId);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2018-01-26 08:38:05 +03:00
|
|
|
if (mComposerCommandsUpdater) {
|
|
|
|
mComposerCommandsUpdater->Init(window);
|
2016-10-24 05:27:45 +03:00
|
|
|
}
|
2008-04-24 01:36:17 +04:00
|
|
|
|
|
|
|
// Get editor
|
2017-08-04 16:53:28 +03:00
|
|
|
RefPtr<HTMLEditor> htmlEditor = GetHTMLEditorForWindow(aWindow);
|
|
|
|
if (NS_WARN_IF(!htmlEditor)) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
2008-04-24 01:36:17 +04:00
|
|
|
|
2016-10-24 05:27:45 +03:00
|
|
|
if (!mInteractive) {
|
2008-04-24 01:36:17 +04:00
|
|
|
// Disable animation of images in this document:
|
2014-09-26 17:19:56 +04:00
|
|
|
nsCOMPtr<nsIPresShell> presShell = docShell->GetPresShell();
|
|
|
|
NS_ENSURE_TRUE(presShell, NS_ERROR_FAILURE);
|
|
|
|
nsPresContext* presContext = presShell->GetPresContext();
|
|
|
|
NS_ENSURE_TRUE(presContext, NS_ERROR_FAILURE);
|
2008-04-24 01:36:17 +04:00
|
|
|
|
2014-09-26 17:19:56 +04:00
|
|
|
mImageAnimationMode = presContext->ImageAnimationMode();
|
|
|
|
presContext->SetImageAnimationMode(imgIContainer::kDontAnimMode);
|
2008-04-24 01:36:17 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
// The third controller takes an nsIEditor as the context
|
2018-09-08 08:35:56 +03:00
|
|
|
rv = SetupEditorCommandController(
|
|
|
|
nsBaseCommandController::CreateHTMLEditorController, aWindow,
|
2017-08-04 16:53:28 +03:00
|
|
|
static_cast<nsIEditor*>(htmlEditor.get()), &mHTMLCommandControllerId);
|
2008-04-24 01:36:17 +04:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
// Set context on all controllers to be the editor
|
2017-08-04 16:53:28 +03:00
|
|
|
rv = SetEditorOnControllers(aWindow, htmlEditor);
|
2008-04-24 01:36:17 +04:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
{
|
2011-09-29 10:19:26 +04:00
|
|
|
bool isEditable;
|
2008-04-24 01:36:17 +04:00
|
|
|
rv = WindowIsEditable(aWindow, &isEditable);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
NS_ASSERTION(isEditable,
|
|
|
|
"Window is not editable after reattaching editor.");
|
|
|
|
}
|
|
|
|
#endif // DEBUG
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2017-08-12 05:44:16 +03:00
|
|
|
|
|
|
|
HTMLEditor* nsIEditingSession::GetHTMLEditorForWindow(
|
|
|
|
mozIDOMWindowProxy* aWindow) {
|
|
|
|
if (NS_WARN_IF(!aWindow)) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCOMPtr<nsIDocShell> docShell =
|
|
|
|
nsPIDOMWindowOuter::From(aWindow)->GetDocShell();
|
|
|
|
if (NS_WARN_IF(!docShell)) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
return docShell->GetHTMLEditor();
|
|
|
|
}
|