OLD | NEW |
---|---|
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" |
11 #include "base/bind.h" | 11 #include "base/bind.h" |
12 #include "base/command_line.h" | 12 #include "base/command_line.h" |
13 #include "base/files/file_path.h" | 13 #include "base/files/file_path.h" |
14 #include "base/files/file_util.h" | 14 #include "base/files/file_util.h" |
15 #include "base/strings/string_util.h" | 15 #include "base/strings/string_util.h" |
16 #include "base/strings/stringprintf.h" | 16 #include "base/strings/stringprintf.h" |
17 #include "base/strings/utf_string_conversions.h" | 17 #include "base/strings/utf_string_conversions.h" |
18 #include "chrome/browser/android/shortcut_helper.h" | 18 #include "chrome/browser/android/shortcut_helper.h" |
19 #include "chrome/browser/android/webapk/webapk.pb.h" | 19 #include "chrome/browser/android/webapk/webapk.pb.h" |
20 #include "chrome/browser/profiles/profile.h" | 20 #include "chrome/browser/profiles/profile.h" |
21 #include "chrome/common/chrome_switches.h" | 21 #include "chrome/common/chrome_switches.h" |
22 #include "components/version_info/version_info.h" | 22 #include "components/version_info/version_info.h" |
23 #include "content/public/browser/browser_thread.h" | 23 #include "content/public/browser/browser_thread.h" |
24 #include "content/public/common/manifest_util.h" | 24 #include "content/public/common/manifest_util.h" |
25 #include "jni/WebApkInstaller_jni.h" | 25 #include "jni/WebApkInstaller_jni.h" |
26 #include "net/http/http_status_code.h" | 26 #include "net/http/http_status_code.h" |
27 #include "net/url_request/url_fetcher.h" | 27 #include "third_party/protobuf/src/google/protobuf/message_lite.h" |
28 #include "third_party/smhasher/src/MurmurHash2.h" | 28 #include "third_party/smhasher/src/MurmurHash2.h" |
29 #include "ui/gfx/codec/png_codec.h" | 29 #include "ui/gfx/codec/png_codec.h" |
30 #include "url/gurl.h" | 30 #include "url/gurl.h" |
31 | 31 |
32 namespace { | 32 namespace { |
33 | 33 |
34 // The default WebAPK server URL. | 34 // The default WebAPK server URL. |
35 const char kDefaultWebApkServerUrl[] = | 35 const char kDefaultWebApkServerUrl[] = |
36 "https://webapk.googleapis.com/v1alpha/webApks?alt=proto"; | 36 "https://webapk.googleapis.com/v1alpha/webApks/"; |
37 | |
38 // The response format type expected from WebAPK server. | |
39 const char kDefaultWebApkServerUrlResponseType[] = "?alt=proto"; | |
37 | 40 |
38 // The MIME type of the POST data sent to the server. | 41 // The MIME type of the POST data sent to the server. |
39 const char kProtoMimeType[] = "application/x-protobuf"; | 42 const char kProtoMimeType[] = "application/x-protobuf"; |
40 | 43 |
41 // The seed to use the murmur2 hash of the app icon. | 44 // The seed to use the murmur2 hash of the app icon. |
42 const uint32_t kMurmur2HashSeed = 0; | 45 const uint32_t kMurmur2HashSeed = 0; |
43 | 46 |
44 // The number of milliseconds to wait for the WebAPK download URL from the | 47 // The number of milliseconds to wait for the WebAPK download URL from the |
45 // WebAPK server. | 48 // WebAPK server. |
46 const int kWebApkDownloadUrlTimeoutMs = 4000; | 49 const int kWebApkDownloadUrlTimeoutMs = 4000; |
(...skipping 27 matching lines...) Expand all Loading... | |
74 double a = SkColorGetA(sk_color) / 255.0; | 77 double a = SkColorGetA(sk_color) / 255.0; |
75 return base::StringPrintf("rgba(%d,%d,%d,%.2f)", r, g, b, a); | 78 return base::StringPrintf("rgba(%d,%d,%d,%.2f)", r, g, b, a); |
76 } | 79 } |
77 | 80 |
78 } // anonymous namespace | 81 } // anonymous namespace |
79 | 82 |
80 WebApkInstaller::WebApkInstaller(const ShortcutInfo& shortcut_info, | 83 WebApkInstaller::WebApkInstaller(const ShortcutInfo& shortcut_info, |
81 const SkBitmap& shortcut_icon) | 84 const SkBitmap& shortcut_icon) |
82 : shortcut_info_(shortcut_info), | 85 : shortcut_info_(shortcut_info), |
83 shortcut_icon_(shortcut_icon), | 86 shortcut_icon_(shortcut_icon), |
87 taskType_(UNDEFINED), | |
pkotwicz
2016/08/08 18:59:16
Nit: Camel case for variables in C++ code
Xi Han
2016/08/08 21:25:05
Updated.
| |
84 io_weak_ptr_factory_(this) { | 88 io_weak_ptr_factory_(this) { |
85 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); | 89 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); |
86 server_url_ = | 90 server_url_ = |
87 GURL(command_line->HasSwitch(switches::kWebApkServerUrl) | 91 GURL(command_line->HasSwitch(switches::kWebApkServerUrl) |
88 ? command_line->GetSwitchValueASCII(switches::kWebApkServerUrl) | 92 ? command_line->GetSwitchValueASCII(switches::kWebApkServerUrl) |
89 : kDefaultWebApkServerUrl); | 93 : kDefaultWebApkServerUrl); |
90 } | 94 } |
91 | 95 |
92 WebApkInstaller::~WebApkInstaller() {} | 96 WebApkInstaller::~WebApkInstaller() {} |
93 | 97 |
94 void WebApkInstaller::InstallAsync(content::BrowserContext* browser_context, | 98 void WebApkInstaller::InstallAsync(content::BrowserContext* browser_context, |
95 const FinishCallback& finish_callback) { | 99 const FinishCallback& finish_callback) { |
96 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); | 100 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); |
97 finish_callback_ = finish_callback; | 101 finish_callback_ = finish_callback; |
102 taskType_ = INSTALL; | |
98 // base::Unretained() is safe because WebApkInstaller owns itself and does not | 103 // base::Unretained() is safe because WebApkInstaller owns itself and does not |
99 // start the timeout timer till after | 104 // start the timeout timer till after |
100 // InitializeRequestContextGetterOnUIThread() is called. | 105 // InitializeRequestContextGetterOnUIThread() is called. |
101 content::BrowserThread::PostTask( | 106 content::BrowserThread::PostTaskAndReply( |
102 content::BrowserThread::UI, FROM_HERE, | 107 content::BrowserThread::UI, FROM_HERE, |
103 base::Bind(&WebApkInstaller::InitializeRequestContextGetterOnUIThread, | 108 base::Bind(&WebApkInstaller::InitializeRequestContextGetterOnUIThread, |
104 base::Unretained(this), browser_context)); | 109 base::Unretained(this), browser_context), |
110 base::Bind(&WebApkInstaller::SendCreateWebApkRequest, | |
111 io_weak_ptr_factory_.GetWeakPtr())); | |
105 } | 112 } |
106 | 113 |
107 void WebApkInstaller::InstallAsyncWithURLRequestContextGetter( | 114 void WebApkInstaller::InstallAsyncWithURLRequestContextGetter( |
108 net::URLRequestContextGetter* request_context_getter, | 115 net::URLRequestContextGetter* request_context_getter, |
109 const FinishCallback& finish_callback) { | 116 const FinishCallback& finish_callback) { |
110 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); | 117 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); |
111 request_context_getter_ = request_context_getter; | 118 request_context_getter_ = request_context_getter; |
112 finish_callback_ = finish_callback; | 119 finish_callback_ = finish_callback; |
120 taskType_ = INSTALL; | |
113 | 121 |
114 SendCreateWebApkRequest(); | 122 SendCreateWebApkRequest(); |
115 } | 123 } |
116 | 124 |
125 void WebApkInstaller::UpdateAsync(content::BrowserContext* browser_context, | |
126 const FinishCallback& finish_callback, | |
127 const std::string& webapk_package, | |
128 int version) { | |
129 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); | |
130 finish_callback_ = finish_callback; | |
131 webapk_package_ = webapk_package; | |
132 version_ = version; | |
133 taskType_ = UPDATE; | |
134 // base::Unretained() is safe because WebApkInstaller owns itself and does not | |
135 // start the timeout timer till after | |
136 // InitializeRequestContextGetterOnUIThread() is called. | |
137 content::BrowserThread::PostTaskAndReply( | |
138 content::BrowserThread::UI, FROM_HERE, | |
139 base::Bind(&WebApkInstaller::InitializeRequestContextGetterOnUIThread, | |
140 base::Unretained(this), browser_context), | |
141 base::Bind(&WebApkInstaller::SendUpdateWebApkRequest, | |
142 io_weak_ptr_factory_.GetWeakPtr())); | |
143 } | |
144 | |
117 bool WebApkInstaller::StartDownloadedWebApkInstall( | 145 bool WebApkInstaller::StartDownloadedWebApkInstall( |
118 JNIEnv* env, | 146 JNIEnv* env, |
119 const base::android::ScopedJavaLocalRef<jstring>& java_file_path, | 147 const base::android::ScopedJavaLocalRef<jstring>& java_file_path, |
120 const base::android::ScopedJavaLocalRef<jstring>& java_package_name) { | 148 const base::android::ScopedJavaLocalRef<jstring>& java_package_name) { |
121 return Java_WebApkInstaller_installAsyncFromNative(env, java_file_path.obj(), | 149 if (taskType_ == INSTALL) { |
122 java_package_name.obj()); | 150 taskType_ = UNDEFINED; |
pkotwicz
2016/08/08 18:59:15
Nit: Don't bother resetting |task_type_|. If you w
Xi Han
2016/08/08 21:25:05
Removed.
| |
151 return Java_WebApkInstaller_installAsyncFromNative( | |
152 env, java_file_path.obj(), java_package_name.obj()); | |
153 } else if (taskType_ == UPDATE) { | |
154 taskType_ = UNDEFINED; | |
155 return Java_WebApkInstaller_updateAsyncFromNative( | |
pkotwicz
2016/08/08 18:59:16
Thank you for adding the Java calls for updating!
Xi Han
2016/08/08 21:25:05
Thanks for catching this! I missed the difference
| |
156 env, java_file_path.obj(), java_package_name.obj()); | |
157 } else { | |
158 return false; | |
159 } | |
123 } | 160 } |
124 | 161 |
125 void WebApkInstaller::OnURLFetchComplete(const net::URLFetcher* source) { | 162 void WebApkInstaller::OnURLFetchComplete(const net::URLFetcher* source) { |
126 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); | 163 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); |
127 timer_.Stop(); | 164 timer_.Stop(); |
128 | 165 |
129 if (!source->GetStatus().is_success() || | 166 if (!source->GetStatus().is_success() || |
130 source->GetResponseCode() != net::HTTP_OK) { | 167 source->GetResponseCode() != net::HTTP_OK) { |
131 OnFailure(); | 168 OnFailure(); |
132 return; | 169 return; |
133 } | 170 } |
134 | 171 |
135 std::string response_string; | 172 std::string response_string; |
136 source->GetResponseAsString(&response_string); | 173 source->GetResponseAsString(&response_string); |
137 | 174 |
138 std::unique_ptr<webapk::CreateWebApkResponse> response( | 175 std::unique_ptr<webapk::WebApkResponse> response( |
139 new webapk::CreateWebApkResponse); | 176 new webapk::WebApkResponse); |
140 if (!response->ParseFromString(response_string)) { | 177 if (!response->ParseFromString(response_string)) { |
141 OnFailure(); | 178 OnFailure(); |
142 return; | 179 return; |
143 } | 180 } |
144 | 181 |
145 if (response->signed_download_url().empty() || | 182 if (response->signed_download_url().empty() || |
146 response->webapk_package_name().empty()) { | 183 response->webapk_package_name().empty()) { |
147 OnFailure(); | 184 OnFailure(); |
148 return; | 185 return; |
149 } | 186 } |
150 OnGotWebApkDownloadUrl(response->signed_download_url(), | 187 OnGotWebApkDownloadUrl(response->signed_download_url(), |
151 response->webapk_package_name()); | 188 response->webapk_package_name()); |
152 } | 189 } |
153 | 190 |
154 void WebApkInstaller::InitializeRequestContextGetterOnUIThread( | 191 void WebApkInstaller::InitializeRequestContextGetterOnUIThread( |
155 content::BrowserContext* browser_context) { | 192 content::BrowserContext* browser_context) { |
156 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 193 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
157 // Profile::GetRequestContext() must be called on UI thread. | 194 // Profile::GetRequestContext() must be called on UI thread. |
158 request_context_getter_ = | 195 request_context_getter_ = |
159 Profile::FromBrowserContext(browser_context)->GetRequestContext(); | 196 Profile::FromBrowserContext(browser_context)->GetRequestContext(); |
160 | |
161 content::BrowserThread::PostTask( | |
162 content::BrowserThread::IO, FROM_HERE, | |
163 base::Bind(&WebApkInstaller::SendCreateWebApkRequest, | |
164 io_weak_ptr_factory_.GetWeakPtr())); | |
165 } | 197 } |
166 | 198 |
167 void WebApkInstaller::SendCreateWebApkRequest() { | 199 void WebApkInstaller::SendCreateWebApkRequest() { |
168 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); | 200 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); |
169 std::unique_ptr<webapk::CreateWebApkRequest> request = | |
170 BuildCreateWebApkRequest(); | |
171 | 201 |
202 std::unique_ptr<webapk::CreateWebApkRequest> request | |
203 = std::unique_ptr<webapk::CreateWebApkRequest>( | |
204 new webapk::CreateWebApkRequest); | |
205 | |
206 PopulateWebApkProto(request->mutable_webapk()); | |
207 // The WebAPK server URL to download and install a WebAPK is: | |
208 // |server_url_| + |kDeaultWebApkServerUrlResponseType|. | |
209 GURL server_url(server_url_.spec() + kDefaultWebApkServerUrlResponseType); | |
210 SendRequest(std::move(request), net::URLFetcher::POST, server_url); | |
211 } | |
212 | |
213 void WebApkInstaller::SendUpdateWebApkRequest() { | |
214 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); | |
215 | |
pkotwicz
2016/08/08 18:59:15
The server expects a webapk::WebApk proto not a we
Xi Han
2016/08/08 21:25:05
I thought there was technical issue that we need t
| |
216 std::unique_ptr<webapk::UpdateWebApkRequest> request | |
217 = std::unique_ptr<webapk::UpdateWebApkRequest>( | |
218 new webapk::UpdateWebApkRequest); | |
219 | |
220 webapk::WebApk* webapk = request->mutable_webapk(); | |
221 PopulateWebApkProto(webapk); | |
222 webapk->set_package_name(webapk_package_); | |
223 webapk->set_version(std::to_string(version_)); | |
224 // The WebAPK server URL to download and update a WebAPK is: | |
225 // |server_url_| + |WebAPK package name| + "/" | |
226 // + |kDeaultWebApkServerUrlResponseType| | |
227 GURL server_url(server_url_.spec() + webapk_package_ + "/" | |
228 + kDefaultWebApkServerUrlResponseType); | |
pkotwicz
2016/08/08 18:59:15
Glenn can you comment? I thought the server URL wo
hartmanng
2016/08/08 19:09:51
Xi is correct - the server currently expects "<hos
hartmanng
2016/08/08 19:10:49
Sorry, the period above was a typo, I really meant
Xi Han
2016/08/08 21:25:05
Thank you Glenn for clarifying the url.
| |
229 SendRequest(std::move(request), net::URLFetcher::PUT, server_url); | |
pkotwicz
2016/08/08 18:59:15
I am unsure whether we want to use PUT here. Are P
hartmanng
2016/08/08 19:09:50
Again, this is what the server is expecting curren
| |
230 } | |
231 | |
232 void WebApkInstaller::SendRequest( | |
233 std::unique_ptr<::google::protobuf::MessageLite> request_proto, | |
234 net::URLFetcher::RequestType request_type, | |
235 const GURL& server_url) { | |
172 timer_.Start(FROM_HERE, | 236 timer_.Start(FROM_HERE, |
173 base::TimeDelta::FromMilliseconds(kWebApkDownloadUrlTimeoutMs), | 237 base::TimeDelta::FromMilliseconds(kWebApkDownloadUrlTimeoutMs), |
174 base::Bind(&WebApkInstaller::OnTimeout, | 238 base::Bind(&WebApkInstaller::OnTimeout, |
175 io_weak_ptr_factory_.GetWeakPtr())); | 239 io_weak_ptr_factory_.GetWeakPtr())); |
176 | 240 |
177 url_fetcher_ = | 241 url_fetcher_ = |
178 net::URLFetcher::Create(server_url_, net::URLFetcher::POST, this); | 242 net::URLFetcher::Create(server_url, request_type, this); |
179 url_fetcher_->SetRequestContext(request_context_getter_); | 243 url_fetcher_->SetRequestContext(request_context_getter_); |
180 std::string serialized_request; | 244 std::string serialized_request; |
181 request->SerializeToString(&serialized_request); | 245 request_proto->SerializeToString(&serialized_request); |
182 url_fetcher_->SetUploadData(kProtoMimeType, serialized_request); | 246 url_fetcher_->SetUploadData(kProtoMimeType, serialized_request); |
183 url_fetcher_->Start(); | 247 url_fetcher_->Start(); |
184 } | 248 } |
185 | 249 |
186 void WebApkInstaller::OnGotWebApkDownloadUrl(const std::string& download_url, | 250 void WebApkInstaller::OnGotWebApkDownloadUrl(const std::string& download_url, |
187 const std::string& package_name) { | 251 const std::string& package_name) { |
188 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); | 252 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); |
189 | 253 |
190 base::FilePath output_dir; | 254 base::FilePath output_dir; |
191 base::android::GetCacheDirectory(&output_dir); | 255 base::android::GetCacheDirectory(&output_dir); |
192 // TODO(pkotwicz): Download WebAPKs into WebAPK-specific subdirectory | 256 // TODO(pkotwicz): Download WebAPKs into WebAPK-specific subdirectory |
193 // directory. | 257 // directory. |
194 // TODO(pkotwicz): Figure out when downloaded WebAPK should be deleted. | 258 // TODO(pkotwicz): Figure out when downloaded WebAPK should be deleted. |
195 | 259 |
196 timer_.Start(FROM_HERE, base::TimeDelta::FromMilliseconds(kDownloadTimeoutMs), | 260 timer_.Start(FROM_HERE, base::TimeDelta::FromMilliseconds(kDownloadTimeoutMs), |
197 base::Bind(&WebApkInstaller::OnTimeout, | 261 base::Bind(&WebApkInstaller::OnTimeout, |
198 io_weak_ptr_factory_.GetWeakPtr())); | 262 io_weak_ptr_factory_.GetWeakPtr())); |
199 | 263 |
200 base::FilePath output_path = output_dir.AppendASCII(package_name); | 264 base::FilePath output_path = output_dir.AppendASCII(package_name); |
201 downloader_.reset(new FileDownloader( | 265 downloader_.reset(new FileDownloader( |
202 GURL(download_url), output_path, true, request_context_getter_, | 266 GURL(download_url), output_path, true, request_context_getter_, |
203 base::Bind(&WebApkInstaller::OnWebApkDownloaded, | 267 base::Bind(&WebApkInstaller::OnWebApkDownloaded, |
204 io_weak_ptr_factory_.GetWeakPtr(), output_path, | 268 io_weak_ptr_factory_.GetWeakPtr(), output_path, |
205 package_name))); | 269 package_name))); |
206 } | 270 } |
207 | 271 |
208 void WebApkInstaller::OnWebApkDownloaded(const base::FilePath& file_path, | 272 void WebApkInstaller::OnWebApkDownloaded(const base::FilePath& file_path, |
209 const std::string& package_name, | 273 const std::string& package_name, |
210 FileDownloader::Result result) { | 274 FileDownloader::Result result) { |
211 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); | 275 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); |
212 | 276 |
213 timer_.Stop(); | 277 timer_.Stop(); |
214 | 278 |
215 if (result != FileDownloader::DOWNLOADED) { | 279 if (result != FileDownloader::DOWNLOADED) { |
216 OnFailure(); | 280 OnFailure(); |
217 return; | 281 return; |
218 } | 282 } |
219 | 283 |
220 JNIEnv* env = base::android::AttachCurrentThread(); | 284 JNIEnv* env = base::android::AttachCurrentThread(); |
221 base::android::ScopedJavaLocalRef<jstring> java_file_path = | 285 base::android::ScopedJavaLocalRef<jstring> java_file_path = |
222 base::android::ConvertUTF8ToJavaString(env, file_path.value()); | 286 base::android::ConvertUTF8ToJavaString(env, file_path.value()); |
223 base::android::ScopedJavaLocalRef<jstring> java_package_name = | 287 base::android::ScopedJavaLocalRef<jstring> java_package_name = |
224 base::android::ConvertUTF8ToJavaString(env, package_name); | 288 base::android::ConvertUTF8ToJavaString(env, package_name); |
225 bool success = | 289 bool success = |
226 StartDownloadedWebApkInstall(env, java_file_path, java_package_name); | 290 StartDownloadedWebApkInstall(env, java_file_path, java_package_name); |
227 if (success) | 291 if (success) |
228 OnSuccess(); | 292 OnSuccess(); |
229 else | 293 else |
230 OnFailure(); | 294 OnFailure(); |
231 } | 295 } |
232 | 296 |
233 std::unique_ptr<webapk::CreateWebApkRequest> | 297 void WebApkInstaller::PopulateWebApkProto(webapk::WebApk* webapk) { |
234 WebApkInstaller::BuildCreateWebApkRequest() { | |
235 std::unique_ptr<webapk::CreateWebApkRequest> request( | |
236 new webapk::CreateWebApkRequest); | |
237 | |
238 webapk::WebApk* webapk = request->mutable_webapk(); | |
239 webapk->set_manifest_url(shortcut_info_.manifest_url.spec()); | 298 webapk->set_manifest_url(shortcut_info_.manifest_url.spec()); |
240 webapk->set_requester_application_package( | 299 webapk->set_requester_application_package( |
241 base::android::BuildInfo::GetInstance()->package_name()); | 300 base::android::BuildInfo::GetInstance()->package_name()); |
242 webapk->set_requester_application_version(version_info::GetVersionNumber()); | 301 webapk->set_requester_application_version(version_info::GetVersionNumber()); |
243 | 302 |
244 webapk::WebAppManifest* web_app_manifest = webapk->mutable_manifest(); | 303 webapk::WebAppManifest* web_app_manifest = webapk->mutable_manifest(); |
245 web_app_manifest->set_name(base::UTF16ToUTF8(shortcut_info_.name)); | 304 web_app_manifest->set_name(base::UTF16ToUTF8(shortcut_info_.name)); |
246 web_app_manifest->set_short_name( | 305 web_app_manifest->set_short_name( |
247 base::UTF16ToUTF8(shortcut_info_.short_name)); | 306 base::UTF16ToUTF8(shortcut_info_.short_name)); |
248 web_app_manifest->set_start_url(shortcut_info_.url.spec()); | 307 web_app_manifest->set_start_url(shortcut_info_.url.spec()); |
249 web_app_manifest->set_orientation( | 308 web_app_manifest->set_orientation( |
250 content::WebScreenOrientationLockTypeToString( | 309 content::WebScreenOrientationLockTypeToString( |
251 shortcut_info_.orientation)); | 310 shortcut_info_.orientation)); |
252 web_app_manifest->set_display_mode( | 311 web_app_manifest->set_display_mode( |
253 content::WebDisplayModeToString(shortcut_info_.display)); | 312 content::WebDisplayModeToString(shortcut_info_.display)); |
254 web_app_manifest->set_background_color( | 313 web_app_manifest->set_background_color( |
255 ColorToString(shortcut_info_.background_color)); | 314 ColorToString(shortcut_info_.background_color)); |
256 web_app_manifest->set_theme_color(ColorToString(shortcut_info_.theme_color)); | 315 web_app_manifest->set_theme_color(ColorToString(shortcut_info_.theme_color)); |
257 | 316 |
258 std::string* scope = web_app_manifest->add_scopes(); | 317 std::string* scope = web_app_manifest->add_scopes(); |
259 scope->assign(GetScope(shortcut_info_).spec()); | 318 scope->assign(GetScope(shortcut_info_).spec()); |
260 webapk::Image* image = web_app_manifest->add_icons(); | 319 webapk::Image* image = web_app_manifest->add_icons(); |
261 image->set_src(shortcut_info_.icon_url.spec()); | 320 image->set_src(shortcut_info_.icon_url.spec()); |
262 // TODO(pkotwicz): Get Murmur2 hash of untransformed icon's bytes (with no | 321 // TODO(pkotwicz): Get Murmur2 hash of untransformed icon's bytes (with no |
263 // encoding/decoding). | 322 // encoding/decoding). |
264 image->set_hash(ComputeBitmapHash(shortcut_icon_)); | 323 image->set_hash(ComputeBitmapHash(shortcut_icon_)); |
265 std::vector<unsigned char> png_bytes; | 324 std::vector<unsigned char> png_bytes; |
266 gfx::PNGCodec::EncodeBGRASkBitmap(shortcut_icon_, false, &png_bytes); | 325 gfx::PNGCodec::EncodeBGRASkBitmap(shortcut_icon_, false, &png_bytes); |
267 image->set_image_data(&png_bytes.front(), png_bytes.size()); | 326 image->set_image_data(&png_bytes.front(), png_bytes.size()); |
268 | |
269 return request; | |
270 } | 327 } |
271 | 328 |
272 void WebApkInstaller::OnTimeout() { | 329 void WebApkInstaller::OnTimeout() { |
273 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); | 330 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); |
274 OnFailure(); | 331 OnFailure(); |
275 } | 332 } |
276 | 333 |
277 void WebApkInstaller::OnSuccess() { | 334 void WebApkInstaller::OnSuccess() { |
278 finish_callback_.Run(true); | 335 finish_callback_.Run(true); |
279 delete this; | 336 delete this; |
280 } | 337 } |
281 | 338 |
282 void WebApkInstaller::OnFailure() { | 339 void WebApkInstaller::OnFailure() { |
283 finish_callback_.Run(false); | 340 finish_callback_.Run(false); |
284 delete this; | 341 delete this; |
285 } | 342 } |
OLD | NEW |