| 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_H_ |
| 6 #define CHROME_BROWSER_ANDROID_WEBAPK_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 "base/memory/weak_ptr.h" |
| 14 #include "content/public/browser/web_contents_observer.h" |
| 15 |
| 16 namespace content { |
| 17 struct Manifest; |
| 18 class WebContents; |
| 19 } |
| 20 |
| 21 class GURL; |
| 22 struct ShortcutInfo; |
| 23 |
| 24 // ManifestUpgradeDetector is the C++ counterpart of |
| 25 // org.chromium.chrome.browser's ManifestUpgradeDetector in Java. It is created |
| 26 // via a JNI (Initialize) call and MUST BE DESTROYED via Destroy(). |
| 27 class ManifestUpgradeDetector : public content::WebContentsObserver { |
| 28 public: |
| 29 ManifestUpgradeDetector(JNIEnv* env, |
| 30 jobject obj, |
| 31 content::WebContents* web_contents, |
| 32 const GURL& scope, |
| 33 const GURL& startUrl, |
| 34 const GURL& web_manifest_url); |
| 35 |
| 36 // Replaces the WebContents that is being observed. |
| 37 void ReplaceWebContents( |
| 38 JNIEnv* env, |
| 39 const base::android::JavaParamRef<jobject>& obj, |
| 40 const base::android::JavaParamRef<jobject>& jweb_contents); |
| 41 |
| 42 // Called by the Java counterpart to destroy its native half. |
| 43 void Destroy(JNIEnv* env, const base::android::JavaParamRef<jobject>& obj); |
| 44 |
| 45 // Called by the Java counterpart to start checking web manifest changes. |
| 46 void Start(JNIEnv* env, const base::android::JavaParamRef<jobject>& obj); |
| 47 |
| 48 // Registers JNI hooks. |
| 49 static bool Register(JNIEnv* env); |
| 50 |
| 51 private: |
| 52 ~ManifestUpgradeDetector() override; |
| 53 |
| 54 // content::WebContentsObserver: |
| 55 void DidFinishLoad(content::RenderFrameHost* render_frame_host, |
| 56 const GURL& validated_url) override; |
| 57 |
| 58 // Called when the Manifest has been parsed, or if no Manifest was found. |
| 59 void OnDidGetManifest(const GURL& manifest_url, |
| 60 const content::Manifest& manifest); |
| 61 |
| 62 void OnDataAvailable(const ShortcutInfo& info); |
| 63 |
| 64 // Points to the Java object. |
| 65 base::android::ScopedJavaGlobalRef<jobject> java_ref_; |
| 66 |
| 67 bool started_; |
| 68 |
| 69 const GURL scope_; |
| 70 |
| 71 const GURL start_url_; |
| 72 |
| 73 const GURL web_manifest_url_; |
| 74 |
| 75 base::WeakPtrFactory<ManifestUpgradeDetector> weak_ptr_factory_; |
| 76 |
| 77 DISALLOW_COPY_AND_ASSIGN(ManifestUpgradeDetector); |
| 78 }; |
| 79 |
| 80 #endif // CHROME_BROWSER_ANDROID_WEBAPK_MANIFEST_UPGRADE_DETECTOR_H_ |
| OLD | NEW |