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" | 10 #include "components/translate/core/browser/translate_download_manager.h" |
11 #include "ios/web/public/app/web_main.h" | 11 #include "ios/web/public/app/web_main.h" |
| 12 #include "ios/web_view/internal/app/application_context.h" |
12 #import "ios/web_view/internal/cwv_user_content_controller_internal.h" | 13 #import "ios/web_view/internal/cwv_user_content_controller_internal.h" |
13 #import "ios/web_view/internal/web_view_browser_state.h" | 14 #import "ios/web_view/internal/web_view_browser_state.h" |
14 #import "ios/web_view/internal/web_view_web_client.h" | 15 #import "ios/web_view/internal/web_view_web_client.h" |
15 #import "ios/web_view/internal/web_view_web_main_delegate.h" | 16 #import "ios/web_view/internal/web_view_web_main_delegate.h" |
16 #include "ui/base/l10n/l10n_util_mac.h" | |
17 | 17 |
18 #if !defined(__has_feature) || !__has_feature(objc_arc) | 18 #if !defined(__has_feature) || !__has_feature(objc_arc) |
19 #error "This file requires ARC support." | 19 #error "This file requires ARC support." |
20 #endif | 20 #endif |
21 | 21 |
22 @interface CWVWebViewConfiguration () { | 22 @interface CWVWebViewConfiguration () { |
23 // The BrowserState for this configuration. | 23 // The BrowserState for this configuration. |
24 std::unique_ptr<ios_web_view::WebViewBrowserState> _browserState; | 24 std::unique_ptr<ios_web_view::WebViewBrowserState> _browserState; |
25 } | 25 } |
26 | 26 |
(...skipping 26 matching lines...) Expand all Loading... |
53 static std::unique_ptr<ios_web_view::WebViewWebMainDelegate> webMainDelegate; | 53 static std::unique_ptr<ios_web_view::WebViewWebMainDelegate> webMainDelegate; |
54 static std::unique_ptr<web::WebMain> webMain; | 54 static std::unique_ptr<web::WebMain> webMain; |
55 static dispatch_once_t onceToken; | 55 static dispatch_once_t onceToken; |
56 dispatch_once(&onceToken, ^{ | 56 dispatch_once(&onceToken, ^{ |
57 webClient = base::MakeUnique<ios_web_view::WebViewWebClient>(); | 57 webClient = base::MakeUnique<ios_web_view::WebViewWebClient>(); |
58 web::SetWebClient(webClient.get()); | 58 web::SetWebClient(webClient.get()); |
59 | 59 |
60 webMainDelegate = base::MakeUnique<ios_web_view::WebViewWebMainDelegate>(); | 60 webMainDelegate = base::MakeUnique<ios_web_view::WebViewWebMainDelegate>(); |
61 web::WebMainParams params(webMainDelegate.get()); | 61 web::WebMainParams params(webMainDelegate.get()); |
62 webMain = base::MakeUnique<web::WebMain>(params); | 62 webMain = base::MakeUnique<web::WebMain>(params); |
| 63 |
| 64 // Initialize translate. |
| 65 translate::TranslateDownloadManager* downloadManager = |
| 66 translate::TranslateDownloadManager::GetInstance(); |
| 67 downloadManager->set_request_context( |
| 68 ios_web_view::GetApplicationContext()->GetSystemURLRequestContext()); |
| 69 downloadManager->set_application_locale( |
| 70 ios_web_view::GetApplicationContext()->GetApplicationLocale()); |
| 71 downloadManager->language_list()->SetResourceRequestsAllowed(true); |
63 }); | 72 }); |
64 } | 73 } |
65 | 74 |
66 - (instancetype)initWithBrowserState: | 75 - (instancetype)initWithBrowserState: |
67 (std::unique_ptr<ios_web_view::WebViewBrowserState>)browserState { | 76 (std::unique_ptr<ios_web_view::WebViewBrowserState>)browserState { |
68 self = [super init]; | 77 self = [super init]; |
69 if (self) { | 78 if (self) { |
70 _browserState = std::move(browserState); | 79 _browserState = std::move(browserState); |
71 | 80 |
72 // Initialize translate. | |
73 translate::TranslateDownloadManager* downloadManager = | |
74 translate::TranslateDownloadManager::GetInstance(); | |
75 // TODO(crbug.com/710948): Use global request context here. | |
76 downloadManager->set_request_context(_browserState->GetRequestContext()); | |
77 // TODO(crbug.com/679895): Bring up application locale correctly. | |
78 downloadManager->set_application_locale(l10n_util::GetLocaleOverride()); | |
79 downloadManager->language_list()->SetResourceRequestsAllowed(true); | |
80 | |
81 _userContentController = | 81 _userContentController = |
82 [[CWVUserContentController alloc] initWithConfiguration:self]; | 82 [[CWVUserContentController alloc] initWithConfiguration:self]; |
83 } | 83 } |
84 return self; | 84 return self; |
85 } | 85 } |
86 | 86 |
87 - (BOOL)isPersistent { | 87 - (BOOL)isPersistent { |
88 return !_browserState->IsOffTheRecord(); | 88 return !_browserState->IsOffTheRecord(); |
89 } | 89 } |
90 | 90 |
91 - (ios_web_view::WebViewBrowserState*)browserState { | 91 - (ios_web_view::WebViewBrowserState*)browserState { |
92 return _browserState.get(); | 92 return _browserState.get(); |
93 } | 93 } |
94 | 94 |
95 // NSCopying | 95 // NSCopying |
96 | 96 |
97 - (id)copyWithZone:(NSZone*)zone { | 97 - (id)copyWithZone:(NSZone*)zone { |
98 [[self class] initialize]; | 98 [[self class] initialize]; |
99 | 99 |
100 auto browserState = base::MakeUnique<ios_web_view::WebViewBrowserState>( | 100 auto browserState = base::MakeUnique<ios_web_view::WebViewBrowserState>( |
101 _browserState->IsOffTheRecord()); | 101 _browserState->IsOffTheRecord()); |
102 | 102 |
103 return [[[self class] allocWithZone:zone] | 103 return [[[self class] allocWithZone:zone] |
104 initWithBrowserState:std::move(browserState)]; | 104 initWithBrowserState:std::move(browserState)]; |
105 } | 105 } |
106 | 106 |
107 @end | 107 @end |
OLD | NEW |