| OLD | NEW |
| 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 "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 275 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 286 // When doing a page reload, we don't get a TAB_LANGUAGE_DETERMINED | 286 // When doing a page reload, we don't get a TAB_LANGUAGE_DETERMINED |
| 287 // notification. So we need to explictly initiate the translation. | 287 // notification. So we need to explictly initiate the translation. |
| 288 // Note that we delay it as the TranslateManager gets this notification | 288 // Note that we delay it as the TranslateManager gets this notification |
| 289 // before the TabContents and the TabContents processing might remove the | 289 // before the TabContents and the TabContents processing might remove the |
| 290 // current infobars. Since InitTranslation might add an infobar, it must | 290 // current infobars. Since InitTranslation might add an infobar, it must |
| 291 // be done after that. | 291 // be done after that. |
| 292 MessageLoop::current()->PostTask(FROM_HERE, | 292 MessageLoop::current()->PostTask(FROM_HERE, |
| 293 base::Bind( | 293 base::Bind( |
| 294 &TranslateManager::InitiateTranslationPosted, | 294 &TranslateManager::InitiateTranslationPosted, |
| 295 weak_method_factory_.GetWeakPtr(), | 295 weak_method_factory_.GetWeakPtr(), |
| 296 controller->tab_contents()->render_view_host()->process()->id(), | 296 controller->tab_contents()->render_view_host()->process()-> |
| 297 GetID(), |
| 297 controller->tab_contents()->render_view_host()->routing_id(), | 298 controller->tab_contents()->render_view_host()->routing_id(), |
| 298 helper->language_state().original_language())); | 299 helper->language_state().original_language())); |
| 299 break; | 300 break; |
| 300 } | 301 } |
| 301 case chrome::NOTIFICATION_TAB_LANGUAGE_DETERMINED: { | 302 case chrome::NOTIFICATION_TAB_LANGUAGE_DETERMINED: { |
| 302 TabContents* tab = content::Source<TabContents>(source).ptr(); | 303 TabContents* tab = content::Source<TabContents>(source).ptr(); |
| 303 // We may get this notifications multiple times. Make sure to translate | 304 // We may get this notifications multiple times. Make sure to translate |
| 304 // only once. | 305 // only once. |
| 305 TabContentsWrapper* wrapper = | 306 TabContentsWrapper* wrapper = |
| 306 TabContentsWrapper::GetCurrentWrapperForContents(tab); | 307 TabContentsWrapper::GetCurrentWrapperForContents(tab); |
| (...skipping 258 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 565 | 566 |
| 566 if (!translate_script_.empty()) { | 567 if (!translate_script_.empty()) { |
| 567 DoTranslatePage(tab_contents, translate_script_, source_lang, target_lang); | 568 DoTranslatePage(tab_contents, translate_script_, source_lang, target_lang); |
| 568 return; | 569 return; |
| 569 } | 570 } |
| 570 | 571 |
| 571 // The script is not available yet. Queue that request and query for the | 572 // The script is not available yet. Queue that request and query for the |
| 572 // script. Once it is downloaded we'll do the translate. | 573 // script. Once it is downloaded we'll do the translate. |
| 573 RenderViewHost* rvh = tab_contents->render_view_host(); | 574 RenderViewHost* rvh = tab_contents->render_view_host(); |
| 574 PendingRequest request; | 575 PendingRequest request; |
| 575 request.render_process_id = rvh->process()->id(); | 576 request.render_process_id = rvh->process()->GetID(); |
| 576 request.render_view_id = rvh->routing_id(); | 577 request.render_view_id = rvh->routing_id(); |
| 577 request.page_id = entry->page_id(); | 578 request.page_id = entry->page_id(); |
| 578 request.source_lang = source_lang; | 579 request.source_lang = source_lang; |
| 579 request.target_lang = target_lang; | 580 request.target_lang = target_lang; |
| 580 pending_requests_.push_back(request); | 581 pending_requests_.push_back(request); |
| 581 RequestTranslateScript(); | 582 RequestTranslateScript(); |
| 582 } | 583 } |
| 583 | 584 |
| 584 void TranslateManager::RevertTranslation(TabContents* tab_contents) { | 585 void TranslateManager::RevertTranslation(TabContents* tab_contents) { |
| 585 NavigationEntry* entry = tab_contents->controller().GetActiveEntry(); | 586 NavigationEntry* entry = tab_contents->controller().GetActiveEntry(); |
| (...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 828 InfoBarTabHelper* infobar_helper = wrapper->infobar_tab_helper(); | 829 InfoBarTabHelper* infobar_helper = wrapper->infobar_tab_helper(); |
| 829 | 830 |
| 830 for (size_t i = 0; i < infobar_helper->infobar_count(); ++i) { | 831 for (size_t i = 0; i < infobar_helper->infobar_count(); ++i) { |
| 831 TranslateInfoBarDelegate* delegate = | 832 TranslateInfoBarDelegate* delegate = |
| 832 infobar_helper->GetInfoBarDelegateAt(i)->AsTranslateInfoBarDelegate(); | 833 infobar_helper->GetInfoBarDelegateAt(i)->AsTranslateInfoBarDelegate(); |
| 833 if (delegate) | 834 if (delegate) |
| 834 return delegate; | 835 return delegate; |
| 835 } | 836 } |
| 836 return NULL; | 837 return NULL; |
| 837 } | 838 } |
| OLD | NEW |