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_manager.h" | 5 #include "chrome/browser/translate/translate_manager.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/compiler_specific.h" | 9 #include "base/compiler_specific.h" |
10 #include "base/json/json_reader.h" | 10 #include "base/json/json_reader.h" |
(...skipping 26 matching lines...) Expand all Loading... |
37 #include "content/browser/renderer_host/render_view_host.h" | 37 #include "content/browser/renderer_host/render_view_host.h" |
38 #include "content/public/browser/navigation_controller.h" | 38 #include "content/public/browser/navigation_controller.h" |
39 #include "content/public/browser/navigation_details.h" | 39 #include "content/public/browser/navigation_details.h" |
40 #include "content/public/browser/navigation_entry.h" | 40 #include "content/public/browser/navigation_entry.h" |
41 #include "content/public/browser/notification_details.h" | 41 #include "content/public/browser/notification_details.h" |
42 #include "content/public/browser/notification_service.h" | 42 #include "content/public/browser/notification_service.h" |
43 #include "content/public/browser/notification_source.h" | 43 #include "content/public/browser/notification_source.h" |
44 #include "content/public/browser/notification_types.h" | 44 #include "content/public/browser/notification_types.h" |
45 #include "content/public/browser/render_process_host.h" | 45 #include "content/public/browser/render_process_host.h" |
46 #include "content/public/browser/web_contents.h" | 46 #include "content/public/browser/web_contents.h" |
| 47 #include "content/public/common/content_url_request_user_data.h" |
47 #include "content/public/common/url_fetcher.h" | 48 #include "content/public/common/url_fetcher.h" |
48 #include "grit/browser_resources.h" | 49 #include "grit/browser_resources.h" |
49 #include "net/base/escape.h" | 50 #include "net/base/escape.h" |
50 #include "net/url_request/url_request_status.h" | 51 #include "net/url_request/url_request_status.h" |
51 #include "ui/base/resource/resource_bundle.h" | 52 #include "ui/base/resource/resource_bundle.h" |
52 | 53 |
53 using content::NavigationController; | 54 using content::NavigationController; |
54 using content::NavigationEntry; | 55 using content::NavigationEntry; |
55 using content::WebContents; | 56 using content::WebContents; |
56 | 57 |
(...skipping 735 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
792 if (CommandLine::ForCurrentProcess()->HasSwitch( | 793 if (CommandLine::ForCurrentProcess()->HasSwitch( |
793 switches::kDisableTranslate) || | 794 switches::kDisableTranslate) || |
794 (prefs != NULL && !prefs->GetBoolean(prefs::kEnableTranslate))) { | 795 (prefs != NULL && !prefs->GetBoolean(prefs::kEnableTranslate))) { |
795 return; | 796 return; |
796 } | 797 } |
797 | 798 |
798 language_list_request_pending_.reset(content::URLFetcher::Create( | 799 language_list_request_pending_.reset(content::URLFetcher::Create( |
799 1, GURL(kLanguageListFetchURL), content::URLFetcher::GET, this)); | 800 1, GURL(kLanguageListFetchURL), content::URLFetcher::GET, this)); |
800 language_list_request_pending_->SetRequestContext( | 801 language_list_request_pending_->SetRequestContext( |
801 g_browser_process->system_request_context()); | 802 g_browser_process->system_request_context()); |
| 803 // TODO(jochen): Do cookie audit. |
| 804 language_list_request_pending_->SetContentURLRequestUserData( |
| 805 new content::ContentURLRequestUserData()); |
802 language_list_request_pending_->SetMaxRetries(kMaxRetryLanguageListFetch); | 806 language_list_request_pending_->SetMaxRetries(kMaxRetryLanguageListFetch); |
803 language_list_request_pending_->Start(); | 807 language_list_request_pending_->Start(); |
804 } | 808 } |
805 | 809 |
806 void TranslateManager::CleanupPendingUlrFetcher() { | 810 void TranslateManager::CleanupPendingUlrFetcher() { |
807 language_list_request_pending_.reset(); | 811 language_list_request_pending_.reset(); |
808 translate_script_request_pending_.reset(); | 812 translate_script_request_pending_.reset(); |
809 } | 813 } |
810 | 814 |
811 void TranslateManager::RequestTranslateScript() { | 815 void TranslateManager::RequestTranslateScript() { |
812 if (translate_script_request_pending_.get() != NULL) | 816 if (translate_script_request_pending_.get() != NULL) |
813 return; | 817 return; |
814 | 818 |
815 translate_script_request_pending_.reset(content::URLFetcher::Create( | 819 translate_script_request_pending_.reset(content::URLFetcher::Create( |
816 0, GURL(kTranslateScriptURL), content::URLFetcher::GET, this)); | 820 0, GURL(kTranslateScriptURL), content::URLFetcher::GET, this)); |
817 translate_script_request_pending_->SetRequestContext( | 821 translate_script_request_pending_->SetRequestContext( |
818 g_browser_process->system_request_context()); | 822 g_browser_process->system_request_context()); |
| 823 // TODO(jochen): Do cookie audit. |
| 824 translate_script_request_pending_->SetContentURLRequestUserData( |
| 825 new content::ContentURLRequestUserData()); |
819 translate_script_request_pending_->SetExtraRequestHeaders( | 826 translate_script_request_pending_->SetExtraRequestHeaders( |
820 kTranslateScriptHeader); | 827 kTranslateScriptHeader); |
821 translate_script_request_pending_->Start(); | 828 translate_script_request_pending_->Start(); |
822 } | 829 } |
823 | 830 |
824 void TranslateManager::ShowInfoBar(content::WebContents* tab, | 831 void TranslateManager::ShowInfoBar(content::WebContents* tab, |
825 TranslateInfoBarDelegate* infobar) { | 832 TranslateInfoBarDelegate* infobar) { |
826 DCHECK(infobar != NULL); | 833 DCHECK(infobar != NULL); |
827 TranslateInfoBarDelegate* old_infobar = GetTranslateInfoBarDelegate(tab); | 834 TranslateInfoBarDelegate* old_infobar = GetTranslateInfoBarDelegate(tab); |
828 infobar->UpdateBackgroundAnimation(old_infobar); | 835 infobar->UpdateBackgroundAnimation(old_infobar); |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
874 InfoBarTabHelper* infobar_helper = wrapper->infobar_tab_helper(); | 881 InfoBarTabHelper* infobar_helper = wrapper->infobar_tab_helper(); |
875 | 882 |
876 for (size_t i = 0; i < infobar_helper->infobar_count(); ++i) { | 883 for (size_t i = 0; i < infobar_helper->infobar_count(); ++i) { |
877 TranslateInfoBarDelegate* delegate = | 884 TranslateInfoBarDelegate* delegate = |
878 infobar_helper->GetInfoBarDelegateAt(i)->AsTranslateInfoBarDelegate(); | 885 infobar_helper->GetInfoBarDelegateAt(i)->AsTranslateInfoBarDelegate(); |
879 if (delegate) | 886 if (delegate) |
880 return delegate; | 887 return delegate; |
881 } | 888 } |
882 return NULL; | 889 return NULL; |
883 } | 890 } |
OLD | NEW |