Bug 777135 - Part 2: Stop using nsDOMWindowUtils::GetIsApp and friends, and instead use the relevant methods on the principal. r=mounir

--HG--
extra : rebase_source : fa8a153a1edc8f64b230b67f121ba5eaaf1098e6
This commit is contained in:
Justin Lebar 2012-08-13 12:58:38 -04:00
parent f813f6360a
commit 9ed276e03f
9 changed files with 72 additions and 60 deletions

View File

@ -9116,7 +9116,7 @@ nsDocument::RequestFullScreen(Element* aElement,
// trusted and so are automatically approved.
if (!mIsApprovedForFullscreen) {
mIsApprovedForFullscreen =
GetWindow()->IsInAppOrigin() ||
NodePrincipal()->GetAppStatus() >= nsIPrincipal::APP_STATUS_INSTALLED ||
nsContentUtils::IsSitePermAllow(NodePrincipal(), "fullscreen");
}

View File

@ -2800,7 +2800,7 @@ static const char*
GetFullScreenError(nsIDocument* aDoc)
{
nsCOMPtr<nsPIDOMWindow> win = aDoc->GetWindow();
if (win && win->IsInAppOrigin()) {
if (aDoc->NodePrincipal()->GetAppStatus() >= nsIPrincipal::APP_STATUS_INSTALLED) {
// Request is in a web app and in the same origin as the web app.
// Don't enforce as strict security checks for web apps, the user
// is supposed to have trust in them. However documents cross-origin

View File

@ -608,9 +608,22 @@ interface nsIDocShell : nsISupports
readonly attribute boolean isInBrowserElement;
/**
* Returns true iif the docshell is inside an application.
* However, it will return false if the docshell is inside a browser element
* that is inside an application.
* Returns true iif the docshell is inside an application. However, it will
* return false if the docshell is inside a browser element that is inside
* an application.
*
* Note: Do not use this method for permissions checks! An app may contain
* an <iframe> pointing at arbitrary web code. This iframe's docshell will
* have isInApp() == true, but the iframe's content is not "app code", and
* so should not be granted more trust than vanilla web content.
*
* (For example, suppose when web content calls API method X, we show a
* permission prompt, but when "app code" calls method X, we don't. In this
* case, it would be /incorrect/ to show the permission prompt if
* !isInApp().)
*
* If you're doing a security check, use the content's principal instead of
* this method.
*/
readonly attribute boolean isInApp;

View File

@ -154,11 +154,9 @@ AlarmsManager.prototype = {
"AlarmsManager:GetAll:Return:OK", "AlarmsManager:GetAll:Return:KO"]);
// Get the manifest URL if this is an installed app
this._manifestURL = null;
let utils = aWindow.QueryInterface(Ci.nsIInterfaceRequestor).getInterface(Ci.nsIDOMWindowUtils);
let app = utils.getApp();
if (app)
this._manifestURL = app.manifestURL;
let appsService = Cc["@mozilla.org/AppsService;1"]
.getService(Ci.nsIAppsService);
this._manifestURL = appsService.getManifestURLByLocalId(principal.appId);
},
// Called from DOMRequestIpcHelper.

View File

@ -9165,8 +9165,15 @@ nsGlobalWindow::OpenInternal(const nsAString& aUrl, const nsAString& aName,
NS_ASSERTION(mDocShell, "Must have docshell here");
// Popups from apps are never blocked.
bool isApp = false;
if (mDoc) {
isApp = mDoc->NodePrincipal()->GetAppStatus() >=
nsIPrincipal::APP_STATUS_INSTALLED;
}
const bool checkForPopup = !nsContentUtils::IsCallerChrome() &&
!IsPartOfApp() && !aDialog && !WindowExists(aName, !aCalledNoScript);
!isApp && !aDialog && !WindowExists(aName, !aCalledNoScript);
// Note: it's very important that this be an nsXPIDLCString, since we want
// .get() on it to return nullptr until we write stuff to it. The window

View File

@ -353,29 +353,46 @@ nsScreen::MozLockOrientation(const nsAString& aOrientation, bool* aReturn)
return NS_OK;
}
if (!GetOwner()) {
return NS_OK;
}
// Determine whether we can lock the screen orientation.
bool canLockOrientation = false;
do {
nsCOMPtr<nsPIDOMWindow> owner = GetOwner();
if (!owner) {
break;
}
// Chrome code and apps can always lock the screen orientation.
if (!IsChromeType(GetOwner()->GetDocShell()) &&
!static_cast<nsGlobalWindow*>(GetOwner())->IsPartOfApp()) {
nsCOMPtr<nsIDOMDocument> doc;
GetOwner()->GetDocument(getter_AddRefs(doc));
// Chrome can always lock the screen orientation.
if (IsChromeType(owner->GetDocShell())) {
canLockOrientation = true;
break;
}
nsCOMPtr<nsIDOMDocument> domDoc;
owner->GetDocument(getter_AddRefs(domDoc));
nsCOMPtr<nsIDocument> doc = do_QueryInterface(domDoc);
if (!doc) {
return NS_OK;
break;
}
// Non-apps content can lock orientation only if fullscreen.
// Apps can always lock the screen orientation.
if (doc->NodePrincipal()->GetAppStatus() >=
nsIPrincipal::APP_STATUS_INSTALLED) {
canLockOrientation = true;
break;
}
// Other content must be full-screen in order to lock orientation.
bool fullscreen;
doc->GetMozFullScreen(&fullscreen);
domDoc->GetMozFullScreen(&fullscreen);
if (!fullscreen) {
return NS_OK;
break;
}
nsCOMPtr<nsIDOMEventTarget> target = do_QueryInterface(GetOwner());
// If we're full-screen, register a listener so we learn when we leave
// full-screen.
nsCOMPtr<nsIDOMEventTarget> target = do_QueryInterface(owner);
if (!target) {
return NS_OK;
break;
}
if (!mEventListener) {
@ -383,10 +400,14 @@ nsScreen::MozLockOrientation(const nsAString& aOrientation, bool* aReturn)
}
target->AddSystemEventListener(NS_LITERAL_STRING("mozfullscreenchange"),
mEventListener, true);
mEventListener, /* useCapture = */ true);
canLockOrientation = true;
} while(0);
if (canLockOrientation) {
*aReturn = hal::LockScreenOrientation(orientation);
}
*aReturn = hal::LockScreenOrientation(orientation);
return NS_OK;
}

View File

@ -87,26 +87,6 @@ BrowserElementChild.prototype = {
.createInstance(Ci.nsISecureBrowserUI);
securityUI.init(content);
// A mozbrowser iframe contained inside a mozapp iframe should return false
// for nsWindowUtils::IsPartOfApp (unless the mozbrowser iframe is itself
// also mozapp). That is, mozapp is transitive down to its children, but
// mozbrowser serves as a barrier.
//
// This is because mozapp iframes have some privileges which we don't want
// to extend to untrusted mozbrowser content.
//
// Get the app manifest from the parent, if our frame has one.
let appManifestURL = sendSyncMsg('get-mozapp-manifest-url')[0];
let windowUtils = content.QueryInterface(Ci.nsIInterfaceRequestor)
.getInterface(Ci.nsIDOMWindowUtils);
if (!!appManifestURL) {
windowUtils.setIsApp(true);
windowUtils.setApp(appManifestURL);
} else {
windowUtils.setIsApp(false);
}
// A cache of the menuitem dom objects keyed by the id we generate
// and pass to the embedder
this._ctxHandlers = {};

View File

@ -167,7 +167,6 @@ function BrowserElementParent(frameLoader, hasRemoteFrame) {
addMessageListener("securitychange", this._fireEventFromMsg);
addMessageListener("error", this._fireEventFromMsg);
addMessageListener("scroll", this._fireEventFromMsg);
addMessageListener("get-mozapp-manifest-url", this._sendMozAppManifestURL);
addMessageListener("keyevent", this._fireKeyEvent);
addMessageListener("showmodalprompt", this._handleShowModalPrompt);
addMessageListener('got-screenshot', this._gotDOMRequestResult);
@ -362,10 +361,6 @@ BrowserElementParent.prototype = {
cancelable: cancelable });
},
_sendMozAppManifestURL: function(data) {
return this._frameElement.getAttribute('mozapp');
},
/**
* Kick off a DOMRequest in the child process.
*

View File

@ -168,15 +168,13 @@ SystemMessageManager.prototype = {
init: function sysMessMgr_init(aWindow) {
debug("init");
this.initHelper(aWindow, ["SystemMessageManager:Message"]);
this._uri = aWindow.document.nodePrincipal.URI.spec;
let utils = aWindow.QueryInterface(Ci.nsIInterfaceRequestor)
.getInterface(Components.interfaces.nsIDOMWindowUtils);
// Get the manifest url is this is an installed app.
this._manifest = null;
let app = utils.getApp();
if (app)
this._manifest = app.manifestURL;
let principal = aWindow.document.nodePrincipal;
this._uri = principal.URI.spec;
let appsService = Cc["@mozilla.org/AppsService;1"]
.getService(Ci.nsIAppsService);
this._manifest = appsService.getManifestURLByLocalId(principal.appId);
},
classID: Components.ID("{bc076ea0-609b-4d8f-83d7-5af7cbdc3bb2}"),