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 "ios/web/public/app/web_main.h" | |
| 8 #import "ios/web_view/internal/cwv_user_content_controller_internal.h" | 10 #import "ios/web_view/internal/cwv_user_content_controller_internal.h" |
| 9 #import "ios/web_view/internal/web_view_browser_state.h" | 11 #import "ios/web_view/internal/web_view_browser_state.h" |
| 10 #import "ios/web_view/internal/web_view_web_client.h" | 12 #import "ios/web_view/internal/web_view_web_client.h" |
| 13 #import "ios/web_view/internal/web_view_web_main_delegate.h" | |
| 11 | 14 |
| 12 #if !defined(__has_feature) || !__has_feature(objc_arc) | 15 #if !defined(__has_feature) || !__has_feature(objc_arc) |
| 13 #error "This file requires ARC support." | 16 #error "This file requires ARC support." |
| 14 #endif | 17 #endif |
| 15 | 18 |
| 16 @interface CWVWebViewConfiguration () | 19 @interface CWVWebViewConfiguration () |
| 17 // Initialize configuration with the specified browser state. | 20 // Initialize configuration with the specified browser state. |
| 18 - (instancetype)initWithBrowserState: | 21 - (instancetype)initWithBrowserState: |
| 19 (ios_web_view::WebViewBrowserState*)browserState; | 22 (ios_web_view::WebViewBrowserState*)browserState; |
| 20 @end | 23 @end |
| 21 | 24 |
| 22 @implementation CWVWebViewConfiguration { | 25 @implementation CWVWebViewConfiguration { |
| 23 // TODO(crbug.com/690182): CWVWebViewConfiguration should own _browserState. | 26 // TODO(crbug.com/690182): CWVWebViewConfiguration should own _browserState. |
| 24 ios_web_view::WebViewBrowserState* _browserState; | 27 ios_web_view::WebViewBrowserState* _browserState; |
| 25 } | 28 } |
| 26 | 29 |
| 27 @synthesize userContentController = _userContentController; | 30 @synthesize userContentController = _userContentController; |
| 28 | 31 |
| 29 + (instancetype)defaultConfiguration { | 32 + (instancetype)defaultConfiguration { |
| 30 static dispatch_once_t once; | 33 static dispatch_once_t once; |
| 31 static CWVWebViewConfiguration* configuration; | 34 static CWVWebViewConfiguration* configuration; |
| 32 dispatch_once(&once, ^{ | 35 dispatch_once(&once, ^{ |
| 33 ios_web_view::WebViewWebClient* client = | 36 configuration = |
| 34 static_cast<ios_web_view::WebViewWebClient*>(web::GetWebClient()); | 37 [[self alloc] initWithBrowserState:[self webClient]->browser_state()]; |
| 35 configuration = [[self alloc] initWithBrowserState:client->browser_state()]; | |
| 36 }); | 38 }); |
| 37 return configuration; | 39 return configuration; |
| 38 } | 40 } |
| 39 | 41 |
| 40 + (instancetype)incognitoConfiguration { | 42 + (instancetype)incognitoConfiguration { |
| 41 static dispatch_once_t once; | 43 static dispatch_once_t once; |
| 42 static CWVWebViewConfiguration* configuration; | 44 static CWVWebViewConfiguration* configuration; |
| 43 dispatch_once(&once, ^{ | 45 dispatch_once(&once, ^{ |
| 44 ios_web_view::WebViewWebClient* client = | |
| 45 static_cast<ios_web_view::WebViewWebClient*>(web::GetWebClient()); | |
| 46 configuration = [[self alloc] | 46 configuration = [[self alloc] |
| 47 initWithBrowserState:client->off_the_record_browser_state()]; | 47 initWithBrowserState:[self webClient]->off_the_record_browser_state()]; |
| 48 }); | 48 }); |
| 49 return configuration; | 49 return configuration; |
| 50 } | 50 } |
| 51 | 51 |
| 52 + (ios_web_view::WebViewWebClient*)webClient { | |
|
Eugene But (OOO till 7-30)
2017/04/08 00:34:36
This whole method looks awkward, and I think that'
michaeldo
2017/04/11 17:07:48
I was able to fix ownership of BrowserState. WebCl
| |
| 53 static std::unique_ptr<ios_web_view::WebViewWebMainDelegate> webMainDelegate; | |
| 54 static std::unique_ptr<web::WebMain> webMain; | |
| 55 | |
| 56 static dispatch_once_t onceToken; | |
| 57 dispatch_once(&onceToken, ^{ | |
| 58 webMainDelegate = base::MakeUnique<ios_web_view::WebViewWebMainDelegate>(); | |
| 59 web::WebMainParams params(webMainDelegate.get()); | |
| 60 webMain = base::MakeUnique<web::WebMain>(params); | |
| 61 }); | |
| 62 | |
| 63 return static_cast<ios_web_view::WebViewWebClient*>(web::GetWebClient()); | |
|
Eugene But (OOO till 7-30)
2017/04/08 00:49:57
After giving some thoughts, I this we can avoid ca
michaeldo
2017/04/11 17:07:48
I was able to get rid of the cast by moving webCli
| |
| 64 } | |
| 65 | |
| 52 - (instancetype)initWithBrowserState: | 66 - (instancetype)initWithBrowserState: |
| 53 (ios_web_view::WebViewBrowserState*)browserState { | 67 (ios_web_view::WebViewBrowserState*)browserState { |
| 54 self = [super init]; | 68 self = [super init]; |
| 55 if (self) { | 69 if (self) { |
| 56 _browserState = browserState; | 70 _browserState = browserState; |
| 57 _userContentController = | 71 _userContentController = |
| 58 [[CWVUserContentController alloc] initWithConfiguration:self]; | 72 [[CWVUserContentController alloc] initWithConfiguration:self]; |
| 59 } | 73 } |
| 60 return self; | 74 return self; |
| 61 } | 75 } |
| 62 | 76 |
| 63 - (BOOL)isPersistent { | 77 - (BOOL)isPersistent { |
| 64 return !_browserState->IsOffTheRecord(); | 78 return !_browserState->IsOffTheRecord(); |
| 65 } | 79 } |
| 66 | 80 |
| 67 - (ios_web_view::WebViewBrowserState*)browserState { | 81 - (ios_web_view::WebViewBrowserState*)browserState { |
| 68 return _browserState; | 82 return _browserState; |
| 69 } | 83 } |
| 70 | 84 |
| 71 // NSCopying | 85 // NSCopying |
| 72 | 86 |
| 73 - (id)copyWithZone:(NSZone*)zone { | 87 - (id)copyWithZone:(NSZone*)zone { |
| 74 return [[[self class] allocWithZone:zone] initWithBrowserState:_browserState]; | 88 return [[[self class] allocWithZone:zone] initWithBrowserState:_browserState]; |
| 75 } | 89 } |
| 76 | 90 |
| 77 @end | 91 @end |
| OLD | NEW |