| 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 "base/memory/ref_counted.h" | 8 #include "base/memory/ref_counted.h" |
| 9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
| 10 #include "base/memory/weak_ptr.h" | 10 #include "base/memory/weak_ptr.h" |
| 11 #include "chrome/browser/banners/app_banner_data_fetcher.h" | 11 #include "chrome/browser/banners/app_banner_data_fetcher.h" |
| 12 #include "content/public/browser/web_contents_observer.h" | 12 #include "content/public/browser/web_contents_observer.h" |
| 13 #include "content/public/browser/web_contents_user_data.h" |
| 13 #include "third_party/WebKit/public/platform/modules/app_banner/WebAppBannerProm
ptReply.h" | 14 #include "third_party/WebKit/public/platform/modules/app_banner/WebAppBannerProm
ptReply.h" |
| 14 | 15 |
| 15 namespace content { | 16 namespace content { |
| 16 struct FrameNavigateParams; | 17 struct FrameNavigateParams; |
| 17 struct LoadCommittedDetails; | 18 struct LoadCommittedDetails; |
| 18 } // namespace content | 19 } // namespace content |
| 19 | 20 |
| 20 namespace banners { | 21 namespace banners { |
| 21 class AppBannerDataFetcher; | 22 class AppBannerDataFetcher; |
| 22 | 23 |
| 23 /** | 24 /** |
| 24 * Creates an app banner. | 25 * Creates an app banner. |
| 25 * | 26 * |
| 26 * Hooks the wiring together for getting the data for a particular app. | 27 * Hooks the wiring together for getting the data for a particular app. |
| 27 * Monitors at most one app at a time, tracking the info for the most recently | 28 * Monitors at most one app at a time, tracking the info for the most recently |
| 28 * requested app. Any work in progress for other apps is discarded. | 29 * requested app. Any work in progress for other apps is discarded. |
| 29 */ | 30 */ |
| 30 class AppBannerManager : public content::WebContentsObserver, | 31 class AppBannerManager : public content::WebContentsObserver, |
| 31 public AppBannerDataFetcher::Delegate { | 32 public AppBannerDataFetcher::Delegate, |
| 33 public content::WebContentsUserData<AppBannerManager> { |
| 32 public: | 34 public: |
| 33 static bool IsEnabled(); | 35 static bool IsEnabled(); |
| 34 static void DisableSecureSchemeCheckForTesting(); | 36 static void DisableSecureSchemeCheckForTesting(); |
| 35 | 37 |
| 36 // Returns whether or not the URLs match for everything except for the ref. | 38 // Returns whether or not the URLs match for everything except for the ref. |
| 37 static bool URLsAreForTheSamePage(const GURL& first, const GURL& second); | 39 static bool URLsAreForTheSamePage(const GURL& first, const GURL& second); |
| 38 | 40 |
| 39 explicit AppBannerManager(int icon_size); | 41 explicit AppBannerManager(int icon_size); |
| 40 ~AppBannerManager() override; | 42 ~AppBannerManager() override; |
| 41 | 43 |
| 42 // WebContentsObserver overrides. | 44 // WebContentsObserver overrides. |
| 43 void DidFinishLoad(content::RenderFrameHost* render_frame_host, | 45 void DidFinishLoad(content::RenderFrameHost* render_frame_host, |
| 44 const GURL& validated_url) override; | 46 const GURL& validated_url) override; |
| 45 | 47 |
| 46 protected: | 48 protected: |
| 47 void ReplaceWebContents(content::WebContents* web_contents); | 49 void ReplaceWebContents(content::WebContents* web_contents); |
| 48 | 50 |
| 49 // Creates an AppBannerDataFetcher, which constructs an app banner. | 51 // Creates an AppBannerDataFetcher, which constructs an app banner. |
| 50 virtual AppBannerDataFetcher* CreateAppBannerDataFetcher( | 52 virtual AppBannerDataFetcher* CreateAppBannerDataFetcher( |
| 51 base::WeakPtr<AppBannerDataFetcher::Delegate> weak_delegate, | 53 base::WeakPtr<AppBannerDataFetcher::Delegate> weak_delegate, |
| 52 const int ideal_icon_size); | 54 const int ideal_icon_size); |
| 53 | 55 |
| 54 // Return whether the AppBannerDataFetcher is active. | 56 // Return whether the AppBannerDataFetcher is active. |
| 55 bool IsFetcherActive(); | 57 bool IsFetcherActive(); |
| 56 | 58 |
| 57 scoped_refptr<AppBannerDataFetcher> data_fetcher() { return data_fetcher_; } | 59 scoped_refptr<AppBannerDataFetcher> data_fetcher() { return data_fetcher_; } |
| 58 int ideal_icon_size() { return ideal_icon_size_; } | 60 int ideal_icon_size() { return ideal_icon_size_; } |
| 59 | 61 |
| 60 private: | 62 private: |
| 63 explicit AppBannerManager(content::WebContents* web_contents); |
| 64 friend class content::WebContentsUserData<AppBannerManager>; |
| 65 |
| 61 // AppBannerDataFetcher::Delegate overrides. | 66 // AppBannerDataFetcher::Delegate overrides. |
| 62 bool HandleNonWebApp(const std::string& platform, | 67 bool HandleNonWebApp(const std::string& platform, |
| 63 const GURL& url, | 68 const GURL& url, |
| 64 const std::string& id) override; | 69 const std::string& id) override; |
| 65 | 70 |
| 66 // Called after the manager sends a message to the renderer regarding its | 71 // Called after the manager sends a message to the renderer regarding its |
| 67 // intention to show a prompt. The renderer will send a message back with the | 72 // intention to show a prompt. The renderer will send a message back with the |
| 68 // opportunity to cancel. | 73 // opportunity to cancel. |
| 69 void OnBannerPromptReply(content::RenderFrameHost* render_frame_host, | 74 void OnBannerPromptReply(content::RenderFrameHost* render_frame_host, |
| 70 int request_id, | 75 int request_id, |
| (...skipping 12 matching lines...) Expand all Loading... |
| 83 // longer than the lifetime of this banner manager. The banner manager | 88 // longer than the lifetime of this banner manager. The banner manager |
| 84 // might be gone when calls sent to the ServiceWorkerContext are completed. | 89 // might be gone when calls sent to the ServiceWorkerContext are completed. |
| 85 base::WeakPtrFactory<AppBannerManager> weak_factory_; | 90 base::WeakPtrFactory<AppBannerManager> weak_factory_; |
| 86 | 91 |
| 87 DISALLOW_COPY_AND_ASSIGN(AppBannerManager); | 92 DISALLOW_COPY_AND_ASSIGN(AppBannerManager); |
| 88 }; // class AppBannerManager | 93 }; // class AppBannerManager |
| 89 | 94 |
| 90 } // namespace banners | 95 } // namespace banners |
| 91 | 96 |
| 92 #endif // CHROME_BROWSER_BANNERS_APP_BANNER_MANAGER_H_ | 97 #endif // CHROME_BROWSER_BANNERS_APP_BANNER_MANAGER_H_ |
| OLD | NEW |