From b2e1a9317704aa3a6c7594161d1c418f1ef5cd60 Mon Sep 17 00:00:00 2001 From: Shelley Vohr Date: Wed, 31 Oct 2018 07:49:44 -0700 Subject: [PATCH] refactor: remove hardcoded google api key (#15478) * refactor: remove hardcoded Google API key * address changes from review --- atom/app/atom_main_delegate.cc | 1 - atom/browser/atom_browser_client.cc | 5 ++--- atom/common/google_api_key.h | 17 ----------------- docs/api/environment-variables.md | 10 +++------- filenames.gni | 1 - 5 files changed, 5 insertions(+), 29 deletions(-) delete mode 100644 atom/common/google_api_key.h diff --git a/atom/app/atom_main_delegate.cc b/atom/app/atom_main_delegate.cc index 8c7b7b67b9..b2c0683e3c 100644 --- a/atom/app/atom_main_delegate.cc +++ b/atom/app/atom_main_delegate.cc @@ -11,7 +11,6 @@ #include "atom/app/atom_content_client.h" #include "atom/browser/atom_browser_client.h" #include "atom/browser/relauncher.h" -#include "atom/common/google_api_key.h" #include "atom/common/options_switches.h" #include "atom/renderer/atom_renderer_client.h" #include "atom/renderer/atom_sandboxed_renderer_client.h" diff --git a/atom/browser/atom_browser_client.cc b/atom/browser/atom_browser_client.cc index 950c6e2d23..7f18f0750b 100644 --- a/atom/browser/atom_browser_client.cc +++ b/atom/browser/atom_browser_client.cc @@ -31,7 +31,6 @@ #include "atom/browser/web_contents_permission_helper.h" #include "atom/browser/web_contents_preferences.h" #include "atom/browser/window_list.h" -#include "atom/common/google_api_key.h" #include "atom/common/options_switches.h" #include "atom/common/platform_util.h" #include "base/command_line.h" @@ -428,11 +427,11 @@ void AtomBrowserClient::DidCreatePpapiPlugin(content::BrowserPpapiHost* host) { #endif } +// attempt to get api key from env std::string AtomBrowserClient::GetGeolocationApiKey() { std::unique_ptr env(base::Environment::Create()); std::string api_key; - if (!env->GetVar("GOOGLE_API_KEY", &api_key)) - api_key = GOOGLEAPIS_API_KEY; + env->GetVar("GOOGLE_API_KEY", &api_key); return api_key; } diff --git a/atom/common/google_api_key.h b/atom/common/google_api_key.h deleted file mode 100644 index d27934595e..0000000000 --- a/atom/common/google_api_key.h +++ /dev/null @@ -1,17 +0,0 @@ -// Copyright (c) 2014 GitHub, Inc. -// Use of this source code is governed by the MIT license that can be -// found in the LICENSE file. - -#ifndef ATOM_COMMON_GOOGLE_API_KEY_H_ -#define ATOM_COMMON_GOOGLE_API_KEY_H_ - -#ifndef GOOGLEAPIS_ENDPOINT -#define GOOGLEAPIS_ENDPOINT \ - "https://www.googleapis.com/geolocation/v1/geolocate?key=" -#endif - -#ifndef GOOGLEAPIS_API_KEY -#define GOOGLEAPIS_API_KEY "AIzaSyAQfxPJiounkhOjODEO5ZieffeBv6yft2Q" -#endif - -#endif // ATOM_COMMON_GOOGLE_API_KEY_H_ diff --git a/docs/api/environment-variables.md b/docs/api/environment-variables.md index fdc74aefff..d31d769614 100644 --- a/docs/api/environment-variables.md +++ b/docs/api/environment-variables.md @@ -48,20 +48,16 @@ Unsupported options are: ### `GOOGLE_API_KEY` -Electron includes a hardcoded API key for making requests to Google's geocoding -webservice. Because this API key is included in every version of Electron, it -often exceeds its usage quota. To work around this, you can supply your own -Google API key in the environment. Place the following code in your main process +You can provide an API key for making requests to Google's geocoding webservice. To do this, place the following code in your main process file, before opening any browser windows that will make geocoding requests: ```javascript process.env.GOOGLE_API_KEY = 'YOUR_KEY_HERE' ``` -For instructions on how to acquire a Google API key, visit [this page](https://www.chromium.org/developers/how-tos/api-keys). - +For instructions on how to acquire a Google API key, visit [this page](https://developers.google.com/maps/documentation/javascript/get-api-key). By default, a newly generated Google API key may not be allowed to make -geocoding requests. To enable geocoding requests, visit [this page](https://console.developers.google.com/apis/api/geolocation/overview). +geocoding requests. To enable geocoding requests, visit [this page](https://developers.google.com/maps/documentation/geocoding/get-api-key). ### `ELECTRON_NO_ASAR` diff --git a/filenames.gni b/filenames.gni index 39597c6679..88138ed217 100644 --- a/filenames.gni +++ b/filenames.gni @@ -576,7 +576,6 @@ filenames = { "atom/common/crash_reporter/win/crash_service_main.h", "atom/common/draggable_region.cc", "atom/common/draggable_region.h", - "atom/common/google_api_key.h", "atom/common/heap_snapshot.cc", "atom/common/heap_snapshot.h", "atom/common/key_weak_map.h",