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

Unified Diff: ios/web_view/internal/cwv_web_view.mm

Issue 2786033002: Expose way to set google api key through CWVWebView class method. (Closed)
Patch Set: added comment to static method Created 3 years, 9 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 side-by-side diff with in-line comments
Download patch
Index: ios/web_view/internal/cwv_web_view.mm
diff --git a/ios/web_view/internal/cwv_web_view.mm b/ios/web_view/internal/cwv_web_view.mm
index 08fb4d8dc30b2994005f51fbd5799b2b1efbc42c..106276d11d3180151a4ce03fa7935af503623a01 100644
--- a/ios/web_view/internal/cwv_web_view.mm
+++ b/ios/web_view/internal/cwv_web_view.mm
@@ -7,9 +7,11 @@
#include <memory>
#include <utility>
+#include "base/environment.h"
#import "base/ios/weak_nsobject.h"
#include "base/memory/ptr_util.h"
#include "base/strings/sys_string_conversions.h"
+#include "google_apis/google_api_keys.h"
#import "ios/web/public/navigation_manager.h"
#include "ios/web/public/referrer.h"
#include "ios/web/public/reload_type.h"
@@ -60,6 +62,28 @@
@synthesize estimatedProgress = _estimatedProgress;
@synthesize UIDelegate = _UIDelegate;
++ (void)setGoogleAPIKey:(NSString*)googleAPIKey
+ clientID:(NSString*)clientID
+ clientSecret:(NSString*)clientSecret {
+ std::unique_ptr<base::Environment> environment(base::Environment::Create());
+
+ environment->SetVar("GOOGLE_API_KEY", base::SysNSStringToUTF8(googleAPIKey));
+ environment->SetVar("GOOGLE_DEFAULT_CLIENT_ID",
+ base::SysNSStringToUTF8(clientID));
+ environment->SetVar("GOOGLE_DEFAULT_CLIENT_SECRET",
+ base::SysNSStringToUTF8(clientSecret));
+
+ DCHECK_EQ(google_apis::GetAPIKey(), base::SysNSStringToUTF8(googleAPIKey));
+ DCHECK_EQ(google_apis::GetOAuth2ClientID(google_apis::CLIENT_MAIN),
+ base::SysNSStringToUTF8(clientID));
+ DCHECK_EQ(google_apis::GetOAuth2ClientSecret(google_apis::CLIENT_MAIN),
+ base::SysNSStringToUTF8(clientSecret));
+
+ 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
+ environment->UnSetVar("GOOGLE_DEFAULT_CLIENT_ID");
+ environment->UnSetVar("GOOGLE_DEFAULT_CLIENT_SECRET");
+}
+
- (instancetype)initWithFrame:(CGRect)frame
configuration:(CWVWebViewConfiguration*)configuration {
self = [super initWithFrame:frame];

Powered by Google App Engine
This is Rietveld 408576698