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

Side by Side Diff: chrome/browser/translate/translate_manager.cc

Issue 6368011: Clean up WebNavigationObserver by taking out password specific callbacks, and... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 9 years, 11 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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/command_line.h"
9 #include "base/compiler_specific.h" 9 #include "base/compiler_specific.h"
10 #include "base/metrics/histogram.h" 10 #include "base/metrics/histogram.h"
11 #include "base/singleton.h" 11 #include "base/singleton.h"
12 #include "base/string_split.h" 12 #include "base/string_split.h"
13 #include "base/string_util.h" 13 #include "base/string_util.h"
14 #include "chrome/browser/autofill/autofill_manager.h"
15 #include "chrome/browser/browser_list.h" 14 #include "chrome/browser/browser_list.h"
16 #include "chrome/browser/browser_process.h" 15 #include "chrome/browser/browser_process.h"
17 #include "chrome/browser/prefs/pref_service.h" 16 #include "chrome/browser/prefs/pref_service.h"
18 #include "chrome/browser/profiles/profile.h" 17 #include "chrome/browser/profiles/profile.h"
19 #include "chrome/browser/renderer_host/render_process_host.h" 18 #include "chrome/browser/renderer_host/render_process_host.h"
20 #include "chrome/browser/renderer_host/render_view_host.h" 19 #include "chrome/browser/renderer_host/render_view_host.h"
21 #include "chrome/browser/tab_contents/language_state.h" 20 #include "chrome/browser/tab_contents/language_state.h"
22 #include "chrome/browser/tab_contents/navigation_controller.h" 21 #include "chrome/browser/tab_contents/navigation_controller.h"
23 #include "chrome/browser/tab_contents/navigation_entry.h" 22 #include "chrome/browser/tab_contents/navigation_entry.h"
24 #include "chrome/browser/tab_contents/tab_contents.h" 23 #include "chrome/browser/tab_contents/tab_contents.h"
25 #include "chrome/browser/tab_contents/tab_util.h" 24 #include "chrome/browser/tab_contents/tab_util.h"
26 #include "chrome/browser/tabs/tab_strip_model.h" 25 #include "chrome/browser/tabs/tab_strip_model.h"
27 #include "chrome/browser/translate/page_translated_details.h" 26 #include "chrome/browser/translate/page_translated_details.h"
28 #include "chrome/browser/translate/translate_infobar_delegate.h" 27 #include "chrome/browser/translate/translate_infobar_delegate.h"
29 #include "chrome/browser/translate/translate_prefs.h" 28 #include "chrome/browser/translate/translate_prefs.h"
30 #include "chrome/browser/ui/browser.h" 29 #include "chrome/browser/ui/browser.h"
31 #include "chrome/common/chrome_switches.h" 30 #include "chrome/common/chrome_switches.h"
32 #include "chrome/common/notification_details.h" 31 #include "chrome/common/notification_details.h"
33 #include "chrome/common/notification_service.h" 32 #include "chrome/common/notification_service.h"
34 #include "chrome/common/notification_source.h" 33 #include "chrome/common/notification_source.h"
35 #include "chrome/common/notification_type.h" 34 #include "chrome/common/notification_type.h"
36 #include "chrome/common/pref_names.h" 35 #include "chrome/common/pref_names.h"
36 #include "chrome/common/render_messages.h"
37 #include "chrome/common/translate_errors.h" 37 #include "chrome/common/translate_errors.h"
38 #include "chrome/common/url_constants.h" 38 #include "chrome/common/url_constants.h"
39 #include "grit/browser_resources.h" 39 #include "grit/browser_resources.h"
40 #include "net/base/escape.h" 40 #include "net/base/escape.h"
41 #include "net/url_request/url_request_status.h" 41 #include "net/url_request/url_request_status.h"
42 42
43 namespace { 43 namespace {
44 44
45 // Mapping from a locale name to a language code name. 45 // Mapping from a locale name to a language code name.
46 // Locale names not included are translated as is. 46 // Locale names not included are translated as is.
(...skipping 419 matching lines...) Expand 10 before | Expand all | Expand 10 after
466 pending_requests_.push_back(request); 466 pending_requests_.push_back(request);
467 RequestTranslateScript(); 467 RequestTranslateScript();
468 } 468 }
469 469
470 void TranslateManager::RevertTranslation(TabContents* tab_contents) { 470 void TranslateManager::RevertTranslation(TabContents* tab_contents) {
471 NavigationEntry* entry = tab_contents->controller().GetActiveEntry(); 471 NavigationEntry* entry = tab_contents->controller().GetActiveEntry();
472 if (!entry) { 472 if (!entry) {
473 NOTREACHED(); 473 NOTREACHED();
474 return; 474 return;
475 } 475 }
476 tab_contents->render_view_host()->RevertTranslation(entry->page_id()); 476 tab_contents->render_view_host()->Send(new ViewMsg_RevertTranslation(
477 tab_contents->render_view_host()->routing_id(), entry->page_id()));
477 tab_contents->language_state().set_current_language( 478 tab_contents->language_state().set_current_language(
478 tab_contents->language_state().original_language()); 479 tab_contents->language_state().original_language());
479 } 480 }
480 481
481 void TranslateManager::ReportLanguageDetectionError(TabContents* tab_contents) { 482 void TranslateManager::ReportLanguageDetectionError(TabContents* tab_contents) {
482 UMA_HISTOGRAM_COUNTS("Translate.ReportLanguageDetectionError", 1); 483 UMA_HISTOGRAM_COUNTS("Translate.ReportLanguageDetectionError", 1);
483 GURL page_url = tab_contents->controller().GetActiveEntry()->url(); 484 GURL page_url = tab_contents->controller().GetActiveEntry()->url();
484 std::string report_error_url(kReportLanguageDetectionErrorURL); 485 std::string report_error_url(kReportLanguageDetectionErrorURL);
485 report_error_url += "?client=cr&action=langidc&u="; 486 report_error_url += "?client=cr&action=langidc&u=";
486 report_error_url += EscapeUrlEncodedData(page_url.spec()); 487 report_error_url += EscapeUrlEncodedData(page_url.spec());
(...skipping 16 matching lines...) Expand all
503 const std::string& translate_script, 504 const std::string& translate_script,
504 const std::string& source_lang, 505 const std::string& source_lang,
505 const std::string& target_lang) { 506 const std::string& target_lang) {
506 NavigationEntry* entry = tab->controller().GetActiveEntry(); 507 NavigationEntry* entry = tab->controller().GetActiveEntry();
507 if (!entry) { 508 if (!entry) {
508 NOTREACHED(); 509 NOTREACHED();
509 return; 510 return;
510 } 511 }
511 512
512 tab->language_state().set_translation_pending(true); 513 tab->language_state().set_translation_pending(true);
513 tab->render_view_host()->TranslatePage(entry->page_id(), translate_script,
514 source_lang, target_lang);
515 514
516 // Ideally we'd have a better way to uniquely identify form control elements, 515 tab->render_view_host()->Send(new ViewMsg_TranslatePage(
517 // but we don't have that yet. So before start translation, we clear the 516 tab->render_view_host()->routing_id(), entry->page_id(), translate_script,
518 // current form and re-parse it in AutoFillManager first to get the new 517 source_lang, target_lang));
519 // labels. 518 tab->TranslateStarted();
Ben Goodger (Google) 2011/01/20 22:38:24 Does this need to go through the tab? It'd be nice
jam 2011/01/20 23:26:59 good point. I didn't like doing this either (actu
Ben Goodger (Google) 2011/01/20 23:44:09 OK - can you add that as a TODO then if you don't
jam 2011/01/20 23:48:18 I wasn't clear: I actually ended up using it in th
520 tab->autofill_manager()->Reset();
521 } 519 }
522 520
523 void TranslateManager::PageTranslated(TabContents* tab, 521 void TranslateManager::PageTranslated(TabContents* tab,
524 PageTranslatedDetails* details) { 522 PageTranslatedDetails* details) {
525 // Create the new infobar to display. 523 // Create the new infobar to display.
526 TranslateInfoBarDelegate* infobar; 524 TranslateInfoBarDelegate* infobar;
527 if (details->error_type != TranslateErrors::NONE) { 525 if (details->error_type != TranslateErrors::NONE) {
528 infobar = TranslateInfoBarDelegate::CreateErrorDelegate( 526 infobar = TranslateInfoBarDelegate::CreateErrorDelegate(
529 details->error_type, tab, 527 details->error_type, tab,
530 details->source_language, details->target_language); 528 details->source_language, details->target_language);
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
632 TranslateInfoBarDelegate* TranslateManager::GetTranslateInfoBarDelegate( 630 TranslateInfoBarDelegate* TranslateManager::GetTranslateInfoBarDelegate(
633 TabContents* tab) { 631 TabContents* tab) {
634 for (int i = 0; i < tab->infobar_delegate_count(); ++i) { 632 for (int i = 0; i < tab->infobar_delegate_count(); ++i) {
635 TranslateInfoBarDelegate* delegate = 633 TranslateInfoBarDelegate* delegate =
636 tab->GetInfoBarDelegateAt(i)->AsTranslateInfoBarDelegate(); 634 tab->GetInfoBarDelegateAt(i)->AsTranslateInfoBarDelegate();
637 if (delegate) 635 if (delegate)
638 return delegate; 636 return delegate;
639 } 637 }
640 return NULL; 638 return NULL;
641 } 639 }
OLDNEW
« no previous file with comments | « chrome/browser/tab_contents/web_navigation_observer.h ('k') | chrome/browser/ui/login/login_prompt.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698