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" | 8 #include "base/memory/ptr_util.h" |
9 #include "base/threading/thread_restrictions.h" | 9 #include "base/threading/thread_restrictions.h" |
10 #include "components/translate/core/browser/translate_download_manager.h" | |
11 #include "ios/web_view/internal/app/application_context.h" | 10 #include "ios/web_view/internal/app/application_context.h" |
12 #import "ios/web_view/internal/cwv_user_content_controller_internal.h" | 11 #import "ios/web_view/internal/cwv_user_content_controller_internal.h" |
13 #include "ios/web_view/internal/web_view_browser_state.h" | 12 #include "ios/web_view/internal/web_view_browser_state.h" |
14 #include "ios/web_view/internal/web_view_global_state_util.h" | 13 #include "ios/web_view/internal/web_view_global_state_util.h" |
15 | 14 |
16 #if !defined(__has_feature) || !__has_feature(objc_arc) | 15 #if !defined(__has_feature) || !__has_feature(objc_arc) |
17 #error "This file requires ARC support." | 16 #error "This file requires ARC support." |
18 #endif | 17 #endif |
19 | 18 |
20 @interface CWVWebViewConfiguration () { | 19 @interface CWVWebViewConfiguration () { |
21 // The BrowserState for this configuration. | 20 // The BrowserState for this configuration. |
22 std::unique_ptr<ios_web_view::WebViewBrowserState> _browserState; | 21 std::unique_ptr<ios_web_view::WebViewBrowserState> _browserState; |
23 } | 22 } |
24 | 23 |
25 // Initializes configuration with the specified browser state mode. | 24 // Initializes configuration with the specified browser state mode. |
26 - (instancetype)initWithBrowserState: | 25 - (instancetype)initWithBrowserState: |
27 (std::unique_ptr<ios_web_view::WebViewBrowserState>)browserState; | 26 (std::unique_ptr<ios_web_view::WebViewBrowserState>)browserState; |
28 @end | 27 @end |
29 | 28 |
30 @implementation CWVWebViewConfiguration | 29 @implementation CWVWebViewConfiguration |
31 | 30 |
32 @synthesize userContentController = _userContentController; | 31 @synthesize userContentController = _userContentController; |
33 | 32 |
34 + (instancetype)defaultConfiguration { | 33 + (instancetype)defaultConfiguration { |
35 auto browserState = | 34 static CWVWebViewConfiguration* defaultConfiguration; |
36 base::MakeUnique<ios_web_view::WebViewBrowserState>(false); | 35 static dispatch_once_t onceToken; |
37 return [[self alloc] initWithBrowserState:std::move(browserState)]; | 36 dispatch_once(&onceToken, ^{ |
| 37 auto browserState = |
| 38 base::MakeUnique<ios_web_view::WebViewBrowserState>(false); |
| 39 defaultConfiguration = |
| 40 [[self alloc] initWithBrowserState:std::move(browserState)]; |
| 41 }); |
| 42 return defaultConfiguration; |
38 } | 43 } |
39 | 44 |
40 + (instancetype)incognitoConfiguration { | 45 + (instancetype)incognitoConfiguration { |
41 auto browserState = base::MakeUnique<ios_web_view::WebViewBrowserState>(true); | 46 static CWVWebViewConfiguration* incognitoConfiguration; |
42 return [[self alloc] initWithBrowserState:std::move(browserState)]; | 47 static dispatch_once_t onceToken; |
| 48 dispatch_once(&onceToken, ^{ |
| 49 auto browserState = |
| 50 base::MakeUnique<ios_web_view::WebViewBrowserState>(true); |
| 51 incognitoConfiguration = |
| 52 [[self alloc] initWithBrowserState:std::move(browserState)]; |
| 53 }); |
| 54 return incognitoConfiguration; |
43 } | 55 } |
44 | 56 |
45 + (void)initialize { | 57 + (void)initialize { |
46 if (self != [CWVWebViewConfiguration class]) { | 58 if (self != [CWVWebViewConfiguration class]) { |
47 return; | 59 return; |
48 } | 60 } |
49 | 61 |
50 ios_web_view::InitializeGlobalState(); | 62 ios_web_view::InitializeGlobalState(); |
51 } | 63 } |
52 | 64 |
53 - (instancetype)initWithBrowserState: | 65 - (instancetype)initWithBrowserState: |
54 (std::unique_ptr<ios_web_view::WebViewBrowserState>)browserState { | 66 (std::unique_ptr<ios_web_view::WebViewBrowserState>)browserState { |
55 self = [super init]; | 67 self = [super init]; |
56 if (self) { | 68 if (self) { |
57 _browserState = std::move(browserState); | 69 _browserState = std::move(browserState); |
58 | 70 |
59 _userContentController = | 71 _userContentController = |
60 [[CWVUserContentController alloc] initWithConfiguration:self]; | 72 [[CWVUserContentController alloc] initWithConfiguration:self]; |
61 } | 73 } |
62 return self; | 74 return self; |
63 } | 75 } |
64 | 76 |
| 77 #pragma mark - Public Methods |
| 78 |
65 - (BOOL)isPersistent { | 79 - (BOOL)isPersistent { |
66 return !_browserState->IsOffTheRecord(); | 80 return !_browserState->IsOffTheRecord(); |
67 } | 81 } |
68 | 82 |
| 83 #pragma mark - Private Methods |
| 84 |
69 - (ios_web_view::WebViewBrowserState*)browserState { | 85 - (ios_web_view::WebViewBrowserState*)browserState { |
70 return _browserState.get(); | 86 return _browserState.get(); |
71 } | 87 } |
72 | 88 |
73 @end | 89 @end |
OLD | NEW |