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
|
|
|
|
#include "mozFlushType.h" // for mozFlushType::Flush_Frames
|
|
|
|
#include "mozilla/mozalloc.h" // for operator new
|
|
|
|
#include "nsAString.h"
|
|
|
|
#include "nsComponentManagerUtils.h" // for do_CreateInstance
|
|
|
|
#include "nsComposerCommandsUpdater.h" // for nsComposerCommandsUpdater
|
|
|
|
#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
|
|
|
|
#include "nsIDOMDocument.h" // for nsIDOMDocument
|
|
|
|
#include "nsIDOMHTMLDocument.h" // for nsIDOMHTMLDocument
|
|
|
|
#include "nsIDOMWindow.h" // for nsIDOMWindow
|
|
|
|
#include "nsIDocShell.h" // for nsIDocShell
|
|
|
|
#include "nsIDocument.h" // for nsIDocument
|
|
|
|
#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 "nsISelection.h" // for nsISelection
|
|
|
|
#include "nsISelectionPrivate.h" // for nsISelectionPrivate
|
|
|
|
#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
|
|
|
|
#include "nsStringFwd.h" // for nsAFlatString
|
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
|
|
|
|
|
|
|
/*---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2014-04-27 11:06:00 +04:00
|
|
|
NS_IMPL_ISUPPORTS(nsEditingSession, nsIEditingSession, nsIWebProgressListener,
|
|
|
|
nsISupportsWeakReference)
|
2002-01-30 07:46:54 +03:00
|
|
|
|
|
|
|
/*---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
MakeWindowEditable
|
|
|
|
|
2002-10-09 06:10:22 +04:00
|
|
|
aEditorType string, "html" "htmlsimple" "text" "textsimple"
|
2002-11-13 02:03:27 +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
|
2002-11-13 02:03:27 +03:00
|
|
|
nsEditingSession::MakeWindowEditable(nsIDOMWindow *aWindow,
|
|
|
|
const char *aEditorType,
|
2011-09-29 10:19:26 +04:00
|
|
|
bool aDoAfterUriLoad,
|
|
|
|
bool aMakeWholeDocumentEditable,
|
|
|
|
bool aInteractive)
|
2002-01-30 07:46:54 +03:00
|
|
|
{
|
2002-11-13 02:03:27 +03:00
|
|
|
mEditorType.Truncate();
|
2002-10-09 06:10:22 +04:00
|
|
|
mEditorFlags = 0;
|
|
|
|
|
2003-01-10 16:13:25 +03:00
|
|
|
// disable plugins
|
2013-02-14 02:39:30 +04:00
|
|
|
nsCOMPtr<nsIDocShell> docShell = GetDocShellFromWindow(aWindow);
|
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);
|
2002-11-20 09:23:05 +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
|
|
|
|
2003-02-27 17:06:29 +03:00
|
|
|
// if all this does is setup listeners and I don't need listeners,
|
|
|
|
// can't this step be ignored?? (based on aDoAfterURILoad)
|
2005-02-24 00:27:20 +03:00
|
|
|
rv = PrepareForEditing(aWindow);
|
2010-06-17 23:27:24 +04: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);
|
2010-06-17 23:27:24 +04: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
|
|
|
|
rv = SetupEditorCommandController("@mozilla.org/editor/editingcontroller;1",
|
2002-11-13 02:03:27 +03:00
|
|
|
aWindow,
|
2007-07-08 11:08:04 +04:00
|
|
|
static_cast<nsIEditingSession*>(this),
|
2002-11-13 02:03:27 +03:00
|
|
|
&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"
|
|
|
|
rv = SetupEditorCommandController("@mozilla.org/editor/editordocstatecontroller;1",
|
|
|
|
aWindow,
|
2007-07-08 11:08:04 +04:00
|
|
|
static_cast<nsIEditingSession*>(this),
|
2002-11-13 02:03:27 +03:00
|
|
|
&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
|
|
|
|
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
|
|
|
|
if (NS_FAILED(rv))
|
2007-11-12 17:47:03 +03:00
|
|
|
TearDownEditorOnWindow(aWindow);
|
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
|
|
|
|
nsEditingSession::DisableJSAndPlugins(nsIDOMWindow *aWindow)
|
|
|
|
{
|
|
|
|
nsIDocShell *docShell = GetDocShellFromWindow(aWindow);
|
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
|
|
|
|
nsEditingSession::RestoreJSAndPlugins(nsIDOMWindow *aWindow)
|
|
|
|
{
|
2010-06-18 00:40:48 +04:00
|
|
|
NS_ENSURE_TRUE(mDisabledJSAndPlugins, 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
|
|
|
|
|
|
|
nsIDocShell *docShell = GetDocShellFromWindow(aWindow);
|
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
|
2011-09-29 10:19:26 +04:00
|
|
|
nsEditingSession::WindowIsEditable(nsIDOMWindow *aWindow, bool *outIsEditable)
|
2002-01-30 07:46:54 +03:00
|
|
|
{
|
2013-02-14 02:39:30 +04:00
|
|
|
nsCOMPtr<nsIDocShell> docShell = GetDocShellFromWindow(aWindow);
|
|
|
|
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
|
|
|
|
// the network channel for these and "text/xml" to "text/plain",
|
|
|
|
// 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
|
|
|
};
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool
|
2002-11-13 02:03:27 +03:00
|
|
|
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
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t i = 0;
|
2002-11-13 02:03:27 +03:00
|
|
|
while (gSupportedTextTypes[i])
|
|
|
|
{
|
|
|
|
if (strcmp(gSupportedTextTypes[i], aMIMEType) == 0)
|
|
|
|
{
|
2011-10-17 18:59:28 +04:00
|
|
|
return true;
|
2002-11-13 02:03:27 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
i ++;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
nsEditingSession::SetupEditorOnWindow(nsIDOMWindow *aWindow)
|
|
|
|
{
|
2011-10-17 18:59:28 +04:00
|
|
|
mDoneSetup = true;
|
2007-02-13 12:26:09 +03:00
|
|
|
|
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
|
|
|
|
nsCOMPtr<nsIDOMDocument> doc;
|
2012-09-02 06:35:17 +04:00
|
|
|
nsAutoCString mimeCType;
|
2002-11-13 02:03:27 +03:00
|
|
|
|
|
|
|
//then lets check the mime type
|
|
|
|
if (NS_SUCCEEDED(aWindow->GetDocument(getter_AddRefs(doc))) && doc)
|
|
|
|
{
|
2011-05-28 11:43:53 +04:00
|
|
|
nsAutoString mimeType;
|
|
|
|
if (NS_SUCCEEDED(doc->GetContentType(mimeType)))
|
|
|
|
AppendUTF16toUTF8(mimeType, mimeCType);
|
|
|
|
|
|
|
|
if (IsSupportedTextType(mimeCType.get()))
|
2002-11-13 02:03:27 +03:00
|
|
|
{
|
2011-05-28 11:43:53 +04:00
|
|
|
mEditorType.AssignLiteral("text");
|
|
|
|
mimeCType = "text/plain";
|
|
|
|
}
|
|
|
|
else if (!mimeCType.EqualsLiteral("text/html") &&
|
|
|
|
!mimeCType.EqualsLiteral("application/xhtml+xml"))
|
|
|
|
{
|
|
|
|
// 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.
|
2011-05-28 11:43:53 +04:00
|
|
|
nsCOMPtr<nsIDocument> document = do_QueryInterface(doc);
|
2006-08-16 06:41:47 +04:00
|
|
|
if (document) {
|
|
|
|
document->FlushPendingNotifications(Flush_Frames);
|
2007-07-06 14:45:16 +04:00
|
|
|
if (mMakeWholeDocumentEditable) {
|
2011-10-17 18:59:28 +04:00
|
|
|
document->SetEditableFlag(true);
|
2011-07-15 16:17:56 +04:00
|
|
|
nsCOMPtr<nsIHTMLDocument> htmlDocument = do_QueryInterface(document);
|
|
|
|
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
|
|
|
|
|
|
|
const char *classString = "@mozilla.org/editor/htmleditor;1";
|
2004-05-23 02:15:22 +04:00
|
|
|
if (mEditorType.EqualsLiteral("textmail"))
|
2002-11-13 02:03:27 +03:00
|
|
|
{
|
|
|
|
mEditorFlags = nsIPlaintextEditor::eEditorPlaintextMask |
|
|
|
|
nsIPlaintextEditor::eEditorEnableWrapHackMask |
|
|
|
|
nsIPlaintextEditor::eEditorMailMask;
|
|
|
|
}
|
2004-05-23 02:15:22 +04:00
|
|
|
else if (mEditorType.EqualsLiteral("text"))
|
2002-11-13 02:03:27 +03:00
|
|
|
{
|
|
|
|
mEditorFlags = nsIPlaintextEditor::eEditorPlaintextMask |
|
|
|
|
nsIPlaintextEditor::eEditorEnableWrapHackMask;
|
|
|
|
}
|
2004-05-23 02:15:22 +04:00
|
|
|
else if (mEditorType.EqualsLiteral("htmlmail"))
|
2002-11-13 02:03:27 +03:00
|
|
|
{
|
2004-05-23 02:15:22 +04:00
|
|
|
if (mimeCType.EqualsLiteral("text/html"))
|
2002-11-13 02:03:27 +03:00
|
|
|
{
|
2011-10-17 18:59:28 +04:00
|
|
|
needHTMLController = true;
|
2002-11-13 02:03:27 +03:00
|
|
|
mEditorFlags = nsIPlaintextEditor::eEditorMailMask;
|
|
|
|
}
|
|
|
|
else //set the flags back to textplain.
|
|
|
|
mEditorFlags = nsIPlaintextEditor::eEditorPlaintextMask |
|
|
|
|
nsIPlaintextEditor::eEditorEnableWrapHackMask;
|
|
|
|
}
|
|
|
|
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
|
2008-04-24 01:36:17 +04:00
|
|
|
mStateMaintainer = new nsComposerCommandsUpdater();
|
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
|
2008-04-24 01:36:17 +04:00
|
|
|
rv = mStateMaintainer->Init(aWindow);
|
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
|
|
|
if (mEditorStatus != eEditorCreationInProgress)
|
|
|
|
{
|
2008-04-24 01:36:17 +04:00
|
|
|
mStateMaintainer->NotifyDocumentCreated();
|
2002-11-13 02:03:27 +03:00
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Create editor and do other things
|
|
|
|
// only if we haven't found some error above,
|
2013-02-14 02:39:30 +04:00
|
|
|
nsCOMPtr<nsIDocShell> docShell = GetDocShellFromWindow(aWindow);
|
2010-06-17 23:41:16 +04:00
|
|
|
NS_ENSURE_TRUE(docShell, 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
|
|
|
nsCOMPtr<nsIPresShell> presShell = docShell->GetPresShell();
|
|
|
|
NS_ENSURE_TRUE(presShell, NS_ERROR_FAILURE);
|
|
|
|
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
|
|
|
|
|
|
|
// create and set editor
|
2010-11-19 00:01:12 +03:00
|
|
|
// Try to reuse an existing editor
|
|
|
|
nsCOMPtr<nsIEditor> editor = do_QueryReferent(mExistingEditor);
|
2011-03-01 00:04:05 +03:00
|
|
|
if (editor) {
|
2011-10-17 18:59:28 +04:00
|
|
|
editor->PreDestroy(false);
|
2011-03-01 00:04:05 +03:00
|
|
|
} else {
|
2010-11-19 00:01:12 +03:00
|
|
|
editor = do_CreateInstance(classString, &rv);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
mExistingEditor = do_GetWeakReference(editor);
|
|
|
|
}
|
2002-01-30 07:46:54 +03:00
|
|
|
// set the editor on the docShell. The docShell now owns it.
|
2013-02-14 02:39:30 +04:00
|
|
|
rv = docShell->SetEditor(editor);
|
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
|
|
|
|
if (needHTMLController)
|
|
|
|
{
|
2003-04-10 22:44:03 +04:00
|
|
|
// The third controller takes an nsIEditor as the context
|
2002-11-13 02:03:27 +03:00
|
|
|
rv = SetupEditorCommandController("@mozilla.org/editor/htmleditorcontroller;1",
|
|
|
|
aWindow, editor,
|
|
|
|
&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
|
|
|
|
rv = editor->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
|
|
|
|
2002-01-30 07:46:54 +03:00
|
|
|
nsCOMPtr<nsIDOMDocument> domDoc;
|
|
|
|
rv = contentViewer->GetDOMDocument(getter_AddRefs(domDoc));
|
2010-06-17 23:27:24 +04:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2010-06-17 23:41:16 +04:00
|
|
|
NS_ENSURE_TRUE(domDoc, 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
|
2008-04-24 01:36:17 +04:00
|
|
|
rv = editor->AddDocumentStateListener(mStateMaintainer);
|
2010-06-17 23:27:24 +04:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2002-01-30 07:46:54 +03:00
|
|
|
|
2012-07-30 18:20:58 +04:00
|
|
|
rv = editor->Init(domDoc, nullptr /* root content */,
|
2014-04-14 16:33:47 +04:00
|
|
|
nullptr, mEditorFlags, EmptyString());
|
2010-06-17 23:27:24 +04:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2002-01-30 07:46:54 +03:00
|
|
|
|
2005-02-24 00:27:20 +03:00
|
|
|
nsCOMPtr<nsISelection> selection;
|
|
|
|
editor->GetSelection(getter_AddRefs(selection));
|
2002-01-30 07:46:54 +03:00
|
|
|
nsCOMPtr<nsISelectionPrivate> selPriv = do_QueryInterface(selection);
|
2010-06-17 23:41:16 +04:00
|
|
|
NS_ENSURE_TRUE(selPriv, NS_ERROR_FAILURE);
|
2002-01-30 07:46:54 +03:00
|
|
|
|
2008-04-24 01:36:17 +04:00
|
|
|
rv = selPriv->AddSelectionListener(mStateMaintainer);
|
2010-06-17 23:27:24 +04:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2002-01-30 07:46:54 +03:00
|
|
|
|
|
|
|
// and as a transaction listener
|
|
|
|
nsCOMPtr<nsITransactionManager> txnMgr;
|
|
|
|
editor->GetTransactionManager(getter_AddRefs(txnMgr));
|
|
|
|
if (txnMgr)
|
2008-04-24 01:36:17 +04:00
|
|
|
txnMgr->AddListener(mStateMaintainer);
|
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
|
2002-11-13 02:03:27 +03:00
|
|
|
rv = SetEditorOnControllers(aWindow, editor);
|
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
|
|
|
|
return editor->PostCreate();
|
|
|
|
}
|
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.
|
|
|
|
void
|
|
|
|
nsEditingSession::RemoveListenersAndControllers(nsIDOMWindow *aWindow,
|
|
|
|
nsIEditor *aEditor)
|
|
|
|
{
|
|
|
|
if (!mStateMaintainer || !aEditor)
|
|
|
|
return;
|
|
|
|
|
|
|
|
// Remove all the listeners
|
|
|
|
nsCOMPtr<nsISelection> selection;
|
|
|
|
aEditor->GetSelection(getter_AddRefs(selection));
|
|
|
|
nsCOMPtr<nsISelectionPrivate> selPriv = do_QueryInterface(selection);
|
|
|
|
if (selPriv)
|
|
|
|
selPriv->RemoveSelectionListener(mStateMaintainer);
|
|
|
|
|
|
|
|
aEditor->RemoveDocumentStateListener(mStateMaintainer);
|
|
|
|
|
|
|
|
nsCOMPtr<nsITransactionManager> txnMgr;
|
|
|
|
aEditor->GetTransactionManager(getter_AddRefs(txnMgr));
|
|
|
|
if (txnMgr)
|
|
|
|
txnMgr->RemoveListener(mStateMaintainer);
|
|
|
|
|
|
|
|
// 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
|
2007-11-12 17:47:03 +03:00
|
|
|
nsEditingSession::TearDownEditorOnWindow(nsIDOMWindow *aWindow)
|
2002-01-30 07:46:54 +03:00
|
|
|
{
|
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
|
|
|
|
2002-01-30 07:46:54 +03:00
|
|
|
nsresult rv;
|
2003-02-14 17:56:32 +03:00
|
|
|
|
2005-02-24 00:27:20 +03:00
|
|
|
// Kill any existing reload timer
|
|
|
|
if (mLoadBlankDocTimer)
|
|
|
|
{
|
|
|
|
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).
|
|
|
|
nsCOMPtr<nsIDOMDocument> domDoc;
|
|
|
|
aWindow->GetDocument(getter_AddRefs(domDoc));
|
|
|
|
nsCOMPtr<nsIHTMLDocument> htmlDoc = do_QueryInterface(domDoc);
|
2011-09-29 10:19:26 +04:00
|
|
|
bool stopEditing = htmlDoc && htmlDoc->IsEditingOn();
|
2008-04-24 01:36:17 +04:00
|
|
|
if (stopEditing)
|
|
|
|
RemoveWebProgressListener(aWindow);
|
2002-11-20 09:23:05 +03:00
|
|
|
|
2013-02-14 02:39:30 +04:00
|
|
|
nsCOMPtr<nsIDocShell> docShell = GetDocShellFromWindow(aWindow);
|
|
|
|
NS_ENSURE_STATE(docShell);
|
2003-01-22 03:46:38 +03:00
|
|
|
|
|
|
|
nsCOMPtr<nsIEditor> editor;
|
2013-02-14 02:39:30 +04:00
|
|
|
rv = docShell->GetEditor(getter_AddRefs(editor));
|
2005-02-24 00:27:20 +03:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2003-01-22 03:46:38 +03:00
|
|
|
|
2008-04-18 06:07:05 +04:00
|
|
|
if (stopEditing)
|
|
|
|
htmlDoc->TearingDownEditor(editor);
|
2008-02-20 12:54:52 +03:00
|
|
|
|
2004-02-11 18:40:34 +03:00
|
|
|
if (mStateMaintainer && editor)
|
|
|
|
{
|
2008-04-24 01:36:17 +04:00
|
|
|
// Null out the editor on the controllers first to prevent their weak
|
|
|
|
// 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
|
|
|
|
2008-04-24 01:36:17 +04:00
|
|
|
RemoveListenersAndControllers(aWindow, editor);
|
2005-02-24 00:27:20 +03:00
|
|
|
|
2008-04-24 01:36:17 +04:00
|
|
|
if (stopEditing)
|
|
|
|
{
|
|
|
|
// Make things the way they were before we started editing.
|
|
|
|
RestoreJSAndPlugins(aWindow);
|
|
|
|
RestoreAnimationMode(aWindow);
|
2005-02-25 01:52:03 +03:00
|
|
|
|
2008-04-24 01:36:17 +04:00
|
|
|
if (mMakeWholeDocumentEditable)
|
|
|
|
{
|
2007-07-06 14:45:16 +04:00
|
|
|
nsCOMPtr<nsIDocument> doc = do_QueryInterface(domDoc, &rv);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-01-22 03:46:38 +03:00
|
|
|
return rv;
|
2002-01-30 07:46:54 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/*---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
GetEditorForFrame
|
|
|
|
|
|
|
|
nsIEditor getEditorForFrame (in nsIDOMWindow aWindow);
|
|
|
|
----------------------------------------------------------------------------*/
|
|
|
|
NS_IMETHODIMP
|
2002-11-13 02:03:27 +03:00
|
|
|
nsEditingSession::GetEditorForWindow(nsIDOMWindow *aWindow,
|
|
|
|
nsIEditor **outEditor)
|
2002-01-30 07:46:54 +03:00
|
|
|
{
|
2013-02-14 02:39:30 +04:00
|
|
|
nsCOMPtr<nsIDocShell> docShell = GetDocShellFromWindow(aWindow);
|
|
|
|
NS_ENSURE_STATE(aWindow);
|
2002-01-30 07:46:54 +03:00
|
|
|
|
2013-02-14 02:39:30 +04:00
|
|
|
return docShell->GetEditor(outEditor);
|
2002-01-30 07:46:54 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/*---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
OnStateChange
|
|
|
|
|
|
|
|
----------------------------------------------------------------------------*/
|
|
|
|
NS_IMETHODIMP
|
2002-11-13 02:03:27 +03:00
|
|
|
nsEditingSession::OnStateChange(nsIWebProgress *aWebProgress,
|
|
|
|
nsIRequest *aRequest,
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t aStateFlags, nsresult aStatus)
|
2002-01-30 07:46:54 +03:00
|
|
|
{
|
2002-11-13 02:03:27 +03:00
|
|
|
|
|
|
|
#ifdef NOISY_DOC_LOADING
|
|
|
|
nsCOMPtr<nsIChannel> channel(do_QueryInterface(aRequest));
|
|
|
|
if (channel)
|
|
|
|
{
|
2012-09-02 06:35:17 +04:00
|
|
|
nsAutoCString contentType;
|
2002-11-13 02:03:27 +03:00
|
|
|
channel->GetContentType(contentType);
|
|
|
|
if (!contentType.IsEmpty())
|
2003-02-27 17:06:29 +03:00
|
|
|
printf(" ++++++ MIMETYPE = %s\n", contentType.get());
|
2002-11-13 02:03:27 +03:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2002-01-30 07:46:54 +03:00
|
|
|
//
|
|
|
|
// A Request has started...
|
|
|
|
//
|
|
|
|
if (aStateFlags & nsIWebProgressListener::STATE_START)
|
|
|
|
{
|
2002-11-13 02:03:27 +03:00
|
|
|
#ifdef NOISY_DOC_LOADING
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIChannel> channel(do_QueryInterface(aRequest));
|
|
|
|
if (channel)
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIURI> uri;
|
|
|
|
channel->GetURI(getter_AddRefs(uri));
|
|
|
|
if (uri)
|
|
|
|
{
|
|
|
|
nsXPIDLCString spec;
|
|
|
|
uri->GetSpec(spec);
|
2003-02-14 17:56:32 +03:00
|
|
|
printf(" **** STATE_START: CHANNEL URI=%s, flags=%x\n",
|
|
|
|
spec.get(), aStateFlags);
|
2002-11-13 02:03:27 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
printf(" STATE_START: NO CHANNEL flags=%x\n", aStateFlags);
|
|
|
|
}
|
|
|
|
#endif
|
2002-01-30 07:46:54 +03:00
|
|
|
// Page level notification...
|
|
|
|
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);
|
|
|
|
|
2006-08-01 03:05:37 +04:00
|
|
|
if (progressIsForTargetDocument)
|
|
|
|
{
|
2005-04-06 06:22:45 +04:00
|
|
|
nsCOMPtr<nsIDOMWindow> window;
|
|
|
|
aWebProgress->GetDOMWindow(getter_AddRefs(window));
|
|
|
|
|
|
|
|
nsCOMPtr<nsIDOMDocument> doc;
|
|
|
|
window->GetDocument(getter_AddRefs(doc));
|
|
|
|
|
|
|
|
nsCOMPtr<nsIHTMLDocument> htmlDoc(do_QueryInterface(doc));
|
|
|
|
|
2006-08-01 03:05:37 +04:00
|
|
|
if (htmlDoc && htmlDoc->IsWriting())
|
|
|
|
{
|
2011-05-28 11:43:57 +04:00
|
|
|
nsCOMPtr<nsIDOMHTMLDocument> htmlDomDoc = do_QueryInterface(doc);
|
2005-04-06 06:22:45 +04:00
|
|
|
nsAutoString designMode;
|
|
|
|
htmlDomDoc->GetDesignMode(designMode);
|
|
|
|
|
2006-08-01 03:05:37 +04: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
|
|
|
|
//
|
|
|
|
else if (aStateFlags & nsIWebProgressListener::STATE_TRANSFERRING)
|
|
|
|
{
|
2006-08-01 03:05:37 +04:00
|
|
|
if (aStateFlags & nsIWebProgressListener::STATE_IS_DOCUMENT)
|
2002-01-30 07:46:54 +03:00
|
|
|
{
|
|
|
|
// document transfer started
|
|
|
|
}
|
|
|
|
}
|
|
|
|
//
|
|
|
|
// Got a redirection
|
|
|
|
//
|
|
|
|
else if (aStateFlags & nsIWebProgressListener::STATE_REDIRECTING)
|
|
|
|
{
|
2006-08-01 03:05:37 +04:00
|
|
|
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
|
|
|
//
|
|
|
|
else if (aStateFlags & nsIWebProgressListener::STATE_STOP)
|
|
|
|
{
|
|
|
|
|
2002-11-13 02:03:27 +03:00
|
|
|
#ifdef NOISY_DOC_LOADING
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIChannel> channel(do_QueryInterface(aRequest));
|
|
|
|
if (channel)
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIURI> uri;
|
|
|
|
channel->GetURI(getter_AddRefs(uri));
|
|
|
|
if (uri)
|
|
|
|
{
|
|
|
|
nsXPIDLCString spec;
|
|
|
|
uri->GetSpec(spec);
|
2003-02-14 17:56:32 +03:00
|
|
|
printf(" **** STATE_STOP: CHANNEL URI=%s, flags=%x\n",
|
|
|
|
spec.get(), aStateFlags);
|
2002-11-13 02:03:27 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
printf(" STATE_STOP: NO CHANNEL flags=%x\n", aStateFlags);
|
|
|
|
}
|
|
|
|
#endif
|
2003-02-27 17:06:29 +03:00
|
|
|
|
2002-01-30 07:46:54 +03:00
|
|
|
// Document level notification...
|
|
|
|
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...
|
|
|
|
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)
|
2002-01-30 07:46:54 +03:00
|
|
|
{
|
2002-05-17 00:57:37 +04:00
|
|
|
NS_NOTREACHED("notification excluded in AddProgressListener(...)");
|
2002-01-30 07:46:54 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
OnLocationChange
|
|
|
|
|
|
|
|
----------------------------------------------------------------------------*/
|
|
|
|
NS_IMETHODIMP
|
2002-11-13 02:03:27 +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)
|
2002-01-30 07:46:54 +03:00
|
|
|
{
|
2002-11-27 03:35:09 +03:00
|
|
|
nsCOMPtr<nsIDOMWindow> domWindow;
|
|
|
|
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
|
|
|
|
|
|
|
nsCOMPtr<nsIDOMDocument> domDoc;
|
|
|
|
rv = domWindow->GetDocument(getter_AddRefs(domDoc));
|
2010-06-17 23:27:24 +04:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2002-11-27 03:35:09 +03:00
|
|
|
|
|
|
|
nsCOMPtr<nsIDocument> doc = do_QueryInterface(domDoc);
|
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
|
2004-02-10 01:48:53 +03:00
|
|
|
nsIDocShell *docShell = GetDocShellFromWindow(domWindow);
|
2010-06-17 23:41:16 +04:00
|
|
|
NS_ENSURE_TRUE(docShell, NS_ERROR_FAILURE);
|
2002-11-27 03:35:09 +03:00
|
|
|
|
|
|
|
nsCOMPtr<nsICommandManager> commandManager = do_GetInterface(docShell);
|
|
|
|
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)
|
2002-01-30 07:46:54 +03:00
|
|
|
{
|
2002-05-17 00:57:37 +04:00
|
|
|
NS_NOTREACHED("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,
|
2012-08-22 19:56:38 +04:00
|
|
|
nsIRequest *aRequest, uint32_t state)
|
2002-01-30 07:46:54 +03:00
|
|
|
{
|
2002-05-17 00:57:37 +04:00
|
|
|
NS_NOTREACHED("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
|
|
|
----------------------------------------------------------------------------*/
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool
|
2003-02-27 17:06:29 +03:00
|
|
|
nsEditingSession::IsProgressForTargetDocument(nsIWebProgress *aWebProgress)
|
2002-01-30 07:46:54 +03:00
|
|
|
{
|
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
|
|
|
|
|
|
|
|
Called during GetCommandStateParams("obs_documentCreated"...)
|
|
|
|
to determine if editor was created and document
|
|
|
|
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
|
|
|
|
----------------------------------------------------------------------------*/
|
|
|
|
nsresult
|
2003-02-27 17:06:29 +03:00
|
|
|
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);
|
2002-01-30 07:46:54 +03:00
|
|
|
|
|
|
|
// If we have an editor here, then we got a reload after making the editor.
|
|
|
|
// We need to blow it away and make a new one at the end of the load.
|
|
|
|
nsCOMPtr<nsIDOMWindow> domWindow;
|
|
|
|
aWebProgress->GetDOMWindow(getter_AddRefs(domWindow));
|
|
|
|
if (domWindow)
|
|
|
|
{
|
2008-04-24 01:36:17 +04:00
|
|
|
nsIDocShell *docShell = GetDocShellFromWindow(domWindow);
|
2010-06-17 23:41:16 +04:00
|
|
|
NS_ENSURE_TRUE(docShell, NS_ERROR_FAILURE);
|
2008-04-24 01:36:17 +04:00
|
|
|
docShell->DetachEditorFromWindow();
|
2002-01-30 07:46:54 +03:00
|
|
|
}
|
|
|
|
|
2003-02-27 17:06:29 +03:00
|
|
|
if (aIsToBeMadeEditable)
|
|
|
|
mEditorStatus = eEditorCreationInProgress;
|
|
|
|
|
2002-01-30 07:46:54 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
EndDocumentLoad
|
|
|
|
|
|
|
|
Called on end of load in a single frame
|
|
|
|
----------------------------------------------------------------------------*/
|
|
|
|
nsresult
|
2002-11-13 02:03:27 +03:00
|
|
|
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-01-30 07:46:54 +03:00
|
|
|
{
|
2002-11-13 02:03:27 +03:00
|
|
|
NS_ENSURE_ARG_POINTER(aWebProgress);
|
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;
|
|
|
|
nsXPIDLCString spec;
|
|
|
|
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).
|
2002-01-30 07:46:54 +03:00
|
|
|
|
|
|
|
// OK, time to make an editor on this document
|
|
|
|
nsCOMPtr<nsIDOMWindow> domWindow;
|
|
|
|
aWebProgress->GetDOMWindow(getter_AddRefs(domWindow));
|
|
|
|
|
2002-11-13 02:03:27 +03:00
|
|
|
// Set the error state -- we will create an editor
|
|
|
|
// anyway and load empty doc later
|
2003-02-27 17:06:29 +03:00
|
|
|
if (aIsToBeMadeEditable) {
|
|
|
|
if (aStatus == NS_ERROR_FILE_NOT_FOUND)
|
|
|
|
mEditorStatus = eEditorErrorFileNotFound;
|
|
|
|
}
|
2002-11-13 02:03:27 +03:00
|
|
|
|
2004-02-10 01:48:53 +03:00
|
|
|
nsIDocShell *docShell = GetDocShellFromWindow(domWindow);
|
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);
|
|
|
|
if (refreshURI)
|
|
|
|
refreshURI->CancelRefreshURITimers();
|
|
|
|
|
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?
|
2013-02-14 02:39:30 +04:00
|
|
|
if (aIsToBeMadeEditable && mCanCreateEditor)
|
2002-01-30 07:46:54 +03:00
|
|
|
{
|
2011-09-29 10:19:26 +04:00
|
|
|
bool makeEditable;
|
2013-02-14 02:39:30 +04:00
|
|
|
docShell->GetEditable(&makeEditable);
|
2002-01-30 07:46:54 +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?
|
|
|
|
nsCOMPtr<nsIEditor> editor;
|
2013-02-14 02:39:30 +04:00
|
|
|
rv = docShell->GetEditor(getter_AddRefs(editor));
|
2010-06-18 00:44:35 +04:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2008-05-06 21:46:55 +04:00
|
|
|
|
|
|
|
needsSetup = !editor;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (needsSetup)
|
2002-11-13 02:03:27 +03:00
|
|
|
{
|
2011-10-17 18:59:28 +04:00
|
|
|
mCanCreateEditor = false;
|
2007-06-28 06:48:16 +04:00
|
|
|
rv = SetupEditorOnWindow(domWindow);
|
|
|
|
if (NS_FAILED(rv))
|
2002-11-13 02:03:27 +03:00
|
|
|
{
|
2007-06-28 06:48:16 +04:00
|
|
|
// If we had an error, setup timer to load a blank page later
|
|
|
|
if (mLoadBlankDocTimer)
|
|
|
|
{
|
|
|
|
// Must cancel previous timer?
|
|
|
|
mLoadBlankDocTimer->Cancel();
|
2013-04-03 04:13:10 +04:00
|
|
|
mLoadBlankDocTimer = nullptr;
|
2007-06-28 06:48:16 +04:00
|
|
|
}
|
2007-06-28 03:21:05 +04:00
|
|
|
|
2007-06-28 06:48:16 +04:00
|
|
|
mLoadBlankDocTimer = do_CreateInstance("@mozilla.org/timer;1", &rv);
|
2010-06-17 23:27:24 +04:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2007-06-28 06:48:16 +04:00
|
|
|
|
|
|
|
mEditorStatus = eEditorCreationInProgress;
|
|
|
|
mLoadBlankDocTimer->InitWithFuncCallback(
|
|
|
|
nsEditingSession::TimerCallback,
|
2010-03-18 19:12:37 +03:00
|
|
|
static_cast<void*> (mDocShell.get()),
|
2007-06-28 06:48:16 +04:00
|
|
|
10, nsITimer::TYPE_ONE_SHOT);
|
|
|
|
}
|
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));
|
2002-11-13 02:03:27 +03:00
|
|
|
if (docShell)
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIWebNavigation> webNav(do_QueryInterface(docShell));
|
|
|
|
if (webNav)
|
2013-12-13 05:50:01 +04:00
|
|
|
webNav->LoadURI(MOZ_UTF16("about:blank"),
|
2012-07-30 18:20:58 +04:00
|
|
|
0, nullptr, nullptr, nullptr);
|
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)
|
|
|
|
----------------------------------------------------------------------------*/
|
|
|
|
nsresult
|
2002-11-13 02:03:27 +03:00
|
|
|
nsEditingSession::StartPageLoad(nsIChannel *aChannel)
|
2002-01-30 07:46:54 +03:00
|
|
|
{
|
2002-11-13 02:03:27 +03:00
|
|
|
#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)
|
|
|
|
----------------------------------------------------------------------------*/
|
|
|
|
nsresult
|
2002-11-13 02:03:27 +03:00
|
|
|
nsEditingSession::EndPageLoad(nsIWebProgress *aWebProgress,
|
|
|
|
nsIChannel* aChannel, nsresult aStatus)
|
2002-01-30 07:46:54 +03:00
|
|
|
{
|
2003-02-27 17:06:29 +03:00
|
|
|
#ifdef NOISY_DOC_LOADING
|
|
|
|
printf("======= EndPageLoad ========\n");
|
|
|
|
printf(" with status %d, ", aStatus);
|
|
|
|
nsCOMPtr<nsIURI> uri;
|
|
|
|
nsXPIDLCString spec;
|
|
|
|
if (NS_SUCCEEDED(aChannel->GetURI(getter_AddRefs(uri)))) {
|
|
|
|
uri->GetSpec(spec);
|
|
|
|
printf("uri %s\n", spec.get());
|
|
|
|
}
|
|
|
|
|
2012-09-02 06:35:17 +04:00
|
|
|
nsAutoCString contentType;
|
2003-02-27 17:06:29 +03:00
|
|
|
aChannel->GetContentType(contentType);
|
|
|
|
if (!contentType.IsEmpty())
|
|
|
|
printf(" flags = %d, status = %d, MIMETYPE = %s\n",
|
|
|
|
mEditorFlags, mEditorStatus, contentType.get());
|
|
|
|
#endif
|
|
|
|
|
2002-11-13 02:03:27 +03:00
|
|
|
// Set the error state -- we will create an editor anyway
|
|
|
|
// and load empty doc later
|
|
|
|
if (aStatus == NS_ERROR_FILE_NOT_FOUND)
|
|
|
|
mEditorStatus = eEditorErrorFileNotFound;
|
|
|
|
|
2003-01-22 03:46:38 +03:00
|
|
|
nsCOMPtr<nsIDOMWindow> domWindow;
|
2005-02-24 00:27:20 +03:00
|
|
|
aWebProgress->GetDOMWindow(getter_AddRefs(domWindow));
|
|
|
|
|
2004-02-10 01:48:53 +03:00
|
|
|
nsIDocShell *docShell = GetDocShellFromWindow(domWindow);
|
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);
|
|
|
|
if (refreshURI)
|
|
|
|
refreshURI->CancelRefreshURITimers();
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
/*---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
GetDocShellFromWindow
|
|
|
|
|
2012-07-30 18:20:58 +04:00
|
|
|
Utility method. This will always return nullptr if no docShell is found.
|
2002-01-30 07:46:54 +03:00
|
|
|
----------------------------------------------------------------------------*/
|
2004-02-10 01:48:53 +03:00
|
|
|
nsIDocShell *
|
|
|
|
nsEditingSession::GetDocShellFromWindow(nsIDOMWindow *aWindow)
|
2002-01-30 07:46:54 +03:00
|
|
|
{
|
2005-11-29 02:56:44 +03:00
|
|
|
nsCOMPtr<nsPIDOMWindow> window = do_QueryInterface(aWindow);
|
2012-07-30 18:20:58 +04:00
|
|
|
NS_ENSURE_TRUE(window, nullptr);
|
2002-01-30 07:46:54 +03:00
|
|
|
|
2005-11-29 02:56:44 +03:00
|
|
|
return window->GetDocShell();
|
2002-01-30 07:46:54 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/*---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
PrepareForEditing
|
|
|
|
|
|
|
|
Set up this editing session for one or more editors
|
|
|
|
----------------------------------------------------------------------------*/
|
|
|
|
nsresult
|
2005-02-24 00:27:20 +03:00
|
|
|
nsEditingSession::PrepareForEditing(nsIDOMWindow *aWindow)
|
2002-01-30 07:46:54 +03:00
|
|
|
{
|
2007-02-13 12:26:09 +03:00
|
|
|
if (mProgressListenerRegistered)
|
2002-01-30 07:46:54 +03:00
|
|
|
return NS_OK;
|
|
|
|
|
2005-02-24 00:27:20 +03:00
|
|
|
nsIDocShell *docShell = GetDocShellFromWindow(aWindow);
|
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(this,
|
|
|
|
(nsIWebProgress::NOTIFY_STATE_NETWORK |
|
|
|
|
nsIWebProgress::NOTIFY_STATE_DOCUMENT |
|
|
|
|
nsIWebProgress::NOTIFY_LOCATION));
|
|
|
|
|
|
|
|
mProgressListenerRegistered = NS_SUCCEEDED(rv);
|
|
|
|
|
|
|
|
return rv;
|
2002-01-30 07:46:54 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/*---------------------------------------------------------------------------
|
|
|
|
|
2002-11-13 02:03:27 +03:00
|
|
|
SetupEditorCommandController
|
2002-01-30 07:46:54 +03:00
|
|
|
|
2002-11-13 02:03:27 +03:00
|
|
|
Create a command controller, append to controllers,
|
2003-04-10 22:44:03 +04:00
|
|
|
get and return the controller ID, and set the context
|
2002-01-30 07:46:54 +03:00
|
|
|
----------------------------------------------------------------------------*/
|
|
|
|
nsresult
|
2002-11-27 03:35:09 +03:00
|
|
|
nsEditingSession::SetupEditorCommandController(
|
|
|
|
const char *aControllerClassName,
|
|
|
|
nsIDOMWindow *aWindow,
|
2003-04-10 22:44:03 +04:00
|
|
|
nsISupports *aContext,
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t *aControllerId)
|
2002-01-30 07:46:54 +03:00
|
|
|
{
|
2002-11-13 02:03:27 +03:00
|
|
|
NS_ENSURE_ARG_POINTER(aControllerClassName);
|
|
|
|
NS_ENSURE_ARG_POINTER(aWindow);
|
2003-04-10 22:44:03 +04:00
|
|
|
NS_ENSURE_ARG_POINTER(aContext);
|
2002-11-13 02:03:27 +03:00
|
|
|
NS_ENSURE_ARG_POINTER(aControllerId);
|
2002-01-30 07:46:54 +03:00
|
|
|
|
|
|
|
nsCOMPtr<nsIControllers> controllers;
|
2011-07-15 14:31:34 +04:00
|
|
|
nsresult rv = aWindow->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
|
|
|
|
2002-11-13 02:03:27 +03:00
|
|
|
// We only have to create each singleton controller once
|
|
|
|
// We know this has happened once we have a controllerId value
|
|
|
|
if (!*aControllerId)
|
2002-10-09 06:10:22 +04:00
|
|
|
{
|
2002-11-13 02:03:27 +03:00
|
|
|
nsCOMPtr<nsIController> controller;
|
|
|
|
controller = do_CreateInstance(aControllerClassName, &rv);
|
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
|
|
|
// 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)
|
2005-02-24 00:27:20 +03:00
|
|
|
rv = controllers->InsertControllerAt(0, controller);
|
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
|
|
|
// Remember the ID for the controller
|
|
|
|
rv = controllers->GetControllerId(controller, aControllerId);
|
2010-06-17 23:27:24 +04:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2002-11-13 02:03:27 +03:00
|
|
|
}
|
|
|
|
|
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
|
2002-11-13 02:03:27 +03:00
|
|
|
nsEditingSession::SetEditorOnControllers(nsIDOMWindow *aWindow,
|
|
|
|
nsIEditor* aEditor)
|
2002-01-30 07:46:54 +03:00
|
|
|
{
|
2011-07-15 14:31:34 +04:00
|
|
|
NS_ENSURE_TRUE(aWindow, NS_ERROR_NULL_POINTER);
|
2002-01-30 07:46:54 +03:00
|
|
|
|
|
|
|
nsCOMPtr<nsIControllers> controllers;
|
2011-07-15 14:31:34 +04:00
|
|
|
nsresult rv = aWindow->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
|
|
|
|
2002-11-13 02:03:27 +03:00
|
|
|
nsCOMPtr<nsISupports> editorAsISupports = do_QueryInterface(aEditor);
|
|
|
|
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
|
|
|
|
2002-11-13 02:03:27 +03:00
|
|
|
if (mDocStateControllerId)
|
2002-01-30 07:46:54 +03:00
|
|
|
{
|
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
|
|
|
}
|
|
|
|
|
2002-11-13 02:03:27 +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);
|
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
|
|
|
nsresult
|
2003-04-10 22:44:03 +04:00
|
|
|
nsEditingSession::SetContextOnControllerById(nsIControllers* aControllers,
|
2005-02-24 00:27:20 +03:00
|
|
|
nsISupports* aContext,
|
2012-08-22 19:56:38 +04:00
|
|
|
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)
|
2002-11-13 02:03:27 +03:00
|
|
|
nsCOMPtr<nsIController> controller;
|
|
|
|
aControllers->GetControllerById(aID, getter_AddRefs(controller));
|
|
|
|
|
|
|
|
// 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
|
|
|
|
|
|
|
void
|
|
|
|
nsEditingSession::RemoveEditorControllers(nsIDOMWindow *aWindow)
|
|
|
|
{
|
|
|
|
// Remove editor controllers from the aWindow, call when we're
|
|
|
|
// tearing down/detaching editor.
|
|
|
|
|
|
|
|
nsCOMPtr<nsIControllers> controllers;
|
2011-07-15 14:31:34 +04:00
|
|
|
if (aWindow)
|
|
|
|
aWindow->GetControllers(getter_AddRefs(controllers));
|
2008-04-24 01:36:17 +04:00
|
|
|
|
|
|
|
if (controllers)
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIController> controller;
|
|
|
|
if (mBaseCommandControllerId)
|
|
|
|
{
|
|
|
|
controllers->GetControllerById(mBaseCommandControllerId,
|
|
|
|
getter_AddRefs(controller));
|
|
|
|
if (controller)
|
|
|
|
controllers->RemoveController(controller);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mDocStateControllerId)
|
|
|
|
{
|
|
|
|
controllers->GetControllerById(mDocStateControllerId,
|
|
|
|
getter_AddRefs(controller));
|
|
|
|
if (controller)
|
|
|
|
controllers->RemoveController(controller);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mHTMLCommandControllerId)
|
|
|
|
{
|
|
|
|
controllers->GetControllerById(mHTMLCommandControllerId,
|
|
|
|
getter_AddRefs(controller));
|
|
|
|
if (controller)
|
|
|
|
controllers->RemoveController(controller);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Clear IDs to trigger creation of new controllers.
|
|
|
|
mBaseCommandControllerId = 0;
|
|
|
|
mDocStateControllerId = 0;
|
|
|
|
mHTMLCommandControllerId = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsEditingSession::RemoveWebProgressListener(nsIDOMWindow *aWindow)
|
|
|
|
{
|
|
|
|
nsIDocShell *docShell = GetDocShellFromWindow(aWindow);
|
|
|
|
nsCOMPtr<nsIWebProgress> webProgress = do_GetInterface(docShell);
|
|
|
|
if (webProgress)
|
|
|
|
{
|
|
|
|
webProgress->RemoveProgressListener(this);
|
2011-10-17 18:59:28 +04:00
|
|
|
mProgressListenerRegistered = false;
|
2008-04-24 01:36:17 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsEditingSession::RestoreAnimationMode(nsIDOMWindow *aWindow)
|
|
|
|
{
|
|
|
|
if (!mInteractive)
|
|
|
|
{
|
2014-09-26 17:19:56 +04:00
|
|
|
nsCOMPtr<nsIDocShell> docShell = GetDocShellFromWindow(aWindow);
|
|
|
|
NS_ENSURE_TRUE(docShell, );
|
|
|
|
nsCOMPtr<nsIPresShell> presShell = docShell->GetPresShell();
|
|
|
|
NS_ENSURE_TRUE(presShell, );
|
|
|
|
nsPresContext* presContext = presShell->GetPresContext();
|
|
|
|
NS_ENSURE_TRUE(presContext, );
|
|
|
|
|
|
|
|
presContext->SetImageAnimationMode(mImageAnimationMode);
|
2008-04-24 01:36:17 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsEditingSession::DetachFromWindow(nsIDOMWindow* aWindow)
|
|
|
|
{
|
2010-06-18 00:40:48 +04:00
|
|
|
NS_ENSURE_TRUE(mDoneSetup, NS_OK);
|
2008-05-01 13:00:11 +04:00
|
|
|
|
2008-04-24 01:36:17 +04:00
|
|
|
NS_ASSERTION(mStateMaintainer, "mStateMaintainer should exist.");
|
|
|
|
|
|
|
|
// Kill any existing reload timer
|
|
|
|
if (mLoadBlankDocTimer)
|
|
|
|
{
|
|
|
|
mLoadBlankDocTimer->Cancel();
|
2012-07-30 18:20:58 +04:00
|
|
|
mLoadBlankDocTimer = nullptr;
|
2008-04-24 01:36:17 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
// Remove controllers, webprogress listener, and otherwise
|
|
|
|
// make things the way they were before we started editing.
|
|
|
|
RemoveEditorControllers(aWindow);
|
|
|
|
RemoveWebProgressListener(aWindow);
|
|
|
|
RestoreJSAndPlugins(aWindow);
|
|
|
|
RestoreAnimationMode(aWindow);
|
|
|
|
|
|
|
|
// 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;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsEditingSession::ReattachToWindow(nsIDOMWindow* aWindow)
|
|
|
|
{
|
2010-06-18 00:40:48 +04:00
|
|
|
NS_ENSURE_TRUE(mDoneSetup, NS_OK);
|
2008-05-01 13:00:11 +04:00
|
|
|
|
2008-04-24 01:36:17 +04:00
|
|
|
NS_ASSERTION(mStateMaintainer, "mStateMaintainer should exist.");
|
|
|
|
|
|
|
|
// Imitate nsEditorDocShell::MakeEditable() to reattach the
|
|
|
|
// old editor ot the window.
|
|
|
|
nsresult rv;
|
|
|
|
|
2010-10-15 21:59:00 +04:00
|
|
|
nsIDocShell *docShell = GetDocShellFromWindow(aWindow);
|
|
|
|
NS_ENSURE_TRUE(docShell, NS_ERROR_FAILURE);
|
|
|
|
mDocShell = do_GetWeakReference(docShell);
|
2008-04-24 01:36:17 +04:00
|
|
|
|
|
|
|
// Disable plugins.
|
|
|
|
if (!mInteractive)
|
|
|
|
{
|
|
|
|
rv = DisableJSAndPlugins(aWindow);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Tells embedder that startup is in progress.
|
|
|
|
mEditorStatus = eEditorCreationInProgress;
|
|
|
|
|
|
|
|
// Adds back web progress listener.
|
|
|
|
rv = PrepareForEditing(aWindow);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
// Setup the command controllers again.
|
2011-12-24 04:11:30 +04:00
|
|
|
rv = SetupEditorCommandController("@mozilla.org/editor/editingcontroller;1",
|
2008-04-24 01:36:17 +04:00
|
|
|
aWindow,
|
|
|
|
static_cast<nsIEditingSession*>(this),
|
|
|
|
&mBaseCommandControllerId);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
rv = SetupEditorCommandController("@mozilla.org/editor/editordocstatecontroller;1",
|
|
|
|
aWindow,
|
|
|
|
static_cast<nsIEditingSession*>(this),
|
|
|
|
&mDocStateControllerId);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
if (mStateMaintainer)
|
|
|
|
mStateMaintainer->Init(aWindow);
|
|
|
|
|
|
|
|
// Get editor
|
|
|
|
nsCOMPtr<nsIEditor> editor;
|
|
|
|
rv = GetEditorForWindow(aWindow, getter_AddRefs(editor));
|
2010-06-18 00:40:48 +04:00
|
|
|
NS_ENSURE_TRUE(editor, NS_ERROR_FAILURE);
|
2008-04-24 01:36:17 +04:00
|
|
|
|
|
|
|
if (!mInteractive)
|
|
|
|
{
|
|
|
|
// 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
|
|
|
|
rv = SetupEditorCommandController("@mozilla.org/editor/htmleditorcontroller;1",
|
|
|
|
aWindow, editor,
|
|
|
|
&mHTMLCommandControllerId);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
// Set context on all controllers to be the editor
|
|
|
|
rv = SetEditorOnControllers(aWindow, editor);
|
|
|
|
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;
|
|
|
|
}
|