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 ScreenWakeLock::ScreenWakeLock(LocalFrame& frame, WebWakeLockClient* client) | |
mlamouri (slow - plz ping)
2015/07/05 14:50:14
nit: could you move around the definitions to matc
| |
17 : PageLifecycleObserver(frame.page()) | |
18 , LocalFrameLifecycleObserver(&frame) | |
19 , m_keepAwake(false) | |
20 , m_client(client) | |
21 { | |
22 } | |
23 | |
24 void ScreenWakeLock::setKeepAwake(bool keepAwake) | |
25 { | |
26 m_keepAwake = keepAwake; | |
27 updateClient(); | |
28 } | |
29 | |
30 // static | |
31 bool ScreenWakeLock::keepAwake(Screen& screen) | |
32 { | |
33 ScreenWakeLock* screenWakeLock = fromScreen(screen); | |
34 | |
mlamouri (slow - plz ping)
2015/07/05 14:50:14
nit: remove empty line
| |
35 if (!screenWakeLock) | |
36 return false; | |
37 | |
38 return screenWakeLock->keepAwake(); | |
39 } | |
40 | |
41 // static | |
42 void ScreenWakeLock::setKeepAwake(Screen& screen, bool keepAwake) | |
43 { | |
44 ScreenWakeLock* screenWakeLock = fromScreen(screen); | |
45 | |
mlamouri (slow - plz ping)
2015/07/05 14:50:14
ditto
| |
46 if (!screenWakeLock) | |
47 return; | |
48 | |
49 screenWakeLock->setKeepAwake(keepAwake); | |
50 } | |
51 | |
52 // static | |
53 const char* ScreenWakeLock::supplementName() | |
54 { | |
55 return "ScreenWakeLock"; | |
56 } | |
57 | |
58 // static | |
59 ScreenWakeLock* ScreenWakeLock::from(LocalFrame* frame) | |
60 { | |
61 return static_cast<ScreenWakeLock*>(WillBeHeapSupplement<LocalFrame>::from(f rame, supplementName())); | |
62 } | |
63 | |
64 // static | |
65 void ScreenWakeLock::provideTo(LocalFrame& frame, WebWakeLockClient* client) | |
66 { | |
67 ASSERT(RuntimeEnabledFeatures::wakeLockEnabled()); | |
68 WillBeHeapSupplement<LocalFrame>::provideTo( | |
69 frame, | |
70 ScreenWakeLock::supplementName(), | |
71 adoptPtrWillBeNoop(new ScreenWakeLock(frame, client))); | |
72 } | |
73 | |
74 void ScreenWakeLock::pageVisibilityChanged() | |
75 { | |
76 updateClient(); | |
77 } | |
78 | |
79 void ScreenWakeLock::didCommitLoad(LocalFrame* committedFrame) | |
80 { | |
81 // Reset wake lock flag for this frame if it is the one being navigated | |
82 if (committedFrame == frame()) { | |
83 setKeepAwake(false); | |
84 } | |
mlamouri (slow - plz ping)
2015/07/05 14:50:14
Couldn't that be handled by the content layer?
alogvinov
2015/07/06 10:18:35
Probably it could, but we're going to need to rese
| |
85 } | |
86 | |
87 void ScreenWakeLock::willDetachFrameHost() | |
88 { | |
89 m_client = nullptr; | |
90 } | |
91 | |
92 DEFINE_TRACE(ScreenWakeLock) | |
93 { | |
94 WillBeHeapSupplement<LocalFrame>::trace(visitor); | |
95 PageLifecycleObserver::trace(visitor); | |
96 LocalFrameLifecycleObserver::trace(visitor); | |
97 } | |
98 | |
99 // static | |
100 ScreenWakeLock* ScreenWakeLock::fromScreen(Screen& screen) | |
101 { | |
102 return screen.frame() ? ScreenWakeLock::from(screen.frame()) : nullptr; | |
103 } | |
104 | |
105 void ScreenWakeLock::updateClient() | |
mlamouri (slow - plz ping)
2015/07/05 14:50:14
nit: could you rename updateClient() to notificyCl
| |
106 { | |
107 if (m_client) { | |
mlamouri (slow - plz ping)
2015/07/05 14:50:14
if (!m_client)
return;
| |
108 bool visible = page() && page()->visibilityState() == PageVisibilityStat eVisible; | |
109 m_client->requestKeepScreenAwake(m_keepAwake && visible); | |
110 } | |
111 } | |
112 | |
113 } // namespace blink | |
OLD | NEW |