Bug 1318117. Stop using IsCallerChrome in pointerlock API, fullscreen API, and documentURI getter. r=ehsan

This commit is contained in:
Boris Zbarsky 2016-11-17 13:49:27 -05:00
parent 061d3629f1
commit c892e11e49
9 changed files with 39 additions and 36 deletions

View File

@ -3321,7 +3321,7 @@ GetFullScreenError(nsIDocument* aDoc)
}
void
Element::RequestFullscreen(ErrorResult& aError)
Element::RequestFullscreen(CallerType aCallerType, ErrorResult& aError)
{
// Only grant full-screen requests if this is called from inside a trusted
// event handler (i.e. inside an event handler for a user initiated event).
@ -3336,15 +3336,15 @@ Element::RequestFullscreen(ErrorResult& aError)
}
auto request = MakeUnique<FullscreenRequest>(this);
request->mIsCallerChrome = nsContentUtils::IsCallerChrome();
request->mIsCallerChrome = (aCallerType == CallerType::System);
OwnerDoc()->AsyncRequestFullScreen(Move(request));
}
void
Element::RequestPointerLock()
Element::RequestPointerLock(CallerType aCallerType)
{
OwnerDoc()->RequestPointerLock(this);
OwnerDoc()->RequestPointerLock(this, aCallerType);
}
void

View File

@ -65,6 +65,7 @@ namespace dom {
class DOMIntersectionObserver;
class ElementOrCSSPseudoElement;
class UnrestrictedDoubleOrKeyframeAnimationOptions;
enum class CallerType : uint32_t;
} // namespace dom
} // namespace mozilla
@ -788,8 +789,8 @@ public:
}
}
void RequestFullscreen(ErrorResult& aError);
void RequestPointerLock();
void RequestFullscreen(CallerType aCallerType, ErrorResult& aError);
void RequestPointerLock(CallerType aCallerType);
Attr* GetAttributeNode(const nsAString& aName);
already_AddRefed<Attr> SetAttributeNode(Attr& aNewAttr,
ErrorResult& aError);

View File

@ -55,6 +55,7 @@
#include "nsIDOMStyleSheet.h"
#include "mozilla/dom/Attr.h"
#include "mozilla/dom/BindingDeclarations.h"
#include "nsIDOMDOMImplementation.h"
#include "nsIDOMDocumentXBL.h"
#include "mozilla/dom/Element.h"
@ -7049,9 +7050,10 @@ nsIDocument::GetURL(nsString& aURL) const
}
void
nsIDocument::GetDocumentURIFromJS(nsString& aDocumentURI, ErrorResult& aRv) const
nsIDocument::GetDocumentURIFromJS(nsString& aDocumentURI, CallerType aCallerType,
ErrorResult& aRv) const
{
if (!mChromeXHRDocURI || !nsContentUtils::IsCallerChrome()) {
if (!mChromeXHRDocURI || aCallerType != CallerType::System) {
aRv = GetDocumentURI(aDocumentURI);
return;
}
@ -10979,15 +10981,14 @@ HasFullScreenSubDocument(nsIDocument* aDoc)
static const char*
GetFullscreenError(nsIDocument* aDoc, bool aCallerIsChrome)
{
if (nsContentUtils::IsFullScreenApiEnabled() && aCallerIsChrome) {
bool apiEnabled = nsContentUtils::IsFullScreenApiEnabled();
if (apiEnabled && aCallerIsChrome) {
// Chrome code can always use the full-screen API, provided it's not
// explicitly disabled. Note IsCallerChrome() returns true when running
// in a Runnable, so don't use GetMozFullScreenEnabled() from a
// Runnable!
// explicitly disabled.
return nullptr;
}
if (!nsContentUtils::IsFullScreenApiEnabled()) {
if (!apiEnabled) {
return "FullscreenDeniedDisabled";
}
@ -11396,9 +11397,9 @@ nsDocument::GetFullscreenElement()
}
bool
nsDocument::FullscreenEnabled()
nsDocument::FullscreenEnabled(CallerType aCallerType)
{
return !GetFullscreenError(this, nsContentUtils::IsCallerChrome());
return !GetFullscreenError(this, aCallerType == CallerType::System);
}
uint16_t
@ -11619,7 +11620,7 @@ PointerLockRequest::Run()
}
void
nsDocument::RequestPointerLock(Element* aElement)
nsDocument::RequestPointerLock(Element* aElement, CallerType aCallerType)
{
NS_ASSERTION(aElement,
"Must pass non-null element to nsDocument::RequestPointerLock");
@ -11636,10 +11637,10 @@ nsDocument::RequestPointerLock(Element* aElement)
return;
}
bool userInputOrChromeCaller = EventStateManager::IsHandlingUserInput() ||
nsContentUtils::IsCallerChrome();
bool userInputOrSystemCaller = EventStateManager::IsHandlingUserInput() ||
aCallerType == CallerType::System;
NS_DispatchToMainThread(new PointerLockRequest(aElement,
userInputOrChromeCaller));
userInputOrSystemCaller));
}
bool

