Back out bug 776649. r=bustage

This commit is contained in:
Chris Jones 2012-08-08 20:13:12 -07:00
Родитель 78d197e3b7
Коммит de98620468
16 изменённых файлов: 70 добавлений и 288 удалений

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

@ -13,7 +13,6 @@
#include "prenv.h"
#include "mozIApplication.h"
#include "nsIDOMHTMLIFrameElement.h"
#include "nsIDOMHTMLFrameElement.h"
#include "nsIDOMMozBrowserFrame.h"
@ -32,7 +31,6 @@
#include "nsIDocShellTreeNode.h"
#include "nsIDocShellTreeOwner.h"
#include "nsIDocShellLoadInfo.h"
#include "nsIDOMApplicationRegistry.h"
#include "nsIBaseWindow.h"
#include "nsContentUtils.h"
#include "nsIXPConnect.h"
@ -1975,8 +1973,9 @@ nsFrameLoader::TryRemoteBrowser()
return false;
}
PRUint32 appId = 0;
bool isBrowserElement = false;
nsCOMPtr<mozIApplication> app;
if (OwnerIsBrowserFrame()) {
isBrowserElement = true;
@ -1990,21 +1989,24 @@ nsFrameLoader::TryRemoteBrowser()
return false;
}
nsCOMPtr<mozIDOMApplication> domApp;
appsService->GetAppByManifestURL(manifest, getter_AddRefs(domApp));
// If the frame is actually an app, we should not mark it as a
// browser. This is to identify the data store: since <app>s
// and <browser>s-within-<app>s have different stores, we want
// to ensure the <app> uses its store, not the one for its
// <browser>s.
app = do_QueryInterface(domApp);
if (app) {
appsService->GetAppLocalIdByManifestURL(manifest, &appId);
// If the frame is actually an app, we should not mark it as a browser.
if (appId != nsIScriptSecurityManager::NO_APP_ID) {
isBrowserElement = false;
}
}
}
if ((mRemoteBrowser = ContentParent::CreateBrowser(app, isBrowserElement))) {
// 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, isBrowserElement, appId);
if (mRemoteBrowser) {
nsCOMPtr<nsIDOMElement> element = do_QueryInterface(mOwnerContent);
mRemoteBrowser->SetOwnerElement(element);
@ -2017,8 +2019,8 @@ nsFrameLoader::TryRemoteBrowser()
nsCOMPtr<nsIBrowserDOMWindow> browserDOMWin;
rootChromeWin->GetBrowserDOMWindow(getter_AddRefs(browserDOMWin));
mRemoteBrowser->SetBrowserDOMWindow(browserDOMWin);
mChildHost = static_cast<ContentParent*>(mRemoteBrowser->Manager());
mChildHost = parent;
}
return true;
}

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

