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 "ios/web_view/internal/app/application_context.h" | 10 #include "ios/web_view/internal/app/application_context.h" |
11 #import "ios/web_view/internal/cwv_user_content_controller_internal.h" | 11 #import "ios/web_view/internal/cwv_user_content_controller_internal.h" |
| 12 #import "ios/web_view/internal/translate/cwv_translation_configuration_internal.
h" |
12 #include "ios/web_view/internal/web_view_browser_state.h" | 13 #include "ios/web_view/internal/web_view_browser_state.h" |
13 #include "ios/web_view/internal/web_view_global_state_util.h" | 14 #include "ios/web_view/internal/web_view_global_state_util.h" |
14 | 15 |
15 #if !defined(__has_feature) || !__has_feature(objc_arc) | 16 #if !defined(__has_feature) || !__has_feature(objc_arc) |
16 #error "This file requires ARC support." | 17 #error "This file requires ARC support." |
17 #endif | 18 #endif |
18 | 19 |
19 @interface CWVWebViewConfiguration () { | 20 @interface CWVWebViewConfiguration () { |
20 // The BrowserState for this configuration. | 21 // The BrowserState for this configuration. |
21 std::unique_ptr<ios_web_view::WebViewBrowserState> _browserState; | 22 std::unique_ptr<ios_web_view::WebViewBrowserState> _browserState; |
22 } | 23 } |
23 | 24 |
24 // Initializes configuration with the specified browser state mode. | 25 // Initializes configuration with the specified browser state mode. |
25 - (instancetype)initWithBrowserState: | 26 - (instancetype)initWithBrowserState: |
26 (std::unique_ptr<ios_web_view::WebViewBrowserState>)browserState; | 27 (std::unique_ptr<ios_web_view::WebViewBrowserState>)browserState; |
27 @end | 28 @end |
28 | 29 |
29 @implementation CWVWebViewConfiguration | 30 @implementation CWVWebViewConfiguration |
30 | 31 |
| 32 @synthesize translationConfiguration = _translationConfiguration; |
31 @synthesize userContentController = _userContentController; | 33 @synthesize userContentController = _userContentController; |
32 | 34 |
33 + (instancetype)defaultConfiguration { | 35 + (instancetype)defaultConfiguration { |
34 static CWVWebViewConfiguration* defaultConfiguration; | 36 static CWVWebViewConfiguration* defaultConfiguration; |
35 static dispatch_once_t onceToken; | 37 static dispatch_once_t onceToken; |
36 dispatch_once(&onceToken, ^{ | 38 dispatch_once(&onceToken, ^{ |
37 auto browserState = | 39 auto browserState = |
38 base::MakeUnique<ios_web_view::WebViewBrowserState>(false); | 40 base::MakeUnique<ios_web_view::WebViewBrowserState>(false); |
39 defaultConfiguration = | 41 defaultConfiguration = |
40 [[self alloc] initWithBrowserState:std::move(browserState)]; | 42 [[self alloc] initWithBrowserState:std::move(browserState)]; |
(...skipping 20 matching lines...) Expand all Loading... |
61 | 63 |
62 ios_web_view::InitializeGlobalState(); | 64 ios_web_view::InitializeGlobalState(); |
63 } | 65 } |
64 | 66 |
65 - (instancetype)initWithBrowserState: | 67 - (instancetype)initWithBrowserState: |
66 (std::unique_ptr<ios_web_view::WebViewBrowserState>)browserState { | 68 (std::unique_ptr<ios_web_view::WebViewBrowserState>)browserState { |
67 self = [super init]; | 69 self = [super init]; |
68 if (self) { | 70 if (self) { |
69 _browserState = std::move(browserState); | 71 _browserState = std::move(browserState); |
70 | 72 |
| 73 _translationConfiguration = [[CWVTranslationConfiguration alloc] |
| 74 initWithPrefService:_browserState->GetPrefs()]; |
| 75 |
71 _userContentController = | 76 _userContentController = |
72 [[CWVUserContentController alloc] initWithConfiguration:self]; | 77 [[CWVUserContentController alloc] initWithConfiguration:self]; |
73 } | 78 } |
74 return self; | 79 return self; |
75 } | 80 } |
76 | 81 |
77 #pragma mark - Public Methods | 82 #pragma mark - Public Methods |
78 | 83 |
79 - (BOOL)isPersistent { | 84 - (BOOL)isPersistent { |
80 return !_browserState->IsOffTheRecord(); | 85 return !_browserState->IsOffTheRecord(); |
81 } | 86 } |
82 | 87 |
83 #pragma mark - Private Methods | 88 #pragma mark - Private Methods |
84 | 89 |
85 - (ios_web_view::WebViewBrowserState*)browserState { | 90 - (ios_web_view::WebViewBrowserState*)browserState { |
86 return _browserState.get(); | 91 return _browserState.get(); |
87 } | 92 } |
88 | 93 |
89 @end | 94 @end |
OLD | NEW |