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

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

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

Bug: 775684
Change-Id: I5add60c72e6046400c2dc1c4a609e9f443ecb782
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/768420
Commit-Queue: Sylvain Defresne <sdefresne@chromium.org>
Reviewed-by: default avatarEugene But <eugenebut@chromium.org>
Cr-Commit-Position: refs/heads/master@{#517049}
parent 786ec7d5
...@@ -47,6 +47,10 @@ class JavaScriptDialogBlockingState ...@@ -47,6 +47,10 @@ class JavaScriptDialogBlockingState
web::NavigationContext* navigation_context) override; web::NavigationContext* navigation_context) override;
void WebStateDestroyed(web::WebState* web_state) 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 to show the blocking option. // Whether to show the blocking option.
size_t dialog_count_ = 0; size_t dialog_count_ = 0;
// The NavigationItem for which JavaScript dialogs were blocked. // The NavigationItem for which JavaScript dialogs were blocked.
......
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
#import "ios/chrome/browser/ui/dialogs/java_script_dialog_blocking_state.h" #import "ios/chrome/browser/ui/dialogs/java_script_dialog_blocking_state.h"
#include "base/logging.h"
#import "ios/web/public/navigation_item.h" #import "ios/web/public/navigation_item.h"
#import "ios/web/public/navigation_manager.h" #import "ios/web/public/navigation_manager.h"
#import "ios/web/public/web_state/navigation_context.h" #import "ios/web/public/web_state/navigation_context.h"
...@@ -16,24 +17,25 @@ DEFINE_WEB_STATE_USER_DATA_KEY(JavaScriptDialogBlockingState); ...@@ -16,24 +17,25 @@ DEFINE_WEB_STATE_USER_DATA_KEY(JavaScriptDialogBlockingState);
JavaScriptDialogBlockingState::JavaScriptDialogBlockingState( JavaScriptDialogBlockingState::JavaScriptDialogBlockingState(
web::WebState* web_state) web::WebState* web_state)
: web::WebStateObserver(web_state) { : web_state_(web_state) {
DCHECK(web_state); web_state_->AddObserver(this);
} }
JavaScriptDialogBlockingState::~JavaScriptDialogBlockingState() { JavaScriptDialogBlockingState::~JavaScriptDialogBlockingState() {
// It is expected that WebStateDestroyed() will be received before this state // It is expected that WebStateDestroyed() will be received before this state
// is deallocated. // is deallocated.
DCHECK(!web_state()); DCHECK(!web_state_);
} }
void JavaScriptDialogBlockingState::JavaScriptDialogBlockingOptionSelected() { void JavaScriptDialogBlockingState::JavaScriptDialogBlockingOptionSelected() {
blocked_item_ = web_state()->GetNavigationManager()->GetLastCommittedItem(); blocked_item_ = web_state_->GetNavigationManager()->GetLastCommittedItem();
DCHECK(blocked_item_); DCHECK(blocked_item_);
} }
void JavaScriptDialogBlockingState::DidStartNavigation( void JavaScriptDialogBlockingState::DidStartNavigation(
web::WebState* web_state, web::WebState* web_state,
web::NavigationContext* navigation_context) { web::NavigationContext* navigation_context) {
DCHECK_EQ(web_state_, web_state);
web::NavigationItem* item = web::NavigationItem* item =
web_state->GetNavigationManager()->GetLastCommittedItem(); web_state->GetNavigationManager()->GetLastCommittedItem();
// The dialog blocking state should be reset for user-initiated loads or for // The dialog blocking state should be reset for user-initiated loads or for
...@@ -47,5 +49,7 @@ void JavaScriptDialogBlockingState::DidStartNavigation( ...@@ -47,5 +49,7 @@ void JavaScriptDialogBlockingState::DidStartNavigation(
void JavaScriptDialogBlockingState::WebStateDestroyed( void JavaScriptDialogBlockingState::WebStateDestroyed(
web::WebState* web_state) { web::WebState* web_state) {
Observe(nullptr); 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