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

Side by Side Diff: chrome/browser/android/webapk/webapk_icon_hasher.cc

Issue 2231843003: Take Murmur2 hash of untransformed icon when creating WebAPK part 1 (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Merge branch 'webapk_builder_impl2_directory' into webapk_builder_impl2_hash Created 4 years, 4 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 unified diff | Download patch
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "chrome/browser/android/webapk/webapk_icon_hasher.h"
6
7 #include "base/strings/string_number_conversions.h"
8 #include "base/strings/utf_string_conversions.h"
9 #include "net/http/http_status_code.h"
10 #include "net/url_request/url_fetcher.h"
11 #include "net/url_request/url_request_context_getter.h"
12 #include "third_party/smhasher/src/MurmurHash2.h"
13 #include "url/gurl.h"
14
15 namespace {
16
17 // The seed to use when taking the murmur2 hash of the icon.
18 const uint32_t kMurmur2HashSeed = 0;
19
20 } // anonymous namespace
21
22 WebApkIconHasher::WebApkIconHasher() {}
23
24 WebApkIconHasher::~WebApkIconHasher() {}
25
26 void WebApkIconHasher::DownloadAndGetMurmur2Hash(
27 net::URLRequestContextGetter* request_context_getter,
28 const GURL& icon_url,
29 const Murmur2HashCallback& callback) {
30 callback_ = callback;
31
32 url_fetcher_ = net::URLFetcher::Create(icon_url, net::URLFetcher::GET, this);
33 url_fetcher_->SetRequestContext(request_context_getter);
34 url_fetcher_->Start();
35 }
36
37 void WebApkIconHasher::OnURLFetchComplete(const net::URLFetcher* source) {
38 if (!source->GetStatus().is_success() ||
39 source->GetResponseCode() != net::HTTP_OK) {
40 callback_.Run("");
41 return;
42 }
43
44 // WARNING: We are running in the browser process. |raw_image_data| is the
45 // image's raw, unsanitized bytes from the web. |raw_image_data| may contain
46 // malicious data. Decoding unsanitized bitmap data to an SkBitmap in the
47 // browser process is a security bug.
48 std::string raw_image_data;
49 source->GetResponseAsString(&raw_image_data);
50 uint64_t hash = MurmurHash64B(&raw_image_data.front(), raw_image_data.size(),
51 kMurmur2HashSeed);
52 callback_.Run(base::Uint64ToString(hash));
53 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698