Chromium Code Reviews| Index: ios/web_view/internal/cwv_web_view_configuration.mm |
| diff --git a/ios/web_view/internal/cwv_web_view_configuration.mm b/ios/web_view/internal/cwv_web_view_configuration.mm |
| index d8916d719da520424576cd898b40c9e11e064559..0733dcb6194bd4d3e6e76bf6ccb6888e374129d2 100644 |
| --- a/ios/web_view/internal/cwv_web_view_configuration.mm |
| +++ b/ios/web_view/internal/cwv_web_view_configuration.mm |
| @@ -5,55 +5,83 @@ |
| #import "ios/web_view/public/cwv_web_view_configuration.h" |
| #import "ios/web_view/internal/cwv_web_view_configuration_internal.h" |
| +#include "base/memory/ptr_util.h" |
| +#include "base/threading/thread_restrictions.h" |
| +#include "components/translate/core/browser/translate_download_manager.h" |
| +#include "ios/web/public/app/web_main.h" |
| #import "ios/web_view/internal/cwv_user_content_controller_internal.h" |
| #import "ios/web_view/internal/web_view_browser_state.h" |
| #import "ios/web_view/internal/web_view_web_client.h" |
| +#import "ios/web_view/internal/web_view_web_main_delegate.h" |
| +#include "ui/base/l10n/l10n_util_mac.h" |
| #if !defined(__has_feature) || !__has_feature(objc_arc) |
| #error "This file requires ARC support." |
| #endif |
| -@interface CWVWebViewConfiguration () |
| -// Initialize configuration with the specified browser state. |
| +@interface CWVWebViewConfiguration () { |
| + // The BrowserState for this configuration. |
| + std::unique_ptr<ios_web_view::WebViewBrowserState> _browserState; |
| +} |
| + |
| +// Initializes configuration with the specified browser state mode. |
| - (instancetype)initWithBrowserState: |
| - (ios_web_view::WebViewBrowserState*)browserState; |
| + (std::unique_ptr<ios_web_view::WebViewBrowserState>)browserState; |
| + |
| +// Initializes global state variables. |
| ++ (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.
|
| @end |
| -@implementation CWVWebViewConfiguration { |
| - // TODO(crbug.com/690182): CWVWebViewConfiguration should own _browserState. |
| - ios_web_view::WebViewBrowserState* _browserState; |
| -} |
| +// The web client associated with all configurations. |
| +static std::unique_ptr<ios_web_view::WebViewWebClient> webClient; |
| + |
| +@implementation CWVWebViewConfiguration |
| @synthesize userContentController = _userContentController; |
| + (instancetype)defaultConfiguration { |
| - static dispatch_once_t once; |
| - static CWVWebViewConfiguration* configuration; |
| - dispatch_once(&once, ^{ |
| - ios_web_view::WebViewWebClient* client = |
| - static_cast<ios_web_view::WebViewWebClient*>(web::GetWebClient()); |
| - configuration = [[self alloc] initWithBrowserState:client->browser_state()]; |
| - }); |
| - return configuration; |
| + [[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.
|
| + |
| + auto browserState = |
| + base::MakeUnique<ios_web_view::WebViewBrowserState>(false); |
| + return [[self alloc] initWithBrowserState:std::move(browserState)]; |
| } |
| + (instancetype)incognitoConfiguration { |
| - static dispatch_once_t once; |
| - static CWVWebViewConfiguration* configuration; |
| - dispatch_once(&once, ^{ |
| - ios_web_view::WebViewWebClient* client = |
| - static_cast<ios_web_view::WebViewWebClient*>(web::GetWebClient()); |
| - configuration = [[self alloc] |
| - initWithBrowserState:client->off_the_record_browser_state()]; |
| + [[self class] initialize]; |
| + |
| + auto browserState = base::MakeUnique<ios_web_view::WebViewBrowserState>(true); |
| + return [[self alloc] initWithBrowserState:std::move(browserState)]; |
| +} |
| + |
| ++ (void)initialize { |
| + 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.
|
| + static std::unique_ptr<web::WebMain> webMain; |
| + static dispatch_once_t onceToken; |
| + dispatch_once(&onceToken, ^{ |
| + webClient = base::MakeUnique<ios_web_view::WebViewWebClient>(); |
| + web::SetWebClient(webClient.get()); |
| + |
| + webMainDelegate = base::MakeUnique<ios_web_view::WebViewWebMainDelegate>(); |
| + web::WebMainParams params(webMainDelegate.get()); |
| + webMain = base::MakeUnique<web::WebMain>(params); |
| }); |
| - return configuration; |
| } |
| - (instancetype)initWithBrowserState: |
| - (ios_web_view::WebViewBrowserState*)browserState { |
| + (std::unique_ptr<ios_web_view::WebViewBrowserState>)browserState { |
| self = [super init]; |
| if (self) { |
| - _browserState = browserState; |
| + _browserState = std::move(browserState); |
| + |
| + // Initialize translate. |
| + translate::TranslateDownloadManager* downloadManager = |
| + translate::TranslateDownloadManager::GetInstance(); |
| + 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.
|
| + // TODO(crbug.com/679895): Bring up application locale correctly. |
| + downloadManager->set_application_locale(l10n_util::GetLocaleOverride()); |
| + downloadManager->language_list()->SetResourceRequestsAllowed(true); |
| + |
| _userContentController = |
| [[CWVUserContentController alloc] initWithConfiguration:self]; |
| } |
| @@ -65,13 +93,19 @@ |
| } |
| - (ios_web_view::WebViewBrowserState*)browserState { |
| - return _browserState; |
| + return _browserState.get(); |
| } |
| // NSCopying |
| - (id)copyWithZone:(NSZone*)zone { |
| - return [[[self class] allocWithZone:zone] initWithBrowserState:_browserState]; |
| + [[self class] initialize]; |
| + |
| + auto browserState = base::MakeUnique<ios_web_view::WebViewBrowserState>( |
| + _browserState->IsOffTheRecord()); |
| + |
| + return [[[self class] allocWithZone:zone] |
| + initWithBrowserState:std::move(browserState)]; |
| } |
| @end |