Skip to content

Commit

Permalink
Bug 1602318 - Expose LoadContext on BrowsingContext webidl. r=nika,km…
Browse files Browse the repository at this point in the history
…ag,necko-reviewers

Differential Revision: https://phabricator.services.mozilla.com/D71135
  • Loading branch information
mattwoodrow committed Apr 24, 2020
1 parent dae1822 commit 89ca645
Show file tree
Hide file tree
Showing 12 changed files with 84 additions and 57 deletions.
49 changes: 42 additions & 7 deletions docshell/base/BrowsingContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1107,6 +1107,47 @@ bool BrowsingContext::CanSetOriginAttributes() {
return true;
}

Nullable<WindowProxyHolder> BrowsingContext::GetAssociatedWindow() {
// nsILoadContext usually only returns same-process windows,
// so we intentionally return nullptr if this BC is out of
// process.
if (IsInProcess()) {
return WindowProxyHolder(this);
}
return nullptr;
}

Nullable<WindowProxyHolder> BrowsingContext::GetTopWindow() {
return Top()->GetAssociatedWindow();
}

Element* BrowsingContext::GetTopFrameElement() {
return Top()->GetEmbedderElement();
}

void BrowsingContext::SetUsePrivateBrowsing(bool aUsePrivateBrowsing,
ErrorResult& aError) {
nsresult rv = SetUsePrivateBrowsing(aUsePrivateBrowsing);
if (NS_FAILED(rv)) {
aError.Throw(rv);
}
}

void BrowsingContext::SetUseTrackingProtectionWebIDL(
bool aUseTrackingProtection) {
SetForceEnableTrackingProtection(aUseTrackingProtection);
}

void BrowsingContext::GetOriginAttributes(JSContext* aCx,
JS::MutableHandle<JS::Value> aVal,
ErrorResult& aError) {
AssertOriginAttributesMatchPrivateBrowsing();

if (!ToJSValue(aCx, mOriginAttributes, aVal)) {
aError.NoteJSContextException(aCx);
}
}

