Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(713)

Unified Diff: content/public/android/java/src/org/chromium/content/browser/PowerSaveBlocker.java

Issue 2075973002: Revert of Move content/browser/power_save_blocker to //device/power_save_blocker (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@power-save-next-2
Patch Set: Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « content/public/android/BUILD.gn ('k') | content/public/browser/BUILD.gn » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: content/public/android/java/src/org/chromium/content/browser/PowerSaveBlocker.java
diff --git a/content/public/android/java/src/org/chromium/content/browser/PowerSaveBlocker.java b/content/public/android/java/src/org/chromium/content/browser/PowerSaveBlocker.java
new file mode 100644
index 0000000000000000000000000000000000000000..915d668da16f01c7d09df3a7cc9c3c323a99434f
--- /dev/null
+++ b/content/public/android/java/src/org/chromium/content/browser/PowerSaveBlocker.java
@@ -0,0 +1,46 @@
+// Copyright 2013 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+package org.chromium.content.browser;
+
+import android.view.View;
+
+import org.chromium.base.annotations.CalledByNative;
+import org.chromium.base.annotations.JNINamespace;
+import org.chromium.ui.base.ViewAndroidDelegate;
+
+import java.lang.ref.WeakReference;
+
+@JNINamespace("content")
+class PowerSaveBlocker {
+ // WeakReference to prevent leaks in Android WebView.
+ private WeakReference<View> mKeepScreenOnView;
+
+ @CalledByNative
+ private static PowerSaveBlocker create() {
+ return new PowerSaveBlocker();
+ }
+
+ private PowerSaveBlocker() {}
+
+ @CalledByNative
+ private void applyBlock(ViewAndroidDelegate delegate) {
+ assert mKeepScreenOnView == null;
+ View anchorView = delegate.acquireAnchorView();
+ mKeepScreenOnView = new WeakReference<>(anchorView);
+ delegate.setAnchorViewPosition(anchorView, 0, 0, 0, 0);
+ anchorView.setKeepScreenOn(true);
+ }
+
+ @CalledByNative
+ private void removeBlock(ViewAndroidDelegate delegate) {
+ assert mKeepScreenOnView != null;
+ View anchorView = mKeepScreenOnView.get();
+ mKeepScreenOnView = null;
+ if (anchorView == null) return;
+
+ anchorView.setKeepScreenOn(false);
+ delegate.releaseAnchorView(anchorView);
+ }
+}
« no previous file with comments | « content/public/android/BUILD.gn ('k') | content/public/browser/BUILD.gn » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698