Bug 1165466 - Fix up docshell and loadcontext inheriting code in nsIScriptSecurityManager. r=bholley

This commit is contained in:
Yoshi Huang 2015-09-23 16:10:21 +08:00
parent 1d5bd5ece0
commit 07934840bb
26 changed files with 254 additions and 111 deletions

View File

@ -6,6 +6,7 @@
#include "mozilla/BasePrincipal.h"
#include "nsDocShell.h"
#include "nsIAddonPolicyService.h"
#include "nsIContentSecurityPolicy.h"
#include "nsIObjectInputStream.h"
@ -27,6 +28,28 @@ namespace mozilla {
using dom::URLParams;
void OriginAttributes::InheritFromDocShellParent(const OriginAttributes& aParent)
{
mAppId = aParent.mAppId;
mInBrowser = aParent.mInBrowser;
mUserContextId = aParent.mUserContextId;
mSignedPkg = aParent.mSignedPkg;
}
bool OriginAttributes::CopyFromLoadContext(nsILoadContext* aLoadContext)
{
OriginAttributes attrs;
bool result = aLoadContext->GetOriginAttributes(attrs);
NS_ENSURE_TRUE(result, false);
mAppId = attrs.mAppId;
mInBrowser = attrs.mInBrowser;
mAddonId = attrs.mAddonId;
mUserContextId = attrs.mUserContextId;
mSignedPkg = attrs.mSignedPkg;
return true;
}
void
OriginAttributes::CreateSuffix(nsACString& aStr) const
{

View File

@ -14,6 +14,7 @@
#include "mozilla/dom/ChromeUtilsBinding.h"
class nsIContentSecurityPolicy;
class nsILoadContext;
class nsIObjectOutputStream;
class nsIObjectInputStream;
@ -44,6 +45,28 @@ public:
return !(*this == aOther);
}
// The docshell often influences the origin attributes of content loaded
// inside of it, and in some cases also influences the origin attributes of
// content loaded in child docshells. We say that a given attribute "lives on
// the docshell" to indicate that this attribute is specified by the docshell
// (if any) associated with a given content document.
//
// In practice, this usually means that we need to store a copy of those
// attributes on each docshell, or provide methods on the docshell to compute
// them on-demand.
// We could track each of these attributes individually, but since the
// majority of the existing origin attributes currently live on the docshell,
// it's cleaner to simply store an entire OriginAttributes struct on each
// docshell, and selectively copy them to child docshells and content
// principals in a manner that implements our desired semantics.
//
// This method is used to propagate attributes from parent to child
// docshells.
void InheritFromDocShellParent(const OriginAttributes& aParent);
// Copy from the origin attributes of the nsILoadContext.
bool CopyFromLoadContext(nsILoadContext* aLoadContext);
// Serializes/Deserializes non-default values into the suffix format, i.e.
// |!key1=value1&key2=value2|. If there are no non-default attributes, this
// returns an empty string.

View File

@ -44,6 +44,7 @@ UNIFIED_SOURCES += [
]
LOCAL_INCLUDES += [
'/docshell/base',
'/dom/base',
'/js/xpconnect/src',
]

View File

@ -1093,10 +1093,10 @@ nsScriptSecurityManager::
nsILoadContext* aLoadContext,
nsIPrincipal** aPrincipal)
{
// XXXbholley - Make this more general in bug 1165466.
OriginAttributes attrs;
aLoadContext->GetAppId(&attrs.mAppId);
aLoadContext->GetIsInBrowserElement(&attrs.mInBrowser);
bool result = attrs.CopyFromLoadContext(aLoadContext);
NS_ENSURE_TRUE(result, NS_ERROR_FAILURE);
nsresult rv = MaybeSetAddonIdFromURI(attrs, aURI);
NS_ENSURE_SUCCESS(rv, rv);
nsCOMPtr<nsIPrincipal> prin = BasePrincipal::CreateCodebasePrincipal(aURI, attrs);
@ -1109,8 +1109,11 @@ nsScriptSecurityManager::GetDocShellCodebasePrincipal(nsIURI* aURI,
nsIDocShell* aDocShell,
nsIPrincipal** aPrincipal)
{
// XXXbholley - Make this more general in bug 1165466.
OriginAttributes attrs(aDocShell->GetAppId(), aDocShell->GetIsInBrowserElement());
OriginAttributes attrs;
nsDocShell* docShell= nsDocShell::Cast(aDocShell);
bool result = attrs.CopyFromLoadContext(docShell);
NS_ENSURE_TRUE(result, NS_ERROR_FAILURE);
nsresult rv = MaybeSetAddonIdFromURI(attrs, aURI);
NS_ENSURE_SUCCESS(rv, rv);
nsCOMPtr<nsIPrincipal> prin = BasePrincipal::CreateCodebasePrincipal(aURI, attrs);

View File

@ -194,18 +194,6 @@ var gData = [
},
test: [ "child-has-different-eo", "child-has-different-appstatus", "child-has-same-appid" ],
},
// app inside a browser is an app.
{
src: "http://example.org/",
isapp: false,
browser: true,
child: {
app: "http://example.org/manifest.webapp",
src: "http://example.org/chrome/",
isapp: true,
},
test: [ "child-has-different-eo", "child-has-different-appstatus", "child-has-different-appid" ],
},
// browser inside a browser are two browsers
{
src: "http://example.org/",

View File

@ -5,6 +5,7 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "mozilla/Assertions.h"
#include "mozilla/BasePrincipal.h"
#include "mozilla/LoadContext.h"
namespace mozilla {
@ -22,9 +23,7 @@ LoadContext::LoadContext(nsIPrincipal* aPrincipal,
, mIsNotNull(true)
#endif
{
MOZ_ALWAYS_TRUE(NS_SUCCEEDED(aPrincipal->GetAppId(&mAppId)));
MOZ_ALWAYS_TRUE(
NS_SUCCEEDED(aPrincipal->GetIsInBrowserElement(&mIsInBrowserElement)));
mOriginAttributes = BasePrincipal::Cast(aPrincipal)->OriginAttributesRef();
if (!aOptionalBase) {
return;
@ -151,7 +150,7 @@ LoadContext::GetIsInBrowserElement(bool* aIsInBrowserElement)
NS_ENSURE_ARG_POINTER(aIsInBrowserElement);
*aIsInBrowserElement = mIsInBrowserElement;
*aIsInBrowserElement = mOriginAttributes.mInBrowser;
return NS_OK;
}
@ -162,7 +161,18 @@ LoadContext::GetAppId(uint32_t* aAppId)
NS_ENSURE_ARG_POINTER(aAppId);
*aAppId = mAppId;
*aAppId = mOriginAttributes.mAppId;
return NS_OK;
}
NS_IMETHODIMP
LoadContext::GetOriginAttributes(JS::MutableHandleValue aAttrs)
{
JSContext* cx = nsContentUtils::GetCurrentJSContext();
MOZ_ASSERT(cx);
bool ok = ToJSValue(cx, mOriginAttributes, aAttrs);
NS_ENSURE_TRUE(ok, NS_ERROR_FAILURE);
return NS_OK;
}

View File

@ -9,6 +9,7 @@
#include "SerializedLoadContext.h"
#include "mozilla/Attributes.h"
#include "mozilla/BasePrincipal.h"
#include "nsIWeakReferenceUtils.h"
#include "mozilla/dom/Element.h"
#include "nsIInterfaceRequestor.h"
@ -42,14 +43,13 @@ public:
// by child process.
LoadContext(const IPC::SerializedLoadContext& aToCopy,
dom::Element* aTopFrameElement,
uint32_t aAppId, bool aInBrowser)
OriginAttributes& aAttrs)
: mTopFrameElement(do_GetWeakReference(aTopFrameElement))
, mNestedFrameId(0)
, mAppId(aAppId)
, mIsContent(aToCopy.mIsContent)
, mUsePrivateBrowsing(aToCopy.mUsePrivateBrowsing)
, mUseRemoteTabs(aToCopy.mUseRemoteTabs)
, mIsInBrowserElement(aInBrowser)
, mOriginAttributes(aAttrs)
#ifdef DEBUG
, mIsNotNull(aToCopy.mIsNotNull)
#endif
@ -60,14 +60,13 @@ public:
// by child process.
LoadContext(const IPC::SerializedLoadContext& aToCopy,
uint64_t aNestedFrameId,
uint32_t aAppId, bool aInBrowser)
OriginAttributes& aAttrs)
: mTopFrameElement(nullptr)
, mNestedFrameId(aNestedFrameId)
, mAppId(aAppId)
, mIsContent(aToCopy.mIsContent)
, mUsePrivateBrowsing(aToCopy.mUsePrivateBrowsing)
, mUseRemoteTabs(aToCopy.mUseRemoteTabs)
, mIsInBrowserElement(aInBrowser)
, mOriginAttributes(aAttrs)
#ifdef DEBUG
, mIsNotNull(aToCopy.mIsNotNull)
#endif
@ -75,18 +74,16 @@ public:
}
LoadContext(dom::Element* aTopFrameElement,
uint32_t aAppId,
bool aIsContent,
bool aUsePrivateBrowsing,
bool aUseRemoteTabs,
bool aIsInBrowserElement)
OriginAttributes& aAttrs)
: mTopFrameElement(do_GetWeakReference(aTopFrameElement))
, mNestedFrameId(0)
, mAppId(aAppId)
, mIsContent(aIsContent)
, mUsePrivateBrowsing(aUsePrivateBrowsing)
, mUseRemoteTabs(aUseRemoteTabs)
, mIsInBrowserElement(aIsInBrowserElement)
, mOriginAttributes(aAttrs)
#ifdef DEBUG
, mIsNotNull(true)
#endif
@ -97,11 +94,10 @@ public:
explicit LoadContext(uint32_t aAppId)
: mTopFrameElement(nullptr)
, mNestedFrameId(0)
, mAppId(aAppId)
, mIsContent(false)
, mUsePrivateBrowsing(false)
, mUseRemoteTabs(false)
, mIsInBrowserElement(false)
, mOriginAttributes(aAppId, false)
#ifdef DEBUG
, mIsNotNull(true)
#endif
@ -118,11 +114,10 @@ private:
nsWeakPtr mTopFrameElement;
uint64_t mNestedFrameId;
uint32_t mAppId;
bool mIsContent;
bool mUsePrivateBrowsing;
bool mUseRemoteTabs;
bool mIsInBrowserElement;
OriginAttributes mOriginAttributes;
#ifdef DEBUG
bool mIsNotNull;
#endif

