| 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_WEBAPPS_MANIFEST_UPGRADE_DETECTOR_H_ |
| 6 #define CHROME_BROWSER_ANDROID_WEBAPPS_MANIFEST_UPGRADE_DETECTOR_H_ |
| 7 |
| 8 #include <vector> |
| 9 |
| 10 #include "base/android/jni_android.h" |
| 11 #include "base/android/jni_weak_ref.h" |
| 12 #include "base/macros.h" |
| 13 #include "chrome/browser/android/shortcut_info.h" |
| 14 #include "chrome/browser/android/webapps/add_to_homescreen_data_fetcher.h" |
| 15 #include "content/public/common/manifest.h" |
| 16 |
| 17 namespace content { |
| 18 class WebContents; |
| 19 } // namespace content |
| 20 |
| 21 namespace IPC { |
| 22 class Message; |
| 23 } |
| 24 |
| 25 class GURL; |
| 26 |
| 27 // ManifestUpgradeDetector is the C++ counterpart of |
| 28 // org.chromium.chrome.browser's ManifestUpgradeDetector in Java. The object |
| 29 // is owned by the Java object. It is created from there via a JNI (Initialize) |
| 30 // call and MUST BE DESTROYED via Destroy(). |
| 31 class ManifestUpgradeDetector : |
| 32 public content::WebContentsObserver, |
| 33 public AddToHomescreenDataFetcher::Observer { |
| 34 public: |
| 35 ManifestUpgradeDetector(JNIEnv* env, |
| 36 jobject obj, |
| 37 content::WebContents* web_contents); |
| 38 |
| 39 // Observes a new WebContents, if necessary. |
| 40 void ReplaceWebContents( |
| 41 JNIEnv* env, |
| 42 const base::android::JavaParamRef<jobject>& obj, |
| 43 const base::android::JavaParamRef<jobject>& jweb_contents); |
| 44 |
| 45 // Called by the Java counterpart to destroy its native half. |
| 46 void Destroy(JNIEnv* env, const base::android::JavaParamRef<jobject>& obj); |
| 47 |
| 48 // Called by the Java counterpart to start checking web manifest changes. |
| 49 void Start(JNIEnv* env, const base::android::JavaParamRef<jobject>& obj); |
| 50 |
| 51 // Registers JNI hooks. |
| 52 static bool Register(JNIEnv* env); |
| 53 |
| 54 // AddToHomescreenDataFetcher::Observer. |
| 55 void OnDidHasManifest(bool has_manifest) override; |
| 56 void OnDataAvailable(const ShortcutInfo& info, |
| 57 const SkBitmap& icon, |
| 58 const std::vector<std::string>& icon_urls) override; |
| 59 void OnUserTitleAvailable(const base::string16& user_title) override {} |
| 60 SkBitmap FinalizeLauncherIcon(const SkBitmap& icon, |
| 61 const GURL& url, |
| 62 bool* is_generated) override; |
| 63 private: |
| 64 ~ManifestUpgradeDetector() override; |
| 65 |
| 66 // content::WebContentsObserver. |
| 67 void DidFinishLoad(content::RenderFrameHost* render_frame_host, |
| 68 const GURL& validated_url) override; |
| 69 |
| 70 void RequestDetector(const GURL& validated_url); |
| 71 |
| 72 AddToHomescreenDataFetcher* CreateDataFetcher(); |
| 73 |
| 74 // Points to the Java object. |
| 75 base::android::ScopedJavaGlobalRef<jobject> java_ref_; |
| 76 |
| 77 bool start_fetching_; |
| 78 |
| 79 // Fetches data required to add a shortcut. |
| 80 scoped_refptr<AddToHomescreenDataFetcher> data_fetcher_; |
| 81 |
| 82 DISALLOW_COPY_AND_ASSIGN(ManifestUpgradeDetector); |
| 83 }; |
| 84 |
| 85 #endif // CHROME_BROWSER_ANDROID_WEBAPPS_MANIFEST_UPGRADE_DETECTOR_H_ |
| OLD | NEW |