diff options
author | phajdan.jr@chromium.org <phajdan.jr@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-05-16 19:10:40 +0000 |
---|---|---|
committer | phajdan.jr@chromium.org <phajdan.jr@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-05-16 19:10:40 +0000 |
commit | e7dd789201dfe869fbba7acb06f63da58ec77f05 (patch) | |
tree | 60531f4a90c7687dfe92eae04e870654a874d522 | |
parent | a1c8bae3608e6c40f0258fbb780223cdae0b61d5 (diff) | |
download | chromium_src-e7dd789201dfe869fbba7acb06f63da58ec77f05.zip chromium_src-e7dd789201dfe869fbba7acb06f63da58ec77f05.tar.gz chromium_src-e7dd789201dfe869fbba7acb06f63da58ec77f05.tar.bz2 |
Display an infobar on startup when Google API keys are missing.
BUG=158766
R=joi@chromium.org, pkasting@chromium.org
Review URL: https://codereview.chromium.org/14766011
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@200599 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | chrome/app/chromium_strings.grd | 7 | ||||
-rw-r--r-- | chrome/app/google_chrome_strings.grd | 7 | ||||
-rw-r--r-- | chrome/browser/ui/startup/google_api_keys_infobar_delegate.cc | 53 | ||||
-rw-r--r-- | chrome/browser/ui/startup/google_api_keys_infobar_delegate.h | 34 | ||||
-rw-r--r-- | chrome/browser/ui/startup/startup_browser_creator_impl.cc | 16 | ||||
-rw-r--r-- | chrome/chrome_browser_ui.gypi | 2 | ||||
-rw-r--r-- | google_apis/google_api_keys.cc | 15 | ||||
-rw-r--r-- | google_apis/google_api_keys.h | 5 | ||||
-rw-r--r-- | google_apis/google_api_keys_unittest.cc | 10 |
9 files changed, 140 insertions, 9 deletions
diff --git a/chrome/app/chromium_strings.grd b/chrome/app/chromium_strings.grd index f440700..aadf989 100644 --- a/chrome/app/chromium_strings.grd +++ b/chrome/app/chromium_strings.grd @@ -690,10 +690,15 @@ Chromium is unable to recover your settings. </if> <!-- Obsolete System info bar --> - <message name="IDS_SYSTEM_OBSOLETE_MESSAGE" desc="Message shown when your OS is no longer supported. This messages is followed by a 'Learn more' link."> + <message name="IDS_SYSTEM_OBSOLETE_MESSAGE" desc="Message shown when your OS is no longer supported. This message is followed by a 'Learn more' link."> Chromium has stopped updating and no longer supports this version of your operating system. </message> + <!-- Google API keys info bar --> + <message name="IDS_MISSING_GOOGLE_API_KEYS" desc="Message shown when Google API keys are missing. This message is followed by a 'Learn more' link."> + Google API keys are missing. Some functionality of Chromium will be disabled. + </message> + <!-- about:memory --> <if expr="not pp_ifdef('android')"> <message name="IDS_MEMORY_USAGE_SUMMARY_DESC" desc="Describes the browser summary table in the about memory page, which shows memory usage for Chromium and any other active browsers." translateable="false"> diff --git a/chrome/app/google_chrome_strings.grd b/chrome/app/google_chrome_strings.grd index 0ecf074..901c7b7 100644 --- a/chrome/app/google_chrome_strings.grd +++ b/chrome/app/google_chrome_strings.grd @@ -614,10 +614,15 @@ Google Chrome is unable to recover your settings. </if> <!-- Obsolete System info bar --> - <message name="IDS_SYSTEM_OBSOLETE_MESSAGE" desc="Message shown when your OS is no longer supported. This messages is followed by a 'Learn more' link."> + <message name="IDS_SYSTEM_OBSOLETE_MESSAGE" desc="Message shown when your OS is no longer supported. This message is followed by a 'Learn more' link."> Google Chrome has stopped updating and no longer supports this version of your operating system. </message> + <!-- Google API keys info bar --> + <message name="IDS_MISSING_GOOGLE_API_KEYS" desc="Message shown when Google API keys are missing. This message is followed by a 'Learn more' link."> + Google API keys are missing. Some functionality of Google Chrome will be disabled. + </message> + <!-- about:memory --> <if expr="not pp_ifdef('android')"> <message name="IDS_MEMORY_USAGE_SUMMARY_DESC" desc="Describes the browser summary table in the about memory page, which shows memory usage for Google Chrome and any other active browsers." translateable="false"> diff --git a/chrome/browser/ui/startup/google_api_keys_infobar_delegate.cc b/chrome/browser/ui/startup/google_api_keys_infobar_delegate.cc new file mode 100644 index 0000000..00ed8ab --- /dev/null +++ b/chrome/browser/ui/startup/google_api_keys_infobar_delegate.cc @@ -0,0 +1,53 @@ +// Copyright 2013 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "chrome/browser/ui/startup/google_api_keys_infobar_delegate.h" + +#include "chrome/browser/infobars/infobar_service.h" +#include "content/public/browser/web_contents.h" +#include "google_apis/google_api_keys.h" +#include "grit/chromium_strings.h" +#include "grit/generated_resources.h" +#include "ui/base/l10n/l10n_util.h" + +// static +void GoogleApiKeysInfoBarDelegate::Create(InfoBarService* infobar_service) { + if (google_apis::HasKeysConfigured()) + return; + + infobar_service->AddInfoBar(scoped_ptr<InfoBarDelegate>( + new GoogleApiKeysInfoBarDelegate(infobar_service))); +} + +GoogleApiKeysInfoBarDelegate::GoogleApiKeysInfoBarDelegate( + InfoBarService* infobar_service) + : ConfirmInfoBarDelegate(infobar_service) { +} + +GoogleApiKeysInfoBarDelegate::~GoogleApiKeysInfoBarDelegate() { +} + +string16 GoogleApiKeysInfoBarDelegate::GetMessageText() const { + return l10n_util::GetStringUTF16(IDS_MISSING_GOOGLE_API_KEYS); +} + +int GoogleApiKeysInfoBarDelegate::GetButtons() const { + return BUTTON_NONE; +} + +string16 GoogleApiKeysInfoBarDelegate::GetLinkText() const { + return l10n_util::GetStringUTF16(IDS_LEARN_MORE); +} + +bool GoogleApiKeysInfoBarDelegate::LinkClicked( + WindowOpenDisposition disposition) { + web_contents()->OpenURL( + content::OpenURLParams( + GURL("http://www.chromium.org/developers/how-tos/api-keys"), + content::Referrer(), + (disposition == CURRENT_TAB) ? NEW_FOREGROUND_TAB : disposition, + content::PAGE_TRANSITION_LINK, + false)); + return false; +} diff --git a/chrome/browser/ui/startup/google_api_keys_infobar_delegate.h b/chrome/browser/ui/startup/google_api_keys_infobar_delegate.h new file mode 100644 index 0000000..3f74ff0 --- /dev/null +++ b/chrome/browser/ui/startup/google_api_keys_infobar_delegate.h @@ -0,0 +1,34 @@ +// Copyright 2013 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef CHROME_BROWSER_UI_STARTUP_GOOGLE_API_KEYS_INFOBAR_DELEGATE_H_ +#define CHROME_BROWSER_UI_STARTUP_GOOGLE_API_KEYS_INFOBAR_DELEGATE_H_ + +#include "base/compiler_specific.h" +#include "base/string16.h" +#include "chrome/browser/infobars/confirm_infobar_delegate.h" +#include "googleurl/src/gurl.h" + +class InfoBarService; + +// An infobar that is run with a string and a "Learn More" link. +class GoogleApiKeysInfoBarDelegate : public ConfirmInfoBarDelegate { + public: + // If Google API keys are missing, creates a missing Google API Keys info bar + // delegate and adds it to |infobar_service|. + static void Create(InfoBarService* infobar_service); + + private: + explicit GoogleApiKeysInfoBarDelegate(InfoBarService* infobar_service); + virtual ~GoogleApiKeysInfoBarDelegate(); + + virtual string16 GetMessageText() const OVERRIDE; + virtual int GetButtons() const OVERRIDE; + virtual string16 GetLinkText() const OVERRIDE; + virtual bool LinkClicked(WindowOpenDisposition disposition) OVERRIDE; + + DISALLOW_COPY_AND_ASSIGN(GoogleApiKeysInfoBarDelegate); +}; + +#endif // CHROME_BROWSER_UI_STARTUP_GOOGLE_API_KEYS_INFOBAR_DELEGATE_H_ diff --git a/chrome/browser/ui/startup/startup_browser_creator_impl.cc b/chrome/browser/ui/startup/startup_browser_creator_impl.cc index 1a00c1f..db43df3 100644 --- a/chrome/browser/ui/startup/startup_browser_creator_impl.cc +++ b/chrome/browser/ui/startup/startup_browser_creator_impl.cc @@ -61,6 +61,7 @@ #include "chrome/browser/ui/startup/autolaunch_prompt.h" #include "chrome/browser/ui/startup/bad_flags_prompt.h" #include "chrome/browser/ui/startup/default_browser_prompt.h" +#include "chrome/browser/ui/startup/google_api_keys_infobar_delegate.h" #include "chrome/browser/ui/startup/obsolete_os_infobar_delegate.h" #include "chrome/browser/ui/startup/session_crashed_prompt.h" #include "chrome/browser/ui/startup/startup_browser_creator.h" @@ -893,15 +894,18 @@ void StartupBrowserCreatorImpl::AddInfoBarsIfNecessary( if (HasPendingUncleanExit(browser->profile())) SessionCrashedInfoBarDelegate::Create(browser); - // The bad flags info bar and the obsolete system info bar are only added to - // the first profile which is launched. Other profiles might be restoring the - // browsing sessions asynchronously, so we cannot add the info bars to the - // focused tabs here. + // The below info bars are only added to the first profile which is launched. + // Other profiles might be restoring the browsing sessions asynchronously, + // so we cannot add the info bars to the focused tabs here. if (is_process_startup == chrome::startup::IS_PROCESS_STARTUP) { chrome::ShowBadFlagsPrompt(browser); - // TODO(phajdan.jr): Always enable after migrating bots: - // http://crbug.com/170262 . if (!command_line_.HasSwitch(switches::kTestType)) { + GoogleApiKeysInfoBarDelegate::Create( + InfoBarService::FromWebContents( + browser->tab_strip_model()->GetActiveWebContents())); + + // TODO(phajdan.jr): Always enable after migrating bots: + // http://crbug.com/170262 . chrome::ObsoleteOSInfoBarDelegate::Create( InfoBarService::FromWebContents( browser->tab_strip_model()->GetActiveWebContents())); diff --git a/chrome/chrome_browser_ui.gypi b/chrome/chrome_browser_ui.gypi index 41133c3..5308473 100644 --- a/chrome/chrome_browser_ui.gypi +++ b/chrome/chrome_browser_ui.gypi @@ -1376,6 +1376,8 @@ 'browser/ui/startup/default_browser_prompt.cc', 'browser/ui/startup/default_browser_prompt.h', 'browser/ui/startup/default_browser_prompt_win.cc', + 'browser/ui/startup/google_api_keys_infobar_delegate.cc', + 'browser/ui/startup/google_api_keys_infobar_delegate.h', 'browser/ui/startup/obsolete_os_infobar_delegate.cc', 'browser/ui/startup/obsolete_os_infobar_delegate.h', 'browser/ui/startup/session_crashed_prompt.cc', diff --git a/google_apis/google_api_keys.cc b/google_apis/google_api_keys.cc index c05435e..034b69a 100644 --- a/google_apis/google_api_keys.cc +++ b/google_apis/google_api_keys.cc @@ -235,6 +235,21 @@ class APIKeyCache { static base::LazyInstance<APIKeyCache> g_api_key_cache = LAZY_INSTANCE_INITIALIZER; +bool HasKeysConfigured() { + if (GetAPIKey() == DUMMY_API_TOKEN) + return false; + + for (size_t client_id = 0; client_id < CLIENT_NUM_ITEMS; ++client_id) { + OAuth2Client client = static_cast<OAuth2Client>(client_id); + if (GetOAuth2ClientID(client) == DUMMY_API_TOKEN || + GetOAuth2ClientSecret(client) == DUMMY_API_TOKEN) { + return false; + } + } + + return true; +} + std::string GetAPIKey() { return g_api_key_cache.Get().api_key(); } diff --git a/google_apis/google_api_keys.h b/google_apis/google_api_keys.h index 28905ac..28421e8 100644 --- a/google_apis/google_api_keys.h +++ b/google_apis/google_api_keys.h @@ -56,7 +56,10 @@ namespace google_apis { -// Retrieves the API key, a.k.a. developer key, or the empty string +// Returns true if no dummy API keys or OAuth2 tokens are set. +bool HasKeysConfigured(); + +// Retrieves the API key, a.k.a. developer key, or a dummy string // if not set. // // Note that the key should be escaped for the context you use it in, diff --git a/google_apis/google_api_keys_unittest.cc b/google_apis/google_api_keys_unittest.cc index ab50d3f..4d338f5 100644 --- a/google_apis/google_api_keys_unittest.cc +++ b/google_apis/google_api_keys_unittest.cc @@ -132,6 +132,8 @@ namespace official_build { TEST_F(GoogleAPIKeysTest, OfficialKeys) { namespace testcase = official_build::google_apis; + EXPECT_TRUE(testcase::HasKeysConfigured()); + std::string api_key = testcase::g_api_key_cache.Get().api_key(); std::string id_main = testcase::g_api_key_cache.Get().GetClientID( testcase::CLIENT_MAIN); @@ -212,6 +214,8 @@ namespace default_keys { TEST_F(GoogleAPIKeysTest, DefaultKeys) { namespace testcase = default_keys::google_apis; + EXPECT_FALSE(testcase::HasKeysConfigured()); + std::string api_key = testcase::g_api_key_cache.Get().api_key(); std::string id_main = testcase::g_api_key_cache.Get().GetClientID( testcase::CLIENT_MAIN); @@ -267,6 +271,8 @@ namespace override_some_keys { TEST_F(GoogleAPIKeysTest, OverrideSomeKeys) { namespace testcase = override_some_keys::google_apis; + EXPECT_FALSE(testcase::HasKeysConfigured()); + std::string api_key = testcase::g_api_key_cache.Get().api_key(); std::string id_main = testcase::g_api_key_cache.Get().GetClientID( testcase::CLIENT_MAIN); @@ -327,6 +333,8 @@ namespace override_all_keys { TEST_F(GoogleAPIKeysTest, OverrideAllKeys) { namespace testcase = override_all_keys::google_apis; + EXPECT_TRUE(testcase::HasKeysConfigured()); + std::string api_key = testcase::g_api_key_cache.Get().api_key(); std::string id_main = testcase::g_api_key_cache.Get().GetClientID( testcase::CLIENT_MAIN); @@ -397,6 +405,8 @@ TEST_F(GoogleAPIKeysTest, OverrideAllKeysUsingEnvironment) { env->SetVar("GOOGLE_CLIENT_SECRET_CLOUD_PRINT", "env-SECRET_CLOUD_PRINT"); env->SetVar("GOOGLE_CLIENT_SECRET_REMOTING", "env-SECRET_REMOTING"); + EXPECT_TRUE(testcase::HasKeysConfigured()); + // It's important that the first call to Get() only happen after the // environment variables have been set. std::string api_key = testcase::g_api_key_cache.Get().api_key(); |