| 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 334 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 345 } | 345 } |
| 346 // When doing a page reload, TAB_LANGUAGE_DETERMINED is not sent, | 346 // When doing a page reload, TAB_LANGUAGE_DETERMINED is not sent, |
| 347 // so the translation needs to be explicitly initiated, but only when the | 347 // so the translation needs to be explicitly initiated, but only when the |
| 348 // page is translatable. | 348 // page is translatable. |
| 349 if (!translate_tab_helper->language_state().page_translatable()) | 349 if (!translate_tab_helper->language_state().page_translatable()) |
| 350 return; | 350 return; |
| 351 // Note that we delay it as the TranslateManager gets this notification | 351 // Note that we delay it as the TranslateManager gets this notification |
| 352 // before the WebContents and the WebContents processing might remove the | 352 // before the WebContents and the WebContents processing might remove the |
| 353 // current infobars. Since InitTranslation might add an infobar, it must | 353 // current infobars. Since InitTranslation might add an infobar, it must |
| 354 // be done after that. | 354 // be done after that. |
| 355 MessageLoop::current()->PostTask(FROM_HERE, | 355 base::MessageLoop::current()->PostTask( |
| 356 FROM_HERE, |
| 356 base::Bind( | 357 base::Bind( |
| 357 &TranslateManager::InitiateTranslationPosted, | 358 &TranslateManager::InitiateTranslationPosted, |
| 358 weak_method_factory_.GetWeakPtr(), | 359 weak_method_factory_.GetWeakPtr(), |
| 359 controller->GetWebContents()->GetRenderProcessHost()->GetID(), | 360 controller->GetWebContents()->GetRenderProcessHost()->GetID(), |
| 360 controller->GetWebContents()->GetRenderViewHost()->GetRoutingID(), | 361 controller->GetWebContents()->GetRenderViewHost()->GetRoutingID(), |
| 361 translate_tab_helper->language_state().original_language())); | 362 translate_tab_helper->language_state().original_language())); |
| 362 break; | 363 break; |
| 363 } | 364 } |
| 364 case chrome::NOTIFICATION_TAB_LANGUAGE_DETERMINED: { | 365 case chrome::NOTIFICATION_TAB_LANGUAGE_DETERMINED: { |
| 365 WebContents* tab = content::Source<WebContents>(source).ptr(); | 366 WebContents* tab = content::Source<WebContents>(source).ptr(); |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 435 std::string argument = "('"; | 436 std::string argument = "('"; |
| 436 std::string api_key = google_apis::GetAPIKey(); | 437 std::string api_key = google_apis::GetAPIKey(); |
| 437 argument += net::EscapeQueryParamValue(api_key, true); | 438 argument += net::EscapeQueryParamValue(api_key, true); |
| 438 argument += "');\n"; | 439 argument += "');\n"; |
| 439 std::string data; | 440 std::string data; |
| 440 source->GetResponseAsString(&data); | 441 source->GetResponseAsString(&data); |
| 441 translate_script_ += argument + data; | 442 translate_script_ += argument + data; |
| 442 // We'll expire the cached script after some time, to make sure long | 443 // We'll expire the cached script after some time, to make sure long |
| 443 // running browsers still get fixes that might get pushed with newer | 444 // running browsers still get fixes that might get pushed with newer |
| 444 // scripts. | 445 // scripts. |
| 445 MessageLoop::current()->PostDelayedTask(FROM_HERE, | 446 base::MessageLoop::current()->PostDelayedTask( |
| 447 FROM_HERE, |
| 446 base::Bind(&TranslateManager::ClearTranslateScript, | 448 base::Bind(&TranslateManager::ClearTranslateScript, |
| 447 weak_method_factory_.GetWeakPtr()), | 449 weak_method_factory_.GetWeakPtr()), |
| 448 translate_script_expiration_delay_); | 450 translate_script_expiration_delay_); |
| 449 } | 451 } |
| 450 // Process any pending requests. | 452 // Process any pending requests. |
| 451 std::vector<PendingRequest>::const_iterator iter; | 453 std::vector<PendingRequest>::const_iterator iter; |
| 452 for (iter = pending_requests_.begin(); iter != pending_requests_.end(); | 454 for (iter = pending_requests_.begin(); iter != pending_requests_.end(); |
| 453 ++iter) { | 455 ++iter) { |
| 454 const PendingRequest& request = *iter; | 456 const PendingRequest& request = *iter; |
| 455 WebContents* web_contents = | 457 WebContents* web_contents = |
| (...skipping 447 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 903 // reason so we are more aggressive showing the shortcuts for never translate. | 905 // reason so we are more aggressive showing the shortcuts for never translate. |
| 904 #if defined(OS_ANDROID) | 906 #if defined(OS_ANDROID) |
| 905 config.never_translate_min_count = 1; | 907 config.never_translate_min_count = 1; |
| 906 #else | 908 #else |
| 907 config.never_translate_min_count = 3; | 909 config.never_translate_min_count = 3; |
| 908 #endif // defined(OS_ANDROID) | 910 #endif // defined(OS_ANDROID) |
| 909 | 911 |
| 910 config.always_translate_min_count = 3; | 912 config.always_translate_min_count = 3; |
| 911 return config; | 913 return config; |
| 912 } | 914 } |
| OLD | NEW |