View File

@ -62,8 +62,9 @@ SerializedLoadContext::Init(nsILoadContext* aLoadContext)
aLoadContext->GetIsContent(&mIsContent);
aLoadContext->GetUsePrivateBrowsing(&mUsePrivateBrowsing);
aLoadContext->GetUseRemoteTabs(&mUseRemoteTabs);
aLoadContext->GetAppId(&mAppId);
aLoadContext->GetIsInBrowserElement(&mIsInBrowserElement);
if (!aLoadContext->GetOriginAttributes(mOriginAttributes)) {
NS_WARNING("GetOriginAttributes failed");
}
} else {
mIsNotNull = false;
mIsPrivateBitValid = false;
@ -72,8 +73,6 @@ SerializedLoadContext::Init(nsILoadContext* aLoadContext)
mIsContent = true;
mUsePrivateBrowsing = false;
mUseRemoteTabs = false;
mAppId = 0;
mIsInBrowserElement = false;
}
}

View File

@ -9,6 +9,7 @@
#include "base/basictypes.h"
#include "ipc/IPCMessageUtils.h"
#include "mozilla/BasePrincipal.h"
class nsILoadContext;
@ -48,8 +49,7 @@ public:
bool mIsContent;
bool mUsePrivateBrowsing;
bool mUseRemoteTabs;
bool mIsInBrowserElement;
uint32_t mAppId;
mozilla::OriginAttributes mOriginAttributes;
};
// Function to serialize over IPDL
@ -60,26 +60,29 @@ struct ParamTraits<SerializedLoadContext>
static void Write(Message* aMsg, const paramType& aParam)
{
nsAutoCString suffix;
aParam.mOriginAttributes.CreateSuffix(suffix);
WriteParam(aMsg, aParam.mIsNotNull);
WriteParam(aMsg, aParam.mIsContent);
WriteParam(aMsg, aParam.mIsPrivateBitValid);
WriteParam(aMsg, aParam.mUsePrivateBrowsing);
WriteParam(aMsg, aParam.mUseRemoteTabs);
WriteParam(aMsg, aParam.mAppId);
WriteParam(aMsg, aParam.mIsInBrowserElement);
WriteParam(aMsg, suffix);
}
static bool Read(const Message* aMsg, void** aIter, paramType* aResult)
{
nsAutoCString suffix;
if (!ReadParam(aMsg, aIter, &aResult->mIsNotNull) ||
!ReadParam(aMsg, aIter, &aResult->mIsContent) ||
!ReadParam(aMsg, aIter, &aResult->mIsPrivateBitValid) ||
!ReadParam(aMsg, aIter, &aResult->mUsePrivateBrowsing) ||
!ReadParam(aMsg, aIter, &aResult->mUseRemoteTabs) ||
!ReadParam(aMsg, aIter, &aResult->mAppId) ||
!ReadParam(aMsg, aIter, &aResult->mIsInBrowserElement)) {
!ReadParam(aMsg, aIter, &suffix)) {
return false;
}
aResult->mOriginAttributes.PopulateFromSuffix(suffix);
return true;
}

