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

Unified Diff: chrome/browser/translate/translate_script.cc

Issue 22645015: Translate: cleanup on how to pass api key to the script (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: (rebase) Created 7 years, 4 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
« no previous file with comments | « chrome/browser/resources/translate.js ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/translate/translate_script.cc
diff --git a/chrome/browser/translate/translate_script.cc b/chrome/browser/translate/translate_script.cc
index 48184aa7256dd7f7e0b764a4f9ca362d90f8385a..d2af7384c9d98364bbca4dc4a433f2ee832f3b07 100644
--- a/chrome/browser/translate/translate_script.cc
+++ b/chrome/browser/translate/translate_script.cc
@@ -8,7 +8,9 @@
#include "base/command_line.h"
#include "base/logging.h"
#include "base/message_loop/message_loop.h"
+#include "base/strings/string_piece.h"
#include "base/strings/string_util.h"
+#include "base/strings/stringprintf.h"
#include "chrome/browser/translate/translate_url_fetcher.h"
#include "chrome/browser/translate/translate_url_util.h"
#include "chrome/common/chrome_switches.h"
@@ -96,15 +98,13 @@ void TranslateScript::OnScriptFetchComplete(
scoped_ptr<const TranslateURLFetcher> delete_ptr(fetcher_.release());
if (success) {
+ DCHECK(data_.empty());
+ data_ = base::StringPrintf("var translateApiKey = '%s';\n",
+ google_apis::GetAPIKey().c_str());
base::StringPiece str = ResourceBundle::GetSharedInstance().
GetRawDataResource(IDR_TRANSLATE_JS);
- DCHECK(data_.empty());
- str.CopyToString(&data_);
- std::string argument = "('";
- std::string api_key = google_apis::GetAPIKey();
- argument += net::EscapeQueryParamValue(api_key, true);
- argument += "');\n";
- data_ += argument + data;
+ str.AppendToString(&data_);
+ data_ += data;
// We'll expire the cached script after some time, to make sure long
// running browsers still get fixes that might get pushed with newer
« no previous file with comments | « chrome/browser/resources/translate.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698