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);
}
// 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 =
NullPrincipal::CreateWithInheritedAttributes(attrs,
/* isFirstParty */ false);
NullPrincipal::CreateWithInheritedAttributes(
target->OriginAttributesRef(),
/* isFirstParty */ false);
WindowGlobalInit windowInit =
WindowGlobalActor::AboutBlankInitializer(target, initialPrincipal);

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

@ -1156,6 +1156,9 @@ nsresult nsFrameLoader::SwapWithOtherRemoteLoader(
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
// for this operation. In this case, the browser code should already have set
// 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
// usercontextid attribute before comparing our originAttributes with the
// other one.
OriginAttributes ourOriginAttributes = browserParent->OriginAttributesRef();
OriginAttributes ourOriginAttributes = ourBc->OriginAttributesRef();
rv = PopulateOriginContextIdsFromAttributes(ourOriginAttributes);
NS_ENSURE_SUCCESS(rv, rv);
OriginAttributes otherOriginAttributes =
otherBrowserParent->OriginAttributesRef();
OriginAttributes otherOriginAttributes = otherBc->OriginAttributesRef();
rv = aOther->PopulateOriginContextIdsFromAttributes(otherOriginAttributes);
NS_ENSURE_SUCCESS(rv, rv);
@ -3275,7 +3277,6 @@ nsresult nsFrameLoader::GetNewTabContext(MutableTabContext* aTabContext,
NS_ENSURE_STATE(parentContext);
MOZ_ASSERT(mPendingBrowsingContext->EverAttached());
OriginAttributes attrs = mPendingBrowsingContext->OriginAttributesRef();
UIStateChangeType showFocusRings = UIStateChangeType_NoChange;
uint64_t chromeOuterWindowID = 0;
@ -3296,9 +3297,8 @@ nsresult nsFrameLoader::GetNewTabContext(MutableTabContext* aTabContext,
uint32_t maxTouchPoints = BrowserParent::GetMaxTouchPoints(mOwnerContent);
bool tabContextUpdated =
aTabContext->SetTabContext(chromeOuterWindowID, showFocusRings, attrs,
presentationURLStr, maxTouchPoints);
bool tabContextUpdated = aTabContext->SetTabContext(
chromeOuterWindowID, showFocusRings, presentationURLStr, maxTouchPoints);
NS_ENSURE_STATE(tabContextUpdated);
return NS_OK;

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

@ -37,20 +37,9 @@ nsresult BrowserBridgeParent::InitWithProcess(
RefPtr<CanonicalBrowsingContext> browsingContext =
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;
OriginAttributes attrs;
attrs = Manager()->OriginAttributesRef();
RefPtr<nsIPrincipal> principal = Manager()->GetContentPrincipal();
if (principal) {
attrs.SetFirstPartyDomain(
true, principal->OriginAttributesRef().mFirstPartyDomain);
}
tabContext.SetTabContext(Manager()->ChromeOuterWindowID(),
Manager()->ShowFocusRings(), attrs, aPresentationURL,
Manager()->ShowFocusRings(), aPresentationURL,
Manager()->GetMaxTouchPoints());
// 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),
nullptr); // HandleWidgetEvent
mWebBrowser = nsWebBrowser::Create(this, mPuppetWidget, OriginAttributesRef(),
mBrowsingContext, aInitialWindowChild);
mWebBrowser = nsWebBrowser::Create(this, mPuppetWidget, mBrowsingContext,
aInitialWindowChild);
nsIWebBrowser* webBrowser = mWebBrowser;
mWebNav = do_QueryInterface(webBrowser);
@ -526,8 +526,6 @@ nsresult BrowserChild::Init(mozIDOMWindowProxy* aParent,
#ifdef DEBUG
nsCOMPtr<nsILoadContext> loadContext = do_GetInterface(WebNavigation());
MOZ_ASSERT(loadContext);
MOZ_ASSERT(loadContext->UsePrivateBrowsing() ==
(OriginAttributesRef().mPrivateBrowsingId > 0));
MOZ_ASSERT(loadContext->UseRemoteTabs() ==
!!(mChromeFlags & nsIWebBrowserChrome::CHROME_REMOTE_WINDOW));
MOZ_ASSERT(loadContext->UseRemoteSubframes() ==

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

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

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

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

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

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

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

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

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

@ -44,13 +44,6 @@ class TabContext {
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
* created for presented content
@ -78,19 +71,8 @@ class TabContext {
*/
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,
UIStateChangeType aShowFocusRings,
const OriginAttributes& aOriginAttributes,
const nsAString& aPresentationURL,
uint32_t aMaxTouchPoints);
@ -132,11 +114,6 @@ class TabContext {
int32_t mJSPluginID;
/**
* OriginAttributes of the top level tab docShell
*/
OriginAttributes mOriginAttributes;
/**
* The requested presentation URL.
*/
@ -166,21 +143,15 @@ class MutableTabContext : public TabContext {
bool SetTabContext(uint64_t aChromeOuterWindowID,
UIStateChangeType aShowFocusRings,
const OriginAttributes& aOriginAttributes,
const nsAString& aPresentationURL,
uint32_t aMaxTouchPoints) {
return TabContext::SetTabContext(aChromeOuterWindowID, aShowFocusRings,
aOriginAttributes, aPresentationURL,
aMaxTouchPoints);
aPresentationURL, aMaxTouchPoints);
}
bool SetTabContextForJSPluginFrame(uint32_t aJSPluginID) {
return TabContext::SetTabContextForJSPluginFrame(aJSPluginID);
}
void SetFirstPartyDomainAttributes(const nsAString& aFirstPartyDomain) {
TabContext::SetFirstPartyDomainAttributes(aFirstPartyDomain);
}
};
/**

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

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

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

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

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

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