Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "config.h" | |
| 6 #include "modules/wake_lock/ScreenWakeLock.h" | |
| 7 | |
| 8 #include "core/frame/LocalFrame.h" | |
| 9 #include "core/frame/Screen.h" | |
| 10 #include "core/page/PageVisibilityState.h" | |
| 11 #include "platform/RuntimeEnabledFeatures.h" | |
| 12 #include "public/platform/modules/wake_lock/WebWakeLockClient.h" | |
| 13 | |
| 14 namespace blink { | |
| 15 | |
| 16 // static | |
| 17 bool ScreenWakeLock::keepAwake(Screen& screen) | |
| 18 { | |
| 19 ScreenWakeLock* screenWakeLock = fromScreen(screen); | |
| 20 if (!screenWakeLock) | |
| 21 return false; | |
| 22 | |
| 23 return screenWakeLock->keepAwake(); | |
| 24 } | |
| 25 | |
| 26 // static | |
| 27 void ScreenWakeLock::setKeepAwake(Screen& screen, bool keepAwake) | |
| 28 { | |
| 29 ScreenWakeLock* screenWakeLock = fromScreen(screen); | |
| 30 if (!screenWakeLock) | |
| 31 return; | |
| 32 | |
| 33 screenWakeLock->setKeepAwake(keepAwake); | |
| 34 } | |
| 35 | |
| 36 void ScreenWakeLock::setKeepAwake(bool keepAwake) | |
| 37 { | |
| 38 m_keepAwake = keepAwake; | |
| 39 notifyClient(); | |
| 40 } | |
| 41 | |
| 42 // static | |
| 43 const char* ScreenWakeLock::supplementName() | |
| 44 { | |
| 45 return "ScreenWakeLock"; | |
| 46 } | |
| 47 | |
| 48 // static | |
| 49 ScreenWakeLock* ScreenWakeLock::from(LocalFrame* frame) | |
| 50 { | |
| 51 return static_cast<ScreenWakeLock*>(WillBeHeapSupplement<LocalFrame>::from(f rame, supplementName())); | |
| 52 } | |
| 53 | |
| 54 // static | |
| 55 void ScreenWakeLock::provideTo(LocalFrame& frame, WebWakeLockClient* client) | |
| 56 { | |
| 57 ASSERT(RuntimeEnabledFeatures::wakeLockEnabled()); | |
| 58 WillBeHeapSupplement<LocalFrame>::provideTo( | |
| 59 frame, | |
| 60 ScreenWakeLock::supplementName(), | |
| 61 adoptPtrWillBeNoop(new ScreenWakeLock(frame, client))); | |
| 62 } | |
| 63 | |
| 64 void ScreenWakeLock::pageVisibilityChanged() | |
| 65 { | |
| 66 notifyClient(); | |
| 67 } | |
| 68 | |
| 69 void ScreenWakeLock::didCommitLoad(LocalFrame* committedFrame) | |
| 70 { | |
| 71 // Reset wake lock flag for this frame if it is the one being navigated | |
|
mlamouri (slow - plz ping)
2015/07/24 10:47:57
nit: period at the end of the sentence.
alogvinov
2015/07/24 13:36:01
Acknowledged.
| |
| 72 if (committedFrame == frame()) { | |
| 73 setKeepAwake(false); | |
| 74 } | |
| 75 } | |
| 76 | |
| 77 void ScreenWakeLock::willDetachFrameHost() | |
| 78 { | |
| 79 m_client = nullptr; | |
| 80 } | |
| 81 | |
| 82 DEFINE_TRACE(ScreenWakeLock) | |
| 83 { | |
| 84 WillBeHeapSupplement<LocalFrame>::trace(visitor); | |
| 85 PageLifecycleObserver::trace(visitor); | |
| 86 LocalFrameLifecycleObserver::trace(visitor); | |
| 87 } | |
| 88 | |
| 89 ScreenWakeLock::ScreenWakeLock(LocalFrame& frame, WebWakeLockClient* client) | |
| 90 : PageLifecycleObserver(frame.page()) | |
| 91 , LocalFrameLifecycleObserver(&frame) | |
| 92 , m_keepAwake(false) | |
| 93 , m_client(client) | |
| 94 { | |
| 95 } | |
| 96 | |
| 97 // static | |
| 98 ScreenWakeLock* ScreenWakeLock::fromScreen(Screen& screen) | |
| 99 { | |
| 100 return screen.frame() ? ScreenWakeLock::from(screen.frame()) : nullptr; | |
| 101 } | |
| 102 | |
| 103 void ScreenWakeLock::notifyClient() | |
| 104 { | |
| 105 if (!m_client) | |
| 106 return; | |
| 107 | |
| 108 bool visible = page() && page()->visibilityState() == PageVisibilityStateVis ible; | |
| 109 m_client->requestKeepScreenAwake(m_keepAwake && visible); | |
| 110 } | |
| 111 | |
| 112 } // namespace blink | |
| OLD | NEW |