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

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: pkotwicz@'s comments. 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 // TODO(hanxi): crbug.com/665078. Add a flag in WebAPK's proto to indicate
104 // that the Web Manifest is staled.
pkotwicz 2016/11/14 22:43:11 How about: "crbug.com/665078. Add a flag in WebAPK
Xi Han 2016/11/15 20:07:08 Done.
105 if (shortcut_icon_murmur2_hash.empty())
106 return webapk;
107
103 webapk::WebAppManifest* web_app_manifest = webapk->mutable_manifest(); 108 webapk::WebAppManifest* web_app_manifest = webapk->mutable_manifest();
104 web_app_manifest->set_name(base::UTF16ToUTF8(shortcut_info.name)); 109 web_app_manifest->set_name(base::UTF16ToUTF8(shortcut_info.name));
105 web_app_manifest->set_short_name( 110 web_app_manifest->set_short_name(
106 base::UTF16ToUTF8(shortcut_info.short_name)); 111 base::UTF16ToUTF8(shortcut_info.short_name));
107 web_app_manifest->set_start_url(shortcut_info.url.spec()); 112 web_app_manifest->set_start_url(shortcut_info.url.spec());
108 web_app_manifest->set_orientation( 113 web_app_manifest->set_orientation(
109 content::WebScreenOrientationLockTypeToString( 114 content::WebScreenOrientationLockTypeToString(
110 shortcut_info.orientation)); 115 shortcut_info.orientation));
111 web_app_manifest->set_display_mode( 116 web_app_manifest->set_display_mode(
112 content::WebDisplayModeToString(shortcut_info.display)); 117 content::WebDisplayModeToString(shortcut_info.display));
113 web_app_manifest->set_background_color( 118 web_app_manifest->set_background_color(
114 ColorToString(shortcut_info.background_color)); 119 ColorToString(shortcut_info.background_color));
115 web_app_manifest->set_theme_color(ColorToString(shortcut_info.theme_color)); 120 web_app_manifest->set_theme_color(ColorToString(shortcut_info.theme_color));
116 121
117 std::string* scope = web_app_manifest->add_scopes(); 122 std::string* scope = web_app_manifest->add_scopes();
118 scope->assign(GetScope(shortcut_info).spec()); 123 scope->assign(GetScope(shortcut_info).spec());
119 webapk::Image* image = web_app_manifest->add_icons(); 124
120 image->set_src(shortcut_info.icon_url.spec()); 125 webapk::Image* best_image = web_app_manifest->add_icons();
121 image->set_hash(shortcut_icon_murmur2_hash); 126 best_image->set_src(shortcut_info.best_icon_url.spec());
127 best_image->set_hash(shortcut_icon_murmur2_hash);
122 std::vector<unsigned char> png_bytes; 128 std::vector<unsigned char> png_bytes;
123 gfx::PNGCodec::EncodeBGRASkBitmap(shortcut_icon, false, &png_bytes); 129 gfx::PNGCodec::EncodeBGRASkBitmap(shortcut_icon, false, &png_bytes);
124 image->set_image_data(&png_bytes.front(), png_bytes.size()); 130 best_image->set_image_data(&png_bytes.front(), png_bytes.size());
131
132 for (const GURL& icon_url : shortcut_info.icon_urls) {
133 if (icon_url == shortcut_info.best_icon_url)
134 continue;
135 webapk::Image* image = web_app_manifest->add_icons();
136 image->set_src(icon_url.spec());
137 }
125 138
126 return webapk; 139 return webapk;
127 } 140 }
128 141
129 // Returns task runner for running background tasks. 142 // Returns task runner for running background tasks.
130 scoped_refptr<base::TaskRunner> GetBackgroundTaskRunner() { 143 scoped_refptr<base::TaskRunner> GetBackgroundTaskRunner() {
131 return content::BrowserThread::GetBlockingPool() 144 return content::BrowserThread::GetBlockingPool()
132 ->GetTaskRunnerWithShutdownBehavior( 145 ->GetTaskRunnerWithShutdownBehavior(
133 base::SequencedWorkerPool::SKIP_ON_SHUTDOWN); 146 base::SequencedWorkerPool::SKIP_ON_SHUTDOWN);
134 } 147 }
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after
304 GURL signed_download_url(response->signed_download_url()); 317 GURL signed_download_url(response->signed_download_url());
305 if (!signed_download_url.is_valid() || response->package_name().empty()) { 318 if (!signed_download_url.is_valid() || response->package_name().empty()) {
306 OnFailure(); 319 OnFailure();
307 return; 320 return;
308 } 321 }
309 OnGotWebApkDownloadUrl(signed_download_url, response->package_name()); 322 OnGotWebApkDownloadUrl(signed_download_url, response->package_name());
310 } 323 }
311 324
312 void WebApkInstaller::DownloadAppIconAndComputeMurmur2Hash() { 325 void WebApkInstaller::DownloadAppIconAndComputeMurmur2Hash() {
313 // Safeguard. WebApkIconHasher crashes if asked to fetch an invalid URL. 326 // Safeguard. WebApkIconHasher crashes if asked to fetch an invalid URL.
314 if (!shortcut_info_.icon_url.is_valid()) { 327 if (!shortcut_info_.best_icon_url.is_valid()) {
315 OnFailure(); 328 OnFailure();
316 return; 329 return;
317 } 330 }
318 331
319 timer_.Start( 332 timer_.Start(
320 FROM_HERE, base::TimeDelta::FromMilliseconds(download_timeout_ms_), 333 FROM_HERE, base::TimeDelta::FromMilliseconds(download_timeout_ms_),
321 base::Bind(&WebApkInstaller::OnTimeout, weak_ptr_factory_.GetWeakPtr())); 334 base::Bind(&WebApkInstaller::OnTimeout, weak_ptr_factory_.GetWeakPtr()));
322 335
323 icon_hasher_.reset(new WebApkIconHasher()); 336 icon_hasher_.reset(new WebApkIconHasher());
324 icon_hasher_->DownloadAndComputeMurmur2Hash( 337 icon_hasher_->DownloadAndComputeMurmur2Hash(
325 request_context_getter_, shortcut_info_.icon_url, 338 request_context_getter_, shortcut_info_.best_icon_url,
326 base::Bind(&WebApkInstaller::OnGotIconMurmur2Hash, 339 base::Bind(&WebApkInstaller::OnGotIconMurmur2Hash,
327 weak_ptr_factory_.GetWeakPtr())); 340 weak_ptr_factory_.GetWeakPtr()));
328 } 341 }
329 342
330 void WebApkInstaller::OnGotIconMurmur2Hash( 343 void WebApkInstaller::OnGotIconMurmur2Hash(
331 const std::string& icon_murmur2_hash) { 344 const std::string& icon_murmur2_hash) {
332 timer_.Stop(); 345 timer_.Stop();
333 icon_hasher_.reset(); 346 icon_hasher_.reset();
334 347
335 shortcut_icon_murmur2_hash_ = icon_murmur2_hash; 348 shortcut_icon_murmur2_hash_ = icon_murmur2_hash;
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after
482 495
483 void WebApkInstaller::OnSuccess() { 496 void WebApkInstaller::OnSuccess() {
484 finish_callback_.Run(true, webapk_package_); 497 finish_callback_.Run(true, webapk_package_);
485 delete this; 498 delete this;
486 } 499 }
487 500
488 void WebApkInstaller::OnFailure() { 501 void WebApkInstaller::OnFailure() {
489 finish_callback_.Run(false, webapk_package_); 502 finish_callback_.Run(false, webapk_package_);
490 delete this; 503 delete this;
491 } 504 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698