Files
tubestation/docshell/base/nsDocShellEditorData.cpp
Gabriele Svelto eeb9bfc398 Bug 1600545 - Remove useless inclusions of header files generated from IDL files in accessible/, browser/, caps/, chrome/, devtools/, docshell/, editor/, extensions/, gfx/, hal/, image/, intl/, ipc/, js/, layout/, and media/ r=Ehsan
The inclusions were removed with the following very crude script and the
resulting breakage was fixed up by hand. The manual fixups did either
revert the changes done by the script, replace a generic header with a more
specific one or replace a header with a forward declaration.

find . -name "*.idl" | grep -v web-platform | grep -v third_party | while read path; do
    interfaces=$(grep "^\(class\|interface\).*:.*" "$path" | cut -d' ' -f2)
    if [ -n "$interfaces" ]; then
        if [[ "$interfaces" == *$'\n'* ]]; then
          regexp="\("
          for i in $interfaces; do regexp="$regexp$i\|"; done
          regexp="${regexp%%\\\|}\)"
        else
          regexp="$interfaces"
        fi
        interface=$(basename "$path")
        rg -l "#include.*${interface%%.idl}.h" . | while read path2; do
            hits=$(grep -v "#include.*${interface%%.idl}.h" "$path2" | grep -c "$regexp" )
            if [ $hits -eq 0 ]; then
                echo "Removing ${interface} from ${path2}"
                grep -v "#include.*${interface%%.idl}.h" "$path2" > "$path2".tmp
                mv -f "$path2".tmp "$path2"
            fi
        done
    fi
done

Differential Revision: https://phabricator.services.mozilla.com/D55443
2019-12-06 09:16:44 +00:00

136 lines
3.8 KiB
C++

/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
/* 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/. */
#include "nsDocShellEditorData.h"
#include "nsIInterfaceRequestorUtils.h"
#include "nsComponentManagerUtils.h"
#include "nsPIDOMWindow.h"
#include "nsEditingSession.h"
#include "nsIDocShell.h"
using namespace mozilla;
nsDocShellEditorData::nsDocShellEditorData(nsIDocShell* aOwningDocShell)
: mDocShell(aOwningDocShell),
mDetachedEditingState(Document::EditingState::eOff),
mMakeEditable(false),
mIsDetached(false),
mDetachedMakeEditable(false) {
NS_ASSERTION(mDocShell, "Where is my docShell?");
}
nsDocShellEditorData::~nsDocShellEditorData() { TearDownEditor(); }
void nsDocShellEditorData::TearDownEditor() {
if (mHTMLEditor) {
RefPtr<HTMLEditor> htmlEditor = mHTMLEditor.forget();
htmlEditor->PreDestroy(false);
}
mEditingSession = nullptr;
mIsDetached = false;
}
nsresult nsDocShellEditorData::MakeEditable(bool aInWaitForUriLoad) {
if (mMakeEditable) {
return NS_OK;
}
// if we are already editable, and are getting turned off,
// nuke the editor.
if (mHTMLEditor) {
NS_WARNING("Destroying existing editor on frame");
RefPtr<HTMLEditor> htmlEditor = mHTMLEditor.forget();
htmlEditor->PreDestroy(false);
}
if (aInWaitForUriLoad) {
mMakeEditable = true;
}
return NS_OK;
}
bool nsDocShellEditorData::GetEditable() {
return mMakeEditable || (mHTMLEditor != nullptr);
}
nsEditingSession* nsDocShellEditorData::GetEditingSession() {
EnsureEditingSession();
return mEditingSession.get();
}
nsresult nsDocShellEditorData::SetHTMLEditor(HTMLEditor* aHTMLEditor) {
// destroy any editor that we have. Checks for equality are
// necessary to ensure that assigment into the nsCOMPtr does
// not temporarily reduce the refCount of the editor to zero
if (mHTMLEditor == aHTMLEditor) {
return NS_OK;
}
if (mHTMLEditor) {
RefPtr<HTMLEditor> htmlEditor = mHTMLEditor.forget();
htmlEditor->PreDestroy(false);
MOZ_ASSERT(!mHTMLEditor,
"Nested call of nsDocShellEditorData::SetHTMLEditor() detected");
}
mHTMLEditor = aHTMLEditor; // owning addref
if (!mHTMLEditor) {
mMakeEditable = false;
}
return NS_OK;
}
// This creates the editing session on the content docShell that owns 'this'.
void nsDocShellEditorData::EnsureEditingSession() {
NS_ASSERTION(mDocShell, "Should have docShell here");
NS_ASSERTION(!mIsDetached, "This will stomp editing session!");
if (!mEditingSession) {
mEditingSession = new nsEditingSession();
}
}
nsresult nsDocShellEditorData::DetachFromWindow() {
NS_ASSERTION(mEditingSession,
"Can't detach when we don't have a session to detach!");
nsCOMPtr<nsPIDOMWindowOuter> domWindow =
mDocShell ? mDocShell->GetWindow() : nullptr;
nsresult rv = mEditingSession->DetachFromWindow(domWindow);
NS_ENSURE_SUCCESS(rv, rv);
mIsDetached = true;
mDetachedMakeEditable = mMakeEditable;
mMakeEditable = false;
nsCOMPtr<dom::Document> doc = domWindow->GetDoc();
mDetachedEditingState = doc->GetEditingState();
mDocShell = nullptr;
return NS_OK;
}
nsresult nsDocShellEditorData::ReattachToWindow(nsIDocShell* aDocShell) {
mDocShell = aDocShell;
nsCOMPtr<nsPIDOMWindowOuter> domWindow =
mDocShell ? mDocShell->GetWindow() : nullptr;
nsresult rv = mEditingSession->ReattachToWindow(domWindow);
NS_ENSURE_SUCCESS(rv, rv);
mIsDetached = false;
mMakeEditable = mDetachedMakeEditable;
RefPtr<dom::Document> doc = domWindow->GetDoc();
doc->SetEditingState(mDetachedEditingState);
return NS_OK;
}