| 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 | 9 |
| 10 #include "base/macros.h" | 10 #include "base/macros.h" |
| 11 #include "base/memory/ref_counted.h" | 11 #include "base/memory/ref_counted.h" |
| 12 #include "base/memory/weak_ptr.h" | 12 #include "base/memory/weak_ptr.h" |
| 13 #include "chrome/browser/banners/app_banner_data_fetcher.h" | 13 #include "chrome/browser/banners/app_banner_data_fetcher.h" |
| 14 #include "chrome/browser/engagement/site_engagement_observer.h" |
| 14 #include "content/public/browser/web_contents_observer.h" | 15 #include "content/public/browser/web_contents_observer.h" |
| 15 #include "third_party/WebKit/public/platform/modules/app_banner/WebAppBannerProm
ptReply.h" | 16 #include "third_party/WebKit/public/platform/modules/app_banner/WebAppBannerProm
ptReply.h" |
| 16 | 17 |
| 17 namespace content { | 18 namespace content { |
| 18 struct FrameNavigateParams; | 19 struct FrameNavigateParams; |
| 19 struct LoadCommittedDetails; | 20 struct LoadCommittedDetails; |
| 20 } // namespace content | 21 } // namespace content |
| 21 | 22 |
| 22 namespace banners { | 23 namespace banners { |
| 23 class AppBannerDataFetcher; | 24 class AppBannerDataFetcher; |
| 24 | 25 |
| 25 /** | 26 /** |
| 26 * Creates an app banner. | 27 * Creates an app banner. |
| 27 * | 28 * |
| 28 * Hooks the wiring together for getting the data for a particular app. | 29 * Hooks the wiring together for getting the data for a particular app. |
| 29 * Monitors at most one app at a time, tracking the info for the most recently | 30 * Monitors at most one app at a time, tracking the info for the most recently |
| 30 * requested app. Any work in progress for other apps is discarded. | 31 * requested app. Any work in progress for other apps is discarded. |
| 31 */ | 32 */ |
| 32 class AppBannerManager : public content::WebContentsObserver, | 33 class AppBannerManager : public content::WebContentsObserver, |
| 33 public AppBannerDataFetcher::Delegate { | 34 public AppBannerDataFetcher::Delegate, |
| 35 public SiteEngagementObserver { |
| 34 public: | 36 public: |
| 35 static void DisableSecureSchemeCheckForTesting(); | 37 static void DisableSecureSchemeCheckForTesting(); |
| 36 | 38 |
| 37 static void SetEngagementWeights(double direct_engagement, | 39 static void SetEngagementWeights(double direct_engagement, |
| 38 double indirect_engagement); | 40 double indirect_engagement); |
| 39 | 41 |
| 40 // Returns whether or not the URLs match for everything except for the ref. | 42 // Returns whether or not the URLs match for everything except for the ref. |
| 41 static bool URLsAreForTheSamePage(const GURL& first, const GURL& second); | 43 static bool URLsAreForTheSamePage(const GURL& first, const GURL& second); |
| 42 | 44 |
| 43 // Requests an app banner. Set |is_debug_mode| when it is triggered by the | 45 // Requests an app banner. Set |is_debug_mode| when it is triggered by the |
| 44 // developer's action in DevTools. | 46 // developer's action in DevTools. |
| 45 void RequestAppBanner(content::RenderFrameHost* render_frame_host, | 47 void RequestAppBanner(const GURL& validated_url, bool is_debug_mode); |
| 46 const GURL& validated_url, | |
| 47 bool is_debug_mode); | |
| 48 | 48 |
| 49 AppBannerManager(); | |
| 50 ~AppBannerManager() override; | 49 ~AppBannerManager() override; |
| 51 | 50 |
| 52 protected: | 51 protected: |
| 53 explicit AppBannerManager(content::WebContents* web_contents); | 52 explicit AppBannerManager(content::WebContents* web_contents); |
| 54 | 53 |
| 55 void ReplaceWebContents(content::WebContents* web_contents); | 54 void ReplaceWebContents(content::WebContents* web_contents); |
| 56 | 55 |
| 57 // Creates an AppBannerDataFetcher, which constructs an app banner. | 56 // Creates an AppBannerDataFetcher, which constructs an app banner. |
| 58 virtual AppBannerDataFetcher* CreateAppBannerDataFetcher( | 57 virtual AppBannerDataFetcher* CreateAppBannerDataFetcher( |
| 59 base::WeakPtr<AppBannerDataFetcher::Delegate> weak_delegate, | 58 base::WeakPtr<AppBannerDataFetcher::Delegate> weak_delegate, |
| 60 bool is_debug_mode) = 0; | 59 bool is_debug_mode) = 0; |
| 61 | 60 |
| 62 // Return whether the AppBannerDataFetcher is active. | 61 // Return whether the AppBannerDataFetcher is active. |
| 63 bool IsFetcherActive(); | 62 bool IsFetcherActive(); |
| 64 | 63 |
| 65 scoped_refptr<AppBannerDataFetcher> data_fetcher() { return data_fetcher_; } | 64 scoped_refptr<AppBannerDataFetcher> data_fetcher() { return data_fetcher_; } |
| 66 | 65 |
| 67 private: | 66 private: |
| 68 // WebContentsObserver overrides. | 67 // WebContentsObserver overrides. |
| 69 void DidNavigateMainFrame( | 68 void DidNavigateMainFrame( |
| 70 const content::LoadCommittedDetails& details, | 69 const content::LoadCommittedDetails& details, |
| 71 const content::FrameNavigateParams& params) override; | 70 const content::FrameNavigateParams& params) override; |
| 72 | 71 |
| 73 void DidFinishLoad(content::RenderFrameHost* render_frame_host, | 72 void DidFinishLoad(content::RenderFrameHost* render_frame_host, |
| 74 const GURL& validated_url) override; | 73 const GURL& validated_url) override; |
| 75 | 74 |
| 75 void WasShown() override; |
| 76 void WasHidden() override; |
| 77 |
| 76 // AppBannerDataFetcher::Delegate overrides. | 78 // AppBannerDataFetcher::Delegate overrides. |
| 77 bool HandleNonWebApp(const std::string& platform, | 79 bool HandleNonWebApp(const std::string& platform, |
| 78 const GURL& url, | 80 const GURL& url, |
| 79 const std::string& id, | 81 const std::string& id, |
| 80 bool is_debug_mode) override; | 82 bool is_debug_mode) override; |
| 81 | 83 |
| 84 // SiteEngagementObserver overrides. |
| 85 void OnEngagementIncreased(const SiteEngagementService* service, |
| 86 const GURL& url, |
| 87 double score) override; |
| 88 |
| 82 // Cancels an active DataFetcher, stopping its banners from appearing. | 89 // Cancels an active DataFetcher, stopping its banners from appearing. |
| 83 void CancelActiveFetcher(); | 90 void CancelActiveFetcher(); |
| 84 | 91 |
| 85 // The type of navigation made to the page | 92 // The type of navigation made to the page |
| 86 ui::PageTransition last_transition_type_; | 93 ui::PageTransition last_transition_type_; |
| 87 | 94 |
| 95 GURL validated_url_; |
| 96 |
| 97 bool is_visible_; |
| 98 |
| 88 // Fetches the data required to display a banner for the current page. | 99 // Fetches the data required to display a banner for the current page. |
| 89 scoped_refptr<AppBannerDataFetcher> data_fetcher_; | 100 scoped_refptr<AppBannerDataFetcher> data_fetcher_; |
| 90 | 101 |
| 91 // A weak pointer is used as the lifetime of the ServiceWorkerContext is | 102 // A weak pointer is used as the lifetime of the ServiceWorkerContext is |
| 92 // longer than the lifetime of this banner manager. The banner manager | 103 // longer than the lifetime of this banner manager. The banner manager |
| 93 // might be gone when calls sent to the ServiceWorkerContext are completed. | 104 // might be gone when calls sent to the ServiceWorkerContext are completed. |
| 94 base::WeakPtrFactory<AppBannerManager> weak_factory_; | 105 base::WeakPtrFactory<AppBannerManager> weak_factory_; |
| 95 | 106 |
| 96 DISALLOW_COPY_AND_ASSIGN(AppBannerManager); | 107 DISALLOW_COPY_AND_ASSIGN(AppBannerManager); |
| 97 }; // class AppBannerManager | 108 }; // class AppBannerManager |
| 98 | 109 |
| 99 } // namespace banners | 110 } // namespace banners |
| 100 | 111 |
| 101 #endif // CHROME_BROWSER_BANNERS_APP_BANNER_MANAGER_H_ | 112 #endif // CHROME_BROWSER_BANNERS_APP_BANNER_MANAGER_H_ |
| OLD | NEW |