| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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_BANNERS_APP_BANNER_MANAGER_H_ | 5 #ifndef CHROME_BROWSER_BANNERS_APP_BANNER_MANAGER_H_ |
| 6 #define CHROME_BROWSER_BANNERS_APP_BANNER_MANAGER_H_ | 6 #define CHROME_BROWSER_BANNERS_APP_BANNER_MANAGER_H_ |
| 7 | 7 |
| 8 #include <memory> | 8 #include <memory> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 87 const extensions::Extension* extension, | 87 const extensions::Extension* extension, |
| 88 const WebApplicationInfo& web_app_info) {} | 88 const WebApplicationInfo& web_app_info) {} |
| 89 | 89 |
| 90 // Overridden and passed through base::Bind on Android. Called when the | 90 // Overridden and passed through base::Bind on Android. Called when the |
| 91 // download of a native app's icon is complete, as native banners use an icon | 91 // download of a native app's icon is complete, as native banners use an icon |
| 92 // provided from the Play Store rather than the web manifest. Not used on | 92 // provided from the Play Store rather than the web manifest. Not used on |
| 93 // desktop platforms. | 93 // desktop platforms. |
| 94 virtual void OnAppIconFetched(const SkBitmap& bitmap) {} | 94 virtual void OnAppIconFetched(const SkBitmap& bitmap) {} |
| 95 | 95 |
| 96 protected: | 96 protected: |
| 97 enum class State { |
| 98 // The banner pipeline has not yet been triggered for this page load. |
| 99 INACTIVE, |
| 100 |
| 101 // The banner pipeline is currently running for this page load. |
| 102 ACTIVE, |
| 103 |
| 104 // The banner pipeline has finished running, but is waiting for sufficient |
| 105 // engagement to trigger the banner. |
| 106 PENDING_ENGAGEMENT, |
| 107 |
| 108 // The banner pipeline has finished running, but is waiting for an event to |
| 109 // trigger the banner. |
| 110 PENDING_EVENT, |
| 111 |
| 112 // The banner pipeline has finished running for this page load and no more |
| 113 // processing is to be done. |
| 114 COMPLETE, |
| 115 }; |
| 116 |
| 97 explicit AppBannerManager(content::WebContents* web_contents); | 117 explicit AppBannerManager(content::WebContents* web_contents); |
| 98 ~AppBannerManager() override; | 118 ~AppBannerManager() override; |
| 99 | 119 |
| 100 // Returns true if the banner should be shown. Returns false if the banner has | 120 // Returns true if the banner should be shown. Returns false if the banner has |
| 101 // been shown too recently, or if the app has already been installed. | 121 // been shown too recently, or if the app has already been installed. |
| 102 // GetAppIdentifier() must return a valid value for this method to work. | 122 // GetAppIdentifier() must return a valid value for this method to work. |
| 103 bool CheckIfShouldShowBanner(); | 123 bool CheckIfShouldShowBanner(); |
| 104 | 124 |
| 105 // Return a string identifying this app for metrics. | 125 // Return a string identifying this app for metrics. |
| 106 virtual std::string GetAppIdentifier(); | 126 virtual std::string GetAppIdentifier(); |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 164 // Stops the banner pipeline, preventing any outstanding callbacks from | 184 // Stops the banner pipeline, preventing any outstanding callbacks from |
| 165 // running and resetting the manager state. This method is virtual to allow | 185 // running and resetting the manager state. This method is virtual to allow |
| 166 // tests to intercept it and verify correct behaviour. | 186 // tests to intercept it and verify correct behaviour. |
| 167 virtual void Stop(); | 187 virtual void Stop(); |
| 168 | 188 |
| 169 // Sends a message to the renderer that the page has met the requirements to | 189 // Sends a message to the renderer that the page has met the requirements to |
| 170 // show a banner. The page can respond to cancel the banner (and possibly | 190 // show a banner. The page can respond to cancel the banner (and possibly |
| 171 // display it later), or otherwise allow it to be shown. | 191 // display it later), or otherwise allow it to be shown. |
| 172 void SendBannerPromptRequest(); | 192 void SendBannerPromptRequest(); |
| 173 | 193 |
| 194 // Updates the current state to |state|. Virtual to allow overriding in tests. |
| 195 virtual void UpdateState(State state); |
| 196 |
| 174 // content::WebContentsObserver overrides. | 197 // content::WebContentsObserver overrides. |
| 175 void DidStartNavigation(content::NavigationHandle* handle) override; | 198 void DidStartNavigation(content::NavigationHandle* handle) override; |
| 176 void DidFinishNavigation(content::NavigationHandle* handle) override; | 199 void DidFinishNavigation(content::NavigationHandle* handle) override; |
| 177 void DidFinishLoad(content::RenderFrameHost* render_frame_host, | 200 void DidFinishLoad(content::RenderFrameHost* render_frame_host, |
| 178 const GURL& validated_url) override; | 201 const GURL& validated_url) override; |
| 179 void MediaStartedPlaying(const MediaPlayerInfo& media_info, | 202 void MediaStartedPlaying(const MediaPlayerInfo& media_info, |
| 180 const MediaPlayerId& id) override; | 203 const MediaPlayerId& id) override; |
| 181 void MediaStoppedPlaying(const MediaPlayerInfo& media_info, | 204 void MediaStoppedPlaying(const MediaPlayerInfo& media_info, |
| 182 const MediaPlayerId& id) override; | 205 const MediaPlayerId& id) override; |
| 183 void WebContentsDestroyed() override; | 206 void WebContentsDestroyed() override; |
| 184 | 207 |
| 185 // SiteEngagementObserver overrides. | 208 // SiteEngagementObserver overrides. |
| 186 void OnEngagementIncreased(content::WebContents* web_contents, | 209 void OnEngagementIncreased(content::WebContents* web_contents, |
| 187 const GURL& url, | 210 const GURL& url, |
| 188 double score) override; | 211 double score) override; |
| 189 | 212 |
| 190 // Subclass accessors for private fields which should not be changed outside | 213 // Subclass accessors for private fields which should not be changed outside |
| 191 // this class. | 214 // this class. |
| 192 InstallableManager* manager() const { return manager_; } | 215 InstallableManager* manager() const { return manager_; } |
| 193 int event_request_id() const { return event_request_id_; } | 216 int event_request_id() const { return event_request_id_; } |
| 194 bool is_active() const { return is_active_; } | 217 bool is_active() const { return state_ == State::ACTIVE; } |
| 218 bool is_active_or_pending() const { |
| 219 return state_ == State::ACTIVE || state_ == State::PENDING_ENGAGEMENT || |
| 220 state_ == State::PENDING_EVENT; |
| 221 } |
| 222 bool is_complete() const { return state_ == State::COMPLETE; } |
| 223 bool is_pending_engagement() const { |
| 224 return state_ == State::PENDING_ENGAGEMENT; |
| 225 } |
| 226 bool is_pending_event() const { |
| 227 return state_ == State::PENDING_EVENT || page_requested_prompt_; |
| 228 } |
| 195 | 229 |
| 196 // The title to display in the banner. | 230 // The title to display in the banner. |
| 197 base::string16 app_title_; | 231 base::string16 app_title_; |
| 198 | 232 |
| 199 // The URL for which the banner check is being conducted. | 233 // The URL for which the banner check is being conducted. |
| 200 GURL validated_url_; | 234 GURL validated_url_; |
| 201 | 235 |
| 202 // The URL of the manifest. | 236 // The URL of the manifest. |
| 203 GURL manifest_url_; | 237 GURL manifest_url_; |
| 204 | 238 |
| 205 // The manifest object. | 239 // The manifest object. |
| 206 content::Manifest manifest_; | 240 content::Manifest manifest_; |
| 207 | 241 |
| 208 // The URL of the primary icon. | 242 // The URL of the primary icon. |
| 209 GURL primary_icon_url_; | 243 GURL primary_icon_url_; |
| 210 | 244 |
| 211 // The primary icon object. | 245 // The primary icon object. |
| 212 std::unique_ptr<SkBitmap> primary_icon_; | 246 std::unique_ptr<SkBitmap> primary_icon_; |
| 213 | 247 |
| 214 // The referrer string (if any) specified in the app URL. Used only for native | 248 // The referrer string (if any) specified in the app URL. Used only for native |
| 215 // app banners. | 249 // app banners. |
| 216 std::string referrer_; | 250 std::string referrer_; |
| 217 | 251 |
| 252 // The current banner pipeline state for this page load. |
| 253 State state_; |
| 254 |
| 218 private: | 255 private: |
| 219 friend class AppBannerManagerTest; | 256 friend class AppBannerManagerTest; |
| 220 | 257 |
| 221 // Record that the banner could be shown at this point, if the triggering | 258 // Record that the banner could be shown at this point, if the triggering |
| 222 // heuristic allowed. | 259 // heuristic allowed. |
| 223 void RecordCouldShowBanner(); | 260 void RecordCouldShowBanner(); |
| 224 | 261 |
| 225 // Creates a banner for the app. Overridden by subclasses as the infobar is | 262 // Creates a banner for the app. Overridden by subclasses as the infobar is |
| 226 // platform-specific. | 263 // platform-specific. |
| 227 virtual void ShowBanner() = 0; | 264 virtual void ShowBanner() = 0; |
| (...skipping 19 matching lines...) Expand all Loading... |
| 247 // We do not want to trigger a banner when the manager is attached to | 284 // We do not want to trigger a banner when the manager is attached to |
| 248 // a WebContents that is playing video. Banners triggering on a site in the | 285 // a WebContents that is playing video. Banners triggering on a site in the |
| 249 // background will appear when the tab is reactivated. | 286 // background will appear when the tab is reactivated. |
| 250 std::vector<MediaPlayerId> active_media_players_; | 287 std::vector<MediaPlayerId> active_media_players_; |
| 251 | 288 |
| 252 // Mojo bindings and interface pointers. | 289 // Mojo bindings and interface pointers. |
| 253 mojo::Binding<blink::mojom::AppBannerService> binding_; | 290 mojo::Binding<blink::mojom::AppBannerService> binding_; |
| 254 blink::mojom::AppBannerEventPtr event_; | 291 blink::mojom::AppBannerEventPtr event_; |
| 255 blink::mojom::AppBannerControllerPtr controller_; | 292 blink::mojom::AppBannerControllerPtr controller_; |
| 256 | 293 |
| 257 // Whether we are currently working on whether to show a banner. | |
| 258 bool is_active_; | |
| 259 | |
| 260 // If a banner is requested before the page has finished loading, defer | 294 // If a banner is requested before the page has finished loading, defer |
| 261 // triggering the pipeline until the load is complete. | 295 // triggering the pipeline until the load is complete. |
| 262 bool banner_request_queued_; | 296 bool has_sufficient_engagement_; |
| 263 bool load_finished_; | 297 bool load_finished_; |
| 264 | 298 |
| 265 // Record whether the page decides to defer showing the banner, and if it | 299 // Record whether the page requests for a banner to be shown later on. |
| 266 // requests for it to be shown later on. | |
| 267 bool was_canceled_by_page_; | |
| 268 bool page_requested_prompt_; | 300 bool page_requested_prompt_; |
| 269 | 301 |
| 270 // Whether we should be logging errors to the console for this request. | 302 // Whether we should be logging errors to the console for this request. |
| 271 bool is_debug_mode_; | 303 bool is_debug_mode_; |
| 272 | 304 |
| 273 // Whether the installable status has been logged for this run. | 305 // Whether the installable status has been logged for this run. |
| 274 bool need_to_log_status_; | 306 bool need_to_log_status_; |
| 275 | 307 |
| 276 // The concrete subclasses of this class are expected to have their lifetimes | 308 // The concrete subclasses of this class are expected to have their lifetimes |
| 277 // scoped to the WebContents which they are observing. This allows us to use | 309 // scoped to the WebContents which they are observing. This allows us to use |
| 278 // weak pointers for callbacks. | 310 // weak pointers for callbacks. |
| 279 base::WeakPtrFactory<AppBannerManager> weak_factory_; | 311 base::WeakPtrFactory<AppBannerManager> weak_factory_; |
| 280 | 312 |
| 281 DISALLOW_COPY_AND_ASSIGN(AppBannerManager); | 313 DISALLOW_COPY_AND_ASSIGN(AppBannerManager); |
| 282 }; | 314 }; |
| 283 | 315 |
| 284 } // namespace banners | 316 } // namespace banners |
| 285 | 317 |
| 286 #endif // CHROME_BROWSER_BANNERS_APP_BANNER_MANAGER_H_ | 318 #endif // CHROME_BROWSER_BANNERS_APP_BANNER_MANAGER_H_ |
| OLD | NEW |