OLD | NEW |
---|---|
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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.h" | 5 #import "ios/web_view/public/cwv_web_view.h" |
6 | 6 |
7 #include <memory> | 7 #include <memory> |
8 #include <utility> | 8 #include <utility> |
9 | 9 |
10 #include "base/environment.h" | |
10 #import "base/ios/weak_nsobject.h" | 11 #import "base/ios/weak_nsobject.h" |
11 #include "base/memory/ptr_util.h" | 12 #include "base/memory/ptr_util.h" |
12 #include "base/strings/sys_string_conversions.h" | 13 #include "base/strings/sys_string_conversions.h" |
14 #include "google_apis/google_api_keys.h" | |
13 #import "ios/web/public/navigation_manager.h" | 15 #import "ios/web/public/navigation_manager.h" |
14 #include "ios/web/public/referrer.h" | 16 #include "ios/web/public/referrer.h" |
15 #include "ios/web/public/reload_type.h" | 17 #include "ios/web/public/reload_type.h" |
16 #import "ios/web/public/web_state/context_menu_params.h" | 18 #import "ios/web/public/web_state/context_menu_params.h" |
17 #import "ios/web/public/web_state/js/crw_js_injection_receiver.h" | 19 #import "ios/web/public/web_state/js/crw_js_injection_receiver.h" |
18 #import "ios/web/public/web_state/ui/crw_web_delegate.h" | 20 #import "ios/web/public/web_state/ui/crw_web_delegate.h" |
19 #import "ios/web/public/web_state/web_state.h" | 21 #import "ios/web/public/web_state/web_state.h" |
20 #import "ios/web/public/web_state/web_state_delegate_bridge.h" | 22 #import "ios/web/public/web_state/web_state_delegate_bridge.h" |
21 #import "ios/web/public/web_state/web_state_observer_bridge.h" | 23 #import "ios/web/public/web_state/web_state_observer_bridge.h" |
22 #import "ios/web_view/internal/cwv_html_element_internal.h" | 24 #import "ios/web_view/internal/cwv_html_element_internal.h" |
(...skipping 30 matching lines...) Expand all Loading... | |
53 @end | 55 @end |
54 | 56 |
55 @implementation CWVWebView | 57 @implementation CWVWebView |
56 | 58 |
57 @synthesize configuration = _configuration; | 59 @synthesize configuration = _configuration; |
58 @synthesize navigationDelegate = _navigationDelegate; | 60 @synthesize navigationDelegate = _navigationDelegate; |
59 @synthesize translationDelegate = _translationDelegate; | 61 @synthesize translationDelegate = _translationDelegate; |
60 @synthesize estimatedProgress = _estimatedProgress; | 62 @synthesize estimatedProgress = _estimatedProgress; |
61 @synthesize UIDelegate = _UIDelegate; | 63 @synthesize UIDelegate = _UIDelegate; |
62 | 64 |
65 + (void)setGoogleAPIKey:(NSString*)googleAPIKey | |
66 clientID:(NSString*)clientID | |
67 clientSecret:(NSString*)clientSecret { | |
68 std::unique_ptr<base::Environment> environment(base::Environment::Create()); | |
69 | |
70 environment->SetVar("GOOGLE_API_KEY", base::SysNSStringToUTF8(googleAPIKey)); | |
71 environment->SetVar("GOOGLE_DEFAULT_CLIENT_ID", | |
72 base::SysNSStringToUTF8(clientID)); | |
73 environment->SetVar("GOOGLE_DEFAULT_CLIENT_SECRET", | |
74 base::SysNSStringToUTF8(clientSecret)); | |
75 | |
76 DCHECK_EQ(google_apis::GetAPIKey(), base::SysNSStringToUTF8(googleAPIKey)); | |
77 DCHECK_EQ(google_apis::GetOAuth2ClientID(google_apis::CLIENT_MAIN), | |
78 base::SysNSStringToUTF8(clientID)); | |
79 DCHECK_EQ(google_apis::GetOAuth2ClientSecret(google_apis::CLIENT_MAIN), | |
80 base::SysNSStringToUTF8(clientSecret)); | |
81 | |
82 environment->UnSetVar("GOOGLE_API_KEY"); | |
Hiroshi Ichikawa
2017/03/31 08:15:26
I'm a bit confused how this code takes effect, by
michaeldo
2017/03/31 20:28:16
You are on the right track. By calling GetAPIKey,
Hiroshi Ichikawa
2017/04/03 05:28:16
Can you move google_apis::GetAPIKey() etc. out of
jzw1
2017/04/11 08:28:46
Yeah I'm OK with removing the DCHECKs and the UnSe
| |
83 environment->UnSetVar("GOOGLE_DEFAULT_CLIENT_ID"); | |
84 environment->UnSetVar("GOOGLE_DEFAULT_CLIENT_SECRET"); | |
85 } | |
86 | |
63 - (instancetype)initWithFrame:(CGRect)frame | 87 - (instancetype)initWithFrame:(CGRect)frame |
64 configuration:(CWVWebViewConfiguration*)configuration { | 88 configuration:(CWVWebViewConfiguration*)configuration { |
65 self = [super initWithFrame:frame]; | 89 self = [super initWithFrame:frame]; |
66 if (self) { | 90 if (self) { |
67 _configuration = [configuration copy]; | 91 _configuration = [configuration copy]; |
68 | 92 |
69 web::WebState::CreateParams webStateCreateParams( | 93 web::WebState::CreateParams webStateCreateParams( |
70 configuration.browserState); | 94 configuration.browserState); |
71 _webState = web::WebState::Create(webStateCreateParams); | 95 _webState = web::WebState::Create(webStateCreateParams); |
72 _webState->SetWebUsageEnabled(true); | 96 _webState->SetWebUsageEnabled(true); |
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
263 [_UIDelegate webViewDidClose:self]; | 287 [_UIDelegate webViewDidClose:self]; |
264 } | 288 } |
265 } | 289 } |
266 | 290 |
267 - (web::JavaScriptDialogPresenter*)javaScriptDialogPresenterForWebState: | 291 - (web::JavaScriptDialogPresenter*)javaScriptDialogPresenterForWebState: |
268 (web::WebState*)webState { | 292 (web::WebState*)webState { |
269 return _javaScriptDialogPresenter.get(); | 293 return _javaScriptDialogPresenter.get(); |
270 } | 294 } |
271 | 295 |
272 @end | 296 @end |
OLD | NEW |