| 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_update_data_fetcher.h" | 5 #include "chrome/browser/android/webapk/webapk_update_data_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_array.h" |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 105 return; | 105 return; |
| 106 is_initial_fetch_ = last_fetched_url_.is_empty(); | 106 is_initial_fetch_ = last_fetched_url_.is_empty(); |
| 107 last_fetched_url_ = url; | 107 last_fetched_url_ = url; |
| 108 | 108 |
| 109 if (!IsInScope(url, scope_)) { | 109 if (!IsInScope(url, scope_)) { |
| 110 OnWebManifestNotWebApkCompatible(); | 110 OnWebManifestNotWebApkCompatible(); |
| 111 return; | 111 return; |
| 112 } | 112 } |
| 113 | 113 |
| 114 InstallableParams params; | 114 InstallableParams params; |
| 115 params.ideal_icon_size_in_px = | 115 params.ideal_primary_icon_size_in_px = |
| 116 ShortcutHelper::GetIdealHomescreenIconSizeInPx(); | 116 ShortcutHelper::GetIdealHomescreenIconSizeInPx(); |
| 117 params.minimum_icon_size_in_px = | 117 params.minimum_primary_icon_size_in_px = |
| 118 ShortcutHelper::GetMinimumHomescreenIconSizeInPx(); | 118 ShortcutHelper::GetMinimumHomescreenIconSizeInPx(); |
| 119 params.check_installable = true; | 119 params.check_installable = true; |
| 120 params.fetch_valid_icon = true; | 120 params.fetch_valid_primary_icon = true; |
| 121 InstallableManager::CreateForWebContents(web_contents()); | 121 InstallableManager::CreateForWebContents(web_contents()); |
| 122 InstallableManager* installable_manager = | 122 InstallableManager* installable_manager = |
| 123 InstallableManager::FromWebContents(web_contents()); | 123 InstallableManager::FromWebContents(web_contents()); |
| 124 installable_manager->GetData( | 124 installable_manager->GetData( |
| 125 params, | 125 params, |
| 126 base::Bind(&WebApkUpdateDataFetcher::OnDidGetInstallableData, | 126 base::Bind(&WebApkUpdateDataFetcher::OnDidGetInstallableData, |
| 127 weak_ptr_factory_.GetWeakPtr())); | 127 weak_ptr_factory_.GetWeakPtr())); |
| 128 } | 128 } |
| 129 | 129 |
| 130 void WebApkUpdateDataFetcher::OnDidGetInstallableData( | 130 void WebApkUpdateDataFetcher::OnDidGetInstallableData( |
| (...skipping 14 matching lines...) Expand all Loading... |
| 145 // change, we will treat the new Web Manifest as the one of another WebAPK. | 145 // change, we will treat the new Web Manifest as the one of another WebAPK. |
| 146 if (data.error_code != NO_ERROR_DETECTED || | 146 if (data.error_code != NO_ERROR_DETECTED || |
| 147 data.manifest.IsEmpty() || web_manifest_url_ != data.manifest_url || | 147 data.manifest.IsEmpty() || web_manifest_url_ != data.manifest_url || |
| 148 !AreWebManifestUrlsWebApkCompatible(data.manifest)) { | 148 !AreWebManifestUrlsWebApkCompatible(data.manifest)) { |
| 149 OnWebManifestNotWebApkCompatible(); | 149 OnWebManifestNotWebApkCompatible(); |
| 150 return; | 150 return; |
| 151 } | 151 } |
| 152 | 152 |
| 153 info_.UpdateFromManifest(data.manifest); | 153 info_.UpdateFromManifest(data.manifest); |
| 154 info_.manifest_url = data.manifest_url; | 154 info_.manifest_url = data.manifest_url; |
| 155 info_.best_icon_url = data.icon_url; | 155 info_.best_icon_url = data.primary_icon_url; |
| 156 best_icon_ = *data.icon; | 156 best_icon_ = *data.primary_icon; |
| 157 | 157 |
| 158 icon_hasher_.reset(new WebApkIconHasher()); | 158 icon_hasher_.reset(new WebApkIconHasher()); |
| 159 Profile* profile = | 159 Profile* profile = |
| 160 Profile::FromBrowserContext(web_contents()->GetBrowserContext()); | 160 Profile::FromBrowserContext(web_contents()->GetBrowserContext()); |
| 161 icon_hasher_->DownloadAndComputeMurmur2Hash( | 161 icon_hasher_->DownloadAndComputeMurmur2Hash( |
| 162 profile->GetRequestContext(), | 162 profile->GetRequestContext(), |
| 163 data.icon_url, | 163 data.primary_icon_url, |
| 164 base::Bind(&WebApkUpdateDataFetcher::OnGotIconMurmur2Hash, | 164 base::Bind(&WebApkUpdateDataFetcher::OnGotIconMurmur2Hash, |
| 165 weak_ptr_factory_.GetWeakPtr())); | 165 weak_ptr_factory_.GetWeakPtr())); |
| 166 } | 166 } |
| 167 | 167 |
| 168 void WebApkUpdateDataFetcher::OnGotIconMurmur2Hash( | 168 void WebApkUpdateDataFetcher::OnGotIconMurmur2Hash( |
| 169 const std::string& best_icon_murmur2_hash) { | 169 const std::string& best_icon_murmur2_hash) { |
| 170 icon_hasher_.reset(); | 170 icon_hasher_.reset(); |
| 171 | 171 |
| 172 if (best_icon_murmur2_hash.empty()) { | 172 if (best_icon_murmur2_hash.empty()) { |
| 173 OnWebManifestNotWebApkCompatible(); | 173 OnWebManifestNotWebApkCompatible(); |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 208 info.background_color); | 208 info.background_color); |
| 209 } | 209 } |
| 210 | 210 |
| 211 void WebApkUpdateDataFetcher::OnWebManifestNotWebApkCompatible() { | 211 void WebApkUpdateDataFetcher::OnWebManifestNotWebApkCompatible() { |
| 212 if (!is_initial_fetch_) | 212 if (!is_initial_fetch_) |
| 213 return; | 213 return; |
| 214 | 214 |
| 215 Java_WebApkUpdateDataFetcher_onWebManifestForInitialUrlNotWebApkCompatible( | 215 Java_WebApkUpdateDataFetcher_onWebManifestForInitialUrlNotWebApkCompatible( |
| 216 base::android::AttachCurrentThread(), java_ref_); | 216 base::android::AttachCurrentThread(), java_ref_); |
| 217 } | 217 } |
| OLD | NEW |