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