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

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 ASSERT(document()->page());
Inactive 2014/06/03 18:04:53 This seems unsafe. We should probably return 0 if
mlamouri (slow - plz ping) 2014/06/03 19:49:30 Done.
107 return document()->page();
Inactive 2014/06/03 18:04:53 We should be able to use frame()->page() since thi
mlamouri (slow - plz ping) 2014/06/03 19:49:30 Done.
108 }
109
104 ScreenOrientation& ScreenOrientation::from(Screen& screen) 110 ScreenOrientation& ScreenOrientation::from(Screen& screen)
105 { 111 {
106 ScreenOrientation* supplement = static_cast<ScreenOrientation*>(WillBeHeapSu pplement<Screen>::from(screen, supplementName())); 112 ScreenOrientation* supplement = static_cast<ScreenOrientation*>(WillBeHeapSu pplement<Screen>::from(screen, supplementName()));
107 if (!supplement) { 113 if (!supplement) {
108 supplement = new ScreenOrientation(screen); 114 supplement = new ScreenOrientation(screen);
109 provideTo(screen, supplementName(), adoptPtrWillBeNoop(supplement)); 115 provideTo(screen, supplementName(), adoptPtrWillBeNoop(supplement));
110 } 116 }
111 return *supplement; 117 return *supplement;
112 } 118 }
113 119
114 ScreenOrientation::~ScreenOrientation() 120 ScreenOrientation::~ScreenOrientation()
115 { 121 {
116 } 122 }
117 123
118 const AtomicString& ScreenOrientation::orientation(Screen& screen) 124 const AtomicString& ScreenOrientation::orientation(Screen& screen)
119 { 125 {
120 ScreenOrientation& screenOrientation = ScreenOrientation::from(screen); 126 ScreenOrientation& screenOrientation = ScreenOrientation::from(screen);
121 if (!screenOrientation.document()) { 127 if (!screenOrientation.document()) {
122 // FIXME: we should try to return a better guess, like the latest known value. 128 // FIXME: we should try to return a better guess, like the latest known value.
123 return orientationTypeToString(blink::WebScreenOrientationPortraitPrimar y); 129 return orientationTypeToString(blink::WebScreenOrientationPortraitPrimar y);
124 } 130 }
125 ScreenOrientationController& controller = ScreenOrientationController::from( *screenOrientation.document()); 131 ScreenOrientationController& controller = ScreenOrientationController::from( *screenOrientation.page());
126 return orientationTypeToString(controller.orientation()); 132 return orientationTypeToString(controller.orientation());
127 } 133 }
128 134
129 ScriptPromise ScreenOrientation::lockOrientation(ScriptState* state, Screen& scr een, const AtomicString& lockString) 135 ScriptPromise ScreenOrientation::lockOrientation(ScriptState* state, Screen& scr een, const AtomicString& lockString)
130 { 136 {
131 RefPtr<ScriptPromiseResolverWithContext> resolver = ScriptPromiseResolverWit hContext::create(state); 137 RefPtr<ScriptPromiseResolverWithContext> resolver = ScriptPromiseResolverWit hContext::create(state);
132 ScriptPromise promise = resolver->promise(); 138 ScriptPromise promise = resolver->promise();
133 139
134 ScreenOrientation& screenOrientation = ScreenOrientation::from(screen); 140 ScreenOrientation& screenOrientation = ScreenOrientation::from(screen);
135 Document* document = screenOrientation.document(); 141 Document* document = screenOrientation.document();
136 142
137 if (!document) { 143 if (!document) {
138 RefPtrWillBeRawPtr<DOMException> exception = DOMException::create(Invali dStateError, "The object is no longer associated to a document."); 144 RefPtrWillBeRawPtr<DOMException> exception = DOMException::create(Invali dStateError, "The object is no longer associated to a document.");
139 resolver->reject(exception); 145 resolver->reject(exception);
140 return promise; 146 return promise;
141 } 147 }
142 148
143 if (document->isSandboxed(SandboxOrientationLock)) { 149 if (document->isSandboxed(SandboxOrientationLock)) {
144 RefPtrWillBeRawPtr<DOMException> exception = DOMException::create(Securi tyError, "The document is sandboxed and lacks the 'allow-orientation-lock' flag. "); 150 RefPtrWillBeRawPtr<DOMException> exception = DOMException::create(Securi tyError, "The document is sandboxed and lacks the 'allow-orientation-lock' flag. ");
145 resolver->reject(exception); 151 resolver->reject(exception);
146 return promise; 152 return promise;
147 } 153 }
148 154
149 blink::Platform::current()->lockOrientation(stringToOrientationLock(lockStri ng), new LockOrientationCallback(resolver)); 155 ScreenOrientationController::from(*document->page()).lockOrientation(stringT oOrientationLock(lockString), new LockOrientationCallback(resolver));
Inactive 2014/06/03 18:04:53 I think it is possible for page() to return null i
mlamouri (slow - plz ping) 2014/06/03 19:49:30 Done.
150 return promise; 156 return promise;
151 } 157 }
152 158
153 void ScreenOrientation::unlockOrientation(Screen& screen) 159 void ScreenOrientation::unlockOrientation(Screen& screen)
154 { 160 {
155 blink::Platform::current()->unlockOrientation(); 161 ScreenOrientation& screenOrientation = ScreenOrientation::from(screen);
162 if (!screenOrientation.page())
Inactive 2014/06/03 18:04:53 That method currently has an assertion making sure
mlamouri (slow - plz ping) 2014/06/03 19:49:30 Done.
163 return;
164
165 ScreenOrientationController::from(*screenOrientation.page()).unlockOrientati on();
156 } 166 }
157 167
158 } // namespace WebCore 168 } // namespace WebCore
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698