| 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 #import "ios/web_view/internal/cwv_user_content_controller_internal.h" |
| 8 #import "ios/web_view/internal/web_view_browser_state.h" | 9 #import "ios/web_view/internal/web_view_browser_state.h" |
| 9 #import "ios/web_view/internal/web_view_web_client.h" | 10 #import "ios/web_view/internal/web_view_web_client.h" |
| 10 | 11 |
| 11 #if !defined(__has_feature) || !__has_feature(objc_arc) | 12 #if !defined(__has_feature) || !__has_feature(objc_arc) |
| 12 #error "This file requires ARC support." | 13 #error "This file requires ARC support." |
| 13 #endif | 14 #endif |
| 14 | 15 |
| 15 @interface CWVWebViewConfiguration () | 16 @interface CWVWebViewConfiguration () |
| 16 // Initialize configuration with the specified browser state. | 17 // Initialize configuration with the specified browser state. |
| 17 - (instancetype)initWithBrowserState: | 18 - (instancetype)initWithBrowserState: |
| 18 (ios_web_view::WebViewBrowserState*)browserState; | 19 (ios_web_view::WebViewBrowserState*)browserState; |
| 19 @end | 20 @end |
| 20 | 21 |
| 21 @implementation CWVWebViewConfiguration { | 22 @implementation CWVWebViewConfiguration { |
| 22 // TODO(crbug.com/690182): CWVWebViewConfiguration should own _browserState. | 23 // TODO(crbug.com/690182): CWVWebViewConfiguration should own _browserState. |
| 23 ios_web_view::WebViewBrowserState* _browserState; | 24 ios_web_view::WebViewBrowserState* _browserState; |
| 24 } | 25 } |
| 25 | 26 |
| 27 @synthesize userContentController = _userContentController; |
| 28 |
| 26 + (instancetype)defaultConfiguration { | 29 + (instancetype)defaultConfiguration { |
| 27 static dispatch_once_t once; | 30 static dispatch_once_t once; |
| 28 static CWVWebViewConfiguration* configuration; | 31 static CWVWebViewConfiguration* configuration; |
| 29 dispatch_once(&once, ^{ | 32 dispatch_once(&once, ^{ |
| 30 ios_web_view::WebViewWebClient* client = | 33 ios_web_view::WebViewWebClient* client = |
| 31 static_cast<ios_web_view::WebViewWebClient*>(web::GetWebClient()); | 34 static_cast<ios_web_view::WebViewWebClient*>(web::GetWebClient()); |
| 32 configuration = [[self alloc] initWithBrowserState:client->browser_state()]; | 35 configuration = [[self alloc] initWithBrowserState:client->browser_state()]; |
| 33 }); | 36 }); |
| 34 return configuration; | 37 return configuration; |
| 35 } | 38 } |
| 36 | 39 |
| 37 + (instancetype)incognitoConfiguration { | 40 + (instancetype)incognitoConfiguration { |
| 38 static dispatch_once_t once; | 41 static dispatch_once_t once; |
| 39 static CWVWebViewConfiguration* configuration; | 42 static CWVWebViewConfiguration* configuration; |
| 40 dispatch_once(&once, ^{ | 43 dispatch_once(&once, ^{ |
| 41 ios_web_view::WebViewWebClient* client = | 44 ios_web_view::WebViewWebClient* client = |
| 42 static_cast<ios_web_view::WebViewWebClient*>(web::GetWebClient()); | 45 static_cast<ios_web_view::WebViewWebClient*>(web::GetWebClient()); |
| 43 configuration = [[self alloc] | 46 configuration = [[self alloc] |
| 44 initWithBrowserState:client->off_the_record_browser_state()]; | 47 initWithBrowserState:client->off_the_record_browser_state()]; |
| 45 }); | 48 }); |
| 46 return configuration; | 49 return configuration; |
| 47 } | 50 } |
| 48 | 51 |
| 49 - (instancetype)initWithBrowserState: | 52 - (instancetype)initWithBrowserState: |
| 50 (ios_web_view::WebViewBrowserState*)browserState { | 53 (ios_web_view::WebViewBrowserState*)browserState { |
| 51 self = [super init]; | 54 self = [super init]; |
| 52 if (self) { | 55 if (self) { |
| 53 _browserState = browserState; | 56 _browserState = browserState; |
| 57 _userContentController = |
| 58 [[CWVUserContentController alloc] initWithConfiguration:self]; |
| 54 } | 59 } |
| 55 return self; | 60 return self; |
| 56 } | 61 } |
| 57 | 62 |
| 58 - (BOOL)isPersistent { | 63 - (BOOL)isPersistent { |
| 59 return !_browserState->IsOffTheRecord(); | 64 return !_browserState->IsOffTheRecord(); |
| 60 } | 65 } |
| 61 | 66 |
| 62 - (ios_web_view::WebViewBrowserState*)browserState { | 67 - (ios_web_view::WebViewBrowserState*)browserState { |
| 63 return _browserState; | 68 return _browserState; |
| 64 } | 69 } |
| 65 | 70 |
| 66 // NSCopying | 71 // NSCopying |
| 67 | 72 |
| 68 - (id)copyWithZone:(NSZone*)zone { | 73 - (id)copyWithZone:(NSZone*)zone { |
| 69 return [[[self class] allocWithZone:zone] initWithBrowserState:_browserState]; | 74 return [[[self class] allocWithZone:zone] initWithBrowserState:_browserState]; |
| 70 } | 75 } |
| 71 | 76 |
| 72 @end | 77 @end |
| OLD | NEW |