Commit 8b55433a authored by John Z Wu's avatar John Z Wu Committed by Commit Bot

Use new WebStateObserver method in IOSTranslateDriver.

ReplaceState is treated as a navigation, but the old method
"navigationItemCommited" was not called in that case and would mess up
translate_manager's language_state, causing a incorrect translation offer.

Bug: 780578
Change-Id: Ie4a5f55c7020a4d76168fcb8e2388a7d47fc815f
Reviewed-on: https://chromium-review.googlesource.com/767043Reviewed-by: default avatarSylvain Defresne <sdefresne@chromium.org>
Reviewed-by: default avatarEugene But <eugenebut@chromium.org>
Commit-Queue: John Wu <jzw@chromium.org>
Cr-Commit-Position: refs/heads/master@{#516380}
parent 631c8af1
...@@ -50,9 +50,8 @@ class IOSTranslateDriver : public TranslateDriver, ...@@ -50,9 +50,8 @@ class IOSTranslateDriver : public TranslateDriver,
CreateLanguageDetectionCallback(); CreateLanguageDetectionCallback();
// web::WebStateObserver methods. // web::WebStateObserver methods.
void NavigationItemCommitted( void DidFinishNavigation(web::WebState* web_state,
web::WebState* web_state, web::NavigationContext* navigation_context) override;
const web::LoadCommittedDetails& load_details) override;
void WebStateDestroyed(web::WebState* web_state) override; void WebStateDestroyed(web::WebState* web_state) override;
// TranslateDriver methods. // TranslateDriver methods.
......
...@@ -20,11 +20,11 @@ ...@@ -20,11 +20,11 @@
#import "components/translate/ios/browser/language_detection_controller.h" #import "components/translate/ios/browser/language_detection_controller.h"
#import "components/translate/ios/browser/translate_controller.h" #import "components/translate/ios/browser/translate_controller.h"
#include "ios/web/public/browser_state.h" #include "ios/web/public/browser_state.h"
#include "ios/web/public/load_committed_details.h"
#include "ios/web/public/navigation_item.h" #include "ios/web/public/navigation_item.h"
#include "ios/web/public/navigation_manager.h" #include "ios/web/public/navigation_manager.h"
#include "ios/web/public/referrer.h" #include "ios/web/public/referrer.h"
#include "ios/web/public/web_state/js/crw_js_injection_receiver.h" #include "ios/web/public/web_state/js/crw_js_injection_receiver.h"
#include "ios/web/public/web_state/navigation_context.h"
#include "ios/web/public/web_state/web_state.h" #include "ios/web/public/web_state/web_state.h"
#include "ui/base/page_transition_types.h" #include "ui/base/page_transition_types.h"
#include "ui/base/window_open_disposition.h" #include "ui/base/window_open_disposition.h"
...@@ -110,24 +110,24 @@ void IOSTranslateDriver::OnLanguageDetermined( ...@@ -110,24 +110,24 @@ void IOSTranslateDriver::OnLanguageDetermined(
// web::WebStateObserver methods // web::WebStateObserver methods
void IOSTranslateDriver::NavigationItemCommitted( void IOSTranslateDriver::DidFinishNavigation(
web::WebState* web_state, web::WebState* web_state,
const web::LoadCommittedDetails& load_details) { web::NavigationContext* navigation_context) {
DCHECK_EQ(web_state_, web_state); DCHECK_EQ(web_state_, web_state);
// Interrupt pending translations and reset various data when a navigation // Interrupt pending translations and reset various data when a navigation
// happens. Desktop does it by tracking changes in the page ID, and // happens. Desktop does it by tracking changes in the page ID, and
// through WebContentObserver, but these concepts do not exist on iOS. // through WebContentObserver, but these concepts do not exist on iOS.
if (!load_details.is_in_page) { if (!navigation_context->IsSameDocument()) {
++page_seq_no_; ++page_seq_no_;
translate_manager_->set_current_seq_no(page_seq_no_); translate_manager_->set_current_seq_no(page_seq_no_);
} }
// TODO(droger): support navigation types, like content/ does. // TODO(droger): support navigation types, like content/ does.
const bool reload = ui::PageTransitionCoreTypeIs( const bool reload = ui::PageTransitionCoreTypeIs(
load_details.item->GetTransitionType(), ui::PAGE_TRANSITION_RELOAD); navigation_context->GetPageTransition(), ui::PAGE_TRANSITION_RELOAD);
translate_manager_->GetLanguageState().DidNavigate(load_details.is_in_page, translate_manager_->GetLanguageState().DidNavigate(
true, reload); navigation_context->IsSameDocument(), true, reload);
} }
void IOSTranslateDriver::WebStateDestroyed(web::WebState* web_state) { void IOSTranslateDriver::WebStateDestroyed(web::WebState* web_state) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment