Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1088)

Unified Diff: chrome/browser/android/webapk/manifest_upgrade_detector_fetcher.cc

Issue 2331773002: Take Murmur2 hash of untransformed icon when creating WebAPK part 2/2 (Closed)
Patch Set: Merge branch 'master' into icon_hasher2 Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/browser/android/webapk/manifest_upgrade_detector_fetcher.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 447b0a57ee2f2144d18732dc16fbad06a17af986..00bc822b24ef915518e65b5d1050bbf7f173aed1 100644
--- a/chrome/browser/android/webapk/manifest_upgrade_detector_fetcher.cc
+++ b/chrome/browser/android/webapk/manifest_upgrade_detector_fetcher.cc
@@ -9,9 +9,10 @@
#include "base/android/jni_string.h"
#include "chrome/browser/android/shortcut_helper.h"
-#include "chrome/browser/android/shortcut_info.h"
+#include "chrome/browser/android/webapk/webapk_icon_hasher.h"
#include "chrome/browser/android/webapk/webapk_web_manifest_checker.h"
#include "chrome/browser/installable/installable_manager.h"
+#include "chrome/browser/profiles/profile.h"
#include "content/public/browser/render_frame_host.h"
#include "content/public/browser/web_contents.h"
#include "content/public/common/manifest.h"
@@ -26,16 +27,6 @@ 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(),
@@ -64,6 +55,7 @@ ManifestUpgradeDetectorFetcher::ManifestUpgradeDetectorFetcher(
: content::WebContentsObserver(nullptr),
scope_(scope),
web_manifest_url_(web_manifest_url),
+ info_(GURL()),
weak_ptr_factory_(this) {
java_ref_.Reset(env, obj);
}
@@ -136,20 +128,42 @@ void ManifestUpgradeDetectorFetcher::OnDidGetInstallableData(
// TODO(pkotwicz): Tell Java side that the Web Manifest was fetched but the
// Web Manifest is not WebAPK-compatible. (http://crbug.com/639536)
- if (!data.is_installable ||
+ if (data.error_code != NO_ERROR_DETECTED ||
!AreWebManifestUrlsWebApkCompatible(data.manifest)) {
return;
}
- ShortcutInfo info(GURL::EmptyGURL());
- info.UpdateFromManifest(data.manifest);
- info.manifest_url = data.manifest_url;
- info.icon_url = data.icon_url;
- OnDataAvailable(info, (data.icon ? *data.icon : SkBitmap()));
+ info_.UpdateFromManifest(data.manifest);
+ info_.manifest_url = data.manifest_url;
+ info_.icon_url = data.icon_url;
+ icon_ = *data.icon;
+
+ icon_hasher_.reset(new WebApkIconHasher());
+ Profile* profile =
+ Profile::FromBrowserContext(web_contents()->GetBrowserContext());
+ icon_hasher_->DownloadAndComputeMurmur2Hash(
+ profile->GetRequestContext(),
+ data.icon_url,
+ base::Bind(&ManifestUpgradeDetectorFetcher::OnGotIconMurmur2Hash,
+ weak_ptr_factory_.GetWeakPtr()));
+}
+
+void ManifestUpgradeDetectorFetcher::OnGotIconMurmur2Hash(
+ const std::string& icon_murmur2_hash) {
+ icon_hasher_.reset();
+
+ if (icon_murmur2_hash.empty()) {
+ // TODO(pkotwicz): Tell Java side that the Web Manifest was fetched but the
+ // Web Manifest is not WebAPK-compatible. (http://crbug.com/639536)
+ return;
+ }
+
+ OnDataAvailable(info_, icon_murmur2_hash, icon_);
}
void ManifestUpgradeDetectorFetcher::OnDataAvailable(
const ShortcutInfo& info,
+ const std::string& icon_murmur2_hash,
const SkBitmap& icon_bitmap) {
JNIEnv* env = base::android::AttachCurrentThread();
@@ -163,17 +177,13 @@ void ManifestUpgradeDetectorFetcher::OnDataAvailable(
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);
- }
+ ScopedJavaLocalRef<jstring> java_icon_murmur2_hash =
+ base::android::ConvertUTF8ToJavaString(env, icon_murmur2_hash);
+ ScopedJavaLocalRef<jobject> java_bitmap =
+ gfx::ConvertToJavaBitmap(&icon_bitmap);
Java_ManifestUpgradeDetectorFetcher_onDataAvailable(
env, java_ref_, java_url, java_scope, java_name, java_short_name,
- java_icon_url, icon_murmur2_hash, java_bitmap, info.display,
+ java_icon_url, java_icon_murmur2_hash, java_bitmap, info.display,
info.orientation, info.theme_color, info.background_color);
}
« no previous file with comments | « chrome/browser/android/webapk/manifest_upgrade_detector_fetcher.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698