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" |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
102 if (render_frame_host->GetParent()) | 102 if (render_frame_host->GetParent()) |
103 return; | 103 return; |
104 if (!IsInScope(validated_url, scope_)) | 104 if (!IsInScope(validated_url, scope_)) |
105 return; | 105 return; |
106 | 106 |
107 InstallableParams params; | 107 InstallableParams params; |
108 params.ideal_icon_size_in_dp = | 108 params.ideal_icon_size_in_dp = |
109 ShortcutHelper::GetIdealHomescreenIconSizeInDp(); | 109 ShortcutHelper::GetIdealHomescreenIconSizeInDp(); |
110 params.minimum_icon_size_in_dp = | 110 params.minimum_icon_size_in_dp = |
111 ShortcutHelper::GetMinimumHomescreenIconSizeInDp(); | 111 ShortcutHelper::GetMinimumHomescreenIconSizeInDp(); |
112 params.check_installable = true; | |
112 params.fetch_valid_icon = true; | 113 params.fetch_valid_icon = true; |
113 InstallableManager::CreateForWebContents(web_contents()); | 114 InstallableManager::CreateForWebContents(web_contents()); |
114 InstallableManager* installable_manager = | 115 InstallableManager* installable_manager = |
115 InstallableManager::FromWebContents(web_contents()); | 116 InstallableManager::FromWebContents(web_contents()); |
116 installable_manager->GetData( | 117 installable_manager->GetData( |
117 params, | 118 params, |
118 base::Bind(&ManifestUpgradeDetectorFetcher::OnDidGetInstallableData, | 119 base::Bind(&ManifestUpgradeDetectorFetcher::OnDidGetInstallableData, |
119 weak_ptr_factory_.GetWeakPtr())); | 120 weak_ptr_factory_.GetWeakPtr())); |
120 } | 121 } |
121 | 122 |
122 void ManifestUpgradeDetectorFetcher::OnDidGetInstallableData( | 123 void ManifestUpgradeDetectorFetcher::OnDidGetInstallableData( |
123 const InstallableData& data) { | 124 const InstallableData& data) { |
124 // If the manifest is empty, it means the current WebContents doesn't | 125 // If the manifest is empty, it means the current WebContents doesn't |
125 // associate with a Web Manifest. In such case, we ignore the empty manifest | 126 // associate with a Web Manifest. In such case, we ignore the empty manifest |
126 // and continue observing the WebContents's loading until we find a page that | 127 // and continue observing the WebContents's loading until we find a page that |
127 // links to the Web Manifest that we are looking for. | 128 // links to the Web Manifest that we are looking for. |
128 // If the manifest URL is different from the current one, we will continue | 129 // If the manifest URL is different from the current one, we will continue |
129 // observing too. It is based on our assumption that it is invalid for | 130 // observing too. It is based on our assumption that it is invalid for |
130 // web developers to change the Web Manifest location. When it does | 131 // web developers to change the Web Manifest location. When it does |
131 // change, we will treat the new Web Manifest as the one of another WebAPK. | 132 // change, we will treat the new Web Manifest as the one of another WebAPK. |
132 if (data.manifest.IsEmpty() || web_manifest_url_ != data.manifest_url) | 133 if (data.manifest.IsEmpty() || web_manifest_url_ != data.manifest_url) |
133 return; | 134 return; |
134 | 135 |
135 ShortcutInfo info(GURL::EmptyGURL()); | 136 ShortcutInfo info(GURL::EmptyGURL()); |
136 info.UpdateFromManifest(data.manifest); | 137 info.UpdateFromManifest(data.manifest); |
137 info.manifest_url = data.manifest_url; | 138 info.manifest_url = data.manifest_url; |
138 info.icon_url = data.icon_url; | 139 info.icon_url = data.icon_url; |
139 OnDataAvailable(info, (data.icon ? *data.icon : SkBitmap())); | 140 OnDataAvailable(data.is_installable, info, |
141 (data.icon ? *data.icon : SkBitmap())); | |
140 } | 142 } |
141 | 143 |
142 void ManifestUpgradeDetectorFetcher::OnDataAvailable( | 144 void ManifestUpgradeDetectorFetcher::OnDataAvailable( |
145 bool is_installable, | |
Yaron
2016/08/19 13:57:10
if it's not installable, we're going to do a bunch
Xi Han
2016/08/23 19:11:52
Yaron's suggestion makes sense, even though I didn
| |
143 const ShortcutInfo& info, | 146 const ShortcutInfo& info, |
144 const SkBitmap& icon_bitmap) { | 147 const SkBitmap& icon_bitmap) { |
145 JNIEnv* env = base::android::AttachCurrentThread(); | 148 JNIEnv* env = base::android::AttachCurrentThread(); |
146 | 149 |
147 ScopedJavaLocalRef<jstring> java_url = | 150 ScopedJavaLocalRef<jstring> java_url = |
148 base::android::ConvertUTF8ToJavaString(env, info.url.spec()); | 151 base::android::ConvertUTF8ToJavaString(env, info.url.spec()); |
149 ScopedJavaLocalRef<jstring> java_scope = | 152 ScopedJavaLocalRef<jstring> java_scope = |
150 base::android::ConvertUTF8ToJavaString(env, info.scope.spec()); | 153 base::android::ConvertUTF8ToJavaString(env, info.scope.spec()); |
151 ScopedJavaLocalRef<jstring> java_name = | 154 ScopedJavaLocalRef<jstring> java_name = |
152 base::android::ConvertUTF16ToJavaString(env, info.name); | 155 base::android::ConvertUTF16ToJavaString(env, info.name); |
153 ScopedJavaLocalRef<jstring> java_short_name = | 156 ScopedJavaLocalRef<jstring> java_short_name = |
154 base::android::ConvertUTF16ToJavaString(env, info.short_name); | 157 base::android::ConvertUTF16ToJavaString(env, info.short_name); |
155 ScopedJavaLocalRef<jstring> java_icon_url = | 158 ScopedJavaLocalRef<jstring> java_icon_url = |
156 base::android::ConvertUTF8ToJavaString(env, info.icon_url.spec()); | 159 base::android::ConvertUTF8ToJavaString(env, info.icon_url.spec()); |
157 ScopedJavaLocalRef<jobject> java_bitmap; | 160 ScopedJavaLocalRef<jobject> java_bitmap; |
158 uint64_t icon_murmur2_hash = 0; | 161 uint64_t icon_murmur2_hash = 0; |
159 if (icon_bitmap.getSize()) { | 162 if (icon_bitmap.getSize()) { |
160 java_bitmap = gfx::ConvertToJavaBitmap(&icon_bitmap); | 163 java_bitmap = gfx::ConvertToJavaBitmap(&icon_bitmap); |
161 // TODO(pkotwicz): Get hash of untransformed icon's bytes (with no | 164 // TODO(pkotwicz): Get hash of untransformed icon's bytes (with no |
162 // encoding/decoding). | 165 // encoding/decoding). |
163 icon_murmur2_hash = ComputeBitmapHash(icon_bitmap); | 166 icon_murmur2_hash = ComputeBitmapHash(icon_bitmap); |
164 } | 167 } |
165 | 168 |
166 Java_ManifestUpgradeDetectorFetcher_onDataAvailable( | 169 Java_ManifestUpgradeDetectorFetcher_onDataAvailable( |
167 env, java_ref_, java_url, java_scope, java_name, java_short_name, | 170 env, java_ref_, is_installable, java_url, java_scope, java_name, |
168 java_icon_url, icon_murmur2_hash, java_bitmap, info.display, | 171 java_short_name, java_icon_url, icon_murmur2_hash, java_bitmap, |
169 info.orientation, info.theme_color, info.background_color); | 172 info.display, info.orientation, info.theme_color, info.background_color); |
170 } | 173 } |
OLD | NEW |