[fuchsia] Add support for Google API Key provided via command line
Add support for Google API Key when provided through the config file read by WebEngine. key present. Test: Manually tested. Safe Sites functionality works without another Bug: 1160130 Change-Id: I8b0fef7aa4892e130e0b6d423dc63e733e05aca6 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2613649 Commit-Queue: Sharon Yang <yangsharon@chromium.org> Reviewed-by: Wez <wez@chromium.org> Reviewed-by: Mihai Sardarescu <msarda@chromium.org> Reviewed-by: David Dorwin <ddorwin@chromium.org> Cr-Commit-Position: refs/heads/master@{#843741}
This commit is contained in:

committed by
Chromium LUCI CQ

parent
dcbd9e3f8b
commit
41d26edbc2
@ -226,9 +226,11 @@ source_set("switches") {
|
||||
|
||||
executable("web_engine_exe") {
|
||||
deps = [
|
||||
":switches",
|
||||
":web_engine_core",
|
||||
"//base",
|
||||
"//content/public/app",
|
||||
"//google_apis",
|
||||
]
|
||||
sources = [ "web_engine_main.cc" ]
|
||||
visibility = [ ":*" ]
|
||||
|
@ -6,6 +6,7 @@ include_rules = [
|
||||
"+components/media_control",
|
||||
"+components/on_load_script_injector",
|
||||
"+content/public/app",
|
||||
"+google_apis",
|
||||
"+gpu/command_buffer/service",
|
||||
"+gpu/config/gpu_finch_features.h",
|
||||
"+gpu/config/gpu_switches.h",
|
||||
|
@ -168,6 +168,7 @@ bool MaybeAddCommandLineArgsFromConfig(const base::Value& config,
|
||||
switches::kForceGpuMemAvailableMb,
|
||||
switches::kForceGpuMemDiscardableLimitMb,
|
||||
switches::kForceMaxTextureSize,
|
||||
switches::kGoogleApiKey,
|
||||
switches::kMaxDecodedImageSizeMb,
|
||||
switches::kRendererProcessLimit,
|
||||
switches::kWebglAntialiasingMode,
|
||||
@ -612,6 +613,13 @@ void ContextProviderImpl::Create(
|
||||
ignore_result(channel.release());
|
||||
ignore_result(data_directory_channel.release());
|
||||
ignore_result(cdm_data_directory_channel.release());
|
||||
|
||||
// Set the Google API key to use Google services.
|
||||
if (launch_command.HasSwitch(switches::kGoogleApiKey)) {
|
||||
AppendFeature(switches::kGoogleApiKey,
|
||||
launch_command.GetSwitchValueASCII(switches::kGoogleApiKey),
|
||||
&launch_command);
|
||||
}
|
||||
}
|
||||
|
||||
void ContextProviderImpl::SetLaunchCallbackForTest(
|
||||
|
@ -20,5 +20,6 @@ const char kEnableCastStreamingReceiver[] = "enable-cast-streaming-receiver";
|
||||
const char kCdmDataDirectory[] = "cdm-data-directory";
|
||||
const char kCdmDataQuotaBytes[] = "cdm-data-quota-bytes";
|
||||
const char kDataQuotaBytes[] = "data-quota-bytes";
|
||||
const char kGoogleApiKey[] = "google-api-key";
|
||||
|
||||
} // namespace switches
|
||||
|
@ -59,6 +59,9 @@ extern const char kCdmDataQuotaBytes[];
|
||||
// Soft quota to apply to the Context's persistent data directory, in bytes.
|
||||
extern const char kDataQuotaBytes[];
|
||||
|
||||
// API Key used to access Google services.
|
||||
extern const char kGoogleApiKey[];
|
||||
|
||||
} // namespace switches
|
||||
|
||||
#endif // FUCHSIA_ENGINE_SWITCHES_H_
|
||||
|
@ -9,14 +9,16 @@
|
||||
#include "content/public/common/content_switches.h"
|
||||
#include "fuchsia/engine/context_provider_impl.h"
|
||||
#include "fuchsia/engine/context_provider_main.h"
|
||||
#include "fuchsia/engine/switches.h"
|
||||
#include "fuchsia/engine/web_engine_main_delegate.h"
|
||||
#include "google_apis/google_api_keys.h"
|
||||
|
||||
int main(int argc, const char** argv) {
|
||||
base::CommandLine::Init(argc, argv);
|
||||
base::CommandLine* command_line = base::CommandLine::ForCurrentProcess();
|
||||
|
||||
std::string process_type =
|
||||
base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII(
|
||||
switches::kProcessType);
|
||||
command_line->GetSwitchValueASCII(switches::kProcessType);
|
||||
fidl::InterfaceRequest<fuchsia::web::Context> context;
|
||||
|
||||
if (process_type.empty()) {
|
||||
@ -41,5 +43,10 @@ int main(int argc, const char** argv) {
|
||||
params.argc = 0;
|
||||
params.argv = nullptr;
|
||||
|
||||
if (command_line->HasSwitch(switches::kGoogleApiKey)) {
|
||||
google_apis::SetAPIKey(
|
||||
command_line->GetSwitchValueASCII(switches::kGoogleApiKey));
|
||||
}
|
||||
|
||||
return content::ContentMain(params);
|
||||
}
|
||||
|
@ -169,13 +169,13 @@ class APIKeyCache {
|
||||
// written.
|
||||
client_ids_[CLIENT_MAIN] = CalculateKeyValue(
|
||||
GOOGLE_CLIENT_ID_MAIN, STRINGIZE_NO_EXPANSION(GOOGLE_CLIENT_ID_MAIN),
|
||||
switches::kOAuth2ClientID, default_client_id, environment.get(),
|
||||
::switches::kOAuth2ClientID, default_client_id, environment.get(),
|
||||
command_line, gaia_config);
|
||||
client_secrets_[CLIENT_MAIN] =
|
||||
CalculateKeyValue(GOOGLE_CLIENT_SECRET_MAIN,
|
||||
STRINGIZE_NO_EXPANSION(GOOGLE_CLIENT_SECRET_MAIN),
|
||||
switches::kOAuth2ClientSecret, default_client_secret,
|
||||
environment.get(), command_line, gaia_config);
|
||||
client_secrets_[CLIENT_MAIN] = CalculateKeyValue(
|
||||
GOOGLE_CLIENT_SECRET_MAIN,
|
||||
STRINGIZE_NO_EXPANSION(GOOGLE_CLIENT_SECRET_MAIN),
|
||||
::switches::kOAuth2ClientSecret, default_client_secret,
|
||||
environment.get(), command_line, gaia_config);
|
||||
|
||||
client_ids_[CLIENT_CLOUD_PRINT] = CalculateKeyValue(
|
||||
GOOGLE_CLIENT_ID_CLOUD_PRINT,
|
||||
@ -206,7 +206,7 @@ class APIKeyCache {
|
||||
}
|
||||
|
||||
std::string api_key() const { return api_key_; }
|
||||
#if defined(OS_IOS)
|
||||
#if defined(OS_IOS) || defined(OS_FUCHSIA)
|
||||
void set_api_key(const std::string& api_key) { api_key_ = api_key; }
|
||||
#endif
|
||||
std::string api_key_non_stable() const { return api_key_non_stable_; }
|
||||
@ -356,7 +356,7 @@ std::string GetSodaAPIKey() {
|
||||
return g_api_key_cache.Get().api_key_soda();
|
||||
}
|
||||
|
||||
#if defined(OS_IOS)
|
||||
#if defined(OS_IOS) || defined(OS_FUCHSIA)
|
||||
void SetAPIKey(const std::string& api_key) {
|
||||
g_api_key_cache.Get().set_api_key(api_key);
|
||||
}
|
||||
|
@ -9,6 +9,8 @@
|
||||
// google_api_keys_unittest.cc.
|
||||
#include <string>
|
||||
|
||||
#include "build/build_config.h"
|
||||
|
||||
// These functions enable you to retrieve keys to use for Google APIs
|
||||
// such as Translate and Safe Browsing.
|
||||
//
|
||||
@ -83,9 +85,10 @@ std::string GetSharingAPIKey();
|
||||
// Retrieves the Speech On-Device API (SODA) API Key.
|
||||
std::string GetSodaAPIKey();
|
||||
|
||||
#if defined(OS_IOS)
|
||||
#if defined(OS_IOS) || defined(OS_FUCHSIA)
|
||||
// Sets the API key. This should be called as early as possible before this
|
||||
// API key is even accessed.
|
||||
// API key is even accessed. It must be called before GetAPIKey.
|
||||
// TODO(https://crbug.com/1166007): Enforce this is called before GetAPIKey.
|
||||
void SetAPIKey(const std::string& api_key);
|
||||
#endif
|
||||
|
||||
|
Reference in New Issue
Block a user