| 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 405 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 416 // Looks like crash on Mac is possibly caused with callback entering here | 416 // Looks like crash on Mac is possibly caused with callback entering here |
| 417 // with unknown fetcher when network is refreshed. | 417 // with unknown fetcher when network is refreshed. |
| 418 scoped_ptr<const net::URLFetcher> delete_ptr(source); | 418 scoped_ptr<const net::URLFetcher> delete_ptr(source); |
| 419 return; | 419 return; |
| 420 } | 420 } |
| 421 | 421 |
| 422 bool error = | 422 bool error = |
| 423 (source->GetStatus().status() != net::URLRequestStatus::SUCCESS || | 423 (source->GetStatus().status() != net::URLRequestStatus::SUCCESS || |
| 424 source->GetResponseCode() != 200); | 424 source->GetResponseCode() != 200); |
| 425 if (translate_script_request_pending_.get() == source) { | 425 if (translate_script_request_pending_.get() == source) { |
| 426 scoped_ptr<const content::URLFetcher> delete_ptr( | 426 scoped_ptr<const net::URLFetcher> delete_ptr( |
| 427 translate_script_request_pending_.release()); | 427 translate_script_request_pending_.release()); |
| 428 if (!error) { | 428 if (!error) { |
| 429 base::StringPiece str = ResourceBundle::GetSharedInstance(). | 429 base::StringPiece str = ResourceBundle::GetSharedInstance(). |
| 430 GetRawDataResource(IDR_TRANSLATE_JS); | 430 GetRawDataResource(IDR_TRANSLATE_JS); |
| 431 DCHECK(translate_script_.empty()); | 431 DCHECK(translate_script_.empty()); |
| 432 str.CopyToString(&translate_script_); | 432 str.CopyToString(&translate_script_); |
| 433 std::string data; | 433 std::string data; |
| 434 source->GetResponseAsString(&data); | 434 source->GetResponseAsString(&data); |
| 435 translate_script_ += "\n" + data; | 435 translate_script_ += "\n" + data; |
| 436 // We'll expire the cached script after some time, to make sure long | 436 // We'll expire the cached script after some time, to make sure long |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 470 request.source_lang, | 470 request.source_lang, |
| 471 request.target_lang)); | 471 request.target_lang)); |
| 472 } else { | 472 } else { |
| 473 // Translate the page. | 473 // Translate the page. |
| 474 DoTranslatePage(tab, translate_script_, | 474 DoTranslatePage(tab, translate_script_, |
| 475 request.source_lang, request.target_lang); | 475 request.source_lang, request.target_lang); |
| 476 } | 476 } |
| 477 } | 477 } |
| 478 pending_requests_.clear(); | 478 pending_requests_.clear(); |
| 479 } else { // if (translate_script_request_pending_.get() == source) | 479 } else { // if (translate_script_request_pending_.get() == source) |
| 480 scoped_ptr<const content::URLFetcher> delete_ptr( | 480 scoped_ptr<const net::URLFetcher> delete_ptr( |
| 481 language_list_request_pending_.release()); | 481 language_list_request_pending_.release()); |
| 482 if (!error) { | 482 if (!error) { |
| 483 std::string data; | 483 std::string data; |
| 484 source->GetResponseAsString(&data); | 484 source->GetResponseAsString(&data); |
| 485 SetSupportedLanguages(data); | 485 SetSupportedLanguages(data); |
| 486 } else { | 486 } else { |
| 487 VLOG(1) << "Failed to Fetch languages from: " << kLanguageListFetchURL; | 487 VLOG(1) << "Failed to Fetch languages from: " << kLanguageListFetchURL; |
| 488 } | 488 } |
| 489 } | 489 } |
| 490 } | 490 } |
| (...skipping 408 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 |