Bug 762802 - Each <iframe mozapp> should get its own process. Part 2: Content/DOM changes. r=mounir

--HG--
extra : rebase_source : 06a6945689c5b112722f461f3cb1d438a94d4030
This commit is contained in:
Justin Lebar 2012-07-13 17:10:20 -04:00
parent 713402885c
commit 1a8eb2a46c
4 changed files with 109 additions and 7 deletions

View File

@ -1369,6 +1369,27 @@ nsFrameLoader::OwnerIsBrowserFrame()
return isBrowser;
}
bool
nsFrameLoader::OwnerIsAppFrame()
{
nsCOMPtr<nsIMozBrowserFrame> browserFrame = do_QueryInterface(mOwnerContent);
bool isApp = false;
if (browserFrame) {
browserFrame->GetReallyIsApp(&isApp);
}
return isApp;
}
void
nsFrameLoader::GetOwnerAppManifestURL(nsAString& aOut)
{
aOut.Truncate();
nsCOMPtr<nsIMozBrowserFrame> browserFrame = do_QueryInterface(mOwnerContent);
if (browserFrame) {
browserFrame->GetAppManifestURL(aOut);
}
}
bool
nsFrameLoader::ShouldUseRemoteProcess()
{
@ -1916,7 +1937,12 @@ nsFrameLoader::TryRemoteBrowser()
return false;
}
ContentParent* parent = ContentParent::GetNewOrUsed();
// If our owner has no app manifest URL, then this is equivalent to
// ContentParent::GetNewOrUsed().
nsAutoString appManifest;
GetOwnerAppManifestURL(appManifest);
ContentParent* parent = ContentParent::GetForApp(appManifest);
NS_ASSERTION(parent->IsAlive(), "Process parent should be alive; something is very wrong!");
mRemoteBrowser = parent->CreateTab(chromeFlags,
/* aIsBrowserFrame = */ OwnerIsBrowserFrame());

View File

@ -275,11 +275,24 @@ private:
bool ShouldUseRemoteProcess();
/**
* Is this a frameloader for a bona fide <iframe mozbrowser>? (I.e., does
* the frame return true for nsIMozBrowserFrame::GetReallyIsBrowser()?)
* Is this a frameloader for a bona fide <iframe mozbrowser> or
* <iframe mozapp>? (I.e., does the frame return true for
* nsIMozBrowserFrame::GetReallyIsBrowser()?)
*/
bool OwnerIsBrowserFrame();
/**
* Is this a frameloader for a bona fide <iframe mozapp>? (I.e., does the
* frame return true for nsIMozBrowserFrame::GetReallyIsApp()?)
*/
bool OwnerIsAppFrame();
/**
* Get our owning element's app manifest URL, or return the empty string if
* our owning element doesn't have an app manifest URL.
*/
void GetOwnerAppManifestURL(nsAString& aOut);
/**
* If we are an IPC frame, set mRemoteFrame. Otherwise, create and
* initialize mDocShell.

View File

@ -9,6 +9,9 @@
#include "nsIInterfaceRequestorUtils.h"
#include "nsContentUtils.h"
#include "mozilla/Preferences.h"
#include "nsIAppsService.h"
#include "nsServiceManagerUtils.h"
#include "nsIDOMApplicationRegistry.h"
using namespace mozilla;
using namespace mozilla::dom;
@ -265,8 +268,9 @@ nsGenericHTMLFrameElement::IsHTMLFocusable(bool aWithMouse,
}
/**
* Return true if this frame element has permission to send mozbrowser
* events, and false otherwise.
* Return true if this frame element really is a mozbrowser or mozapp. (It
* needs to have the right attributes, and its creator must have the right
* permissions.)
*/
nsresult
nsGenericHTMLFrameElement::GetReallyIsBrowser(bool *aOut)
@ -301,6 +305,50 @@ nsGenericHTMLFrameElement::GetReallyIsBrowser(bool *aOut)
return NS_OK;
}
NS_IMETHODIMP
nsGenericHTMLFrameElement::GetReallyIsApp(bool *aOut)
{
nsAutoString manifestURL;
GetAppManifestURL(manifestURL);
*aOut = !manifestURL.IsEmpty();
return NS_OK;
}
NS_IMETHODIMP
nsGenericHTMLFrameElement::GetAppManifestURL(nsAString& aOut)
{
aOut.Truncate();
// At the moment, you can't be an app without being a browser.
bool isBrowser = false;
GetReallyIsBrowser(&isBrowser);
if (!isBrowser) {
return NS_OK;
}
// TODO: We surely need a permissions check here, particularly once we no
// longer rely on the mozbrowser permission check.
nsAutoString manifestURL;
GetAttr(kNameSpaceID_None, nsGkAtoms::mozapp, manifestURL);
if (manifestURL.IsEmpty()) {
return NS_OK;
}
nsCOMPtr<nsIAppsService> appsService = do_GetService(APPS_SERVICE_CONTRACTID);
NS_ENSURE_STATE(appsService);
nsCOMPtr<mozIDOMApplication> app;
appsService->GetAppByManifestURL(manifestURL, getter_AddRefs(app));
if (app) {
aOut.Assign(manifestURL);
}
return NS_OK;
}
NS_IMETHODIMP
nsGenericHTMLFrameElement::DisallowCreateFrameLoader()
{

View File

@ -9,11 +9,11 @@
interface nsITabParent;
[scriptable, uuid(0acd92dd-2902-48ee-adcf-082d3bb3ec45)]
[scriptable, uuid(6f043e42-02c9-4e8f-8f8d-1b83c6102827)]
interface nsIMozBrowserFrame : nsIDOMMozBrowserFrame
{
/**
* Gets whether this frame really is a browser frame.
* Gets whether this frame really is a browser or app frame.
*
* In order to really be a browser frame, this frame's
* nsIDOMMozBrowserFrame::mozbrowser attribute must be true, and the frame
@ -21,6 +21,21 @@ interface nsIMozBrowserFrame : nsIDOMMozBrowserFrame
*/
readonly attribute boolean reallyIsBrowser;
/**
* Gets whether this frame really is an app frame.
*
* In order to really be an app frame, this frame must really be a browser
* frame (this requirement will go away eventually), and the frame's mozapp
* attribute must point to the manifest of a valid app.
*/
readonly attribute boolean reallyIsApp;
/**
* Gets this frame's app manifest URL, if the frame really is an app frame.
* Otherwise, returns the empty string.
*/
readonly attribute AString appManifestURL;
/**
* Normally, a frame tries to create its frame loader when its src is
* modified, or its contentWindow is accessed.