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/ExceptionState.h" |
| 9 #include "core/dom/Document.h" |
8 #include "core/frame/DOMWindow.h" | 10 #include "core/frame/DOMWindow.h" |
9 #include "core/frame/LocalFrame.h" | 11 #include "core/frame/LocalFrame.h" |
10 #include "core/frame/Screen.h" | 12 #include "core/frame/Screen.h" |
11 #include "modules/screen_orientation/ScreenOrientationController.h" | 13 #include "modules/screen_orientation/ScreenOrientationController.h" |
12 #include "public/platform/Platform.h" | 14 #include "public/platform/Platform.h" |
13 #include "public/platform/WebScreenOrientationType.h" | 15 #include "public/platform/WebScreenOrientationType.h" |
14 | 16 |
15 // This code assumes that WebScreenOrientationType values are included in WebScr
eenOrientationLockType. | 17 // This code assumes that WebScreenOrientationType values are included in WebScr
eenOrientationLockType. |
16 #define COMPILE_ASSERT_MATCHING_ENUM(enum1, enum2) \ | 18 #define COMPILE_ASSERT_MATCHING_ENUM(enum1, enum2) \ |
17 COMPILE_ASSERT(static_cast<unsigned>(blink::enum1) == static_cast<unsigned>(
blink::enum2), mismatching_types) | 19 COMPILE_ASSERT(static_cast<unsigned>(blink::enum1) == static_cast<unsigned>(
blink::enum2), mismatching_types) |
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
132 { | 134 { |
133 ScreenOrientation& screenOrientation = ScreenOrientation::from(screen); | 135 ScreenOrientation& screenOrientation = ScreenOrientation::from(screen); |
134 if (!screenOrientation.document()) { | 136 if (!screenOrientation.document()) { |
135 // FIXME: we should try to return a better guess, like the latest known
value. | 137 // FIXME: we should try to return a better guess, like the latest known
value. |
136 return orientationTypeToString(blink::WebScreenOrientationPortraitPrimar
y); | 138 return orientationTypeToString(blink::WebScreenOrientationPortraitPrimar
y); |
137 } | 139 } |
138 ScreenOrientationController& controller = ScreenOrientationController::from(
*screenOrientation.document()); | 140 ScreenOrientationController& controller = ScreenOrientationController::from(
*screenOrientation.document()); |
139 return orientationTypeToString(controller.orientation()); | 141 return orientationTypeToString(controller.orientation()); |
140 } | 142 } |
141 | 143 |
142 bool ScreenOrientation::lockOrientation(Screen& screen, const AtomicString& lock
String) | 144 bool ScreenOrientation::lockOrientation(Screen& screen, const AtomicString& lock
String, ExceptionState& exceptionState) |
143 { | 145 { |
144 ScreenOrientation::from(screen).lockOrientationAsync(stringToOrientationLock
(lockString)); | 146 ScreenOrientation& screenOrientation = ScreenOrientation::from(screen); |
| 147 Document* document = screenOrientation.document(); |
| 148 if (!document) |
| 149 return false; |
| 150 if (document->isSandboxed(SandboxOrientationLock)) { |
| 151 exceptionState.throwSecurityError("The document is sandboxed and lacks t
he 'allow-orientation-lock' flag."); |
| 152 return false; |
| 153 } |
| 154 screenOrientation.lockOrientationAsync(stringToOrientationLock(lockString)); |
145 return true; | 155 return true; |
146 } | 156 } |
147 | 157 |
148 void ScreenOrientation::unlockOrientation(Screen& screen) | 158 void ScreenOrientation::unlockOrientation(Screen& screen) |
149 { | 159 { |
150 ScreenOrientation::from(screen).lockOrientationAsync(blink::WebScreenOrienta
tionLockDefault); | 160 ScreenOrientation::from(screen).lockOrientationAsync(blink::WebScreenOrienta
tionLockDefault); |
151 } | 161 } |
152 | 162 |
153 } // namespace WebCore | 163 } // namespace WebCore |
OLD | NEW |