Bug 1633820 - Part 4: Remove OriginAttributes from TabContext, r=kmag

This information is now redundant with 'BrowsingContext', meaning that it can be
omitted from the 'TabContext'.

Differential Revision: https://phabricator.services.mozilla.com/D72934
This commit is contained in:
Nika Layzell 2020-05-06 17:41:02 +00:00
Родитель da2aae6af5
Коммит e6c0899f5d
12 изменённых файлов: 22 добавлений и 102 удалений

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

@ -403,18 +403,10 @@ void CanonicalBrowsingContext::PendingRemotenessChange::Complete(
callback, callback); callback, callback);
} }
// FIXME: We should get the correct principal for the to-be-created window so
// we can avoid creating unnecessary extra windows in the new process.
OriginAttributes attrs = embedderBrowser->OriginAttributesRef();
RefPtr<nsIPrincipal> principal = embedderBrowser->GetContentPrincipal();
if (principal) {
attrs.SetFirstPartyDomain(
true, principal->OriginAttributesRef().mFirstPartyDomain);
}
nsCOMPtr<nsIPrincipal> initialPrincipal = nsCOMPtr<nsIPrincipal> initialPrincipal =
NullPrincipal::CreateWithInheritedAttributes(attrs, NullPrincipal::CreateWithInheritedAttributes(
/* isFirstParty */ false); target->OriginAttributesRef(),
/* isFirstParty */ false);
WindowGlobalInit windowInit = WindowGlobalInit windowInit =
WindowGlobalActor::AboutBlankInitializer(target, initialPrincipal); WindowGlobalActor::AboutBlankInitializer(target, initialPrincipal);

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

