Skip to content

Commit

Permalink
Bug 1238160 - Set frame type on TabContext. r=billm,mayhemer
Browse files Browse the repository at this point in the history
This change renames TabContext::IsBrowserElement to IsIsolatedMozBrowserElement.
Other methods that pass these values around also have name changes.

Adds TabContext::IsMozBrowserElement which is set by the frame loader for all
browser frames.  This is in contrast to its previous implementation, which has
since been renamed IsIsolatedMozBrowserElement, since it checks isolated state
in OriginAttributes.

TabContext methods related to browser elements (and their callers) are updated
to use IsIsolatedMozBrowserElement when check isolation / origins and
IsMozBrowserElement when checking frame types.

MozReview-Commit-ID: DDMZTkSn5yd
  • Loading branch information
jryans committed Mar 2, 2016
1 parent 777c113 commit 764b9f1
Show file tree
Hide file tree
Showing 17 changed files with 123 additions and 76 deletions.
6 changes: 5 additions & 1 deletion dom/base/nsFrameLoader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3118,7 +3118,11 @@ nsFrameLoader::GetNewTabContext(MutableTabContext* aTabContext,
}

bool tabContextUpdated =
aTabContext->SetTabContext(ownApp, containingApp, attrs, signedPkgOrigin);
aTabContext->SetTabContext(OwnerIsMozBrowserFrame(),
ownApp,
containingApp,
attrs,
signedPkgOrigin);
NS_ENSURE_STATE(tabContextUpdated);