View File

@ -9388,17 +9388,7 @@ nsresult
nsDocShell::CreatePrincipalFromReferrer(nsIURI* aReferrer,
nsIPrincipal** aResult)
{
nsresult rv;
uint32_t appId;
rv = GetAppId(&appId);
NS_ENSURE_SUCCESS(rv, rv);
bool isInBrowserElement;
rv = GetIsInBrowserElement(&isInBrowserElement);
NS_ENSURE_SUCCESS(rv, rv);
// TODO: Bug 1165466 - Pass mOriginAttributes directly.
OriginAttributes attrs(appId, isInBrowserElement);
OriginAttributes attrs = GetOriginAttributes();
nsCOMPtr<nsIPrincipal> prin =
BasePrincipal::CreateCodebasePrincipal(aReferrer, attrs);
prin.forget(aResult);
@ -13715,6 +13705,38 @@ nsDocShell::GetAppId(uint32_t* aAppId)
return parent->GetAppId(aAppId);
}
OriginAttributes
nsDocShell::GetOriginAttributes()
{
OriginAttributes attrs;
nsRefPtr<nsDocShell> parent = GetParentDocshell();
if (parent) {
attrs.InheritFromDocShellParent(parent->GetOriginAttributes());
}
if (mOwnOrContainingAppId != nsIScriptSecurityManager::UNKNOWN_APP_ID) {
attrs.mAppId = mOwnOrContainingAppId;
}
if (mFrameType == eFrameTypeBrowser) {
attrs.mInBrowser = true;
}
return attrs;
}
NS_IMETHODIMP
nsDocShell::GetOriginAttributes(JS::MutableHandle<JS::Value> aVal)
{
JSContext* cx = nsContentUtils::GetCurrentJSContext();
MOZ_ASSERT(cx);
OriginAttributes attrs = GetOriginAttributes();
bool ok = ToJSValue(cx, attrs, aVal);
NS_ENSURE_TRUE(ok, NS_ERROR_FAILURE);
return NS_OK;
}
NS_IMETHODIMP
nsDocShell::GetAppManifestURL(nsAString& aAppManifestURL)
{

View File

@ -18,6 +18,7 @@
#include "nsIContentViewerContainer.h"
#include "nsIDOMStorageManager.h"
#include "nsDocLoader.h"
#include "mozilla/BasePrincipal.h"
#include "mozilla/UniquePtr.h"
#include "mozilla/WeakPtr.h"
#include "mozilla/TimeStamp.h"
@ -230,6 +231,7 @@ public:
NS_IMETHOD SetPrivateBrowsing(bool) override;
NS_IMETHOD GetUseRemoteTabs(bool*) override;
NS_IMETHOD SetRemoteTabs(bool) override;
NS_IMETHOD GetOriginAttributes(JS::MutableHandle<JS::Value>) override;
// Restores a cached presentation from history (mLSHE).
// This method swaps out the content viewer and simulates loads for
@ -268,6 +270,8 @@ public:
}
bool InFrameSwap();
mozilla::OriginAttributes GetOriginAttributes();
private:
// An observed docshell wrapper is created when recording markers is enabled.
mozilla::UniquePtr<mozilla::ObservedDocShell> mObserved;
@ -295,6 +299,11 @@ public:
nsIURI* aNewURI,
bool aInPrivateBrowsing);
static nsDocShell* Cast(nsIDocShell* aDocShell)
{
return static_cast<nsDocShell*>(aDocShell);
}
protected:
virtual ~nsDocShell();
virtual void DestroyChildren() override;

