Chromium Code Reviews| 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_DATA_FETCHER_H_ | 5 #ifndef CHROME_BROWSER_BANNERS_APP_BANNER_DATA_FETCHER_H_ |
| 6 #define CHROME_BROWSER_BANNERS_APP_BANNER_DATA_FETCHER_H_ | 6 #define CHROME_BROWSER_BANNERS_APP_BANNER_DATA_FETCHER_H_ |
| 7 | 7 |
| 8 #include "base/macros.h" | 8 #include "base/macros.h" |
| 9 #include "base/memory/ref_counted.h" | 9 #include "base/memory/ref_counted.h" |
| 10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 42 bool will_show) = 0; | 42 bool will_show) = 0; |
| 43 virtual void OnFetcherDestroyed(AppBannerDataFetcher* fetcher) = 0; | 43 virtual void OnFetcherDestroyed(AppBannerDataFetcher* fetcher) = 0; |
| 44 }; | 44 }; |
| 45 | 45 |
| 46 class Delegate { | 46 class Delegate { |
| 47 public: | 47 public: |
| 48 // Called to handle a non-web app. Returns |true| if the non-web app can be | 48 // Called to handle a non-web app. Returns |true| if the non-web app can be |
| 49 // handled, and the fetcher needs to remain active and wait for a callback. | 49 // handled, and the fetcher needs to remain active and wait for a callback. |
| 50 virtual bool HandleNonWebApp(const std::string& platform, | 50 virtual bool HandleNonWebApp(const std::string& platform, |
| 51 const GURL& url, | 51 const GURL& url, |
| 52 const std::string& id) = 0; | 52 const std::string& id, |
| 53 bool is_debug_mode) = 0; | |
| 53 }; | 54 }; |
| 54 | 55 |
| 55 // Returns the current time. | 56 // Returns the current time. |
| 56 static base::Time GetCurrentTime(); | 57 static base::Time GetCurrentTime(); |
| 57 | 58 |
| 58 // Fast-forwards the current time for testing. | 59 // Fast-forwards the current time for testing. |
| 59 static void SetTimeDeltaForTesting(int days); | 60 static void SetTimeDeltaForTesting(int days); |
| 60 | 61 |
| 61 AppBannerDataFetcher(content::WebContents* web_contents, | 62 AppBannerDataFetcher(content::WebContents* web_contents, |
| 62 base::WeakPtr<Delegate> weak_delegate, | 63 base::WeakPtr<Delegate> weak_delegate, |
| 63 int ideal_icon_size_in_dp, | 64 int ideal_icon_size_in_dp, |
| 64 int minimum_icon_size_in_dp); | 65 int minimum_icon_size_in_dp, |
| 66 bool is_debug_mode); | |
| 65 | 67 |
| 66 // Begins creating a banner for the URL being displayed by the Delegate's | 68 // Begins creating a banner for the URL being displayed by the Delegate's |
| 67 // WebContents. | 69 // WebContents. |
| 68 void Start(const GURL& validated_url, ui::PageTransition transition_type); | 70 void Start(const GURL& validated_url, ui::PageTransition transition_type); |
| 69 | 71 |
| 70 // Stops the pipeline when any asynchronous calls return. | 72 // Stops the pipeline when any asynchronous calls return. |
| 71 void Cancel(); | 73 void Cancel(); |
| 72 | 74 |
| 73 // Replaces the WebContents that is being observed. | 75 // Replaces the WebContents that is being observed. |
| 74 void ReplaceWebContents(content::WebContents* web_contents); | 76 void ReplaceWebContents(content::WebContents* web_contents); |
| 75 | 77 |
| 76 // Adds an observer to the list. | 78 // Adds an observer to the list. |
| 77 void AddObserverForTesting(Observer* observer); | 79 void AddObserverForTesting(Observer* observer); |
| 78 | 80 |
| 79 // Removes an observer from the list. | 81 // Removes an observer from the list. |
| 80 void RemoveObserverForTesting(Observer* observer); | 82 void RemoveObserverForTesting(Observer* observer); |
| 81 | 83 |
| 82 // Returns whether or not the pipeline has been stopped. | 84 // Returns whether or not the pipeline has been stopped. |
| 83 bool is_active() { return is_active_; } | 85 bool is_active() { return is_active_; } |
| 84 | 86 |
| 85 // Returns whether the beforeinstallprompt Javascript event was canceled. | 87 // Returns whether the beforeinstallprompt Javascript event was canceled. |
| 86 bool was_canceled_by_page() { return was_canceled_by_page_; } | 88 bool was_canceled_by_page() { return was_canceled_by_page_; } |
| 87 | 89 |
| 88 // Returns whether the page has validly requested that the banner be shown | 90 // Returns whether the page has validly requested that the banner be shown |
| 89 // by calling prompt() on the beforeinstallprompt Javascript event. | 91 // by calling prompt() on the beforeinstallprompt Javascript event. |
| 90 bool page_requested_prompt() { return page_requested_prompt_; } | 92 bool page_requested_prompt() { return page_requested_prompt_; } |
| 91 | 93 |
| 94 // Returns whether it was created by the user action in DevTools. | |
|
gone
2016/01/19 18:35:00
nit: This is inaccurate. You || the devtools chec
horo
2016/01/20 02:26:34
Done.
| |
| 95 bool is_debug_mode() const { return is_debug_mode_; } | |
| 96 | |
| 92 // Returns the type of transition which triggered this fetch. | 97 // Returns the type of transition which triggered this fetch. |
| 93 ui::PageTransition transition_type() { return transition_type_; } | 98 ui::PageTransition transition_type() { return transition_type_; } |
| 94 | 99 |
| 95 // Returns the URL that kicked off the banner data retrieval. | 100 // Returns the URL that kicked off the banner data retrieval. |
| 96 const GURL& validated_url() { return validated_url_; } | 101 const GURL& validated_url() { return validated_url_; } |
| 97 | 102 |
| 98 // WebContentsObserver overrides. | 103 // WebContentsObserver overrides. |
| 99 void WebContentsDestroyed() override; | 104 void WebContentsDestroyed() override; |
| 100 void DidNavigateMainFrame( | 105 void DidNavigateMainFrame( |
| 101 const content::LoadCommittedDetails& details, | 106 const content::LoadCommittedDetails& details, |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 165 // Returns whether the banner should be shown. | 170 // Returns whether the banner should be shown. |
| 166 bool CheckIfShouldShowBanner(); | 171 bool CheckIfShouldShowBanner(); |
| 167 | 172 |
| 168 // Returns whether the fetcher is active and web contents have not been | 173 // Returns whether the fetcher is active and web contents have not been |
| 169 // closed. | 174 // closed. |
| 170 bool CheckFetcherIsStillAlive(content::WebContents* web_contents); | 175 bool CheckFetcherIsStillAlive(content::WebContents* web_contents); |
| 171 | 176 |
| 172 // Returns whether the given Manifest is following the requirements to show | 177 // Returns whether the given Manifest is following the requirements to show |
| 173 // a web app banner. | 178 // a web app banner. |
| 174 static bool IsManifestValidForWebApp(const content::Manifest& manifest, | 179 static bool IsManifestValidForWebApp(const content::Manifest& manifest, |
| 175 content::WebContents* web_contents); | 180 content::WebContents* web_contents, |
| 181 bool is_debug_mode); | |
| 176 | 182 |
| 177 const base::WeakPtr<Delegate> weak_delegate_; | 183 const base::WeakPtr<Delegate> weak_delegate_; |
| 178 const int ideal_icon_size_in_dp_; | 184 const int ideal_icon_size_in_dp_; |
| 179 const int minimum_icon_size_in_dp_; | 185 const int minimum_icon_size_in_dp_; |
| 180 base::ObserverList<Observer> observer_list_; | 186 base::ObserverList<Observer> observer_list_; |
| 181 bool is_active_; | 187 bool is_active_; |
| 182 bool was_canceled_by_page_; | 188 bool was_canceled_by_page_; |
| 183 bool page_requested_prompt_; | 189 bool page_requested_prompt_; |
| 190 const bool is_debug_mode_; | |
| 184 ui::PageTransition transition_type_; | 191 ui::PageTransition transition_type_; |
| 185 int event_request_id_; | 192 int event_request_id_; |
| 186 scoped_ptr<SkBitmap> app_icon_; | 193 scoped_ptr<SkBitmap> app_icon_; |
| 187 std::string referrer_; | 194 std::string referrer_; |
| 188 | 195 |
| 189 GURL validated_url_; | 196 GURL validated_url_; |
| 190 base::string16 app_title_; | 197 base::string16 app_title_; |
| 191 content::Manifest web_app_data_; | 198 content::Manifest web_app_data_; |
| 192 | 199 |
| 193 friend struct content::BrowserThread::DeleteOnThread< | 200 friend struct content::BrowserThread::DeleteOnThread< |
| 194 content::BrowserThread::UI>; | 201 content::BrowserThread::UI>; |
| 195 friend class base::DeleteHelper<AppBannerDataFetcher>; | 202 friend class base::DeleteHelper<AppBannerDataFetcher>; |
| 196 friend class AppBannerDataFetcherUnitTest; | 203 friend class AppBannerDataFetcherUnitTest; |
| 197 friend class base::RefCounted<AppBannerDataFetcher>; | 204 friend class base::RefCounted<AppBannerDataFetcher>; |
| 198 DISALLOW_COPY_AND_ASSIGN(AppBannerDataFetcher); | 205 DISALLOW_COPY_AND_ASSIGN(AppBannerDataFetcher); |
| 199 }; | 206 }; |
| 200 | 207 |
| 201 } // namespace banners | 208 } // namespace banners |
| 202 | 209 |
| 203 #endif // CHROME_BROWSER_BANNERS_APP_BANNER_DATA_FETCHER_H_ | 210 #endif // CHROME_BROWSER_BANNERS_APP_BANNER_DATA_FETCHER_H_ |
| OLD | NEW |