return NS_OK;
Expand Down
2 changes: 1 addition & 1 deletion dom/ipc/ContentChild.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -806,7 +806,7 @@ ContentChild::ProvideWindowCommon(TabChild* aTabOpener,
PopupIPCTabContext context;
openerTabId = aTabOpener->GetTabId();
context.opener() = openerTabId;
context.isBrowserElement() = aTabOpener->IsBrowserElement();
context.isMozBrowserElement() = aTabOpener->IsMozBrowserElement();
ipcContext = new IPCTabContext(context);
} else {
// It's possible to not have a TabChild opener in the case
Expand Down
8 changes: 4 additions & 4 deletions dom/ipc/ContentParent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1122,19 +1122,19 @@ ContentParent::CreateBrowserOrApp(const TabContext& aContext,
openerTabId = TabParent::GetTabIdFrom(docShell);
}

if (aContext.IsBrowserElement() || !aContext.HasOwnApp()) {
if (aContext.IsMozBrowserElement() || !aContext.HasOwnApp()) {
RefPtr<TabParent> tp;
RefPtr<nsIContentParent> constructorSender;
if (isInContentProcess) {
MOZ_ASSERT(aContext.IsBrowserElement());
MOZ_ASSERT(aContext.IsMozBrowserElement());
constructorSender = CreateContentBridgeParent(aContext, initialPriority,
openerTabId, &tabId);
} else {
if (aOpenerContentParent) {
constructorSender = aOpenerContentParent;
} else {
constructorSender =
GetNewOrUsedBrowserProcess(aContext.IsBrowserElement(),
GetNewOrUsedBrowserProcess(aContext.IsMozBrowserElement(),
initialPriority);
if (!constructorSender) {
return nullptr;
Expand Down Expand Up @@ -5334,7 +5334,7 @@ ContentParent::RecvCreateWindow(PBrowserParent* aThisTab,
thisTabParent = TabParent::GetFrom(aThisTab);
}

if (NS_WARN_IF(thisTabParent && thisTabParent->IsBrowserOrApp())) {
if (NS_WARN_IF(thisTabParent && thisTabParent->IsMozBrowserOrApp())) {
return false;
}

Expand Down
19 changes: 12 additions & 7 deletions dom/ipc/PTabContext.ipdlh
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,21 @@ namespace dom {
// An IPCTabContext which corresponds to a PBrowser opened by a child when it
// receives window.open().
//
// If isBrowserElement is false, this PopupIPCTabContext corresponds to an app
// frame, and the frame's app-id and app-frame-owner-app-id will be equal to the
// opener's values.
// If isMozBrowserElement is false, this PopupIPCTabContext is either a
// <xul:browser> or an app frame. The frame's app-id and app-frame-owner-app-id
// will be equal to the opener's values. For a <xul:browser>, those app IDs
// will be NO_APP_ID.
//
// If isBrowserElement is true, the frame's browserFrameOwnerAppId will be equal
// to the opener's app-id.
// If isMozBrowserElement is true, the frame's browserFrameOwnerAppId will be
// equal to the opener's app-id.
//
// It's an error to set isBrowserElement == false if opener is a browser
// It's an error to set isMozBrowserElement == false if opener is a mozbrowser
// element. Such a PopupIPCTabContext should be rejected by code which receives
// it.
struct PopupIPCTabContext
{
PBrowserOrId opener;
bool isBrowserElement;
bool isMozBrowserElement;
};

// An IPCTabContext which corresponds to an app, browser, or normal frame.
Expand All @@ -42,6 +43,10 @@ struct FrameIPCTabContext
// This value would be empty if the TabContext doesn't own a signed
// package.
nsCString signedPkgOriginNoSuffix;

// Whether this is a mozbrowser frame. <iframe mozbrowser mozapp> and
// <xul:browser> are not considered to be mozbrowser frames.
bool isMozBrowserElement;
};

// XXXcatalinb: This is only used by ServiceWorkerClients::OpenWindow.
Expand Down
14 changes: 6 additions & 8 deletions dom/ipc/TabChild.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -549,7 +549,7 @@ TabChild::Create(nsIContentChild* aManager,
{
if (sPreallocatedTab &&
sPreallocatedTab->mChromeFlags == aChromeFlags &&
aContext.IsBrowserOrApp()) {
aContext.IsMozBrowserOrApp()) {

RefPtr<TabChild> child = sPreallocatedTab.get();
sPreallocatedTab = nullptr;
Expand Down Expand Up @@ -865,11 +865,9 @@ TabChild::NotifyTabContextUpdated()
if (docShell) {
// nsDocShell will do the right thing if we pass NO_APP_ID or
// UNKNOWN_APP_ID for aOwnOrContainingAppId.
if (IsBrowserElement()) {
if (IsMozBrowserElement()) {
docShell->SetIsBrowserInsideApp(BrowserOwnerAppId());
// TODO: Wants to call TabContext::IsIsolatedMozBrowserElement() based
// on isolation in principal, which is added in a later patch.
docShell->SetIsInIsolatedMozBrowserElement(IsBrowserElement());
docShell->SetIsInIsolatedMozBrowserElement(IsIsolatedMozBrowserElement());
} else {
docShell->SetIsApp(OwnAppId());
}
Expand Down Expand Up @@ -1506,7 +1504,7 @@ TabChild::ApplyShowInfo(const ShowInfo& aInfo)
nsCOMPtr<nsIDocShell> docShell = do_GetInterface(WebNavigation());
if (docShell) {
nsCOMPtr<nsIDocShellTreeItem> item = do_GetInterface(docShell);
if (IsBrowserOrApp()) {
if (IsMozBrowserOrApp()) {
// B2G allows window.name to be set by changing the name attribute on the
// <iframe mozbrowser> element. window.open calls cause this attribute to
// be set to the correct value. A normal <xul:browser> element has no such
Expand Down Expand Up @@ -1543,7 +1541,7 @@ TabChild::MaybeRequestPreinitCamera()
{
// Check if this tab is an app (not a browser frame) and will use the
// `camera` permission,
if (IsBrowserElement()) {
if (IsIsolatedMozBrowserElement()) {
return;
}

Expand Down Expand Up @@ -2528,7 +2526,7 @@ TabChild::InitTabChildGlobal(FrameScriptLoading aScriptLoading)
mTriedBrowserInit = true;
// Initialize the child side of the browser element machinery,
// if appropriate.
if (IsBrowserOrApp()) {
if (IsMozBrowserOrApp()) {
RecvLoadRemoteScript(BROWSER_ELEMENT_CHILD_SCRIPT, true);
}
}
Expand Down
39 changes: 27 additions & 12 deletions dom/ipc/TabContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,21 +22,28 @@ namespace dom {

TabContext::TabContext()
: mInitialized(false)
, mIsMozBrowserElement(false)
, mContainingAppId(NO_APP_ID)
, mOriginAttributes()
{
}

bool
TabContext::IsBrowserElement() const
TabContext::IsMozBrowserElement() const
{
return mIsMozBrowserElement;
}

bool
TabContext::IsIsolatedMozBrowserElement() const
{
return mOriginAttributes.mInIsolatedMozBrowser;
}

bool
TabContext::IsBrowserOrApp() const
TabContext::IsMozBrowserOrApp() const
{
return HasOwnApp() || IsBrowserElement();
return HasOwnApp() || IsMozBrowserElement();
}

uint32_t
Expand All @@ -62,7 +69,7 @@ TabContext::HasOwnApp() const
uint32_t
TabContext::BrowserOwnerAppId() const
{
if (IsBrowserElement()) {
if (IsMozBrowserElement()) {
return mContainingAppId;
}
return NO_APP_ID;
Expand All @@ -72,7 +79,7 @@ already_AddRefed<mozIApplication>
TabContext::GetBrowserOwnerApp() const
{
nsCOMPtr<mozIApplication> ownerApp;
if (IsBrowserElement()) {
if (IsMozBrowserElement()) {
ownerApp = mContainingApp;
}
return ownerApp.forget();
Expand Down Expand Up @@ -165,7 +172,8 @@ TabContext::SignedPkgOriginNoSuffix() const
}

bool
TabContext::SetTabContext(mozIApplication* aOwnApp,
TabContext::SetTabContext(bool aIsMozBrowserElement,
mozIApplication* aOwnApp,
mozIApplication* aAppFrameOwnerApp,
const DocShellOriginAttributes& aOriginAttributes,
const nsACString& aSignedPkgOriginNoSuffix)
Expand Down Expand Up @@ -194,6 +202,7 @@ TabContext::SetTabContext(mozIApplication* aOwnApp,
aOriginAttributes.mAppId == NO_APP_ID);

mInitialized = true;
mIsMozBrowserElement = aIsMozBrowserElement;
mOriginAttributes = aOriginAttributes;
mContainingAppId = containingAppId;
mOwnApp = aOwnApp;
Expand All @@ -209,7 +218,8 @@ TabContext::AsIPCTabContext() const
mOriginAttributes.CreateSuffix(originSuffix);
return IPCTabContext(FrameIPCTabContext(originSuffix,
mContainingAppId,
mSignedPkgOriginNoSuffix));
mSignedPkgOriginNoSuffix,
mIsMozBrowserElement));
}

static already_AddRefed<mozIApplication>
Expand All @@ -227,6 +237,7 @@ GetAppForId(uint32_t aAppId)
MaybeInvalidTabContext::MaybeInvalidTabContext(const IPCTabContext& aParams)
: mInvalidReason(nullptr)
{
bool isMozBrowserElement = false;
uint32_t containingAppId = NO_APP_ID;
DocShellOriginAttributes originAttributes;
nsAutoCString originSuffix;
Expand All @@ -239,7 +250,8 @@ MaybeInvalidTabContext::MaybeInvalidTabContext(const IPCTabContext& aParams)
TabContext *context;
if (ipcContext.opener().type() == PBrowserOrId::TPBrowserParent) {
context = TabParent::GetFrom(ipcContext.opener().get_PBrowserParent());
if (context->IsBrowserElement() && !ipcContext.isBrowserElement()) {
if (context->IsMozBrowserElement() &&
!ipcContext.isMozBrowserElement()) {
// If the TabParent corresponds to a browser element, then it can only
// open other browser elements, for security reasons. We should have
// checked this before calling the TabContext constructor, so this is
Expand Down Expand Up @@ -269,8 +281,9 @@ MaybeInvalidTabContext::MaybeInvalidTabContext(const IPCTabContext& aParams)
//
// Otherwise, we're a new app window and we inherit from our
// opener app.
isMozBrowserElement = ipcContext.isMozBrowserElement();
originAttributes = context->mOriginAttributes;
if (ipcContext.isBrowserElement()) {
if (isMozBrowserElement) {
containingAppId = context->OwnOrContainingAppId();
} else {
containingAppId = context->mContainingAppId;
Expand All @@ -281,6 +294,7 @@ MaybeInvalidTabContext::MaybeInvalidTabContext(const IPCTabContext& aParams)
const FrameIPCTabContext &ipcContext =
aParams.get_FrameIPCTabContext();

isMozBrowserElement = ipcContext.isMozBrowserElement();
containingAppId = ipcContext.frameOwnerAppId();
signedPkgOriginNoSuffix = ipcContext.signedPkgOriginNoSuffix();
originSuffix = ipcContext.originSuffix();
Expand Down Expand Up @@ -310,8 +324,8 @@ MaybeInvalidTabContext::MaybeInvalidTabContext(const IPCTabContext& aParams)
}

nsCOMPtr<mozIApplication> ownApp;
if (!originAttributes.mInIsolatedMozBrowser) {
// mAppId corresponds to OwnOrContainingAppId; if mInIsolatedMozBrowser is
if (!isMozBrowserElement) {
// mAppId corresponds to OwnOrContainingAppId; if isMozBrowserElement is
// false then it's ownApp otherwise it's containingApp
ownApp = GetAppForId(originAttributes.mAppId);
if ((ownApp == nullptr) != (originAttributes.mAppId == NO_APP_ID)) {
Expand All @@ -327,7 +341,8 @@ MaybeInvalidTabContext::MaybeInvalidTabContext(const IPCTabContext& aParams)
}

bool rv;
rv = mTabContext.SetTabContext(ownApp,
rv = mTabContext.SetTabContext(isMozBrowserElement,
ownApp,
containingApp,
originAttributes,
signedPkgOriginNoSuffix);
Expand Down
57 changes: 41 additions & 16 deletions dom/ipc/TabContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,37 +42,51 @@ class TabContext
IPCTabContext AsIPCTabContext() const;

/**
* Does this TabContext correspond to a mozbrowser? (<iframe mozbrowser
* mozapp> is not a browser.)
* Does this TabContext correspond to a mozbrowser?
*
* If IsBrowserElement() is true, HasOwnApp() and HasAppOwnerApp() are
* <iframe mozbrowser mozapp> and <xul:browser> are not considered to be
* mozbrowser elements.
*
* If IsMozBrowserElement() is true, HasOwnApp() and HasAppOwnerApp() are
* guaranteed to be false.
*
* If IsBrowserElement() is false, HasBrowserOwnerApp() is guaranteed to be
* If IsMozBrowserElement() is false, HasBrowserOwnerApp() is guaranteed to be
* false.
*/
bool IsBrowserElement() const;
bool IsMozBrowserElement() const;

/**
* Does this TabContext correspond to an isolated mozbrowser?
*
* <iframe mozbrowser mozapp> and <xul:browser> are not considered to be
* mozbrowser elements. <iframe mozbrowser noisolation> does not count as
* isolated since isolation is disabled. Isolation can only be disabled by
* chrome pages.
*/
bool IsIsolatedMozBrowserElement() const;

/**
* Does this TabContext correspond to a mozbrowser or mozapp? This is
* equivalent to IsBrowserElement() || HasOwnApp().
* equivalent to IsMozBrowserElement() || HasOwnApp(). Returns false for
* <xul:browser>, which is neither a mozbrowser nor a mozapp.
*/
bool IsBrowserOrApp() const;
bool IsMozBrowserOrApp() const;

/**
* OwnAppId() returns the id of the app which directly corresponds to this
* context's frame. GetOwnApp() returns the corresponding app object, and
* HasOwnApp() returns true iff GetOwnApp() would return a non-null value.
*
* If HasOwnApp() is true, IsBrowserElement() is guaranteed to be false.
* If HasOwnApp() is true, IsMozBrowserElement() is guaranteed to be
* false.
*/
uint32_t OwnAppId() const;
already_AddRefed<mozIApplication> GetOwnApp() const;
bool HasOwnApp() const;

/**
* BrowserOwnerAppId() gets the ID of the app which contains this browser
* frame. If this is not a browser frame (i.e., if !IsBrowserElement()), then
* frame. If this is not a mozbrowser frame (if !IsMozBrowserElement()), then
* BrowserOwnerAppId() is guaranteed to return NO_APP_ID.
*
* Even if we are a browser frame, BrowserOwnerAppId() may still return
Expand Down Expand Up @@ -140,7 +154,8 @@ class TabContext
* - a browser frame inside the given owner app (which may be null).
* - a non-browser, non-app frame. Both own app and owner app should be null.
*/
bool SetTabContext(mozIApplication* aOwnApp,
bool SetTabContext(bool aIsMozBrowserElement,
mozIApplication* aOwnApp,
mozIApplication* aAppFrameOwnerApp,
const DocShellOriginAttributes& aOriginAttributes,
const nsACString& aSignedPkgOriginNoSuffix);
Expand All @@ -151,16 +166,24 @@ class TabContext
*/
bool mInitialized;

/**
* Whether this TabContext corresponds to a mozbrowser.
*
* <iframe mozbrowser mozapp> and <xul:browser> are not considered to be
* mozbrowser elements.
*/
bool mIsMozBrowserElement;

/**
* This TabContext's own app. If this is non-null, then this
* TabContext corresponds to an app, and mIsBrowser must be false.
* TabContext corresponds to an app, and mIsMozBrowserElement must be false.
*/
nsCOMPtr<mozIApplication> mOwnApp;

/**
* This TabContext's containing app. If mIsBrowser, this corresponds to the
* app which contains the browser frame; otherwise, this corresponds to the
* app which contains the app frame.
* This TabContext's containing app. If mIsMozBrowserElement, this
* corresponds to the app which contains the browser frame; otherwise, this
* corresponds to the app which contains the app frame.
*/
nsCOMPtr<mozIApplication> mContainingApp;

Expand Down Expand Up @@ -197,12 +220,14 @@ class MutableTabContext : public TabContext
}

bool
SetTabContext(mozIApplication* aOwnApp,
SetTabContext(bool aIsMozBrowserElement,
mozIApplication* aOwnApp,
mozIApplication* aAppFrameOwnerApp,
const DocShellOriginAttributes& aOriginAttributes,
const nsACString& aSignedPkgOriginNoSuffix = EmptyCString())
{
return TabContext::SetTabContext(aOwnApp,
return TabContext::SetTabContext(aIsMozBrowserElement,
aOwnApp,
aAppFrameOwnerApp,
aOriginAttributes,
aSignedPkgOriginNoSuffix);
Expand Down
Loading

0 comments on commit 764b9f1

Please sign in to comment.