Index: chrome/browser/ssl/common_name_mismatch_handler.h |
diff --git a/chrome/browser/ssl/common_name_mismatch_handler.h b/chrome/browser/ssl/common_name_mismatch_handler.h |
new file mode 100644 |
index 0000000000000000000000000000000000000000..a0d49ffd083a2dd3ee90d8e4d3d63713f5a725c4 |
--- /dev/null |
+++ b/chrome/browser/ssl/common_name_mismatch_handler.h |
@@ -0,0 +1,91 @@ |
+// Copyright (c) 2015 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#ifndef CHROME_BROWSER_SSL_COMMON_NAME_MISMATCH_HANDLER_H_ |
+#define CHROME_BROWSER_SSL_COMMON_NAME_MISMATCH_HANDLER_H_ |
+ |
+#include "base/basictypes.h" |
+#include "base/callback.h" |
+#include "base/compiler_specific.h" |
meacer
2015/07/28 01:18:06
Why do you need this?
Bhanu Dev
2015/07/30 02:39:09
Done.
|
+#include "base/memory/ref_counted.h" |
+#include "base/memory/scoped_ptr.h" |
+#include "base/threading/non_thread_safe.h" |
+#include "base/time/time.h" |
+#include "net/url_request/url_fetcher.h" |
+#include "net/url_request/url_fetcher_delegate.h" |
+#include "net/url_request/url_request_context_getter.h" |
+#include "url/gurl.h" |
+ |
+// This class contains methods to get a suggested URL when certificate |
+// validation fails due to |ERR_CERT_COMMON_NAME_INVALID| and has methods to |
+// perform a network request to check the validity of new URL. |
+class CommonNameMismatchHandler : public net::URLFetcherDelegate, |
+ public base::NonThreadSafe { |
+ public: |
+ enum SuggestedUrlCheckResult { |
+ // The request succeeds with good response code i.e. URL exists and its |
+ // certificate is valid. |
+ RESULT_SUGGESTED_URL_VALID, |
+ // Suggested URL is invalid |
meacer
2015/07/28 01:18:05
I still think these should be named AVAILABLE/NOT_
meacer
2015/07/28 01:18:05
nit: Period at the end of comment
Bhanu Dev
2015/07/30 02:39:09
Done.
Bhanu Dev
2015/07/30 02:39:09
Done.
|
+ RESULT_SUGGESTED_URL_INVALID |
+ }; |
+ |
+ enum TestingState { |
+ NOT_TESTING, |
+ // Disables the actual request to the |suggested_url|. |
+ IGNORE_REQUESTS_FOR_TESTING |
+ }; |
+ |
+ struct Results { |
+ Results() : result(RESULT_SUGGESTED_URL_INVALID) {} |
+ |
+ SuggestedUrlCheckResult result; |
+ GURL suggested_url; |
+ }; |
+ |
+ typedef base::Callback<void(const Results& results)> CheckUrlCallback; |
+ |
+ explicit CommonNameMismatchHandler( |
meacer
2015/07/28 01:18:06
No need for explicit with a constructor with more
Bhanu Dev
2015/07/30 02:39:10
Done.
|
+ const GURL request_url, |
+ const scoped_refptr<net::URLRequestContextGetter>& request_context); |
+ ~CommonNameMismatchHandler() override; |
+ |
+ // Triggers a check to validate suggested URL. After completion, runs the |
+ // |callback|. |
+ void CheckSuggestedUrl(const GURL& url, const CheckUrlCallback& callback); |
+ |
+ // Returns true if any other DNS names in the certificate's subject |
+ // alternative names list closely match the original request hostname. |
+ // If such a domain name exists, writes a suggestion for a new URL |
+ // to try into |suggested_url|. |
+ static bool GetSuggestedUrl(const GURL& request_url, |
+ const std::vector<std::string>& dns_names, |
+ GURL* suggested_url); |
+ |
+ static TestingState testing_state_; |
meacer
2015/07/28 01:18:06
Make this private and add a getter/setter.
Bhanu Dev
2015/07/30 02:39:09
Done.
|
+ |
+ private: |
+ // net::URLFetcherDelegate: |
+ void OnURLFetchComplete(const net::URLFetcher* source) override; |
+ |
+ // Takes a |net::URLFetcher| that has finished trying to retrieve the |
+ // suggested URL, and fills a |Results| struct based on its result. |
+ void GetSuggestedUrlCheckResult(const net::URLFetcher* url_fetcher, |
+ Results* results) const; |
+ |
+ const GURL request_url_; |
+ |
+ // Returns true if the check is currently running. |
+ bool CheckingSuggestedUrl() const; |
meacer
2015/07/28 01:18:06
Move this above request_url. Keep methods and memb
Bhanu Dev
2015/07/30 02:39:09
Done.
|
+ |
+ scoped_refptr<net::URLRequestContextGetter> request_context_; |
+ |
+ CheckUrlCallback check_url_callback_; |
+ |
+ scoped_ptr<net::URLFetcher> url_fetcher_; |
+ |
+ DISALLOW_COPY_AND_ASSIGN(CommonNameMismatchHandler); |
+}; |
+ |
+#endif // CHROME_BROWSER_SSL_COMMON_NAME_MISMATCH_HANDLER_H_ |