diff options
author | Matt A. Tobin <email@mattatobin.com> | 2020-04-16 16:41:20 -0400 |
---|---|---|
committer | Matt A. Tobin <email@mattatobin.com> | 2020-04-16 16:41:20 -0400 |
commit | 0d149a4c091f856869490b1567d541c91010bc5c (patch) | |
tree | ac12d132c5dce3db09eb6985247acf750ddd84cd /dom/html | |
parent | 4375774c901bac4bd1ecaa35b40f55397044b7e9 (diff) | |
download | UXP-0d149a4c091f856869490b1567d541c91010bc5c.tar UXP-0d149a4c091f856869490b1567d541c91010bc5c.tar.gz UXP-0d149a4c091f856869490b1567d541c91010bc5c.tar.lz UXP-0d149a4c091f856869490b1567d541c91010bc5c.tar.xz UXP-0d149a4c091f856869490b1567d541c91010bc5c.zip |
Bug 1340333 - Eagerly compute whether a frame is really a browser.
Tag #1375
Diffstat (limited to 'dom/html')
-rw-r--r-- | dom/html/nsGenericHTMLFrameElement.cpp | 39 | ||||
-rw-r--r-- | dom/html/nsGenericHTMLFrameElement.h | 2 |
2 files changed, 19 insertions, 22 deletions
diff --git a/dom/html/nsGenericHTMLFrameElement.cpp b/dom/html/nsGenericHTMLFrameElement.cpp index 6e50a4092..0a69116a1 100644 --- a/dom/html/nsGenericHTMLFrameElement.cpp +++ b/dom/html/nsGenericHTMLFrameElement.cpp @@ -399,6 +399,17 @@ nsGenericHTMLFrameElement::MapScrollingAttribute(const nsAttrValue* aValue) return mappedValue; } +static bool +PrincipalAllowsBrowserFrame(nsIPrincipal* aPrincipal) +{ + nsCOMPtr<nsIPermissionManager> permMgr = mozilla::services::GetPermissionManager(); + NS_ENSURE_TRUE(permMgr, false); + uint32_t permission = nsIPermissionManager::DENY_ACTION; + nsresult rv = permMgr->TestPermissionFromPrincipal(aPrincipal, "browser", &permission); + NS_ENSURE_SUCCESS(rv, false); + return permission == nsIPermissionManager::ALLOW_ACTION; +} + /* virtual */ nsresult nsGenericHTMLFrameElement::AfterSetAttr(int32_t aNameSpaceID, nsIAtom* aName, const nsAttrValue* aValue, @@ -428,6 +439,11 @@ nsGenericHTMLFrameElement::AfterSetAttr(int32_t aNameSpaceID, nsIAtom* aName, } } + if (aName == nsGkAtoms::mozbrowser && aNameSpaceID == kNameSpaceID_None) { + mReallyIsBrowser = !!aValue && BrowserFramesEnabled() && + PrincipalAllowsBrowserFrame(NodePrincipal()); + } + return nsGenericHTMLElement::AfterSetAttr(aNameSpaceID, aName, aValue, aNotify); } @@ -503,28 +519,7 @@ nsGenericHTMLFrameElement::BrowserFramesEnabled() /* [infallible] */ nsresult nsGenericHTMLFrameElement::GetReallyIsBrowserOrApp(bool *aOut) { - *aOut = false; - - // Fail if browser frames are globally disabled. - if (!nsGenericHTMLFrameElement::BrowserFramesEnabled()) { - return NS_OK; - } - - // Fail if this frame doesn't have the mozbrowser attribute. - if (!GetBoolAttr(nsGkAtoms::mozbrowser)) { - return NS_OK; - } - - // Fail if the node principal isn't trusted. - nsIPrincipal *principal = NodePrincipal(); - nsCOMPtr<nsIPermissionManager> permMgr = - services::GetPermissionManager(); - NS_ENSURE_TRUE(permMgr, NS_OK); - - uint32_t permission = nsIPermissionManager::DENY_ACTION; - nsresult rv = permMgr->TestPermissionFromPrincipal(principal, "browser", &permission); - NS_ENSURE_SUCCESS(rv, NS_OK); - *aOut = permission == nsIPermissionManager::ALLOW_ACTION; + *aOut = mReallyIsBrowser; return NS_OK; } diff --git a/dom/html/nsGenericHTMLFrameElement.h b/dom/html/nsGenericHTMLFrameElement.h index d9c2df9d5..0367a7fe1 100644 --- a/dom/html/nsGenericHTMLFrameElement.h +++ b/dom/html/nsGenericHTMLFrameElement.h @@ -36,6 +36,7 @@ public: , mIsPrerendered(false) , mBrowserFrameListenersRegistered(false) , mFrameLoaderCreationDisallowed(false) + , mReallyIsBrowser(false) { } @@ -122,6 +123,7 @@ protected: bool mIsPrerendered; bool mBrowserFrameListenersRegistered; bool mFrameLoaderCreationDisallowed; + bool mReallyIsBrowser; // This flag is only used by <iframe>. See HTMLIFrameElement:: // FullscreenFlag() for details. It is placed here so that we |