Commit b08d9ec0 authored by Yuheng Huang's avatar Yuheng Huang Committed by Commit Bot

Devtools protocol: Implement browser.executeBrowserCommand to support invoking Tab Search UI

Right now there's no easy way to invoke a native UI in the browser using
devtools protocol. The API provides a way to open/close UI, particularly
Tab Search UI. It's mainly used for telemetry based performance tests.

Related CL:

Doc: https://docs.google.com/document/d/1-1ijT7wt05hlBZmSKjX_DaTCzVqpxbfTM1y-j7kYHlc
https: //chromium-review.googlesource.com/c/catapult/+/2488841
Bug: 1099917
Change-Id: Id87c9eb6f66c05278fdf722562ba8794e466d8e3
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2488764
Commit-Queue: Yuheng Huang <yuhengh@chromium.org>
Reviewed-by: default avatarAndrey Kosyakov <caseq@chromium.org>
Cr-Commit-Position: refs/heads/master@{#820099}
parent 2decd986
...@@ -14,7 +14,7 @@ ...@@ -14,7 +14,7 @@
}, },
{ {
"domain": "Browser", "domain": "Browser",
"include": [ "getWindowForTarget", "getWindowBounds", "setWindowBounds", "close", "setDockTile" ], "include": [ "getWindowForTarget", "getWindowBounds", "setWindowBounds", "close", "setDockTile", "executeBrowserCommand" ],
"include_events": [] "include_events": []
}, },
{ {
......
...@@ -9,9 +9,11 @@ ...@@ -9,9 +9,11 @@
#include "base/bind.h" #include "base/bind.h"
#include "base/memory/ref_counted_memory.h" #include "base/memory/ref_counted_memory.h"
#include "chrome/app/chrome_command_ids.h"
#include "chrome/browser/devtools/chrome_devtools_manager_delegate.h" #include "chrome/browser/devtools/chrome_devtools_manager_delegate.h"
#include "chrome/browser/devtools/devtools_dock_tile.h" #include "chrome/browser/devtools/devtools_dock_tile.h"
#include "chrome/browser/lifetime/application_lifetime.h" #include "chrome/browser/lifetime/application_lifetime.h"
#include "chrome/browser/ui/browser_commands.h"
#include "chrome/browser/ui/browser_list.h" #include "chrome/browser/ui/browser_list.h"
#include "chrome/browser/ui/browser_window.h" #include "chrome/browser/ui/browser_window.h"
#include "chrome/browser/ui/exclusive_access/exclusive_access_context.h" #include "chrome/browser/ui/exclusive_access/exclusive_access_context.h"
...@@ -192,3 +194,20 @@ protocol::Response BrowserHandler::SetDockTile( ...@@ -192,3 +194,20 @@ protocol::Response BrowserHandler::SetDockTile(
!reps.empty() ? gfx::Image(reps) : gfx::Image()); !reps.empty() ? gfx::Image(reps) : gfx::Image());
return Response::Success(); return Response::Success();
} }
protocol::Response BrowserHandler::ExecuteBrowserCommand(
const protocol::Browser::BrowserCommandId& command_id) {
static auto& command_id_map =
*new std::map<protocol::Browser::BrowserCommandId, int>{
{protocol::Browser::BrowserCommandIdEnum::OpenTabSearch,
IDC_TAB_SEARCH}};
if (command_id_map.count(command_id) == 0) {
return Response::InvalidParams("Invalid BrowserCommandId: " + command_id);
}
if (!chrome::ExecuteCommand(BrowserList::GetInstance()->GetLastActive(),
command_id_map[command_id])) {
return Response::InvalidRequest(
"Browser command not supported. BrowserCommandId: " + command_id);
}
return Response::Success();
}
...@@ -29,6 +29,8 @@ class BrowserHandler : public protocol::Browser::Backend { ...@@ -29,6 +29,8 @@ class BrowserHandler : public protocol::Browser::Backend {
protocol::Response SetDockTile( protocol::Response SetDockTile(
protocol::Maybe<std::string> label, protocol::Maybe<std::string> label,
protocol::Maybe<protocol::Binary> image) override; protocol::Maybe<protocol::Binary> image) override;
protocol::Response ExecuteBrowserCommand(
const protocol::Browser::BrowserCommandId& command_id) override;
private: private:
base::flat_set<std::string> contexts_with_overridden_permissions_; base::flat_set<std::string> contexts_with_overridden_permissions_;
......
...@@ -855,6 +855,11 @@ domain Browser ...@@ -855,6 +855,11 @@ domain Browser
# For "camera" permission, may specify panTiltZoom. # For "camera" permission, may specify panTiltZoom.
optional boolean panTiltZoom optional boolean panTiltZoom
# Browser command ids used by executeBrowserCommand.
experimental type BrowserCommandId extends string
enum
openTabSearch
# Set permission settings for given origin. # Set permission settings for given origin.
experimental command setPermission experimental command setPermission
parameters parameters
...@@ -1014,6 +1019,11 @@ domain Browser ...@@ -1014,6 +1019,11 @@ domain Browser
# Png encoded image. # Png encoded image.
optional binary image optional binary image
# Invoke custom browser commands used by telemetry.
experimental command executeBrowserCommand
parameters
BrowserCommandId commandId
# This domain exposes CSS read/write operations. All CSS objects (stylesheets, rules, and styles) # This domain exposes CSS read/write operations. All CSS objects (stylesheets, rules, and styles)
# have an associated `id` used in subsequent operations on the related object. Each object type has # have an associated `id` used in subsequent operations on the related object. Each object type has
# a specific `id` structure, and those are not interchangeable between objects of different kinds. # a specific `id` structure, and those are not interchangeable between objects of different kinds.
......
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