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/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" |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
50 }; | 50 }; |
51 | 51 |
52 // Returns the current time. | 52 // Returns the current time. |
53 static base::Time GetCurrentTime(); | 53 static base::Time GetCurrentTime(); |
54 | 54 |
55 // Fast-forwards the current time for testing. | 55 // Fast-forwards the current time for testing. |
56 static void SetTimeDeltaForTesting(int days); | 56 static void SetTimeDeltaForTesting(int days); |
57 | 57 |
58 AppBannerDataFetcher(content::WebContents* web_contents, | 58 AppBannerDataFetcher(content::WebContents* web_contents, |
59 base::WeakPtr<Delegate> weak_delegate, | 59 base::WeakPtr<Delegate> weak_delegate, |
60 int ideal_icon_size); | 60 int ideal_icon_size_in_dp); |
61 | 61 |
62 // Begins creating a banner for the URL being displayed by the Delegate's | 62 // Begins creating a banner for the URL being displayed by the Delegate's |
63 // WebContents. | 63 // WebContents. |
64 void Start(const GURL& validated_url, ui::PageTransition transition_type); | 64 void Start(const GURL& validated_url, ui::PageTransition transition_type); |
65 | 65 |
66 // Stops the pipeline when any asynchronous calls return. | 66 // Stops the pipeline when any asynchronous calls return. |
67 void Cancel(); | 67 void Cancel(); |
68 | 68 |
69 // Replaces the WebContents that is being observed. | 69 // Replaces the WebContents that is being observed. |
70 void ReplaceWebContents(content::WebContents* web_contents); | 70 void ReplaceWebContents(content::WebContents* web_contents); |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
112 void OnBannerPromptReply(content::RenderFrameHost* render_frame_host, | 112 void OnBannerPromptReply(content::RenderFrameHost* render_frame_host, |
113 int request_id, | 113 int request_id, |
114 blink::WebAppBannerPromptReply reply, | 114 blink::WebAppBannerPromptReply reply, |
115 std::string referrer); | 115 std::string referrer); |
116 | 116 |
117 // Called when the client has prevented a banner from being shown, and is | 117 // Called when the client has prevented a banner from being shown, and is |
118 // now requesting that it be shown later. | 118 // now requesting that it be shown later. |
119 void OnRequestShowAppBanner(content::RenderFrameHost* render_frame_host, | 119 void OnRequestShowAppBanner(content::RenderFrameHost* render_frame_host, |
120 int request_id); | 120 int request_id); |
121 | 121 |
122 // Called when it is determined that the webapp has fulfilled the initial | |
123 // criteria of having a manifest and a service worker. | |
124 void OnHasServiceWorker(content::WebContents* web_contents); | |
125 | |
126 content::WebContents* GetWebContents(); | 122 content::WebContents* GetWebContents(); |
127 virtual std::string GetAppIdentifier(); | 123 virtual std::string GetAppIdentifier(); |
128 const content::Manifest& web_app_data() { return web_app_data_; } | 124 const content::Manifest& web_app_data() { return web_app_data_; } |
129 void set_app_title(const base::string16& title) { app_title_ = title; } | 125 void set_app_title(const base::string16& title) { app_title_ = title; } |
130 int event_request_id() { return event_request_id_; } | 126 int event_request_id() { return event_request_id_; } |
131 | 127 |
132 // Fetches the icon at the given URL asynchronously, returning |false| if a | 128 // Fetches the icon at the given URL asynchronously, returning |false| if a |
133 // load could not be started. | 129 // load could not be started. |
134 bool FetchAppIcon(content::WebContents* web_contents, const GURL& url); | 130 bool FetchAppIcon(content::WebContents* web_contents, const GURL& url); |
135 | 131 |
136 // Records that a banner was shown. The |event_name| corresponds to the RAPPOR | 132 // Records that a banner was shown. The |event_name| corresponds to the RAPPOR |
137 // metric being recorded. | 133 // metric being recorded. |
138 void RecordDidShowBanner(const std::string& event_name); | 134 void RecordDidShowBanner(const std::string& event_name); |
139 | 135 |
140 private: | 136 private: |
141 // Callbacks for data retrieval. | 137 // Callbacks for data retrieval. |
142 void OnDidGetManifest(const content::Manifest& manifest); | 138 void OnDidGetManifest(const content::Manifest& manifest); |
143 void OnDidCheckHasServiceWorker(bool has_service_worker); | 139 void OnDidCheckHasServiceWorker(bool has_service_worker); |
144 void OnAppIconFetched(const SkBitmap& bitmap); | 140 void OnAppIconFetched(const SkBitmap& bitmap); |
145 | 141 |
| 142 // Called when it is determined that the webapp has fulfilled the initial |
| 143 // criteria of having a manifest and a service worker. |
| 144 void OnHasServiceWorker(content::WebContents* web_contents); |
| 145 |
146 // Returns whether the given web app has already been installed. | 146 // Returns whether the given web app has already been installed. |
147 // Implemented on desktop platforms only. | 147 // Implemented on desktop platforms only. |
148 virtual bool IsWebAppInstalled(content::BrowserContext* browser_context, | 148 virtual bool IsWebAppInstalled(content::BrowserContext* browser_context, |
149 const GURL& start_url); | 149 const GURL& start_url); |
150 | 150 |
151 // Record that the banner could be shown at this point, if the triggering | 151 // Record that the banner could be shown at this point, if the triggering |
152 // heuristic allowed. | 152 // heuristic allowed. |
153 void RecordCouldShowBanner(); | 153 void RecordCouldShowBanner(); |
154 | 154 |
155 // Creates a banner for the app using the given |icon|. | 155 // Creates a banner for the app using the given |icon|. |
156 virtual void ShowBanner(const SkBitmap* icon, | 156 virtual void ShowBanner(const SkBitmap* icon, |
157 const base::string16& title, | 157 const base::string16& title, |
158 const std::string& referrer) = 0; | 158 const std::string& referrer) = 0; |
159 | 159 |
160 // Returns whether the banner should be shown. | 160 // Returns whether the banner should be shown. |
161 bool CheckIfShouldShowBanner(); | 161 bool CheckIfShouldShowBanner(); |
162 | 162 |
163 // Returns whether the fetcher is active and web contents have not been | 163 // Returns whether the fetcher is active and web contents have not been |
164 // closed. | 164 // closed. |
165 bool CheckFetcherIsStillAlive(content::WebContents* web_contents); | 165 bool CheckFetcherIsStillAlive(content::WebContents* web_contents); |
166 | 166 |
167 // Returns whether the given Manifest is following the requirements to show | 167 // Returns whether the given Manifest is following the requirements to show |
168 // a web app banner. | 168 // a web app banner. |
169 static bool IsManifestValidForWebApp(const content::Manifest& manifest, | 169 static bool IsManifestValidForWebApp(const content::Manifest& manifest, |
170 content::WebContents* web_contents); | 170 content::WebContents* web_contents); |
171 | 171 |
172 const int ideal_icon_size_; | 172 const int ideal_icon_size_in_dp_; |
173 const base::WeakPtr<Delegate> weak_delegate_; | 173 const base::WeakPtr<Delegate> weak_delegate_; |
174 base::ObserverList<Observer> observer_list_; | 174 base::ObserverList<Observer> observer_list_; |
175 bool is_active_; | 175 bool is_active_; |
176 bool was_canceled_by_page_; | 176 bool was_canceled_by_page_; |
177 bool page_requested_prompt_; | 177 bool page_requested_prompt_; |
178 ui::PageTransition transition_type_; | 178 ui::PageTransition transition_type_; |
179 int event_request_id_; | 179 int event_request_id_; |
180 scoped_ptr<SkBitmap> app_icon_; | 180 scoped_ptr<SkBitmap> app_icon_; |
181 std::string referrer_; | 181 std::string referrer_; |
182 | 182 |
183 GURL validated_url_; | 183 GURL validated_url_; |
184 base::string16 app_title_; | 184 base::string16 app_title_; |
185 content::Manifest web_app_data_; | 185 content::Manifest web_app_data_; |
186 | 186 |
187 friend class AppBannerDataFetcherUnitTest; | 187 friend class AppBannerDataFetcherUnitTest; |
188 friend class base::RefCounted<AppBannerDataFetcher>; | 188 friend class base::RefCounted<AppBannerDataFetcher>; |
189 DISALLOW_COPY_AND_ASSIGN(AppBannerDataFetcher); | 189 DISALLOW_COPY_AND_ASSIGN(AppBannerDataFetcher); |
190 }; | 190 }; |
191 | 191 |
192 } // namespace banners | 192 } // namespace banners |
193 | 193 |
194 #endif // CHROME_BROWSER_BANNERS_APP_BANNER_DATA_FETCHER_H_ | 194 #endif // CHROME_BROWSER_BANNERS_APP_BANNER_DATA_FETCHER_H_ |
OLD | NEW |