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

Side by Side Diff: ios/web_view/internal/cwv_web_view_configuration.mm

Issue 2791403005: Remove CWV class and move setting User Agent to CWVWebViewConfiguration. (Closed)
Patch Set: Rebase. Created 3 years, 8 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
« no previous file with comments | « ios/web_view/internal/cwv_web_view.mm ('k') | ios/web_view/internal/web_view_browser_state.mm » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2017 The Chromium Authors. All rights reserved. 1 // Copyright 2017 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #import "ios/web_view/public/cwv_web_view_configuration.h" 5 #import "ios/web_view/public/cwv_web_view_configuration.h"
6 #import "ios/web_view/internal/cwv_web_view_configuration_internal.h" 6 #import "ios/web_view/internal/cwv_web_view_configuration_internal.h"
7 7
8 #include "base/memory/ptr_util.h"
9 #include "base/threading/thread_restrictions.h"
10 #include "components/translate/core/browser/translate_download_manager.h"
11 #include "ios/web/public/app/web_main.h"
8 #import "ios/web_view/internal/cwv_user_content_controller_internal.h" 12 #import "ios/web_view/internal/cwv_user_content_controller_internal.h"
9 #import "ios/web_view/internal/web_view_browser_state.h" 13 #import "ios/web_view/internal/web_view_browser_state.h"
10 #import "ios/web_view/internal/web_view_web_client.h" 14 #import "ios/web_view/internal/web_view_web_client.h"
15 #import "ios/web_view/internal/web_view_web_main_delegate.h"
16 #include "ui/base/l10n/l10n_util_mac.h"
11 17
12 #if !defined(__has_feature) || !__has_feature(objc_arc) 18 #if !defined(__has_feature) || !__has_feature(objc_arc)
13 #error "This file requires ARC support." 19 #error "This file requires ARC support."
14 #endif 20 #endif
15 21
16 @interface CWVWebViewConfiguration () 22 @interface CWVWebViewConfiguration () {
17 // Initialize configuration with the specified browser state. 23 // The BrowserState for this configuration.
24 std::unique_ptr<ios_web_view::WebViewBrowserState> _browserState;
25 }
26
27 // Initializes configuration with the specified browser state mode.
18 - (instancetype)initWithBrowserState: 28 - (instancetype)initWithBrowserState:
19 (ios_web_view::WebViewBrowserState*)browserState; 29 (std::unique_ptr<ios_web_view::WebViewBrowserState>)browserState;
20 @end 30 @end
21 31
22 @implementation CWVWebViewConfiguration { 32 @implementation CWVWebViewConfiguration
23 // TODO(crbug.com/690182): CWVWebViewConfiguration should own _browserState.
24 ios_web_view::WebViewBrowserState* _browserState;
25 }
26 33
27 @synthesize userContentController = _userContentController; 34 @synthesize userContentController = _userContentController;
28 35
29 + (instancetype)defaultConfiguration { 36 + (instancetype)defaultConfiguration {
30 static dispatch_once_t once; 37 auto browserState =
31 static CWVWebViewConfiguration* configuration; 38 base::MakeUnique<ios_web_view::WebViewBrowserState>(false);
32 dispatch_once(&once, ^{ 39 return [[self alloc] initWithBrowserState:std::move(browserState)];
33 ios_web_view::WebViewWebClient* client =
34 static_cast<ios_web_view::WebViewWebClient*>(web::GetWebClient());
35 configuration = [[self alloc] initWithBrowserState:client->browser_state()];
36 });
37 return configuration;
38 } 40 }
39 41
40 + (instancetype)incognitoConfiguration { 42 + (instancetype)incognitoConfiguration {
41 static dispatch_once_t once; 43 auto browserState = base::MakeUnique<ios_web_view::WebViewBrowserState>(true);
42 static CWVWebViewConfiguration* configuration; 44 return [[self alloc] initWithBrowserState:std::move(browserState)];
43 dispatch_once(&once, ^{ 45 }
44 ios_web_view::WebViewWebClient* client = 46
45 static_cast<ios_web_view::WebViewWebClient*>(web::GetWebClient()); 47 + (void)initialize {
46 configuration = [[self alloc] 48 if (self != [CWVWebViewConfiguration class]) {
47 initWithBrowserState:client->off_the_record_browser_state()]; 49 return;
50 }
51
52 static std::unique_ptr<ios_web_view::WebViewWebClient> webClient;
53 static std::unique_ptr<ios_web_view::WebViewWebMainDelegate> webMainDelegate;
54 static std::unique_ptr<web::WebMain> webMain;
55 static dispatch_once_t onceToken;
56 dispatch_once(&onceToken, ^{
57 webClient = base::MakeUnique<ios_web_view::WebViewWebClient>();
58 web::SetWebClient(webClient.get());
59
60 webMainDelegate = base::MakeUnique<ios_web_view::WebViewWebMainDelegate>();
61 web::WebMainParams params(webMainDelegate.get());
62 webMain = base::MakeUnique<web::WebMain>(params);
48 }); 63 });
49 return configuration;
50 } 64 }
51 65
52 - (instancetype)initWithBrowserState: 66 - (instancetype)initWithBrowserState:
53 (ios_web_view::WebViewBrowserState*)browserState { 67 (std::unique_ptr<ios_web_view::WebViewBrowserState>)browserState {
54 self = [super init]; 68 self = [super init];
55 if (self) { 69 if (self) {
56 _browserState = browserState; 70 _browserState = std::move(browserState);
71
72 // Initialize translate.
73 translate::TranslateDownloadManager* downloadManager =
74 translate::TranslateDownloadManager::GetInstance();
75 // TODO(crbug.com/710948): Use global request context here.
76 downloadManager->set_request_context(_browserState->GetRequestContext());
77 // TODO(crbug.com/679895): Bring up application locale correctly.
78 downloadManager->set_application_locale(l10n_util::GetLocaleOverride());
79 downloadManager->language_list()->SetResourceRequestsAllowed(true);
80
57 _userContentController = 81 _userContentController =
58 [[CWVUserContentController alloc] initWithConfiguration:self]; 82 [[CWVUserContentController alloc] initWithConfiguration:self];
59 } 83 }
60 return self; 84 return self;
61 } 85 }
62 86
63 - (BOOL)isPersistent { 87 - (BOOL)isPersistent {
64 return !_browserState->IsOffTheRecord(); 88 return !_browserState->IsOffTheRecord();
65 } 89 }
66 90
67 - (ios_web_view::WebViewBrowserState*)browserState { 91 - (ios_web_view::WebViewBrowserState*)browserState {
68 return _browserState; 92 return _browserState.get();
69 } 93 }
70 94
71 // NSCopying 95 // NSCopying
72 96
73 - (id)copyWithZone:(NSZone*)zone { 97 - (id)copyWithZone:(NSZone*)zone {
74 return [[[self class] allocWithZone:zone] initWithBrowserState:_browserState]; 98 [[self class] initialize];
99
100 auto browserState = base::MakeUnique<ios_web_view::WebViewBrowserState>(
101 _browserState->IsOffTheRecord());
102
103 return [[[self class] allocWithZone:zone]
104 initWithBrowserState:std::move(browserState)];
75 } 105 }
76 106
77 @end 107 @end
OLDNEW
« no previous file with comments | « ios/web_view/internal/cwv_web_view.mm ('k') | ios/web_view/internal/web_view_browser_state.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698