Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(331)

Side by Side Diff: Source/modules/screen_orientation/ScreenOrientation.cpp

Issue 315693002: Use WebViewClient instead of BlinkPlatform for screen lock. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 6 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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"
16 #include "modules/screen_orientation/LockOrientationCallback.h" 17 #include "modules/screen_orientation/LockOrientationCallback.h"
17 #include "modules/screen_orientation/ScreenOrientationController.h" 18 #include "modules/screen_orientation/ScreenOrientationController.h"
18 #include "public/platform/Platform.h"
19 #include "public/platform/WebScreenOrientationType.h" 19 #include "public/platform/WebScreenOrientationType.h"
20 20
21 // This code assumes that WebScreenOrientationType values are included in WebScr eenOrientationLockType. 21 // This code assumes that WebScreenOrientationType values are included in WebScr eenOrientationLockType.
22 #define COMPILE_ASSERT_MATCHING_ENUM(enum1, enum2) \ 22 #define COMPILE_ASSERT_MATCHING_ENUM(enum1, enum2) \
23 COMPILE_ASSERT(static_cast<unsigned>(blink::enum1) == static_cast<unsigned>( blink::enum2), mismatching_types) 23 COMPILE_ASSERT(static_cast<unsigned>(blink::enum1) == static_cast<unsigned>( blink::enum2), mismatching_types)
24 COMPILE_ASSERT_MATCHING_ENUM(WebScreenOrientationPortraitPrimary, WebScreenOrien tationLockPortraitPrimary); 24 COMPILE_ASSERT_MATCHING_ENUM(WebScreenOrientationPortraitPrimary, WebScreenOrien tationLockPortraitPrimary);
25 COMPILE_ASSERT_MATCHING_ENUM(WebScreenOrientationPortraitSecondary, WebScreenOri entationLockPortraitSecondary); 25 COMPILE_ASSERT_MATCHING_ENUM(WebScreenOrientationPortraitSecondary, WebScreenOri entationLockPortraitSecondary);
26 COMPILE_ASSERT_MATCHING_ENUM(WebScreenOrientationLandscapePrimary, WebScreenOrie ntationLockLandscapePrimary); 26 COMPILE_ASSERT_MATCHING_ENUM(WebScreenOrientationLandscapePrimary, WebScreenOrie ntationLockLandscapePrimary);
27 COMPILE_ASSERT_MATCHING_ENUM(WebScreenOrientationLandscapeSecondary, WebScreenOr ientationLockLandscapeSecondary); 27 COMPILE_ASSERT_MATCHING_ENUM(WebScreenOrientationLandscapeSecondary, WebScreenOr ientationLockLandscapeSecondary);
28 28
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
94 } 94 }
95 95
96 Document* ScreenOrientation::document() const 96 Document* ScreenOrientation::document() const
97 { 97 {
98 if (!m_associatedDOMWindow || !m_associatedDOMWindow->isCurrentlyDisplayedIn Frame()) 98 if (!m_associatedDOMWindow || !m_associatedDOMWindow->isCurrentlyDisplayedIn Frame())
99 return 0; 99 return 0;
100 ASSERT(m_associatedDOMWindow->document()); 100 ASSERT(m_associatedDOMWindow->document());
101 return m_associatedDOMWindow->document(); 101 return m_associatedDOMWindow->document();
102 } 102 }
103 103
104 Page* ScreenOrientation::page() const
105 {
106 if (!frame())
107 return 0;
108 return frame()->page();
109 }
110
104 ScreenOrientation& ScreenOrientation::from(Screen& screen) 111 ScreenOrientation& ScreenOrientation::from(Screen& screen)
105 { 112 {
106 ScreenOrientation* supplement = static_cast<ScreenOrientation*>(WillBeHeapSu pplement<Screen>::from(screen, supplementName())); 113 ScreenOrientation* supplement = static_cast<ScreenOrientation*>(WillBeHeapSu pplement<Screen>::from(screen, supplementName()));
107 if (!supplement) { 114 if (!supplement) {
108 supplement = new ScreenOrientation(screen); 115 supplement = new ScreenOrientation(screen);
109 provideTo(screen, supplementName(), adoptPtrWillBeNoop(supplement)); 116 provideTo(screen, supplementName(), adoptPtrWillBeNoop(supplement));
110 } 117 }
111 return *supplement; 118 return *supplement;
112 } 119 }
113 120
114 ScreenOrientation::~ScreenOrientation() 121 ScreenOrientation::~ScreenOrientation()
115 { 122 {
116 } 123 }
117 124
118 const AtomicString& ScreenOrientation::orientation(Screen& screen) 125 const AtomicString& ScreenOrientation::orientation(Screen& screen)
119 { 126 {
120 ScreenOrientation& screenOrientation = ScreenOrientation::from(screen); 127 ScreenOrientation& screenOrientation = ScreenOrientation::from(screen);
121 if (!screenOrientation.document()) { 128 if (!screenOrientation.page()) {
122 // FIXME: we should try to return a better guess, like the latest known value. 129 // FIXME: we should try to return a better guess, like the latest known value.
123 return orientationTypeToString(blink::WebScreenOrientationPortraitPrimar y); 130 return orientationTypeToString(blink::WebScreenOrientationPortraitPrimar y);
124 } 131 }
125 ScreenOrientationController& controller = ScreenOrientationController::from( *screenOrientation.document()); 132 ScreenOrientationController& controller = ScreenOrientationController::from( *screenOrientation.page());
eseidel 2014/06/03 20:57:49 I would just have an accessor for the controller i
dcheng 2014/06/03 21:02:04 I don't think it's clear what the plan is yet so j
126 return orientationTypeToString(controller.orientation()); 133 return orientationTypeToString(controller.orientation());
127 } 134 }
128 135
129 ScriptPromise ScreenOrientation::lockOrientation(ScriptState* state, Screen& scr een, const AtomicString& lockString) 136 ScriptPromise ScreenOrientation::lockOrientation(ScriptState* state, Screen& scr een, const AtomicString& lockString)
130 { 137 {
131 RefPtr<ScriptPromiseResolverWithContext> resolver = ScriptPromiseResolverWit hContext::create(state); 138 RefPtr<ScriptPromiseResolverWithContext> resolver = ScriptPromiseResolverWit hContext::create(state);
132 ScriptPromise promise = resolver->promise(); 139 ScriptPromise promise = resolver->promise();
133 140
134 ScreenOrientation& screenOrientation = ScreenOrientation::from(screen); 141 ScreenOrientation& screenOrientation = ScreenOrientation::from(screen);
135 Document* document = screenOrientation.document(); 142 Document* document = screenOrientation.document();
136 143
137 if (!document) { 144 if (!document || !screenOrientation.page()) {
138 RefPtrWillBeRawPtr<DOMException> exception = DOMException::create(Invali dStateError, "The object is no longer associated to a document."); 145 RefPtrWillBeRawPtr<DOMException> exception = DOMException::create(Invali dStateError, "The object is no longer associated to a document.");
139 resolver->reject(exception); 146 resolver->reject(exception);
140 return promise; 147 return promise;
141 } 148 }
142 149
143 if (document->isSandboxed(SandboxOrientationLock)) { 150 if (document->isSandboxed(SandboxOrientationLock)) {
144 RefPtrWillBeRawPtr<DOMException> exception = DOMException::create(Securi tyError, "The document is sandboxed and lacks the 'allow-orientation-lock' flag. "); 151 RefPtrWillBeRawPtr<DOMException> exception = DOMException::create(Securi tyError, "The document is sandboxed and lacks the 'allow-orientation-lock' flag. ");
145 resolver->reject(exception); 152 resolver->reject(exception);
146 return promise; 153 return promise;
147 } 154 }
148 155
149 blink::Platform::current()->lockOrientation(stringToOrientationLock(lockStri ng), new LockOrientationCallback(resolver)); 156 ScreenOrientationController::from(*screenOrientation.page()).lockOrientation (stringToOrientationLock(lockString), new LockOrientationCallback(resolver));
150 return promise; 157 return promise;
151 } 158 }
152 159
153 void ScreenOrientation::unlockOrientation(Screen& screen) 160 void ScreenOrientation::unlockOrientation(Screen& screen)
154 { 161 {
155 blink::Platform::current()->unlockOrientation(); 162 ScreenOrientation& screenOrientation = ScreenOrientation::from(screen);
163 if (!screenOrientation.page())
164 return;
165
166 ScreenOrientationController::from(*screenOrientation.page()).unlockOrientati on();
156 } 167 }
157 168
158 } // namespace WebCore 169 } // namespace WebCore
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698