| 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/frame/LocalFrame.h" | 7 #include "core/frame/LocalFrame.h" |
| 8 #include "core/frame/Screen.h" | 8 #include "core/frame/Screen.h" |
| 9 #include "core/page/PageVisibilityState.h" | 9 #include "core/page/PageVisibilityState.h" |
| 10 #include "platform/RuntimeEnabledFeatures.h" | 10 #include "platform/RuntimeEnabledFeatures.h" |
| (...skipping 29 matching lines...) Expand all Loading... |
| 40 | 40 |
| 41 // static | 41 // static |
| 42 const char* ScreenWakeLock::supplementName() | 42 const char* ScreenWakeLock::supplementName() |
| 43 { | 43 { |
| 44 return "ScreenWakeLock"; | 44 return "ScreenWakeLock"; |
| 45 } | 45 } |
| 46 | 46 |
| 47 // static | 47 // static |
| 48 ScreenWakeLock* ScreenWakeLock::from(LocalFrame* frame) | 48 ScreenWakeLock* ScreenWakeLock::from(LocalFrame* frame) |
| 49 { | 49 { |
| 50 return static_cast<ScreenWakeLock*>(WillBeHeapSupplement<LocalFrame>::from(f
rame, supplementName())); | 50 return static_cast<ScreenWakeLock*>(HeapSupplement<LocalFrame>::from(frame,
supplementName())); |
| 51 } | 51 } |
| 52 | 52 |
| 53 // static | 53 // static |
| 54 void ScreenWakeLock::provideTo(LocalFrame& frame, WebWakeLockClient* client) | 54 void ScreenWakeLock::provideTo(LocalFrame& frame, WebWakeLockClient* client) |
| 55 { | 55 { |
| 56 ASSERT(RuntimeEnabledFeatures::wakeLockEnabled()); | 56 ASSERT(RuntimeEnabledFeatures::wakeLockEnabled()); |
| 57 WillBeHeapSupplement<LocalFrame>::provideTo( | 57 HeapSupplement<LocalFrame>::provideTo( |
| 58 frame, | 58 frame, |
| 59 ScreenWakeLock::supplementName(), | 59 ScreenWakeLock::supplementName(), |
| 60 adoptPtrWillBeNoop(new ScreenWakeLock(frame, client))); | 60 new ScreenWakeLock(frame, client)); |
| 61 } | 61 } |
| 62 | 62 |
| 63 void ScreenWakeLock::pageVisibilityChanged() | 63 void ScreenWakeLock::pageVisibilityChanged() |
| 64 { | 64 { |
| 65 notifyClient(); | 65 notifyClient(); |
| 66 } | 66 } |
| 67 | 67 |
| 68 void ScreenWakeLock::didCommitLoad(LocalFrame* committedFrame) | 68 void ScreenWakeLock::didCommitLoad(LocalFrame* committedFrame) |
| 69 { | 69 { |
| 70 // Reset wake lock flag for this frame if it is the one being navigated. | 70 // Reset wake lock flag for this frame if it is the one being navigated. |
| 71 if (committedFrame == frame()) { | 71 if (committedFrame == frame()) { |
| 72 setKeepAwake(false); | 72 setKeepAwake(false); |
| 73 } | 73 } |
| 74 } | 74 } |
| 75 | 75 |
| 76 void ScreenWakeLock::willDetachFrameHost() | 76 void ScreenWakeLock::willDetachFrameHost() |
| 77 { | 77 { |
| 78 m_client = nullptr; | 78 m_client = nullptr; |
| 79 } | 79 } |
| 80 | 80 |
| 81 DEFINE_TRACE(ScreenWakeLock) | 81 DEFINE_TRACE(ScreenWakeLock) |
| 82 { | 82 { |
| 83 WillBeHeapSupplement<LocalFrame>::trace(visitor); | 83 HeapSupplement<LocalFrame>::trace(visitor); |
| 84 PageLifecycleObserver::trace(visitor); | 84 PageLifecycleObserver::trace(visitor); |
| 85 LocalFrameLifecycleObserver::trace(visitor); | 85 LocalFrameLifecycleObserver::trace(visitor); |
| 86 } | 86 } |
| 87 | 87 |
| 88 ScreenWakeLock::ScreenWakeLock(LocalFrame& frame, WebWakeLockClient* client) | 88 ScreenWakeLock::ScreenWakeLock(LocalFrame& frame, WebWakeLockClient* client) |
| 89 : PageLifecycleObserver(frame.page()) | 89 : PageLifecycleObserver(frame.page()) |
| 90 , LocalFrameLifecycleObserver(&frame) | 90 , LocalFrameLifecycleObserver(&frame) |
| 91 , m_client(client) | 91 , m_client(client) |
| 92 , m_keepAwake(false) | 92 , m_keepAwake(false) |
| 93 { | 93 { |
| 94 } | 94 } |
| 95 | 95 |
| 96 // static | 96 // static |
| 97 ScreenWakeLock* ScreenWakeLock::fromScreen(Screen& screen) | 97 ScreenWakeLock* ScreenWakeLock::fromScreen(Screen& screen) |
| 98 { | 98 { |
| 99 return screen.frame() ? ScreenWakeLock::from(screen.frame()) : nullptr; | 99 return screen.frame() ? ScreenWakeLock::from(screen.frame()) : nullptr; |
| 100 } | 100 } |
| 101 | 101 |
| 102 void ScreenWakeLock::notifyClient() | 102 void ScreenWakeLock::notifyClient() |
| 103 { | 103 { |
| 104 if (!m_client) | 104 if (!m_client) |
| 105 return; | 105 return; |
| 106 | 106 |
| 107 m_client->requestKeepScreenAwake(m_keepAwake && page() && page()->isPageVisi
ble()); | 107 m_client->requestKeepScreenAwake(m_keepAwake && page() && page()->isPageVisi
ble()); |
| 108 } | 108 } |
| 109 | 109 |
| 110 } // namespace blink | 110 } // namespace blink |
| OLD | NEW |