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 "modules/screen_orientation/ScreenOrientationControllerImpl.h" | 5 #include "modules/screen_orientation/ScreenOrientationControllerImpl.h" |
6 | 6 |
7 #include "core/dom/Document.h" | |
7 #include "core/events/Event.h" | 8 #include "core/events/Event.h" |
8 #include "core/frame/FrameHost.h" | 9 #include "core/frame/FrameHost.h" |
9 #include "core/frame/FrameView.h" | 10 #include "core/frame/FrameView.h" |
10 #include "core/frame/LocalFrame.h" | 11 #include "core/frame/LocalFrame.h" |
11 #include "core/page/ChromeClient.h" | 12 #include "core/page/ChromeClient.h" |
12 #include "core/page/Page.h" | 13 #include "core/page/Page.h" |
13 #include "modules/screen_orientation/ScreenOrientation.h" | 14 #include "modules/screen_orientation/ScreenOrientation.h" |
14 #include "modules/screen_orientation/ScreenOrientationDispatcher.h" | 15 #include "modules/screen_orientation/ScreenOrientationDispatcher.h" |
15 #include "platform/LayoutTestSupport.h" | 16 #include "platform/LayoutTestSupport.h" |
16 #include "platform/ScopedOrientationChangeIndicator.h" | 17 #include "platform/ScopedOrientationChangeIndicator.h" |
(...skipping 15 matching lines...) Expand all Loading... | |
32 | 33 |
33 ScreenOrientationControllerImpl* ScreenOrientationControllerImpl::from( | 34 ScreenOrientationControllerImpl* ScreenOrientationControllerImpl::from( |
34 LocalFrame& frame) { | 35 LocalFrame& frame) { |
35 return static_cast<ScreenOrientationControllerImpl*>( | 36 return static_cast<ScreenOrientationControllerImpl*>( |
36 ScreenOrientationController::from(frame)); | 37 ScreenOrientationController::from(frame)); |
37 } | 38 } |
38 | 39 |
39 ScreenOrientationControllerImpl::ScreenOrientationControllerImpl( | 40 ScreenOrientationControllerImpl::ScreenOrientationControllerImpl( |
40 LocalFrame& frame, | 41 LocalFrame& frame, |
41 WebScreenOrientationClient* client) | 42 WebScreenOrientationClient* client) |
42 : DOMWindowProperty(&frame), | 43 : ContextLifecycleObserver(frame.document()), |
43 PlatformEventController(frame.page()), | 44 PlatformEventController(frame.page()), |
44 m_client(client), | 45 m_client(client), |
45 m_dispatchEventTimer( | 46 m_dispatchEventTimer( |
46 this, | 47 this, |
47 &ScreenOrientationControllerImpl::dispatchEventTimerFired) {} | 48 &ScreenOrientationControllerImpl::dispatchEventTimerFired) {} |
48 | 49 |
49 // Compute the screen orientation using the orientation angle and the screen | 50 // Compute the screen orientation using the orientation angle and the screen |
50 // width / height. | 51 // width / height. |
51 WebScreenOrientationType ScreenOrientationControllerImpl::computeOrientation( | 52 WebScreenOrientationType ScreenOrientationControllerImpl::computeOrientation( |
52 const IntRect& rect, | 53 const IntRect& rect, |
(...skipping 20 matching lines...) Expand all Loading... | |
73 return isTallDisplay ? WebScreenOrientationLandscapeSecondary | 74 return isTallDisplay ? WebScreenOrientationLandscapeSecondary |
74 : WebScreenOrientationPortraitPrimary; | 75 : WebScreenOrientationPortraitPrimary; |
75 default: | 76 default: |
76 NOTREACHED(); | 77 NOTREACHED(); |
77 return WebScreenOrientationPortraitPrimary; | 78 return WebScreenOrientationPortraitPrimary; |
78 } | 79 } |
79 } | 80 } |
80 | 81 |
81 void ScreenOrientationControllerImpl::updateOrientation() { | 82 void ScreenOrientationControllerImpl::updateOrientation() { |
82 DCHECK(m_orientation); | 83 DCHECK(m_orientation); |
83 DCHECK(frame()); | 84 |
85 if (!frame()) { | |
86 m_orientation->setType(WebScreenOrientationPortraitPrimary); | |
87 return; | |
88 } | |
89 | |
84 DCHECK(frame()->host()); | 90 DCHECK(frame()->host()); |
85 | |
86 ChromeClient& chromeClient = frame()->host()->chromeClient(); | 91 ChromeClient& chromeClient = frame()->host()->chromeClient(); |
87 WebScreenInfo screenInfo = chromeClient.screenInfo(); | 92 WebScreenInfo screenInfo = chromeClient.screenInfo(); |
88 WebScreenOrientationType orientationType = screenInfo.orientationType; | 93 WebScreenOrientationType orientationType = screenInfo.orientationType; |
89 if (orientationType == WebScreenOrientationUndefined) { | 94 if (orientationType == WebScreenOrientationUndefined) { |
90 // The embedder could not provide us with an orientation, deduce it | 95 // The embedder could not provide us with an orientation, deduce it |
91 // ourselves. | 96 // ourselves. |
92 orientationType = computeOrientation(chromeClient.screenInfo().rect, | 97 orientationType = computeOrientation(chromeClient.screenInfo().rect, |
93 screenInfo.orientationAngle); | 98 screenInfo.orientationAngle); |
94 } | 99 } |
95 DCHECK(orientationType != WebScreenOrientationUndefined); | 100 DCHECK(orientationType != WebScreenOrientationUndefined); |
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
201 } | 206 } |
202 | 207 |
203 void ScreenOrientationControllerImpl::unregisterWithDispatcher() { | 208 void ScreenOrientationControllerImpl::unregisterWithDispatcher() { |
204 ScreenOrientationDispatcher::instance().removeController(this); | 209 ScreenOrientationDispatcher::instance().removeController(this); |
205 } | 210 } |
206 | 211 |
207 bool ScreenOrientationControllerImpl::hasLastData() { | 212 bool ScreenOrientationControllerImpl::hasLastData() { |
208 return true; | 213 return true; |
209 } | 214 } |
210 | 215 |
211 void ScreenOrientationControllerImpl::frameDestroyed() { | 216 void ScreenOrientationControllerImpl::contextDestroyed() { |
217 stopUpdating(); | |
sof
2016/12/14 14:00:31
Seems like this is too strong a measure.
| |
212 m_client = nullptr; | 218 m_client = nullptr; |
213 DOMWindowProperty::frameDestroyed(); | |
214 m_activeLock = false; | 219 m_activeLock = false; |
215 } | 220 } |
216 | 221 |
217 void ScreenOrientationControllerImpl::notifyDispatcher() { | 222 void ScreenOrientationControllerImpl::notifyDispatcher() { |
218 if (m_orientation && page()->isPageVisible()) | 223 if (m_orientation && page()->isPageVisible()) |
219 startUpdating(); | 224 startUpdating(); |
220 else | 225 else |
221 stopUpdating(); | 226 stopUpdating(); |
222 } | 227 } |
223 | 228 |
224 DEFINE_TRACE(ScreenOrientationControllerImpl) { | 229 DEFINE_TRACE(ScreenOrientationControllerImpl) { |
225 visitor->trace(m_orientation); | 230 visitor->trace(m_orientation); |
226 DOMWindowProperty::trace(visitor); | 231 ContextLifecycleObserver::trace(visitor); |
227 Supplement<LocalFrame>::trace(visitor); | 232 Supplement<LocalFrame>::trace(visitor); |
228 PlatformEventController::trace(visitor); | 233 PlatformEventController::trace(visitor); |
229 } | 234 } |
230 | 235 |
231 } // namespace blink | 236 } // namespace blink |
OLD | NEW |