| OLD | NEW |
| (Empty) |
| 1 // Copyright 2016 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 #ifndef CHROME_BROWSER_ANDROID_WEBAPK_MANIFEST_UPGRADE_DETECTOR_FETCHER_H_ | |
| 6 #define CHROME_BROWSER_ANDROID_WEBAPK_MANIFEST_UPGRADE_DETECTOR_FETCHER_H_ | |
| 7 | |
| 8 #include "base/android/jni_android.h" | |
| 9 #include "base/android/jni_weak_ref.h" | |
| 10 #include "base/macros.h" | |
| 11 #include "base/memory/weak_ptr.h" | |
| 12 #include "chrome/browser/android/shortcut_info.h" | |
| 13 #include "content/public/browser/web_contents_observer.h" | |
| 14 #include "third_party/skia/include/core/SkBitmap.h" | |
| 15 | |
| 16 namespace content { | |
| 17 struct Manifest; | |
| 18 class WebContents; | |
| 19 } | |
| 20 | |
| 21 class GURL; | |
| 22 struct InstallableData; | |
| 23 class WebApkIconHasher; | |
| 24 | |
| 25 // ManifestUpgradeDetectorFetcher is the C++ counterpart of | |
| 26 // org.chromium.chrome.browser's ManifestUpgradeDetectorFetcher in Java. It is | |
| 27 // created via a JNI (Initialize) call and MUST BE DESTROYED via Destroy(). | |
| 28 class ManifestUpgradeDetectorFetcher : public content::WebContentsObserver { | |
| 29 public: | |
| 30 ManifestUpgradeDetectorFetcher(JNIEnv* env, | |
| 31 jobject obj, | |
| 32 const GURL& scope, | |
| 33 const GURL& web_manifest_url); | |
| 34 | |
| 35 // Replaces the WebContents that is being observed. | |
| 36 void ReplaceWebContents( | |
| 37 JNIEnv* env, | |
| 38 const base::android::JavaParamRef<jobject>& obj, | |
| 39 const base::android::JavaParamRef<jobject>& java_web_contents); | |
| 40 | |
| 41 // Called by the Java counterpart to destroy its native half. | |
| 42 void Destroy(JNIEnv* env, const base::android::JavaParamRef<jobject>& obj); | |
| 43 | |
| 44 // Called by the Java counterpart to start checking web manifest changes. | |
| 45 void Start(JNIEnv* env, | |
| 46 const base::android::JavaParamRef<jobject>& obj, | |
| 47 const base::android::JavaParamRef<jobject>& java_web_contents); | |
| 48 | |
| 49 // Registers JNI hooks. | |
| 50 static bool Register(JNIEnv* env); | |
| 51 | |
| 52 private: | |
| 53 ~ManifestUpgradeDetectorFetcher() override; | |
| 54 | |
| 55 // content::WebContentsObserver: | |
| 56 void DidStopLoading() override; | |
| 57 | |
| 58 // Fetches the installable data. | |
| 59 void FetchInstallableData(); | |
| 60 | |
| 61 // Called once the installable data has been fetched. | |
| 62 void OnDidGetInstallableData(const InstallableData& installable_data); | |
| 63 | |
| 64 // Called with the computed Murmur2 hash for the app icon. | |
| 65 void OnGotIconMurmur2Hash(const std::string& best_icon_murmur2_hash); | |
| 66 | |
| 67 void OnDataAvailable(const ShortcutInfo& info, | |
| 68 const std::string& best_icon_murmur2_hash, | |
| 69 const SkBitmap& best_icon); | |
| 70 | |
| 71 // Points to the Java object. | |
| 72 base::android::ScopedJavaGlobalRef<jobject> java_ref_; | |
| 73 | |
| 74 // The detector will only fetch the URL within the scope of the WebAPK. | |
| 75 const GURL scope_; | |
| 76 | |
| 77 // The WebAPK's Web Manifest URL that the detector is looking for. | |
| 78 const GURL web_manifest_url_; | |
| 79 | |
| 80 // The URL for which the installable data is being fetched / was last fetched. | |
| 81 GURL last_fetched_url_; | |
| 82 | |
| 83 // Downloads app icon and computes Murmur2 hash. | |
| 84 std::unique_ptr<WebApkIconHasher> icon_hasher_; | |
| 85 | |
| 86 // Downloaded data for |web_manifest_url_|. | |
| 87 ShortcutInfo info_; | |
| 88 SkBitmap best_icon_; | |
| 89 | |
| 90 base::WeakPtrFactory<ManifestUpgradeDetectorFetcher> weak_ptr_factory_; | |
| 91 | |
| 92 DISALLOW_COPY_AND_ASSIGN(ManifestUpgradeDetectorFetcher); | |
| 93 }; | |
| 94 | |
| 95 #endif // CHROME_BROWSER_ANDROID_WEBAPK_MANIFEST_UPGRADE_DETECTOR_FETCHER_H_ | |
| OLD | NEW |