OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "components/translate/content/browser/content_translate_driver.h" | 5 #include "components/translate/content/browser/content_translate_driver.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/location.h" | 8 #include "base/location.h" |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/single_thread_task_runner.h" | 10 #include "base/single_thread_task_runner.h" |
11 #include "base/threading/thread_task_runner_handle.h" | 11 #include "base/threading/thread_task_runner_handle.h" |
12 #include "components/translate/core/browser/translate_download_manager.h" | 12 #include "components/translate/core/browser/translate_download_manager.h" |
13 #include "components/translate/core/browser/translate_manager.h" | 13 #include "components/translate/core/browser/translate_manager.h" |
14 #include "content/public/browser/browser_context.h" | 14 #include "content/public/browser/browser_context.h" |
15 #include "content/public/browser/navigation_controller.h" | 15 #include "content/public/browser/navigation_controller.h" |
16 #include "content/public/browser/navigation_details.h" | 16 #include "content/public/browser/navigation_details.h" |
17 #include "content/public/browser/navigation_entry.h" | 17 #include "content/public/browser/navigation_entry.h" |
18 #include "content/public/browser/navigation_handle.h" | 18 #include "content/public/browser/navigation_handle.h" |
19 #include "content/public/browser/page_navigator.h" | 19 #include "content/public/browser/page_navigator.h" |
20 #include "content/public/browser/render_frame_host.h" | 20 #include "content/public/browser/render_frame_host.h" |
21 #include "content/public/browser/web_contents.h" | 21 #include "content/public/browser/web_contents.h" |
22 #include "content/public/common/referrer.h" | 22 #include "content/public/common/referrer.h" |
| 23 #include "net/base/network_change_notifier.h" |
23 #include "net/http/http_status_code.h" | 24 #include "net/http/http_status_code.h" |
24 #include "url/gurl.h" | 25 #include "url/gurl.h" |
25 | 26 |
26 namespace { | 27 namespace { |
27 | 28 |
28 // The maximum number of attempts we'll do to see if the page has finshed | 29 // The maximum number of attempts we'll do to see if the page has finshed |
29 // loading before giving up the translation | 30 // loading before giving up the translation |
30 const int kMaxTranslateLoadCheckAttempts = 20; | 31 const int kMaxTranslateLoadCheckAttempts = 20; |
31 | 32 |
32 } // namespace | 33 } // namespace |
(...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
252 } | 253 } |
253 | 254 |
254 void ContentTranslateDriver::OnPageTranslated( | 255 void ContentTranslateDriver::OnPageTranslated( |
255 bool cancelled, | 256 bool cancelled, |
256 const std::string& original_lang, | 257 const std::string& original_lang, |
257 const std::string& translated_lang, | 258 const std::string& translated_lang, |
258 TranslateErrors::Type error_type) { | 259 TranslateErrors::Type error_type) { |
259 if (cancelled) | 260 if (cancelled) |
260 return; | 261 return; |
261 | 262 |
| 263 if (net::NetworkChangeNotifier::IsOffline()) { |
| 264 error_type = TranslateErrors::NETWORK; |
| 265 } |
| 266 |
262 translate_manager_->PageTranslated( | 267 translate_manager_->PageTranslated( |
263 original_lang, translated_lang, error_type); | 268 original_lang, translated_lang, error_type); |
264 for (auto& observer : observer_list_) | 269 for (auto& observer : observer_list_) |
265 observer.OnPageTranslated(original_lang, translated_lang, error_type); | 270 observer.OnPageTranslated(original_lang, translated_lang, error_type); |
266 } | 271 } |
267 | 272 |
268 } // namespace translate | 273 } // namespace translate |
OLD | NEW |