Bug 1493655 - make nsISecureBrowserUI initialize from a docshell instead of a window, r=keeler,nika

This also removes the (afaict, unused) stub implementation from TabParent. The netwerk header
inclusions were necessary because those files included TabParent.h and through it,
nsISecureBrowserUI, but now TabParent.h no longer does that.

Differential Revision: https://phabricator.services.mozilla.com/D6829
This commit is contained in:
Gijs Kruitbosch
2018-09-26 17:48:38 +00:00
parent bc62d876c1
commit ae4c0d1d3d
13 changed files with 31 additions and 81 deletions

View File

@@ -281,6 +281,12 @@ class BasePopup {
stack.appendChild(browser); stack.appendChild(browser);
viewNode.appendChild(stack); viewNode.appendChild(stack);
if (!this.extension.remote) {
// FIXME: bug 1494029 - this code used to rely on the browser binding
// accessing browser.contentWindow. This is a stopgap to continue doing
// that, but we should get rid of it in the long term.
browser.contentWindow; // eslint-disable-line no-unused-expressions
}
ExtensionParent.apiManager.emit("extension-browser-inserted", browser); ExtensionParent.apiManager.emit("extension-browser-inserted", browser);

View File

@@ -2251,7 +2251,6 @@ nsDocShell::SetSecurityUI(nsISecureBrowserUI* aSecurityUI)
MOZ_ASSERT(!mIsBeingDestroyed); MOZ_ASSERT(!mIsBeingDestroyed);
mSecurityUI = aSecurityUI; mSecurityUI = aSecurityUI;
mSecurityUI->SetDocShell(this);
return NS_OK; return NS_OK;
} }

View File

