/*--------------------------------------------------------------------------- WindowIsEditable boolean windowIsEditable (in nsIDOMWindow aWindow); ----------------------------------------------------------------------------*/ NS_IMETHODIMP nsEditingSession::WindowIsEditable(nsIDOMWindow *aWindow, bool *outIsEditable) { nsCOMPtr<nsIEditorDocShell> editorDocShell; nsresult rv = GetEditorDocShellFromWindow(aWindow, getter_AddRefs(editorDocShell)); NS_ENSURE_SUCCESS(rv, rv); return editorDocShell->GetEditable(outIsEditable); }
/*--------------------------------------------------------------------------- WindowIsEditable boolean windowIsEditable (in nsIDOMWindow aWindow); ----------------------------------------------------------------------------*/ NS_IMETHODIMP nsEditingSession::WindowIsEditable(nsIDOMWindow *aWindow, PRBool *outIsEditable) { nsCOMPtr<nsIEditorDocShell> editorDocShell; nsresult rv = GetEditorDocShellFromWindow(aWindow, getter_AddRefs(editorDocShell)); if (NS_FAILED(rv)) return rv; return editorDocShell->GetEditable(outIsEditable); }
/*--------------------------------------------------------------------------- GetEditorForFrame nsIEditor getEditorForFrame (in nsIDOMWindow aWindow); ----------------------------------------------------------------------------*/ NS_IMETHODIMP nsEditingSession::GetEditorForWindow(nsIDOMWindow *aWindow, nsIEditor **outEditor) { nsCOMPtr<nsIEditorDocShell> editorDocShell; nsresult rv = GetEditorDocShellFromWindow(aWindow, getter_AddRefs(editorDocShell)); NS_ENSURE_SUCCESS(rv, rv); return editorDocShell->GetEditor(outEditor); }
/*--------------------------------------------------------------------------- GetEditorForFrame nsIEditor getEditorForFrame (in nsIDOMWindow aWindow); ----------------------------------------------------------------------------*/ NS_IMETHODIMP nsEditingSession::GetEditorForWindow(nsIDOMWindow *aWindow, nsIEditor **outEditor) { nsCOMPtr<nsIEditorDocShell> editorDocShell; nsresult rv = GetEditorDocShellFromWindow(aWindow, getter_AddRefs(editorDocShell)); if (NS_FAILED(rv)) return rv; return editorDocShell->GetEditor(outEditor); }
/*--------------------------------------------------------------------------- TearDownEditorOnWindow void tearDownEditorOnWindow (in nsIDOMWindow aWindow); ----------------------------------------------------------------------------*/ NS_IMETHODIMP nsEditingSession::TearDownEditorOnWindow(nsIDOMWindow *aWindow) { if (!mDoneSetup) { return NS_OK; } NS_ENSURE_TRUE(aWindow, NS_ERROR_NULL_POINTER); nsresult rv; // Kill any existing reload timer if (mLoadBlankDocTimer) { mLoadBlankDocTimer->Cancel(); mLoadBlankDocTimer = nullptr; } mDoneSetup = false; // 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); bool stopEditing = htmlDoc && htmlDoc->IsEditingOn(); if (stopEditing) RemoveWebProgressListener(aWindow); nsCOMPtr<nsIEditorDocShell> editorDocShell; rv = GetEditorDocShellFromWindow(aWindow, getter_AddRefs(editorDocShell)); NS_ENSURE_SUCCESS(rv, rv); nsCOMPtr<nsIEditor> editor; rv = editorDocShell->GetEditor(getter_AddRefs(editor)); NS_ENSURE_SUCCESS(rv, rv); if (stopEditing) htmlDoc->TearingDownEditor(editor); if (mStateMaintainer && editor) { // Null out the editor on the controllers first to prevent their weak // references from pointing to a destroyed editor. SetEditorOnControllers(aWindow, nullptr); } // Null out the editor on the docShell to trigger PreDestroy which // needs to happen before document state listeners are removed below. editorDocShell->SetEditor(nullptr); RemoveListenersAndControllers(aWindow, editor); if (stopEditing) { // Make things the way they were before we started editing. RestoreJSAndPlugins(aWindow); RestoreAnimationMode(aWindow); if (mMakeWholeDocumentEditable) { nsCOMPtr<nsIDocument> doc = do_QueryInterface(domDoc, &rv); NS_ENSURE_SUCCESS(rv, rv); doc->SetEditableFlag(false); nsCOMPtr<nsIHTMLDocument> htmlDocument = do_QueryInterface(doc); if (htmlDocument) { htmlDocument->SetEditingState(nsIHTMLDocument::eOff); } } } return rv; }
NS_IMETHODIMP nsEditingSession::MakeWindowEditable(nsIDOMWindow *aWindow, const char *aEditorType, bool aDoAfterUriLoad, bool aMakeWholeDocumentEditable, bool aInteractive) { mEditorType.Truncate(); mEditorFlags = 0; // disable plugins nsIDocShell *docShell = GetDocShellFromWindow(aWindow); NS_ENSURE_TRUE(docShell, NS_ERROR_FAILURE); mDocShell = do_GetWeakReference(docShell); mInteractive = aInteractive; mMakeWholeDocumentEditable = aMakeWholeDocumentEditable; nsresult rv; if (!mInteractive) { rv = DisableJSAndPlugins(aWindow); NS_ENSURE_SUCCESS(rv, rv); } // Always remove existing editor TearDownEditorOnWindow(aWindow); // Tells embedder that startup is in progress mEditorStatus = eEditorCreationInProgress; //temporary to set editor type here. we will need different classes soon. if (!aEditorType) aEditorType = DEFAULT_EDITOR_TYPE; mEditorType = aEditorType; // if all this does is setup listeners and I don't need listeners, // can't this step be ignored?? (based on aDoAfterURILoad) rv = PrepareForEditing(aWindow); NS_ENSURE_SUCCESS(rv, rv); nsCOMPtr<nsIEditorDocShell> editorDocShell; rv = GetEditorDocShellFromWindow(aWindow, getter_AddRefs(editorDocShell)); NS_ENSURE_SUCCESS(rv, rv); // set the flag on the docShell to say that it's editable rv = editorDocShell->MakeEditable(aDoAfterUriLoad); NS_ENSURE_SUCCESS(rv, rv); // Setup commands common to plaintext and html editors, // including the document creation observers // the first is an editing controller rv = SetupEditorCommandController("@mozilla.org/editor/editingcontroller;1", aWindow, static_cast<nsIEditingSession*>(this), &mBaseCommandControllerId); NS_ENSURE_SUCCESS(rv, rv); // The second is a controller to monitor doc state, // such as creation and "dirty flag" rv = SetupEditorCommandController("@mozilla.org/editor/editordocstatecontroller;1", aWindow, static_cast<nsIEditingSession*>(this), &mDocStateControllerId); NS_ENSURE_SUCCESS(rv, rv); // aDoAfterUriLoad can be false only when making an existing window editable if (!aDoAfterUriLoad) { rv = SetupEditorOnWindow(aWindow); // 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)) TearDownEditorOnWindow(aWindow); } return rv; }