Chromium Code Reviews| 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/page_navigator.h" | 19 #include "content/public/browser/page_navigator.h" |
| 19 #include "content/public/browser/render_frame_host.h" | 20 #include "content/public/browser/render_frame_host.h" |
| 20 #include "content/public/browser/web_contents.h" | 21 #include "content/public/browser/web_contents.h" |
| 21 #include "content/public/common/referrer.h" | 22 #include "content/public/common/referrer.h" |
| 22 #include "net/http/http_status_code.h" | 23 #include "net/http/http_status_code.h" |
| 23 #include "url/gurl.h" | 24 #include "url/gurl.h" |
| 24 | 25 |
| 25 namespace { | 26 namespace { |
| 26 | 27 |
| 27 // The maximum number of attempts we'll do to see if the page has finshed | 28 // The maximum number of attempts we'll do to see if the page has finshed |
| (...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 204 // infobars being removed. Since the translation initiation process might add | 205 // infobars being removed. Since the translation initiation process might add |
| 205 // an infobar, it must be done after that. | 206 // an infobar, it must be done after that. |
| 206 base::ThreadTaskRunnerHandle::Get()->PostTask( | 207 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 207 FROM_HERE, | 208 FROM_HERE, |
| 208 base::Bind(&ContentTranslateDriver::InitiateTranslation, | 209 base::Bind(&ContentTranslateDriver::InitiateTranslation, |
| 209 weak_pointer_factory_.GetWeakPtr(), | 210 weak_pointer_factory_.GetWeakPtr(), |
| 210 translate_manager_->GetLanguageState().original_language(), | 211 translate_manager_->GetLanguageState().original_language(), |
| 211 0)); | 212 0)); |
| 212 } | 213 } |
| 213 | 214 |
| 214 void ContentTranslateDriver::DidNavigateAnyFrame( | 215 void ContentTranslateDriver::DidFinishNavigation( |
| 215 content::RenderFrameHost* render_frame_host, | 216 content::NavigationHandle* navigation_handle) { |
| 216 const content::LoadCommittedDetails& details, | 217 if (!navigation_handle->HasCommitted()) |
|
groby-ooo-7-16
2017/02/07 18:31:08
Why do we need to check HasCommitted()? Isn't that
jam
2017/02/07 18:35:17
If the response is a download or 204/205, then the
jam
2017/02/07 18:37:05
btw thanks for reminding me, I wanted to add some
| |
| 217 const content::FrameNavigateParams& params) { | 218 return; |
| 219 | |
| 218 // Let the LanguageState clear its state. | 220 // Let the LanguageState clear its state. |
| 219 const bool reload = | 221 const bool reload = |
| 220 ui::PageTransitionCoreTypeIs(details.entry->GetTransitionType(), | 222 navigation_handle->GetReloadType() != content::ReloadType::NONE || |
|
groby-ooo-7-16
2017/02/07 18:31:08
I assume ReloadType()!=NONE is the equivalent of P
jam
2017/02/07 18:35:17
Correct
| |
| 221 ui::PAGE_TRANSITION_RELOAD) || | 223 navigation_handle->IsSamePage(); |
| 222 details.type == content::NAVIGATION_TYPE_SAME_PAGE; | |
| 223 translate_manager_->GetLanguageState().DidNavigate( | 224 translate_manager_->GetLanguageState().DidNavigate( |
| 224 details.is_in_page, details.is_main_frame, reload); | 225 navigation_handle->IsSamePage(), navigation_handle->IsInMainFrame(), |
|
groby-ooo-7-16
2017/02/07 18:31:08
Should this pass through the |navigation_handle| i
jam
2017/02/07 18:35:17
That's calling out to shared code with ios, so it
| |
| 226 reload); | |
| 225 } | 227 } |
| 226 | 228 |
| 227 void ContentTranslateDriver::OnPageAway(int page_seq_no) { | 229 void ContentTranslateDriver::OnPageAway(int page_seq_no) { |
| 228 pages_.erase(page_seq_no); | 230 pages_.erase(page_seq_no); |
| 229 } | 231 } |
| 230 | 232 |
| 231 // mojom::ContentTranslateDriver implementation. | 233 // mojom::ContentTranslateDriver implementation. |
| 232 void ContentTranslateDriver::RegisterPage( | 234 void ContentTranslateDriver::RegisterPage( |
| 233 mojom::PagePtr page, | 235 mojom::PagePtr page, |
| 234 const LanguageDetectionDetails& details, | 236 const LanguageDetectionDetails& details, |
| (...skipping 22 matching lines...) Expand all Loading... | |
| 257 if (cancelled) | 259 if (cancelled) |
| 258 return; | 260 return; |
| 259 | 261 |
| 260 translate_manager_->PageTranslated( | 262 translate_manager_->PageTranslated( |
| 261 original_lang, translated_lang, error_type); | 263 original_lang, translated_lang, error_type); |
| 262 for (auto& observer : observer_list_) | 264 for (auto& observer : observer_list_) |
| 263 observer.OnPageTranslated(original_lang, translated_lang, error_type); | 265 observer.OnPageTranslated(original_lang, translated_lang, error_type); |
| 264 } | 266 } |
| 265 | 267 |
| 266 } // namespace translate | 268 } // namespace translate |
| OLD | NEW |