From 04870fc9805f9f0882a46a79a79b4a13a463cd51 Mon Sep 17 00:00:00 2001 From: Dan Glastonbury Date: Fri, 20 Mar 2020 04:53:43 +0000 Subject: [PATCH] Bug 1623562 - Refactor allowPlugins to use BrowsingContext. r=nika Differential Revision: https://phabricator.services.mozilla.com/D67428 --HG-- extra : moz-landing-system : lando --- docshell/base/nsWebNavigationInfo.cpp | 7 +++---- dom/base/Document.cpp | 8 +++----- editor/composer/nsEditingSession.cpp | 11 +++++++---- 3 files changed, 13 insertions(+), 13 deletions(-) diff --git a/docshell/base/nsWebNavigationInfo.cpp b/docshell/base/nsWebNavigationInfo.cpp index 6e746dbd7dd9..08228e9c9de9 100644 --- a/docshell/base/nsWebNavigationInfo.cpp +++ b/docshell/base/nsWebNavigationInfo.cpp @@ -32,10 +32,9 @@ uint32_t nsWebNavigationInfo::IsTypeSupported(const nsACString& aType, // an nsSHistory, but not much we can do with that). So if we start using // it here, we need to be careful to get to the docshell correctly. nsCOMPtr docShell(do_QueryInterface(aWebNav)); - bool pluginsAllowed = true; - if (docShell) { - docShell->GetAllowPlugins(&pluginsAllowed); - } + auto* browsingContext = docShell ? docShell->GetBrowsingContext() : nullptr; + bool pluginsAllowed = + browsingContext ? browsingContext->GetAllowPlugins() : true; return IsTypeSupported(aType, pluginsAllowed); } diff --git a/dom/base/Document.cpp b/dom/base/Document.cpp index 10c1d35d722f..08466a8c5b06 100644 --- a/dom/base/Document.cpp +++ b/dom/base/Document.cpp @@ -3835,12 +3835,10 @@ void Document::SetContentType(const nsAString& aContentType) { bool Document::GetAllowPlugins() { // First, we ask our docshell if it allows plugins. - nsCOMPtr docShell(mDocumentContainer); + auto* browsingContext = GetBrowsingContext(); - if (docShell) { - bool allowPlugins = false; - docShell->GetAllowPlugins(&allowPlugins); - if (!allowPlugins) { + if (browsingContext) { + if (!browsingContext->GetAllowPlugins()) { return false; } diff --git a/editor/composer/nsEditingSession.cpp b/editor/composer/nsEditingSession.cpp index bff9f96a5f3b..7c487e607659 100644 --- a/editor/composer/nsEditingSession.cpp +++ b/editor/composer/nsEditingSession.cpp @@ -112,8 +112,8 @@ nsEditingSession::MakeWindowEditable(mozIDOMWindowProxy* aWindow, // disable plugins nsCOMPtr docShell = window->GetDocShell(); NS_ENSURE_TRUE(docShell, NS_ERROR_FAILURE); - mDocShell = do_GetWeakReference(docShell); + mInteractive = aInteractive; mMakeWholeDocumentEditable = aMakeWholeDocumentEditable; @@ -184,8 +184,7 @@ nsresult nsEditingSession::DisableJSAndPlugins(nsIDocShell& aDocShell) { // Disable plugins in this document: mPluginsEnabled = aDocShell.PluginsAllowedInCurrentDoc(); - rv = aDocShell.SetAllowPlugins(false); - NS_ENSURE_SUCCESS(rv, rv); + aDocShell.GetBrowsingContext()->SetAllowPlugins(false); mDisabledJSAndPlugins = true; @@ -210,7 +209,11 @@ nsresult nsEditingSession::RestoreJSAndPlugins(nsPIDOMWindowOuter* aWindow) { NS_ENSURE_SUCCESS(rv, rv); // Disable plugins in this document: - return docShell->SetAllowPlugins(mPluginsEnabled); + auto* browsingContext = aWindow->GetBrowsingContext(); + NS_ENSURE_TRUE(browsingContext, NS_ERROR_FAILURE); + browsingContext->SetAllowPlugins(mPluginsEnabled); + + return NS_OK; } /*---------------------------------------------------------------------------