Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(765)

Unified Diff: ios/web/net/web_http_protocol_handler_delegate.mm

Issue 1043243003: Upstream most of ios/web/net (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Remove accidentally-added clients Created 5 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: ios/web/net/web_http_protocol_handler_delegate.mm
diff --git a/ios/web/net/web_http_protocol_handler_delegate.mm b/ios/web/net/web_http_protocol_handler_delegate.mm
new file mode 100644
index 0000000000000000000000000000000000000000..9405fbe635ddd49ebcd0c3097f6a970119ab9c1f
--- /dev/null
+++ b/ios/web/net/web_http_protocol_handler_delegate.mm
@@ -0,0 +1,58 @@
+// Copyright 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "ios/web/net/web_http_protocol_handler_delegate.h"
+
+#include "ios/web/public/url_scheme_util.h"
+#include "ios/web/public/web_client.h"
+#import "ios/web/web_state/ui/crw_static_file_web_view.h"
+#include "net/url_request/url_request_context_getter.h"
+#include "url/gurl.h"
+
+namespace {
+
+bool IsAppSpecificScheme(NSURL* url) {
+ NSString* scheme = [url scheme];
+ if (![scheme length])
+ return false;
+ // Use the GURL implementation, but with a scheme-only URL to avoid
+ // unnecessary parsing in GURL construction.
+ GURL gurl([[scheme stringByAppendingString:@":"] UTF8String]);
+ return web::GetWebClient()->IsAppSpecificURL(gurl);
+}
+
+} // namespace
+
+namespace web {
+
+WebHTTPProtocolHandlerDelegate::WebHTTPProtocolHandlerDelegate(
+ net::URLRequestContextGetter* default_getter)
+ : default_getter_(default_getter) {
+ DCHECK(default_getter_);
+}
+
+WebHTTPProtocolHandlerDelegate::~WebHTTPProtocolHandlerDelegate() {
+}
+
+bool WebHTTPProtocolHandlerDelegate::CanHandleRequest(NSURLRequest* request) {
+ // Accept all the requests. If we declined a request, it would then be passed
+ // to the default iOS network stack, which would possibly load it.
+ // As we want to control what is loaded, we have to prevent the default stack
+ // from loading anything.
+ return true;
+}
+
+bool WebHTTPProtocolHandlerDelegate::IsRequestSupported(NSURLRequest* request) {
+ return web::UrlHasWebScheme([request URL]) ||
+ [CRWStaticFileWebView isStaticFileRequest:request] ||
+ (IsAppSpecificScheme([request URL]) &&
+ IsAppSpecificScheme([request mainDocumentURL]));
+}
+
+net::URLRequestContextGetter*
+WebHTTPProtocolHandlerDelegate::GetDefaultURLRequestContext() {
+ return default_getter_.get();
+}
+
+} // namespace web
« no previous file with comments | « ios/web/net/web_http_protocol_handler_delegate.h ('k') | ios/web/net/web_http_protocol_handler_delegate_unittest.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698