Commit 80b5a6ea authored by Miyoung Shin's avatar Miyoung Shin Committed by Commit Bot

Fix regression at chrome://user-actions

This fixes a regression of https://crrev.com/c/2335213 that the user
actions isn't recorded at chrome://user-actions since Javascript is
disallowed in
WebUIImpl::MainFrameNavigationObserver::DidFinishNavigation after
it is allowed in UserActionsUIHandler::ReadyToCommitNavigation.

This CL registers a message called when the page is loaded to allow
the JavaScript and adds the user action callback in OnJavascriptAllowed
instead of ctor not to access RenderFrameHost too early.

Bug: 1122791
Change-Id: I285d62b8fb15ff388c1183e63047efe93705390d
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2387900Reviewed-by: default avatarTommy Li <tommycli@chromium.org>
Commit-Queue: Miyoung Shin <myid.shin@igalia.com>
Cr-Commit-Position: refs/heads/master@{#805183}
parent d4fc79f0
...@@ -11,24 +11,30 @@ ...@@ -11,24 +11,30 @@
UserActionsUIHandler::UserActionsUIHandler() UserActionsUIHandler::UserActionsUIHandler()
: action_callback_(base::Bind(&UserActionsUIHandler::OnUserAction, : action_callback_(base::Bind(&UserActionsUIHandler::OnUserAction,
base::Unretained(this))) { base::Unretained(this))) {}
base::AddActionCallback(action_callback_);
}
UserActionsUIHandler::~UserActionsUIHandler() { UserActionsUIHandler::~UserActionsUIHandler() {
WebContentsObserver::Observe(nullptr);
base::RemoveActionCallback(action_callback_); base::RemoveActionCallback(action_callback_);
} }
void UserActionsUIHandler::RegisterMessages() { void UserActionsUIHandler::RegisterMessages() {
WebContentsObserver::Observe(web_ui()->GetWebContents()); web_ui()->RegisterMessageCallback(
"pageLoaded", base::BindRepeating(&UserActionsUIHandler::HandlePageLoaded,
base::Unretained(this)));
} }
void UserActionsUIHandler::ReadyToCommitNavigation( void UserActionsUIHandler::HandlePageLoaded(const base::ListValue* args) {
content::NavigationHandle* navigation_handle) {
AllowJavascript(); AllowJavascript();
} }
void UserActionsUIHandler::OnJavascriptAllowed() {
base::AddActionCallback(action_callback_);
}
void UserActionsUIHandler::OnJavascriptDisallowed() {
base::RemoveActionCallback(action_callback_);
}
void UserActionsUIHandler::OnUserAction(const std::string& action, void UserActionsUIHandler::OnUserAction(const std::string& action,
base::TimeTicks action_time) { base::TimeTicks action_time) {
if (!IsJavascriptAllowed()) if (!IsJavascriptAllowed())
......
...@@ -7,31 +7,28 @@ ...@@ -7,31 +7,28 @@
#include "base/macros.h" #include "base/macros.h"
#include "base/metrics/user_metrics.h" #include "base/metrics/user_metrics.h"
#include "content/public/browser/web_contents_observer.h"
#include "content/public/browser/web_ui_message_handler.h" #include "content/public/browser/web_ui_message_handler.h"
namespace base { namespace base {
class ListValue;
class TimeTicks; class TimeTicks;
} // namespace base } // namespace base
// UI Handler for chrome://user-actions/ // UI Handler for chrome://user-actions/
// It listens to user action notifications and passes those notifications // It listens to user action notifications and passes those notifications
// into the Javascript to update the page. // into the Javascript to update the page.
class UserActionsUIHandler : public content::WebUIMessageHandler, class UserActionsUIHandler : public content::WebUIMessageHandler {
public content::WebContentsObserver {
public: public:
UserActionsUIHandler(); UserActionsUIHandler();
~UserActionsUIHandler() override; ~UserActionsUIHandler() override;
// WebUIMessageHandler implementation: // WebUIMessageHandler implementation:
// Does nothing for now.
void RegisterMessages() override; void RegisterMessages() override;
void OnJavascriptAllowed() override;
// WebContentsObserver:: void OnJavascriptDisallowed() override;
void ReadyToCommitNavigation(
content::NavigationHandle* navigation_handle) override;
private: private:
void HandlePageLoaded(const base::ListValue* args);
void OnUserAction(const std::string& action, base::TimeTicks action_time); void OnUserAction(const std::string& action, base::TimeTicks action_time);
base::ActionCallback action_callback_; base::ActionCallback action_callback_;
......
...@@ -34,3 +34,7 @@ cr.define('userActions', function() { ...@@ -34,3 +34,7 @@ cr.define('userActions', function() {
return {observeUserAction: observeUserAction}; return {observeUserAction: observeUserAction};
}); });
document.addEventListener('DOMContentLoaded', function() {
chrome.send('pageLoaded');
});
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