Chromium Code Reviews| 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 <stdlib.h> | |
| 8 | |
| 7 #include "base/android/build_info.h" | 9 #include "base/android/build_info.h" |
| 8 #include "base/android/jni_android.h" | 10 #include "base/android/jni_android.h" |
| 9 #include "base/android/jni_string.h" | 11 #include "base/android/jni_string.h" |
| 10 #include "base/android/path_utils.h" | 12 #include "base/android/path_utils.h" |
| 11 #include "base/bind.h" | 13 #include "base/bind.h" |
| 12 #include "base/files/file_path.h" | 14 #include "base/files/file_path.h" |
| 13 #include "base/files/file_util.h" | 15 #include "base/files/file_util.h" |
| 14 #include "base/memory/ref_counted.h" | 16 #include "base/memory/ref_counted.h" |
| 15 #include "base/strings/string_util.h" | 17 #include "base/strings/string_util.h" |
| 16 #include "base/strings/stringprintf.h" | 18 #include "base/strings/stringprintf.h" |
| 17 #include "base/strings/utf_string_conversions.h" | 19 #include "base/strings/utf_string_conversions.h" |
| 18 #include "base/task_runner_util.h" | 20 #include "base/task_runner_util.h" |
| 19 #include "base/threading/sequenced_worker_pool.h" | 21 #include "base/threading/sequenced_worker_pool.h" |
| 20 #include "chrome/browser/android/chrome_feature_list.h" | 22 #include "chrome/browser/android/chrome_feature_list.h" |
| 21 #include "chrome/browser/android/shortcut_helper.h" | 23 #include "chrome/browser/android/shortcut_helper.h" |
| 22 #include "chrome/browser/android/webapk/webapk.pb.h" | 24 #include "chrome/browser/android/webapk/webapk.pb.h" |
| 23 #include "chrome/browser/android/webapk/webapk_icon_hasher.h" | 25 #include "chrome/browser/android/webapk/webapk_icon_hasher.h" |
| 24 #include "chrome/browser/profiles/profile.h" | 26 #include "chrome/browser/profiles/profile.h" |
| 27 #include "chrome/common/chrome_switches.h" | |
| 25 #include "components/variations/variations_associated_data.h" | 28 #include "components/variations/variations_associated_data.h" |
| 26 #include "components/version_info/version_info.h" | 29 #include "components/version_info/version_info.h" |
| 27 #include "content/public/browser/browser_thread.h" | 30 #include "content/public/browser/browser_thread.h" |
| 28 #include "content/public/common/manifest_util.h" | 31 #include "content/public/common/manifest_util.h" |
| 29 #include "jni/WebApkInstaller_jni.h" | 32 #include "jni/WebApkInstaller_jni.h" |
| 30 #include "net/http/http_status_code.h" | 33 #include "net/http/http_status_code.h" |
| 31 #include "net/url_request/url_fetcher.h" | 34 #include "net/url_request/url_fetcher.h" |
| 32 #include "ui/gfx/codec/png_codec.h" | 35 #include "ui/gfx/codec/png_codec.h" |
| 33 #include "url/gurl.h" | 36 #include "url/gurl.h" |
| 34 | 37 |
| (...skipping 299 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 334 if (!response->ParseFromString(response_string)) { | 337 if (!response->ParseFromString(response_string)) { |
| 335 OnFailure(); | 338 OnFailure(); |
| 336 return; | 339 return; |
| 337 } | 340 } |
| 338 | 341 |
| 339 GURL signed_download_url(response->signed_download_url()); | 342 GURL signed_download_url(response->signed_download_url()); |
| 340 if (!signed_download_url.is_valid() || response->package_name().empty()) { | 343 if (!signed_download_url.is_valid() || response->package_name().empty()) { |
| 341 OnFailure(); | 344 OnFailure(); |
| 342 return; | 345 return; |
| 343 } | 346 } |
| 347 | |
| 348 if (base::FeatureList::IsEnabled(chrome::android::kPlayInstallWebApks)){ | |
| 349 InstallWebApkFromPlayStore(response->package_name(), | |
| 350 std::atoi(response->version().c_str()), | |
| 351 response->token()); | |
|
pkotwicz
2016/11/24 22:59:20
Ideally, Google Play installs will work when:
- Go
| |
| 352 return; | |
| 353 } | |
| 354 | |
| 344 OnGotWebApkDownloadUrl(signed_download_url, response->package_name()); | 355 OnGotWebApkDownloadUrl(signed_download_url, response->package_name()); |
| 345 } | 356 } |
| 346 | 357 |
| 347 void WebApkInstaller::DownloadAppIconAndComputeMurmur2Hash() { | 358 void WebApkInstaller::DownloadAppIconAndComputeMurmur2Hash() { |
| 348 // Safeguard. WebApkIconHasher crashes if asked to fetch an invalid URL. | 359 // Safeguard. WebApkIconHasher crashes if asked to fetch an invalid URL. |
| 349 if (!shortcut_info_.best_icon_url.is_valid()) { | 360 if (!shortcut_info_.best_icon_url.is_valid()) { |
| 350 OnFailure(); | 361 OnFailure(); |
| 351 return; | 362 return; |
| 352 } | 363 } |
| 353 | 364 |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 405 | 416 |
| 406 url_fetcher_ = | 417 url_fetcher_ = |
| 407 net::URLFetcher::Create(server_url, net::URLFetcher::POST, this); | 418 net::URLFetcher::Create(server_url, net::URLFetcher::POST, this); |
| 408 url_fetcher_->SetRequestContext(request_context_getter_); | 419 url_fetcher_->SetRequestContext(request_context_getter_); |
| 409 std::string serialized_request; | 420 std::string serialized_request; |
| 410 request_proto->SerializeToString(&serialized_request); | 421 request_proto->SerializeToString(&serialized_request); |
| 411 url_fetcher_->SetUploadData(kProtoMimeType, serialized_request); | 422 url_fetcher_->SetUploadData(kProtoMimeType, serialized_request); |
| 412 url_fetcher_->Start(); | 423 url_fetcher_->Start(); |
| 413 } | 424 } |
| 414 | 425 |
| 426 void WebApkInstaller::InstallWebApkFromPlayStore( | |
| 427 const std::string& package_name, int version, const std::string& token) { | |
| 428 webapk_package_ = package_name; | |
| 429 | |
| 430 JNIEnv* env = base::android::AttachCurrentThread(); | |
| 431 base::android::ScopedJavaLocalRef<jstring> java_webapk_package = | |
| 432 base::android::ConvertUTF8ToJavaString(env, webapk_package_); | |
| 433 base::android::ScopedJavaLocalRef<jstring> java_title = | |
| 434 base::android::ConvertUTF16ToJavaString(env, shortcut_info_.user_title); | |
| 435 base::android::ScopedJavaLocalRef<jstring> java_token = | |
| 436 base::android::ConvertUTF8ToJavaString(env, token); | |
| 437 | |
| 438 Java_WebApkInstaller_installWebApkFromPlayStoreAsyncAndMonitorInstallation( | |
| 439 env, java_ref_, java_webapk_package, version, java_title, java_token); | |
| 440 } | |
| 441 | |
| 415 void WebApkInstaller::OnGotWebApkDownloadUrl(const GURL& download_url, | 442 void WebApkInstaller::OnGotWebApkDownloadUrl(const GURL& download_url, |
| 416 const std::string& package_name) { | 443 const std::string& package_name) { |
| 417 webapk_package_ = package_name; | 444 webapk_package_ = package_name; |
| 418 | 445 |
| 419 base::PostTaskAndReplyWithResult( | 446 base::PostTaskAndReplyWithResult( |
| 420 GetBackgroundTaskRunner().get(), FROM_HERE, | 447 GetBackgroundTaskRunner().get(), FROM_HERE, |
| 421 base::Bind(&CreateSubDirAndSetPermissionsInBackground, | 448 base::Bind(&CreateSubDirAndSetPermissionsInBackground, |
| 422 task_type_ == WebApkInstaller::INSTALL ? "install" : "update", | 449 task_type_ == WebApkInstaller::INSTALL ? "install" : "update", |
| 423 package_name), | 450 package_name), |
| 424 base::Bind(&WebApkInstaller::OnCreatedSubDirAndSetPermissions, | 451 base::Bind(&WebApkInstaller::OnCreatedSubDirAndSetPermissions, |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 517 | 544 |
| 518 void WebApkInstaller::OnSuccess() { | 545 void WebApkInstaller::OnSuccess() { |
| 519 finish_callback_.Run(true, webapk_package_); | 546 finish_callback_.Run(true, webapk_package_); |
| 520 delete this; | 547 delete this; |
| 521 } | 548 } |
| 522 | 549 |
| 523 void WebApkInstaller::OnFailure() { | 550 void WebApkInstaller::OnFailure() { |
| 524 finish_callback_.Run(false, webapk_package_); | 551 finish_callback_.Run(false, webapk_package_); |
| 525 delete this; | 552 delete this; |
| 526 } | 553 } |
| OLD | NEW |