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

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: 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
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/strings/sys_string_conversions.h"
10 #include "ios/web/public/app/web_main.h"
8 #import "ios/web_view/internal/cwv_user_content_controller_internal.h" 11 #import "ios/web_view/internal/cwv_user_content_controller_internal.h"
9 #import "ios/web_view/internal/web_view_browser_state.h" 12 #import "ios/web_view/internal/web_view_browser_state.h"
10 #import "ios/web_view/internal/web_view_web_client.h" 13 #import "ios/web_view/internal/web_view_web_client.h"
14 #import "ios/web_view/internal/web_view_web_main_delegate.h"
11 15
12 #if !defined(__has_feature) || !__has_feature(objc_arc) 16 #if !defined(__has_feature) || !__has_feature(objc_arc)
13 #error "This file requires ARC support." 17 #error "This file requires ARC support."
14 #endif 18 #endif
15 19
16 @interface CWVWebViewConfiguration () 20 @interface CWVWebViewConfiguration ()
17 // Initialize configuration with the specified browser state. 21 // Initialize configuration with the specified browser state.
18 - (instancetype)initWithBrowserState: 22 - (instancetype)initWithBrowserState:
19 (ios_web_view::WebViewBrowserState*)browserState; 23 (ios_web_view::WebViewBrowserState*)browserState;
20 @end 24 @end
21 25
26 // The name of the product to be used in the User Agent string.
27 static NSString* userAgentProductName;
28
22 @implementation CWVWebViewConfiguration { 29 @implementation CWVWebViewConfiguration {
23 // TODO(crbug.com/690182): CWVWebViewConfiguration should own _browserState. 30 // TODO(crbug.com/690182): CWVWebViewConfiguration should own _browserState.
24 ios_web_view::WebViewBrowserState* _browserState; 31 ios_web_view::WebViewBrowserState* _browserState;
25 } 32 }
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 static dispatch_once_t once;
31 static CWVWebViewConfiguration* configuration; 38 static CWVWebViewConfiguration* configuration;
32 dispatch_once(&once, ^{ 39 dispatch_once(&once, ^{
40 [self setupWebClientIfNeeded];
41
33 ios_web_view::WebViewWebClient* client = 42 ios_web_view::WebViewWebClient* client =
34 static_cast<ios_web_view::WebViewWebClient*>(web::GetWebClient()); 43 static_cast<ios_web_view::WebViewWebClient*>(web::GetWebClient());
35 configuration = [[self alloc] initWithBrowserState:client->browser_state()]; 44 configuration = [[self alloc] initWithBrowserState:client->browser_state()];
36 }); 45 });
37 return configuration; 46 return configuration;
38 } 47 }
39 48
40 + (instancetype)incognitoConfiguration { 49 + (instancetype)incognitoConfiguration {
41 static dispatch_once_t once; 50 static dispatch_once_t once;
42 static CWVWebViewConfiguration* configuration; 51 static CWVWebViewConfiguration* configuration;
43 dispatch_once(&once, ^{ 52 dispatch_once(&once, ^{
53 [self setupWebClientIfNeeded];
54
44 ios_web_view::WebViewWebClient* client = 55 ios_web_view::WebViewWebClient* client =
45 static_cast<ios_web_view::WebViewWebClient*>(web::GetWebClient()); 56 static_cast<ios_web_view::WebViewWebClient*>(web::GetWebClient());
46 configuration = [[self alloc] 57 configuration = [[self alloc]
47 initWithBrowserState:client->off_the_record_browser_state()]; 58 initWithBrowserState:client->off_the_record_browser_state()];
48 }); 59 });
49 return configuration; 60 return configuration;
50 } 61 }
51 62
63 + (void)setupWebClientIfNeeded {
Eugene But (OOO till 7-30) 2017/04/04 21:50:26 Does this method need a different name? It does no
Eugene But (OOO till 7-30) 2017/04/04 21:50:26 Please add comments.
michaeldo 2017/04/07 22:31:35 PTAL, in newest patch, I renamed to webClient and
64 static std::unique_ptr<ios_web_view::WebViewWebMainDelegate> webMainDelegate;
65 static std::unique_ptr<web::WebMain> webMain;
66
67 static dispatch_once_t onceToken;
68 dispatch_once(&onceToken, ^{
69 webMainDelegate = base::MakeUnique<ios_web_view::WebViewWebMainDelegate>(
70 base::SysNSStringToUTF8(userAgentProductName));
71 web::WebMainParams params(webMainDelegate.get());
72 webMain = base::MakeUnique<web::WebMain>(params);
73 });
74 }
75
76 + (void)setUserAgentProductName:(NSString*)productName {
77 userAgentProductName = productName;
78 }
79
52 - (instancetype)initWithBrowserState: 80 - (instancetype)initWithBrowserState:
53 (ios_web_view::WebViewBrowserState*)browserState { 81 (ios_web_view::WebViewBrowserState*)browserState {
54 self = [super init]; 82 self = [super init];
55 if (self) { 83 if (self) {
56 _browserState = browserState; 84 _browserState = browserState;
57 _userContentController = 85 _userContentController =
58 [[CWVUserContentController alloc] initWithConfiguration:self]; 86 [[CWVUserContentController alloc] initWithConfiguration:self];
59 } 87 }
60 return self; 88 return self;
61 } 89 }
62 90
63 - (BOOL)isPersistent { 91 - (BOOL)isPersistent {
64 return !_browserState->IsOffTheRecord(); 92 return !_browserState->IsOffTheRecord();
65 } 93 }
66 94
67 - (ios_web_view::WebViewBrowserState*)browserState { 95 - (ios_web_view::WebViewBrowserState*)browserState {
68 return _browserState; 96 return _browserState;
69 } 97 }
70 98
71 // NSCopying 99 // NSCopying
72 100
73 - (id)copyWithZone:(NSZone*)zone { 101 - (id)copyWithZone:(NSZone*)zone {
74 return [[[self class] allocWithZone:zone] initWithBrowserState:_browserState]; 102 return [[[self class] allocWithZone:zone] initWithBrowserState:_browserState];
75 } 103 }
76 104
77 @end 105 @end
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698