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( | |
209 const SkBitmap* icon, | |
210 const base::string16& title) { | |
211 content::WebContents* web_contents = GetWebContents(); | |
212 DCHECK(web_contents && !web_app_data_.IsEmpty()); | |
213 | |
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"); | |
217 return nullptr; | |
218 } | |
219 | |
220 void AppBannerDataFetcher::RecordDidShowBanner(const std::string& event_name) { | 202 void AppBannerDataFetcher::RecordDidShowBanner(const std::string& event_name) { |
221 content::WebContents* web_contents = GetWebContents(); | 203 content::WebContents* web_contents = GetWebContents(); |
222 DCHECK(web_contents); | 204 DCHECK(web_contents); |
223 | 205 |
224 AppBannerSettingsHelper::RecordBannerEvent( | 206 AppBannerSettingsHelper::RecordBannerEvent( |
225 web_contents, validated_url_, GetAppIdentifier(), | 207 web_contents, validated_url_, GetAppIdentifier(), |
226 AppBannerSettingsHelper::APP_BANNER_EVENT_DID_SHOW, | 208 AppBannerSettingsHelper::APP_BANNER_EVENT_DID_SHOW, |
227 GetCurrentTime()); | 209 GetCurrentTime()); |
228 rappor::SampleDomainAndRegistryFromGURL(g_browser_process->rappor_service(), | 210 rappor::SampleDomainAndRegistryFromGURL(g_browser_process->rappor_service(), |
229 event_name, | 211 event_name, |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
303 TrackDisplayEvent(DISPLAY_EVENT_LACKS_SERVICE_WORKER); | 285 TrackDisplayEvent(DISPLAY_EVENT_LACKS_SERVICE_WORKER); |
304 OutputDeveloperNotShownMessage(web_contents, kNoMatchingServiceWorker); | 286 OutputDeveloperNotShownMessage(web_contents, kNoMatchingServiceWorker); |
305 } | 287 } |
306 | 288 |
307 Cancel(); | 289 Cancel(); |
308 } | 290 } |
309 | 291 |
310 void AppBannerDataFetcher::OnFetchComplete(const GURL& url, | 292 void AppBannerDataFetcher::OnFetchComplete(const GURL& url, |
311 const SkBitmap* icon) { | 293 const SkBitmap* icon) { |
312 if (is_active_) | 294 if (is_active_) |
313 ShowBanner(icon); | 295 RequestShowBanner(icon); |
314 | 296 |
315 Release(); | 297 Release(); |
316 } | 298 } |
317 | 299 |
318 void AppBannerDataFetcher::ShowBanner(const SkBitmap* icon) { | 300 void AppBannerDataFetcher::RequestShowBanner(const SkBitmap* icon) { |
319 content::WebContents* web_contents = GetWebContents(); | 301 content::WebContents* web_contents = GetWebContents(); |
320 if (!CheckFetcherIsStillAlive(web_contents)) { | 302 if (!CheckFetcherIsStillAlive(web_contents)) { |
321 Cancel(); | 303 Cancel(); |
322 return; | 304 return; |
323 } | 305 } |
324 if (!icon) { | 306 if (!icon) { |
325 OutputDeveloperNotShownMessage(web_contents, kNoIconAvailable); | 307 OutputDeveloperNotShownMessage(web_contents, kNoIconAvailable); |
326 Cancel(); | 308 Cancel(); |
327 return; | 309 return; |
328 } | 310 } |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
394 return false; | 376 return false; |
395 } | 377 } |
396 if (!DoesManifestContainRequiredIcon(manifest)) { | 378 if (!DoesManifestContainRequiredIcon(manifest)) { |
397 OutputDeveloperNotShownMessage(web_contents, kManifestMissingSuitableIcon); | 379 OutputDeveloperNotShownMessage(web_contents, kManifestMissingSuitableIcon); |
398 return false; | 380 return false; |
399 } | 381 } |
400 return true; | 382 return true; |
401 } | 383 } |
402 | 384 |
403 } // namespace banners | 385 } // namespace banners |
OLD | NEW |