@@ -254,7 +254,7 @@
.createInstance(Ci.nsISecureBrowserUI); .createInstance(Ci.nsISecureBrowserUI);
try { try {
secureUI.setDocShell(docshell); secureUI.init(docshell);
ok(false, "expected exception passing CPOW to C++"); ok(false, "expected exception passing CPOW to C++");
} catch (e) { } catch (e) {
is(e.result, Cr.NS_ERROR_XPC_CANT_PASS_CPOW_TO_NATIVE, is(e.result, Cr.NS_ERROR_XPC_CANT_PASS_CPOW_TO_NATIVE,

View File

@@ -148,7 +148,7 @@ BrowserElementChild.prototype = {
// This is necessary to get security web progress notifications. // This is necessary to get security web progress notifications.
var securityUI = Cc['@mozilla.org/secure_browser_ui;1'] var securityUI = Cc['@mozilla.org/secure_browser_ui;1']
.createInstance(Ci.nsISecureBrowserUI); .createInstance(Ci.nsISecureBrowserUI);
securityUI.init(content); securityUI.init(docShell);
// A cache of the menuitem dom objects keyed by the id we generate // A cache of the menuitem dom objects keyed by the id we generate
// and pass to the embedder // and pass to the embedder

View File

@@ -4,6 +4,6 @@
width="640" height="480"> width="640" height="480">
<browser id="browser" type="content" primary="true" flex="1" src="about:blank" <browser id="browser" type="content" primary="true" flex="1" src="about:blank"
disablehistory="true" disablesecurity="true"/> disablehistory="true"/>
</window> </window>

View File

@@ -133,7 +133,6 @@ TabParent::LayerToTabParentTable* TabParent::sLayerToTabParentTable = nullptr;
NS_IMPL_ISUPPORTS(TabParent, NS_IMPL_ISUPPORTS(TabParent,
nsITabParent, nsITabParent,
nsIAuthPromptProvider, nsIAuthPromptProvider,
nsISecureBrowserUI,
nsISupportsWeakReference) nsISupportsWeakReference)
TabParent::TabParent(nsIContentParent* aManager, TabParent::TabParent(nsIContentParent* aManager,
@@ -878,38 +877,6 @@ TabParent::Deactivate()
} }
} }
NS_IMETHODIMP
TabParent::Init(mozIDOMWindowProxy *window)
{
return NS_OK;
}
NS_IMETHODIMP
TabParent::GetState(uint32_t *aState)
{
NS_ENSURE_ARG(aState);
NS_WARNING("SecurityState not valid here");
*aState = 0;
return NS_OK;
}
NS_IMETHODIMP
TabParent::GetSecInfo(nsITransportSecurityInfo** _result)
{
NS_ENSURE_ARG_POINTER(_result);
NS_WARNING("TransportSecurityInfo not valid here");
*_result = nullptr;
return NS_OK;
}
NS_IMETHODIMP
TabParent::SetDocShell(nsIDocShell *aDocShell)
{
NS_ENSURE_ARG(aDocShell);
NS_WARNING("No mDocShell member in TabParent so there is no docShell to set");
return NS_OK;
}
a11y::PDocAccessibleParent* a11y::PDocAccessibleParent*
TabParent::AllocPDocAccessibleParent(PDocAccessibleParent* aParent, TabParent::AllocPDocAccessibleParent(PDocAccessibleParent* aParent,
const uint64_t&, const uint32_t&, const uint64_t&, const uint32_t&,

View File

@@ -25,7 +25,6 @@
#include "nsIBrowserDOMWindow.h" #include "nsIBrowserDOMWindow.h"
#include "nsIDOMEventListener.h" #include "nsIDOMEventListener.h"
#include "nsIKeyEventInPluginCallback.h" #include "nsIKeyEventInPluginCallback.h"
#include "nsISecureBrowserUI.h"
#include "nsITabParent.h" #include "nsITabParent.h"
#include "nsIXULBrowserWindow.h" #include "nsIXULBrowserWindow.h"
#include "nsRefreshDriver.h" #include "nsRefreshDriver.h"
@@ -83,7 +82,6 @@ class TabParent final : public PBrowserParent
, public nsIDOMEventListener , public nsIDOMEventListener
, public nsITabParent , public nsITabParent
, public nsIAuthPromptProvider , public nsIAuthPromptProvider
, public nsISecureBrowserUI
, public nsIKeyEventInPluginCallback , public nsIKeyEventInPluginCallback
, public nsSupportsWeakReference , public nsSupportsWeakReference
, public TabContext , public TabContext
@@ -487,7 +485,6 @@ public:
NS_DECL_ISUPPORTS NS_DECL_ISUPPORTS
NS_DECL_NSIAUTHPROMPTPROVIDER NS_DECL_NSIAUTHPROMPTPROVIDER
NS_DECL_NSISECUREBROWSERUI
void StartPersistence(uint64_t aOuterWindowID, void StartPersistence(uint64_t aOuterWindowID,
nsIWebBrowserPersistDocumentReceiver* aRecv, nsIWebBrowserPersistDocumentReceiver* aRecv,

View File

@@ -6,15 +6,13 @@
#include "nsISupports.idl" #include "nsISupports.idl"
interface mozIDOMWindowProxy;
interface nsIDocShell; interface nsIDocShell;
interface nsITransportSecurityInfo; interface nsITransportSecurityInfo;
[scriptable, uuid(718c662a-f810-4a80-a6c9-0b1810ecade2)] [scriptable, uuid(718c662a-f810-4a80-a6c9-0b1810ecade2)]
interface nsISecureBrowserUI : nsISupports interface nsISecureBrowserUI : nsISupports
{ {
void init(in mozIDOMWindowProxy window); void init(in nsIDocShell docShell);
void setDocShell(in nsIDocShell docShell);
readonly attribute unsigned long state; readonly attribute unsigned long state;
readonly attribute nsITransportSecurityInfo secInfo; readonly attribute nsITransportSecurityInfo secInfo;

View File

@@ -18,6 +18,7 @@
#include "nsIAuthPromptProvider.h" #include "nsIAuthPromptProvider.h"
#include "nsIEncodedChannel.h" #include "nsIEncodedChannel.h"
#include "nsIHttpChannelInternal.h" #include "nsIHttpChannelInternal.h"
#include "nsISecureBrowserUI.h"
#include "nsIForcePendingChannel.h" #include "nsIForcePendingChannel.h"
#include "mozilla/ipc/IPCStreamUtils.h" #include "mozilla/ipc/IPCStreamUtils.h"
#include "mozilla/ipc/URIUtils.h" #include "mozilla/ipc/URIUtils.h"

View File

@@ -47,6 +47,7 @@
#include "mozilla/net/RedirectChannelRegistrar.h" #include "mozilla/net/RedirectChannelRegistrar.h"
#include "nsIWindowWatcher.h" #include "nsIWindowWatcher.h"
#include "nsIDocument.h" #include "nsIDocument.h"
#include "nsISecureBrowserUI.h"
#include "nsStreamUtils.h" #include "nsStreamUtils.h"
#include "nsStringStream.h" #include "nsStringStream.h"
#include "nsIStorageStream.h" #include "nsIStorageStream.h"

View File

@@ -32,29 +32,27 @@ NS_IMPL_ISUPPORTS(nsSecureBrowserUIImpl,
nsISupportsWeakReference) nsISupportsWeakReference)
NS_IMETHODIMP NS_IMETHODIMP
nsSecureBrowserUIImpl::Init(mozIDOMWindowProxy* aWindow) nsSecureBrowserUIImpl::Init(nsIDocShell* aDocShell)
{ {
MOZ_ASSERT(NS_IsMainThread()); MOZ_ASSERT(NS_IsMainThread());
NS_ENSURE_ARG(aWindow); NS_ENSURE_ARG(aDocShell);
auto* piwindow = nsPIDOMWindowOuter::From(aWindow); aDocShell->SetSecurityUI(this);
nsIDocShell* docShell = piwindow->GetDocShell();
// The Docshell will own the SecureBrowserUI object // The Docshell will own the SecureBrowserUI object, we keep a weak ref.
if (!docShell) { nsresult rv;
return NS_ERROR_FAILURE; mDocShell = do_GetWeakReference(aDocShell, &rv);
if (NS_FAILED(rv)) {
return rv;
} }
docShell->SetSecurityUI(this);
// hook up to the webprogress notifications. // hook up to the webprogress notifications.
nsCOMPtr<nsIWebProgress> wp(do_GetInterface(docShell)); nsCOMPtr<nsIWebProgress> wp(do_GetInterface(aDocShell));
if (!wp) { if (!wp) {
return NS_ERROR_FAILURE; return NS_ERROR_FAILURE;
} }
// Save this so we can compare it to the web progress in OnLocationChange. // Save this so we can compare it to the web progress in OnLocationChange.
nsresult rv;
mWebProgress = do_GetWeakReference(wp, &rv); mWebProgress = do_GetWeakReference(wp, &rv);
if (NS_FAILED(rv)) { if (NS_FAILED(rv)) {
return rv; return rv;
@@ -92,16 +90,6 @@ nsSecureBrowserUIImpl::GetSecInfo(nsITransportSecurityInfo** result)
return NS_OK; return NS_OK;
} }
NS_IMETHODIMP
nsSecureBrowserUIImpl::SetDocShell(nsIDocShell* aDocShell)
{
MOZ_ASSERT(NS_IsMainThread());
NS_ENSURE_ARG(aDocShell);
nsresult rv;
mDocShell = do_GetWeakReference(aDocShell, &rv);
return rv;
}
// Ask the docShell if we've blocked or loaded any mixed or tracking content. // Ask the docShell if we've blocked or loaded any mixed or tracking content.
void void
nsSecureBrowserUIImpl::CheckForBlockedContent() nsSecureBrowserUIImpl::CheckForBlockedContent()

View File

@@ -1191,18 +1191,14 @@ nsWebBrowser::Create()
// Hook into the OnSecurityChange() notification for lock/unlock icon // Hook into the OnSecurityChange() notification for lock/unlock icon
// updates // updates
nsCOMPtr<mozIDOMWindowProxy> domWindow; // this works because the implementation of nsISecureBrowserUI
rv = GetContentDOMWindow(getter_AddRefs(domWindow)); // (nsSecureBrowserUIImpl) calls docShell->SetSecurityUI(this);
if (NS_SUCCEEDED(rv)) { nsCOMPtr<nsISecureBrowserUI> securityUI =
// this works because the implementation of nsISecureBrowserUI do_CreateInstance(NS_SECURE_BROWSER_UI_CONTRACTID, &rv);
// (nsSecureBrowserUIImpl) gets a docShell from the domWindow, if (NS_FAILED(rv)) {
// and calls docShell->SetSecurityUI(this); return rv;
nsCOMPtr<nsISecureBrowserUI> securityUI =
do_CreateInstance(NS_SECURE_BROWSER_UI_CONTRACTID, &rv);
if (NS_SUCCEEDED(rv)) {
securityUI->Init(domWindow);
}
} }
securityUI->Init(mDocShell);
mDocShellTreeOwner->AddToWatcher(); // evil twin of Remove in SetDocShell(0) mDocShellTreeOwner->AddToWatcher(); // evil twin of Remove in SetDocShell(0)
mDocShellTreeOwner->AddChromeListeners(); mDocShellTreeOwner->AddChromeListeners();

View File

@@ -914,12 +914,9 @@
if (!this.docShell.securityUI) { if (!this.docShell.securityUI) {
const SECUREBROWSERUI_CONTRACTID = "@mozilla.org/secure_browser_ui;1"; const SECUREBROWSERUI_CONTRACTID = "@mozilla.org/secure_browser_ui;1";
if (!this.hasAttribute("disablesecurity") && var securityUI = Cc[SECUREBROWSERUI_CONTRACTID]
SECUREBROWSERUI_CONTRACTID in Cc) { .createInstance(Ci.nsISecureBrowserUI);
var securityUI = Cc[SECUREBROWSERUI_CONTRACTID] securityUI.init(this.docShell);
.createInstance(Ci.nsISecureBrowserUI);
securityUI.init(this.contentWindow);
}
} }
return this.docShell.securityUI; return this.docShell.securityUI;