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

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Gijs Kruitbosch 2018-09-26 17:48:38 +00:00
parent 10714b6c62
commit 76afb51661
13 changed files with 31 additions and 81 deletions

View File

@ -281,6 +281,12 @@ class BasePopup {
stack.appendChild(browser);
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);

View File

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

View File

@ -254,7 +254,7 @@
.createInstance(Ci.nsISecureBrowserUI);
try {
secureUI.setDocShell(docshell);
secureUI.init(docshell);
ok(false, "expected exception passing CPOW to C++");
} catch (e) {
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.
var securityUI = Cc['@mozilla.org/secure_browser_ui;1']
.createInstance(Ci.nsISecureBrowserUI);
securityUI.init(content);
securityUI.init(docShell);
// A cache of the menuitem dom objects keyed by the id we generate
// and pass to the embedder

View File

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

View File

@ -133,7 +133,6 @@ TabParent::LayerToTabParentTable* TabParent::sLayerToTabParentTable = nullptr;
NS_IMPL_ISUPPORTS(TabParent,
nsITabParent,
nsIAuthPromptProvider,
nsISecureBrowserUI,
nsISupportsWeakReference)
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*
TabParent::AllocPDocAccessibleParent(PDocAccessibleParent* aParent,
const uint64_t&, const uint32_t&,

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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