Index: Source/modules/screen_orientation/ScreenOrientation.cpp |
diff --git a/Source/modules/screen_orientation/ScreenOrientation.cpp b/Source/modules/screen_orientation/ScreenOrientation.cpp |
index 8acb1303a8497ac21023b11032d5901608e78769..504fda15eaa2df75458e48db0fe92d019ee14df8 100644 |
--- a/Source/modules/screen_orientation/ScreenOrientation.cpp |
+++ b/Source/modules/screen_orientation/ScreenOrientation.cpp |
@@ -5,11 +5,15 @@ |
#include "config.h" |
#include "modules/screen_orientation/ScreenOrientation.h" |
-#include "bindings/v8/ExceptionState.h" |
+#include "bindings/v8/ScriptPromise.h" |
+#include "bindings/v8/ScriptPromiseResolverWithContext.h" |
+#include "core/dom/DOMException.h" |
#include "core/dom/Document.h" |
+#include "core/dom/ExceptionCode.h" |
#include "core/frame/DOMWindow.h" |
#include "core/frame/LocalFrame.h" |
#include "core/frame/Screen.h" |
+#include "modules/screen_orientation/LockOrientationCallback.h" |
#include "modules/screen_orientation/ScreenOrientationController.h" |
#include "public/platform/Platform.h" |
#include "public/platform/WebScreenOrientationType.h" |
@@ -53,7 +57,7 @@ static ScreenOrientationInfo* orientationsMap(unsigned& length) |
return orientationMap; |
} |
-static const AtomicString& orientationTypeToString(blink::WebScreenOrientationType orientation) |
+const AtomicString& ScreenOrientation::orientationTypeToString(blink::WebScreenOrientationType orientation) |
{ |
unsigned length = 0; |
ScreenOrientationInfo* orientationMap = orientationsMap(length); |
@@ -81,28 +85,9 @@ static blink::WebScreenOrientationLockType stringToOrientationLock(const AtomicS |
ScreenOrientation::ScreenOrientation(Screen& screen) |
: DOMWindowProperty(screen.frame()) |
- , m_orientationLockTimer(this, &ScreenOrientation::orientationLockTimerFired) |
- , m_prospectiveLock(blink::WebScreenOrientationLockDefault) |
{ |
} |
-void ScreenOrientation::lockOrientationAsync(blink::WebScreenOrientationLockType orientation) |
-{ |
- if (m_orientationLockTimer.isActive()) |
- m_orientationLockTimer.stop(); |
- |
- m_prospectiveLock = orientation; |
- m_orientationLockTimer.startOneShot(0, FROM_HERE); |
-} |
- |
-void ScreenOrientation::orientationLockTimerFired(Timer<ScreenOrientation>*) |
-{ |
- if (m_prospectiveLock == blink::WebScreenOrientationLockDefault) |
- blink::Platform::current()->unlockOrientation(); |
- else |
- blink::Platform::current()->lockOrientation(m_prospectiveLock); |
-} |
- |
const char* ScreenOrientation::supplementName() |
{ |
return "ScreenOrientation"; |
@@ -141,23 +126,33 @@ const AtomicString& ScreenOrientation::orientation(Screen& screen) |
return orientationTypeToString(controller.orientation()); |
} |
-bool ScreenOrientation::lockOrientation(Screen& screen, const AtomicString& lockString, ExceptionState& exceptionState) |
+ScriptPromise ScreenOrientation::lockOrientation(ScriptState* state, Screen& screen, const AtomicString& lockString) |
{ |
+ RefPtr<ScriptPromiseResolverWithContext> resolver = ScriptPromiseResolverWithContext::create(state); |
+ ScriptPromise promise = resolver->promise(); |
+ |
ScreenOrientation& screenOrientation = ScreenOrientation::from(screen); |
Document* document = screenOrientation.document(); |
- if (!document) |
- return false; |
+ |
+ if (!document) { |
+ RefPtrWillBeRawPtr<DOMException> exception = DOMException::create(InvalidStateError, "The object is no longer associated to a document."); |
+ resolver->reject(exception); |
+ return promise; |
+ } |
+ |
if (document->isSandboxed(SandboxOrientationLock)) { |
- exceptionState.throwSecurityError("The document is sandboxed and lacks the 'allow-orientation-lock' flag."); |
- return false; |
+ RefPtrWillBeRawPtr<DOMException> exception = DOMException::create(SecurityError, "The document is sandboxed and lacks the 'allow-orientation-lock' flag."); |
+ resolver->reject(exception); |
+ return promise; |
} |
- screenOrientation.lockOrientationAsync(stringToOrientationLock(lockString)); |
- return true; |
+ |
+ blink::Platform::current()->lockOrientation(stringToOrientationLock(lockString), new LockOrientationCallback(resolver)); |
+ return promise; |
} |
void ScreenOrientation::unlockOrientation(Screen& screen) |
{ |
- ScreenOrientation::from(screen).lockOrientationAsync(blink::WebScreenOrientationLockDefault); |
+ blink::Platform::current()->unlockOrientation(); |
} |
} // namespace WebCore |