| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "config.h" | 5 #include "config.h" |
| 6 #include "modules/screen_orientation/ScreenOrientation.h" | 6 #include "modules/screen_orientation/ScreenOrientation.h" |
| 7 | 7 |
| 8 #include "bindings/v8/ScriptPromise.h" | 8 #include "bindings/v8/ScriptPromise.h" |
| 9 #include "bindings/v8/ScriptPromiseResolverWithContext.h" | 9 #include "bindings/v8/ScriptPromiseResolverWithContext.h" |
| 10 #include "core/dom/DOMException.h" | 10 #include "core/dom/DOMException.h" |
| 11 #include "core/dom/Document.h" | 11 #include "core/dom/Document.h" |
| 12 #include "core/dom/ExceptionCode.h" | 12 #include "core/dom/ExceptionCode.h" |
| 13 #include "core/frame/DOMWindow.h" | 13 #include "core/frame/DOMWindow.h" |
| 14 #include "core/frame/LocalFrame.h" | 14 #include "core/frame/LocalFrame.h" |
| 15 #include "core/frame/Screen.h" | 15 #include "core/frame/Screen.h" |
| 16 #include "core/page/Page.h" | |
| 17 #include "modules/screen_orientation/LockOrientationCallback.h" | 16 #include "modules/screen_orientation/LockOrientationCallback.h" |
| 18 #include "modules/screen_orientation/ScreenOrientationController.h" | 17 #include "modules/screen_orientation/ScreenOrientationController.h" |
| 19 #include "public/platform/WebScreenOrientationType.h" | 18 #include "public/platform/WebScreenOrientationType.h" |
| 20 | 19 |
| 21 // This code assumes that WebScreenOrientationType values are included in WebScr
eenOrientationLockType. | 20 // This code assumes that WebScreenOrientationType values are included in WebScr
eenOrientationLockType. |
| 22 #define COMPILE_ASSERT_MATCHING_ENUM(enum1, enum2) \ | 21 #define COMPILE_ASSERT_MATCHING_ENUM(enum1, enum2) \ |
| 23 COMPILE_ASSERT(static_cast<unsigned>(blink::enum1) == static_cast<unsigned>(
blink::enum2), mismatching_types) | 22 COMPILE_ASSERT(static_cast<unsigned>(blink::enum1) == static_cast<unsigned>(
blink::enum2), mismatching_types) |
| 24 COMPILE_ASSERT_MATCHING_ENUM(WebScreenOrientationPortraitPrimary, WebScreenOrien
tationLockPortraitPrimary); | 23 COMPILE_ASSERT_MATCHING_ENUM(WebScreenOrientationPortraitPrimary, WebScreenOrien
tationLockPortraitPrimary); |
| 25 COMPILE_ASSERT_MATCHING_ENUM(WebScreenOrientationPortraitSecondary, WebScreenOri
entationLockPortraitSecondary); | 24 COMPILE_ASSERT_MATCHING_ENUM(WebScreenOrientationPortraitSecondary, WebScreenOri
entationLockPortraitSecondary); |
| 26 COMPILE_ASSERT_MATCHING_ENUM(WebScreenOrientationLandscapePrimary, WebScreenOrie
ntationLockLandscapePrimary); | 25 COMPILE_ASSERT_MATCHING_ENUM(WebScreenOrientationLandscapePrimary, WebScreenOrie
ntationLockLandscapePrimary); |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 94 } | 93 } |
| 95 | 94 |
| 96 Document* ScreenOrientation::document() const | 95 Document* ScreenOrientation::document() const |
| 97 { | 96 { |
| 98 if (!m_associatedDOMWindow || !m_associatedDOMWindow->isCurrentlyDisplayedIn
Frame()) | 97 if (!m_associatedDOMWindow || !m_associatedDOMWindow->isCurrentlyDisplayedIn
Frame()) |
| 99 return 0; | 98 return 0; |
| 100 ASSERT(m_associatedDOMWindow->document()); | 99 ASSERT(m_associatedDOMWindow->document()); |
| 101 return m_associatedDOMWindow->document(); | 100 return m_associatedDOMWindow->document(); |
| 102 } | 101 } |
| 103 | 102 |
| 104 Page* ScreenOrientation::page() const | |
| 105 { | |
| 106 if (!frame()) | |
| 107 return 0; | |
| 108 return frame()->page(); | |
| 109 } | |
| 110 | |
| 111 ScreenOrientation& ScreenOrientation::from(Screen& screen) | 103 ScreenOrientation& ScreenOrientation::from(Screen& screen) |
| 112 { | 104 { |
| 113 ScreenOrientation* supplement = static_cast<ScreenOrientation*>(WillBeHeapSu
pplement<Screen>::from(screen, supplementName())); | 105 ScreenOrientation* supplement = static_cast<ScreenOrientation*>(WillBeHeapSu
pplement<Screen>::from(screen, supplementName())); |
| 114 if (!supplement) { | 106 if (!supplement) { |
| 115 supplement = new ScreenOrientation(screen); | 107 supplement = new ScreenOrientation(screen); |
| 116 provideTo(screen, supplementName(), adoptPtrWillBeNoop(supplement)); | 108 provideTo(screen, supplementName(), adoptPtrWillBeNoop(supplement)); |
| 117 } | 109 } |
| 118 return *supplement; | 110 return *supplement; |
| 119 } | 111 } |
| 120 | 112 |
| 121 ScreenOrientation::~ScreenOrientation() | 113 ScreenOrientation::~ScreenOrientation() |
| 122 { | 114 { |
| 123 } | 115 } |
| 124 | 116 |
| 125 const AtomicString& ScreenOrientation::orientation(Screen& screen) | 117 const AtomicString& ScreenOrientation::orientation(Screen& screen) |
| 126 { | 118 { |
| 127 ScreenOrientation& screenOrientation = ScreenOrientation::from(screen); | 119 ScreenOrientation& screenOrientation = ScreenOrientation::from(screen); |
| 128 if (!screenOrientation.page()) { | 120 if (!screenOrientation.frame()) { |
| 129 // FIXME: we should try to return a better guess, like the latest known
value. | 121 // FIXME: we should try to return a better guess, like the latest known
value. |
| 130 return orientationTypeToString(blink::WebScreenOrientationPortraitPrimar
y); | 122 return orientationTypeToString(blink::WebScreenOrientationPortraitPrimar
y); |
| 131 } | 123 } |
| 132 ScreenOrientationController& controller = ScreenOrientationController::from(
*screenOrientation.page()); | 124 ScreenOrientationController& controller = ScreenOrientationController::from(
*screenOrientation.frame()); |
| 133 return orientationTypeToString(controller.orientation()); | 125 return orientationTypeToString(controller.orientation()); |
| 134 } | 126 } |
| 135 | 127 |
| 136 ScriptPromise ScreenOrientation::lockOrientation(ScriptState* state, Screen& scr
een, const AtomicString& lockString) | 128 ScriptPromise ScreenOrientation::lockOrientation(ScriptState* state, Screen& scr
een, const AtomicString& lockString) |
| 137 { | 129 { |
| 138 RefPtr<ScriptPromiseResolverWithContext> resolver = ScriptPromiseResolverWit
hContext::create(state); | 130 RefPtr<ScriptPromiseResolverWithContext> resolver = ScriptPromiseResolverWit
hContext::create(state); |
| 139 ScriptPromise promise = resolver->promise(); | 131 ScriptPromise promise = resolver->promise(); |
| 140 | 132 |
| 141 ScreenOrientation& screenOrientation = ScreenOrientation::from(screen); | 133 ScreenOrientation& screenOrientation = ScreenOrientation::from(screen); |
| 142 Document* document = screenOrientation.document(); | 134 Document* document = screenOrientation.document(); |
| 143 | 135 |
| 144 if (!document || !screenOrientation.page()) { | 136 if (!document || !screenOrientation.frame()) { |
| 145 RefPtrWillBeRawPtr<DOMException> exception = DOMException::create(Invali
dStateError, "The object is no longer associated to a document."); | 137 RefPtrWillBeRawPtr<DOMException> exception = DOMException::create(Invali
dStateError, "The object is no longer associated to a document."); |
| 146 resolver->reject(exception); | 138 resolver->reject(exception); |
| 147 return promise; | 139 return promise; |
| 148 } | 140 } |
| 149 | 141 |
| 150 if (document->isSandboxed(SandboxOrientationLock)) { | 142 if (document->isSandboxed(SandboxOrientationLock)) { |
| 151 RefPtrWillBeRawPtr<DOMException> exception = DOMException::create(Securi
tyError, "The document is sandboxed and lacks the 'allow-orientation-lock' flag.
"); | 143 RefPtrWillBeRawPtr<DOMException> exception = DOMException::create(Securi
tyError, "The document is sandboxed and lacks the 'allow-orientation-lock' flag.
"); |
| 152 resolver->reject(exception); | 144 resolver->reject(exception); |
| 153 return promise; | 145 return promise; |
| 154 } | 146 } |
| 155 | 147 |
| 156 ScreenOrientationController::from(*screenOrientation.page()).lockOrientation
(stringToOrientationLock(lockString), new LockOrientationCallback(resolver)); | 148 ScreenOrientationController::from(*screenOrientation.frame()).lockOrientatio
n(stringToOrientationLock(lockString), new LockOrientationCallback(resolver)); |
| 157 return promise; | 149 return promise; |
| 158 } | 150 } |
| 159 | 151 |
| 160 void ScreenOrientation::unlockOrientation(Screen& screen) | 152 void ScreenOrientation::unlockOrientation(Screen& screen) |
| 161 { | 153 { |
| 162 ScreenOrientation& screenOrientation = ScreenOrientation::from(screen); | 154 ScreenOrientation& screenOrientation = ScreenOrientation::from(screen); |
| 163 if (!screenOrientation.page()) | 155 if (!screenOrientation.frame()) |
| 164 return; | 156 return; |
| 165 | 157 |
| 166 ScreenOrientationController::from(*screenOrientation.page()).unlockOrientati
on(); | 158 ScreenOrientationController::from(*screenOrientation.frame()).unlockOrientat
ion(); |
| 167 } | 159 } |
| 168 | 160 |
| 169 } // namespace WebCore | 161 } // namespace WebCore |
| OLD | NEW |