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 796 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
807 if (CommandLine::ForCurrentProcess()->HasSwitch( | 807 if (CommandLine::ForCurrentProcess()->HasSwitch( |
808 switches::kDisableTranslate) || | 808 switches::kDisableTranslate) || |
809 (prefs != NULL && !prefs->GetBoolean(prefs::kEnableTranslate))) { | 809 (prefs != NULL && !prefs->GetBoolean(prefs::kEnableTranslate))) { |
810 return; | 810 return; |
811 } | 811 } |
812 | 812 |
813 std::string language_list_fetch_url = base::StringPrintf( | 813 std::string language_list_fetch_url = base::StringPrintf( |
814 kLanguageListFetchURL, | 814 kLanguageListFetchURL, |
815 GetLanguageCode(g_browser_process->GetApplicationLocale()).c_str()); | 815 GetLanguageCode(g_browser_process->GetApplicationLocale()).c_str()); |
816 language_list_request_pending_.reset(content::URLFetcher::Create( | 816 language_list_request_pending_.reset(content::URLFetcher::Create( |
817 1, GURL(language_list_fetch_url), content::URLFetcher::GET, this)); | 817 1, GURL(language_list_fetch_url), net::URLFetcher::GET, this)); |
818 language_list_request_pending_->SetLoadFlags(net::LOAD_DO_NOT_SEND_COOKIES | | 818 language_list_request_pending_->SetLoadFlags(net::LOAD_DO_NOT_SEND_COOKIES | |
819 net::LOAD_DO_NOT_SAVE_COOKIES); | 819 net::LOAD_DO_NOT_SAVE_COOKIES); |
820 language_list_request_pending_->SetRequestContext( | 820 language_list_request_pending_->SetRequestContext( |
821 g_browser_process->system_request_context()); | 821 g_browser_process->system_request_context()); |
822 language_list_request_pending_->SetMaxRetries(kMaxRetryLanguageListFetch); | 822 language_list_request_pending_->SetMaxRetries(kMaxRetryLanguageListFetch); |
823 language_list_request_pending_->Start(); | 823 language_list_request_pending_->Start(); |
824 } | 824 } |
825 | 825 |
826 void TranslateManager::CleanupPendingUlrFetcher() { | 826 void TranslateManager::CleanupPendingUlrFetcher() { |
827 language_list_request_pending_.reset(); | 827 language_list_request_pending_.reset(); |
828 translate_script_request_pending_.reset(); | 828 translate_script_request_pending_.reset(); |
829 } | 829 } |
830 | 830 |
831 void TranslateManager::RequestTranslateScript() { | 831 void TranslateManager::RequestTranslateScript() { |
832 if (translate_script_request_pending_.get() != NULL) | 832 if (translate_script_request_pending_.get() != NULL) |
833 return; | 833 return; |
834 | 834 |
835 std::string translate_script_url = base::StringPrintf( | 835 std::string translate_script_url = base::StringPrintf( |
836 kTranslateScriptURL, | 836 kTranslateScriptURL, |
837 GetLanguageCode(g_browser_process->GetApplicationLocale()).c_str()); | 837 GetLanguageCode(g_browser_process->GetApplicationLocale()).c_str()); |
838 translate_script_request_pending_.reset(content::URLFetcher::Create( | 838 translate_script_request_pending_.reset(content::URLFetcher::Create( |
839 0, GURL(translate_script_url), content::URLFetcher::GET, this)); | 839 0, GURL(translate_script_url), net::URLFetcher::GET, this)); |
840 translate_script_request_pending_->SetLoadFlags( | 840 translate_script_request_pending_->SetLoadFlags( |
841 net::LOAD_DO_NOT_SEND_COOKIES | net::LOAD_DO_NOT_SAVE_COOKIES); | 841 net::LOAD_DO_NOT_SEND_COOKIES | net::LOAD_DO_NOT_SAVE_COOKIES); |
842 translate_script_request_pending_->SetRequestContext( | 842 translate_script_request_pending_->SetRequestContext( |
843 g_browser_process->system_request_context()); | 843 g_browser_process->system_request_context()); |
844 translate_script_request_pending_->SetExtraRequestHeaders( | 844 translate_script_request_pending_->SetExtraRequestHeaders( |
845 kTranslateScriptHeader); | 845 kTranslateScriptHeader); |
846 translate_script_request_pending_->Start(); | 846 translate_script_request_pending_->Start(); |
847 } | 847 } |
848 | 848 |
849 void TranslateManager::ShowInfoBar(content::WebContents* tab, | 849 void TranslateManager::ShowInfoBar(content::WebContents* tab, |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
899 InfoBarTabHelper* infobar_helper = wrapper->infobar_tab_helper(); | 899 InfoBarTabHelper* infobar_helper = wrapper->infobar_tab_helper(); |
900 | 900 |
901 for (size_t i = 0; i < infobar_helper->infobar_count(); ++i) { | 901 for (size_t i = 0; i < infobar_helper->infobar_count(); ++i) { |
902 TranslateInfoBarDelegate* delegate = | 902 TranslateInfoBarDelegate* delegate = |
903 infobar_helper->GetInfoBarDelegateAt(i)->AsTranslateInfoBarDelegate(); | 903 infobar_helper->GetInfoBarDelegateAt(i)->AsTranslateInfoBarDelegate(); |
904 if (delegate) | 904 if (delegate) |
905 return delegate; | 905 return delegate; |
906 } | 906 } |
907 return NULL; | 907 return NULL; |
908 } | 908 } |
OLD | NEW |