Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef CHROME_BROWSER_ANDROID_BANNERS_APP_BANNER_MANAGER_H_ | 5 #ifndef CHROME_BROWSER_ANDROID_BANNERS_APP_BANNER_MANAGER_H_ |
| 6 #define CHROME_BROWSER_ANDROID_BANNERS_APP_BANNER_MANAGER_H_ | 6 #define CHROME_BROWSER_ANDROID_BANNERS_APP_BANNER_MANAGER_H_ |
| 7 | 7 |
| 8 #include "base/android/jni_android.h" | 8 #include "base/android/jni_android.h" |
| 9 #include "base/android/jni_weak_ref.h" | 9 #include "base/android/jni_weak_ref.h" |
| 10 #include "base/memory/ref_counted.h" | 10 #include "base/memory/ref_counted.h" |
| 11 #include "base/memory/scoped_ptr.h" | 11 #include "base/memory/scoped_ptr.h" |
| 12 #include "base/memory/weak_ptr.h" | 12 #include "base/memory/weak_ptr.h" |
| 13 #include "base/time/time.h" | 13 #include "base/time/time.h" |
| 14 #include "chrome/browser/android/banners/app_banner_infobar_delegate.h" | 14 #include "chrome/browser/android/banners/app_banner_infobar_delegate.h" |
| 15 #include "chrome/browser/bitmap_fetcher/bitmap_fetcher.h" | 15 #include "chrome/browser/bitmap_fetcher/bitmap_fetcher.h" |
| 16 #include "chrome/browser/ui/android/infobars/app_banner_infobar.h" | 16 #include "chrome/browser/ui/android/infobars/app_banner_infobar.h" |
| 17 #include "components/infobars/core/infobar_manager.h" | 17 #include "components/infobars/core/infobar_manager.h" |
| 18 #include "content/public/browser/web_contents_observer.h" | 18 #include "content/public/browser/web_contents_observer.h" |
| 19 #include "content/public/common/manifest.h" | 19 #include "content/public/common/manifest.h" |
| 20 | 20 |
| 21 namespace content { | 21 namespace content { |
| 22 struct FrameNavigateParams; | 22 struct FrameNavigateParams; |
| 23 struct LoadCommittedDetails; | 23 struct LoadCommittedDetails; |
| 24 } // namespace content | 24 } // namespace content |
| 25 | 25 |
| 26 namespace infobars { | 26 namespace infobars { |
| 27 class InfoBar; | 27 class InfoBar; |
| 28 } // namspace infobars | 28 } // namspace infobars |
| 29 | 29 |
| 30 class BannerBitmapFetcher; | |
|
benwells
2015/02/16 01:58:43
Nit: I think it is nicer to put this inside AppBan
gone
2015/02/17 22:56:52
Done.
| |
| 31 | |
| 30 /** | 32 /** |
| 31 * Manages when an app banner is created or dismissed. | 33 * Manages when an app banner is created or dismissed. |
| 32 * | 34 * |
| 33 * Hooks the wiring together for getting the data for a particular app. | 35 * Hooks the wiring together for getting the data for a particular app. |
| 34 * Monitors at most one package at a time, and tracks the info for the | 36 * Monitors at most one package at a time, and tracks the info for the |
| 35 * most recent app that was requested. Any work in progress for other apps is | 37 * most recent app that was requested. Any work in progress for other apps is |
| 36 * discarded. | 38 * discarded. |
| 37 * | 39 * |
| 38 * The procedure for creating a banner spans multiple asynchronous calls across | 40 * The procedure for creating a banner spans multiple asynchronous calls across |
| 39 * the JNI boundary, as well as querying a Service to get info about the app. | 41 * the JNI boundary, as well as querying a Service to get info about the app. |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 60 * app we retrieved the details for is still for the page that requested it. | 62 * app we retrieved the details for is still for the page that requested it. |
| 61 * | 63 * |
| 62 * Because of the asynchronous nature of this pipeline, it's entirely possible | 64 * Because of the asynchronous nature of this pipeline, it's entirely possible |
| 63 * that a request to show a banner is interrupted by another request. The | 65 * that a request to show a banner is interrupted by another request. The |
| 64 * Java side manages what happens in these situations, which will usually result | 66 * Java side manages what happens in these situations, which will usually result |
| 65 * in dropping the old banner request on the floor. | 67 * in dropping the old banner request on the floor. |
| 66 */ | 68 */ |
| 67 | 69 |
| 68 namespace banners { | 70 namespace banners { |
| 69 | 71 |
| 70 class AppBannerManager : public chrome::BitmapFetcherDelegate, | 72 class AppBannerManager : public content::WebContentsObserver { |
| 71 public content::WebContentsObserver { | |
| 72 public: | 73 public: |
| 73 AppBannerManager(JNIEnv* env, jobject obj); | 74 AppBannerManager(JNIEnv* env, jobject obj); |
| 74 ~AppBannerManager() override; | 75 ~AppBannerManager() override; |
| 75 | 76 |
| 76 // Destroys the AppBannerManager. | 77 // Destroys the AppBannerManager. |
| 77 void Destroy(JNIEnv* env, jobject obj); | 78 void Destroy(JNIEnv* env, jobject obj); |
| 78 | 79 |
| 79 // Observes a new WebContents, if necessary. | 80 // Observes a new WebContents, if necessary. |
| 80 void ReplaceWebContents(JNIEnv* env, | 81 void ReplaceWebContents(JNIEnv* env, |
| 81 jobject obj, | 82 jobject obj, |
| 82 jobject jweb_contents); | 83 jobject jweb_contents); |
| 83 | 84 |
| 84 // Called when the Java-side has retrieved information for the app. | 85 // Called when the Java-side has retrieved information for the app. |
| 85 // Returns |false| if an icon fetch couldn't be kicked off. | 86 // Returns |false| if an icon fetch couldn't be kicked off. |
| 86 bool OnAppDetailsRetrieved(JNIEnv* env, | 87 bool OnAppDetailsRetrieved(JNIEnv* env, |
| 87 jobject obj, | 88 jobject obj, |
| 88 jobject japp_data, | 89 jobject japp_data, |
| 89 jstring japp_title, | 90 jstring japp_title, |
| 90 jstring japp_package, | 91 jstring japp_package, |
| 91 jstring jicon_url); | 92 jstring jicon_url); |
| 92 | 93 |
| 93 // Fetches the icon at the given URL asynchronously. | 94 // Fetches the icon at the given URL asynchronously. |
| 94 // Returns |false| if this couldn't be kicked off. | 95 // Returns |false| if this couldn't be kicked off. |
| 95 bool FetchIcon(const GURL& image_url); | 96 bool FetchIcon(const GURL& image_url); |
| 96 | 97 |
| 98 // Called when everything required to show a banner is ready. | |
| 99 void OnFetchComplete(BannerBitmapFetcher* fetcher, | |
| 100 const GURL url, | |
| 101 const SkBitmap* icon); | |
| 102 | |
| 97 // Return how many fetchers are active. | 103 // Return how many fetchers are active. |
| 98 int GetNumActiveFetchers(JNIEnv* env, jobject jobj); | 104 int GetNumActiveFetchers(JNIEnv* env, jobject jobj); |
| 99 | 105 |
| 100 // Returns the current time. | 106 // Returns the current time. |
| 101 static base::Time GetCurrentTime(); | 107 static base::Time GetCurrentTime(); |
| 102 | 108 |
| 103 // WebContentsObserver overrides. | 109 // WebContentsObserver overrides. |
| 104 void DidNavigateMainFrame( | 110 void DidNavigateMainFrame( |
| 105 const content::LoadCommittedDetails& details, | 111 const content::LoadCommittedDetails& details, |
| 106 const content::FrameNavigateParams& params) override; | 112 const content::FrameNavigateParams& params) override; |
| 107 void DidFinishLoad(content::RenderFrameHost* render_frame_host, | 113 void DidFinishLoad(content::RenderFrameHost* render_frame_host, |
| 108 const GURL& validated_url) override; | 114 const GURL& validated_url) override; |
| 109 bool OnMessageReceived(const IPC::Message& message) override; | 115 bool OnMessageReceived(const IPC::Message& message) override; |
| 110 | 116 |
| 111 // BitmapFetcherDelegate overrides. | |
| 112 void OnFetchComplete(const GURL url, const SkBitmap* bitmap) override; | |
| 113 | |
| 114 private: | 117 private: |
| 115 // Gets the preferred icon size for the banner icons. | 118 // Gets the preferred icon size for the banner icons. |
| 116 int GetPreferredIconSize(); | 119 int GetPreferredIconSize(); |
| 117 | 120 |
| 118 // Called when the manifest has been retrieved, or if there is no manifest to | 121 // Called when the manifest has been retrieved, or if there is no manifest to |
| 119 // retrieve. | 122 // retrieve. |
| 120 void OnDidGetManifest(const content::Manifest& manifest); | 123 void OnDidGetManifest(const content::Manifest& manifest); |
| 121 | 124 |
| 122 // Called when the renderer has returned information about the meta tag. | 125 // Called when the renderer has returned information about the meta tag. |
| 123 // If there is some metadata for the play store tag, this kicks off the | 126 // If there is some metadata for the play store tag, this kicks off the |
| 124 // process of showing a banner for the package designated by |tag_content| on | 127 // process of showing a banner for the package designated by |tag_content| on |
| 125 // the page at the |expected_url|. | 128 // the page at the |expected_url|. |
| 126 void OnDidRetrieveMetaTagContent(bool success, | 129 void OnDidRetrieveMetaTagContent(bool success, |
| 127 const std::string& tag_name, | 130 const std::string& tag_name, |
| 128 const std::string& tag_content, | 131 const std::string& tag_content, |
| 129 const GURL& expected_url); | 132 const GURL& expected_url); |
| 130 | 133 |
| 131 // Called when the result of the CheckHasServiceWorker query has completed. | 134 // Called when the result of the CheckHasServiceWorker query has completed. |
| 132 void OnDidCheckHasServiceWorker(bool has_service_worker); | 135 void OnDidCheckHasServiceWorker(bool has_service_worker); |
| 133 | 136 |
| 134 // Record that the banner could be shown at this point, if the triggering | 137 // Record that the banner could be shown at this point, if the triggering |
| 135 // heuristic allowed. | 138 // heuristic allowed. |
| 136 void RecordCouldShowBanner(const std::string& package_or_start_url); | 139 void RecordCouldShowBanner(const std::string& package_or_start_url); |
| 137 | 140 |
| 138 // Check if the banner should be shown. | 141 // Check if the banner should be shown. |
| 139 bool CheckIfShouldShow(const std::string& package_or_start_url); | 142 bool CheckIfShouldShow(const std::string& package_or_start_url); |
| 140 | 143 |
| 141 // Fetches the icon for an app. | 144 // Fetches the icon for an app. |
| 142 scoped_ptr<chrome::BitmapFetcher> fetcher_; | 145 typedef std::vector<BannerBitmapFetcher*> BitmapFetcherVector; |
| 146 BitmapFetcherVector active_fetchers_; | |
| 147 | |
| 143 GURL validated_url_; | 148 GURL validated_url_; |
| 144 GURL app_icon_url_; | 149 GURL app_icon_url_; |
| 145 | 150 |
| 146 base::string16 app_title_; | 151 base::string16 app_title_; |
| 147 | 152 |
| 148 content::Manifest web_app_data_; | 153 content::Manifest web_app_data_; |
| 149 | 154 |
| 150 base::android::ScopedJavaGlobalRef<jobject> native_app_data_; | 155 base::android::ScopedJavaGlobalRef<jobject> native_app_data_; |
| 151 std::string native_app_package_; | 156 std::string native_app_package_; |
| 152 | 157 |
| 153 // AppBannerManager on the Java side. | 158 // AppBannerManager on the Java side. |
| 154 JavaObjectWeakGlobalRef weak_java_banner_view_manager_; | 159 JavaObjectWeakGlobalRef weak_java_banner_view_manager_; |
| 155 | 160 |
| 156 // A weak pointer is used as the lifetime of the ServiceWorkerContext is | 161 // A weak pointer is used as the lifetime of the ServiceWorkerContext is |
| 157 // longer than the lifetime of this banner manager. The banner manager | 162 // longer than the lifetime of this banner manager. The banner manager |
| 158 // might be gone when calls sent to the ServiceWorkerContext are completed. | 163 // might be gone when calls sent to the ServiceWorkerContext are completed. |
| 159 base::WeakPtrFactory<AppBannerManager> weak_factory_; | 164 base::WeakPtrFactory<AppBannerManager> weak_factory_; |
| 160 | 165 |
| 161 DISALLOW_COPY_AND_ASSIGN(AppBannerManager); | 166 DISALLOW_COPY_AND_ASSIGN(AppBannerManager); |
| 162 }; // class AppBannerManager | 167 }; // class AppBannerManager |
| 163 | 168 |
| 164 // Register native methods | 169 // Register native methods |
| 165 bool RegisterAppBannerManager(JNIEnv* env); | 170 bool RegisterAppBannerManager(JNIEnv* env); |
| 166 | 171 |
| 167 } // namespace banners | 172 } // namespace banners |
| 168 | 173 |
| 169 #endif // CHROME_BROWSER_ANDROID_BANNERS_APP_BANNER_MANAGER_H_ | 174 #endif // CHROME_BROWSER_ANDROID_BANNERS_APP_BANNER_MANAGER_H_ |
| OLD | NEW |