OLD | NEW |
| (Empty) |
1 // Copyright 2013 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 package org.chromium.content.browser; | |
6 | |
7 import android.view.View; | |
8 | |
9 import org.chromium.base.annotations.CalledByNative; | |
10 import org.chromium.base.annotations.JNINamespace; | |
11 import org.chromium.ui.base.ViewAndroidDelegate; | |
12 | |
13 import java.lang.ref.WeakReference; | |
14 | |
15 @JNINamespace("content") | |
16 class PowerSaveBlocker { | |
17 // WeakReference to prevent leaks in Android WebView. | |
18 private WeakReference<View> mKeepScreenOnView; | |
19 | |
20 @CalledByNative | |
21 private static PowerSaveBlocker create() { | |
22 return new PowerSaveBlocker(); | |
23 } | |
24 | |
25 private PowerSaveBlocker() {} | |
26 | |
27 @CalledByNative | |
28 private void applyBlock(ViewAndroidDelegate delegate) { | |
29 assert mKeepScreenOnView == null; | |
30 View anchorView = delegate.acquireAnchorView(); | |
31 mKeepScreenOnView = new WeakReference<>(anchorView); | |
32 delegate.setAnchorViewPosition(anchorView, 0, 0, 0, 0); | |
33 anchorView.setKeepScreenOn(true); | |
34 } | |
35 | |
36 @CalledByNative | |
37 private void removeBlock(ViewAndroidDelegate delegate) { | |
38 assert mKeepScreenOnView != null; | |
39 View anchorView = mKeepScreenOnView.get(); | |
40 mKeepScreenOnView = null; | |
41 if (anchorView == null) return; | |
42 | |
43 anchorView.setKeepScreenOn(false); | |
44 delegate.releaseAnchorView(anchorView); | |
45 } | |
46 } | |
OLD | NEW |