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 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
60 * app we retrieved the details for is still for the page that requested it. | 60 * app we retrieved the details for is still for the page that requested it. |
61 * | 61 * |
62 * Because of the asynchronous nature of this pipeline, it's entirely possible | 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 | 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 | 64 * Java side manages what happens in these situations, which will usually result |
65 * in dropping the old banner request on the floor. | 65 * in dropping the old banner request on the floor. |
66 */ | 66 */ |
67 | 67 |
68 namespace banners { | 68 namespace banners { |
69 | 69 |
70 class AppBannerManager : public chrome::BitmapFetcherDelegate, | 70 class AppBannerManager : public content::WebContentsObserver { |
71 public content::WebContentsObserver { | 71 class BannerBitmapFetcher; |
benwells
2015/02/18 06:01:18
This should be after 'public:', if it has to be pu
gone
2015/02/18 18:33:29
Couldn't put it under private because it's referen
| |
72 | |
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 |
97 // Return how many fetchers are active. | 98 // Called when everything required to show a banner is ready. |
98 int GetNumActiveFetchers(JNIEnv* env, jobject jobj); | 99 void OnFetchComplete(BannerBitmapFetcher* fetcher, |
100 const GURL url, | |
101 const SkBitmap* icon); | |
102 | |
103 // Return whether a BitmapFetcher is active. | |
104 bool IsFetcherActive(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 // Cancels an active BitmapFetcher, stopping its banner from appearing. |
142 scoped_ptr<chrome::BitmapFetcher> fetcher_; | 145 void CancelActiveFetcher(); |
146 | |
147 // Fetches the icon for an app. Weakly held because they delete themselves. | |
148 BannerBitmapFetcher* fetcher_; | |
149 | |
143 GURL validated_url_; | 150 GURL validated_url_; |
144 GURL app_icon_url_; | 151 GURL app_icon_url_; |
145 | 152 |
146 base::string16 app_title_; | 153 base::string16 app_title_; |
147 | 154 |
148 content::Manifest web_app_data_; | 155 content::Manifest web_app_data_; |
149 | 156 |
150 base::android::ScopedJavaGlobalRef<jobject> native_app_data_; | 157 base::android::ScopedJavaGlobalRef<jobject> native_app_data_; |
151 std::string native_app_package_; | 158 std::string native_app_package_; |
152 | 159 |
153 // AppBannerManager on the Java side. | 160 // AppBannerManager on the Java side. |
154 JavaObjectWeakGlobalRef weak_java_banner_view_manager_; | 161 JavaObjectWeakGlobalRef weak_java_banner_view_manager_; |
155 | 162 |
156 // A weak pointer is used as the lifetime of the ServiceWorkerContext is | 163 // A weak pointer is used as the lifetime of the ServiceWorkerContext is |
157 // longer than the lifetime of this banner manager. The banner manager | 164 // longer than the lifetime of this banner manager. The banner manager |
158 // might be gone when calls sent to the ServiceWorkerContext are completed. | 165 // might be gone when calls sent to the ServiceWorkerContext are completed. |
159 base::WeakPtrFactory<AppBannerManager> weak_factory_; | 166 base::WeakPtrFactory<AppBannerManager> weak_factory_; |
160 | 167 |
161 DISALLOW_COPY_AND_ASSIGN(AppBannerManager); | 168 DISALLOW_COPY_AND_ASSIGN(AppBannerManager); |
162 }; // class AppBannerManager | 169 }; // class AppBannerManager |
163 | 170 |
164 // Register native methods | 171 // Register native methods |
165 bool RegisterAppBannerManager(JNIEnv* env); | 172 bool RegisterAppBannerManager(JNIEnv* env); |
166 | 173 |
167 } // namespace banners | 174 } // namespace banners |
168 | 175 |
169 #endif // CHROME_BROWSER_ANDROID_BANNERS_APP_BANNER_MANAGER_H_ | 176 #endif // CHROME_BROWSER_ANDROID_BANNERS_APP_BANNER_MANAGER_H_ |
OLD | NEW |