| 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 "base/android/jni_android.h" |
| 9 #include "base/android/jni_weak_ref.h" |
| 10 #include "base/gtest_prod_util.h" |
| 11 #include "base/macros.h" |
| 12 #include "base/memory/weak_ptr.h" |
| 13 #include "content/public/browser/web_contents_observer.h" |
| 14 |
| 15 namespace content { |
| 16 struct Manifest; |
| 17 class WebContents; |
| 18 } |
| 19 |
| 20 class GURL; |
| 21 struct ShortcutInfo; |
| 22 |
| 23 // ManifestUpgradeDetector is the C++ counterpart of |
| 24 // org.chromium.chrome.browser's ManifestUpgradeDetector in Java. It is created |
| 25 // via a JNI (Initialize) call and MUST BE DESTROYED via Destroy(). |
| 26 class ManifestUpgradeDetector : public content::WebContentsObserver { |
| 27 public: |
| 28 enum ErrorCode { |
| 29 NoErrorDetected, |
| 30 FetchedManifestEmpty, |
| 31 }; |
| 32 |
| 33 ManifestUpgradeDetector(JNIEnv* env, |
| 34 jobject obj, |
| 35 content::WebContents* web_contents, |
| 36 const GURL& scope, |
| 37 const GURL& web_manifest_url); |
| 38 |
| 39 // Replaces the WebContents that is being observed. |
| 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 ErrorCode error_code() { return error_code_; } |
| 55 |
| 56 private: |
| 57 FRIEND_TEST_ALL_PREFIXES(ManifestUpgradeDetectorTest, |
| 58 OnDidGetManifestReturnsFalseWhenTheFetchedManifestUrlIsEmpty); |
| 59 ~ManifestUpgradeDetector() override; |
| 60 |
| 61 // content::WebContentsObserver: |
| 62 void DidFinishLoad(content::RenderFrameHost* render_frame_host, |
| 63 const GURL& validated_url) override; |
| 64 |
| 65 // Called when the Manifest has been parsed, or if no Manifest was found. |
| 66 void OnDidGetManifest(const GURL& manifest_url, |
| 67 const content::Manifest& manifest); |
| 68 |
| 69 void OnDataAvailable(const ShortcutInfo& info); |
| 70 |
| 71 // Points to the Java object. |
| 72 base::android::ScopedJavaGlobalRef<jobject> java_ref_; |
| 73 |
| 74 // A flag to indicate if the detection pipeline was started. |
| 75 bool started_; |
| 76 |
| 77 // The detector will only fetch the URL within the scope of the WebAPK. |
| 78 const GURL scope_; |
| 79 |
| 80 // The WebAPK's Web Manifest URL that the detector is looking for. |
| 81 const GURL web_manifest_url_; |
| 82 |
| 83 // Error message code. |
| 84 ErrorCode error_code_; |
| 85 |
| 86 base::WeakPtrFactory<ManifestUpgradeDetector> weak_ptr_factory_; |
| 87 |
| 88 DISALLOW_COPY_AND_ASSIGN(ManifestUpgradeDetector); |
| 89 }; |
| 90 |
| 91 #endif // CHROME_BROWSER_ANDROID_WEBAPK_MANIFEST_UPGRADE_DETECTOR_H_ |
| OLD | NEW |