| 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 27 matching lines...) Expand all Loading... |
| 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/render_view_host.h" | 46 #include "content/public/browser/render_view_host.h" |
| 47 #include "content/public/browser/web_contents.h" | 47 #include "content/public/browser/web_contents.h" |
| 48 #include "content/public/common/url_fetcher.h" | |
| 49 #include "grit/browser_resources.h" | 48 #include "grit/browser_resources.h" |
| 50 #include "net/base/escape.h" | 49 #include "net/base/escape.h" |
| 51 #include "net/base/load_flags.h" | 50 #include "net/base/load_flags.h" |
| 51 #include "net/url_request/url_fetcher.h" |
| 52 #include "net/url_request/url_request_status.h" | 52 #include "net/url_request/url_request_status.h" |
| 53 #include "ui/base/layout.h" | 53 #include "ui/base/layout.h" |
| 54 #include "ui/base/resource/resource_bundle.h" | 54 #include "ui/base/resource/resource_bundle.h" |
| 55 | 55 |
| 56 #ifdef FILE_MANAGER_EXTENSION | 56 #ifdef FILE_MANAGER_EXTENSION |
| 57 #include "chrome/browser/chromeos/extensions/file_manager_util.h" | 57 #include "chrome/browser/chromeos/extensions/file_manager_util.h" |
| 58 #endif | 58 #endif |
| 59 | 59 |
| 60 using content::NavigationController; | 60 using content::NavigationController; |
| 61 using content::NavigationEntry; | 61 using content::NavigationEntry; |
| (...skipping 743 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 805 DCHECK(prefs != NULL); | 805 DCHECK(prefs != NULL); |
| 806 if (CommandLine::ForCurrentProcess()->HasSwitch( | 806 if (CommandLine::ForCurrentProcess()->HasSwitch( |
| 807 switches::kDisableTranslate) || | 807 switches::kDisableTranslate) || |
| 808 (prefs != NULL && !prefs->GetBoolean(prefs::kEnableTranslate))) { | 808 (prefs != NULL && !prefs->GetBoolean(prefs::kEnableTranslate))) { |
| 809 return; | 809 return; |
| 810 } | 810 } |
| 811 | 811 |
| 812 std::string language_list_fetch_url = base::StringPrintf( | 812 std::string language_list_fetch_url = base::StringPrintf( |
| 813 kLanguageListFetchURL, | 813 kLanguageListFetchURL, |
| 814 GetLanguageCode(g_browser_process->GetApplicationLocale()).c_str()); | 814 GetLanguageCode(g_browser_process->GetApplicationLocale()).c_str()); |
| 815 language_list_request_pending_.reset(content::URLFetcher::Create( | 815 language_list_request_pending_.reset(net::URLFetcher::Create( |
| 816 1, GURL(language_list_fetch_url), net::URLFetcher::GET, this)); | 816 1, GURL(language_list_fetch_url), net::URLFetcher::GET, this)); |
| 817 language_list_request_pending_->SetLoadFlags(net::LOAD_DO_NOT_SEND_COOKIES | | 817 language_list_request_pending_->SetLoadFlags(net::LOAD_DO_NOT_SEND_COOKIES | |
| 818 net::LOAD_DO_NOT_SAVE_COOKIES); | 818 net::LOAD_DO_NOT_SAVE_COOKIES); |
| 819 language_list_request_pending_->SetRequestContext( | 819 language_list_request_pending_->SetRequestContext( |
| 820 g_browser_process->system_request_context()); | 820 g_browser_process->system_request_context()); |
| 821 language_list_request_pending_->SetMaxRetries(kMaxRetryLanguageListFetch); | 821 language_list_request_pending_->SetMaxRetries(kMaxRetryLanguageListFetch); |
| 822 language_list_request_pending_->Start(); | 822 language_list_request_pending_->Start(); |
| 823 } | 823 } |
| 824 | 824 |
| 825 void TranslateManager::CleanupPendingUlrFetcher() { | 825 void TranslateManager::CleanupPendingUlrFetcher() { |
| 826 language_list_request_pending_.reset(); | 826 language_list_request_pending_.reset(); |
| 827 translate_script_request_pending_.reset(); | 827 translate_script_request_pending_.reset(); |
| 828 } | 828 } |
| 829 | 829 |
| 830 void TranslateManager::RequestTranslateScript() { | 830 void TranslateManager::RequestTranslateScript() { |
| 831 if (translate_script_request_pending_.get() != NULL) | 831 if (translate_script_request_pending_.get() != NULL) |
| 832 return; | 832 return; |
| 833 | 833 |
| 834 std::string translate_script_url = base::StringPrintf( | 834 std::string translate_script_url = base::StringPrintf( |
| 835 kTranslateScriptURL, | 835 kTranslateScriptURL, |
| 836 GetLanguageCode(g_browser_process->GetApplicationLocale()).c_str()); | 836 GetLanguageCode(g_browser_process->GetApplicationLocale()).c_str()); |
| 837 translate_script_request_pending_.reset(content::URLFetcher::Create( | 837 translate_script_request_pending_.reset(net::URLFetcher::Create( |
| 838 0, GURL(translate_script_url), net::URLFetcher::GET, this)); | 838 0, GURL(translate_script_url), net::URLFetcher::GET, this)); |
| 839 translate_script_request_pending_->SetLoadFlags( | 839 translate_script_request_pending_->SetLoadFlags( |
| 840 net::LOAD_DO_NOT_SEND_COOKIES | net::LOAD_DO_NOT_SAVE_COOKIES); | 840 net::LOAD_DO_NOT_SEND_COOKIES | net::LOAD_DO_NOT_SAVE_COOKIES); |
| 841 translate_script_request_pending_->SetRequestContext( | 841 translate_script_request_pending_->SetRequestContext( |
| 842 g_browser_process->system_request_context()); | 842 g_browser_process->system_request_context()); |
| 843 translate_script_request_pending_->SetExtraRequestHeaders( | 843 translate_script_request_pending_->SetExtraRequestHeaders( |
| 844 kTranslateScriptHeader); | 844 kTranslateScriptHeader); |
| 845 translate_script_request_pending_->Start(); | 845 translate_script_request_pending_->Start(); |
| 846 } | 846 } |
| 847 | 847 |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 897 InfoBarTabHelper* infobar_helper = tab_contents->infobar_tab_helper(); | 897 InfoBarTabHelper* infobar_helper = tab_contents->infobar_tab_helper(); |
| 898 | 898 |
| 899 for (size_t i = 0; i < infobar_helper->infobar_count(); ++i) { | 899 for (size_t i = 0; i < infobar_helper->infobar_count(); ++i) { |
| 900 TranslateInfoBarDelegate* delegate = | 900 TranslateInfoBarDelegate* delegate = |
| 901 infobar_helper->GetInfoBarDelegateAt(i)->AsTranslateInfoBarDelegate(); | 901 infobar_helper->GetInfoBarDelegateAt(i)->AsTranslateInfoBarDelegate(); |
| 902 if (delegate) | 902 if (delegate) |
| 903 return delegate; | 903 return delegate; |
| 904 } | 904 } |
| 905 return NULL; | 905 return NULL; |
| 906 } | 906 } |
| OLD | NEW |