Bug 1602318 - Expose LoadContext on BrowsingContext webidl. r=nika,kmag,necko-reviewers

Differential Revision: https://phabricator.services.mozilla.com/D71135
This commit is contained in:
Matt Woodrow 2020-04-26 00:53:01 +00:00
parent 848bfde797
commit 98e4b6eb1f
12 changed files with 82 additions and 56 deletions

View File

@ -1071,6 +1071,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();
@ -1083,17 +1124,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;

View File

@ -346,6 +346,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(); }

View File

@ -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),
@ -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);

View File

@ -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),
@ -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),
@ -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),
@ -101,7 +84,6 @@ class LoadContext final : public nsILoadContext, public nsIInterfaceRequestor {
~LoadContext() {}
nsWeakPtr mTopFrameElement;
uint64_t mNestedFrameId;
bool mIsContent;
bool mUseRemoteTabs;
bool mUseRemoteSubframes;

View File

@ -11748,11 +11748,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);

View File

@ -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;

View File

@ -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

View File

@ -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)) {

View File

@ -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);
@ -70,6 +93,8 @@ interface BrowsingContext {
void setRDMPaneMaxTouchPoints(octet maxTouchPoints);
};
BrowsingContext includes LoadContextMixin;
[Exposed=Window, ChromeOnly]
interface CanonicalBrowsingContext : BrowsingContext {
sequence<WindowGlobalParent> getWindowGlobals();

View File

@ -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;

View File

@ -245,7 +245,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:

View File

@ -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;