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
Родитель 568787b95f
Коммит 6b41e6135b
7 изменённых файлов: 48 добавлений и 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"
@ -3174,6 +3175,19 @@ 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()
{

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

@ -48,6 +48,7 @@ namespace mozilla {
class OriginAttributes;
namespace dom {
class BrowsingContext;
class ChromeMessageSender;
class ContentParent;
class InProcessTabChildMessageManager;
@ -121,6 +122,8 @@ public:
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.

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

@ -579,6 +579,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

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

@ -586,6 +586,11 @@ 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.

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

@ -100,6 +100,7 @@
#include "ProcessPriorityManager.h"
#include "nsString.h"
#include "IHistory.h"
#include "mozilla/dom/ChromeBrowsingContext.h"
#ifdef XP_WIN
#include "mozilla/plugins/PluginWidgetParent.h"
@ -3723,6 +3724,15 @@ 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;
@ -130,6 +131,8 @@ public:
nsIXULBrowserWindow* GetXULBrowserWindow();
ChromeBrowsingContext* GetBrowsingContext() { return mBrowsingContext; }
void Destroy();
void RemoveWindowListeners();
@ -623,6 +626,8 @@ protected:
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
@ -698,6 +703,9 @@ private:
// 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.