@ -698,25 +698,7 @@ let DOMApplicationRegistry = {
for (let id in this.webapps) {
let app = this.webapps[id];
if (app.manifestURL == aManifestURL) {
let res = this._cloneAppObject(app);
res.hasPermission = function(permission) {
let localId = DOMApplicationRegistry.getAppLocalIdByManifestURL(
this.manifestURL);
let uri = Services.io.newURI(this.manifestURL, null, null);
let secMan = Cc["@mozilla.org/scriptsecuritymanager;1"]
.getService(Ci.nsIScriptSecurityManager);
// XXX for the purposes of permissions checking, this helper
// should always be called on !isBrowser frames, so we
// assume false here.
let principal = secMan.getAppCodebasePrincipal(uri, localId,
/*mozbrowser*/false);
let perm = Services.perms.testExactPermissionFromPrincipal(principal,
permission);
return (perm === Ci.nsIPermissionManager.ALLOW_ACTION);
};
res.QueryInterface = XPCOMUtils.generateQI([Ci.mozIDOMApplication,
Ci.mozIApplication]);
return res;
return this._cloneAppObject(app);
}
}

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

@ -15,7 +15,6 @@ XPIDL_MODULE = dom_apps
GRE_MODULE = 1
XPIDLSRCS = \
mozIApplication.idl \
nsIDOMApplicationRegistry.idl \
nsIAppsService.idl \
nsIDOMMozApplicationEvent.idl \

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

@ -1,19 +0,0 @@
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*-
* vim: sw=2 ts=8 et :
*/
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "nsIDOMApplicationRegistry.idl"
/**
* We expose Gecko-internal helpers related to "web apps" through this
* sub-interface.
*/
[scriptable, uuid(8de25e36-b4cb-4e89-9310-a199dce4e5f4)]
interface mozIApplication: mozIDOMApplication
{
/* Return true if this app has |permission|. */
boolean hasPermission(in string permission);
};

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

@ -1,54 +0,0 @@
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*-
* vim: sw=2 ts=8 et :
*/
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "AppProcessPermissions.h"
#include "ContentParent.h"
#include "mozIApplication.h"
#include "nsIDOMApplicationRegistry.h"
#include "TabParent.h"
using namespace mozilla::dom;
using namespace mozilla::services;
namespace mozilla {
bool
AppProcessHasPermission(PBrowserParent* aActor, const char* aPermission)
{
if (!aActor) {
NS_WARNING("Testing permissions for null actor");
return false;
}
TabParent* tab = static_cast<TabParent*>(aActor);
nsCOMPtr<mozIApplication> app = tab->GetApp();
// isBrowser frames inherit their app descriptor to identify their
// data storage, but they don't inherit the permissions associated
// with that descriptor.
if (!app || tab->IsBrowserElement()) {
return false;
}
bool hasPermission = false;
return (NS_SUCCEEDED(app->HasPermission(aPermission, &hasPermission)) &&
hasPermission);
}
bool
AppProcessHasPermission(PContentParent* aActor, const char* aPermission)
{
const InfallibleTArray<PBrowserParent*>& browsers =
aActor->ManagedPBrowserParent();
for (uint32_t i = 0; i < browsers.Length(); ++i) {
if (AppProcessHasPermission(browsers[i], aPermission)) {
return true;
}
}
return false;
}
} // namespace mozilla

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

@ -1,43 +0,0 @@
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*-
* vim: sw=2 ts=8 et :
*/
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/. */
#ifndef mozilla_Capabilities_h
#define mozilla_Capabilities_h
namespace mozilla {
namespace dom {
class PBrowserParent;
class PContentParent;
}
/**
* Return true iff the specified browser has the specified capability.
*/
bool
AppProcessHasPermissions(mozilla::dom::PBrowserParent* aActor,
const char* aPermission);
/**
* Return true iff any of the PBrowsers loaded in this content process
* has the specified capability.
*/
bool
AppProcessHasPermission(mozilla::dom::PContentParent* aActor,
const char* aPermission);
// NB: when adding capability checks for other IPDL actors, please add
// them to this file and have them delegate to the two functions above
// as appropriate. For example,
//
// bool AppProcessHasCapability(PNeckoParent* aActor) {
// return AppProcessHasCapability(aActor->Manager());
// }
} // namespace mozilla
#endif // mozilla_Capabilities_h

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

@ -39,7 +39,6 @@
#include "nsIObserverService.h"
#include "nsTObserverArray.h"
#include "nsIObserver.h"
#include "nsIScriptSecurityManager.h"
#include "nsServiceManagerUtils.h"
#include "nsXULAppAPI.h"
#include "nsWeakReference.h"
@ -403,11 +402,10 @@ ContentChild::AllocPCompositor(mozilla::ipc::Transport* aTransport,
PBrowserChild*
ContentChild::AllocPBrowser(const PRUint32& aChromeFlags,
const bool& aIsBrowserElement, const AppId& aApp)
const bool& aIsBrowserElement,
const PRUint32& aAppId)
{
PRUint32 appId = aApp.get_uint32_t();
nsRefPtr<TabChild> iframe = new TabChild(aChromeFlags, aIsBrowserElement,
appId);
nsRefPtr<TabChild> iframe = new TabChild(aChromeFlags, aIsBrowserElement, aAppId);
return NS_SUCCEEDED(iframe->Init()) ? iframe.forget().get() : NULL;
}

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

@ -68,7 +68,7 @@ public:
virtual PBrowserChild* AllocPBrowser(const PRUint32& aChromeFlags,
const bool& aIsBrowserElement,
const AppId& aAppId);
const PRUint32& aAppId);
virtual bool DeallocPBrowser(PBrowserChild*);
virtual PDeviceStorageRequestChild* AllocPDeviceStorageRequest(const DeviceStorageParams&);

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

