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 295 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
331 notification_registrar_.Add(this, NotificationType::PAGE_TRANSLATED, | 333 notification_registrar_.Add(this, NotificationType::PAGE_TRANSLATED, |
332 NotificationService::AllSources()); | 334 NotificationService::AllSources()); |
333 } | 335 } |
334 | 336 |
335 void TranslateManager::InitiateTranslation(TabContents* tab, | 337 void TranslateManager::InitiateTranslation(TabContents* tab, |
336 const std::string& page_lang) { | 338 const std::string& page_lang) { |
337 PrefService* prefs = tab->profile()->GetPrefs(); | 339 PrefService* prefs = tab->profile()->GetPrefs(); |
338 if (!prefs->GetBoolean(prefs::kEnableTranslate)) | 340 if (!prefs->GetBoolean(prefs::kEnableTranslate)) |
339 return; | 341 return; |
340 | 342 |
| 343 // Allow disabling of translate from the command line to assist with |
| 344 // automated browser testing. |
| 345 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kDisableTranslate)) |
| 346 return; |
| 347 |
341 NavigationEntry* entry = tab->controller().GetActiveEntry(); | 348 NavigationEntry* entry = tab->controller().GetActiveEntry(); |
342 if (!entry) { | 349 if (!entry) { |
343 // This can happen for popups created with window.open(""). | 350 // This can happen for popups created with window.open(""). |
344 return; | 351 return; |
345 } | 352 } |
346 | 353 |
347 // If there is already a translate infobar showing, don't show another one. | 354 // If there is already a translate infobar showing, don't show another one. |
348 if (GetTranslateInfoBarDelegate(tab)) | 355 if (GetTranslateInfoBarDelegate(tab)) |
349 return; | 356 return; |
350 | 357 |
(...skipping 250 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
601 TranslateInfoBarDelegate* TranslateManager::GetTranslateInfoBarDelegate( | 608 TranslateInfoBarDelegate* TranslateManager::GetTranslateInfoBarDelegate( |
602 TabContents* tab) { | 609 TabContents* tab) { |
603 for (int i = 0; i < tab->infobar_delegate_count(); ++i) { | 610 for (int i = 0; i < tab->infobar_delegate_count(); ++i) { |
604 TranslateInfoBarDelegate* delegate = | 611 TranslateInfoBarDelegate* delegate = |
605 tab->GetInfoBarDelegateAt(i)->AsTranslateInfoBarDelegate(); | 612 tab->GetInfoBarDelegateAt(i)->AsTranslateInfoBarDelegate(); |
606 if (delegate) | 613 if (delegate) |
607 return delegate; | 614 return delegate; |
608 } | 615 } |
609 return NULL; | 616 return NULL; |
610 } | 617 } |
OLD | NEW |