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/manifest_upgrade_detector_fetcher.h" | 5 #include "chrome/browser/android/webapk/manifest_upgrade_detector_fetcher.h" |
| 6 | 6 |
| 7 #include <jni.h> | 7 #include <jni.h> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/android/jni_array.h" | |
| 10 #include "base/android/jni_string.h" | 11 #include "base/android/jni_string.h" |
| 11 #include "chrome/browser/android/shortcut_helper.h" | 12 #include "chrome/browser/android/shortcut_helper.h" |
| 12 #include "chrome/browser/android/webapk/webapk_icon_hasher.h" | 13 #include "chrome/browser/android/webapk/webapk_icon_hasher.h" |
| 13 #include "chrome/browser/android/webapk/webapk_web_manifest_checker.h" | 14 #include "chrome/browser/android/webapk/webapk_web_manifest_checker.h" |
| 14 #include "chrome/browser/installable/installable_manager.h" | 15 #include "chrome/browser/installable/installable_manager.h" |
| 15 #include "chrome/browser/profiles/profile.h" | 16 #include "chrome/browser/profiles/profile.h" |
| 16 #include "content/public/browser/web_contents.h" | 17 #include "content/public/browser/web_contents.h" |
| 17 #include "content/public/common/manifest.h" | 18 #include "content/public/common/manifest.h" |
| 18 #include "jni/ManifestUpgradeDetectorFetcher_jni.h" | 19 #include "jni/ManifestUpgradeDetectorFetcher_jni.h" |
| 19 #include "third_party/smhasher/src/MurmurHash2.h" | 20 #include "third_party/smhasher/src/MurmurHash2.h" |
| (...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 137 | 138 |
| 138 // TODO(pkotwicz): Tell Java side that the Web Manifest was fetched but the | 139 // TODO(pkotwicz): Tell Java side that the Web Manifest was fetched but the |
| 139 // Web Manifest is not WebAPK-compatible. (http://crbug.com/639536) | 140 // Web Manifest is not WebAPK-compatible. (http://crbug.com/639536) |
| 140 if (data.error_code != NO_ERROR_DETECTED || | 141 if (data.error_code != NO_ERROR_DETECTED || |
| 141 !AreWebManifestUrlsWebApkCompatible(data.manifest)) { | 142 !AreWebManifestUrlsWebApkCompatible(data.manifest)) { |
| 142 return; | 143 return; |
| 143 } | 144 } |
| 144 | 145 |
| 145 info_.UpdateFromManifest(data.manifest); | 146 info_.UpdateFromManifest(data.manifest); |
| 146 info_.manifest_url = data.manifest_url; | 147 info_.manifest_url = data.manifest_url; |
| 147 info_.icon_url = data.icon_url; | 148 info_.best_icon_url = data.icon_url; |
| 148 icon_ = *data.icon; | 149 icon_ = *data.icon; |
| 149 | 150 |
| 150 icon_hasher_.reset(new WebApkIconHasher()); | 151 icon_hasher_.reset(new WebApkIconHasher()); |
| 151 Profile* profile = | 152 Profile* profile = |
| 152 Profile::FromBrowserContext(web_contents()->GetBrowserContext()); | 153 Profile::FromBrowserContext(web_contents()->GetBrowserContext()); |
| 153 icon_hasher_->DownloadAndComputeMurmur2Hash( | 154 icon_hasher_->DownloadAndComputeMurmur2Hash( |
| 154 profile->GetRequestContext(), | 155 profile->GetRequestContext(), |
| 155 data.icon_url, | 156 data.icon_url, |
| 156 base::Bind(&ManifestUpgradeDetectorFetcher::OnGotIconMurmur2Hash, | 157 base::Bind(&ManifestUpgradeDetectorFetcher::OnGotIconMurmur2Hash, |
| 157 weak_ptr_factory_.GetWeakPtr())); | 158 weak_ptr_factory_.GetWeakPtr())); |
| 158 } | 159 } |
| 159 | 160 |
| 160 void ManifestUpgradeDetectorFetcher::OnGotIconMurmur2Hash( | 161 void ManifestUpgradeDetectorFetcher::OnGotIconMurmur2Hash( |
| 161 const std::string& icon_murmur2_hash) { | 162 const std::string& icon_murmur2_hash) { |
|
pkotwicz
2016/11/01 00:29:49
Nit: Rename |icon_murmur2_hash| to |best_icon_murm
Xi Han
2016/11/07 16:51:43
Done.
| |
| 162 icon_hasher_.reset(); | 163 icon_hasher_.reset(); |
| 163 | 164 |
| 164 if (icon_murmur2_hash.empty()) { | 165 if (icon_murmur2_hash.empty()) { |
| 165 // TODO(pkotwicz): Tell Java side that the Web Manifest was fetched but the | 166 // TODO(pkotwicz): Tell Java side that the Web Manifest was fetched but the |
| 166 // Web Manifest is not WebAPK-compatible. (http://crbug.com/639536) | 167 // Web Manifest is not WebAPK-compatible. (http://crbug.com/639536) |
| 167 return; | 168 return; |
| 168 } | 169 } |
| 169 | 170 |
| 170 OnDataAvailable(info_, icon_murmur2_hash, icon_); | 171 OnDataAvailable(info_, icon_murmur2_hash, icon_); |
|
pkotwicz
2016/11/01 00:29:49
Nit: |icon_| -> |best_icon_|
Xi Han
2016/11/07 16:51:43
Done.
| |
| 171 } | 172 } |
| 172 | 173 |
| 173 void ManifestUpgradeDetectorFetcher::OnDataAvailable( | 174 void ManifestUpgradeDetectorFetcher::OnDataAvailable( |
| 174 const ShortcutInfo& info, | 175 const ShortcutInfo& info, |
| 175 const std::string& icon_murmur2_hash, | 176 const std::string& icon_murmur2_hash, |
| 176 const SkBitmap& icon_bitmap) { | 177 const SkBitmap& icon_bitmap) { |
| 177 JNIEnv* env = base::android::AttachCurrentThread(); | 178 JNIEnv* env = base::android::AttachCurrentThread(); |
| 178 | 179 |
| 179 ScopedJavaLocalRef<jstring> java_url = | 180 ScopedJavaLocalRef<jstring> java_url = |
| 180 base::android::ConvertUTF8ToJavaString(env, info.url.spec()); | 181 base::android::ConvertUTF8ToJavaString(env, info.url.spec()); |
| 181 ScopedJavaLocalRef<jstring> java_scope = | 182 ScopedJavaLocalRef<jstring> java_scope = |
| 182 base::android::ConvertUTF8ToJavaString(env, info.scope.spec()); | 183 base::android::ConvertUTF8ToJavaString(env, info.scope.spec()); |
| 183 ScopedJavaLocalRef<jstring> java_name = | 184 ScopedJavaLocalRef<jstring> java_name = |
| 184 base::android::ConvertUTF16ToJavaString(env, info.name); | 185 base::android::ConvertUTF16ToJavaString(env, info.name); |
| 185 ScopedJavaLocalRef<jstring> java_short_name = | 186 ScopedJavaLocalRef<jstring> java_short_name = |
| 186 base::android::ConvertUTF16ToJavaString(env, info.short_name); | 187 base::android::ConvertUTF16ToJavaString(env, info.short_name); |
| 187 ScopedJavaLocalRef<jstring> java_icon_url = | 188 ScopedJavaLocalRef<jstring> java_best_icon_url = |
| 188 base::android::ConvertUTF8ToJavaString(env, info.icon_url.spec()); | 189 base::android::ConvertUTF8ToJavaString(env, info.best_icon_url.spec()); |
| 189 ScopedJavaLocalRef<jstring> java_icon_murmur2_hash = | 190 ScopedJavaLocalRef<jstring> java_icon_murmur2_hash = |
| 190 base::android::ConvertUTF8ToJavaString(env, icon_murmur2_hash); | 191 base::android::ConvertUTF8ToJavaString(env, icon_murmur2_hash); |
| 191 ScopedJavaLocalRef<jobject> java_bitmap = | 192 ScopedJavaLocalRef<jobject> java_bitmap = |
| 192 gfx::ConvertToJavaBitmap(&icon_bitmap); | 193 gfx::ConvertToJavaBitmap(&icon_bitmap); |
|
pkotwicz
2016/11/01 00:29:49
Nit: |java_bitmap| -> |java_best_bitmap|
Xi Han
2016/11/07 16:51:43
Done.
| |
| 193 | 194 |
| 195 std::vector<std::string> icon_urls; | |
| 196 for (const auto& icon_url : info.icon_urls) | |
|
pkotwicz
2016/11/01 00:29:49
Nit: "const auto& icon_url" -> "const GURL& icon_u
Xi Han
2016/11/07 16:51:43
Done.
| |
| 197 icon_urls.push_back(icon_url.spec()); | |
| 198 | |
| 199 ScopedJavaLocalRef<jobjectArray> java_icon_urls = | |
| 200 base::android::ToJavaArrayOfStrings(env, icon_urls); | |
| 201 | |
| 194 Java_ManifestUpgradeDetectorFetcher_onDataAvailable( | 202 Java_ManifestUpgradeDetectorFetcher_onDataAvailable( |
| 195 env, java_ref_, java_url, java_scope, java_name, java_short_name, | 203 env, java_ref_, java_url, java_scope, java_name, java_short_name, |
| 196 java_icon_url, java_icon_murmur2_hash, java_bitmap, info.display, | 204 java_best_icon_url, java_icon_murmur2_hash, java_bitmap, java_icon_urls, |
| 197 info.orientation, info.theme_color, info.background_color); | 205 info.display, info.orientation, info.theme_color, info.background_color); |
| 198 } | 206 } |
| OLD | NEW |