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

Side by Side Diff: components/digital_asset_links/digital_asset_links_handler.cc

Issue 2767333006: Add Digital Asset Links verification for postMessage API (Closed)
Patch Set: moved digital_asset_links to a component Created 3 years, 8 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 (c) 2017 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 "components/digital_asset_links/digital_asset_links_handler.h"
6
7 #include "base/json/json_reader.h"
8 #include "base/logging.h"
9 #include "base/strings/string_number_conversions.h"
10 #include "base/strings/stringprintf.h"
11 #include "base/values.h"
12 #include "net/base/load_flags.h"
13 #include "net/base/url_util.h"
14 #include "net/http/http_response_headers.h"
15 #include "net/http/http_status_code.h"
16 #include "net/http/http_util.h"
17 #include "net/url_request/url_request_status.h"
18
19 namespace {
20 static const char kDigitalAssetLinksBaseURL[] =
Benoit L 2017/03/31 15:38:43 nit: "static" is unnecessary here and below (due t
Yusuf 2017/03/31 22:41:49 Done.
21 "https://digitalassetlinks.googleapis.com";
22 static const char kDigitalAssetLinksCheckAPI[] = "/v1/assetlinks:check?";
Benoit L 2017/03/31 15:38:42 nit: Should the path include the "?" at the end? W
Yusuf 2017/03/31 22:41:50 I might be missing something but it looks like no.
23 static const char kTargetOriginParam[] = "source.web.site";
24 static const char kSourcePackageNameParam[] = "target.androidApp.packageName";
25 static const char kSourceFingerprintParam[] =
26 "target.androidApp.certificate.sha256Fingerprint";
27 static const char kRelationshipParam[] = "relation";
28
29 GURL GetUrlForCheckingRelationship(std::string web_domain,
Benoit L 2017/03/31 15:38:42 nit: make all parameters const std::string& param
Yusuf 2017/03/31 22:41:50 Done.
30 std::string package_name,
31 std::string fingerprint,
32 std::string relationship) {
33 GURL request_url =
34 GURL(kDigitalAssetLinksBaseURL).Resolve(kDigitalAssetLinksCheckAPI);
35 request_url =
36 net::AppendQueryParameter(request_url, kTargetOriginParam, web_domain);
37 request_url = net::AppendQueryParameter(request_url, kSourcePackageNameParam,
38 package_name);
39 request_url = net::AppendQueryParameter(request_url, kSourceFingerprintParam,
40 fingerprint);
41 request_url =
42 net::AppendQueryParameter(request_url, kRelationshipParam, relationship);
43 return request_url;
Benoit L 2017/03/31 15:38:43 nit: Add a DCHECK() above to check that the URL is
Yusuf 2017/03/31 22:41:50 Done.
44 }
45 }
Benoit L 2017/03/31 15:38:42 nit: Add // namespace
Yusuf 2017/03/31 22:41:50 Done.
46
47 namespace digital_asset_links {
48
49 DigitalAssetLinksHandler::DigitalAssetLinksHandler(
50 const scoped_refptr<net::URLRequestContextGetter>& request_context) {
Benoit L 2017/03/31 15:38:42 nit: Initializer list instead of inline in the con
Yusuf 2017/03/31 22:41:49 Done.
51 request_context_ = request_context;
52 }
53
54 DigitalAssetLinksHandler::~DigitalAssetLinksHandler() {}
55
56 void DigitalAssetLinksHandler::OnURLFetchComplete(
57 const net::URLFetcher* source) {
58 base::DictionaryValue* dict = NULL;
59 if (!source->GetStatus().is_success() ||
60 source->GetResponseCode() != net::HTTP_OK) {
61 LOG(WARNING) << base::StringPrintf(
62 "Digital Asset Links endpoint responded with code %d.",
63 source->GetResponseCode());
64 listener_.get()->OnRelationshipCheckComplete(dict);
Benoit L 2017/03/31 15:38:42 nit: listener_->OnRelationshipCheckComplete(nullpt
Yusuf 2017/03/31 22:41:50 Done.
65 return;
66 }
67 std::string response_body;
68 source->GetResponseAsString(&response_body);
69
70 std::unique_ptr<base::Value> value = base::JSONReader::Read(response_body);
71 if (!value.get() || !value->GetAsDictionary(&dict)) {
Benoit L 2017/03/31 15:38:42 nit: if (!value || !value->GetAsDictionary(...))
Yusuf 2017/03/31 22:41:50 Done.
72 listener_.get()->OnRelationshipCheckComplete(dict);
73 return;
74 }
75 listener_.get()->OnRelationshipCheckComplete(dict);
76 }
77
78 bool DigitalAssetLinksHandler::CheckDigitalAssetLinkRelationship(
79 AssetLinkListener* listener,
80 std::string web_domain,
Benoit L 2017/03/31 15:38:42 nit: make the std::string arguments const std::str
Yusuf 2017/03/31 22:41:50 Done.
81 std::string package_name,
82 std::string fingerprint,
83 std::string relationship) {
84 GURL request_url = GetUrlForCheckingRelationship(web_domain, package_name,
85 fingerprint, relationship);
86 if (!request_url.is_valid())
87 return false;
88
89 listener_.reset(listener);
Benoit L 2017/03/31 15:38:42 If this object takes ownership of the listener, th
Yusuf 2017/03/31 22:41:50 After the conversion to Callback, it made sense to
90
91 url_fetcher_.reset();
Benoit L 2017/03/31 15:38:42 nit: url_fetcher_ = std::move(net::URLFetcher::Cr
Yusuf 2017/03/31 22:41:50 Done.
92
93 url_fetcher_ =
Benoit L 2017/03/31 15:38:42 Question: What is the behavior of URLFetcher with
Yusuf 2017/03/31 22:41:50 From url_fetcher.h: Normally, URLFetcher will abor
94 net::URLFetcher::Create(0, request_url, net::URLFetcher::GET, this);
95 url_fetcher_->SetAutomaticallyRetryOn5xx(false);
96 url_fetcher_->SetRequestContext(request_context_.get());
97 url_fetcher_->Start();
98 return true;
99 }
100
101 } // namespace digital_asset_links
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698