View File

@ -1080,10 +1080,11 @@ public:
Element* FullScreenStackTop();
// DOM-exposed fullscreen API
bool FullscreenEnabled() override;
bool FullscreenEnabled(mozilla::dom::CallerType aCallerType) override;
Element* GetFullscreenElement() override;
void RequestPointerLock(Element* aElement) override;
void RequestPointerLock(Element* aElement,
mozilla::dom::CallerType aCallerType) override;
bool SetPointerLock(Element* aElement, int aCursorStyle);
static void UnlockPointer(nsIDocument* aDoc = nullptr);

View File

@ -166,6 +166,8 @@ template<typename> class Sequence;
template<typename, typename> class CallbackObjectHolder;
typedef CallbackObjectHolder<NodeFilter, nsIDOMNodeFilter> NodeFilterHolder;
enum class CallerType : uint32_t;
} // namespace dom
} // namespace mozilla
@ -1439,7 +1441,8 @@ public:
*/
void DispatchFullscreenError(const char* aMessage);
virtual void RequestPointerLock(Element* aElement) = 0;
virtual void RequestPointerLock(Element* aElement,
mozilla::dom::CallerType aCallerType) = 0;
static void UnlockPointer(nsIDocument* aDoc = nullptr);
@ -2551,6 +2554,7 @@ public:
// when accessed from chrome privileged script and
// from content privileged script for compatibility.
void GetDocumentURIFromJS(nsString& aDocumentURI,
mozilla::dom::CallerType aCallerType,
mozilla::ErrorResult& aRv) const;
void GetCompatMode(nsString& retval) const;
void GetCharacterSet(nsAString& retval) const;
@ -2667,7 +2671,7 @@ public:
Element* aElement) = 0;
nsIURI* GetDocumentURIObject() const;
// Not const because all the full-screen goop is not const
virtual bool FullscreenEnabled() = 0;
virtual bool FullscreenEnabled(mozilla::dom::CallerType aCallerType) = 0;
virtual Element* GetFullscreenElement() = 0;
bool Fullscreen()
{

View File

@ -524,7 +524,7 @@ public:
} // namespace binding_detail
// Enum to represent a system or non-system caller type.
enum class CallerType {
enum class CallerType : uint32_t {
System,
NonSystem
};

View File

@ -235,10 +235,6 @@ DOMInterfaces = {
'Document': {
'nativeType': 'nsIDocument',
'binaryNames': {
'documentURI': 'documentURIFromJS',
'URL': 'documentURIFromJS'
}
},
'DominatorTree': {

View File

@ -24,9 +24,9 @@ dictionary ElementCreationOptions {
interface Document : Node {
[Throws]
readonly attribute DOMImplementation implementation;
[Pure, Throws]
[Pure, Throws, BinaryName="documentURIFromJS", NeedsCallerType]
readonly attribute DOMString URL;
[Pure, Throws]
[Pure, Throws, BinaryName="documentURIFromJS", NeedsCallerType]
readonly attribute DOMString documentURI;
[Pure]
readonly attribute DOMString compatMode;
@ -232,9 +232,9 @@ partial interface Document {
readonly attribute boolean fullscreen;
[BinaryName="fullscreen"]
readonly attribute boolean mozFullScreen;
[LenientSetter, Func="nsDocument::IsUnprefixedFullscreenEnabled"]
[LenientSetter, Func="nsDocument::IsUnprefixedFullscreenEnabled", NeedsCallerType]
readonly attribute boolean fullscreenEnabled;
[BinaryName="fullscreenEnabled"]
[BinaryName="fullscreenEnabled", NeedsCallerType]
readonly attribute boolean mozFullScreenEnabled;
[LenientSetter, Func="nsDocument::IsUnprefixedFullscreenEnabled"]
readonly attribute Element? fullscreenElement;

View File

@ -250,16 +250,16 @@ Element implements GeometryUtils;
// https://fullscreen.spec.whatwg.org/#api
partial interface Element {
[Throws, UnsafeInPrerendering, Func="nsDocument::IsUnprefixedFullscreenEnabled"]
[Throws, UnsafeInPrerendering, Func="nsDocument::IsUnprefixedFullscreenEnabled", NeedsCallerType]
void requestFullscreen();
[Throws, UnsafeInPrerendering, BinaryName="requestFullscreen"]
[Throws, UnsafeInPrerendering, BinaryName="requestFullscreen", NeedsCallerType]
void mozRequestFullScreen();
};
// https://w3c.github.io/pointerlock/#extensions-to-the-element-interface
partial interface Element {
[UnsafeInPrerendering]
[UnsafeInPrerendering, NeedsCallerType]
void requestPointerLock();
[UnsafeInPrerendering, BinaryName="requestPointerLock", Pref="pointer-lock-api.prefixed.enabled"]
[UnsafeInPrerendering, BinaryName="requestPointerLock", Pref="pointer-lock-api.prefixed.enabled", NeedsCallerType]
void mozRequestPointerLock();
};