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

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

Issue 1092193004: Use related_applications manifest fields when showing native app banners (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 8 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 "chrome/browser/banners/app_banner_metrics.h" 10 #include "chrome/browser/banners/app_banner_metrics.h"
10 #include "chrome/browser/banners/app_banner_settings_helper.h" 11 #include "chrome/browser/banners/app_banner_settings_helper.h"
11 #include "chrome/browser/bitmap_fetcher/bitmap_fetcher.h" 12 #include "chrome/browser/bitmap_fetcher/bitmap_fetcher.h"
12 #include "chrome/browser/browser_process.h" 13 #include "chrome/browser/browser_process.h"
13 #include "chrome/browser/infobars/infobar_service.h" 14 #include "chrome/browser/infobars/infobar_service.h"
14 #include "chrome/browser/manifest/manifest_icon_selector.h" 15 #include "chrome/browser/manifest/manifest_icon_selector.h"
15 #include "chrome/browser/profiles/profile.h" 16 #include "chrome/browser/profiles/profile.h"
16 #include "chrome/common/render_messages.h" 17 #include "chrome/common/render_messages.h"
17 #include "components/infobars/core/infobar.h" 18 #include "components/infobars/core/infobar.h"
18 #include "components/rappor/rappor_utils.h" 19 #include "components/rappor/rappor_utils.h"
(...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after
224 GetCurrentTime()); 225 GetCurrentTime());
225 rappor::SampleDomainAndRegistryFromGURL(g_browser_process->rappor_service(), 226 rappor::SampleDomainAndRegistryFromGURL(g_browser_process->rappor_service(),
226 event_name, 227 event_name,
227 web_contents->GetURL()); 228 web_contents->GetURL());
228 banners::TrackDisplayEvent(DISPLAY_EVENT_CREATED); 229 banners::TrackDisplayEvent(DISPLAY_EVENT_CREATED);
229 } 230 }
230 231
231 void AppBannerDataFetcher::OnDidGetManifest( 232 void AppBannerDataFetcher::OnDidGetManifest(
232 const content::Manifest& manifest) { 233 const content::Manifest& manifest) {
233 content::WebContents* web_contents = GetWebContents(); 234 content::WebContents* web_contents = GetWebContents();
234 if (!is_active_ || !web_contents) { 235 if (!is_active_ || !web_contents || manifest.IsEmpty()) {
235 Cancel(); 236 Cancel();
236 return; 237 return;
237 } 238 }
238 239
239 if (!IsManifestValid(manifest)) { 240 if (manifest.prefer_related_applications &&
240 if (!weak_delegate_.get()->OnInvalidManifest(this)) 241 manifest.related_applications.size()) {
241 Cancel(); 242 for (const auto& application : manifest.related_applications) {
243 std::string platform = base::UTF16ToUTF8(application.platform.string());
244 std::string id = base::UTF16ToUTF8(application.id.string());
245 if (weak_delegate_->HandleNonWebApp(platform, application.url, id))
246 return;
247 }
248 }
249
250 if (!IsManifestValidForWebApp(manifest)) {
251 Cancel();
242 return; 252 return;
243 } 253 }
244 254
245 banners::TrackDisplayEvent(DISPLAY_EVENT_BANNER_REQUESTED); 255 banners::TrackDisplayEvent(DISPLAY_EVENT_BANNER_REQUESTED);
246 256
247 web_app_data_ = manifest; 257 web_app_data_ = manifest;
248 app_title_ = web_app_data_.name.string(); 258 app_title_ = web_app_data_.name.string();
249 259
250 // Check to see if there is a single service worker controlling this page 260 // Check to see if there is a single service worker controlling this page
251 // and the manifest's start url. 261 // and the manifest's start url.
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
329 339
330 bool AppBannerDataFetcher::CheckIfShouldShowBanner() { 340 bool AppBannerDataFetcher::CheckIfShouldShowBanner() {
331 content::WebContents* web_contents = GetWebContents(); 341 content::WebContents* web_contents = GetWebContents();
332 DCHECK(web_contents); 342 DCHECK(web_contents);
333 343
334 return AppBannerSettingsHelper::ShouldShowBanner( 344 return AppBannerSettingsHelper::ShouldShowBanner(
335 web_contents, validated_url_, GetAppIdentifier(), GetCurrentTime()); 345 web_contents, validated_url_, GetAppIdentifier(), GetCurrentTime());
336 } 346 }
337 347
338 // static 348 // static
339 bool AppBannerDataFetcher::IsManifestValid( 349 bool AppBannerDataFetcher::IsManifestValidForWebApp(
340 const content::Manifest& manifest) { 350 const content::Manifest& manifest) {
341 if (manifest.IsEmpty()) 351 if (manifest.IsEmpty())
342 return false; 352 return false;
343 if (!manifest.start_url.is_valid()) 353 if (!manifest.start_url.is_valid())
344 return false; 354 return false;
345 if (manifest.name.is_null() && manifest.short_name.is_null()) 355 if (manifest.name.is_null() && manifest.short_name.is_null())
346 return false; 356 return false;
347 if (!DoesManifestContainRequiredIcon(manifest)) 357 if (!DoesManifestContainRequiredIcon(manifest))
348 return false; 358 return false;
349 return true; 359 return true;
350 } 360 }
351 361
352 } // namespace banners 362 } // namespace banners
OLDNEW
« no previous file with comments | « chrome/browser/banners/app_banner_data_fetcher.h ('k') | chrome/browser/banners/app_banner_data_fetcher_browsertest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698