Update V8 to version 4.6.61.
[chromium-blink-merge.git] / ios / web / net / web_http_protocol_handler_delegate.mm
blob9405fbe635ddd49ebcd0c3097f6a970119ab9c1f
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.
5 #include "ios/web/net/web_http_protocol_handler_delegate.h"
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"
13 namespace {
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);
25 }  // namespace
27 namespace web {
29 WebHTTPProtocolHandlerDelegate::WebHTTPProtocolHandlerDelegate(
30     net::URLRequestContextGetter* default_getter)
31     : default_getter_(default_getter) {
32   DCHECK(default_getter_);
35 WebHTTPProtocolHandlerDelegate::~WebHTTPProtocolHandlerDelegate() {
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;
46 bool WebHTTPProtocolHandlerDelegate::IsRequestSupported(NSURLRequest* request) {
47   return web::UrlHasWebScheme([request URL]) ||
48          [CRWStaticFileWebView isStaticFileRequest:request] ||
49          (IsAppSpecificScheme([request URL]) &&
50           IsAppSpecificScheme([request mainDocumentURL]));
53 net::URLRequestContextGetter*
54 WebHTTPProtocolHandlerDelegate::GetDefaultURLRequestContext() {
55   return default_getter_.get();
58 }  // namespace web