View File

@ -9,12 +9,21 @@
interface nsIDOMWindow;
interface nsIDOMElement;
%{C++
#ifdef MOZILLA_INTERNAL_API
#include "mozilla/BasePrincipal.h" // for OriginAttributes
#include "mozilla/dom/ScriptSettings.h" // for AutoJSAPI
#include "xpcpublic.h" // for PrivilegedJunkScope
#include "nsContentUtils.h" // for IsSystemPrincipal
#endif
%}
/**
* An nsILoadContext represents the context of a load. This interface
* can be queried for various information about where the load is
* happening.
*/
[scriptable, uuid(6ec837fa-af93-4350-bbb8-0985d54c74ca)]
[scriptable, uuid(1220e340-b337-4c35-aaa1-f51362763621)]
interface nsILoadContext : nsISupports
{
/**
@ -120,4 +129,39 @@ interface nsILoadContext : nsISupports
*/
readonly attribute unsigned long appId;
/**
* A dictionary of the non-default origin attributes associated with this
* nsILoadContext.
*/
readonly attribute jsval originAttributes;
%{C++
#ifdef MOZILLA_INTERNAL_API
/**
* The C++ getter for origin attributes.
*/
bool GetOriginAttributes(mozilla::OriginAttributes& aAttrs)
{
mozilla::dom::AutoJSAPI jsapi;
bool ok = jsapi.Init(xpc::PrivilegedJunkScope());
NS_ENSURE_TRUE(ok, false);
JS::Rooted<JS::Value> v(jsapi.cx());
nsresult rv = GetOriginAttributes(&v);
NS_ENSURE_SUCCESS(rv, false);
MOZ_ASSERT(v.isObject());
JS::Rooted<JSObject*> obj(jsapi.cx(), &v.toObject());
// If we're JS-implemented, the object will be left in a different (System-Principaled)
// scope, so we may need to enter its compartment.
MOZ_ASSERT(nsContentUtils::IsSystemPrincipal(nsContentUtils::ObjectPrincipal(obj)));
JSAutoCompartment ac(jsapi.cx(), obj);
mozilla::OriginAttributes attrs;
ok = attrs.Init(jsapi.cx(), v);
NS_ENSURE_TRUE(ok, false);
aAttrs = attrs;
return true;
}
#endif
%}
};

