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 #include "chrome/browser/banners/app_banner_data_fetcher.h" | 5 #include "chrome/browser/banners/app_banner_data_fetcher.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/strings/string_util.h" | 8 #include "base/strings/string_util.h" |
9 #include "base/strings/utf_string_conversions.h" | 9 #include "base/strings/utf_string_conversions.h" |
10 #include "chrome/browser/banners/app_banner_debug_log.h" | 10 #include "chrome/browser/banners/app_banner_debug_log.h" |
11 #include "chrome/browser/banners/app_banner_metrics.h" | 11 #include "chrome/browser/banners/app_banner_metrics.h" |
12 #include "chrome/browser/banners/app_banner_settings_helper.h" | 12 #include "chrome/browser/banners/app_banner_settings_helper.h" |
13 #include "chrome/browser/bitmap_fetcher/bitmap_fetcher.h" | 13 #include "chrome/browser/bitmap_fetcher/bitmap_fetcher.h" |
14 #include "chrome/browser/browser_process.h" | 14 #include "chrome/browser/browser_process.h" |
15 #include "chrome/browser/infobars/infobar_service.h" | |
16 #include "chrome/browser/manifest/manifest_icon_selector.h" | 15 #include "chrome/browser/manifest/manifest_icon_selector.h" |
17 #include "chrome/browser/profiles/profile.h" | 16 #include "chrome/browser/profiles/profile.h" |
18 #include "chrome/common/render_messages.h" | 17 #include "chrome/common/render_messages.h" |
19 #include "components/infobars/core/infobar.h" | |
20 #include "components/rappor/rappor_utils.h" | 18 #include "components/rappor/rappor_utils.h" |
21 #include "content/public/browser/browser_context.h" | 19 #include "content/public/browser/browser_context.h" |
22 #include "content/public/browser/browser_thread.h" | 20 #include "content/public/browser/browser_thread.h" |
23 #include "content/public/browser/navigation_details.h" | 21 #include "content/public/browser/navigation_details.h" |
24 #include "content/public/browser/render_frame_host.h" | 22 #include "content/public/browser/render_frame_host.h" |
25 #include "content/public/browser/service_worker_context.h" | 23 #include "content/public/browser/service_worker_context.h" |
26 #include "content/public/browser/storage_partition.h" | 24 #include "content/public/browser/storage_partition.h" |
27 #include "net/base/load_flags.h" | 25 #include "net/base/load_flags.h" |
28 #include "third_party/WebKit/public/platform/modules/app_banner/WebAppBannerProm ptReply.h" | 26 #include "third_party/WebKit/public/platform/modules/app_banner/WebAppBannerProm ptReply.h" |
29 #include "ui/gfx/screen.h" | 27 #include "ui/gfx/screen.h" |
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
151 if (reply == blink::WebAppBannerPromptReply::Cancel) { | 149 if (reply == blink::WebAppBannerPromptReply::Cancel) { |
152 OutputDeveloperNotShownMessage(web_contents, kRendererRequestCancel); | 150 OutputDeveloperNotShownMessage(web_contents, kRendererRequestCancel); |
153 Cancel(); | 151 Cancel(); |
154 return; | 152 return; |
155 } | 153 } |
156 | 154 |
157 // Definitely going to show the banner now. | 155 // Definitely going to show the banner now. |
158 FOR_EACH_OBSERVER(Observer, observer_list_, | 156 FOR_EACH_OBSERVER(Observer, observer_list_, |
159 OnDecidedWhetherToShow(this, true)); | 157 OnDecidedWhetherToShow(this, true)); |
160 | 158 |
161 infobars::InfoBar* infobar = CreateBanner(app_icon_.get(), app_title_); | 159 ShowBanner(app_icon_.get(), app_title_); |
162 if (infobar) { | |
163 InfoBarService::FromWebContents(web_contents)->AddInfoBar( | |
164 make_scoped_ptr(infobar)); | |
165 } | |
166 is_active_ = false; | 160 is_active_ = false; |
167 } | 161 } |
168 | 162 |
169 AppBannerDataFetcher::~AppBannerDataFetcher() { | 163 AppBannerDataFetcher::~AppBannerDataFetcher() { |
170 FOR_EACH_OBSERVER(Observer, observer_list_, OnFetcherDestroyed(this)); | 164 FOR_EACH_OBSERVER(Observer, observer_list_, OnFetcherDestroyed(this)); |
171 } | 165 } |
172 | 166 |
173 std::string AppBannerDataFetcher::GetBannerType() { | 167 std::string AppBannerDataFetcher::GetBannerType() { |
174 return "web"; | 168 return "web"; |
175 } | 169 } |
(...skipping 22 matching lines...) Expand all Loading... | |
198 Profile::FromBrowserContext(web_contents->GetBrowserContext()); | 192 Profile::FromBrowserContext(web_contents->GetBrowserContext()); |
199 bitmap_fetcher_.reset(new chrome::BitmapFetcher(image_url, this)); | 193 bitmap_fetcher_.reset(new chrome::BitmapFetcher(image_url, this)); |
200 bitmap_fetcher_->Start( | 194 bitmap_fetcher_->Start( |
201 profile->GetRequestContext(), | 195 profile->GetRequestContext(), |
202 std::string(), | 196 std::string(), |
203 net::URLRequest::CLEAR_REFERRER_ON_TRANSITION_FROM_SECURE_TO_INSECURE, | 197 net::URLRequest::CLEAR_REFERRER_ON_TRANSITION_FROM_SECURE_TO_INSECURE, |
204 net::LOAD_NORMAL); | 198 net::LOAD_NORMAL); |
205 return true; | 199 return true; |
206 } | 200 } |
207 | 201 |
208 infobars::InfoBar* AppBannerDataFetcher::CreateBanner( | 202 // This method is overridden on Android and desktop to provide |
209 const SkBitmap* icon, | 203 // platform-specific implementations. |
210 const base::string16& title) { | 204 void AppBannerDataFetcher::ShowBanner(const SkBitmap* icon, |
gone
2015/06/02 21:36:04
This function is a little strange, now. All the w
| |
205 const base::string16& title) { | |
211 content::WebContents* web_contents = GetWebContents(); | 206 content::WebContents* web_contents = GetWebContents(); |
212 DCHECK(web_contents && !web_app_data_.IsEmpty()); | 207 DCHECK(web_contents && !web_app_data_.IsEmpty()); |
213 | 208 |
214 // TODO(dfalcantara): Desktop doesn't display app banners, yet. Just pretend | |
215 // that a banner was shown for testing purposes. | |
216 RecordDidShowBanner("AppBanner.WebApp.Shown"); | 209 RecordDidShowBanner("AppBanner.WebApp.Shown"); |
217 return nullptr; | |
218 } | 210 } |
219 | 211 |
220 void AppBannerDataFetcher::RecordDidShowBanner(const std::string& event_name) { | 212 void AppBannerDataFetcher::RecordDidShowBanner(const std::string& event_name) { |
221 content::WebContents* web_contents = GetWebContents(); | 213 content::WebContents* web_contents = GetWebContents(); |
222 DCHECK(web_contents); | 214 DCHECK(web_contents); |
223 | 215 |
224 AppBannerSettingsHelper::RecordBannerEvent( | 216 AppBannerSettingsHelper::RecordBannerEvent( |
225 web_contents, validated_url_, GetAppIdentifier(), | 217 web_contents, validated_url_, GetAppIdentifier(), |
226 AppBannerSettingsHelper::APP_BANNER_EVENT_DID_SHOW, | 218 AppBannerSettingsHelper::APP_BANNER_EVENT_DID_SHOW, |
227 GetCurrentTime()); | 219 GetCurrentTime()); |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
303 TrackDisplayEvent(DISPLAY_EVENT_LACKS_SERVICE_WORKER); | 295 TrackDisplayEvent(DISPLAY_EVENT_LACKS_SERVICE_WORKER); |
304 OutputDeveloperNotShownMessage(web_contents, kNoMatchingServiceWorker); | 296 OutputDeveloperNotShownMessage(web_contents, kNoMatchingServiceWorker); |
305 } | 297 } |
306 | 298 |
307 Cancel(); | 299 Cancel(); |
308 } | 300 } |
309 | 301 |
310 void AppBannerDataFetcher::OnFetchComplete(const GURL& url, | 302 void AppBannerDataFetcher::OnFetchComplete(const GURL& url, |
311 const SkBitmap* icon) { | 303 const SkBitmap* icon) { |
312 if (is_active_) | 304 if (is_active_) |
313 ShowBanner(icon); | 305 RequestShowBanner(icon); |
314 | 306 |
315 Release(); | 307 Release(); |
316 } | 308 } |
317 | 309 |
318 void AppBannerDataFetcher::ShowBanner(const SkBitmap* icon) { | 310 void AppBannerDataFetcher::RequestShowBanner(const SkBitmap* icon) { |
319 content::WebContents* web_contents = GetWebContents(); | 311 content::WebContents* web_contents = GetWebContents(); |
320 if (!CheckFetcherIsStillAlive(web_contents)) { | 312 if (!CheckFetcherIsStillAlive(web_contents)) { |
321 Cancel(); | 313 Cancel(); |
322 return; | 314 return; |
323 } | 315 } |
324 if (!icon) { | 316 if (!icon) { |
325 OutputDeveloperNotShownMessage(web_contents, kNoIconAvailable); | 317 OutputDeveloperNotShownMessage(web_contents, kNoIconAvailable); |
326 Cancel(); | 318 Cancel(); |
327 return; | 319 return; |
328 } | 320 } |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
394 return false; | 386 return false; |
395 } | 387 } |
396 if (!DoesManifestContainRequiredIcon(manifest)) { | 388 if (!DoesManifestContainRequiredIcon(manifest)) { |
397 OutputDeveloperNotShownMessage(web_contents, kManifestMissingSuitableIcon); | 389 OutputDeveloperNotShownMessage(web_contents, kManifestMissingSuitableIcon); |
398 return false; | 390 return false; |
399 } | 391 } |
400 return true; | 392 return true; |
401 } | 393 } |
402 | 394 |
403 } // namespace banners | 395 } // namespace banners |
OLD | NEW |