| 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 |
| 136 // TODO(pkotwicz): Tell Java side that the Web Manifest was fetched but the |
| 137 // Web Manifest is not WebAPK-compatible. (http://crbug.com/639536) |
| 138 if (!data.is_installable) |
| 139 return; |
| 140 |
| 135 ShortcutInfo info(GURL::EmptyGURL()); | 141 ShortcutInfo info(GURL::EmptyGURL()); |
| 136 info.UpdateFromManifest(data.manifest); | 142 info.UpdateFromManifest(data.manifest); |
| 137 info.manifest_url = data.manifest_url; | 143 info.manifest_url = data.manifest_url; |
| 138 info.icon_url = data.icon_url; | 144 info.icon_url = data.icon_url; |
| 139 OnDataAvailable(info, (data.icon ? *data.icon : SkBitmap())); | 145 OnDataAvailable(info, (data.icon ? *data.icon : SkBitmap())); |
| 140 } | 146 } |
| 141 | 147 |
| 142 void ManifestUpgradeDetectorFetcher::OnDataAvailable( | 148 void ManifestUpgradeDetectorFetcher::OnDataAvailable( |
| 143 const ShortcutInfo& info, | 149 const ShortcutInfo& info, |
| 144 const SkBitmap& icon_bitmap) { | 150 const SkBitmap& icon_bitmap) { |
| (...skipping 16 matching lines...) Expand all Loading... |
| 161 // TODO(pkotwicz): Get hash of untransformed icon's bytes (with no | 167 // TODO(pkotwicz): Get hash of untransformed icon's bytes (with no |
| 162 // encoding/decoding). | 168 // encoding/decoding). |
| 163 icon_murmur2_hash = ComputeBitmapHash(icon_bitmap); | 169 icon_murmur2_hash = ComputeBitmapHash(icon_bitmap); |
| 164 } | 170 } |
| 165 | 171 |
| 166 Java_ManifestUpgradeDetectorFetcher_onDataAvailable( | 172 Java_ManifestUpgradeDetectorFetcher_onDataAvailable( |
| 167 env, java_ref_, java_url, java_scope, java_name, java_short_name, | 173 env, java_ref_, java_url, java_scope, java_name, java_short_name, |
| 168 java_icon_url, icon_murmur2_hash, java_bitmap, info.display, | 174 java_icon_url, icon_murmur2_hash, java_bitmap, info.display, |
| 169 info.orientation, info.theme_color, info.background_color); | 175 info.orientation, info.theme_color, info.background_color); |
| 170 } | 176 } |
| OLD | NEW |