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..df53a90428c1cbf1fc129f03c8509b21b6ec3b5a 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,38 @@ const AtomicString& ScreenOrientation::orientation(Screen& screen) |
return orientationTypeToString(controller.orientation()); |
} |
-bool ScreenOrientation::lockOrientation(Screen& screen, const AtomicString& lockString, ExceptionState& exceptionState) |
+ScriptPromise ScreenOrientation::lockOrientation( |
+ ExecutionContext* context, Screen& screen, const AtomicString& lockString) |
jochen (gone - plz use gerrit)
2014/05/22 08:34:35
should go on previous line
mlamouri (slow - plz ping)
2014/05/22 08:58:56
Done. Though, that makes the line ~120 characters
|
{ |
+ RefPtr<ScriptPromiseResolverWithContext> resolver = ScriptPromiseResolverWithContext::create(ScriptState::current(toIsolate(context))); |
+ 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."); |
jochen (gone - plz use gerrit)
2014/05/22 08:34:35
should go on previous line
mlamouri (slow - plz ping)
2014/05/22 08:58:56
Done. 140 characters long :(
|
+ 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."); |
jochen (gone - plz use gerrit)
2014/05/22 08:34:35
and here
mlamouri (slow - plz ping)
2014/05/22 08:58:56
160 :'(
|
+ resolver->reject(exception); |
+ return promise; |
} |
- screenOrientation.lockOrientationAsync(stringToOrientationLock(lockString)); |
- return true; |
+ |
+ blink::Platform::current()->lockOrientation( |
+ stringToOrientationLock(lockString), |
+ new LockOrientationCallback(resolver)); |
jochen (gone - plz use gerrit)
2014/05/22 08:34:35
and this, all in one line
mlamouri (slow - plz ping)
2014/05/22 08:58:56
Obviously, having vertical screen is not compatibl
|
+ return promise; |
} |
void ScreenOrientation::unlockOrientation(Screen& screen) |
{ |
- ScreenOrientation::from(screen).lockOrientationAsync(blink::WebScreenOrientationLockDefault); |
+ blink::Platform::current()->unlockOrientation(); |
} |
} // namespace WebCore |