Skip to content

Commit

Permalink
Remove unused ScriptCommandCallback remnants
Browse files Browse the repository at this point in the history
Support for ScriptCommandCallbacks was removed in crrev.com/c/4182545.
These *ScriptCommand* APIs are now unused and can be removed.

Bug: 837706
Change-Id: I772d0e07d0920d2ffd4a5ac5925af437dae967dc
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4193392
Commit-Queue: Mike Dougherty <michaeldo@chromium.org>
Reviewed-by: Gauthier Ambard <gambard@chromium.org>
Reviewed-by: Sebastien Seguin-Gagnon <sebsg@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1096841}
  • Loading branch information
michaeldo1 authored and Chromium LUCI CQ committed Jan 25, 2023
1 parent bce6bd4 commit d33096f
Show file tree
Hide file tree
Showing 12 changed files with 4 additions and 253 deletions.
9 changes: 1 addition & 8 deletions components/autofill/ios/form_util/form_activity_observer.h
Expand Up @@ -33,8 +33,6 @@ class FormActivityObserver {
// same-origin iframe. |params.input_missing| is indicating if there is any
// error when parsing the form field information.
// |sender_frame| is the WebFrame that sent the form activity message.
// |sender_frame| can be null if frame messaging is not enabled (see
// web::WebState::ScriptCommandCallback comment for details).
virtual void FormActivityRegistered(web::WebState* web_state,
web::WebFrame* sender_frame,
const FormActivityParams& params) {}
Expand All @@ -48,10 +46,7 @@ class FormActivityObserver {
// computed ('name', 'action', ...) and a 'field' element containing a list of
// dictionaries, each representing a field of the form and containing some
// attributes ('name', 'type', ...). |sender_frame| is the WebFrame that sent
// the form submission message. |sender_frame| can be null if frame messaging
// is not enabled (see web::WebState::ScriptCommandCallback comment for
// details).
// TODO(crbug.com/881816): Update comment once WebFrame cannot be null.
// the form submission message.
virtual void DocumentSubmitted(web::WebState* web_state,
web::WebFrame* sender_frame,
const std::string& form_name,
Expand All @@ -62,8 +57,6 @@ class FormActivityObserver {
// iframe. |params.input_missing| is indicating if there is any
// error when parsing the form field information.
// |sender_frame| is the WebFrame that sent the form activity message.
// |sender_frame| can be null if frame messaging is not enabled (see
// web::WebState::ScriptCommandCallback comment for details).
virtual void FormRemoved(web::WebState* web_state,
web::WebFrame* sender_frame,
const FormRemovalParams& params) {}
Expand Down
1 change: 0 additions & 1 deletion docs/ios/unrealized_web_state.md
Expand Up @@ -31,7 +31,6 @@ An "unrealized" `WebState` supports the following features:

- registering and removing Observers
- registering and removing WebStatePolicyDecider
- registering ScriptCommandCallback
- `const` property getters (*)
- retrieving saved state (**)
- attaching tab helpers
Expand Down
Expand Up @@ -8,6 +8,7 @@
#include <string>

#include "base/memory/weak_ptr.h"
#import "base/values.h"
#import "ios/web/find_in_page/java_script_find_in_page_request.h"
#import "ios/web/public/find_in_page/java_script_find_in_page_manager.h"
#include "ios/web/public/web_state_observer.h"
Expand Down
10 changes: 0 additions & 10 deletions ios/web/public/test/fakes/fake_web_state.h
Expand Up @@ -21,7 +21,6 @@
#import "ios/web/public/permissions/permissions.h"
#import "ios/web/public/web_state.h"
#include "ios/web/public/web_state_observer.h"
#include "third_party/abseil-cpp/absl/types/optional.h"
#include "url/gurl.h"

class SessionCertificatePolicyCache;
Expand Down Expand Up @@ -87,9 +86,6 @@ class FakeWebState : public WebState {
const GURL& GetVisibleURL() const override;
const GURL& GetLastCommittedURL() const override;
GURL GetCurrentURL(URLVerificationTrustLevel* trust_level) const override;
base::CallbackListSubscription AddScriptCommandCallback(
const ScriptCommandCallback& callback,
const std::string& command_prefix) override;
CRWWebViewProxyType GetWebViewProxy() const override;

void AddObserver(WebStateObserver* observer) override;
Expand Down Expand Up @@ -164,9 +160,6 @@ class FakeWebState : public WebState {
NSURLResponse* response,
WebStatePolicyDecider::ResponseInfo response_info,
WebStatePolicyDecider::PolicyDecisionCallback callback);
// Returns a copy of the last added callback, if one has been added.
absl::optional<ScriptCommandCallback> GetLastAddedCallback() const;
std::string GetLastCommandPrefix() const;
NSData* GetLastLoadedData() const;
bool IsClosed() const;

Expand Down Expand Up @@ -207,9 +200,6 @@ class FakeWebState : public WebState {
UIView* view_ = nil;
CRWWebViewProxyType web_view_proxy_;
NSData* last_loaded_data_ = nil;
base::RepeatingCallbackList<ScriptCommandCallbackSignature> callback_list_;
absl::optional<ScriptCommandCallback> last_added_callback_;
std::string last_command_prefix_;
PermissionState camera_permission_state_ = PermissionStateNotAccessible;
PermissionState microphone_permission_state_ = PermissionStateNotAccessible;

Expand Down
17 changes: 0 additions & 17 deletions ios/web/public/test/fakes/fake_web_state.mm
Expand Up @@ -249,14 +249,6 @@
return url_;
}

base::CallbackListSubscription FakeWebState::AddScriptCommandCallback(
const ScriptCommandCallback& callback,
const std::string& command_prefix) {
last_added_callback_ = callback;
last_command_prefix_ = command_prefix;
return callback_list_.Add(callback);
}

void FakeWebState::SetLastActiveTime(base::Time time) {
last_active_time_ = time;
}
Expand Down Expand Up @@ -435,15 +427,6 @@
num_decisions_requested);
}

absl::optional<WebState::ScriptCommandCallback>
FakeWebState::GetLastAddedCallback() const {
return last_added_callback_;
}

std::string FakeWebState::GetLastCommandPrefix() const {
return last_command_prefix_;
}

NSData* FakeWebState::GetLastLoadedData() const {
return last_loaded_data_;
}
Expand Down
27 changes: 0 additions & 27 deletions ios/web/public/web_state.h
Expand Up @@ -15,7 +15,6 @@
#include <utility>
#include <vector>

#include "base/callback_list.h"
#include "base/functional/callback_forward.h"
#include "base/memory/weak_ptr.h"
#include "base/strings/string_piece.h"
Expand All @@ -41,10 +40,6 @@ typedef id<CRWWebViewProxy> CRWWebViewProxyType;
@class UIView;
typedef UIView<CRWScrollableContent> CRWContentView;

namespace base {
class Value;
}

namespace gfx {
class Image;
class RectF;
Expand All @@ -58,7 +53,6 @@ class NavigationManager;
enum Permission : NSUInteger;
enum PermissionState : NSUInteger;
class SessionCertificatePolicyCache;
class WebFrame;
class WebFramesManager;
class WebStateDelegate;
class WebStateObserver;
Expand Down Expand Up @@ -386,27 +380,6 @@ class WebState : public base::SupportsUserData {
// TODO(crbug.com/457679): Figure out a clean API for this.
virtual GURL GetCurrentURL(URLVerificationTrustLevel* trust_level) const = 0;

// Callback used to handle script commands. `message` is the JS message sent
// from the `sender_frame` in the page, `page_url` is the URL of page's main
// frame, `user_is_interacting` indicates if the user is interacting with the
// page.
// TODO(crbug.com/881813): remove `page_url`.
using ScriptCommandCallbackSignature = void(const base::Value& message,
const GURL& page_url,
bool user_is_interacting,
web::WebFrame* sender_frame);
using ScriptCommandCallback =
base::RepeatingCallback<ScriptCommandCallbackSignature>;
// Registers `callback` for JS message whose 'command' matches
// `command_prefix`. The returned subscription should be stored by the caller.
// When the description object is destroyed, it will unregister `callback` if
// this WebState is still alive, and do nothing if this WebState is already
// destroyed. Therefore if the caller want to stop receiving JS messages it
// can just destroy the subscription.
[[nodiscard]] virtual base::CallbackListSubscription AddScriptCommandCallback(
const ScriptCommandCallback& callback,
const std::string& command_prefix) = 0;

// Returns the current CRWWebViewProxy object.
virtual CRWWebViewProxyType GetWebViewProxy() const = 0;

Expand Down
23 changes: 2 additions & 21 deletions ios/web/web_state/web_state_impl.h
Expand Up @@ -106,13 +106,6 @@ class WebStateImpl final : public WebState {
// Notifies the observers that the render process was terminated.
void OnRenderProcessGone();

// Called when a script command is received.
void OnScriptCommandReceived(const std::string& command,
const base::Value& value,
const GURL& page_url,
bool user_is_interacting,
WebFrame* sender_frame);

// Marks the WebState as loading/not loading.
void SetIsLoading(bool is_loading);

Expand Down Expand Up @@ -328,9 +321,6 @@ class WebStateImpl final : public WebState {
const GURL& GetVisibleURL() const final;
const GURL& GetLastCommittedURL() const final;
GURL GetCurrentURL(URLVerificationTrustLevel* trust_level) const final;
base::CallbackListSubscription AddScriptCommandCallback(
const ScriptCommandCallback& callback,
const std::string& command_prefix) final;
id<CRWWebViewProxy> GetWebViewProxy() const final;
void DidChangeVisibleSecurityState() final;
InterfaceBinder* GetInterfaceBinderForMainFrame() final;
Expand Down Expand Up @@ -372,17 +362,13 @@ class WebStateImpl final : public WebState {
class RealizedWebState;
class SerializedData;

// Type aliases for the various ObserverList or ScriptCommandCallback map
// used by WebStateImpl (those are reused by the RealizedWebState class).
// Type aliases for the various ObserverList map used by WebStateImpl (reused
// by the RealizedWebState class).
using WebStateObserverList = base::ObserverList<WebStateObserver, true>;

using WebStatePolicyDeciderList =
base::ObserverList<WebStatePolicyDecider, true>;

using ScriptCommandCallbackMap =
std::map<std::string,
base::RepeatingCallbackList<ScriptCommandCallbackSignature>>;

// Force the WebState to become realized (if in "unrealized" state) and
// then return a pointer to the RealizedWebState. Safe to call if the
// WebState is already realized.
Expand All @@ -404,11 +390,6 @@ class WebStateImpl final : public WebState {
// allow adding policy decider to an "unrealized" WebState.
WebStatePolicyDeciderList policy_deciders_;

// Callbacks associated to command prefixes. This is not stored in
// RealizedWebState/SerializedData to to allow registering command
// callback on an "unrealized" WebState.
ScriptCommandCallbackMap script_command_callbacks_;

// The instances of the two internal classes used to implement the
// "unrealized" state of the WebState. One important invariant is
// that except at all point either `pimpl_` or `saved_` is valid
Expand Down
19 changes: 0 additions & 19 deletions ios/web/web_state/web_state_impl.mm
Expand Up @@ -171,15 +171,6 @@ void IgnoreOverRealizationCheck() {
RealizedState()->OnRenderProcessGone();
}

void WebStateImpl::OnScriptCommandReceived(const std::string& command,
const base::Value& value,
const GURL& page_url,
bool user_is_interacting,
WebFrame* sender_frame) {
RealizedState()->OnScriptCommandReceived(command, value, page_url,
user_is_interacting, sender_frame);
}

void WebStateImpl::SetIsLoading(bool is_loading) {
RealizedState()->SetIsLoading(is_loading);
}
Expand Down Expand Up @@ -600,16 +591,6 @@ void IgnoreOverRealizationCheck() {
return LIKELY(pimpl_) ? pimpl_->GetCurrentURL(trust_level) : GURL();
}

base::CallbackListSubscription WebStateImpl::AddScriptCommandCallback(
const ScriptCommandCallback& callback,
const std::string& command_prefix) {
DCHECK(!command_prefix.empty());
DCHECK(command_prefix.find_first_of('.') == std::string::npos);
DCHECK(script_command_callbacks_.count(command_prefix) == 0 ||
script_command_callbacks_[command_prefix].empty());
return script_command_callbacks_[command_prefix].Add(callback);
}

id<CRWWebViewProxy> WebStateImpl::GetWebViewProxy() const {
return LIKELY(pimpl_) ? pimpl_->GetWebViewProxy() : nil;
}
Expand Down
10 changes: 0 additions & 10 deletions ios/web/web_state/web_state_impl_realized_web_state.h
Expand Up @@ -83,11 +83,6 @@ class WebStateImpl::RealizedWebState final : public NavigationManagerDelegate {
void OnBackForwardStateChanged();
void OnTitleChanged();
void OnRenderProcessGone();
void OnScriptCommandReceived(const std::string& command,
const base::Value& value,
const GURL& page_url,
bool user_is_interacting,
WebFrame* sender_frame);
void SetIsLoading(bool is_loading);
void OnPageLoaded(const GURL& url, bool load_success);
void OnFaviconUrlUpdated(const std::vector<FaviconURL>& candidates);
Expand Down Expand Up @@ -232,11 +227,6 @@ class WebStateImpl::RealizedWebState final : public NavigationManagerDelegate {
return owner_->policy_deciders_;
}

// Returns a reference to the owning WebState ScriptCommandCallbackMap.
ScriptCommandCallbackMap& script_command_callbacks() {
return owner_->script_command_callbacks_;
}

// Returns a new callback with the same signature as `callback` which
// will clear `running_javascript_dialog_` of the current instance (if
// it still exists) and then invoke the original callback.
Expand Down
18 changes: 0 additions & 18 deletions ios/web/web_state/web_state_impl_realized_web_state.mm
Expand Up @@ -253,24 +253,6 @@
observer.RenderProcessGone(owner_);
}

void WebStateImpl::RealizedWebState::OnScriptCommandReceived(
const std::string& command,
const base::Value& value,
const GURL& page_url,
bool user_is_interacting,
WebFrame* sender_frame) {
size_t dot_position = command.find_first_of('.');
if (dot_position == 0 || dot_position == std::string::npos)
return;

std::string prefix = command.substr(0, dot_position);
auto it = script_command_callbacks().find(prefix);
if (it == script_command_callbacks().end())
return;

it->second.Notify(value, page_url, user_is_interacting, sender_frame);
}

void WebStateImpl::RealizedWebState::SetIsLoading(bool is_loading) {
if (is_loading == is_loading_)
return;
Expand Down
5 changes: 0 additions & 5 deletions ios/web/web_state/web_state_impl_serialized_data.h
Expand Up @@ -67,11 +67,6 @@ class WebStateImpl::SerializedData {
return owner_->policy_deciders_;
}

// Returns a reference to the owning WebState ScriptCommandCallbackMap.
ScriptCommandCallbackMap& script_command_callbacks() {
return owner_->script_command_callbacks_;
}

// Returns the CRWNavigationItemStorage* corresponding to the last committed
// navigation item from the serialized state. May return nil.
CRWNavigationItemStorage* GetLastCommittedItem() const;
Expand Down

0 comments on commit d33096f

Please sign in to comment.