| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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_manager.h" | 5 #include "chrome/browser/translate/translate_manager.h" |
| 6 | 6 |
| 7 #include "app/resource_bundle.h" | 7 #include "app/resource_bundle.h" |
| 8 #include "base/command_line.h" |
| 8 #include "base/compiler_specific.h" | 9 #include "base/compiler_specific.h" |
| 9 #include "base/histogram.h" | 10 #include "base/histogram.h" |
| 10 #include "base/string_util.h" | 11 #include "base/string_util.h" |
| 11 #include "chrome/browser/browser.h" | 12 #include "chrome/browser/browser.h" |
| 12 #include "chrome/browser/browser_list.h" | 13 #include "chrome/browser/browser_list.h" |
| 13 #include "chrome/browser/browser_process.h" | 14 #include "chrome/browser/browser_process.h" |
| 14 #include "chrome/browser/pref_service.h" | 15 #include "chrome/browser/pref_service.h" |
| 15 #include "chrome/browser/profile.h" | 16 #include "chrome/browser/profile.h" |
| 16 #include "chrome/browser/renderer_host/render_process_host.h" | 17 #include "chrome/browser/renderer_host/render_process_host.h" |
| 17 #include "chrome/browser/renderer_host/render_view_host.h" | 18 #include "chrome/browser/renderer_host/render_view_host.h" |
| 18 #include "chrome/browser/tab_contents/language_state.h" | 19 #include "chrome/browser/tab_contents/language_state.h" |
| 19 #include "chrome/browser/tab_contents/navigation_controller.h" | 20 #include "chrome/browser/tab_contents/navigation_controller.h" |
| 20 #include "chrome/browser/tab_contents/navigation_entry.h" | 21 #include "chrome/browser/tab_contents/navigation_entry.h" |
| 21 #include "chrome/browser/tab_contents/tab_contents.h" | 22 #include "chrome/browser/tab_contents/tab_contents.h" |
| 22 #include "chrome/browser/tab_contents/tab_util.h" | 23 #include "chrome/browser/tab_contents/tab_util.h" |
| 23 #include "chrome/browser/translate/page_translated_details.h" | 24 #include "chrome/browser/translate/page_translated_details.h" |
| 24 #include "chrome/browser/translate/translate_infobar_delegate.h" | 25 #include "chrome/browser/translate/translate_infobar_delegate.h" |
| 25 #include "chrome/browser/translate/translate_prefs.h" | 26 #include "chrome/browser/translate/translate_prefs.h" |
| 27 #include "chrome/common/chrome_switches.h" |
| 26 #include "chrome/common/notification_details.h" | 28 #include "chrome/common/notification_details.h" |
| 27 #include "chrome/common/notification_service.h" | 29 #include "chrome/common/notification_service.h" |
| 28 #include "chrome/common/notification_source.h" | 30 #include "chrome/common/notification_source.h" |
| 29 #include "chrome/common/notification_type.h" | 31 #include "chrome/common/notification_type.h" |
| 30 #include "chrome/common/pref_names.h" | 32 #include "chrome/common/pref_names.h" |
| 31 #include "chrome/common/translate_errors.h" | 33 #include "chrome/common/translate_errors.h" |
| 32 #include "grit/browser_resources.h" | 34 #include "grit/browser_resources.h" |
| 33 #include "net/base/escape.h" | 35 #include "net/base/escape.h" |
| 34 #include "net/url_request/url_request_status.h" | 36 #include "net/url_request/url_request_status.h" |
| 35 | 37 |
| (...skipping 288 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 324 notification_registrar_.Add(this, NotificationType::PAGE_TRANSLATED, | 326 notification_registrar_.Add(this, NotificationType::PAGE_TRANSLATED, |
| 325 NotificationService::AllSources()); | 327 NotificationService::AllSources()); |
| 326 } | 328 } |
| 327 | 329 |
| 328 void TranslateManager::InitiateTranslation(TabContents* tab, | 330 void TranslateManager::InitiateTranslation(TabContents* tab, |
| 329 const std::string& page_lang) { | 331 const std::string& page_lang) { |
| 330 PrefService* prefs = tab->profile()->GetPrefs(); | 332 PrefService* prefs = tab->profile()->GetPrefs(); |
| 331 if (!prefs->GetBoolean(prefs::kEnableTranslate)) | 333 if (!prefs->GetBoolean(prefs::kEnableTranslate)) |
| 332 return; | 334 return; |
| 333 | 335 |
| 336 // Allow disabling of translate from the command line to assist with |
| 337 // automated browser testing. |
| 338 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kDisableTranslate)) |
| 339 return; |
| 340 |
| 334 NavigationEntry* entry = tab->controller().GetActiveEntry(); | 341 NavigationEntry* entry = tab->controller().GetActiveEntry(); |
| 335 if (!entry) { | 342 if (!entry) { |
| 336 // This can happen for popups created with window.open(""). | 343 // This can happen for popups created with window.open(""). |
| 337 return; | 344 return; |
| 338 } | 345 } |
| 339 | 346 |
| 340 // If there is already a translate infobar showing, don't show another one. | 347 // If there is already a translate infobar showing, don't show another one. |
| 341 if (GetTranslateInfoBarDelegate(tab)) | 348 if (GetTranslateInfoBarDelegate(tab)) |
| 342 return; | 349 return; |
| 343 | 350 |
| (...skipping 249 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 593 TranslateInfoBarDelegate* TranslateManager::GetTranslateInfoBarDelegate( | 600 TranslateInfoBarDelegate* TranslateManager::GetTranslateInfoBarDelegate( |
| 594 TabContents* tab) { | 601 TabContents* tab) { |
| 595 for (int i = 0; i < tab->infobar_delegate_count(); ++i) { | 602 for (int i = 0; i < tab->infobar_delegate_count(); ++i) { |
| 596 TranslateInfoBarDelegate* delegate = | 603 TranslateInfoBarDelegate* delegate = |
| 597 tab->GetInfoBarDelegateAt(i)->AsTranslateInfoBarDelegate(); | 604 tab->GetInfoBarDelegateAt(i)->AsTranslateInfoBarDelegate(); |
| 598 if (delegate) | 605 if (delegate) |
| 599 return delegate; | 606 return delegate; |
| 600 } | 607 } |
| 601 return NULL; | 608 return NULL; |
| 602 } | 609 } |
| OLD | NEW |