OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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_infobar_delegate.h" | 5 #include "chrome/browser/translate/translate_infobar_delegate.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "base/i18n/string_compare.h" | 9 #include "base/i18n/string_compare.h" |
10 #include "base/metrics/histogram.h" | 10 #include "base/metrics/histogram.h" |
(...skipping 276 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
287 | 287 |
288 if (autodetermined_source_language) { | 288 if (autodetermined_source_language) { |
289 size_t offset; | 289 size_t offset; |
290 string16 text = l10n_util::GetStringFUTF16( | 290 string16 text = l10n_util::GetStringFUTF16( |
291 IDS_TRANSLATE_INFOBAR_AFTER_MESSAGE_AUTODETERMINED_SOURCE_LANGUAGE, | 291 IDS_TRANSLATE_INFOBAR_AFTER_MESSAGE_AUTODETERMINED_SOURCE_LANGUAGE, |
292 string16(), | 292 string16(), |
293 &offset); | 293 &offset); |
294 | 294 |
295 strings->push_back(text.substr(0, offset)); | 295 strings->push_back(text.substr(0, offset)); |
296 strings->push_back(text.substr(offset)); | 296 strings->push_back(text.substr(offset)); |
297 } else { | 297 return; |
298 DCHECK(swap_languages); | 298 } |
| 299 DCHECK(swap_languages); |
299 | 300 |
300 std::vector<size_t> offsets; | 301 std::vector<size_t> offsets; |
301 string16 text = l10n_util::GetStringFUTF16( | 302 string16 text = l10n_util::GetStringFUTF16( |
302 IDS_TRANSLATE_INFOBAR_AFTER_MESSAGE, | 303 IDS_TRANSLATE_INFOBAR_AFTER_MESSAGE, string16(), string16(), &offsets); |
303 string16(), | 304 DCHECK_EQ(2U, offsets.size()); |
304 string16(), | |
305 &offsets); | |
306 DCHECK_EQ(2U, offsets.size()); | |
307 | 305 |
308 *swap_languages = (offsets[0] > offsets[1]); | 306 *swap_languages = (offsets[0] > offsets[1]); |
309 if (*swap_languages) | 307 if (*swap_languages) |
310 std::swap(offsets[0], offsets[1]); | 308 std::swap(offsets[0], offsets[1]); |
311 | 309 |
312 strings->push_back(text.substr(0, offsets[0])); | 310 strings->push_back(text.substr(0, offsets[0])); |
313 strings->push_back(text.substr(offsets[0], offsets[1] - offsets[0])); | 311 strings->push_back(text.substr(offsets[0], offsets[1] - offsets[0])); |
314 strings->push_back(text.substr(offsets[1])); | 312 strings->push_back(text.substr(offsets[1])); |
315 } | |
316 } | 313 } |
317 | 314 |
318 TranslateInfoBarDelegate::TranslateInfoBarDelegate( | 315 TranslateInfoBarDelegate::TranslateInfoBarDelegate( |
319 Type infobar_type, | 316 Type infobar_type, |
320 TranslateErrors::Type error_type, | 317 TranslateErrors::Type error_type, |
321 InfoBarService* infobar_service, | 318 InfoBarService* infobar_service, |
322 PrefService* prefs, | 319 PrefService* prefs, |
323 ShortcutConfiguration shortcut_config, | 320 ShortcutConfiguration shortcut_config, |
324 const std::string& original_language, | 321 const std::string& original_language, |
325 const std::string& target_language) | 322 const std::string& target_language) |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
403 | 400 |
404 TranslateInfoBarDelegate* | 401 TranslateInfoBarDelegate* |
405 TranslateInfoBarDelegate::AsTranslateInfoBarDelegate() { | 402 TranslateInfoBarDelegate::AsTranslateInfoBarDelegate() { |
406 return this; | 403 return this; |
407 } | 404 } |
408 | 405 |
409 std::string TranslateInfoBarDelegate::GetPageHost() { | 406 std::string TranslateInfoBarDelegate::GetPageHost() { |
410 NavigationEntry* entry = web_contents()->GetController().GetActiveEntry(); | 407 NavigationEntry* entry = web_contents()->GetController().GetActiveEntry(); |
411 return entry ? entry->GetURL().HostNoBrackets() : std::string(); | 408 return entry ? entry->GetURL().HostNoBrackets() : std::string(); |
412 } | 409 } |
OLD | NEW |