NS_IMETHODIMP BrowsingContext::GetAssociatedWindow(
mozIDOMWindowProxy** aAssociatedWindow) {
nsCOMPtr<mozIDOMWindowProxy> win = GetDOMWindow();
Expand All @@ -1119,17 +1160,11 @@ NS_IMETHODIMP BrowsingContext::GetTopWindow(mozIDOMWindowProxy** aTopWindow) {
}

NS_IMETHODIMP BrowsingContext::GetTopFrameElement(Element** aTopFrameElement) {
RefPtr<Element> topFrameElement = Top()->GetEmbedderElement();
RefPtr<Element> topFrameElement = GetTopFrameElement();
topFrameElement.forget(aTopFrameElement);
return NS_OK;
}

NS_IMETHODIMP BrowsingContext::GetNestedFrameId(uint64_t* aNestedFrameId) {
// FIXME: nestedFrameId should be removed, as it was only used by B2G.
*aNestedFrameId = 0;
return NS_OK;
}

NS_IMETHODIMP BrowsingContext::GetIsContent(bool* aIsContent) {
*aIsContent = IsContent();
return NS_OK;
Expand Down
16 changes: 15 additions & 1 deletion docshell/base/BrowsingContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,8 @@ class BrowsingContext : public nsILoadContext, public nsWrapperCache {
void RestoreChildren(Children&& aChildren, bool aFromIPC = false);

// Triggers a load in the process which currently owns this BrowsingContext.
nsresult LoadURI(nsDocShellLoadState* aLoadState, bool aSetNavigating = false);
nsresult LoadURI(nsDocShellLoadState* aLoadState,
bool aSetNavigating = false);

nsresult InternalLoad(nsDocShellLoadState* aLoadState,
nsIDocShell** aDocShell, nsIRequest** aRequest);
Expand Down Expand Up @@ -353,6 +354,19 @@ class BrowsingContext : public nsILoadContext, public nsWrapperCache {

BrowsingContextGroup* Group() { return mGroup; }

// WebIDL bindings for nsILoadContext
Nullable<WindowProxyHolder> GetAssociatedWindow();
Nullable<WindowProxyHolder> GetTopWindow();
Element* GetTopFrameElement();
bool GetIsContent() { return IsContent(); }
void SetUsePrivateBrowsing(bool aUsePrivateBrowsing, ErrorResult& aError);
// Needs a different name to disambiguate from the xpidl method with
// the same signature but different return value.
void SetUseTrackingProtectionWebIDL(bool aUseTrackingProtection);
bool UseTrackingProtectionWebIDL() { return UseTrackingProtection(); }
void GetOriginAttributes(JSContext* aCx, JS::MutableHandle<JS::Value> aVal,
ErrorResult& aError);

bool InRDMPane() const { return GetInRDMPane(); }

float FullZoom() const { return GetFullZoom(); }
Expand Down
8 changes: 0 additions & 8 deletions docshell/base/LoadContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ NS_IMPL_ISUPPORTS(LoadContext, nsILoadContext, nsIInterfaceRequestor)
LoadContext::LoadContext(nsIPrincipal* aPrincipal,
nsILoadContext* aOptionalBase)
: mTopFrameElement(nullptr),
mNestedFrameId(0),
mIsContent(true),
mUseRemoteTabs(false),
mUseRemoteSubframes(false),
Expand Down Expand Up @@ -68,13 +67,6 @@ LoadContext::GetTopFrameElement(dom::Element** aElement) {
return NS_OK;
}

NS_IMETHODIMP
LoadContext::GetNestedFrameId(uint64_t* aId) {
NS_ENSURE_ARG(aId);
*aId = mNestedFrameId;
return NS_OK;
}

NS_IMETHODIMP
LoadContext::GetIsContent(bool* aIsContent) {
MOZ_ASSERT(mIsNotNull);
Expand Down
18 changes: 0 additions & 18 deletions docshell/base/LoadContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,21 +36,6 @@ class LoadContext final : public nsILoadContext, public nsIInterfaceRequestor {
LoadContext(const IPC::SerializedLoadContext& aToCopy,
dom::Element* aTopFrameElement, OriginAttributes& aAttrs)
: mTopFrameElement(do_GetWeakReference(aTopFrameElement)),
mNestedFrameId(0),
mIsContent(aToCopy.mIsContent),
mUseRemoteTabs(aToCopy.mUseRemoteTabs),
mUseRemoteSubframes(aToCopy.mUseRemoteSubframes),
mUseTrackingProtection(aToCopy.mUseTrackingProtection),
#ifdef DEBUG
mIsNotNull(aToCopy.mIsNotNull),
#endif
mOriginAttributes(aAttrs) {
}

LoadContext(const IPC::SerializedLoadContext& aToCopy,
uint64_t aNestedFrameId, OriginAttributes& aAttrs)
: mTopFrameElement(nullptr),
mNestedFrameId(aNestedFrameId),
mIsContent(aToCopy.mIsContent),
mUseRemoteTabs(aToCopy.mUseRemoteTabs),
mUseRemoteSubframes(aToCopy.mUseRemoteSubframes),
Expand All @@ -66,7 +51,6 @@ class LoadContext final : public nsILoadContext, public nsIInterfaceRequestor {
bool aUseRemoteSubframes, bool aUseTrackingProtection,
const OriginAttributes& aAttrs)
: mTopFrameElement(do_GetWeakReference(aTopFrameElement)),
mNestedFrameId(0),
mIsContent(aIsContent),
mUseRemoteTabs(aUseRemoteTabs),
mUseRemoteSubframes(aUseRemoteSubframes),
Expand All @@ -82,7 +66,6 @@ class LoadContext final : public nsILoadContext, public nsIInterfaceRequestor {
// Constructor taking reserved origin attributes.
explicit LoadContext(OriginAttributes& aAttrs)
: mTopFrameElement(nullptr),
mNestedFrameId(0),
mIsContent(false),
mUseRemoteTabs(false),
mUseRemoteSubframes(false),
Expand All @@ -101,7 +84,6 @@ class LoadContext final : public nsILoadContext, public nsIInterfaceRequestor {
~LoadContext() {}

nsWeakPtr mTopFrameElement;
uint64_t mNestedFrameId;
bool mIsContent;
bool mUseRemoteTabs;
bool mUseRemoteSubframes;
Expand Down
5 changes: 0 additions & 5 deletions docshell/base/nsDocShell.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11765,11 +11765,6 @@ nsDocShell::GetTopFrameElement(Element** aElement) {
return mBrowsingContext->GetTopFrameElement(aElement);
}

NS_IMETHODIMP
nsDocShell::GetNestedFrameId(uint64_t* aId) {
return mBrowsingContext->GetNestedFrameId(aId);
}

NS_IMETHODIMP
nsDocShell::GetUseTrackingProtection(bool* aUseTrackingProtection) {
return mBrowsingContext->GetUseTrackingProtection(aUseTrackingProtection);
Expand Down
1 change: 0 additions & 1 deletion docshell/base/nsDocShell.h
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,6 @@ class nsDocShell final : public nsDocLoader,
NS_IMETHOD GetAssociatedWindow(mozIDOMWindowProxy**) override;
NS_IMETHOD GetTopWindow(mozIDOMWindowProxy**) override;
NS_IMETHOD GetTopFrameElement(mozilla::dom::Element**) override;
NS_IMETHOD GetNestedFrameId(uint64_t*) override;
NS_IMETHOD GetIsContent(bool*) override;
NS_IMETHOD GetUsePrivateBrowsing(bool*) override;
NS_IMETHOD SetUsePrivateBrowsing(bool) override;
Expand Down
8 changes: 0 additions & 8 deletions docshell/base/nsILoadContext.idl
Original file line number Diff line number Diff line change
Expand Up @@ -55,14 +55,6 @@ interface nsILoadContext : nsISupports
*/
readonly attribute Element topFrameElement;

/**
* If this LoadContext corresponds to a nested remote iframe, we don't have
* access to the topFrameElement. Instead, we must use this id to send
* messages. A return value of 0 signifies that this load context is not for
* a nested frame.
*/
readonly attribute unsigned long long nestedFrameId;

/**
* True if the load context is content (as opposed to chrome). This is
* determined based on the type of window the load is performed in, NOT based
Expand Down
3 changes: 1 addition & 2 deletions dom/browser-element/BrowserElementPromptService.jsm
Original file line number Diff line number Diff line change
Expand Up @@ -523,8 +523,7 @@ AuthPromptWrapper.prototype = {
);
let frame = context.topFrameElement;
if (!frame) {
// This function returns a boolean value
return !!context.nestedFrameId;
return false;
}

if (!BrowserElementPromptService.getBrowserElementParentForFrame(frame)) {
Expand Down
25 changes: 25 additions & 0 deletions dom/chrome-webidl/BrowsingContext.webidl
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,29 @@

interface nsIDocShell;

interface mixin LoadContextMixin {
readonly attribute WindowProxy? associatedWindow;

readonly attribute WindowProxy? topWindow;

readonly attribute Element? topFrameElement;

readonly attribute boolean isContent;

[SetterThrows]
attribute boolean usePrivateBrowsing;

readonly attribute boolean useRemoteTabs;

readonly attribute boolean useRemoteSubframes;

[BinaryName="useTrackingProtectionWebIDL"]
attribute boolean useTrackingProtection;

[NewObject, Throws]
readonly attribute any originAttributes;
};

[Exposed=Window, ChromeOnly]
interface BrowsingContext {
static BrowsingContext? get(unsigned long long aId);
Expand Down Expand Up @@ -70,6 +93,8 @@ interface BrowsingContext {
void setRDMPaneMaxTouchPoints(octet maxTouchPoints);
};

BrowsingContext includes LoadContextMixin;

[Exposed=Window, ChromeOnly]
interface CanonicalBrowsingContext : BrowsingContext {
sequence<WindowGlobalParent> getWindowGlobals();
Expand Down
1 change: 0 additions & 1 deletion dom/ipc/BrowserParent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3795,7 +3795,6 @@ class FakeChannel final : public nsIChannel,
elem.forget(aElement);
return NS_OK;
}
NS_IMETHOD GetNestedFrameId(uint64_t*) NO_IMPL;
NS_IMETHOD GetIsContent(bool*) NO_IMPL;
NS_IMETHOD GetUsePrivateBrowsing(bool*) NO_IMPL;
NS_IMETHOD SetUsePrivateBrowsing(bool) NO_IMPL;
Expand Down
2 changes: 1 addition & 1 deletion netwerk/ipc/NeckoParent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ const char* NeckoParent::CreateChannelLoadContext(
break;
}
case PBrowserOrId::TTabId: {
aResult = new LoadContext(aSerialized, aBrowser.get_TabId(), attrs);
aResult = new LoadContext(aSerialized, nullptr, attrs);
break;
}
default:
Expand Down
5 changes: 0 additions & 5 deletions uriloader/prefetch/OfflineCacheUpdateParent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -208,11 +208,6 @@ OfflineCacheUpdateParent::GetTopFrameElement(dom::Element** aElement) {
return NS_ERROR_NOT_IMPLEMENTED;
}

NS_IMETHODIMP
OfflineCacheUpdateParent::GetNestedFrameId(uint64_t* aId) {
return NS_ERROR_NOT_IMPLEMENTED;
}

NS_IMETHODIMP
OfflineCacheUpdateParent::GetIsContent(bool* aIsContent) {
return NS_ERROR_NOT_IMPLEMENTED;
Expand Down

0 comments on commit 89ca645

Please sign in to comment.