Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(143)

Side by Side Diff: chrome/browser/banners/app_banner_data_fetcher.cc

Issue 1161233005: Implement app banner info bars on desktop. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@stop-icon-overgeneration
Patch Set: Reuploading Created 5 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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
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,
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());
benwells 2015/06/03 06:13:55 I think you can remove this method's implementatio
dominickn (DO NOT USE) 2015/06/03 07:10:36 Done. This also required making the manager abstra
213 208
214 // TODO(dfalcantara): Desktop doesn't display app banners, yet. Just pretend 209 // The actual display of the banner is platform specific, and implemented in
215 // that a banner was shown for testing purposes. 210 // the Android and Desktop subclasses of the data fetcher. No banner is
211 // displayed in this implementation: just record that a banner was shown.
216 RecordDidShowBanner("AppBanner.WebApp.Shown"); 212 RecordDidShowBanner("AppBanner.WebApp.Shown");
217 return nullptr;
218 } 213 }
219 214
220 void AppBannerDataFetcher::RecordDidShowBanner(const std::string& event_name) { 215 void AppBannerDataFetcher::RecordDidShowBanner(const std::string& event_name) {
221 content::WebContents* web_contents = GetWebContents(); 216 content::WebContents* web_contents = GetWebContents();
222 DCHECK(web_contents); 217 DCHECK(web_contents);
223 218
224 AppBannerSettingsHelper::RecordBannerEvent( 219 AppBannerSettingsHelper::RecordBannerEvent(
225 web_contents, validated_url_, GetAppIdentifier(), 220 web_contents, validated_url_, GetAppIdentifier(),
226 AppBannerSettingsHelper::APP_BANNER_EVENT_DID_SHOW, 221 AppBannerSettingsHelper::APP_BANNER_EVENT_DID_SHOW,
227 GetCurrentTime()); 222 GetCurrentTime());
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
303 TrackDisplayEvent(DISPLAY_EVENT_LACKS_SERVICE_WORKER); 298 TrackDisplayEvent(DISPLAY_EVENT_LACKS_SERVICE_WORKER);
304 OutputDeveloperNotShownMessage(web_contents, kNoMatchingServiceWorker); 299 OutputDeveloperNotShownMessage(web_contents, kNoMatchingServiceWorker);
305 } 300 }
306 301
307 Cancel(); 302 Cancel();
308 } 303 }
309 304
310 void AppBannerDataFetcher::OnFetchComplete(const GURL& url, 305 void AppBannerDataFetcher::OnFetchComplete(const GURL& url,
311 const SkBitmap* icon) { 306 const SkBitmap* icon) {
312 if (is_active_) 307 if (is_active_)
313 ShowBanner(icon); 308 RequestShowBanner(icon);
314 309
315 Release(); 310 Release();
316 } 311 }
317 312
318 void AppBannerDataFetcher::ShowBanner(const SkBitmap* icon) { 313 void AppBannerDataFetcher::RequestShowBanner(const SkBitmap* icon) {
319 content::WebContents* web_contents = GetWebContents(); 314 content::WebContents* web_contents = GetWebContents();
320 if (!CheckFetcherIsStillAlive(web_contents)) { 315 if (!CheckFetcherIsStillAlive(web_contents)) {
321 Cancel(); 316 Cancel();
322 return; 317 return;
323 } 318 }
324 if (!icon) { 319 if (!icon) {
325 OutputDeveloperNotShownMessage(web_contents, kNoIconAvailable); 320 OutputDeveloperNotShownMessage(web_contents, kNoIconAvailable);
326 Cancel(); 321 Cancel();
327 return; 322 return;
328 } 323 }
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
394 return false; 389 return false;
395 } 390 }
396 if (!DoesManifestContainRequiredIcon(manifest)) { 391 if (!DoesManifestContainRequiredIcon(manifest)) {
397 OutputDeveloperNotShownMessage(web_contents, kManifestMissingSuitableIcon); 392 OutputDeveloperNotShownMessage(web_contents, kManifestMissingSuitableIcon);
398 return false; 393 return false;
399 } 394 }
400 return true; 395 return true;
401 } 396 }
402 397
403 } // namespace banners 398 } // namespace banners
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698