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

Side by Side 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 unified diff | Download patch
OLDNEW
(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 #import "ios/web_view/public/criwv.h"
6
7 #include <memory>
8
9 #include "base/location.h"
10 #import "base/mac/bind_objc_block.h"
11 #include "base/single_thread_task_runner.h"
12 #import "ios/net/crn_http_protocol_handler.h"
13 #import "ios/net/empty_nsurlcache.h"
14 #import "ios/web/net/request_tracker_factory_impl.h"
15 #import "ios/web/net/request_tracker_impl.h"
16 #import "ios/web/net/web_http_protocol_handler_delegate.h"
17 #include "ios/web/public/app/web_main.h"
18 #include "ios/web/public/web_thread.h"
19 #include "ios/web_view/internal/criwv_browser_state.h"
20 #import "ios/web_view/internal/criwv_web_client.h"
21 #import "ios/web_view/internal/criwv_web_main_delegate.h"
22 #import "ios/web_view/internal/criwv_web_view_impl.h"
23 #import "ios/web_view/public/criwv_delegate.h"
24 #include "net/url_request/url_request_context_getter.h"
25
26 namespace {
27 CRIWV* g_criwv = nil;
28 }
29
30 @interface CRIWV () {
31 id<CRIWVDelegate> _delegate;
32 std::unique_ptr<ios_web_view::CRIWVWebMainDelegate> _webMainDelegate;
33 std::unique_ptr<web::WebMain> _webMain;
34 std::unique_ptr<web::RequestTrackerFactoryImpl> _requestTrackerFactory;
35 std::unique_ptr<web::WebHTTPProtocolHandlerDelegate> _httpProtocolDelegate;
36 }
37
38 - (instancetype)initWithDelegate:(id<CRIWVDelegate>)delegate;
39 - (void)installNetworkStackImpl;
40 - (ios_web_view::CRIWVBrowserState*)browserState;
41 @end
42
43 @implementation CRIWV
44
45 + (void)configureWithDelegate:(id<CRIWVDelegate>)delegate {
46 g_criwv = [[CRIWV alloc] initWithDelegate:delegate];
47 }
48
49 + (void)shutDown {
50 [g_criwv release];
51 g_criwv = nil;
52 }
53
54 + (void)installNetworkStack {
55 [g_criwv installNetworkStackImpl];
56 }
57
58 + (id<CRIWVWebView>)webView {
59 return [[[CRIWVWebViewImpl alloc] initWithBrowserState:[g_criwv browserState]]
60 autorelease];
61 }
62
63 - (instancetype)initWithDelegate:(id<CRIWVDelegate>)delegate {
64 self = [super init];
65 if (self) {
66 _delegate = delegate;
67 _webMainDelegate.reset(new ios_web_view::CRIWVWebMainDelegate(_delegate));
68 web::WebMainParams params(_webMainDelegate.get());
69 _webMain.reset(new web::WebMain(params));
70 }
71 return self;
72 }
73
74 - (void)dealloc {
75 _webMain.reset();
76 _webMainDelegate.reset();
77 net::RequestTracker::SetRequestTrackerFactory(nullptr);
78 net::HTTPProtocolHandlerDelegate::SetInstance(nullptr);
79 [super dealloc];
80 }
81
82 - (void)installNetworkStackImpl {
83 // Disable the default cache.
84 [NSURLCache setSharedURLCache:[EmptyNSURLCache emptyNSURLCache]];
85
86 _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.
87 [self browserState]->GetRequestContext()));
88 net::HTTPProtocolHandlerDelegate::SetInstance(_httpProtocolDelegate.get());
89 BOOL success = [NSURLProtocol registerClass:[CRNHTTPProtocolHandler class]];
90 DCHECK(success);
91 _requestTrackerFactory.reset(
92 new web::RequestTrackerFactoryImpl(std::string()));
93 net::RequestTracker::SetRequestTrackerFactory(_requestTrackerFactory.get());
94 }
95
96 - (ios_web_view::CRIWVBrowserState*)browserState {
97 ios_web_view::CRIWVWebClient* client =
98 static_cast<ios_web_view::CRIWVWebClient*>(web::GetWebClient());
99 return client->browser_state();
100 }
101
102 @end
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698