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

Unified Diff: ios/web_view/internal/criwv.mm

Issue 2643773005: Upstream ios/web_view source code. (Closed)
Patch Set: Created 3 years, 11 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_view/internal/criwv.mm
diff --git a/ios/web_view/internal/criwv.mm b/ios/web_view/internal/criwv.mm
new file mode 100644
index 0000000000000000000000000000000000000000..3c3096f735976fc31d530173a5cd6e0ea2af971d
--- /dev/null
+++ b/ios/web_view/internal/criwv.mm
@@ -0,0 +1,102 @@
+// 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.
+
+#import "ios/web_view/public/criwv.h"
+
+#include <memory>
+
+#include "base/location.h"
+#import "base/mac/bind_objc_block.h"
+#include "base/single_thread_task_runner.h"
+#import "ios/net/crn_http_protocol_handler.h"
+#import "ios/net/empty_nsurlcache.h"
+#import "ios/web/net/request_tracker_factory_impl.h"
+#import "ios/web/net/request_tracker_impl.h"
+#import "ios/web/net/web_http_protocol_handler_delegate.h"
+#include "ios/web/public/app/web_main.h"
+#include "ios/web/public/web_thread.h"
+#include "ios/web_view/internal/criwv_browser_state.h"
+#import "ios/web_view/internal/criwv_web_client.h"
+#import "ios/web_view/internal/criwv_web_main_delegate.h"
+#import "ios/web_view/internal/criwv_web_view_impl.h"
+#import "ios/web_view/public/criwv_delegate.h"
+#include "net/url_request/url_request_context_getter.h"
+
+namespace {
+CRIWV* g_criwv = nil;
+}
+
+@interface CRIWV () {
+ id<CRIWVDelegate> _delegate;
+ std::unique_ptr<ios_web_view::CRIWVWebMainDelegate> _webMainDelegate;
+ std::unique_ptr<web::WebMain> _webMain;
+ std::unique_ptr<web::RequestTrackerFactoryImpl> _requestTrackerFactory;
+ std::unique_ptr<web::WebHTTPProtocolHandlerDelegate> _httpProtocolDelegate;
+}
+
+- (instancetype)initWithDelegate:(id<CRIWVDelegate>)delegate;
+- (void)installNetworkStackImpl;
+- (ios_web_view::CRIWVBrowserState*)browserState;
+@end
+
+@implementation CRIWV
+
++ (void)configureWithDelegate:(id<CRIWVDelegate>)delegate {
+ g_criwv = [[CRIWV alloc] initWithDelegate:delegate];
+}
+
++ (void)shutDown {
+ [g_criwv release];
+ g_criwv = nil;
+}
+
++ (void)installNetworkStack {
+ [g_criwv installNetworkStackImpl];
+}
+
++ (id<CRIWVWebView>)webView {
+ return [[[CRIWVWebViewImpl alloc] initWithBrowserState:[g_criwv browserState]]
+ autorelease];
+}
+
+- (instancetype)initWithDelegate:(id<CRIWVDelegate>)delegate {
+ self = [super init];
+ if (self) {
+ _delegate = delegate;
+ _webMainDelegate.reset(new ios_web_view::CRIWVWebMainDelegate(_delegate));
+ web::WebMainParams params(_webMainDelegate.get());
+ _webMain.reset(new web::WebMain(params));
+ }
+ return self;
+}
+
+- (void)dealloc {
+ _webMain.reset();
+ _webMainDelegate.reset();
+ net::RequestTracker::SetRequestTrackerFactory(nullptr);
+ net::HTTPProtocolHandlerDelegate::SetInstance(nullptr);
+ [super dealloc];
+}
+
+- (void)installNetworkStackImpl {
+ // Disable the default cache.
+ [NSURLCache setSharedURLCache:[EmptyNSURLCache emptyNSURLCache]];
+
+ _httpProtocolDelegate.reset(new web::WebHTTPProtocolHandlerDelegate(
sdefresne 2017/01/20 10:28:12 This is only required for UIWebView IIUC. Given th
michaeldo 2017/01/20 18:43:30 Done.
+ [self browserState]->GetRequestContext()));
+ net::HTTPProtocolHandlerDelegate::SetInstance(_httpProtocolDelegate.get());
+ BOOL success = [NSURLProtocol registerClass:[CRNHTTPProtocolHandler class]];
+ DCHECK(success);
+ _requestTrackerFactory.reset(
+ new web::RequestTrackerFactoryImpl(std::string()));
+ net::RequestTracker::SetRequestTrackerFactory(_requestTrackerFactory.get());
+}
+
+- (ios_web_view::CRIWVBrowserState*)browserState {
+ ios_web_view::CRIWVWebClient* client =
+ static_cast<ios_web_view::CRIWVWebClient*>(web::GetWebClient());
+ return client->browser_state();
+}
+
+@end

Powered by Google App Engine
This is Rietveld 408576698