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 #include "ios/web/net/web_http_protocol_handler_delegate.h" |
| 6 |
| 7 #include "ios/web/public/url_scheme_util.h" |
| 8 #include "ios/web/public/web_client.h" |
| 9 #import "ios/web/web_state/ui/crw_static_file_web_view.h" |
| 10 #include "net/url_request/url_request_context_getter.h" |
| 11 #include "url/gurl.h" |
| 12 |
| 13 namespace { |
| 14 |
| 15 bool IsAppSpecificScheme(NSURL* url) { |
| 16 NSString* scheme = [url scheme]; |
| 17 if (![scheme length]) |
| 18 return false; |
| 19 // Use the GURL implementation, but with a scheme-only URL to avoid |
| 20 // unnecessary parsing in GURL construction. |
| 21 GURL gurl([[scheme stringByAppendingString:@":"] UTF8String]); |
| 22 return web::GetWebClient()->IsAppSpecificURL(gurl); |
| 23 } |
| 24 |
| 25 } // namespace |
| 26 |
| 27 namespace web { |
| 28 |
| 29 WebHTTPProtocolHandlerDelegate::WebHTTPProtocolHandlerDelegate( |
| 30 net::URLRequestContextGetter* default_getter) |
| 31 : default_getter_(default_getter) { |
| 32 DCHECK(default_getter_); |
| 33 } |
| 34 |
| 35 WebHTTPProtocolHandlerDelegate::~WebHTTPProtocolHandlerDelegate() { |
| 36 } |
| 37 |
| 38 bool WebHTTPProtocolHandlerDelegate::CanHandleRequest(NSURLRequest* request) { |
| 39 // Accept all the requests. If we declined a request, it would then be passed |
| 40 // to the default iOS network stack, which would possibly load it. |
| 41 // As we want to control what is loaded, we have to prevent the default stack |
| 42 // from loading anything. |
| 43 return true; |
| 44 } |
| 45 |
| 46 bool WebHTTPProtocolHandlerDelegate::IsRequestSupported(NSURLRequest* request) { |
| 47 return web::UrlHasWebScheme([request URL]) || |
| 48 [CRWStaticFileWebView isStaticFileRequest:request] || |
| 49 (IsAppSpecificScheme([request URL]) && |
| 50 IsAppSpecificScheme([request mainDocumentURL])); |
| 51 } |
| 52 |
| 53 net::URLRequestContextGetter* |
| 54 WebHTTPProtocolHandlerDelegate::GetDefaultURLRequestContext() { |
| 55 return default_getter_.get(); |
| 56 } |
| 57 |
| 58 } // namespace web |
OLD | NEW |