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 @@
UserActionsUIHandler::UserActionsUIHandler()
: action_callback_(base::Bind(&UserActionsUIHandler::OnUserAction,
base::Unretained(this))) {
base::AddActionCallback(action_callback_);
}
base::Unretained(this))) {}
UserActionsUIHandler::~UserActionsUIHandler() {
WebContentsObserver::Observe(nullptr);
base::RemoveActionCallback(action_callback_);
}
void UserActionsUIHandler::RegisterMessages() {
WebContentsObserver::Observe(web_ui()->GetWebContents());
web_ui()->RegisterMessageCallback(
"pageLoaded", base::BindRepeating(&UserActionsUIHandler::HandlePageLoaded,
base::Unretained(this)));
}
void UserActionsUIHandler::ReadyToCommitNavigation(
content::NavigationHandle* navigation_handle) {
void UserActionsUIHandler::HandlePageLoaded(const base::ListValue* args) {
AllowJavascript();
}
void UserActionsUIHandler::OnJavascriptAllowed() {
base::AddActionCallback(action_callback_);
}
void UserActionsUIHandler::OnJavascriptDisallowed() {
base::RemoveActionCallback(action_callback_);
}
void UserActionsUIHandler::OnUserAction(const std::string& action,
base::TimeTicks action_time) {
if (!IsJavascriptAllowed())
......
......@@ -7,31 +7,28 @@
#include "base/macros.h"
#include "base/metrics/user_metrics.h"
#include "content/public/browser/web_contents_observer.h"
#include "content/public/browser/web_ui_message_handler.h"
namespace base {
class ListValue;
class TimeTicks;
} // namespace base
// UI Handler for chrome://user-actions/
// It listens to user action notifications and passes those notifications
// into the Javascript to update the page.
class UserActionsUIHandler : public content::WebUIMessageHandler,
public content::WebContentsObserver {
class UserActionsUIHandler : public content::WebUIMessageHandler {
public:
UserActionsUIHandler();
~UserActionsUIHandler() override;
// WebUIMessageHandler implementation:
// Does nothing for now.
void RegisterMessages() override;
// WebContentsObserver::
void ReadyToCommitNavigation(
content::NavigationHandle* navigation_handle) override;
void OnJavascriptAllowed() override;
void OnJavascriptDisallowed() override;
private:
void HandlePageLoaded(const base::ListValue* args);
void OnUserAction(const std::string& action, base::TimeTicks action_time);
base::ActionCallback action_callback_;
......
......@@ -34,3 +34,7 @@ cr.define('userActions', function() {
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