Chromium Code Reviews| 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 |