OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef CHROME_BROWSER_EXTENSIONS_API_IDENTITY_GAIA_WEB_AUTH_FLOW_H_ | 5 #ifndef CHROME_BROWSER_EXTENSIONS_API_IDENTITY_GAIA_WEB_AUTH_FLOW_H_ |
6 #define CHROME_BROWSER_EXTENSIONS_API_IDENTITY_GAIA_WEB_AUTH_FLOW_H_ | 6 #define CHROME_BROWSER_EXTENSIONS_API_IDENTITY_GAIA_WEB_AUTH_FLOW_H_ |
7 | 7 |
8 #include "base/macros.h" | 8 #include "base/macros.h" |
9 #include "chrome/browser/extensions/api/identity/extension_token_key.h" | 9 #include "chrome/browser/extensions/api/identity/extension_token_key.h" |
10 #include "chrome/browser/extensions/api/identity/web_auth_flow.h" | 10 #include "chrome/browser/extensions/api/identity/web_auth_flow.h" |
11 #include "extensions/common/manifest_handlers/oauth2_manifest_handler.h" | 11 #include "extensions/common/manifest_handlers/oauth2_manifest_handler.h" |
12 #include "google_apis/gaia/ubertoken_fetcher.h" | 12 #include "google_apis/gaia/ubertoken_fetcher.h" |
| 13 #include "net/http/http_cache.h" |
| 14 |
| 15 namespace net { |
| 16 class HttpNetworkSession; |
| 17 class TrivialURLRequestContextGetter; |
| 18 } |
13 | 19 |
14 namespace extensions { | 20 namespace extensions { |
15 | 21 |
16 // Implements a web-based OAuth2 scope approval dialog. This flow has | 22 // Implements a web-based OAuth2 scope approval dialog. This flow has |
17 // four parts: | 23 // four parts: |
18 // 1. Fetch an ubertoken for a signed-in user. | 24 // 1. Fetch an ubertoken for a signed-in user. |
19 // 2. Use the ubertoken to get session cookies using MergeSession. | 25 // 2. Use the ubertoken to get session cookies using MergeSession. |
20 // 3. Start the OAuth flow and wait for final redirect. | 26 // 3. Start the OAuth flow and wait for final redirect. |
21 // 4. Parse results from the fragment component of the final redirect URI. | 27 // 4. Parse results from the fragment component of the final redirect URI. |
22 // | 28 // |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
76 // WebAuthFlow::Delegate implementation. | 82 // WebAuthFlow::Delegate implementation. |
77 void OnAuthFlowFailure(WebAuthFlow::Failure failure) override; | 83 void OnAuthFlowFailure(WebAuthFlow::Failure failure) override; |
78 void OnAuthFlowURLChange(const GURL& redirect_url) override; | 84 void OnAuthFlowURLChange(const GURL& redirect_url) override; |
79 void OnAuthFlowTitleChange(const std::string& title) override; | 85 void OnAuthFlowTitleChange(const std::string& title) override; |
80 | 86 |
81 private: | 87 private: |
82 // Creates a WebAuthFlow, which will navigate to |url|. Can override | 88 // Creates a WebAuthFlow, which will navigate to |url|. Can override |
83 // for testing. Used to kick off the MergeSession (step #2). | 89 // for testing. Used to kick off the MergeSession (step #2). |
84 virtual std::unique_ptr<WebAuthFlow> CreateWebAuthFlow(GURL url); | 90 virtual std::unique_ptr<WebAuthFlow> CreateWebAuthFlow(GURL url); |
85 | 91 |
| 92 class IOHelper { |
| 93 public: |
| 94 IOHelper(base::WeakPtr<GaiaWebAuthFlow> gaia_web_auth_flow, |
| 95 net::URLRequestContextGetter* main_context); |
| 96 ~IOHelper(); |
| 97 |
| 98 void PrepareRequestContext(); |
| 99 void Cleanup(); |
| 100 |
| 101 net::URLRequestContext* ubertoken_request_context() { |
| 102 return ubertoken_request_context_.get(); |
| 103 } |
| 104 |
| 105 private: |
| 106 std::unique_ptr<net::HttpCache::BackendFactory> app_backend_; |
| 107 std::unique_ptr<net::HttpNetworkSession> http_network_session_; |
| 108 std::unique_ptr<net::HttpCache> app_http_cache_; |
| 109 std::unique_ptr<net::URLRequestContext> ubertoken_request_context_; |
| 110 |
| 111 base::WeakPtr<GaiaWebAuthFlow> gaia_web_auth_flow_; |
| 112 net::URLRequestContextGetter* main_context_; |
| 113 }; |
| 114 |
| 115 void StartUberTokenFetch(); |
| 116 |
86 Delegate* delegate_; | 117 Delegate* delegate_; |
87 Profile* profile_; | 118 Profile* profile_; |
88 std::string account_id_; | 119 std::string account_id_; |
89 std::string redirect_scheme_; | 120 std::string redirect_scheme_; |
90 std::string redirect_path_prefix_; | 121 std::string redirect_path_prefix_; |
91 GURL auth_url_; | 122 GURL auth_url_; |
| 123 |
| 124 std::unique_ptr<IOHelper> io_helper_; |
92 std::unique_ptr<UbertokenFetcher> ubertoken_fetcher_; | 125 std::unique_ptr<UbertokenFetcher> ubertoken_fetcher_; |
93 std::unique_ptr<WebAuthFlow> web_flow_; | 126 std::unique_ptr<WebAuthFlow> web_flow_; |
| 127 scoped_refptr<net::TrivialURLRequestContextGetter> context_getter_; |
| 128 |
| 129 base::WeakPtrFactory<GaiaWebAuthFlow> weak_ptr_factory_; |
94 | 130 |
95 DISALLOW_COPY_AND_ASSIGN(GaiaWebAuthFlow); | 131 DISALLOW_COPY_AND_ASSIGN(GaiaWebAuthFlow); |
96 }; | 132 }; |
97 | 133 |
98 } // namespace extensions | 134 } // namespace extensions |
99 | 135 |
100 #endif // CHROME_BROWSER_EXTENSIONS_API_IDENTITY_GAIA_WEB_AUTH_FLOW_H_ | 136 #endif // CHROME_BROWSER_EXTENSIONS_API_IDENTITY_GAIA_WEB_AUTH_FLOW_H_ |
OLD | NEW |