View File

@ -839,15 +839,12 @@ BrowserElementParent.prototype = {
debug('Malformed referrer -- ' + e);
}
// TODO Bug 1165466: use originAttributes from nsILoadContext.
let attrs = {appId: this._frameLoader.loadContext.appId,
inBrowser: this._frameLoader.loadContext.isInBrowserElement};
// This simply returns null if there is no principal available
// for the requested uri. This is an acceptable fallback when
// calling newChannelFromURI2.
principal =
Services.scriptSecurityManager.createCodebasePrincipal(
referrer, attrs);
referrer, this._frameLoader.loadContext.originAttributes);
}
debug('Using principal? ' + !!principal);

View File

@ -2974,12 +2974,13 @@ TabParent::GetLoadContext()
if (mLoadContext) {
loadContext = mLoadContext;
} else {
// TODO Bug 1191740 - Add OriginAttributes in TabContext
OriginAttributes attrs = OriginAttributes(OwnOrContainingAppId(), IsBrowserElement());
loadContext = new LoadContext(GetOwnerElement(),
OwnOrContainingAppId(),
true /* aIsContent */,
mChromeFlags & nsIWebBrowserChrome::CHROME_PRIVATE_WINDOW,
mChromeFlags & nsIWebBrowserChrome::CHROME_REMOTE_WINDOW,
IsBrowserElement());
attrs);
mLoadContext = loadContext;
}
return loadContext.forget();
@ -3348,6 +3349,7 @@ public:
NS_IMETHOD SetPrivateBrowsing(bool) NO_IMPL
NS_IMETHOD GetIsInBrowserElement(bool*) NO_IMPL
NS_IMETHOD GetAppId(uint32_t*) NO_IMPL
NS_IMETHOD GetOriginAttributes(JS::MutableHandleValue) NO_IMPL
NS_IMETHOD GetUseRemoteTabs(bool*) NO_IMPL
NS_IMETHOD SetRemoteTabs(bool) NO_IMPL
#undef NO_IMPL

View File

@ -46,7 +46,8 @@ NotificationCallbacks.prototype = {
if (iid.equals(Ci.nsILoadContext))
return this;
throw Cr.NS_ERROR_NO_INTERFACE;
}
},
originAttributes: {}
};
var gImgPath = 'http://localhost:' + server.identity.primaryPort + '/image.png';

View File

