Revert "Fix broken channel icon in chrome://help on CrOS" and try again
[chromium-blink-merge.git] / ios / net / clients / crn_network_client_protocol.h
blobaebd1554468a7c02b721771301820e82b5d3cf88
1 // Copyright 2012 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.
5 #ifndef IOS_NET_CLIENTS_CRN_NETWORK_CLIENT_PROTOCOL_H_
6 #define IOS_NET_CLIENTS_CRN_NETWORK_CLIENT_PROTOCOL_H_
8 #import <Foundation/Foundation.h>
10 #include "base/callback_forward.h"
11 #include "base/memory/scoped_ptr.h"
12 #include "base/strings/string_util.h"
14 namespace net {
15 class AuthChallengeInfo;
16 class URLRequest;
17 } // namespace net
19 namespace network_client {
20 typedef base::Callback<void(bool auth_ok,
21 const base::string16& username,
22 const base::string16& password)> AuthCallback;
23 } // namespace network_client
25 // CRNNetworkClientProtocol provides an interface for delegate classes that
26 // receive calls about data loading from the Chromium network stack.
27 // Many methods in this protocol correspond to the NSURLProtocol methods, and
28 // are called by the HttpProtocolHandlerCore when events occur in the network
29 // stack. A class that implements this protocol can respond by proxying the call
30 // over to an NSURLProtocolClient that it manages, or by managing the data as it
31 // sees fit.
32 @protocol CRNNetworkClientProtocol<NSObject>
33 // Methods corresponding to NSURLProtocolClient methods.
34 // Called from the IO thread.
35 // Corresponds to |-URLProtocol:didFailWithError|.
36 // The base client will create an NSError instance using |nsErrorCode| (an error
37 // code from NSURLError.h) and |netErrorCode| (a Chrome errror code) and url
38 // and creation time information supplied by the HttpProtocolHandlerCore
39 // instance.
40 - (void)didFailWithNSErrorCode:(NSInteger)nsErrorCode
41 netErrorCode:(int)netErrorCode;
42 // Corresponds to |-URLProtocol:didLoadData|.
43 - (void)didLoadData:(NSData*)data;
44 // Corresponds to |-URLProtocol:didReceiveResponse:cacheStoragePolicy|.
45 - (void)didReceiveResponse:(NSURLResponse*)response;
46 // Corresponds to |-URLProtocol:wasRedirectedToRequest:redirectResponse|.
47 // TODO(marq): make |nativeRequest| a const ref.
48 - (void)wasRedirectedToRequest:(NSURLRequest*)request
49 nativeRequest:(net::URLRequest*)nativeRequest
50 redirectResponse:(NSURLResponse*)redirectResponse;
51 // Corresponds to |-URLProtocol:didFinishLoading|.
52 - (void)didFinishLoading;
54 // Methods that don't correspond to NSURLProtocolClient methdods but which are
55 // used to implement injectible features using network clients.
57 // Called after |nativeRequest| is created, but before it's started; native
58 // clients have the opportunity to modify the request at this time.
59 - (void)didCreateNativeRequest:(net::URLRequest*)nativeRequest;
61 // Called when an authentication challenge represented by |authInfo| is recieved
62 // from |nativeRequest|.
63 // Clients that won't handle the challenge should forward this call down the
64 // client stack.
65 // Clients that will handle the request should do so asynchronously, immediately
66 // returning without forwarding down the client stack, and then invoking
67 // |callback| on the IO thread when credentials are available.
68 // |callback|'s first parameter is a boolean that indicates if authentication
69 // was successful.
70 // If authentication was successful, |callback|'s second and third parameters
71 // are username and password; if unsuccesful they are empty strings.
72 - (void)didRecieveAuthChallenge:(net::AuthChallengeInfo*)authInfo
73 nativeRequest:(const net::URLRequest&)nativeRequest
74 callback:(const network_client::AuthCallback&)callback;
76 // Called when a request is terminated, signalling that any outstanding
77 // authentication requests should cancel.
78 - (void)cancelAuthRequest;
80 // If |underlyingClient| is not nil, the protocol is responsible for calling it.
81 // If the protocol is only listening for network events, it should simply
82 // forward all the calls to the underlying client.
83 // Called from the IO thread.
84 - (void)setUnderlyingClient:(id<CRNNetworkClientProtocol>)underlyingClient;
85 @end
87 #endif // IOS_NET_CLIENTS_CRN_NETWORK_CLIENT_PROTOCOL_H_