Chromium Code Reviews| OLD | NEW |
|---|---|
| 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; |
| 30 | |
| 31 // Initializes global state variables. | |
| 32 + (void)initialize; | |
|
Eugene But (OOO till 7-30)
2017/04/12 00:46:17
nit: There is no need to redeclare NSObject's meth
michaeldo
2017/04/12 17:16:48
Done.
| |
| 20 @end | 33 @end |
| 21 | 34 |
| 22 @implementation CWVWebViewConfiguration { | 35 // The web client associated with all configurations. |
| 23 // TODO(crbug.com/690182): CWVWebViewConfiguration should own _browserState. | 36 static std::unique_ptr<ios_web_view::WebViewWebClient> webClient; |
| 24 ios_web_view::WebViewBrowserState* _browserState; | 37 |
| 25 } | 38 @implementation CWVWebViewConfiguration |
| 26 | 39 |
| 27 @synthesize userContentController = _userContentController; | 40 @synthesize userContentController = _userContentController; |
| 28 | 41 |
| 29 + (instancetype)defaultConfiguration { | 42 + (instancetype)defaultConfiguration { |
| 30 static dispatch_once_t once; | 43 [[self class] initialize]; |
|
Eugene But (OOO till 7-30)
2017/04/12 00:46:17
I don't think you need to call this explicitly. |i
michaeldo
2017/04/12 17:16:48
Done.
| |
| 31 static CWVWebViewConfiguration* configuration; | 44 |
| 32 dispatch_once(&once, ^{ | 45 auto browserState = |
| 33 ios_web_view::WebViewWebClient* client = | 46 base::MakeUnique<ios_web_view::WebViewBrowserState>(false); |
| 34 static_cast<ios_web_view::WebViewWebClient*>(web::GetWebClient()); | 47 return [[self alloc] initWithBrowserState:std::move(browserState)]; |
| 35 configuration = [[self alloc] initWithBrowserState:client->browser_state()]; | |
| 36 }); | |
| 37 return configuration; | |
| 38 } | 48 } |
| 39 | 49 |
| 40 + (instancetype)incognitoConfiguration { | 50 + (instancetype)incognitoConfiguration { |
| 41 static dispatch_once_t once; | 51 [[self class] initialize]; |
| 42 static CWVWebViewConfiguration* configuration; | 52 |
| 43 dispatch_once(&once, ^{ | 53 auto browserState = base::MakeUnique<ios_web_view::WebViewBrowserState>(true); |
| 44 ios_web_view::WebViewWebClient* client = | 54 return [[self alloc] initWithBrowserState:std::move(browserState)]; |
| 45 static_cast<ios_web_view::WebViewWebClient*>(web::GetWebClient()); | 55 } |
| 46 configuration = [[self alloc] | 56 |
| 47 initWithBrowserState:client->off_the_record_browser_state()]; | 57 + (void)initialize { |
| 58 static std::unique_ptr<ios_web_view::WebViewWebMainDelegate> webMainDelegate; | |
|
Eugene But (OOO till 7-30)
2017/04/12 00:46:17
if (self != [CWVWebViewConfiguration class])
ret
michaeldo
2017/04/12 17:16:48
Done. But wouldn't we want this to still execute f
Eugene But (OOO till 7-30)
2017/04/12 17:48:27
For CWVConfiguration subclass this will be called
michaeldo
2017/04/12 18:22:55
Ah, I see. Thanks.
| |
| 59 static std::unique_ptr<web::WebMain> webMain; | |
| 60 static dispatch_once_t onceToken; | |
| 61 dispatch_once(&onceToken, ^{ | |
| 62 webClient = base::MakeUnique<ios_web_view::WebViewWebClient>(); | |
| 63 web::SetWebClient(webClient.get()); | |
| 64 | |
| 65 webMainDelegate = base::MakeUnique<ios_web_view::WebViewWebMainDelegate>(); | |
| 66 web::WebMainParams params(webMainDelegate.get()); | |
| 67 webMain = base::MakeUnique<web::WebMain>(params); | |
| 48 }); | 68 }); |
| 49 return configuration; | |
| 50 } | 69 } |
| 51 | 70 |
| 52 - (instancetype)initWithBrowserState: | 71 - (instancetype)initWithBrowserState: |
| 53 (ios_web_view::WebViewBrowserState*)browserState { | 72 (std::unique_ptr<ios_web_view::WebViewBrowserState>)browserState { |
| 54 self = [super init]; | 73 self = [super init]; |
| 55 if (self) { | 74 if (self) { |
| 56 _browserState = browserState; | 75 _browserState = std::move(browserState); |
| 76 | |
| 77 // Initialize translate. | |
| 78 translate::TranslateDownloadManager* downloadManager = | |
| 79 translate::TranslateDownloadManager::GetInstance(); | |
| 80 downloadManager->set_request_context(_browserState->GetRequestContext()); | |
|
Eugene But (OOO till 7-30)
2017/04/12 00:46:17
Sorry, I missed this during the previous round. Lo
michaeldo
2017/04/12 17:16:48
Sorry I missed this too. Chrome actually has a glo
michaeldo
2017/04/12 18:22:55
I've created a bug for this.
| |
| 81 // TODO(crbug.com/679895): Bring up application locale correctly. | |
| 82 downloadManager->set_application_locale(l10n_util::GetLocaleOverride()); | |
| 83 downloadManager->language_list()->SetResourceRequestsAllowed(true); | |
| 84 | |
| 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.get(); |
| 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 [[self class] initialize]; |
| 103 | |
| 104 auto browserState = base::MakeUnique<ios_web_view::WebViewBrowserState>( | |
| 105 _browserState->IsOffTheRecord()); | |
| 106 | |
| 107 return [[[self class] allocWithZone:zone] | |
| 108 initWithBrowserState:std::move(browserState)]; | |
| 75 } | 109 } |
| 76 | 110 |
| 77 @end | 111 @end |
| OLD | NEW |