| 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_string.h" | 10 #include "base/android/jni_string.h" |
| 11 #include "chrome/browser/android/shortcut_helper.h" | 11 #include "chrome/browser/android/shortcut_helper.h" |
| 12 #include "chrome/browser/android/webapk/webapk_icon_hasher.h" | 12 #include "chrome/browser/android/webapk/webapk_icon_hasher.h" |
| 13 #include "chrome/browser/android/webapk/webapk_web_manifest_checker.h" | 13 #include "chrome/browser/android/webapk/webapk_web_manifest_checker.h" |
| 14 #include "chrome/browser/installable/installable_manager.h" | 14 #include "chrome/browser/installable/installable_manager.h" |
| 15 #include "chrome/browser/profiles/profile.h" | 15 #include "chrome/browser/profiles/profile.h" |
| 16 #include "content/public/browser/render_frame_host.h" | |
| 17 #include "content/public/browser/web_contents.h" | 16 #include "content/public/browser/web_contents.h" |
| 18 #include "content/public/common/manifest.h" | 17 #include "content/public/common/manifest.h" |
| 19 #include "jni/ManifestUpgradeDetectorFetcher_jni.h" | 18 #include "jni/ManifestUpgradeDetectorFetcher_jni.h" |
| 20 #include "third_party/smhasher/src/MurmurHash2.h" | 19 #include "third_party/smhasher/src/MurmurHash2.h" |
| 21 #include "ui/gfx/android/java_bitmap.h" | 20 #include "ui/gfx/android/java_bitmap.h" |
| 22 #include "ui/gfx/codec/png_codec.h" | 21 #include "ui/gfx/codec/png_codec.h" |
| 23 #include "url/gurl.h" | 22 #include "url/gurl.h" |
| 24 | 23 |
| 25 using base::android::JavaParamRef; | 24 using base::android::JavaParamRef; |
| 26 using base::android::ScopedJavaLocalRef; | 25 using base::android::ScopedJavaLocalRef; |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 80 void ManifestUpgradeDetectorFetcher::Destroy(JNIEnv* env, | 79 void ManifestUpgradeDetectorFetcher::Destroy(JNIEnv* env, |
| 81 const JavaParamRef<jobject>& obj) { | 80 const JavaParamRef<jobject>& obj) { |
| 82 delete this; | 81 delete this; |
| 83 } | 82 } |
| 84 | 83 |
| 85 void ManifestUpgradeDetectorFetcher::Start( | 84 void ManifestUpgradeDetectorFetcher::Start( |
| 86 JNIEnv* env, | 85 JNIEnv* env, |
| 87 const JavaParamRef<jobject>& obj, | 86 const JavaParamRef<jobject>& obj, |
| 88 const JavaParamRef<jobject>& java_web_contents) { | 87 const JavaParamRef<jobject>& java_web_contents) { |
| 89 ReplaceWebContents(env, obj, java_web_contents); | 88 ReplaceWebContents(env, obj, java_web_contents); |
| 89 if (!web_contents()->IsLoading()) |
| 90 FetchInstallableData(); |
| 90 } | 91 } |
| 91 | 92 |
| 92 void ManifestUpgradeDetectorFetcher::DidFinishLoad( | 93 void ManifestUpgradeDetectorFetcher::DidStopLoading() { |
| 93 content::RenderFrameHost* render_frame_host, | 94 FetchInstallableData(); |
| 94 const GURL& validated_url) { | 95 } |
| 95 if (render_frame_host->GetParent()) | 96 |
| 97 void ManifestUpgradeDetectorFetcher::FetchInstallableData() { |
| 98 GURL url = web_contents()->GetLastCommittedURL(); |
| 99 |
| 100 // DidStopLoading() can be called multiple times for a single URL. Only fetch |
| 101 // installable data the first time. |
| 102 if (url == last_fetched_url_) |
| 96 return; | 103 return; |
| 97 if (!IsInScope(validated_url, scope_)) | 104 last_fetched_url_ = url; |
| 105 |
| 106 if (!IsInScope(url, scope_)) |
| 98 return; | 107 return; |
| 99 | 108 |
| 100 InstallableParams params; | 109 InstallableParams params; |
| 101 params.ideal_icon_size_in_dp = | 110 params.ideal_icon_size_in_dp = |
| 102 ShortcutHelper::GetIdealHomescreenIconSizeInDp(); | 111 ShortcutHelper::GetIdealHomescreenIconSizeInDp(); |
| 103 params.minimum_icon_size_in_dp = | 112 params.minimum_icon_size_in_dp = |
| 104 ShortcutHelper::GetMinimumHomescreenIconSizeInDp(); | 113 ShortcutHelper::GetMinimumHomescreenIconSizeInDp(); |
| 105 params.check_installable = true; | 114 params.check_installable = true; |
| 106 params.fetch_valid_icon = true; | 115 params.fetch_valid_icon = true; |
| 107 InstallableManager::CreateForWebContents(web_contents()); | 116 InstallableManager::CreateForWebContents(web_contents()); |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 180 ScopedJavaLocalRef<jstring> java_icon_murmur2_hash = | 189 ScopedJavaLocalRef<jstring> java_icon_murmur2_hash = |
| 181 base::android::ConvertUTF8ToJavaString(env, icon_murmur2_hash); | 190 base::android::ConvertUTF8ToJavaString(env, icon_murmur2_hash); |
| 182 ScopedJavaLocalRef<jobject> java_bitmap = | 191 ScopedJavaLocalRef<jobject> java_bitmap = |
| 183 gfx::ConvertToJavaBitmap(&icon_bitmap); | 192 gfx::ConvertToJavaBitmap(&icon_bitmap); |
| 184 | 193 |
| 185 Java_ManifestUpgradeDetectorFetcher_onDataAvailable( | 194 Java_ManifestUpgradeDetectorFetcher_onDataAvailable( |
| 186 env, java_ref_, java_url, java_scope, java_name, java_short_name, | 195 env, java_ref_, java_url, java_scope, java_name, java_short_name, |
| 187 java_icon_url, java_icon_murmur2_hash, java_bitmap, info.display, | 196 java_icon_url, java_icon_murmur2_hash, java_bitmap, info.display, |
| 188 info.orientation, info.theme_color, info.background_color); | 197 info.orientation, info.theme_color, info.background_color); |
| 189 } | 198 } |
| OLD | NEW |