@ -75,10 +75,10 @@ CookieServiceParent::GetAppInfoFromParams(const IPC::SerializedLoadContext &aLoa
aIsInBrowserElement = false;
aIsPrivate = false;
OriginAttributes attrs;
const char* error = NeckoParent::GetValidatedAppInfo(aLoadContext,
Manager()->Manager(),
&aAppId,
&aIsInBrowserElement);
attrs);
if (error) {
NS_WARNING(nsPrintfCString("CookieServiceParent: GetAppInfoFromParams: "
"FATAL error: %s: KILLING CHILD PROCESS\n",
@ -86,6 +86,8 @@ CookieServiceParent::GetAppInfoFromParams(const IPC::SerializedLoadContext &aLoa
return false;
}
aAppId = attrs.mAppId;
aIsInBrowserElement = attrs.mInBrowser;
if (aLoadContext.IsPrivateBitValid()) {
aIsPrivate = aLoadContext.mUsePrivateBrowsing;
}

View File

@ -44,6 +44,7 @@
#include "mozilla/net/OfflineObserver.h"
#include "nsISpeculativeConnect.h"
using mozilla::OriginAttributes;
using mozilla::dom::ContentParent;
using mozilla::dom::TabContext;
using mozilla::dom::TabParent;
@ -109,12 +110,8 @@ PBOverrideStatusFromLoadContext(const SerializedLoadContext& aSerialized)
const char*
NeckoParent::GetValidatedAppInfo(const SerializedLoadContext& aSerialized,
PContentParent* aContent,
uint32_t* aAppId,
bool* aInBrowserElement)
OriginAttributes& aAttrs)
{
*aAppId = NECKO_UNKNOWN_APP_ID;
*aInBrowserElement = false;
if (UsingNeckoIPCSecurity()) {
if (!aSerialized.IsNotNull()) {
return "SerializedLoadContext from child is null";
@ -126,8 +123,9 @@ NeckoParent::GetValidatedAppInfo(const SerializedLoadContext& aSerialized,
for (uint32_t i = 0; i < contextArray.Length(); i++) {
TabContext tabContext = contextArray[i];
uint32_t appId = tabContext.OwnOrContainingAppId();
bool inBrowserElement = aSerialized.IsNotNull() ? aSerialized.mIsInBrowserElement
: tabContext.IsBrowserElement();
bool inBrowserElement = aSerialized.IsNotNull() ?
aSerialized.mOriginAttributes.mInBrowser :
tabContext.IsBrowserElement();
if (appId == NECKO_UNKNOWN_APP_ID) {
continue;
@ -145,8 +143,7 @@ NeckoParent::GetValidatedAppInfo(const SerializedLoadContext& aSerialized,
continue;
}
}
*aAppId = appId;
*aInBrowserElement = inBrowserElement;
aAttrs = OriginAttributes(appId, inBrowserElement);
return nullptr;
}
@ -157,10 +154,9 @@ NeckoParent::GetValidatedAppInfo(const SerializedLoadContext& aSerialized,
if (!UsingNeckoIPCSecurity()) {
// We are running xpcshell tests
if (aSerialized.IsNotNull()) {
*aAppId = aSerialized.mAppId;
*aInBrowserElement = aSerialized.mIsInBrowserElement;
aAttrs = aSerialized.mOriginAttributes;
} else {
*aAppId = NECKO_NO_APP_ID;
aAttrs = OriginAttributes(NECKO_NO_APP_ID, false);
}
return nullptr;
}
@ -174,9 +170,8 @@ NeckoParent::CreateChannelLoadContext(const PBrowserOrId& aBrowser,
const SerializedLoadContext& aSerialized,
nsCOMPtr<nsILoadContext> &aResult)
{
uint32_t appId = NECKO_UNKNOWN_APP_ID;
bool inBrowser = false;
const char* error = GetValidatedAppInfo(aSerialized, aContent, &appId, &inBrowser);
OriginAttributes attrs;
const char* error = GetValidatedAppInfo(aSerialized, aContent, attrs);
if (error) {
return error;
}
@ -193,14 +188,12 @@ NeckoParent::CreateChannelLoadContext(const PBrowserOrId& aBrowser,
if (tabParent) {
topFrameElement = tabParent->GetOwnerElement();
}
aResult = new LoadContext(aSerialized, topFrameElement,
appId, inBrowser);
aResult = new LoadContext(aSerialized, topFrameElement, attrs);
break;
}
case PBrowserOrId::TTabId:
{
aResult = new LoadContext(aSerialized, aBrowser.get_TabId(),
appId, inBrowser);
aResult = new LoadContext(aSerialized, aBrowser.get_TabId(), attrs);
break;
}
default:
@ -566,7 +559,7 @@ NeckoParent::AllocPRemoteOpenFileParent(const SerializedLoadContext& aSerialized
// Note: this enforces that SerializedLoadContext.appID is one of the apps
// in the child process, but there's currently no way to verify the
// request is not from a different app in that process.
if (appId == aSerialized.mAppId) {
if (appId == aSerialized.mOriginAttributes.mAppId) {
nsresult rv = appsService->GetAppByLocalId(appId, getter_AddRefs(mozApp));
if (NS_FAILED(rv) || !mozApp) {
break;
@ -878,11 +871,12 @@ NeckoParent::RecvPredPredict(const ipc::OptionalURIParams& aTargetURI,
nsCOMPtr<nsIURI> sourceURI = DeserializeURI(aSourceURI);
// We only actually care about the loadContext.mPrivateBrowsing, so we'll just
// pass dummy params for nestFrameId, inBrowser and appId
// pass dummy params for nestFrameId, and originAttributes.
uint64_t nestedFrameId = 0;
OriginAttributes attrs(NECKO_UNKNOWN_APP_ID, false);
nsCOMPtr<nsILoadContext> loadContext;
if (aLoadContext.IsNotNull()) {
loadContext = new LoadContext(aLoadContext, nestedFrameId, NECKO_UNKNOWN_APP_ID, false);
loadContext = new LoadContext(aLoadContext, nestedFrameId, attrs);
}
// Get the current predictor
@ -909,11 +903,12 @@ NeckoParent::RecvPredLearn(const ipc::URIParams& aTargetURI,
nsCOMPtr<nsIURI> sourceURI = DeserializeURI(aSourceURI);
// We only actually care about the loadContext.mPrivateBrowsing, so we'll just
// pass dummy params for nestFrameId, inBrowser and appId
// pass dummy params for nestFrameId, and originAttributes;
uint64_t nestedFrameId = 0;
OriginAttributes attrs(NECKO_UNKNOWN_APP_ID, false);
nsCOMPtr<nsILoadContext> loadContext;
if (aLoadContext.IsNotNull()) {
loadContext = new LoadContext(aLoadContext, nestedFrameId, NECKO_UNKNOWN_APP_ID, false);
loadContext = new LoadContext(aLoadContext, nestedFrameId, attrs);
}
// Get the current predictor

View File

@ -5,6 +5,7 @@
* 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 "mozilla/BasePrincipal.h"
#include "mozilla/net/PNeckoParent.h"
#include "mozilla/net/NeckoCommon.h"
#include "mozilla/net/OfflineObserver.h"
@ -38,8 +39,7 @@ public:
static const char *
GetValidatedAppInfo(const SerializedLoadContext& aSerialized,
PContentParent* aBrowser,
uint32_t* aAppId,
bool* aInBrowserElement);
mozilla::OriginAttributes& aAttrs);
/*
* Creates LoadContext for parent-side of an e10s channel.

View File

@ -521,13 +521,11 @@ HttpChannelParent::DoAsyncOpen( const URIParams& aURI,
}
if (setChooseApplicationCache) {
bool inBrowser = false;
OriginAttributes attrs;
if (mLoadContext) {
mLoadContext->GetIsInBrowserElement(&inBrowser);
attrs.CopyFromLoadContext(mLoadContext);
}
// TODO: Bug 1165466 - use originAttribute in nsILoadContext.
OriginAttributes attrs(appId, inBrowser);
nsCOMPtr<nsIPrincipal> principal =
BasePrincipal::CreateCodebasePrincipal(uri, attrs);

View File

@ -211,6 +211,10 @@ ChannelEventSink.prototype = {
function LoadContextCallback(appId, inBrowserElement, isPrivate, isContent) {
this.appId = appId;
this.isInBrowserElement = inBrowserElement;
this.originAttributes = {
appId: appId,
inBrowser: inBrowserElement
};
this.usePrivateBrowsing = isPrivate;
this.isContent = isContent;
}

View File

@ -31,6 +31,10 @@ function makeChan(url, appId, inBrowser) {
chan.notificationCallbacks = {
appId: appId,
isInBrowserElement: inBrowser,
originAttributes: {
appId: appId,
inBrowser: inBrowser,
},
QueryInterface: function(iid) {
if (iid.equals(Ci.nsILoadContext))
return this;

View File

@ -33,7 +33,9 @@ LoadContext.prototype = {
if (iid.equals(Ci.nsILoadContext))
return this;
throw Cr.NS_ERROR_NO_INTERFACE;
}
},
originAttributes: {}
};
PrivateBrowsingLoadContext = new LoadContext(true);

View File

@ -38,7 +38,9 @@ LoadContext.prototype = {
}
throw Cr.NS_ERROR_NO_INTERFACE;
}
},
originAttributes: {}
};
var load_context = new LoadContext();

View File

@ -19,6 +19,10 @@ function makeChan(url, appId, inBrowser) {
chan.notificationCallbacks = {
appId: appId,
isInBrowserElement: inBrowser,
originAttributes: {
appId: appId,
inBrowser: inBrowser,
},
QueryInterface: function(iid) {
if (iid.equals(Ci.nsILoadContext))
return this;

View File

@ -51,11 +51,11 @@ NS_IMPL_ISUPPORTS(OfflineCacheUpdateParent,
// OfflineCacheUpdateParent <public>
//-----------------------------------------------------------------------------
// TODO: Bug 1191740 - Add OriginAttributes in TabContext
OfflineCacheUpdateParent::OfflineCacheUpdateParent(uint32_t aAppId,
bool aIsInBrowser)
: mIPCClosed(false)
, mIsInBrowserElement(aIsInBrowser)
, mAppId(aAppId)
, mOriginAttributes(aAppId, aIsInBrowser)
{
// Make sure the service has been initialized
nsOfflineCacheUpdateService::EnsureService();
@ -93,10 +93,8 @@ OfflineCacheUpdateParent::Schedule(const URIParams& aManifestURI,
bool offlinePermissionAllowed = false;
// TODO: Bug 1165466 - use OriginAttributes
OriginAttributes attrs(mAppId, mIsInBrowserElement);
nsCOMPtr<nsIPrincipal> principal =
BasePrincipal::CreateCodebasePrincipal(manifestURI, attrs);
BasePrincipal::CreateCodebasePrincipal(manifestURI, mOriginAttributes);
nsresult rv = service->OfflineAppAllowed(
principal, nullptr, &offlinePermissionAllowed);
@ -112,7 +110,11 @@ OfflineCacheUpdateParent::Schedule(const URIParams& aManifestURI,
if (!NS_SecurityCompareURIs(manifestURI, documentURI, false))
return NS_ERROR_DOM_SECURITY_ERR;
service->FindUpdate(manifestURI, mAppId, mIsInBrowserElement, nullptr,
// TODO: Bug 1197093 - add originAttributes to nsIOfflineCacheUpdate
service->FindUpdate(manifestURI,
mOriginAttributes.mAppId,
mOriginAttributes.mInBrowser,
nullptr,
getter_AddRefs(update));
if (!update) {
update = new nsOfflineCacheUpdate();
@ -120,7 +122,7 @@ OfflineCacheUpdateParent::Schedule(const URIParams& aManifestURI,
// Leave aDocument argument null. Only glues and children keep
// document instances.
rv = update->Init(manifestURI, documentURI, nullptr, nullptr,
mAppId, mIsInBrowserElement);
mOriginAttributes.mAppId, mOriginAttributes.mInBrowser);
NS_ENSURE_SUCCESS(rv, rv);
rv = update->Schedule();
@ -254,14 +256,25 @@ OfflineCacheUpdateParent::SetRemoteTabs(bool aUseRemoteTabs)
NS_IMETHODIMP
OfflineCacheUpdateParent::GetIsInBrowserElement(bool *aIsInBrowserElement)
{
*aIsInBrowserElement = mIsInBrowserElement;
*aIsInBrowserElement = mOriginAttributes.mInBrowser;
return NS_OK;
}
NS_IMETHODIMP
OfflineCacheUpdateParent::GetAppId(uint32_t *aAppId)
{
*aAppId = mAppId;
*aAppId = mOriginAttributes.mAppId;
return NS_OK;
}
NS_IMETHODIMP
OfflineCacheUpdateParent::GetOriginAttributes(JS::MutableHandleValue aAttrs)
{
JSContext* cx = nsContentUtils::GetCurrentJSContext();
MOZ_ASSERT(cx);
bool ok = ToJSValue(cx, mOriginAttributes, aAttrs);
NS_ENSURE_TRUE(ok, NS_ERROR_FAILURE);
return NS_OK;
}

View File

@ -7,6 +7,7 @@
#define nsOfflineCacheUpdateParent_h
#include "mozilla/docshell/POfflineCacheUpdateParent.h"
#include "mozilla/BasePrincipal.h"
#include "nsIOfflineCacheUpdate.h"
#include "nsString.h"
@ -45,14 +46,12 @@ public:
OfflineCacheUpdateParent(uint32_t aAppId, bool aIsInBrowser);
virtual void ActorDestroy(ActorDestroyReason aWhy) override;
private:
~OfflineCacheUpdateParent();
bool mIPCClosed;
bool mIsInBrowserElement;
uint32_t mAppId;
mozilla::OriginAttributes mOriginAttributes;
};
} // namespace docshell