| Index: chrome/browser/android/webapk/manifest_upgrade_detector_fetcher.cc
|
| diff --git a/chrome/browser/android/webapk/manifest_upgrade_detector_fetcher.cc b/chrome/browser/android/webapk/manifest_upgrade_detector_fetcher.cc
|
| index af49eaaf78182ac7bf35c6a71353f91dfc05d18e..f67ec2de0dd66de204c78e21607008e1e447e93e 100644
|
| --- a/chrome/browser/android/webapk/manifest_upgrade_detector_fetcher.cc
|
| +++ b/chrome/browser/android/webapk/manifest_upgrade_detector_fetcher.cc
|
| @@ -5,13 +5,19 @@
|
| #include "chrome/browser/android/webapk/manifest_upgrade_detector_fetcher.h"
|
|
|
| #include <jni.h>
|
| +#include <vector>
|
|
|
| #include "base/android/jni_string.h"
|
| +#include "chrome/browser/android/shortcut_helper.h"
|
| #include "chrome/browser/android/shortcut_info.h"
|
| +#include "chrome/browser/installable/installable_manager.h"
|
| #include "content/public/browser/render_frame_host.h"
|
| #include "content/public/browser/web_contents.h"
|
| #include "content/public/common/manifest.h"
|
| #include "jni/ManifestUpgradeDetectorFetcher_jni.h"
|
| +#include "third_party/smhasher/src/MurmurHash2.h"
|
| +#include "ui/gfx/android/java_bitmap.h"
|
| +#include "ui/gfx/codec/png_codec.h"
|
| #include "url/gurl.h"
|
|
|
| using base::android::JavaParamRef;
|
| @@ -19,6 +25,16 @@ using base::android::ScopedJavaLocalRef;
|
|
|
| namespace {
|
|
|
| +// The seed to use for the murmur2 hash.
|
| +const uint64_t kMurmur2HashSeed = 0;
|
| +
|
| +// Computes a murmur2 hash of |bitmap|'s PNG encoded bytes.
|
| +uint64_t ComputeBitmapHash(const SkBitmap& bitmap) {
|
| + std::vector<unsigned char> png_bytes;
|
| + gfx::PNGCodec::EncodeBGRASkBitmap(bitmap, false, &png_bytes);
|
| + return MurmurHash64B(&png_bytes.front(), png_bytes.size(), kMurmur2HashSeed);
|
| +}
|
| +
|
| // Returns whether the given |url| is within the scope of the |scope| url.
|
| bool IsInScope(const GURL& url, const GURL& scope) {
|
| return base::StartsWith(url.spec(), scope.spec(),
|
| @@ -88,14 +104,23 @@ void ManifestUpgradeDetectorFetcher::DidFinishLoad(
|
| if (!IsInScope(validated_url, scope_))
|
| return;
|
|
|
| - web_contents()->GetManifest(
|
| - base::Bind(&ManifestUpgradeDetectorFetcher::OnDidGetManifest,
|
| + InstallableParams params;
|
| + params.ideal_icon_size_in_dp =
|
| + ShortcutHelper::GetIdealHomescreenIconSizeInDp();
|
| + params.minimum_icon_size_in_dp =
|
| + ShortcutHelper::GetMinimumHomescreenIconSizeInDp();
|
| + params.fetch_valid_icon = true;
|
| + InstallableManager::CreateForWebContents(web_contents());
|
| + InstallableManager* installable_manager =
|
| + InstallableManager::FromWebContents(web_contents());
|
| + installable_manager->GetData(
|
| + params,
|
| + base::Bind(&ManifestUpgradeDetectorFetcher::OnDidGetInstallableData,
|
| weak_ptr_factory_.GetWeakPtr()));
|
| }
|
|
|
| -void ManifestUpgradeDetectorFetcher::OnDidGetManifest(
|
| - const GURL& manifest_url,
|
| - const content::Manifest& manifest) {
|
| +void ManifestUpgradeDetectorFetcher::OnDidGetInstallableData(
|
| + const InstallableData& data) {
|
| // If the manifest is empty, it means the current WebContents doesn't
|
| // associate with a Web Manifest. In such case, we ignore the empty manifest
|
| // and continue observing the WebContents's loading until we find a page that
|
| @@ -104,17 +129,19 @@ void ManifestUpgradeDetectorFetcher::OnDidGetManifest(
|
| // observing too. It is based on our assumption that it is invalid for
|
| // web developers to change the Web Manifest location. When it does
|
| // change, we will treat the new Web Manifest as the one of another WebAPK.
|
| - if (manifest.IsEmpty() || web_manifest_url_ != manifest_url)
|
| + if (data.manifest.IsEmpty() || web_manifest_url_ != data.manifest_url)
|
| return;
|
|
|
| ShortcutInfo info(GURL::EmptyGURL());
|
| - info.UpdateFromManifest(manifest);
|
| - info.manifest_url = manifest_url;
|
| -
|
| - OnDataAvailable(info);
|
| + info.UpdateFromManifest(data.manifest);
|
| + info.manifest_url = data.manifest_url;
|
| + info.icon_url = data.icon_url;
|
| + OnDataAvailable(info, (data.icon ? *data.icon : SkBitmap()));
|
| }
|
|
|
| -void ManifestUpgradeDetectorFetcher::OnDataAvailable(const ShortcutInfo& info) {
|
| +void ManifestUpgradeDetectorFetcher::OnDataAvailable(
|
| + const ShortcutInfo& info,
|
| + const SkBitmap& icon_bitmap) {
|
| JNIEnv* env = base::android::AttachCurrentThread();
|
|
|
| ScopedJavaLocalRef<jstring> java_url =
|
| @@ -125,8 +152,19 @@ void ManifestUpgradeDetectorFetcher::OnDataAvailable(const ShortcutInfo& info) {
|
| base::android::ConvertUTF16ToJavaString(env, info.name);
|
| ScopedJavaLocalRef<jstring> java_short_name =
|
| base::android::ConvertUTF16ToJavaString(env, info.short_name);
|
| + ScopedJavaLocalRef<jstring> java_icon_url =
|
| + base::android::ConvertUTF8ToJavaString(env, info.icon_url.spec());
|
| + ScopedJavaLocalRef<jobject> java_bitmap;
|
| + uint64_t icon_murmur2_hash = 0;
|
| + if (icon_bitmap.getSize()) {
|
| + java_bitmap = gfx::ConvertToJavaBitmap(&icon_bitmap);
|
| + // TODO(pkotwicz): Get hash of untransformed icon's bytes (with no
|
| + // encoding/decoding).
|
| + icon_murmur2_hash = ComputeBitmapHash(icon_bitmap);
|
| + }
|
|
|
| Java_ManifestUpgradeDetectorFetcher_onDataAvailable(
|
| env, java_ref_, java_url, java_scope, java_name, java_short_name,
|
| - info.display, info.orientation, info.theme_color, info.background_color);
|
| + java_icon_url, icon_murmur2_hash, java_bitmap, info.display,
|
| + info.orientation, info.theme_color, info.background_color);
|
| }
|
|
|