@ -1156,6 +1156,9 @@ nsresult nsFrameLoader::SwapWithOtherRemoteLoader(
return NS_ERROR_NOT_IMPLEMENTED; return NS_ERROR_NOT_IMPLEMENTED;
} }
RefPtr<BrowsingContext> ourBc = browserParent->GetBrowsingContext();
RefPtr<BrowsingContext> otherBc = otherBrowserParent->GetBrowsingContext();
// When we swap docShells, maybe we have to deal with a new page created just // When we swap docShells, maybe we have to deal with a new page created just
// for this operation. In this case, the browser code should already have set // for this operation. In this case, the browser code should already have set
// the correct userContextId attribute value in the owning element, but our // the correct userContextId attribute value in the owning element, but our
@ -1164,12 +1167,11 @@ nsresult nsFrameLoader::SwapWithOtherRemoteLoader(
// This is the reason why now we must retrieve the correct value from the // This is the reason why now we must retrieve the correct value from the
// usercontextid attribute before comparing our originAttributes with the // usercontextid attribute before comparing our originAttributes with the
// other one. // other one.
OriginAttributes ourOriginAttributes = browserParent->OriginAttributesRef(); OriginAttributes ourOriginAttributes = ourBc->OriginAttributesRef();
rv = PopulateOriginContextIdsFromAttributes(ourOriginAttributes); rv = PopulateOriginContextIdsFromAttributes(ourOriginAttributes);
NS_ENSURE_SUCCESS(rv, rv); NS_ENSURE_SUCCESS(rv, rv);
OriginAttributes otherOriginAttributes = OriginAttributes otherOriginAttributes = otherBc->OriginAttributesRef();
otherBrowserParent->OriginAttributesRef();
rv = aOther->PopulateOriginContextIdsFromAttributes(otherOriginAttributes); rv = aOther->PopulateOriginContextIdsFromAttributes(otherOriginAttributes);
NS_ENSURE_SUCCESS(rv, rv); NS_ENSURE_SUCCESS(rv, rv);
@ -3275,7 +3277,6 @@ nsresult nsFrameLoader::GetNewTabContext(MutableTabContext* aTabContext,
NS_ENSURE_STATE(parentContext); NS_ENSURE_STATE(parentContext);
MOZ_ASSERT(mPendingBrowsingContext->EverAttached()); MOZ_ASSERT(mPendingBrowsingContext->EverAttached());
OriginAttributes attrs = mPendingBrowsingContext->OriginAttributesRef();
UIStateChangeType showFocusRings = UIStateChangeType_NoChange; UIStateChangeType showFocusRings = UIStateChangeType_NoChange;
uint64_t chromeOuterWindowID = 0; uint64_t chromeOuterWindowID = 0;
@ -3296,9 +3297,8 @@ nsresult nsFrameLoader::GetNewTabContext(MutableTabContext* aTabContext,
uint32_t maxTouchPoints = BrowserParent::GetMaxTouchPoints(mOwnerContent); uint32_t maxTouchPoints = BrowserParent::GetMaxTouchPoints(mOwnerContent);
bool tabContextUpdated = bool tabContextUpdated = aTabContext->SetTabContext(
aTabContext->SetTabContext(chromeOuterWindowID, showFocusRings, attrs, chromeOuterWindowID, showFocusRings, presentationURLStr, maxTouchPoints);
presentationURLStr, maxTouchPoints);
NS_ENSURE_STATE(tabContextUpdated); NS_ENSURE_STATE(tabContextUpdated);
return NS_OK; return NS_OK;

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

@ -37,20 +37,9 @@ nsresult BrowserBridgeParent::InitWithProcess(
RefPtr<CanonicalBrowsingContext> browsingContext = RefPtr<CanonicalBrowsingContext> browsingContext =
aWindowInit.browsingContext().get_canonical(); aWindowInit.browsingContext().get_canonical();
// We can inherit most TabContext fields for the new BrowserParent actor from
// our Manager BrowserParent. We also need to sync the first party domain if
// the content principal exists.
MutableTabContext tabContext; MutableTabContext tabContext;
OriginAttributes attrs;
attrs = Manager()->OriginAttributesRef();
RefPtr<nsIPrincipal> principal = Manager()->GetContentPrincipal();
if (principal) {
attrs.SetFirstPartyDomain(
true, principal->OriginAttributesRef().mFirstPartyDomain);
}
tabContext.SetTabContext(Manager()->ChromeOuterWindowID(), tabContext.SetTabContext(Manager()->ChromeOuterWindowID(),
Manager()->ShowFocusRings(), attrs, aPresentationURL, Manager()->ShowFocusRings(), aPresentationURL,
Manager()->GetMaxTouchPoints()); Manager()->GetMaxTouchPoints());
// Ensure that our content process is subscribed to our newly created // Ensure that our content process is subscribed to our newly created

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

@ -489,8 +489,8 @@ nsresult BrowserChild::Init(mozIDOMWindowProxy* aParent,
LayoutDeviceIntRect(0, 0, 0, 0), LayoutDeviceIntRect(0, 0, 0, 0),
nullptr); // HandleWidgetEvent nullptr); // HandleWidgetEvent
mWebBrowser = nsWebBrowser::Create(this, mPuppetWidget, OriginAttributesRef(), mWebBrowser = nsWebBrowser::Create(this, mPuppetWidget, mBrowsingContext,
mBrowsingContext, aInitialWindowChild); aInitialWindowChild);
nsIWebBrowser* webBrowser = mWebBrowser; nsIWebBrowser* webBrowser = mWebBrowser;
mWebNav = do_QueryInterface(webBrowser); mWebNav = do_QueryInterface(webBrowser);
@ -526,8 +526,6 @@ nsresult BrowserChild::Init(mozIDOMWindowProxy* aParent,
#ifdef DEBUG #ifdef DEBUG
nsCOMPtr<nsILoadContext> loadContext = do_GetInterface(WebNavigation()); nsCOMPtr<nsILoadContext> loadContext = do_GetInterface(WebNavigation());
MOZ_ASSERT(loadContext); MOZ_ASSERT(loadContext);
MOZ_ASSERT(loadContext->UsePrivateBrowsing() ==
(OriginAttributesRef().mPrivateBrowsingId > 0));
MOZ_ASSERT(loadContext->UseRemoteTabs() == MOZ_ASSERT(loadContext->UseRemoteTabs() ==
!!(mChromeFlags & nsIWebBrowserChrome::CHROME_REMOTE_WINDOW)); !!(mChromeFlags & nsIWebBrowserChrome::CHROME_REMOTE_WINDOW));
MOZ_ASSERT(loadContext->UseRemoteSubframes() == MOZ_ASSERT(loadContext->UseRemoteSubframes() ==

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

@ -983,13 +983,11 @@ nsresult ContentChild::ProvideWindowCommon(
if (aTabOpener) { if (aTabOpener) {
newTabContext.SetTabContext( newTabContext.SetTabContext(
aTabOpener->ChromeOuterWindowID(), aTabOpener->ShowFocusRings(), aTabOpener->ChromeOuterWindowID(), aTabOpener->ShowFocusRings(),
browsingContext->OriginAttributesRef(), aTabOpener->PresentationURL(), aTabOpener->PresentationURL(), aTabOpener->MaxTouchPoints());
aTabOpener->MaxTouchPoints());
} else { } else {
newTabContext.SetTabContext( newTabContext.SetTabContext(
/* chromeOuterWindowID */ 0, /* chromeOuterWindowID */ 0,
/* showFocusRings */ UIStateChangeType_NoChange, /* showFocusRings */ UIStateChangeType_NoChange,
browsingContext->OriginAttributesRef(),
/* presentationURL */ EmptyString(), /* presentationURL */ EmptyString(),
/* maxTouchPoints */ 0); /* maxTouchPoints */ 0);
} }

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

@ -1283,7 +1283,7 @@ already_AddRefed<RemoteBrowser> ContentParent::CreateBrowser(
cpm->RegisterRemoteFrame(browserParent); cpm->RegisterRemoteFrame(browserParent);
nsCOMPtr<nsIPrincipal> initialPrincipal = nsCOMPtr<nsIPrincipal> initialPrincipal =
NullPrincipal::Create(aContext.OriginAttributesRef()); NullPrincipal::Create(aBrowsingContext->OriginAttributesRef());
WindowGlobalInit windowInit = WindowGlobalActor::AboutBlankInitializer( WindowGlobalInit windowInit = WindowGlobalActor::AboutBlankInitializer(
aBrowsingContext, initialPrincipal); aBrowsingContext, initialPrincipal);

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

@ -25,9 +25,6 @@ struct PopupIPCTabContext
// An IPCTabContext which corresponds to an app, browser, or normal frame. // An IPCTabContext which corresponds to an app, browser, or normal frame.
struct FrameIPCTabContext struct FrameIPCTabContext
{ {
// The originAttributes dictionary.
OriginAttributes originAttributes;
uint64_t chromeOuterWindowID; uint64_t chromeOuterWindowID;
// The requested presentation URL. // The requested presentation URL.

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

@ -41,33 +41,17 @@ bool TabContext::SetTabContext(const TabContext& aContext) {
return true; return true;
} }
void TabContext::SetPrivateBrowsingAttributes(bool aIsPrivateBrowsing) {
mOriginAttributes.SyncAttributesWithPrivateBrowsing(aIsPrivateBrowsing);
}
void TabContext::SetFirstPartyDomainAttributes(
const nsAString& aFirstPartyDomain) {
mOriginAttributes.SetFirstPartyDomain(true, aFirstPartyDomain);
}
bool TabContext::UpdateTabContextAfterSwap(const TabContext& aContext) { bool TabContext::UpdateTabContextAfterSwap(const TabContext& aContext) {
// This is only used after already initialized. // This is only used after already initialized.
MOZ_ASSERT(mInitialized); MOZ_ASSERT(mInitialized);
// The only permissable changes are to mChromeOuterWindowID. All other fields // The only permissable changes are to mChromeOuterWindowID. All other fields
// must match for the change to be accepted. // must match for the change to be accepted.
if (aContext.mOriginAttributes != mOriginAttributes) {
return false;
}
mChromeOuterWindowID = aContext.mChromeOuterWindowID; mChromeOuterWindowID = aContext.mChromeOuterWindowID;
return true; return true;
} }
const OriginAttributes& TabContext::OriginAttributesRef() const {
return mOriginAttributes;
}
const nsAString& TabContext::PresentationURL() const { const nsAString& TabContext::PresentationURL() const {
return mPresentationURL; return mPresentationURL;
} }
@ -76,14 +60,12 @@ UIStateChangeType TabContext::ShowFocusRings() const { return mShowFocusRings; }
bool TabContext::SetTabContext(uint64_t aChromeOuterWindowID, bool TabContext::SetTabContext(uint64_t aChromeOuterWindowID,
UIStateChangeType aShowFocusRings, UIStateChangeType aShowFocusRings,
const OriginAttributes& aOriginAttributes,
const nsAString& aPresentationURL, const nsAString& aPresentationURL,
uint32_t aMaxTouchPoints) { uint32_t aMaxTouchPoints) {
NS_ENSURE_FALSE(mInitialized, false); NS_ENSURE_FALSE(mInitialized, false);
mInitialized = true; mInitialized = true;
mChromeOuterWindowID = aChromeOuterWindowID; mChromeOuterWindowID = aChromeOuterWindowID;
mOriginAttributes = aOriginAttributes;
mPresentationURL = aPresentationURL; mPresentationURL = aPresentationURL;
mShowFocusRings = aShowFocusRings; mShowFocusRings = aShowFocusRings;
mMaxTouchPoints = aMaxTouchPoints; mMaxTouchPoints = aMaxTouchPoints;
@ -103,16 +85,15 @@ IPCTabContext TabContext::AsIPCTabContext() const {
return IPCTabContext(JSPluginFrameIPCTabContext(mJSPluginID)); return IPCTabContext(JSPluginFrameIPCTabContext(mJSPluginID));
} }
return IPCTabContext( return IPCTabContext(FrameIPCTabContext(mChromeOuterWindowID,
FrameIPCTabContext(mOriginAttributes, mChromeOuterWindowID, mPresentationURL, mShowFocusRings,
mPresentationURL, mShowFocusRings, mMaxTouchPoints)); mMaxTouchPoints));
} }
MaybeInvalidTabContext::MaybeInvalidTabContext(const IPCTabContext& aParams) MaybeInvalidTabContext::MaybeInvalidTabContext(const IPCTabContext& aParams)
: mInvalidReason(nullptr) { : mInvalidReason(nullptr) {
uint64_t chromeOuterWindowID = 0; uint64_t chromeOuterWindowID = 0;
int32_t jsPluginId = -1; int32_t jsPluginId = -1;
OriginAttributes originAttributes;
nsAutoString presentationURL; nsAutoString presentationURL;
UIStateChangeType showFocusRings = UIStateChangeType_NoChange; UIStateChangeType showFocusRings = UIStateChangeType_NoChange;
uint32_t maxTouchPoints = 0; uint32_t maxTouchPoints = 0;
@ -133,7 +114,6 @@ MaybeInvalidTabContext::MaybeInvalidTabContext(const IPCTabContext& aParams)
return; return;
} }
originAttributes = context->mOriginAttributes;
chromeOuterWindowID = ipcContext.chromeOuterWindowID(); chromeOuterWindowID = ipcContext.chromeOuterWindowID();
break; break;
} }
@ -150,7 +130,6 @@ MaybeInvalidTabContext::MaybeInvalidTabContext(const IPCTabContext& aParams)
chromeOuterWindowID = ipcContext.chromeOuterWindowID(); chromeOuterWindowID = ipcContext.chromeOuterWindowID();
presentationURL = ipcContext.presentationURL(); presentationURL = ipcContext.presentationURL();
showFocusRings = ipcContext.showFocusRings(); showFocusRings = ipcContext.showFocusRings();
originAttributes = ipcContext.originAttributes();
maxTouchPoints = ipcContext.maxTouchPoints(); maxTouchPoints = ipcContext.maxTouchPoints();
break; break;
} }
@ -176,8 +155,7 @@ MaybeInvalidTabContext::MaybeInvalidTabContext(const IPCTabContext& aParams)
rv = mTabContext.SetTabContextForJSPluginFrame(jsPluginId); rv = mTabContext.SetTabContextForJSPluginFrame(jsPluginId);
} else { } else {
rv = mTabContext.SetTabContext(chromeOuterWindowID, showFocusRings, rv = mTabContext.SetTabContext(chromeOuterWindowID, showFocusRings,
originAttributes, presentationURL, presentationURL, maxTouchPoints);
maxTouchPoints);
} }
if (!rv) { if (!rv) {
mInvalidReason = "Couldn't initialize TabContext."; mInvalidReason = "Couldn't initialize TabContext.";

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

@ -44,13 +44,6 @@ class TabContext {
uint64_t ChromeOuterWindowID() const; uint64_t ChromeOuterWindowID() const;
/**
* OriginAttributesRef() returns the OriginAttributes of this frame to
* the caller. This is used to store any attribute associated with the frame's
* docshell.
*/
const OriginAttributes& OriginAttributesRef() const;
/** /**
* Returns the presentation URL associated with the tab if this tab is * Returns the presentation URL associated with the tab if this tab is
* created for presented content * created for presented content
@ -78,19 +71,8 @@ class TabContext {
*/ */
bool SetTabContext(const TabContext& aContext); bool SetTabContext(const TabContext& aContext);
/**
* Set the tab context's origin attributes to a private browsing value.
*/
void SetPrivateBrowsingAttributes(bool aIsPrivateBrowsing);
/**
* Set the first party domain of the tab context's origin attributes.
*/
void SetFirstPartyDomainAttributes(const nsAString& aFirstPartyDomain);
bool SetTabContext(uint64_t aChromeOuterWindowID, bool SetTabContext(uint64_t aChromeOuterWindowID,
UIStateChangeType aShowFocusRings, UIStateChangeType aShowFocusRings,
const OriginAttributes& aOriginAttributes,
const nsAString& aPresentationURL, const nsAString& aPresentationURL,
uint32_t aMaxTouchPoints); uint32_t aMaxTouchPoints);
@ -132,11 +114,6 @@ class TabContext {
int32_t mJSPluginID; int32_t mJSPluginID;
/**
* OriginAttributes of the top level tab docShell
*/
OriginAttributes mOriginAttributes;
/** /**
* The requested presentation URL. * The requested presentation URL.
*/ */
@ -166,21 +143,15 @@ class MutableTabContext : public TabContext {
bool SetTabContext(uint64_t aChromeOuterWindowID, bool SetTabContext(uint64_t aChromeOuterWindowID,
UIStateChangeType aShowFocusRings, UIStateChangeType aShowFocusRings,
const OriginAttributes& aOriginAttributes,
const nsAString& aPresentationURL, const nsAString& aPresentationURL,
uint32_t aMaxTouchPoints) { uint32_t aMaxTouchPoints) {
return TabContext::SetTabContext(aChromeOuterWindowID, aShowFocusRings, return TabContext::SetTabContext(aChromeOuterWindowID, aShowFocusRings,
aOriginAttributes, aPresentationURL, aPresentationURL, aMaxTouchPoints);
aMaxTouchPoints);
} }
bool SetTabContextForJSPluginFrame(uint32_t aJSPluginID) { bool SetTabContextForJSPluginFrame(uint32_t aJSPluginID) {
return TabContext::SetTabContextForJSPluginFrame(aJSPluginID); return TabContext::SetTabContextForJSPluginFrame(aJSPluginID);
} }
void SetFirstPartyDomainAttributes(const nsAString& aFirstPartyDomain) {
TabContext::SetFirstPartyDomainAttributes(aFirstPartyDomain);
}
}; };
/** /**

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

@ -97,7 +97,6 @@ nsIWidget* nsWebBrowser::EnsureWidget() {
/* static */ /* static */
already_AddRefed<nsWebBrowser> nsWebBrowser::Create( already_AddRefed<nsWebBrowser> nsWebBrowser::Create(
nsIWebBrowserChrome* aContainerWindow, nsIWidget* aParentWidget, nsIWebBrowserChrome* aContainerWindow, nsIWidget* aParentWidget,
const OriginAttributes& aOriginAttributes,
dom::BrowsingContext* aBrowsingContext, dom::BrowsingContext* aBrowsingContext,
dom::WindowGlobalChild* aInitialWindowChild, dom::WindowGlobalChild* aInitialWindowChild,
bool aDisableHistory /* = false */) { bool aDisableHistory /* = false */) {
@ -124,7 +123,6 @@ already_AddRefed<nsWebBrowser> nsWebBrowser::Create(
if (NS_WARN_IF(!docShell)) { if (NS_WARN_IF(!docShell)) {
return nullptr; return nullptr;
} }
MOZ_ASSERT(aBrowsingContext->OriginAttributesRef() == aOriginAttributes);
browser->SetDocShell(docShell); browser->SetDocShell(docShell);
// get the system default window background colour // get the system default window background colour

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

@ -108,7 +108,6 @@ class nsWebBrowser final : public nsIWebBrowser,
static already_AddRefed<nsWebBrowser> Create( static already_AddRefed<nsWebBrowser> Create(
nsIWebBrowserChrome* aContainerWindow, nsIWidget* aParentWidget, nsIWebBrowserChrome* aContainerWindow, nsIWidget* aParentWidget,
const mozilla::OriginAttributes& aOriginAttributes,
mozilla::dom::BrowsingContext* aBrowsingContext, mozilla::dom::BrowsingContext* aBrowsingContext,
mozilla::dom::WindowGlobalChild* aInitialWindowChild, mozilla::dom::WindowGlobalChild* aInitialWindowChild,
bool aDisableHistory = false); bool aDisableHistory = false);

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

@ -457,8 +457,8 @@ nsAppShellService::CreateWindowlessBrowser(bool aIsChrome,
* an associated doc shell, which is what we're interested in. * an associated doc shell, which is what we're interested in.
*/ */
nsCOMPtr<nsIWebBrowser> browser = nsWebBrowser::Create( nsCOMPtr<nsIWebBrowser> browser = nsWebBrowser::Create(
stub, widget, OriginAttributes(), browsingContext, stub, widget, browsingContext, nullptr /* initialWindowChild */,
nullptr /* initialWindowChild */, true /* disable history */); true /* disable history */);
if (NS_WARN_IF(!browser)) { if (NS_WARN_IF(!browser)) {
NS_ERROR("Couldn't create instance of nsWebBrowser!"); NS_ERROR("Couldn't create instance of nsWebBrowser!");