Commit f0872687 authored by Sylvain Defresne's avatar Sylvain Defresne Committed by Commit Bot

Allow WebStateObserver to observe N WebStates [28/N].

Convert VoiceSearchNavigationTabHelper to directly track
the registration with the observed WebState instead of
relying on the deprecated code in WebStateObserver.

Bug: 775684
Change-Id: I0ab524c26da8afb97753788fa36db0f5df603430
Cq-Include-Trybots: master.tryserver.chromium.mac:ios-simulator-cronet;master.tryserver.chromium.mac:ios-simulator-full-configs
Reviewed-on: https://chromium-review.googlesource.com/768743
Commit-Queue: Sylvain Defresne <sdefresne@chromium.org>
Reviewed-by: default avatarEugene But <eugenebut@chromium.org>
Cr-Commit-Position: refs/heads/master@{#517062}
parent c2a825d8
...@@ -35,6 +35,11 @@ class VoiceSearchNavigationTabHelper ...@@ -35,6 +35,11 @@ class VoiceSearchNavigationTabHelper
void NavigationItemCommitted( void NavigationItemCommitted(
web::WebState* web_state, web::WebState* web_state,
const web::LoadCommittedDetails& load_details) override; const web::LoadCommittedDetails& load_details) override;
void WebStateDestroyed(web::WebState* web_state) override;
// The WebState this instance is observing. Will be null after
// WebStateDestroyed has been called.
web::WebState* web_state_ = nullptr;
// Whether a voice search navigation is expected. // Whether a voice search navigation is expected.
bool will_navigate_to_voice_search_result_ = false; bool will_navigate_to_voice_search_result_ = false;
......
...@@ -32,8 +32,8 @@ class VoiceSearchNavigationMarker : public base::SupportsUserData::Data {}; ...@@ -32,8 +32,8 @@ class VoiceSearchNavigationMarker : public base::SupportsUserData::Data {};
VoiceSearchNavigationTabHelper::VoiceSearchNavigationTabHelper( VoiceSearchNavigationTabHelper::VoiceSearchNavigationTabHelper(
web::WebState* web_state) web::WebState* web_state)
: web::WebStateObserver(web_state) { : web_state_(web_state) {
DCHECK(web_state); web_state_->AddObserver(this);
} }
void VoiceSearchNavigationTabHelper::WillLoadVoiceSearchResult() { void VoiceSearchNavigationTabHelper::WillLoadVoiceSearchResult() {
...@@ -44,7 +44,7 @@ bool VoiceSearchNavigationTabHelper::IsNavigationFromVoiceSearch( ...@@ -44,7 +44,7 @@ bool VoiceSearchNavigationTabHelper::IsNavigationFromVoiceSearch(
const web::NavigationItem* item) const { const web::NavigationItem* item) const {
DCHECK(item); DCHECK(item);
// Check if a voice search navigation is expected if |item| is pending load. // Check if a voice search navigation is expected if |item| is pending load.
const web::NavigationManager* manager = web_state()->GetNavigationManager(); const web::NavigationManager* manager = web_state_->GetNavigationManager();
const web::NavigationItem* pending_item = manager->GetPendingItem(); const web::NavigationItem* pending_item = manager->GetPendingItem();
const web::NavigationItem* transient_item = manager->GetTransientItem(); const web::NavigationItem* transient_item = manager->GetTransientItem();
if (item && (item == pending_item || item == transient_item)) if (item && (item == pending_item || item == transient_item))
...@@ -55,11 +55,19 @@ bool VoiceSearchNavigationTabHelper::IsNavigationFromVoiceSearch( ...@@ -55,11 +55,19 @@ bool VoiceSearchNavigationTabHelper::IsNavigationFromVoiceSearch(
} }
void VoiceSearchNavigationTabHelper::NavigationItemCommitted( void VoiceSearchNavigationTabHelper::NavigationItemCommitted(
web::WebState* web_state_, web::WebState* web_state,
const web::LoadCommittedDetails& load_details) { const web::LoadCommittedDetails& load_details) {
DCHECK_EQ(web_state_, web_state);
if (will_navigate_to_voice_search_result_) { if (will_navigate_to_voice_search_result_) {
load_details.item->SetUserData( load_details.item->SetUserData(
kNavigationMarkerKey, base::MakeUnique<VoiceSearchNavigationMarker>()); kNavigationMarkerKey, base::MakeUnique<VoiceSearchNavigationMarker>());
will_navigate_to_voice_search_result_ = false; will_navigate_to_voice_search_result_ = false;
} }
} }
void VoiceSearchNavigationTabHelper::WebStateDestroyed(
web::WebState* web_state) {
DCHECK_EQ(web_state_, web_state);
web_state_->RemoveObserver(this);
web_state_ = nullptr;
}
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