| 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" |
| (...skipping 13 matching lines...) Expand all Loading... |
| 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 /** | 30 /** |
| 31 * Manages when an app banner is created or dismissed. | 31 * Manages when an app banner is created or dismissed. |
| 32 * | 32 * |
| 33 * Hooks the wiring together for getting the data for a particular app. | 33 * 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 | 34 * Monitors at most one app at a time, tracking the info for the most recently |
| 35 * most recent app that was requested. Any work in progress for other apps is | 35 * requested app. Any work in progress for other apps is discarded. |
| 36 * discarded. | |
| 37 * | 36 * |
| 38 * The procedure for creating a banner spans multiple asynchronous calls across | 37 * TODO(dfalcantara): Update this when the pipeline requirements resolidify. |
| 39 * the JNI boundary, as well as querying a Service to get info about the app. | |
| 40 * | |
| 41 * 0) A navigation of the main frame is triggered. Upon completion of the load, | |
| 42 * the page is parsed for the correct meta tag. If it doesn't exist, abort. | |
| 43 * | |
| 44 * 1) The AppBannerManager is alerted about the tag's contents, which should | |
| 45 * be the Play Store package name. This is sent to the Java side | |
| 46 * AppBannerManager. | |
| 47 * | |
| 48 * 2) The AppBannerManager's ServiceDelegate is asynchronously queried about the | |
| 49 * package name. | |
| 50 * | |
| 51 * 3) At some point, the Java-side AppBannerManager is alerted of the completed | |
| 52 * query and is given back data about the requested package, which includes a | |
| 53 * URL for the app's icon. This URL is sent to native code for retrieval. | |
| 54 * | |
| 55 * 4) The process of fetching the icon begins by invoking the BitmapFetcher, | |
| 56 * which works asynchonously. | |
| 57 * | |
| 58 * 5) Once the icon has been downloaded, the icon is sent to the Java-side | |
| 59 * AppBannerManager to (finally) create a AppBannerView, assuming that the | |
| 60 * app we retrieved the details for is still for the page that requested it. | |
| 61 * | |
| 62 * 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 | |
| 64 * Java side manages what happens in these situations, which will usually result | |
| 65 * in dropping the old banner request on the floor. | |
| 66 */ | 38 */ |
| 67 | 39 |
| 68 namespace banners { | 40 namespace banners { |
| 69 | 41 |
| 70 class AppBannerManager : public content::WebContentsObserver { | 42 class AppBannerManager : public content::WebContentsObserver { |
| 71 public: | 43 public: |
| 72 class BannerBitmapFetcher; | 44 class BannerBitmapFetcher; |
| 73 | 45 |
| 74 AppBannerManager(JNIEnv* env, jobject obj); | 46 AppBannerManager(JNIEnv* env, jobject obj, int icon_size); |
| 75 ~AppBannerManager() override; | 47 ~AppBannerManager() override; |
| 76 | 48 |
| 77 // Destroys the AppBannerManager. | 49 // Destroys the AppBannerManager. |
| 78 void Destroy(JNIEnv* env, jobject obj); | 50 void Destroy(JNIEnv* env, jobject obj); |
| 79 | 51 |
| 80 // Observes a new WebContents, if necessary. | 52 // Observes a new WebContents, if necessary. |
| 81 void ReplaceWebContents(JNIEnv* env, | 53 void ReplaceWebContents(JNIEnv* env, |
| 82 jobject obj, | 54 jobject obj, |
| 83 jobject jweb_contents); | 55 jobject jweb_contents); |
| 84 | 56 |
| (...skipping 23 matching lines...) Expand all Loading... |
| 108 | 80 |
| 109 // WebContentsObserver overrides. | 81 // WebContentsObserver overrides. |
| 110 void DidNavigateMainFrame( | 82 void DidNavigateMainFrame( |
| 111 const content::LoadCommittedDetails& details, | 83 const content::LoadCommittedDetails& details, |
| 112 const content::FrameNavigateParams& params) override; | 84 const content::FrameNavigateParams& params) override; |
| 113 void DidFinishLoad(content::RenderFrameHost* render_frame_host, | 85 void DidFinishLoad(content::RenderFrameHost* render_frame_host, |
| 114 const GURL& validated_url) override; | 86 const GURL& validated_url) override; |
| 115 bool OnMessageReceived(const IPC::Message& message) override; | 87 bool OnMessageReceived(const IPC::Message& message) override; |
| 116 | 88 |
| 117 private: | 89 private: |
| 118 // Gets the preferred icon size for the banner icons. | |
| 119 int GetPreferredIconSize(); | |
| 120 | |
| 121 // Called when the manifest has been retrieved, or if there is no manifest to | 90 // Called when the manifest has been retrieved, or if there is no manifest to |
| 122 // retrieve. | 91 // retrieve. |
| 123 void OnDidGetManifest(const content::Manifest& manifest); | 92 void OnDidGetManifest(const content::Manifest& manifest); |
| 124 | 93 |
| 125 // Called when the renderer has returned information about the meta tag. | 94 // Called when the renderer has returned information about the meta tag. |
| 126 // If there is some metadata for the play store tag, this kicks off the | 95 // If there is some metadata for the play store tag, this kicks off the |
| 127 // process of showing a banner for the package designated by |tag_content| on | 96 // process of showing a banner for the package designated by |tag_content| on |
| 128 // the page at the |expected_url|. | 97 // the page at the |expected_url|. |
| 129 void OnDidRetrieveMetaTagContent(bool success, | 98 void OnDidRetrieveMetaTagContent(bool success, |
| 130 const std::string& tag_name, | 99 const std::string& tag_name, |
| 131 const std::string& tag_content, | 100 const std::string& tag_content, |
| 132 const GURL& expected_url); | 101 const GURL& expected_url); |
| 133 | 102 |
| 134 // Called when the result of the CheckHasServiceWorker query has completed. | 103 // Called when the result of the CheckHasServiceWorker query has completed. |
| 135 void OnDidCheckHasServiceWorker(bool has_service_worker); | 104 void OnDidCheckHasServiceWorker(bool has_service_worker); |
| 136 | 105 |
| 137 // Record that the banner could be shown at this point, if the triggering | 106 // Record that the banner could be shown at this point, if the triggering |
| 138 // heuristic allowed. | 107 // heuristic allowed. |
| 139 void RecordCouldShowBanner(const std::string& package_or_start_url); | 108 void RecordCouldShowBanner(const std::string& package_or_start_url); |
| 140 | 109 |
| 141 // Check if the banner should be shown. | 110 // Check if the banner should be shown. |
| 142 bool CheckIfShouldShow(const std::string& package_or_start_url); | 111 bool CheckIfShouldShow(const std::string& package_or_start_url); |
| 143 | 112 |
| 144 // Cancels an active BitmapFetcher, stopping its banner from appearing. | 113 // Cancels an active BitmapFetcher, stopping its banner from appearing. |
| 145 void CancelActiveFetcher(); | 114 void CancelActiveFetcher(); |
| 146 | 115 |
| 116 // Icon size that we want to be use for the launcher. |
| 117 const int preferred_icon_size_; |
| 118 |
| 147 // Fetches the icon for an app. Weakly held because they delete themselves. | 119 // Fetches the icon for an app. Weakly held because they delete themselves. |
| 148 BannerBitmapFetcher* fetcher_; | 120 BannerBitmapFetcher* fetcher_; |
| 149 | 121 |
| 150 GURL validated_url_; | 122 GURL validated_url_; |
| 151 GURL app_icon_url_; | 123 GURL app_icon_url_; |
| 152 | 124 |
| 153 base::string16 app_title_; | 125 base::string16 app_title_; |
| 154 | 126 |
| 155 content::Manifest web_app_data_; | 127 content::Manifest web_app_data_; |
| 156 | 128 |
| (...skipping 10 matching lines...) Expand all Loading... |
| 167 | 139 |
| 168 DISALLOW_COPY_AND_ASSIGN(AppBannerManager); | 140 DISALLOW_COPY_AND_ASSIGN(AppBannerManager); |
| 169 }; // class AppBannerManager | 141 }; // class AppBannerManager |
| 170 | 142 |
| 171 // Register native methods | 143 // Register native methods |
| 172 bool RegisterAppBannerManager(JNIEnv* env); | 144 bool RegisterAppBannerManager(JNIEnv* env); |
| 173 | 145 |
| 174 } // namespace banners | 146 } // namespace banners |
| 175 | 147 |
| 176 #endif // CHROME_BROWSER_ANDROID_BANNERS_APP_BANNER_MANAGER_H_ | 148 #endif // CHROME_BROWSER_ANDROID_BANNERS_APP_BANNER_MANAGER_H_ |
| OLD | NEW |