Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(275)

Side by Side Diff: ios/web_view/internal/cwv_web_view_configuration.mm

Issue 2894483003: Initialize ios/web_view translate with a system-wide URLRequestContext. (Closed)
Patch Set: Respond to comments. Created 3 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
62 webMain = base::MakeUnique<web::WebMain>(params); 62 webMain = base::MakeUnique<web::WebMain>(params);
63 }); 63 });
64 } 64 }
65 65
66 - (instancetype)initWithBrowserState: 66 - (instancetype)initWithBrowserState:
67 (std::unique_ptr<ios_web_view::WebViewBrowserState>)browserState { 67 (std::unique_ptr<ios_web_view::WebViewBrowserState>)browserState {
68 self = [super init]; 68 self = [super init];
69 if (self) { 69 if (self) {
70 _browserState = std::move(browserState); 70 _browserState = std::move(browserState);
71 71
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 = 72 _userContentController =
82 [[CWVUserContentController alloc] initWithConfiguration:self]; 73 [[CWVUserContentController alloc] initWithConfiguration:self];
83 } 74 }
84 return self; 75 return self;
85 } 76 }
86 77
87 - (BOOL)isPersistent { 78 - (BOOL)isPersistent {
88 return !_browserState->IsOffTheRecord(); 79 return !_browserState->IsOffTheRecord();
89 } 80 }
90 81
91 - (ios_web_view::WebViewBrowserState*)browserState { 82 - (ios_web_view::WebViewBrowserState*)browserState {
92 return _browserState.get(); 83 return _browserState.get();
93 } 84 }
94 85
95 // NSCopying 86 // NSCopying
96 87
97 - (id)copyWithZone:(NSZone*)zone { 88 - (id)copyWithZone:(NSZone*)zone {
98 [[self class] initialize]; 89 [[self class] initialize];
99 90
100 auto browserState = base::MakeUnique<ios_web_view::WebViewBrowserState>( 91 auto browserState = base::MakeUnique<ios_web_view::WebViewBrowserState>(
101 _browserState->IsOffTheRecord()); 92 _browserState->IsOffTheRecord());
102 93
103 return [[[self class] allocWithZone:zone] 94 return [[[self class] allocWithZone:zone]
104 initWithBrowserState:std::move(browserState)]; 95 initWithBrowserState:std::move(browserState)];
105 } 96 }
106 97
107 @end 98 @end
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698