OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 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/password_manager/core/browser/site_affiliation/asset_link_r etriever.h" | |
6 | |
7 #include <utility> | |
8 | |
9 #include "base/logging.h" | |
10 #include "net/base/load_flags.h" | |
11 #include "net/http/http_status_code.h" | |
12 #include "net/traffic_annotation/network_traffic_annotation.h" | |
13 #include "net/url_request/url_fetcher.h" | |
14 | |
15 namespace password_manager { | |
16 | |
17 AssetLinkRetriever::AssetLinkRetriever(GURL file_url) | |
18 : url_(std::move(file_url)), state_(State::INACTIVE), error_(false) { | |
19 DCHECK(url_.is_valid()); | |
20 DCHECK(url_.SchemeIs(url::kHttpsScheme)); | |
21 } | |
22 | |
23 void AssetLinkRetriever::Start(net::URLRequestContextGetter* context_getter) { | |
24 if (state_ != State::INACTIVE) | |
25 return; | |
26 net::NetworkTrafficAnnotationTag traffic_annotation = | |
27 net::DefineNetworkTrafficAnnotation("asset_links", R"( | |
28 semantics { | |
29 sender: "Asset Links Fetcher" | |
30 description: | |
31 "The asset links is a JSON file hosted on " | |
32 "https://<domain>/.well-known/assetlinks.json. It contains " | |
33 "different permissions the site gives to apps/other sites. Chrome " | |
34 "looks for a permission to delegate the credentials from the site " | |
35 "to another domain. It's used for handling the stored credentials " | |
36 "in the password manager." | |
37 trigger: | |
38 "Load a site where it's possible to sign-in. The site can have a " | |
39 "password form or use the Credential Management API." | |
40 data: "None." | |
41 destination: WEBSITE | |
42 } | |
43 policy { | |
44 cookies_allowed: false | |
45 setting: "No setting" | |
46 policy_exception_justification: | |
47 "The file is considered to be a resource of the page loaded." | |
48 })"); | |
49 fetcher_ = net::URLFetcher::Create(url_, net::URLFetcher::GET, this, | |
50 traffic_annotation); | |
51 fetcher_->SetRequestContext(context_getter); | |
52 fetcher_->SetLoadFlags( | |
53 net::LOAD_DO_NOT_SEND_COOKIES | net::LOAD_DO_NOT_SAVE_COOKIES | | |
54 net::LOAD_DO_NOT_SEND_AUTH_DATA | net::LOAD_MAYBE_USER_GESTURE); | |
55 fetcher_->SetStopOnRedirect(true); | |
56 fetcher_->Start(); | |
57 state_ = State::NETWORK_REQUEST; | |
58 } | |
59 | |
60 AssetLinkRetriever::~AssetLinkRetriever() = default; | |
61 | |
62 void AssetLinkRetriever::OnURLFetchComplete(const net::URLFetcher* source) { | |
63 DCHECK(source == fetcher_.get()); | |
64 | |
65 error_ = !source->GetStatus().is_success() || | |
66 source->GetResponseCode() != net::HTTP_OK; | |
67 if (error_) { | |
68 state_ = State::FINISHED; | |
vabr (Chromium)
2017/06/18 16:37:51
Why not set the state independently of |error_|? D
vasilii
2017/06/19 12:20:20
Because if there is no error then the next state s
vabr (Chromium)
2017/06/19 13:07:54
Acknowledged.
| |
69 } else { | |
70 // Start parsing here. | |
vabr (Chromium)
2017/06/18 16:37:51
nit: This should be a TODO(crbug.com/630555).
vasilii
2017/06/19 12:20:20
Done.
| |
71 } | |
72 fetcher_.reset(); | |
73 } | |
74 | |
75 } // namespace password_manager | |
OLD | NEW |