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

Unified Diff: chrome/android/java/src/org/chromium/chrome/browser/banners/AppBannerManager.java

Issue 155503004: Create a skeleton AppBannerManager class (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Back and forth, forth and back Created 6 years, 10 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
Index: chrome/android/java/src/org/chromium/chrome/browser/banners/AppBannerManager.java
diff --git a/chrome/android/java/src/org/chromium/chrome/browser/banners/AppBannerManager.java b/chrome/android/java/src/org/chromium/chrome/browser/banners/AppBannerManager.java
new file mode 100644
index 0000000000000000000000000000000000000000..4aa92215949f79398de65bd075f83915976c7a9d
--- /dev/null
+++ b/chrome/android/java/src/org/chromium/chrome/browser/banners/AppBannerManager.java
@@ -0,0 +1,90 @@
+// Copyright 2014 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.chrome.browser.banners;
+
+import org.chromium.chrome.browser.EmptyTabObserver;
+import org.chromium.chrome.browser.TabBase;
+import org.chromium.chrome.browser.TabObserver;
+import org.chromium.content.browser.ContentView;
+import org.chromium.content_public.browser.WebContents;
+
+/**
+ * Manages an AppBannerView for a TabBase and its ContentView.
+ *
+ * The AppBannerManager manages a single AppBannerView, dismissing it when the user navigates to a
+ * new page or creating a new one when it detects that the current webpage is requesting a banner
+ * to be built. The actual observeration of the WebContents (which triggers the automatic creation
+ * and removal of banners, among other things) is done by the native-side AppBannerManager.
+ *
+ * This Java-side class owns its native-side counterpart.
+ */
+public class AppBannerManager {
+ /** Pointer to the native side AppBannerManager. */
+ private final long mNativePointer;
+
+ /** TabBase that the AppBannerView/AppBannerManager is owned by. */
+ private final TabBase mTabBase;
+
+ /** ContentView that the AppBannerView/AppBannerManager is currently attached to. */
+ private ContentView mContentView;
+
+ /**
+ * Constructs an AppBannerManager for the given tab.
+ * @param tab Tab that the AppBannerManager will be attached to.
+ */
+ public AppBannerManager(TabBase tab) {
+ mNativePointer = nativeInit();
+ mTabBase = tab;
+ mTabBase.addObserver(createTabObserver());
+ updatePointers();
+ }
+
+ /**
+ * Creates a TabObserver for monitoring a TabBase, used to react to changes in the ContentView
+ * or to trigger its own destruction.
+ * @return TabObserver that can be used to monitor a TabBase.
+ */
+ private TabObserver createTabObserver() {
+ return new EmptyTabObserver() {
+ @Override
+ public void onWebContentsSwapped(TabBase tab, boolean didStartLoad,
+ boolean didFinishLoad) {
+ updatePointers();
+ }
+
+ @Override
+ public void onContentChanged(TabBase tab) {
+ updatePointers();
+ }
+
+ @Override
+ public void onDestroyed(TabBase tab) {
+ nativeDestroy(mNativePointer);
+ }
+ };
+ }
+
+ /**
+ * Updates which ContentView and WebContents the AppBannerView is monitoring.
+ */
+ private void updatePointers() {
+ if (mContentView != mTabBase.getContentView()) mContentView = mTabBase.getContentView();
+ nativeReplaceWebContents(mNativePointer, mTabBase.getWebContents());
+ }
+
+ /**
+ * Checks if app banners are enabled.
+ * @return True if banners are enabled, false otherwise.
+ */
+ public static boolean isEnabled() {
+ return nativeIsEnabled();
+ }
+
+ private static native boolean nativeIsEnabled();
+ private native long nativeInit();
+ private native void nativeDestroy(long nativeAppBannerManager);
+ private native void nativeReplaceWebContents(
+ long nativeAppBannerManager, WebContents webContents);
+}
« no previous file with comments | « chrome/android/java/src/org/chromium/chrome/browser/TabBase.java ('k') | chrome/browser/android/banners/OWNERS » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698