0

Plumb through the API key for devtools surveys

Devtools is adding functionality to do in-product surveys via a
non-public API. This CL adds the ability for the chrome-internal
repository to set an API key that gets piped through to devtools.

The API key is added to google_api_keys in the same way that other API
keys are handled, meaning it can be locally overridden, although there
is not much point to actually doing this because the API itself is not
public.

This CL adds a new method 'getSurveyAPIKey' to the InspectorFrontendHost
API which the devtools frontend uses to communicate with chrome.

The corresponding frontend CL is http://crrev.com/c/2361683/

Doc: https://docs.google.com/document/d/1wMRb1hI2zJ1mzOSJjjF46C2hToGksQf2AxurorxaiTg/edit#heading=h.jc7x7daf69yo

Bug: 1112738
Change-Id: Ic3d9d436556f06b8ff8fb3593e4ed40d68ed3507
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2362182
Reviewed-by: Simon Zünd <szuend@chromium.org>
Reviewed-by: Andrey Kosyakov <caseq@chromium.org>
Reviewed-by: Mihai Sardarescu <msarda@chromium.org>
Reviewed-by: Tom Sepez <tsepez@chromium.org>
Commit-Queue: Peter Marshall <petermarshall@chromium.org>
Cr-Commit-Position: refs/heads/master@{#807027}
This commit is contained in:
Peter Marshall
2020-09-15 14:48:22 +00:00
committed by Commit Bot
parent 7237d1343c
commit 4cd7ee2dd9
6 changed files with 34 additions and 0 deletions

@ -233,5 +233,7 @@ DevToolsEmbedderMessageDispatcher::CreateForDevToolsFrontend(
&Delegate::SetOpenNewWindowForPopups, delegate);
d->RegisterHandler("registerExtensionsAPI", &Delegate::RegisterExtensionsAPI,
delegate);
d->RegisterHandlerWithCallback("getSurveyAPIKey", &Delegate::GetSurveyAPIKey,
delegate);
return d;
}

@ -104,6 +104,7 @@ class DevToolsEmbedderMessageDispatcher {
virtual void SetOpenNewWindowForPopups(bool value) = 0;
virtual void RegisterExtensionsAPI(const std::string& origin,
const std::string& script) = 0;
virtual void GetSurveyAPIKey(const DispatchCallback& callback) = 0;
};
using DispatchCallback = Delegate::DispatchCallback;

@ -73,6 +73,7 @@
#include "extensions/browser/extension_registry.h"
#include "extensions/common/constants.h"
#include "extensions/common/permissions/permissions_data.h"
#include "google_apis/google_api_keys.h"
#include "ipc/ipc_channel.h"
#include "net/base/escape.h"
#include "net/base/net_errors.h"
@ -1530,6 +1531,12 @@ void DevToolsUIBindings::RegisterExtensionsAPI(const std::string& origin,
extensions_api_[origin + "/"] = script;
}
void DevToolsUIBindings::GetSurveyAPIKey(const DispatchCallback& callback) {
base::DictionaryValue response;
response.SetString("apiKey", google_apis::GetDevtoolsSurveysAPIKey());
callback.Run(&response);
}
void DevToolsUIBindings::SetDelegate(Delegate* delegate) {
delegate_.reset(delegate);
}

@ -171,6 +171,7 @@ class DevToolsUIBindings : public DevToolsEmbedderMessageDispatcher::Delegate,
void SetOpenNewWindowForPopups(bool value) override;
void RegisterExtensionsAPI(const std::string& origin,
const std::string& script) override;
void GetSurveyAPIKey(const DispatchCallback& callback) override;
void EnableRemoteDeviceCounter(bool enable);

@ -95,6 +95,12 @@
#define GOOGLE_API_KEY_SODA DUMMY_API_TOKEN
#endif
// API key for the DevTools frontend to use for surveys. Note there is no
// public API to replace this functionality.
#if !defined(GOOGLE_API_KEY_DEVTOOLS_SURVEYS)
#define GOOGLE_API_KEY_DEVTOOLS_SURVEYS DUMMY_API_TOKEN
#endif
// These are used as shortcuts for developers and users providing
// OAuth credentials via preprocessor defines or environment
// variables. If set, they will be used to replace any of the client
@ -147,6 +153,11 @@ class APIKeyCache {
GOOGLE_API_KEY_SODA, STRINGIZE_NO_EXPANSION(GOOGLE_API_KEY_SODA),
nullptr, std::string(), environment.get(), command_line, gaia_config);
api_key_devtools_surveys_ = CalculateKeyValue(
GOOGLE_API_KEY_DEVTOOLS_SURVEYS,
STRINGIZE_NO_EXPANSION(GOOGLE_API_KEY_DEVTOOLS_SURVEYS), nullptr,
std::string(), environment.get(), command_line, gaia_config);
metrics_key_ = CalculateKeyValue(
GOOGLE_METRICS_SIGNING_KEY,
STRINGIZE_NO_EXPANSION(GOOGLE_METRICS_SIGNING_KEY), nullptr,
@ -213,6 +224,9 @@ class APIKeyCache {
std::string api_key_remoting() const { return api_key_remoting_; }
std::string api_key_sharing() const { return api_key_sharing_; }
std::string api_key_soda() const { return api_key_soda_; }
std::string api_key_devtools_surveys() const {
return api_key_devtools_surveys_;
}
std::string metrics_key() const { return metrics_key_; }
@ -324,6 +338,7 @@ class APIKeyCache {
std::string api_key_remoting_;
std::string api_key_sharing_;
std::string api_key_soda_;
std::string api_key_devtools_surveys_;
std::string metrics_key_;
std::string client_ids_[CLIENT_NUM_ITEMS];
std::string client_secrets_[CLIENT_NUM_ITEMS];
@ -356,6 +371,10 @@ std::string GetSodaAPIKey() {
return g_api_key_cache.Get().api_key_soda();
}
std::string GetDevtoolsSurveysAPIKey() {
return g_api_key_cache.Get().api_key_devtools_surveys();
}
#if defined(OS_IOS)
void SetAPIKey(const std::string& api_key) {
g_api_key_cache.Get().set_api_key(api_key);

@ -83,6 +83,10 @@ std::string GetSharingAPIKey();
// Retrieves the Speech On-Device API (SODA) API Key.
std::string GetSodaAPIKey();
// Retrieves the DevTools Survey API Key. Note there is no public API to replace
// this functionality.
std::string GetDevtoolsSurveysAPIKey();
#if defined(OS_IOS)
// Sets the API key. This should be called as early as possible before this
// API key is even accessed.