| 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_number_conversions.h" | 15 #include "base/strings/string_number_conversions.h" |
| 16 #include "base/strings/string_util.h" | 16 #include "base/strings/string_util.h" |
| 17 #include "base/strings/stringprintf.h" | 17 #include "base/strings/stringprintf.h" |
| 18 #include "base/strings/utf_string_conversions.h" | 18 #include "base/strings/utf_string_conversions.h" |
| 19 #include "chrome/browser/android/shortcut_helper.h" | 19 #include "chrome/browser/android/shortcut_helper.h" |
| 20 #include "chrome/browser/android/webapk/webapk.pb.h" | 20 #include "chrome/browser/android/webapk/webapk.pb.h" |
| 21 #include "chrome/browser/profiles/profile.h" | 21 #include "chrome/browser/profiles/profile.h" |
| 22 #include "chrome/common/chrome_switches.h" | 22 #include "chrome/common/chrome_switches.h" |
| 23 #include "components/version_info/version_info.h" | 23 #include "components/version_info/version_info.h" |
| 24 #include "content/public/browser/browser_thread.h" | 24 #include "content/public/browser/browser_thread.h" |
| 25 #include "content/public/common/manifest_util.h" |
| 25 #include "jni/WebApkInstaller_jni.h" | 26 #include "jni/WebApkInstaller_jni.h" |
| 26 #include "net/http/http_status_code.h" | 27 #include "net/http/http_status_code.h" |
| 27 #include "net/url_request/url_fetcher.h" | 28 #include "net/url_request/url_fetcher.h" |
| 28 #include "third_party/smhasher/src/MurmurHash2.h" | 29 #include "third_party/smhasher/src/MurmurHash2.h" |
| 29 #include "ui/gfx/codec/png_codec.h" | 30 #include "ui/gfx/codec/png_codec.h" |
| 30 #include "url/gurl.h" | 31 #include "url/gurl.h" |
| 31 | 32 |
| 32 namespace { | 33 namespace { |
| 33 | 34 |
| 34 // The default WebAPK server URL. | 35 // The default WebAPK server URL. |
| (...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 246 webapk->set_manifest_url(shortcut_info_.manifest_url.spec()); | 247 webapk->set_manifest_url(shortcut_info_.manifest_url.spec()); |
| 247 webapk->set_requester_application_package( | 248 webapk->set_requester_application_package( |
| 248 base::android::BuildInfo::GetInstance()->package_name()); | 249 base::android::BuildInfo::GetInstance()->package_name()); |
| 249 webapk->set_requester_application_version(version_info::GetVersionNumber()); | 250 webapk->set_requester_application_version(version_info::GetVersionNumber()); |
| 250 | 251 |
| 251 webapk::WebAppManifest* web_app_manifest = webapk->mutable_manifest(); | 252 webapk::WebAppManifest* web_app_manifest = webapk->mutable_manifest(); |
| 252 web_app_manifest->set_name(base::UTF16ToUTF8(shortcut_info_.name)); | 253 web_app_manifest->set_name(base::UTF16ToUTF8(shortcut_info_.name)); |
| 253 web_app_manifest->set_short_name( | 254 web_app_manifest->set_short_name( |
| 254 base::UTF16ToUTF8(shortcut_info_.short_name)); | 255 base::UTF16ToUTF8(shortcut_info_.short_name)); |
| 255 web_app_manifest->set_start_url(shortcut_info_.url.spec()); | 256 web_app_manifest->set_start_url(shortcut_info_.url.spec()); |
| 256 // TODO(pkotwicz): Add "display mode" and "orientation" to proto. | 257 web_app_manifest->set_orientation( |
| 258 content::WebScreenOrientationLockTypeToString( |
| 259 shortcut_info_.orientation)); |
| 260 web_app_manifest->set_display_mode( |
| 261 content::WebDisplayModeToString(shortcut_info_.display)); |
| 257 web_app_manifest->set_background_color( | 262 web_app_manifest->set_background_color( |
| 258 ColorToString(shortcut_info_.background_color)); | 263 ColorToString(shortcut_info_.background_color)); |
| 259 web_app_manifest->set_theme_color(ColorToString(shortcut_info_.theme_color)); | 264 web_app_manifest->set_theme_color(ColorToString(shortcut_info_.theme_color)); |
| 260 | 265 |
| 261 std::string* scope = web_app_manifest->add_scopes(); | 266 std::string* scope = web_app_manifest->add_scopes(); |
| 262 scope->assign(GetScope(shortcut_info_).spec()); | 267 scope->assign(GetScope(shortcut_info_).spec()); |
| 263 webapk::Image* image = web_app_manifest->add_icons(); | 268 webapk::Image* image = web_app_manifest->add_icons(); |
| 264 image->set_src(shortcut_info_.icon_url.spec()); | 269 image->set_src(shortcut_info_.icon_url.spec()); |
| 265 // TODO(pkotwicz): Get Murmur2 hash of untransformed icon's bytes (with no | 270 // TODO(pkotwicz): Get Murmur2 hash of untransformed icon's bytes (with no |
| 266 // encoding/decoding). | 271 // encoding/decoding). |
| (...skipping 12 matching lines...) Expand all Loading... |
| 279 | 284 |
| 280 void WebApkInstaller::OnSuccess() { | 285 void WebApkInstaller::OnSuccess() { |
| 281 finish_callback_.Run(true); | 286 finish_callback_.Run(true); |
| 282 delete this; | 287 delete this; |
| 283 } | 288 } |
| 284 | 289 |
| 285 void WebApkInstaller::OnFailure() { | 290 void WebApkInstaller::OnFailure() { |
| 286 finish_callback_.Run(false); | 291 finish_callback_.Run(false); |
| 287 delete this; | 292 delete this; |
| 288 } | 293 } |
| OLD | NEW |