| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 SERVICES_AUTHENTICATING_URL_LOADER_INTERCEPTOR_AUTHENTICATING_URL_LOADER
_INTERCEPTOR_H_ | 5 #ifndef SERVICES_AUTHENTICATING_URL_LOADER_INTERCEPTOR_AUTHENTICATING_URL_LOADER
_INTERCEPTOR_H_ |
| 6 #define SERVICES_AUTHENTICATING_URL_LOADER_INTERCEPTOR_AUTHENTICATING_URL_LOADER
_INTERCEPTOR_H_ | 6 #define SERVICES_AUTHENTICATING_URL_LOADER_INTERCEPTOR_AUTHENTICATING_URL_LOADER
_INTERCEPTOR_H_ |
| 7 | 7 |
| 8 #include "mojo/public/cpp/bindings/binding.h" | 8 #include "mojo/public/cpp/bindings/binding.h" |
| 9 #include "mojo/public/cpp/bindings/error_handler.h" | |
| 10 #include "mojo/services/network/public/interfaces/url_loader.mojom.h" | 9 #include "mojo/services/network/public/interfaces/url_loader.mojom.h" |
| 11 #include "services/authenticating_url_loader_interceptor/authenticating_url_load
er_interceptor_factory.h" | 10 #include "services/authenticating_url_loader_interceptor/authenticating_url_load
er_interceptor_factory.h" |
| 12 #include "url/gurl.h" | 11 #include "url/gurl.h" |
| 13 | 12 |
| 14 namespace mojo { | 13 namespace mojo { |
| 15 | 14 |
| 16 class NetworkService; | 15 class NetworkService; |
| 17 | 16 |
| 18 enum RequestAuthorizationState { | 17 enum RequestAuthorizationState { |
| 19 REQUEST_INITIAL, | 18 REQUEST_INITIAL, |
| 20 REQUEST_USED_CURRENT_AUTH_SERVICE_TOKEN, | 19 REQUEST_USED_CURRENT_AUTH_SERVICE_TOKEN, |
| 21 REQUEST_USED_FRESH_AUTH_SERVICE_TOKEN, | 20 REQUEST_USED_FRESH_AUTH_SERVICE_TOKEN, |
| 22 }; | 21 }; |
| 23 | 22 |
| 24 class AuthenticatingURLLoaderInterceptor : public URLLoaderInterceptor, | 23 class AuthenticatingURLLoaderInterceptor : public URLLoaderInterceptor { |
| 25 public ErrorHandler { | |
| 26 public: | 24 public: |
| 27 AuthenticatingURLLoaderInterceptor( | 25 AuthenticatingURLLoaderInterceptor( |
| 28 mojo::InterfaceRequest<URLLoaderInterceptor> request, | 26 mojo::InterfaceRequest<URLLoaderInterceptor> request, |
| 29 AuthenticatingURLLoaderInterceptorFactory* factory); | 27 AuthenticatingURLLoaderInterceptorFactory* factory); |
| 30 ~AuthenticatingURLLoaderInterceptor() override; | 28 ~AuthenticatingURLLoaderInterceptor() override; |
| 31 | 29 |
| 30 void set_connection_error_handler(const Closure& error_handler); |
| 31 |
| 32 private: | 32 private: |
| 33 // URLLoaderInterceptor: | 33 // URLLoaderInterceptor: |
| 34 void InterceptRequest(mojo::URLRequestPtr request, | 34 void InterceptRequest(mojo::URLRequestPtr request, |
| 35 const InterceptRequestCallback& callback) override; | 35 const InterceptRequestCallback& callback) override; |
| 36 void InterceptFollowRedirect( | 36 void InterceptFollowRedirect( |
| 37 const InterceptResponseCallback& callback) override; | 37 const InterceptResponseCallback& callback) override; |
| 38 void InterceptResponse(mojo::URLResponsePtr response, | 38 void InterceptResponse(mojo::URLResponsePtr response, |
| 39 const InterceptResponseCallback& callback) override; | 39 const InterceptResponseCallback& callback) override; |
| 40 | 40 |
| 41 // ErrorHandler: | |
| 42 void OnConnectionError() override; | |
| 43 | |
| 44 void OnOAuth2TokenReceived(std::string token); | 41 void OnOAuth2TokenReceived(std::string token); |
| 45 | 42 |
| 46 URLRequestPtr BuildRequest(std::string token); | 43 URLRequestPtr BuildRequest(std::string token); |
| 47 void StartRequest(mojo::URLRequestPtr request); | 44 void StartRequest(mojo::URLRequestPtr request); |
| 48 | 45 |
| 49 Binding<URLLoaderInterceptor> binding_; | 46 Binding<URLLoaderInterceptor> binding_; |
| 47 |
| 48 // Owns this object. |
| 50 AuthenticatingURLLoaderInterceptorFactory* factory_; | 49 AuthenticatingURLLoaderInterceptorFactory* factory_; |
| 51 InterceptResponseCallback pending_interception_callback_; | 50 InterceptResponseCallback pending_interception_callback_; |
| 52 URLResponsePtr pending_response_; | 51 URLResponsePtr pending_response_; |
| 53 bool add_authentication_; | 52 bool add_authentication_; |
| 54 RequestAuthorizationState request_authorization_state_; | 53 RequestAuthorizationState request_authorization_state_; |
| 55 GURL url_; | 54 GURL url_; |
| 56 bool auto_follow_redirects_; | 55 bool auto_follow_redirects_; |
| 57 bool bypass_cache_; | 56 bool bypass_cache_; |
| 58 Array<HttpHeaderPtr> headers_; | 57 Array<HttpHeaderPtr> headers_; |
| 59 }; | 58 }; |
| 60 | 59 |
| 61 } // namespace mojo | 60 } // namespace mojo |
| 62 | 61 |
| 63 #endif // SERVICES_AUTHENTICATING_URL_LOADER_INTERCEPTOR_AUTHENTICATING_URL_LOA
DER_INTERCEPTOR_H_ | 62 #endif // SERVICES_AUTHENTICATING_URL_LOADER_INTERCEPTOR_AUTHENTICATING_URL_LOA
DER_INTERCEPTOR_H_ |
| OLD | NEW |