Bug 1616171 - P3: Move initatorType from DocumentChannelCreationArgs to BC. r=mattwoodrow,nika

Differential Revision: https://phabricator.services.mozilla.com/D63452
This commit is contained in:
Dan Glastonbury
2020-02-25 23:17:56 +00:00
parent 113009b2f1
commit 98cd5d2e09
12 changed files with 73 additions and 55 deletions

View File

@@ -291,7 +291,8 @@ BrowsingContext::BrowsingContext(BrowsingContext* aParent,
mIsDiscarded(false), mIsDiscarded(false),
mWindowless(false), mWindowless(false),
mDanglingRemoteOuterProxies(false), mDanglingRemoteOuterProxies(false),
mPendingInitialization(false) { mPendingInitialization(false),
mEmbeddedByThisProcess(false) {
MOZ_RELEASE_ASSERT(!mParent || mParent->Group() == mGroup); MOZ_RELEASE_ASSERT(!mParent || mParent->Group() == mGroup);
MOZ_RELEASE_ASSERT(mBrowsingContextId != 0); MOZ_RELEASE_ASSERT(mBrowsingContextId != 0);
MOZ_RELEASE_ASSERT(mGroup); MOZ_RELEASE_ASSERT(mGroup);
@@ -352,12 +353,16 @@ void BrowsingContext::CleanUpDanglingRemoteOuterWindowProxies(
} }
void BrowsingContext::SetEmbedderElement(Element* aEmbedder) { void BrowsingContext::SetEmbedderElement(Element* aEmbedder) {
mEmbeddedByThisProcess = true;
// Notify the parent process of the embedding status. We don't need to do // Notify the parent process of the embedding status. We don't need to do
// this when clearing our embedder, as we're being destroyed either way. // this when clearing our embedder, as we're being destroyed either way.
if (aEmbedder) { if (aEmbedder) {
if (nsCOMPtr<nsPIDOMWindowInner> inner = if (nsCOMPtr<nsPIDOMWindowInner> inner =
do_QueryInterface(aEmbedder->GetOwnerGlobal())) { do_QueryInterface(aEmbedder->GetOwnerGlobal())) {
SetEmbedderInnerWindowId(inner->WindowID()); Transaction txn;
txn.SetEmbedderInnerWindowId(inner->WindowID());
txn.SetEmbedderElementType(Some(aEmbedder->LocalName()));
txn.Commit(this);
} }
} }
@@ -1395,6 +1400,17 @@ bool BrowsingContext::CanSet(FieldIndex<IDX_UserAgentOverride>,
return true; return true;
} }
bool BrowsingContext::CheckOnlyEmbedderCanSet(ContentParent* aSource) {
if (aSource) {
// Set by a content process, verify that it's this BC's embedder.
MOZ_ASSERT(XRE_IsParentProcess());
return Canonical()->IsEmbeddedInProcess(aSource->ChildID());
}
// In-process case, verify that we've been embedded in this process.
return mEmbeddedByThisProcess;
}
bool BrowsingContext::CanSet(FieldIndex<IDX_EmbedderInnerWindowId>, bool BrowsingContext::CanSet(FieldIndex<IDX_EmbedderInnerWindowId>,
const uint64_t& aValue, ContentParent* aSource) { const uint64_t& aValue, ContentParent* aSource) {
// Generally allow clearing this. We may want to be more precise about this // Generally allow clearing this. We may want to be more precise about this
@@ -1449,6 +1465,11 @@ bool BrowsingContext::CanSet(FieldIndex<IDX_EmbedderInnerWindowId>,
return true; return true;
} }
bool BrowsingContext::CanSet(FieldIndex<IDX_EmbedderElementType>,
const Maybe<nsString>&, ContentParent* aSource) {
return CheckOnlyEmbedderCanSet(aSource);
}
bool BrowsingContext::CanSet(FieldIndex<IDX_CurrentInnerWindowId>, bool BrowsingContext::CanSet(FieldIndex<IDX_CurrentInnerWindowId>,
const uint64_t& aValue, ContentParent* aSource) { const uint64_t& aValue, ContentParent* aSource) {
// Generally allow clearing this. We may want to be more precise about this // Generally allow clearing this. We may want to be more precise about this

View File

@@ -32,6 +32,7 @@
class nsDocShellLoadState; class nsDocShellLoadState;
class nsGlobalWindowOuter; class nsGlobalWindowOuter;
class nsILoadInfo;
class nsIPrincipal; class nsIPrincipal;
class nsOuterWindowProxy; class nsOuterWindowProxy;
class PickleIterator; class PickleIterator;
@@ -108,7 +109,8 @@ class WindowProxyHolder;
/* ScreenOrientation-related APIs */ \ /* ScreenOrientation-related APIs */ \
FIELD(CurrentOrientationAngle, float) \ FIELD(CurrentOrientationAngle, float) \
FIELD(CurrentOrientationType, mozilla::dom::OrientationType) \ FIELD(CurrentOrientationType, mozilla::dom::OrientationType) \
FIELD(UserAgentOverride, nsString) FIELD(UserAgentOverride, nsString) \
FIELD(EmbedderElementType, Maybe<nsString>)
// BrowsingContext, in this context, is the cross process replicated // BrowsingContext, in this context, is the cross process replicated
// environment in which information about documents is stored. In // environment in which information about documents is stored. In
@@ -637,6 +639,9 @@ class BrowsingContext : public nsISupports, public nsWrapperCache {
bool CanSet(FieldIndex<IDX_UserAgentOverride>, const nsString& aUserAgent, bool CanSet(FieldIndex<IDX_UserAgentOverride>, const nsString& aUserAgent,
ContentParent* aSource); ContentParent* aSource);
bool CanSet(FieldIndex<IDX_EmbedderElementType>,
const Maybe<nsString>& aInitiatorType, ContentParent* aSource);
template <size_t I, typename T> template <size_t I, typename T>
bool CanSet(FieldIndex<I>, const T&, ContentParent*) { bool CanSet(FieldIndex<I>, const T&, ContentParent*) {
return true; return true;
@@ -645,6 +650,10 @@ class BrowsingContext : public nsISupports, public nsWrapperCache {
template <size_t I> template <size_t I>
void DidSet(FieldIndex<I>) {} void DidSet(FieldIndex<I>) {}
// True if the process attempting to set field is the same as the embedder's
// process.
bool CheckOnlyEmbedderCanSet(ContentParent* aSource);
// Type of BrowsingContent // Type of BrowsingContent
const Type mType; const Type mType;
@@ -694,6 +703,10 @@ class BrowsingContext : public nsISupports, public nsWrapperCache {
// as the target of a load. // as the target of a load.
bool mPendingInitialization : 1; bool mPendingInitialization : 1;
// True if this BrowsingContext has been embedded in a element in this
// process.
bool mEmbeddedByThisProcess : 1;
// The start time of user gesture, this is only available if the browsing // The start time of user gesture, this is only available if the browsing
// context is in process. // context is in process.
TimeStamp mUserGestureStart; TimeStamp mUserGestureStart;

View File

@@ -9361,9 +9361,11 @@ static bool SchemeUsesDocChannel(nsIURI* aURI) {
/* static */ bool nsDocShell::CreateAndConfigureRealChannelForLoadState( /* static */ bool nsDocShell::CreateAndConfigureRealChannelForLoadState(
nsDocShellLoadState* aLoadState, LoadInfo* aLoadInfo, nsDocShellLoadState* aLoadState, LoadInfo* aLoadInfo,
nsIInterfaceRequestor* aCallbacks, nsDocShell* aDocShell, nsIInterfaceRequestor* aCallbacks, nsDocShell* aDocShell,
const nsString* aInitiatorType, nsLoadFlags aLoadFlags, uint32_t aLoadType, nsLoadFlags aLoadFlags, uint32_t aLoadType, uint32_t aCacheKey,
uint32_t aCacheKey, bool aIsActive, bool aIsTopLevelDoc, bool aIsActive, bool aIsTopLevelDoc, bool aHasNonEmptySandboxingFlags,
bool aHasNonEmptySandboxingFlags, nsresult& aRv, nsIChannel** aChannel) { nsresult& aRv, nsIChannel** aChannel) {
MOZ_ASSERT(aLoadInfo);
nsString srcdoc = VoidString(); nsString srcdoc = VoidString();
bool isSrcdoc = aLoadState->HasLoadFlags(INTERNAL_LOAD_FLAGS_IS_SRCDOC); bool isSrcdoc = aLoadState->HasLoadFlags(INTERNAL_LOAD_FLAGS_IS_SRCDOC);
if (isSrcdoc) { if (isSrcdoc) {
@@ -9555,8 +9557,10 @@ static bool SchemeUsesDocChannel(nsIURI* aURI) {
if (nsCOMPtr<nsITimedChannel> timedChannel = do_QueryInterface(channel)) { if (nsCOMPtr<nsITimedChannel> timedChannel = do_QueryInterface(channel)) {
timedChannel->SetTimingEnabled(true); timedChannel->SetTimingEnabled(true);
if (aInitiatorType) { RefPtr<dom::BrowsingContext> bc;
timedChannel->SetInitiatorType(*aInitiatorType); MOZ_ALWAYS_SUCCEEDS(aLoadInfo->GetFrameBrowsingContext(getter_AddRefs(bc)));
if (bc && bc->GetEmbedderElementType()) {
timedChannel->SetInitiatorType(*bc->GetEmbedderElementType());
} }
} }
@@ -9855,15 +9859,6 @@ nsresult nsDocShell::DoURILoad(nsDocShellLoadState* aLoadState,
cacheKey = mOSHE->GetCacheKey(); cacheKey = mOSHE->GetCacheKey();
} }
const nsString* initiatorType = nullptr;
nsCOMPtr<nsPIDOMWindowOuter> win = GetWindow();
if (IsFrame() && win) {
nsCOMPtr<Element> frameElement = win->GetFrameElementInternal();
if (frameElement) {
initiatorType = &frameElement->LocalName();
}
}
bool isActive = mBrowsingContext->GetIsActive() || bool isActive = mBrowsingContext->GetIsActive() ||
(mLoadType & (LOAD_CMD_NORMAL | LOAD_CMD_HISTORY)); (mLoadType & (LOAD_CMD_NORMAL | LOAD_CMD_HISTORY));
@@ -9878,13 +9873,13 @@ nsresult nsDocShell::DoURILoad(nsDocShellLoadState* aLoadState,
if (StaticPrefs::browser_tabs_documentchannel() && XRE_IsContentProcess() && if (StaticPrefs::browser_tabs_documentchannel() && XRE_IsContentProcess() &&
canUseDocumentChannel) { canUseDocumentChannel) {
channel = new DocumentChannelChild(aLoadState, loadInfo, initiatorType, channel = new DocumentChannelChild(aLoadState, loadInfo, loadFlags,
loadFlags, mLoadType, cacheKey, isActive, mLoadType, cacheKey, isActive,
isTopLevelDoc, sandboxFlags); isTopLevelDoc, sandboxFlags);
channel->SetNotificationCallbacks(this); channel->SetNotificationCallbacks(this);
} else if (!CreateAndConfigureRealChannelForLoadState( } else if (!CreateAndConfigureRealChannelForLoadState(
aLoadState, loadInfo, this, this, initiatorType, loadFlags, aLoadState, loadInfo, this, this, loadFlags, mLoadType,
mLoadType, cacheKey, isActive, isTopLevelDoc, cacheKey, isActive, isTopLevelDoc,
mBrowsingContext->GetSandboxFlags(), rv, mBrowsingContext->GetSandboxFlags(), rv,
getter_AddRefs(channel))) { getter_AddRefs(channel))) {
return rv; return rv;

View File

@@ -501,10 +501,9 @@ class nsDocShell final : public nsDocLoader,
static bool CreateAndConfigureRealChannelForLoadState( static bool CreateAndConfigureRealChannelForLoadState(
nsDocShellLoadState* aLoadState, mozilla::net::LoadInfo* aLoadInfo, nsDocShellLoadState* aLoadState, mozilla::net::LoadInfo* aLoadInfo,
nsIInterfaceRequestor* aCallbacks, nsDocShell* aDocShell, nsIInterfaceRequestor* aCallbacks, nsDocShell* aDocShell,
const nsString* aInitiatorType, nsLoadFlags aLoadFlags, nsLoadFlags aLoadFlags, uint32_t aLoadType, uint32_t aCacheKey,
uint32_t aLoadType, uint32_t aCacheKey, bool aIsActive, bool aIsActive, bool aIsTopLevelDoc, bool aHasNonEmptySandboxingFlags,
bool aIsTopLevelDoc, bool aHasNonEmptySandboxingFlags, nsresult& rv, nsresult& rv, nsIChannel** aChannel);
nsIChannel** aChannel);
// Notify consumers of a search being loaded through the observer service: // Notify consumers of a search being loaded through the observer service:
static void MaybeNotifyKeywordSearchLoading(const nsString& aProvider, static void MaybeNotifyKeywordSearchLoading(const nsString& aProvider,

View File

@@ -85,14 +85,12 @@ NS_INTERFACE_MAP_END
DocumentChannel::DocumentChannel(nsDocShellLoadState* aLoadState, DocumentChannel::DocumentChannel(nsDocShellLoadState* aLoadState,
net::LoadInfo* aLoadInfo, net::LoadInfo* aLoadInfo,
const nsString* aInitiatorType,
nsLoadFlags aLoadFlags, uint32_t aLoadType, nsLoadFlags aLoadFlags, uint32_t aLoadType,
uint32_t aCacheKey, bool aIsActive, uint32_t aCacheKey, bool aIsActive,
bool aIsTopLevelDoc, bool aIsTopLevelDoc,
bool aHasNonEmptySandboxingFlags) bool aHasNonEmptySandboxingFlags)
: mAsyncOpenTime(TimeStamp::Now()), : mAsyncOpenTime(TimeStamp::Now()),
mLoadState(aLoadState), mLoadState(aLoadState),
mInitiatorType(aInitiatorType ? Some(*aInitiatorType) : Nothing()),
mLoadType(aLoadType), mLoadType(aLoadType),
mCacheKey(aCacheKey), mCacheKey(aCacheKey),
mIsActive(aIsActive), mIsActive(aIsActive),

View File

@@ -45,9 +45,9 @@ class DocumentChannel : public nsIIdentChannel, public nsITraceableChannel {
NS_DECLARE_STATIC_IID_ACCESSOR(DOCUMENT_CHANNEL_IID) NS_DECLARE_STATIC_IID_ACCESSOR(DOCUMENT_CHANNEL_IID)
DocumentChannel(nsDocShellLoadState* aLoadState, class LoadInfo* aLoadInfo, DocumentChannel(nsDocShellLoadState* aLoadState, class LoadInfo* aLoadInfo,
const nsString* aInitiatorType, nsLoadFlags aLoadFlags, nsLoadFlags aLoadFlags, uint32_t aLoadType,
uint32_t aLoadType, uint32_t aCacheKey, bool aIsActive, uint32_t aCacheKey, bool aIsActive, bool aIsTopLevelDoc,
bool aIsTopLevelDoc, bool aHasNonEmptySandboxingFlags); bool aHasNonEmptySandboxingFlags);
const nsTArray<DocumentChannelRedirect>& GetRedirectChain() const { const nsTArray<DocumentChannelRedirect>& GetRedirectChain() const {
return mRedirects; return mRedirects;
@@ -77,7 +77,6 @@ class DocumentChannel : public nsIIdentChannel, public nsITraceableChannel {
const TimeStamp mAsyncOpenTime; const TimeStamp mAsyncOpenTime;
const RefPtr<nsDocShellLoadState> mLoadState; const RefPtr<nsDocShellLoadState> mLoadState;
const Maybe<nsString> mInitiatorType;
const uint32_t mLoadType; const uint32_t mLoadType;
const uint32_t mCacheKey; const uint32_t mCacheKey;
const bool mIsActive; const bool mIsActive;

View File

@@ -28,12 +28,10 @@ NS_IMPL_RELEASE_INHERITED(DocumentChannelChild, DocumentChannel)
DocumentChannelChild::DocumentChannelChild( DocumentChannelChild::DocumentChannelChild(
nsDocShellLoadState* aLoadState, net::LoadInfo* aLoadInfo, nsDocShellLoadState* aLoadState, net::LoadInfo* aLoadInfo,
const nsString* aInitiatorType, nsLoadFlags aLoadFlags, uint32_t aLoadType, nsLoadFlags aLoadFlags, uint32_t aLoadType, uint32_t aCacheKey,
uint32_t aCacheKey, bool aIsActive, bool aIsTopLevelDoc, bool aIsActive, bool aIsTopLevelDoc, bool aHasNonEmptySandboxingFlags)
bool aHasNonEmptySandboxingFlags) : DocumentChannel(aLoadState, aLoadInfo, aLoadFlags, aLoadType, aCacheKey,
: DocumentChannel(aLoadState, aLoadInfo, aInitiatorType, aLoadFlags, aIsActive, aIsTopLevelDoc, aHasNonEmptySandboxingFlags) {
aLoadType, aCacheKey, aIsActive, aIsTopLevelDoc,
aHasNonEmptySandboxingFlags) {
LOG(("DocumentChannelChild ctor [this=%p, uri=%s]", this, LOG(("DocumentChannelChild ctor [this=%p, uri=%s]", this,
aLoadState->URI()->GetSpecOrDefault().get())); aLoadState->URI()->GetSpecOrDefault().get()));
} }
@@ -116,7 +114,6 @@ DocumentChannelChild::AsyncOpen(nsIStreamListener* aListener) {
args.loadInfo() = *maybeArgs; args.loadInfo() = *maybeArgs;
args.loadFlags() = mLoadFlags; args.loadFlags() = mLoadFlags;
args.initiatorType() = mInitiatorType;
args.loadType() = mLoadType; args.loadType() = mLoadType;
args.cacheKey() = mCacheKey; args.cacheKey() = mCacheKey;
args.isActive() = mIsActive; args.isActive() = mIsActive;

View File

@@ -25,8 +25,7 @@ class DocumentChannelChild final : public DocumentChannel,
public PDocumentChannelChild { public PDocumentChannelChild {
public: public:
DocumentChannelChild(nsDocShellLoadState* aLoadState, DocumentChannelChild(nsDocShellLoadState* aLoadState,
class LoadInfo* aLoadInfo, class LoadInfo* aLoadInfo, nsLoadFlags aLoadFlags,
const nsString* aInitiatorType, nsLoadFlags aLoadFlags,
uint32_t aLoadType, uint32_t aCacheKey, bool aIsActive, uint32_t aLoadType, uint32_t aCacheKey, bool aIsActive,
bool aIsTopLevelDoc, bool aHasNonEmptySandboxingFlags); bool aIsTopLevelDoc, bool aHasNonEmptySandboxingFlags);

View File

@@ -39,9 +39,8 @@ bool DocumentChannelParent::Init(BrowserParent* aBrowser,
rv = NS_ERROR_UNEXPECTED; rv = NS_ERROR_UNEXPECTED;
if (!mParent->Open( if (!mParent->Open(
aBrowser, loadState, loadInfo, aArgs.initiatorType().ptrOr(nullptr), aBrowser, loadState, loadInfo, aArgs.loadFlags(), aArgs.loadType(),
aArgs.loadFlags(), aArgs.loadType(), aArgs.cacheKey(), aArgs.cacheKey(), aArgs.isActive(), aArgs.isTopLevelDoc(),
aArgs.isActive(), aArgs.isTopLevelDoc(),
aArgs.hasNonEmptySandboxingFlags(), aArgs.topWindowURI(), aArgs.hasNonEmptySandboxingFlags(), aArgs.topWindowURI(),
aArgs.contentBlockingAllowListPrincipal(), aArgs.channelId(), aArgs.contentBlockingAllowListPrincipal(), aArgs.channelId(),
aArgs.asyncOpenTime(), aArgs.documentOpenFlags(), aArgs.asyncOpenTime(), aArgs.documentOpenFlags(),

View File

@@ -250,10 +250,9 @@ DocumentLoadListener::~DocumentLoadListener() {
bool DocumentLoadListener::Open( bool DocumentLoadListener::Open(
BrowserParent* aBrowser, nsDocShellLoadState* aLoadState, BrowserParent* aBrowser, nsDocShellLoadState* aLoadState,
class LoadInfo* aLoadInfo, const nsString* aInitiatorType, LoadInfo* aLoadInfo, nsLoadFlags aLoadFlags, uint32_t aLoadType,
nsLoadFlags aLoadFlags, uint32_t aLoadType, uint32_t aCacheKey, uint32_t aCacheKey, bool aIsActive, bool aIsTopLevelDoc,
bool aIsActive, bool aIsTopLevelDoc, bool aHasNonEmptySandboxingFlags, bool aHasNonEmptySandboxingFlags, const Maybe<URIParams>& aTopWindowURI,
const Maybe<URIParams>& aTopWindowURI,
const Maybe<PrincipalInfo>& aContentBlockingAllowListPrincipal, const Maybe<PrincipalInfo>& aContentBlockingAllowListPrincipal,
const uint64_t& aChannelId, const TimeStamp& aAsyncOpenTime, const uint64_t& aChannelId, const TimeStamp& aAsyncOpenTime,
const Maybe<uint32_t>& aDocumentOpenFlags, bool aPluginsAllowed, const Maybe<uint32_t>& aDocumentOpenFlags, bool aPluginsAllowed,
@@ -262,10 +261,9 @@ bool DocumentLoadListener::Open(
aLoadState->URI()->GetSpecOrDefault().get())); aLoadState->URI()->GetSpecOrDefault().get()));
if (!nsDocShell::CreateAndConfigureRealChannelForLoadState( if (!nsDocShell::CreateAndConfigureRealChannelForLoadState(
aLoadState, aLoadInfo, mParentChannelListener, nullptr, aLoadState, aLoadInfo, mParentChannelListener, nullptr, aLoadFlags,
aInitiatorType, aLoadFlags, aLoadType, aCacheKey, aIsActive, aLoadType, aCacheKey, aIsActive, aIsTopLevelDoc,
aIsTopLevelDoc, aHasNonEmptySandboxingFlags, *aRv, aHasNonEmptySandboxingFlags, *aRv, getter_AddRefs(mChannel))) {
getter_AddRefs(mChannel))) {
mParentChannelListener = nullptr; mParentChannelListener = nullptr;
return false; return false;
} }

View File

@@ -34,6 +34,8 @@
namespace mozilla { namespace mozilla {
namespace net { namespace net {
class LoadInfo;
/** /**
* DocumentLoadListener represents a connecting document load for a * DocumentLoadListener represents a connecting document load for a
* CanonicalBrowsingContext (in the parent process). * CanonicalBrowsingContext (in the parent process).
@@ -71,9 +73,8 @@ class DocumentLoadListener : public nsIInterfaceRequestor,
// expect Necko to pass it again so that we don't need a member var for // expect Necko to pass it again so that we don't need a member var for
// it. // it.
bool Open(dom::BrowserParent* aBrowser, nsDocShellLoadState* aLoadState, bool Open(dom::BrowserParent* aBrowser, nsDocShellLoadState* aLoadState,
class LoadInfo* aLoadInfo, const nsString* aInitiatorType, LoadInfo* aLoadInfo, nsLoadFlags aLoadFlags, uint32_t aLoadType,
nsLoadFlags aLoadFlags, uint32_t aLoadType, uint32_t aCacheKey, uint32_t aCacheKey, bool aIsActive, bool aIsTopLevelDoc,
bool aIsActive, bool aIsTopLevelDoc,
bool aHasNonEmptySandboxingFlags, bool aHasNonEmptySandboxingFlags,
const Maybe<ipc::URIParams>& aTopWindowURI, const Maybe<ipc::URIParams>& aTopWindowURI,
const Maybe<ipc::PrincipalInfo>& aContentBlockingAllowListPrincipal, const Maybe<ipc::PrincipalInfo>& aContentBlockingAllowListPrincipal,

View File

@@ -402,7 +402,6 @@ struct DocumentChannelCreationArgs {
LoadInfoArgs loadInfo; LoadInfoArgs loadInfo;
PrincipalInfo? contentBlockingAllowListPrincipal; PrincipalInfo? contentBlockingAllowListPrincipal;
TimeStamp asyncOpenTime; TimeStamp asyncOpenTime;
nsString? initiatorType;
uint64_t channelId; uint64_t channelId;
uint32_t loadFlags; uint32_t loadFlags;
uint32_t loadType; uint32_t loadType;