Bug 1500948 - Expose BrowsingContext on nsFrameLoader objects, r=farre

This should make BrowsingContext more usable by making it much easier to obtain
for a given frame or browser. BrowsingContext and nsFrameLoader should have
the same lifetime.

Differential Revision: https://phabricator.services.mozilla.com/D9395
This commit is contained in:
Nika Layzell 2018-10-19 20:02:37 -04:00
Родитель 91dd6c616f
Коммит 554bfd2811
7 изменённых файлов: 45 добавлений и 0 удалений

Просмотреть файл

@ -100,6 +100,7 @@
#include "mozilla/dom/PromiseNativeHandler.h"
#include "mozilla/dom/ParentSHistory.h"
#include "mozilla/dom/ChildSHistory.h"
#include "mozilla/dom/ChromeBrowsingContext.h"
#include "mozilla/dom/HTMLBodyElement.h"
@ -3022,6 +3023,16 @@ already_AddRefed<nsILoadContext> nsFrameLoader::LoadContext() {
return loadContext.forget();
}
already_AddRefed<BrowsingContext> nsFrameLoader::GetBrowsingContext() {
RefPtr<BrowsingContext> browsingContext;
if (IsRemoteFrame() && (mRemoteBrowser || TryRemoteBrowser())) {
browsingContext = mRemoteBrowser->GetBrowsingContext();
} else if (GetDocShell(IgnoreErrors())) {
browsingContext = nsDocShell::Cast(mDocShell)->GetBrowsingContext();
}
return browsingContext.forget();
}
void nsFrameLoader::InitializeBrowserAPI() {
if (!OwnerIsMozBrowserFrame()) {
return;

Просмотреть файл

@ -48,6 +48,7 @@ namespace mozilla {
class OriginAttributes;
namespace dom {
class BrowsingContext;
class ChromeMessageSender;
class ContentParent;
class InProcessTabChildMessageManager;
@ -123,6 +124,8 @@ class nsFrameLoader final : public nsStubMutationObserver,
already_AddRefed<nsILoadContext> LoadContext();
already_AddRefed<mozilla::dom::BrowsingContext> GetBrowsingContext();
/**
* Start loading the frame. This method figures out what to load
* from the owner content in the frame loader.

Просмотреть файл

@ -588,6 +588,8 @@ parent:
sync SetPrefersReducedMotionOverrideForTest(bool aValue);
sync ResetPrefersReducedMotionOverrideForTest();
async RootBrowsingContext(BrowsingContextId aId);
child:
/**
* Notify the remote browser that it has been Show()n on this

Просмотреть файл

@ -538,6 +538,11 @@ nsresult TabChild::Init(mozIDOMWindowProxy* aParent) {
loadContext->SetRemoteTabs(mChromeFlags &
nsIWebBrowserChrome::CHROME_REMOTE_WINDOW);
// Send our browsing context to the parent process.
RefPtr<BrowsingContext> browsingContext =
nsDocShell::Cast(docShell)->GetBrowsingContext();
SendRootBrowsingContext(BrowsingContextId(browsingContext->Id()));
// Few lines before, baseWindow->Create() will end up creating a new
// window root in nsGlobalWindow::SetDocShell.
// Then this chrome event handler, will be inherited to inner windows.

Просмотреть файл

@ -101,6 +101,7 @@
#include "nsString.h"
#include "IHistory.h"
#include "mozilla/dom/WindowGlobalParent.h"
#include "mozilla/dom/ChromeBrowsingContext.h"
#ifdef XP_WIN
#include "mozilla/plugins/PluginWidgetParent.h"
@ -3390,6 +3391,14 @@ mozilla::ipc::IPCResult TabParent::RecvGetSystemFont(nsCString* aFontName) {
return IPC_OK();
}
mozilla::ipc::IPCResult TabParent::RecvRootBrowsingContext(
const BrowsingContextId& aId) {
MOZ_ASSERT(!mBrowsingContext, "May only set browsing context once!");
mBrowsingContext = ChromeBrowsingContext::Get(aId);
MOZ_ASSERT(mBrowsingContext, "Invalid ID!");
return IPC_OK();
}
NS_IMETHODIMP
FakeChannel::OnAuthAvailable(nsISupports* aContext,
nsIAuthInformation* aAuthInfo) {

Просмотреть файл

@ -67,6 +67,7 @@ class DataSourceSurface;
namespace dom {
class ChromeBrowsingContext;
class ClonedMessageData;
class nsIContentParent;
class Element;
@ -125,6 +126,8 @@ class TabParent final : public PBrowserParent,
nsIXULBrowserWindow* GetXULBrowserWindow();
ChromeBrowsingContext* GetBrowsingContext() { return mBrowsingContext; }
void Destroy();
void RemoveWindowListeners();
@ -584,6 +587,9 @@ class TabParent final : public PBrowserParent,
virtual mozilla::ipc::IPCResult RecvShowCanvasPermissionPrompt(
const nsCString& aFirstPartyURI) override;
virtual mozilla::ipc::IPCResult RecvRootBrowsingContext(
const BrowsingContextId& aId) override;
mozilla::ipc::IPCResult RecvSetSystemFont(
const nsCString& aFontName) override;
mozilla::ipc::IPCResult RecvGetSystemFont(nsCString* aFontName) override;
@ -661,6 +667,9 @@ class TabParent final : public PBrowserParent,
// dispatch message manager messages during this time.
RefPtr<nsFrameLoader> mFrameLoader;
// The root browsing context loaded in this TabParent.
RefPtr<ChromeBrowsingContext> mBrowsingContext;
TabId mTabId;
// When loading a new tab or window via window.open, the child is

Просмотреть файл

@ -33,6 +33,12 @@ interface FrameLoader {
*/
readonly attribute LoadContext loadContext;
/**
* Get the root BrowsingContext within the frame.
* This may be null immediately after creating a remote frame.
*/
readonly attribute BrowsingContext? browsingContext;
/**
* Get the ParentSHistory for the nsFrameLoader. May return null if this
* frameloader is not for a toplevel frame.