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

Side by Side Diff: chrome/browser/android/webapk/webapk_installer.cc

Issue 2453423002: Send all of the icon URLs listed in Web Manifest to WebAPK Server. (Closed)
Patch Set: Remove best_icon_url and best_icon_hash from metadata, but add all icon urls and icon hashs in. Created 4 years, 1 month 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 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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/webapk/webapk_installer.h" 5 #include "chrome/browser/android/webapk/webapk_installer.h"
6 6
7 #include "base/android/build_info.h" 7 #include "base/android/build_info.h"
8 #include "base/android/jni_android.h" 8 #include "base/android/jni_android.h"
9 #include "base/android/jni_string.h" 9 #include "base/android/jni_string.h"
10 #include "base/android/path_utils.h" 10 #include "base/android/path_utils.h"
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
93 const SkBitmap& shortcut_icon, 93 const SkBitmap& shortcut_icon,
94 const std::string& shortcut_icon_murmur2_hash) { 94 const std::string& shortcut_icon_murmur2_hash) {
95 DCHECK(content::BrowserThread::GetBlockingPool()->RunsTasksOnCurrentThread()); 95 DCHECK(content::BrowserThread::GetBlockingPool()->RunsTasksOnCurrentThread());
96 96
97 std::unique_ptr<webapk::WebApk> webapk(new webapk::WebApk); 97 std::unique_ptr<webapk::WebApk> webapk(new webapk::WebApk);
98 webapk->set_manifest_url(shortcut_info.manifest_url.spec()); 98 webapk->set_manifest_url(shortcut_info.manifest_url.spec());
99 webapk->set_requester_application_package( 99 webapk->set_requester_application_package(
100 base::android::BuildInfo::GetInstance()->package_name()); 100 base::android::BuildInfo::GetInstance()->package_name());
101 webapk->set_requester_application_version(version_info::GetVersionNumber()); 101 webapk->set_requester_application_version(version_info::GetVersionNumber());
102 102
103 if (shortcut_icon_murmur2_hash.empty())
pkotwicz 2016/11/11 21:04:19 An empty |shortcut_icon_murmur2_hash| shouldn't ha
Xi Han 2016/11/14 19:36:10 Yes, I will wait for Glenn to add this new attribu
104 return webapk;
105
103 webapk::WebAppManifest* web_app_manifest = webapk->mutable_manifest(); 106 webapk::WebAppManifest* web_app_manifest = webapk->mutable_manifest();
104 web_app_manifest->set_name(base::UTF16ToUTF8(shortcut_info.name)); 107 web_app_manifest->set_name(base::UTF16ToUTF8(shortcut_info.name));
105 web_app_manifest->set_short_name( 108 web_app_manifest->set_short_name(
106 base::UTF16ToUTF8(shortcut_info.short_name)); 109 base::UTF16ToUTF8(shortcut_info.short_name));
107 web_app_manifest->set_start_url(shortcut_info.url.spec()); 110 web_app_manifest->set_start_url(shortcut_info.url.spec());
108 web_app_manifest->set_orientation( 111 web_app_manifest->set_orientation(
109 content::WebScreenOrientationLockTypeToString( 112 content::WebScreenOrientationLockTypeToString(
110 shortcut_info.orientation)); 113 shortcut_info.orientation));
111 web_app_manifest->set_display_mode( 114 web_app_manifest->set_display_mode(
112 content::WebDisplayModeToString(shortcut_info.display)); 115 content::WebDisplayModeToString(shortcut_info.display));
113 web_app_manifest->set_background_color( 116 web_app_manifest->set_background_color(
114 ColorToString(shortcut_info.background_color)); 117 ColorToString(shortcut_info.background_color));
115 web_app_manifest->set_theme_color(ColorToString(shortcut_info.theme_color)); 118 web_app_manifest->set_theme_color(ColorToString(shortcut_info.theme_color));
116 119
117 std::string* scope = web_app_manifest->add_scopes(); 120 std::string* scope = web_app_manifest->add_scopes();
118 scope->assign(GetScope(shortcut_info).spec()); 121 scope->assign(GetScope(shortcut_info).spec());
pkotwicz 2016/11/11 21:04:19 Nit: Add a new line for clarity
Xi Han 2016/11/14 19:36:10 Done.
119 webapk::Image* image = web_app_manifest->add_icons(); 122 webapk::Image* best_image = web_app_manifest->add_icons();
120 image->set_src(shortcut_info.icon_url.spec()); 123 best_image->set_src(shortcut_info.best_icon_url.spec());
121 image->set_hash(shortcut_icon_murmur2_hash); 124 best_image->set_hash(shortcut_icon_murmur2_hash);
122 std::vector<unsigned char> png_bytes; 125 std::vector<unsigned char> png_bytes;
123 gfx::PNGCodec::EncodeBGRASkBitmap(shortcut_icon, false, &png_bytes); 126 gfx::PNGCodec::EncodeBGRASkBitmap(shortcut_icon, false, &png_bytes);
124 image->set_image_data(&png_bytes.front(), png_bytes.size()); 127 best_image->set_image_data(&png_bytes.front(), png_bytes.size());
128
129 for (const GURL& icon_url : shortcut_info.icon_urls) {
130 if (icon_url == shortcut_info.best_icon_url)
131 continue;
132 webapk::Image* image = web_app_manifest->add_icons();
133 image->set_src(icon_url.spec());
134 }
125 135
126 return webapk; 136 return webapk;
127 } 137 }
128 138
129 // Returns task runner for running background tasks. 139 // Returns task runner for running background tasks.
130 scoped_refptr<base::TaskRunner> GetBackgroundTaskRunner() { 140 scoped_refptr<base::TaskRunner> GetBackgroundTaskRunner() {
131 return content::BrowserThread::GetBlockingPool() 141 return content::BrowserThread::GetBlockingPool()
132 ->GetTaskRunnerWithShutdownBehavior( 142 ->GetTaskRunnerWithShutdownBehavior(
133 base::SequencedWorkerPool::SKIP_ON_SHUTDOWN); 143 base::SequencedWorkerPool::SKIP_ON_SHUTDOWN);
134 } 144 }
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after
304 GURL signed_download_url(response->signed_download_url()); 314 GURL signed_download_url(response->signed_download_url());
305 if (!signed_download_url.is_valid() || response->package_name().empty()) { 315 if (!signed_download_url.is_valid() || response->package_name().empty()) {
306 OnFailure(); 316 OnFailure();
307 return; 317 return;
308 } 318 }
309 OnGotWebApkDownloadUrl(signed_download_url, response->package_name()); 319 OnGotWebApkDownloadUrl(signed_download_url, response->package_name());
310 } 320 }
311 321
312 void WebApkInstaller::DownloadAppIconAndComputeMurmur2Hash() { 322 void WebApkInstaller::DownloadAppIconAndComputeMurmur2Hash() {
313 // Safeguard. WebApkIconHasher crashes if asked to fetch an invalid URL. 323 // Safeguard. WebApkIconHasher crashes if asked to fetch an invalid URL.
314 if (!shortcut_info_.icon_url.is_valid()) { 324 if (!shortcut_info_.best_icon_url.is_valid()) {
315 OnFailure(); 325 OnFailure();
316 return; 326 return;
317 } 327 }
318 328
319 timer_.Start( 329 timer_.Start(
320 FROM_HERE, base::TimeDelta::FromMilliseconds(download_timeout_ms_), 330 FROM_HERE, base::TimeDelta::FromMilliseconds(download_timeout_ms_),
321 base::Bind(&WebApkInstaller::OnTimeout, weak_ptr_factory_.GetWeakPtr())); 331 base::Bind(&WebApkInstaller::OnTimeout, weak_ptr_factory_.GetWeakPtr()));
322 332
323 icon_hasher_.reset(new WebApkIconHasher()); 333 icon_hasher_.reset(new WebApkIconHasher());
324 icon_hasher_->DownloadAndComputeMurmur2Hash( 334 icon_hasher_->DownloadAndComputeMurmur2Hash(
325 request_context_getter_, shortcut_info_.icon_url, 335 request_context_getter_, shortcut_info_.best_icon_url,
326 base::Bind(&WebApkInstaller::OnGotIconMurmur2Hash, 336 base::Bind(&WebApkInstaller::OnGotIconMurmur2Hash,
327 weak_ptr_factory_.GetWeakPtr())); 337 weak_ptr_factory_.GetWeakPtr()));
328 } 338 }
329 339
330 void WebApkInstaller::OnGotIconMurmur2Hash( 340 void WebApkInstaller::OnGotIconMurmur2Hash(
331 const std::string& icon_murmur2_hash) { 341 const std::string& icon_murmur2_hash) {
332 timer_.Stop(); 342 timer_.Stop();
333 icon_hasher_.reset(); 343 icon_hasher_.reset();
334 344
335 shortcut_icon_murmur2_hash_ = icon_murmur2_hash; 345 shortcut_icon_murmur2_hash_ = icon_murmur2_hash;
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after
481 491
482 void WebApkInstaller::OnSuccess() { 492 void WebApkInstaller::OnSuccess() {
483 finish_callback_.Run(true, webapk_package_); 493 finish_callback_.Run(true, webapk_package_);
484 delete this; 494 delete this;
485 } 495 }
486 496
487 void WebApkInstaller::OnFailure() { 497 void WebApkInstaller::OnFailure() {
488 finish_callback_.Run(false, webapk_package_); 498 finish_callback_.Run(false, webapk_package_);
489 delete this; 499 delete this;
490 } 500 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698