| 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" |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 79 | 79 |
| 80 translate_manager_->InitiateTranslation( | 80 translate_manager_->InitiateTranslation( |
| 81 translate::TranslateDownloadManager::GetLanguageCode(page_lang)); | 81 translate::TranslateDownloadManager::GetLanguageCode(page_lang)); |
| 82 } | 82 } |
| 83 | 83 |
| 84 // TranslateDriver methods | 84 // TranslateDriver methods |
| 85 | 85 |
| 86 bool ContentTranslateDriver::IsLinkNavigation() { | 86 bool ContentTranslateDriver::IsLinkNavigation() { |
| 87 return navigation_controller_ && | 87 return navigation_controller_ && |
| 88 navigation_controller_->GetLastCommittedEntry() && | 88 navigation_controller_->GetLastCommittedEntry() && |
| 89 navigation_controller_->GetLastCommittedEntry()->GetTransitionType() == | 89 ui::PageTransitionCoreTypeIs( |
| 90 ui::PAGE_TRANSITION_LINK; | 90 navigation_controller_->GetLastCommittedEntry() |
| 91 ->GetTransitionType(), |
| 92 ui::PAGE_TRANSITION_LINK); |
| 91 } | 93 } |
| 92 | 94 |
| 93 void ContentTranslateDriver::OnTranslateEnabledChanged() { | 95 void ContentTranslateDriver::OnTranslateEnabledChanged() { |
| 94 content::WebContents* web_contents = navigation_controller_->GetWebContents(); | 96 content::WebContents* web_contents = navigation_controller_->GetWebContents(); |
| 95 FOR_EACH_OBSERVER( | 97 FOR_EACH_OBSERVER( |
| 96 Observer, observer_list_, OnTranslateEnabledChanged(web_contents)); | 98 Observer, observer_list_, OnTranslateEnabledChanged(web_contents)); |
| 97 } | 99 } |
| 98 | 100 |
| 99 void ContentTranslateDriver::OnIsPageTranslatedChanged() { | 101 void ContentTranslateDriver::OnIsPageTranslatedChanged() { |
| 100 content::WebContents* web_contents = | 102 content::WebContents* web_contents = |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 172 | 174 |
| 173 if (!load_details.is_main_frame && | 175 if (!load_details.is_main_frame && |
| 174 translate_manager_->GetLanguageState().translation_declined()) { | 176 translate_manager_->GetLanguageState().translation_declined()) { |
| 175 // Some sites (such as Google map) may trigger sub-frame navigations | 177 // Some sites (such as Google map) may trigger sub-frame navigations |
| 176 // when the user interacts with the page. We don't want to show a new | 178 // when the user interacts with the page. We don't want to show a new |
| 177 // infobar if the user already dismissed one in that case. | 179 // infobar if the user already dismissed one in that case. |
| 178 return; | 180 return; |
| 179 } | 181 } |
| 180 | 182 |
| 181 // If not a reload, return. | 183 // If not a reload, return. |
| 182 if (entry->GetTransitionType() != ui::PAGE_TRANSITION_RELOAD && | 184 if (!ui::PageTransitionCoreTypeIs(entry->GetTransitionType(), |
| 185 ui::PAGE_TRANSITION_RELOAD) && |
| 183 load_details.type != content::NAVIGATION_TYPE_SAME_PAGE) { | 186 load_details.type != content::NAVIGATION_TYPE_SAME_PAGE) { |
| 184 return; | 187 return; |
| 185 } | 188 } |
| 186 | 189 |
| 187 if (!translate_manager_->GetLanguageState().page_needs_translation()) | 190 if (!translate_manager_->GetLanguageState().page_needs_translation()) |
| 188 return; | 191 return; |
| 189 | 192 |
| 190 // Note that we delay it as the ordering of the processing of this callback | 193 // Note that we delay it as the ordering of the processing of this callback |
| 191 // by WebContentsObservers is undefined and might result in the current | 194 // by WebContentsObservers is undefined and might result in the current |
| 192 // infobars being removed. Since the translation initiation process might add | 195 // infobars being removed. Since the translation initiation process might add |
| 193 // an infobar, it must be done after that. | 196 // an infobar, it must be done after that. |
| 194 base::ThreadTaskRunnerHandle::Get()->PostTask( | 197 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 195 FROM_HERE, | 198 FROM_HERE, |
| 196 base::Bind(&ContentTranslateDriver::InitiateTranslation, | 199 base::Bind(&ContentTranslateDriver::InitiateTranslation, |
| 197 weak_pointer_factory_.GetWeakPtr(), | 200 weak_pointer_factory_.GetWeakPtr(), |
| 198 translate_manager_->GetLanguageState().original_language(), | 201 translate_manager_->GetLanguageState().original_language(), |
| 199 0)); | 202 0)); |
| 200 } | 203 } |
| 201 | 204 |
| 202 void ContentTranslateDriver::DidNavigateAnyFrame( | 205 void ContentTranslateDriver::DidNavigateAnyFrame( |
| 203 content::RenderFrameHost* render_frame_host, | 206 content::RenderFrameHost* render_frame_host, |
| 204 const content::LoadCommittedDetails& details, | 207 const content::LoadCommittedDetails& details, |
| 205 const content::FrameNavigateParams& params) { | 208 const content::FrameNavigateParams& params) { |
| 206 // Let the LanguageState clear its state. | 209 // Let the LanguageState clear its state. |
| 207 const bool reload = | 210 const bool reload = |
| 208 details.entry->GetTransitionType() == ui::PAGE_TRANSITION_RELOAD || | 211 ui::PageTransitionCoreTypeIs(details.entry->GetTransitionType(), |
| 212 ui::PAGE_TRANSITION_RELOAD) || |
| 209 details.type == content::NAVIGATION_TYPE_SAME_PAGE; | 213 details.type == content::NAVIGATION_TYPE_SAME_PAGE; |
| 210 translate_manager_->GetLanguageState().DidNavigate( | 214 translate_manager_->GetLanguageState().DidNavigate( |
| 211 details.is_in_page, details.is_main_frame, reload); | 215 details.is_in_page, details.is_main_frame, reload); |
| 212 } | 216 } |
| 213 | 217 |
| 214 bool ContentTranslateDriver::OnMessageReceived( | 218 bool ContentTranslateDriver::OnMessageReceived( |
| 215 const IPC::Message& message, | 219 const IPC::Message& message, |
| 216 content::RenderFrameHost* render_frame_host) { | 220 content::RenderFrameHost* render_frame_host) { |
| 217 bool handled = true; | 221 bool handled = true; |
| 218 IPC_BEGIN_MESSAGE_MAP(ContentTranslateDriver, message) | 222 IPC_BEGIN_MESSAGE_MAP(ContentTranslateDriver, message) |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 255 TranslateErrors::Type error_type) { | 259 TranslateErrors::Type error_type) { |
| 256 translate_manager_->PageTranslated( | 260 translate_manager_->PageTranslated( |
| 257 original_lang, translated_lang, error_type); | 261 original_lang, translated_lang, error_type); |
| 258 FOR_EACH_OBSERVER( | 262 FOR_EACH_OBSERVER( |
| 259 Observer, | 263 Observer, |
| 260 observer_list_, | 264 observer_list_, |
| 261 OnPageTranslated(original_lang, translated_lang, error_type)); | 265 OnPageTranslated(original_lang, translated_lang, error_type)); |
| 262 } | 266 } |
| 263 | 267 |
| 264 } // namespace translate | 268 } // namespace translate |
| OLD | NEW |