Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright (c) 2015 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 #ifndef CHROME_BROWSER_SSL_COMMON_NAME_MISMATCH_HANDLER_H_ | |
| 6 #define CHROME_BROWSER_SSL_COMMON_NAME_MISMATCH_HANDLER_H_ | |
| 7 | |
| 8 #include "base/basictypes.h" | |
| 9 #include "base/callback.h" | |
| 10 #include "base/compiler_specific.h" | |
| 11 #include "base/memory/ref_counted.h" | |
| 12 #include "base/memory/scoped_ptr.h" | |
| 13 #include "base/threading/non_thread_safe.h" | |
| 14 #include "base/time/time.h" | |
| 15 #include "net/url_request/url_fetcher.h" | |
| 16 #include "net/url_request/url_fetcher_delegate.h" | |
| 17 #include "net/url_request/url_request_context_getter.h" | |
| 18 #include "url/gurl.h" | |
| 19 | |
| 20 // This class contains methods to get a suggested URL when certificate | |
| 21 // validation fails due to |ERR_CERT_COMMON_NAME_INVALID| and has methods to | |
| 22 // perform a network request to check the validity of new URL. | |
| 23 class CommonNameMismatchHandler : public net::URLFetcherDelegate, | |
| 24 public base::NonThreadSafe { | |
| 25 public: | |
| 26 enum SuggestedUrlCheckResult { | |
| 27 // The request succeeds with good response code i.e. URL exists and its | |
| 28 // certificate is valid. | |
| 29 RESULT_SUGGESTED_URL_VALID, | |
| 30 // Suggested URL is invalid | |
| 31 RESULT_SUGGESTED_URL_INVALID | |
|
meacer
2015/07/15 20:11:46
nit: rename to AVAILABLE/NOT_AVAILABLE instead of
Bhanu Dev
2015/07/16 23:38:05
Using AVAILABLE/NOT_AVAILABLE is a good idea, I am
| |
| 32 }; | |
| 33 | |
| 34 struct Results { | |
| 35 Results() : result(RESULT_SUGGESTED_URL_INVALID) {} | |
| 36 | |
| 37 SuggestedUrlCheckResult result; | |
| 38 GURL new_url; | |
|
meacer
2015/07/15 20:11:46
suggested_url?
Bhanu Dev
2015/07/16 23:38:05
If there is a redirect, |new_url| can be different
| |
| 39 }; | |
| 40 | |
| 41 typedef base::Callback<void(const Results& results)> CheckUrlCallback; | |
| 42 | |
| 43 explicit CommonNameMismatchHandler(const GURL request_url, | |
| 44 const scoped_refptr<net::URLRequestContextGetter>& request_context); | |
| 45 ~CommonNameMismatchHandler() override; | |
| 46 | |
| 47 // Triggers a check to validate suggested URL. After completion, runs the | |
| 48 // |callback|. | |
| 49 void CheckSuggestedUrl(const GURL& url, | |
| 50 const CheckUrlCallback& CheckUrlcallback); | |
|
palmer
2015/07/16 22:55:32
Nit: Name the argument |checkUrlCallback| (note ca
Bhanu Dev
2015/07/16 23:38:05
Done.
| |
| 51 | |
| 52 // Returns true if the error can be handled. Interacts with | |
|
palmer
2015/07/16 22:55:32
Nit: Don't use the passive voice here ("...be hand
Bhanu Dev
2015/07/16 23:38:06
Done. I just now realized that I use a lot of pass
| |
| 53 // |SslErrorClassification| to find the cause of the certificate | |
| 54 // validation error. If the error can be handled, writes a suggestion | |
| 55 // for a new URL to try into |suggested_url|. | |
| 56 static bool GetSuggestedUrl(const GURL& request_url, | |
|
meacer
2015/07/15 20:11:46
I'd just return a GURL() here, with empty GURL mea
palmer
2015/07/16 22:55:32
I agree.
Bhanu Dev
2015/07/16 23:38:06
I thought that, returning bool makes it easy to ch
meacer
2015/07/28 01:18:04
I think it's one less dimension you'll need to wor
| |
| 57 const std::vector<std::string>& dns_names, | |
| 58 GURL* suggested_url); | |
| 59 | |
| 60 private: | |
| 61 // net::URLFetcherDelegate: | |
| 62 void OnURLFetchComplete(const net::URLFetcher* source) override; | |
| 63 | |
| 64 // Takes a |net::URLFetcher| that has finished trying to retrieve the | |
| 65 // suggested URL, and fills a |Results| struct based on its result. | |
| 66 void GetSuggestedUrlCheckResult(const net::URLFetcher* url_fetcher, | |
| 67 Results* results) const; | |
| 68 | |
| 69 const GURL request_url_; | |
| 70 | |
| 71 // Returns true if the check is currently running. | |
| 72 bool CheckingSuggestedUrl() const; | |
| 73 | |
| 74 scoped_refptr<net::URLRequestContextGetter> request_context_; | |
| 75 | |
| 76 CheckUrlCallback check_url_callback_; | |
| 77 | |
| 78 scoped_ptr<net::URLFetcher> url_fetcher_; | |
| 79 | |
| 80 DISALLOW_COPY_AND_ASSIGN(CommonNameMismatchHandler); | |
| 81 }; | |
| 82 | |
| 83 #endif // CHROME_BROWSER_SSL_COMMON_NAME_MISMATCH_HANDLER_H_ | |
| OLD | NEW |