@ -20,7 +20,6 @@
#include "IDBFactory.h"
#include "IndexedDBParent.h"
#include "IndexedDatabaseManager.h"
#include "mozIApplication.h"
#include "mozilla/Preferences.h"
#include "mozilla/Preferences.h"
#include "mozilla/Services.h"
@ -50,10 +49,8 @@
#include "nsFrameMessageManager.h"
#include "nsHashPropertyBag.h"
#include "nsIAlertsService.h"
#include "nsIAppsService.h"
#include "nsIClipboard.h"
#include "nsIConsoleService.h"
#include "nsIDOMApplicationRegistry.h"
#include "nsIDOMGeoGeolocation.h"
#include "nsIDOMWindow.h"
#include "nsIFilePicker.h"
@ -62,7 +59,6 @@
#include "nsIPresShell.h"
#include "nsIRemoteBlob.h"
#include "nsIScriptError.h"
#include "nsIScriptSecurityManager.h"
#include "nsISupportsPrimitives.h"
#include "nsIWindowWatcher.h"
#include "nsMemoryReporterManager.h"
@ -153,7 +149,7 @@ nsTArray<ContentParent*>* ContentParent::gPrivateContent;
// The first content child has ID 1, so the chrome process can have ID 0.
static PRUint64 gContentChildID = 1;
/*static*/ ContentParent*
ContentParent*
ContentParent::GetNewOrUsed()
{
if (!gNonAppContentParents)
@ -169,7 +165,7 @@ ContentParent::GetNewOrUsed()
NS_ASSERTION(p->IsAlive(), "Non-alive contentparent in gNonAppContentParents?");
return p;
}
nsRefPtr<ContentParent> p =
new ContentParent(/* appManifestURL = */ EmptyString());
p->Init();
@ -177,20 +173,11 @@ ContentParent::GetNewOrUsed()
return p;
}
/*static*/ TabParent*
ContentParent::CreateBrowser(mozIApplication* aApp, bool aIsBrowserElement)
ContentParent*
ContentParent::GetForApp(const nsAString& aAppManifestURL)
{
if (!aApp) {
if (ContentParent* cp = GetNewOrUsed()) {
nsRefPtr<TabParent> tp(new TabParent(aApp, aIsBrowserElement));
return static_cast<TabParent*>(
cp->SendPBrowserConstructor(
// DeallocPBrowserParent() releases the ref we take here
tp.forget().get(),
/*chromeFlags*/0,
aIsBrowserElement, nsIScriptSecurityManager::NO_APP_ID));
}
return nullptr;
if (aAppManifestURL.IsEmpty()) {
return GetNewOrUsed();
}
if (!gAppContentParents) {
@ -200,39 +187,14 @@ ContentParent::CreateBrowser(mozIApplication* aApp, bool aIsBrowserElement)
}
// Each app gets its own ContentParent instance.
nsAutoString manifestURL;
if (NS_FAILED(aApp->GetManifestURL(manifestURL))) {
NS_ERROR("Failed to get manifest URL");
return nullptr;
}
nsCOMPtr<nsIAppsService> appsService = do_GetService(APPS_SERVICE_CONTRACTID);
if (!appsService) {
NS_ERROR("Failed to get apps service");
return nullptr;
}
// Send the local app ID to the new TabChild so it knows what app
// it is.
PRUint32 appId;
if (NS_FAILED(appsService->GetAppLocalIdByManifestURL(manifestURL, &appId))) {
NS_ERROR("Failed to get local app ID");
return nullptr;
}
ContentParent* p = gAppContentParents->Get(manifestURL);
ContentParent* p = gAppContentParents->Get(aAppManifestURL);
if (!p) {
p = new ContentParent(manifestURL);
p = new ContentParent(aAppManifestURL);
p->Init();
gAppContentParents->Put(manifestURL, p);
gAppContentParents->Put(aAppManifestURL, p);
}
nsRefPtr<TabParent> tp(new TabParent(aApp, aIsBrowserElement));
return static_cast<TabParent*>(
// DeallocPBrowserParent() releases the ref we take here
p->SendPBrowserConstructor(tp.forget().get(),
/*chromeFlags*/0,
aIsBrowserElement, appId));
return p;
}
static PLDHashOperator
@ -493,6 +455,12 @@ ContentParent::ActorDestroy(ActorDestroyReason why)
NS_DispatchToCurrentThread(new DelayedDeleteContentParentTask(this));
}
TabParent*
ContentParent::CreateTab(PRUint32 aChromeFlags, bool aIsBrowserElement, PRUint32 aAppId)
{
return static_cast<TabParent*>(SendPBrowserConstructor(aChromeFlags, aIsBrowserElement, aAppId));
}
void
ContentParent::NotifyTabDestroyed(PBrowserParent* aTab)
{
@ -894,40 +862,22 @@ ContentParent::AllocPCompositor(mozilla::ipc::Transport* aTransport,
PBrowserParent*
ContentParent::AllocPBrowser(const PRUint32& aChromeFlags,
const bool& aIsBrowserElement, const AppId& aApp)
const bool& aIsBrowserElement,
const PRUint32& aAppId)
{
// We only use this Alloc() method when the content processes asks
// us to open a window. In that case, we're expecting to see the
// opening PBrowser as its app descriptor, and we can trust the data
// associated with that PBrowser since it's fully owned by this
// process.
if (AppId::TPBrowserParent != aApp.type()) {
NS_ERROR("Content process attempting to forge app ID");
return nullptr;
}
TabParent* opener = static_cast<TabParent*>(aApp.get_PBrowserParent());
// Popup windows of isBrowser frames are isBrowser if the parent
// isBrowser. Allocating a !isBrowser frame with same app ID
// would allow the content to access data it's not supposed to.
if (opener && opener->IsBrowserElement() && !aIsBrowserElement) {
NS_ERROR("Content process attempting to escalate data access privileges");
return nullptr;
}
TabParent* parent = new TabParent(opener ? opener->GetApp() : nullptr,
aIsBrowserElement);
// We release this ref in DeallocPBrowser()
TabParent* parent = new TabParent();
if (parent){
NS_ADDREF(parent);
return parent;
}
return parent;
}
bool
ContentParent::DeallocPBrowser(PBrowserParent* frame)
{
TabParent* parent = static_cast<TabParent*>(frame);
NS_RELEASE(parent);
return true;
TabParent* parent = static_cast<TabParent*>(frame);
NS_RELEASE(parent);
return true;
}
PDeviceStorageRequestParent*

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

@ -26,7 +26,6 @@
#include "nsInterfaceHashtable.h"
#include "nsHashKeys.h"
class mozIApplication;
class nsFrameMessageManager;
class nsIDOMBlob;
@ -61,16 +60,13 @@ public:
static ContentParent* GetNewOrUsed();
/**
* Get or create a content process for the given app descriptor,
* which may be null. This function will assign processes to app
* or non-app browsers by internal heuristics.
* Get or create a content process for the given app. A given app
* (identified by its manifest URL) gets one process all to itself.
*
* Currently apps are given their own process, and browser tabs
* share processes.
* If the given manifest is the empty string, then this method is equivalent
* to GetNewOrUsed().
*/
static TabParent* CreateBrowser(mozIApplication* aApp,
bool aIsBrowserFrame);
static ContentParent* GetForApp(const nsAString& aManifestURL);
static void GetAll(nsTArray<ContentParent*>& aArray);
NS_DECL_ISUPPORTS
@ -78,6 +74,14 @@ public:
NS_DECL_NSITHREADOBSERVER
NS_DECL_NSIDOMGEOPOSITIONCALLBACK
/**
* Create a new tab.
*
* |aIsBrowserElement| indicates whether this tab is part of an
* <iframe mozbrowser>.
* |aAppId| indicates which app the tab belongs to.
*/
TabParent* CreateTab(PRUint32 aChromeFlags, bool aIsBrowserElement, PRUint32 aAppId);
/** Notify that a tab was destroyed during normal operation. */
void NotifyTabDestroyed(PBrowserParent* aTab);
@ -139,9 +143,7 @@ private:
PCompositorParent* AllocPCompositor(mozilla::ipc::Transport* aTransport,
base::ProcessId aOtherProcess) MOZ_OVERRIDE;
virtual PBrowserParent* AllocPBrowser(const PRUint32& aChromeFlags,
const bool& aIsBrowserElement,
const AppId& aApp);
virtual PBrowserParent* AllocPBrowser(const PRUint32& aChromeFlags, const bool& aIsBrowserElement, const PRUint32& aAppId);
virtual bool DeallocPBrowser(PBrowserParent* frame);
virtual PDeviceStorageRequestParent* AllocPDeviceStorageRequest(const DeviceStorageParams&);

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

@ -23,15 +23,10 @@ endif
EXPORTS = PCOMContentPermissionRequestChild.h
EXPORTS_NAMESPACES = \
mozilla \
mozilla/dom \
mozilla/dom/ipc \
$(NULL)
EXPORTS_mozilla = \
AppProcessPermissions.h \
$(NULL)
EXPORTS_mozilla/dom = \
ContentChild.h \
ContentParent.h \
@ -52,7 +47,6 @@ EXPORTS_mozilla/dom/ipc = \
$(NULL)
CPPSRCS = \
AppProcessPermissions.cpp \
Blob.cpp \
ContentProcess.cpp \
ContentParent.cpp \

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

@ -122,11 +122,6 @@ union BlobConstructorParams
MysteryBlobConstructorParams;
};
union AppId {
uint32_t;
nullable PBrowser;
};
rpc protocol PContent
{
parent opens PCompositor;
@ -150,16 +145,9 @@ both:
// created from either the child or parent process!
//
// The child creates the PBrowser as part of
// TabChild::BrowserFrameProvideWindow, and the parent creates the
// PBrowser as part of ContentParent::CreateTab.
//
// When the parent constructs a PBrowser, the app ID handed to the
// child side is trusted. In that case, |appId| is uint32_t.
// However, when the child side constructs a PBrowser, for
// window.open(), the parent must validate the app ID used on the
// parent side. To do so, the child process must pass a valid
// PBrowser as its |AppId|.
async PBrowser(PRUint32 chromeFlags, bool isBrowserElement, AppId appId);
// TabChild::BrowserFrameProvideWindow, and the parent creates the PBrowser
// as part of ContentParent::CreateTab.
async PBrowser(PRUint32 chromeFlags, bool isBrowserElement, PRUint32 appId);
async PBlob(BlobConstructorParams params);

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

@ -422,13 +422,10 @@ TabChild::BrowserFrameProvideWindow(nsIDOMWindow* aOpener,
{
*aReturn = nullptr;
PRUint32 chromeFlags = 0;
nsRefPtr<TabChild> newChild = new TabChild(chromeFlags,
mIsBrowserElement, mAppId);
static_cast<TabChild*>(Manager()->SendPBrowserConstructor(
// We release this ref in DeallocPBrowserChild
nsRefPtr<TabChild>(newChild).forget().get(),
chromeFlags, mIsBrowserElement, this));
nsRefPtr<TabChild> newChild =
static_cast<TabChild*>(Manager()->SendPBrowserConstructor(
/* aChromeFlags = */ 0, mIsBrowserElement, mAppId));
nsCAutoString spec;
if (aURI) {
aURI->GetSpec(spec);

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

@ -158,8 +158,6 @@ public:
virtual ~TabChild();
nsresult Init();
PRUint32 GetAppId() { return mAppId; }
NS_DECL_ISUPPORTS
NS_DECL_NSIWEBBROWSERCHROME
NS_DECL_NSIWEBBROWSERCHROME2

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

@ -11,7 +11,6 @@
#include "Blob.h"
#include "IDBFactory.h"
#include "IndexedDBParent.h"
#include "mozIApplication.h"
#include "mozilla/BrowserElementParent.h"
#include "mozilla/docshell/OfflineCacheUpdateParent.h"
#include "mozilla/dom/ContentParent.h"
@ -28,7 +27,6 @@
#include "nsFocusManager.h"
#include "nsFrameLoader.h"
#include "nsIContent.h"
#include "nsIDOMApplicationRegistry.h"
#include "nsIDOMElement.h"
#include "nsIDOMEvent.h"
#include "nsIDOMEventTarget.h"
@ -38,7 +36,6 @@
#include "nsIPromptFactory.h"
#include "nsIURI.h"
#include "nsIMozBrowserFrame.h"
#include "nsIScriptSecurityManager.h"
#include "nsIViewManager.h"
#include "nsIWidget.h"
#include "nsIWindowWatcher.h"
@ -55,7 +52,6 @@ using namespace mozilla::dom;
using namespace mozilla::ipc;
using namespace mozilla::layers;
using namespace mozilla::layout;
using namespace mozilla::services;
using namespace mozilla::widget;
using namespace mozilla::dom::indexedDB;
@ -70,9 +66,8 @@ TabParent *TabParent::mIMETabParent = nullptr;
NS_IMPL_ISUPPORTS3(TabParent, nsITabParent, nsIAuthPromptProvider, nsISecureBrowserUI)
TabParent::TabParent(mozIApplication* aApp, bool aIsBrowserElement)
TabParent::TabParent()
: mFrameElement(NULL)
, mApp(aApp)
, mIMESelectionAnchor(0)
, mIMESelectionFocus(0)
, mIMEComposing(false)
@ -81,7 +76,6 @@ TabParent::TabParent(mozIApplication* aApp, bool aIsBrowserElement)
, mIMESeqno(0)
, mDPI(0)
, mActive(false)
, mIsBrowserElement(aIsBrowserElement)
, mShown(false)
{
}

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

@ -24,7 +24,6 @@
struct gfxMatrix;
struct JSContext;
struct JSObject;
class mozIApplication;
class nsFrameLoader;
class nsIDOMElement;
class nsIURI;
@ -54,7 +53,7 @@ class TabParent : public PBrowserParent
typedef mozilla::dom::ClonedMessageData ClonedMessageData;
public:
TabParent(mozIApplication* aApp, bool aIsBrowserElement);
TabParent();
virtual ~TabParent();
nsIDOMElement* GetOwnerElement() { return mFrameElement; }
void SetOwnerElement(nsIDOMElement* aElement);
@ -63,9 +62,6 @@ public:
mBrowserDOMWindow = aBrowserDOMWindow;
}
mozIApplication* GetApp() { return mApp; }
bool IsBrowserElement() { return mIsBrowserElement; }
void Destroy();
virtual bool RecvMoveFocus(const bool& aForward);
@ -229,7 +225,6 @@ protected:
uint64_t* aLayersId) MOZ_OVERRIDE;
virtual bool DeallocPRenderFrame(PRenderFrameParent* aFrame) MOZ_OVERRIDE;
nsCOMPtr<mozIApplication> mApp;
// IME
static TabParent *mIMETabParent;
nsString mIMECacheText;
@ -245,7 +240,6 @@ protected:
float mDPI;
bool mActive;
bool mIsBrowserElement;
bool mShown;
private: