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

Side by Side Diff: chrome/browser/android/webapps/add_to_homescreen_data_fetcher.cc

Issue 2050933002: Upstream: Add additional checks before creating a WebAPK after clicking "Add to Homescreen" (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Merge branch 'create_webapk_requirements_enum_class' into create_webapk_requirements2 Created 4 years, 5 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/android/webapps/add_to_homescreen_data_fetcher.h" 5 #include "chrome/browser/android/webapps/add_to_homescreen_data_fetcher.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/callback.h" 8 #include "base/callback.h"
9 #include "base/command_line.h"
9 #include "base/location.h" 10 #include "base/location.h"
10 #include "base/strings/string16.h" 11 #include "base/strings/string16.h"
11 #include "base/task/cancelable_task_tracker.h" 12 #include "base/task/cancelable_task_tracker.h"
12 #include "chrome/browser/android/offline_pages/offline_page_utils.h" 13 #include "chrome/browser/android/offline_pages/offline_page_utils.h"
13 #include "chrome/browser/android/shortcut_helper.h" 14 #include "chrome/browser/android/shortcut_helper.h"
15 #include "chrome/browser/banners/app_banner_debug_log.h"
16 #include "chrome/browser/banners/webapp_manifest_validator.h"
14 #include "chrome/browser/favicon/favicon_service_factory.h" 17 #include "chrome/browser/favicon/favicon_service_factory.h"
15 #include "chrome/browser/manifest/manifest_icon_downloader.h" 18 #include "chrome/browser/manifest/manifest_icon_downloader.h"
16 #include "chrome/browser/manifest/manifest_icon_selector.h" 19 #include "chrome/browser/manifest/manifest_icon_selector.h"
17 #include "chrome/browser/profiles/profile.h" 20 #include "chrome/browser/profiles/profile.h"
18 #include "chrome/common/chrome_constants.h" 21 #include "chrome/common/chrome_constants.h"
22 #include "chrome/common/chrome_switches.h"
19 #include "chrome/common/render_messages.h" 23 #include "chrome/common/render_messages.h"
20 #include "chrome/common/web_application_info.h" 24 #include "chrome/common/web_application_info.h"
21 #include "components/dom_distiller/core/url_utils.h" 25 #include "components/dom_distiller/core/url_utils.h"
22 #include "components/favicon/core/favicon_service.h" 26 #include "components/favicon/core/favicon_service.h"
23 #include "content/public/browser/browser_thread.h" 27 #include "content/public/browser/browser_thread.h"
28 #include "content/public/browser/service_worker_context.h"
29 #include "content/public/browser/storage_partition.h"
24 #include "content/public/browser/user_metrics.h" 30 #include "content/public/browser/user_metrics.h"
25 #include "content/public/browser/web_contents.h" 31 #include "content/public/browser/web_contents.h"
26 #include "content/public/browser/web_contents_observer.h" 32 #include "content/public/browser/web_contents_observer.h"
27 #include "content/public/common/frame_navigate_params.h" 33 #include "content/public/common/frame_navigate_params.h"
28 #include "content/public/common/manifest.h" 34 #include "content/public/common/manifest.h"
29 #include "third_party/WebKit/public/platform/modules/screen_orientation/WebScree nOrientationLockType.h" 35 #include "third_party/WebKit/public/platform/modules/screen_orientation/WebScree nOrientationLockType.h"
30 #include "ui/display/display.h" 36 #include "ui/display/display.h"
31 #include "ui/display/screen.h" 37 #include "ui/display/screen.h"
32 #include "ui/gfx/codec/png_codec.h" 38 #include "ui/gfx/codec/png_codec.h"
33 #include "ui/gfx/favicon_size.h" 39 #include "ui/gfx/favicon_size.h"
(...skipping 14 matching lines...) Expand all
48 is_icon_saved_(false), 54 is_icon_saved_(false),
49 is_ready_(false), 55 is_ready_(false),
50 icon_timeout_timer_(false, false), 56 icon_timeout_timer_(false, false),
51 shortcut_info_(GetShortcutUrl(web_contents->GetURL())), 57 shortcut_info_(GetShortcutUrl(web_contents->GetURL())),
52 ideal_icon_size_in_dp_(ideal_icon_size_in_dp), 58 ideal_icon_size_in_dp_(ideal_icon_size_in_dp),
53 minimum_icon_size_in_dp_(minimum_icon_size_in_dp), 59 minimum_icon_size_in_dp_(minimum_icon_size_in_dp),
54 ideal_splash_image_size_in_dp_(ideal_splash_image_size_in_dp), 60 ideal_splash_image_size_in_dp_(ideal_splash_image_size_in_dp),
55 minimum_splash_image_size_in_dp_(minimum_splash_image_size_in_dp) { 61 minimum_splash_image_size_in_dp_(minimum_splash_image_size_in_dp) {
56 DCHECK(minimum_icon_size_in_dp <= ideal_icon_size_in_dp); 62 DCHECK(minimum_icon_size_in_dp <= ideal_icon_size_in_dp);
57 DCHECK(minimum_splash_image_size_in_dp <= ideal_splash_image_size_in_dp); 63 DCHECK(minimum_splash_image_size_in_dp <= ideal_splash_image_size_in_dp);
64 shortcut_url_ = shortcut_info_.url;
58 65
59 // Send a message to the renderer to retrieve information about the page. 66 // Send a message to the renderer to retrieve information about the page.
60 is_waiting_for_web_application_info_ = true; 67 is_waiting_for_web_application_info_ = true;
61 Send(new ChromeViewMsg_GetWebApplicationInfo(routing_id())); 68 Send(new ChromeViewMsg_GetWebApplicationInfo(routing_id()));
62 } 69 }
63 70
64 void AddToHomescreenDataFetcher::OnDidGetWebApplicationInfo( 71 void AddToHomescreenDataFetcher::OnDidGetWebApplicationInfo(
65 const WebApplicationInfo& received_web_app_info) { 72 const WebApplicationInfo& received_web_app_info) {
66 is_waiting_for_web_application_info_ = false; 73 is_waiting_for_web_application_info_ = false;
67 if (!web_contents() || !weak_observer_) return; 74 if (!web_contents() || !weak_observer_) return;
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
110 const content::Manifest& manifest) { 117 const content::Manifest& manifest) {
111 if (!web_contents() || !weak_observer_) return; 118 if (!web_contents() || !weak_observer_) return;
112 119
113 if (!manifest.IsEmpty()) { 120 if (!manifest.IsEmpty()) {
114 content::RecordAction( 121 content::RecordAction(
115 base::UserMetricsAction("webapps.AddShortcut.Manifest")); 122 base::UserMetricsAction("webapps.AddShortcut.Manifest"));
116 shortcut_info_.UpdateFromManifest(manifest); 123 shortcut_info_.UpdateFromManifest(manifest);
117 shortcut_info_.manifest_url = manifest_url; 124 shortcut_info_.manifest_url = manifest_url;
118 } 125 }
119 126
127 if (!IsManifestWebApkCapable(manifest)) {
128 banners::OutputDeveloperMessageCode code =
129 banners::OutputDeveloperMessageCode::kNone;
130 if (banners::webapp_manifest_validator::IsWebappCapable(manifest, &code)) {
131 shortcut_info_.type = ShortcutInfo::Type::WEBAPP;
132 }
133 OnCheckIsWebApk(manifest, false);
134 return;
135 }
136
137 // Check to see if there is a single service worker controlling this page
138 // and the manifest's start url.
139 Profile* profile =
140 Profile::FromBrowserContext(web_contents()->GetBrowserContext());
141 content::StoragePartition* storage_partition =
142 content::BrowserContext::GetStoragePartition(
143 profile, web_contents()->GetSiteInstance());
144 DCHECK(storage_partition);
145 storage_partition->GetServiceWorkerContext()->CheckHasServiceWorker(
146 shortcut_url_, manifest.start_url,
147 base::Bind(&AddToHomescreenDataFetcher::OnDidCheckServiceWorkerForWebApk,
148 this, manifest));
149 }
150
151 void AddToHomescreenDataFetcher::OnDidCheckServiceWorkerForWebApk(
152 const content::Manifest& manifest,
153 bool has_service_worker) {
154 if (!web_contents() || !weak_observer_) return;
155 OnCheckIsWebApk(manifest, has_service_worker);
156 }
157
158 void AddToHomescreenDataFetcher::OnCheckIsWebApk(
159 const content::Manifest& manifest,
160 bool is_webapk) {
161 if (is_webapk)
162 shortcut_info_.type = ShortcutInfo::Type::WEBAPK;
163
120 GURL icon_src = ManifestIconSelector::FindBestMatchingIcon( 164 GURL icon_src = ManifestIconSelector::FindBestMatchingIcon(
121 manifest.icons, ideal_icon_size_in_dp_, minimum_icon_size_in_dp_); 165 manifest.icons, ideal_icon_size_in_dp_, minimum_icon_size_in_dp_);
122 166
123 // If fetching the Manifest icon fails, fallback to the best favicon 167 // If fetching the Manifest icon fails, fallback to the best favicon
124 // for the page. 168 // for the page.
125 if (!ManifestIconDownloader::Download( 169 if (!ManifestIconDownloader::Download(
126 web_contents(), 170 web_contents(),
127 icon_src, 171 icon_src,
128 ideal_icon_size_in_dp_, 172 ideal_icon_size_in_dp_,
129 minimum_icon_size_in_dp_, 173 minimum_icon_size_in_dp_,
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after
272 316
273 // If URL points to an offline content, get original URL. 317 // If URL points to an offline content, get original URL.
274 GURL online_url = 318 GURL online_url =
275 offline_pages::OfflinePageUtils::MaybeGetOnlineURLForOfflineURL( 319 offline_pages::OfflinePageUtils::MaybeGetOnlineURLForOfflineURL(
276 web_contents()->GetBrowserContext(), original_url); 320 web_contents()->GetBrowserContext(), original_url);
277 if (online_url.is_valid()) 321 if (online_url.is_valid())
278 return online_url; 322 return online_url;
279 323
280 return original_url; 324 return original_url;
281 } 325 }
326
327 bool AddToHomescreenDataFetcher::IsManifestWebApkCapable(
328 const content::Manifest& manifest) const {
329 banners::OutputDeveloperMessageCode code =
330 banners::OutputDeveloperMessageCode::kNone;
331 return banners::webapp_manifest_validator::IsManifestGoodForWebapp(manifest,
332 &code) &&
333 base::CommandLine::ForCurrentProcess()->HasSwitch(
334 switches::kEnableWebApk);
335 }
OLDNEW
« no previous file with comments | « chrome/browser/android/webapps/add_to_homescreen_data_fetcher.h ('k') | chrome/browser/banners/app_banner_data_fetcher.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698