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

Unified Diff: chrome/android/java/src/org/chromium/chrome/browser/webapps/ManifestUpgradeDetectorFetcher.java

Issue 2161163004: Split fetcher logic out of ManifestUpgradeDetector (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Merge branch 'master' into webapk_updater_images0 Created 4 years, 4 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/webapps/ManifestUpgradeDetectorFetcher.java
diff --git a/chrome/android/java/src/org/chromium/chrome/browser/webapps/ManifestUpgradeDetectorFetcher.java b/chrome/android/java/src/org/chromium/chrome/browser/webapps/ManifestUpgradeDetectorFetcher.java
new file mode 100644
index 0000000000000000000000000000000000000000..4c1e5c119634f9ef5cb1fbe4465dc03f0120f5d9
--- /dev/null
+++ b/chrome/android/java/src/org/chromium/chrome/browser/webapps/ManifestUpgradeDetectorFetcher.java
@@ -0,0 +1,96 @@
+// Copyright 2016 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.webapps;
+
+import org.chromium.base.annotations.CalledByNative;
+import org.chromium.chrome.browser.tab.EmptyTabObserver;
+import org.chromium.chrome.browser.tab.Tab;
+import org.chromium.content_public.browser.WebContents;
+
+/**
+ * Downloads the Web Manifest if the web site still uses the {@link manifestUrl} passed to the
+ * constructor.
+ */
+public class ManifestUpgradeDetectorFetcher extends EmptyTabObserver {
+
+ /**
+ * Called once the Web Manifest has been downloaded.
+ */
+ public interface Callback {
+ public void onGotManifestData(String startUrl, String scopeUrl, String name,
+ String shortName, int displayMode, int orientation, long themeColor,
+ long backgroundColor);
+ }
+
+ /**
+ * Pointer to the native side ManifestUpgradeDetectorFetcher. The Java side owns the native side
+ * ManifestUpgradeDetectorFetcher.
+ */
+ private long mNativePointer;
+
+ /** The tab that is being observed. */
+ private final Tab mTab;
+
+ private Callback mCallback;
+
+ public ManifestUpgradeDetectorFetcher(Tab tab, String scopeUrl, String manifestUrl) {
+ mTab = tab;
+ mNativePointer = nativeInitialize(scopeUrl, manifestUrl);
+ }
+
+ /**
+ * Starts fetching the web manifest resources.
+ * @param callback Called once the Web Manifest has been downloaded.
+ */
+ public void start(Callback callback) {
+ mCallback = callback;
+ mTab.addObserver(this);
+ nativeStart(mNativePointer, mTab.getWebContents());
+ }
+
+ /**
+ * Puts the object in a state where it is safe to be destroyed.
+ */
+ public void destroy() {
+ mTab.removeObserver(this);
+ nativeDestroy(mNativePointer);
+ mNativePointer = 0;
+ }
+
+ @Override
+ public void onWebContentsSwapped(Tab tab, boolean didStartLoad,
+ boolean didFinishLoad) {
+ updatePointers();
+ }
+
+ @Override
+ public void onContentChanged(Tab tab) {
+ updatePointers();
+ }
+
+ /**
+ * Updates which WebContents the native ManifestUpgradeDetectorFetcher is monitoring.
+ */
+ private void updatePointers() {
+ nativeReplaceWebContents(mNativePointer, mTab.getWebContents());
+ }
+
+ /**
+ * Called when the updated Web Manifest has been fetched.
+ */
+ @CalledByNative
+ private void onDataAvailable(String startUrl, String scopeUrl, String name, String shortName,
+ int displayMode, int orientation, long themeColor, long backgroundColor) {
+ mCallback.onGotManifestData(startUrl, scopeUrl, name, shortName, displayMode, orientation,
+ themeColor, backgroundColor);
+ }
+
+ private native long nativeInitialize(String scope, String webManifestUrl);
+ private native void nativeReplaceWebContents(
+ long nativeManifestUpgradeDetectorFetcher, WebContents webContents);
+ private native void nativeDestroy(long nativeManifestUpgradeDetectorFetcher);
+ private native void nativeStart(
+ long nativeManifestUpgradeDetectorFetcher, WebContents webContents);
+}

Powered by Google App Engine
This is Rietveld 408576698