OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/wake_lock/ScreenWakeLock.h" | 5 #include "modules/wake_lock/ScreenWakeLock.h" |
6 | 6 |
7 #include "core/dom/Document.h" | 7 #include "core/dom/Document.h" |
8 #include "core/frame/LocalFrame.h" | 8 #include "core/frame/LocalFrame.h" |
9 #include "core/frame/Screen.h" | 9 #include "core/frame/Screen.h" |
10 #include "core/page/PageVisibilityState.h" | 10 #include "core/page/PageVisibilityState.h" |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
60 PageVisibilityObserver::trace(visitor); | 60 PageVisibilityObserver::trace(visitor); |
61 ContextLifecycleObserver::trace(visitor); | 61 ContextLifecycleObserver::trace(visitor); |
62 } | 62 } |
63 | 63 |
64 ScreenWakeLock::ScreenWakeLock(LocalFrame& frame) | 64 ScreenWakeLock::ScreenWakeLock(LocalFrame& frame) |
65 : ContextLifecycleObserver(frame.document()), | 65 : ContextLifecycleObserver(frame.document()), |
66 PageVisibilityObserver(frame.page()), | 66 PageVisibilityObserver(frame.page()), |
67 m_keepAwake(false) { | 67 m_keepAwake(false) { |
68 DCHECK(!m_service.is_bound()); | 68 DCHECK(!m_service.is_bound()); |
69 DCHECK(frame.interfaceProvider()); | 69 DCHECK(frame.interfaceProvider()); |
70 frame.interfaceProvider()->getInterface(mojo::GetProxy(&m_service)); | 70 frame.interfaceProvider()->getInterface(mojo::MakeRequest(&m_service)); |
71 } | 71 } |
72 | 72 |
73 bool ScreenWakeLock::keepAwake() const { | 73 bool ScreenWakeLock::keepAwake() const { |
74 return m_keepAwake; | 74 return m_keepAwake; |
75 } | 75 } |
76 | 76 |
77 void ScreenWakeLock::setKeepAwake(bool keepAwake) { | 77 void ScreenWakeLock::setKeepAwake(bool keepAwake) { |
78 m_keepAwake = keepAwake; | 78 m_keepAwake = keepAwake; |
79 notifyService(); | 79 notifyService(); |
80 } | 80 } |
81 | 81 |
82 // static | 82 // static |
83 ScreenWakeLock* ScreenWakeLock::fromScreen(Screen& screen) { | 83 ScreenWakeLock* ScreenWakeLock::fromScreen(Screen& screen) { |
84 return screen.frame() ? ScreenWakeLock::from(screen.frame()) : nullptr; | 84 return screen.frame() ? ScreenWakeLock::from(screen.frame()) : nullptr; |
85 } | 85 } |
86 | 86 |
87 void ScreenWakeLock::notifyService() { | 87 void ScreenWakeLock::notifyService() { |
88 if (!m_service) | 88 if (!m_service) |
89 return; | 89 return; |
90 | 90 |
91 if (m_keepAwake && page() && page()->isPageVisible()) | 91 if (m_keepAwake && page() && page()->isPageVisible()) |
92 m_service->RequestWakeLock(); | 92 m_service->RequestWakeLock(); |
93 else | 93 else |
94 m_service->CancelWakeLock(); | 94 m_service->CancelWakeLock(); |
95 } | 95 } |
96 | 96 |
97 } // namespace blink | 97 } // namespace blink |
OLD | NEW |