| OLD | NEW |
| (Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef IOS_WEB_NET_REQUEST_GROUP_UTIL_H_ |
| 6 #define IOS_WEB_NET_REQUEST_GROUP_UTIL_H_ |
| 7 |
| 8 @class NSString; |
| 9 @class NSURL; |
| 10 @class NSURLRequest; |
| 11 |
| 12 // Request group IDs are internally used by the web layer to associate network |
| 13 // requests to RequestTracker instances, and in turn, to WebState instances. |
| 14 // The ID can be added to the user-agent string by UIWebView in most cases and |
| 15 // then extracted by the network layer. |
| 16 // However, when using non-standard schemes, UIWebView does not add the |
| 17 // "User-Agent" HTTP header to the requests. The workaround for this case is to |
| 18 // add the ID directly in the URL of the main request (which is the only request |
| 19 // accessible from the UIWebView delegate). |
| 20 |
| 21 namespace web { |
| 22 |
| 23 // Generates a request-group ID. |
| 24 NSString* GenerateNewRequestGroupID(); |
| 25 |
| 26 // Extracts the requestGroupID embedded in a User-Agent string or nil if a |
| 27 // requestGroupID cannot be located. |
| 28 NSString* ExtractRequestGroupIDFromUserAgent(NSString* user_agent); |
| 29 |
| 30 // Returns a new user agent, which is the result of the encoding of |
| 31 // |request_group_id| in |base_user_agent|. The request group ID can be later |
| 32 // extracted with ExtractRequestGroupIDFromUserAgent(). |
| 33 NSString* AddRequestGroupIDToUserAgent(NSString* base_user_agent, |
| 34 NSString* request_group_id); |
| 35 |
| 36 // Extracts the requestGroupID embedded in a NSURL or nil if a requestGroupID |
| 37 // cannot be located. |
| 38 NSString* ExtractRequestGroupIDFromURL(NSURL* url); |
| 39 |
| 40 // Returns a new user agent, which is the result of the encoding of |
| 41 // |request_group_id| in |base_url|. The request group ID can be later extracted |
| 42 // with ExtractRequestGroupIDFromURL(). |
| 43 NSURL* AddRequestGroupIDToURL(NSURL* base_url, NSString* request_group_id); |
| 44 |
| 45 // Extracts the request group ID from |request| by retrieving it from the |
| 46 // user-agent if possible, and from the parent URL otherwise. |
| 47 // The ID can only be retrived from the parent URL if its scheme is |
| 48 // |application_scheme|. |
| 49 // The reason why the |application_scheme| case is different is because |
| 50 // UIWebView does not provide a "User-Agent" HTTP header for these requests. |
| 51 // The ID is then encoded in the URL of the main request, and thus sub-requests |
| 52 // have to look in their parent URL for the ID. |
| 53 NSString* ExtractRequestGroupIDFromRequest(NSURLRequest* request, |
| 54 NSString* application_scheme); |
| 55 |
| 56 } // namespace web |
| 57 |
| 58 #endif // IOS_WEB_NET_REQUEST_GROUP_UTIL_H_ |
| OLD | NEW |