| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/translate/translate_script.h" | 5 #include "chrome/browser/translate/translate_script.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/message_loop/message_loop.h" | 10 #include "base/message_loop/message_loop.h" |
| 11 #include "base/strings/string_piece.h" | 11 #include "base/strings/string_piece.h" |
| 12 #include "base/strings/string_util.h" | 12 #include "base/strings/string_util.h" |
| 13 #include "base/strings/stringprintf.h" | 13 #include "base/strings/stringprintf.h" |
| 14 #include "chrome/browser/translate/translate_url_fetcher.h" | 14 #include "chrome/browser/translate/translate_url_fetcher.h" |
| 15 #include "chrome/browser/translate/translate_url_util.h" | 15 #include "chrome/browser/translate/translate_url_util.h" |
| 16 #include "chrome/common/chrome_switches.h" | 16 #include "chrome/common/chrome_switches.h" |
| 17 #include "chrome/common/translate/translate_util.h" | 17 #include "components/translate/common/translate_util.h" |
| 18 #include "google_apis/google_api_keys.h" | 18 #include "google_apis/google_api_keys.h" |
| 19 #include "grit/browser_resources.h" | 19 #include "grit/browser_resources.h" |
| 20 #include "net/base/escape.h" | 20 #include "net/base/escape.h" |
| 21 #include "net/base/url_util.h" | 21 #include "net/base/url_util.h" |
| 22 #include "ui/base/resource/resource_bundle.h" | 22 #include "ui/base/resource/resource_bundle.h" |
| 23 | 23 |
| 24 namespace { | 24 namespace { |
| 25 | 25 |
| 26 const int kExpirationDelayDays = 1; | 26 const int kExpirationDelayDays = 1; |
| 27 | 27 |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 119 DCHECK_EQ(kFetcherId, id); | 119 DCHECK_EQ(kFetcherId, id); |
| 120 | 120 |
| 121 scoped_ptr<const TranslateURLFetcher> delete_ptr(fetcher_.release()); | 121 scoped_ptr<const TranslateURLFetcher> delete_ptr(fetcher_.release()); |
| 122 | 122 |
| 123 if (success) { | 123 if (success) { |
| 124 DCHECK(data_.empty()); | 124 DCHECK(data_.empty()); |
| 125 // Insert variable definitions on API Key and security origin. | 125 // Insert variable definitions on API Key and security origin. |
| 126 data_ = base::StringPrintf("var translateApiKey = '%s';\n", | 126 data_ = base::StringPrintf("var translateApiKey = '%s';\n", |
| 127 google_apis::GetAPIKey().c_str()); | 127 google_apis::GetAPIKey().c_str()); |
| 128 | 128 |
| 129 GURL security_origin = TranslateUtil::GetTranslateSecurityOrigin(); | 129 GURL security_origin = translate::GetTranslateSecurityOrigin(); |
| 130 base::StringAppendF( | 130 base::StringAppendF( |
| 131 &data_, "var securityOrigin = '%s';", security_origin.spec().c_str()); | 131 &data_, "var securityOrigin = '%s';", security_origin.spec().c_str()); |
| 132 | 132 |
| 133 // Append embedded translate.js and a remote element library. | 133 // Append embedded translate.js and a remote element library. |
| 134 base::StringPiece str = ResourceBundle::GetSharedInstance(). | 134 base::StringPiece str = ResourceBundle::GetSharedInstance(). |
| 135 GetRawDataResource(IDR_TRANSLATE_JS); | 135 GetRawDataResource(IDR_TRANSLATE_JS); |
| 136 str.AppendToString(&data_); | 136 str.AppendToString(&data_); |
| 137 data_ += data; | 137 data_ += data; |
| 138 | 138 |
| 139 // We'll expire the cached script after some time, to make sure long | 139 // We'll expire the cached script after some time, to make sure long |
| 140 // running browsers still get fixes that might get pushed with newer | 140 // running browsers still get fixes that might get pushed with newer |
| 141 // scripts. | 141 // scripts. |
| 142 base::MessageLoop::current()->PostDelayedTask( | 142 base::MessageLoop::current()->PostDelayedTask( |
| 143 FROM_HERE, | 143 FROM_HERE, |
| 144 base::Bind(&TranslateScript::Clear, | 144 base::Bind(&TranslateScript::Clear, |
| 145 weak_method_factory_.GetWeakPtr()), | 145 weak_method_factory_.GetWeakPtr()), |
| 146 expiration_delay_); | 146 expiration_delay_); |
| 147 } | 147 } |
| 148 | 148 |
| 149 callback_.Run(success, data); | 149 callback_.Run(success, data); |
| 150 } | 150 } |
| OLD | NEW |