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); |
(...skipping 13 matching lines...) Expand all Loading... | |
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 |
92 // Returns the type of transition which triggered this fetch. | 94 // Returns the type of transition which triggered this fetch. |
93 ui::PageTransition transition_type() { return transition_type_; } | 95 ui::PageTransition transition_type() { return transition_type_; } |
94 | 96 |
95 // Returns the URL that kicked off the banner data retrieval. | 97 // Returns the URL that kicked off the banner data retrieval. |
96 const GURL& validated_url() { return validated_url_; } | 98 const GURL& validated_url() { return validated_url_; } |
97 | 99 |
100 // Returns whether it was created by the user action in DevTools. | |
101 bool is_debug_mode() const { return is_debug_mode_; } | |
dominickn
2016/01/17 23:20:18
Nit: after reordering, please place this following
horo
2016/01/18 06:28:56
Done.
| |
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, |
102 const content::FrameNavigateParams& params) override; | 107 const content::FrameNavigateParams& params) override; |
103 bool OnMessageReceived(const IPC::Message& message, | 108 bool OnMessageReceived(const IPC::Message& message, |
104 content::RenderFrameHost* render_frame_host) override; | 109 content::RenderFrameHost* render_frame_host) override; |
105 | 110 |
106 protected: | 111 protected: |
107 ~AppBannerDataFetcher() override; | 112 ~AppBannerDataFetcher() override; |
(...skipping 57 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_; |
184 ui::PageTransition transition_type_; | 190 ui::PageTransition transition_type_; |
185 int event_request_id_; | 191 int event_request_id_; |
186 scoped_ptr<SkBitmap> app_icon_; | 192 scoped_ptr<SkBitmap> app_icon_; |
187 std::string referrer_; | 193 std::string referrer_; |
188 | 194 |
189 GURL validated_url_; | 195 GURL validated_url_; |
190 base::string16 app_title_; | 196 base::string16 app_title_; |
191 content::Manifest web_app_data_; | 197 content::Manifest web_app_data_; |
198 const bool is_debug_mode_; | |
dominickn
2016/01/17 23:20:18
Nit: please put this below page_requested_prompt s
horo
2016/01/18 06:28:56
Done.
| |
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 |