Skip to content

Commit

Permalink
Layout
Browse files Browse the repository at this point in the history
Working modifiers

WIP command info

Scaffholding webui

Maybe get things set up for webui

Loading okay

WIP

Display shortcuts

Add filtering

Use util

Filter out non-accelerated

Show more keycodes

Add more keys

More key names

Deps fixes

Name cleanup

shortcuts ==> commands

Search by shortcut

Try execute

Execution cleanup

Improve filtering

Add confirm prompt

Add feature

Don't add webui unless flag is set

WIP

WIP command cleanup

Presubmit

Add more commands

Add BrowserTest

Includes

Cleanup for PR
  • Loading branch information
fallaciousreasoning committed Feb 7, 2023
1 parent 9ad65b7 commit f2b5a87
Show file tree
Hide file tree
Showing 36 changed files with 1,171 additions and 11 deletions.
10 changes: 9 additions & 1 deletion app/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,15 @@ import("//build/config/features.gni")
import("//build/config/locales.gni")

source_set("command_ids") {
sources = [ "brave_command_ids.h" ]
sources = [
"brave_command_ids.h",
"command_utils.cc",
"command_utils.h",
]
deps = [
"//base",
"//chrome/app:command_ids",
]
}

brave_grit("brave_generated_resources_grit") {
Expand Down
216 changes: 216 additions & 0 deletions app/command_utils.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,216 @@
// Copyright (c) 2023 The Brave Authors. All rights reserved.
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this file,
// You can obtain one at https://mozilla.org/MPL/2.0/.

#include "brave/app/command_utils.h"

#include <map>
#include <string>
#include <vector>

#include "base/strings/string_split.h"
#include "base/strings/string_util.h"
#include "brave/app/brave_command_ids.h"
#include "chrome/app/chrome_command_ids.h"

namespace commands {
namespace {
std::string GetName(std::string raw_name) {
auto words = base::SplitString(raw_name, "_", base::TRIM_WHITESPACE,
base::SPLIT_WANT_NONEMPTY);
for (auto& word : words) {
if (word.size() == 1) {
continue;
}
word = word[0] + base::ToLowerASCII(word.substr(1));
}
return base::JoinString(words, " ");
}

} // namespace

std::map<uint16_t, std::string> GetCommandInfo() {
static const std::map<uint16_t, std::string> kCommands {
// Navigation commands.
ADD_UNTRANSLATED_COMMAND(BACK), ADD_UNTRANSLATED_COMMAND(FORWARD),
ADD_UNTRANSLATED_COMMAND(RELOAD),
ADD_UNTRANSLATED_COMMAND(RELOAD_BYPASSING_CACHE),
ADD_UNTRANSLATED_COMMAND(RELOAD_CLEARING_CACHE),
ADD_UNTRANSLATED_COMMAND(HOME), ADD_UNTRANSLATED_COMMAND(STOP),

// Window management commands
ADD_UNTRANSLATED_COMMAND(NEW_WINDOW),
ADD_UNTRANSLATED_COMMAND(NEW_INCOGNITO_WINDOW),
ADD_UNTRANSLATED_COMMAND(CLOSE_WINDOW),
ADD_UNTRANSLATED_COMMAND(NEW_TAB), ADD_UNTRANSLATED_COMMAND(CLOSE_TAB),
ADD_UNTRANSLATED_COMMAND(SELECT_NEXT_TAB),
ADD_UNTRANSLATED_COMMAND(SELECT_PREVIOUS_TAB),
ADD_UNTRANSLATED_COMMAND(SELECT_TAB_0),
ADD_UNTRANSLATED_COMMAND(SELECT_TAB_1),
ADD_UNTRANSLATED_COMMAND(SELECT_TAB_2),
ADD_UNTRANSLATED_COMMAND(SELECT_TAB_3),
ADD_UNTRANSLATED_COMMAND(SELECT_TAB_4),
ADD_UNTRANSLATED_COMMAND(SELECT_TAB_5),
ADD_UNTRANSLATED_COMMAND(SELECT_TAB_6),
ADD_UNTRANSLATED_COMMAND(SELECT_TAB_7),
ADD_UNTRANSLATED_COMMAND(SELECT_LAST_TAB),
ADD_UNTRANSLATED_COMMAND(MOVE_TAB_TO_NEW_WINDOW),
ADD_UNTRANSLATED_COMMAND(DUPLICATE_TAB),
ADD_UNTRANSLATED_COMMAND(RESTORE_TAB),
ADD_UNTRANSLATED_COMMAND(FULLSCREEN), ADD_UNTRANSLATED_COMMAND(EXIT),
ADD_UNTRANSLATED_COMMAND(MOVE_TAB_NEXT),
ADD_UNTRANSLATED_COMMAND(MOVE_TAB_PREVIOUS),
ADD_UNTRANSLATED_COMMAND(SEARCH),
ADD_UNTRANSLATED_COMMAND(DEBUG_FRAME_TOGGLE),
ADD_UNTRANSLATED_COMMAND(WINDOW_MENU),
ADD_UNTRANSLATED_COMMAND(MINIMIZE_WINDOW),
ADD_UNTRANSLATED_COMMAND(MAXIMIZE_WINDOW),
ADD_UNTRANSLATED_COMMAND(NAME_WINDOW),
ADD_UNTRANSLATED_COMMAND(RESTORE_WINDOW),

#if BUILDFLAG(IS_LINUX)
ADD_UNTRANSLATED_COMMAND(USE_SYSTEM_TITLE_BAR),
#endif

// Web app window commands
ADD_UNTRANSLATED_COMMAND(OPEN_IN_PWA_WINDOW),
ADD_UNTRANSLATED_COMMAND(COPY_URL),
ADD_UNTRANSLATED_COMMAND(SITE_SETTINGS),
ADD_UNTRANSLATED_COMMAND(WEB_APP_MENU_APP_INFO),

// Page related commands
ADD_UNTRANSLATED_COMMAND(BOOKMARK_THIS_TAB),
ADD_UNTRANSLATED_COMMAND(BOOKMARK_ALL_TABS),
ADD_UNTRANSLATED_COMMAND(VIEW_SOURCE), ADD_UNTRANSLATED_COMMAND(PRINT),
ADD_UNTRANSLATED_COMMAND(SAVE_PAGE),
ADD_UNTRANSLATED_COMMAND(EMAIL_PAGE_LOCATION),
ADD_UNTRANSLATED_COMMAND(BASIC_PRINT),
ADD_UNTRANSLATED_COMMAND(TRANSLATE_PAGE),
ADD_UNTRANSLATED_COMMAND(WINDOW_MUTE_SITE),
ADD_UNTRANSLATED_COMMAND(WINDOW_PIN_TAB),
ADD_UNTRANSLATED_COMMAND(WINDOW_GROUP_TAB),
ADD_UNTRANSLATED_COMMAND(QRCODE_GENERATOR),
ADD_UNTRANSLATED_COMMAND(WINDOW_CLOSE_TABS_TO_RIGHT),
ADD_UNTRANSLATED_COMMAND(WINDOW_CLOSE_OTHER_TABS),
ADD_UNTRANSLATED_COMMAND(NEW_TAB_TO_RIGHT),

// Page manipulation for specific tab
ADD_UNTRANSLATED_COMMAND(MUTE_TARGET_SITE),
ADD_UNTRANSLATED_COMMAND(PIN_TARGET_TAB),
ADD_UNTRANSLATED_COMMAND(GROUP_TARGET_TAB),
ADD_UNTRANSLATED_COMMAND(DUPLICATE_TARGET_TAB),

// Edit
ADD_UNTRANSLATED_COMMAND(CUT), ADD_UNTRANSLATED_COMMAND(COPY),
ADD_UNTRANSLATED_COMMAND(PASTE), ADD_UNTRANSLATED_COMMAND(EDIT_MENU),

// Find
ADD_UNTRANSLATED_COMMAND(FIND), ADD_UNTRANSLATED_COMMAND(FIND_NEXT),
ADD_UNTRANSLATED_COMMAND(FIND_PREVIOUS),
ADD_UNTRANSLATED_COMMAND(CLOSE_FIND_OR_STOP),

// Zoom
ADD_UNTRANSLATED_COMMAND(ZOOM_MENU),
ADD_UNTRANSLATED_COMMAND(ZOOM_PLUS),
ADD_UNTRANSLATED_COMMAND(ZOOM_NORMAL),
ADD_UNTRANSLATED_COMMAND(ZOOM_MINUS),
ADD_UNTRANSLATED_COMMAND(ZOOM_PERCENT_DISPLAY),

// Focus
ADD_UNTRANSLATED_COMMAND(FOCUS_TOOLBAR),
ADD_UNTRANSLATED_COMMAND(FOCUS_LOCATION),
ADD_UNTRANSLATED_COMMAND(FOCUS_SEARCH),
ADD_UNTRANSLATED_COMMAND(FOCUS_MENU_BAR),
ADD_UNTRANSLATED_COMMAND(FOCUS_NEXT_PANE),
ADD_UNTRANSLATED_COMMAND(FOCUS_PREVIOUS_PANE),
ADD_UNTRANSLATED_COMMAND(FOCUS_BOOKMARKS),
ADD_UNTRANSLATED_COMMAND(FOCUS_INACTIVE_POPUP_FOR_ACCESSIBILITY),
ADD_UNTRANSLATED_COMMAND(FOCUS_WEB_CONTENTS_PANE),

// UI bits
ADD_UNTRANSLATED_COMMAND(OPEN_FILE),
ADD_UNTRANSLATED_COMMAND(CREATE_SHORTCUT),
ADD_UNTRANSLATED_COMMAND(DEVELOPER_MENU),
ADD_UNTRANSLATED_COMMAND(DEV_TOOLS),
ADD_UNTRANSLATED_COMMAND(DEV_TOOLS_CONSOLE),
ADD_UNTRANSLATED_COMMAND(TASK_MANAGER),
ADD_UNTRANSLATED_COMMAND(DEV_TOOLS_DEVICES),
ADD_UNTRANSLATED_COMMAND(FEEDBACK),
ADD_UNTRANSLATED_COMMAND(SHOW_BOOKMARK_BAR),
ADD_UNTRANSLATED_COMMAND(SHOW_HISTORY),
ADD_UNTRANSLATED_COMMAND(SHOW_BOOKMARK_MANAGER),
ADD_UNTRANSLATED_COMMAND(SHOW_DOWNLOADS),
ADD_UNTRANSLATED_COMMAND(CLEAR_BROWSING_DATA),
ADD_UNTRANSLATED_COMMAND(IMPORT_SETTINGS),
ADD_UNTRANSLATED_COMMAND(OPTIONS),
ADD_UNTRANSLATED_COMMAND(EDIT_SEARCH_ENGINES),
ADD_UNTRANSLATED_COMMAND(VIEW_PASSWORDS),
ADD_UNTRANSLATED_COMMAND(ABOUT),
ADD_UNTRANSLATED_COMMAND(HELP_PAGE_VIA_KEYBOARD),
ADD_UNTRANSLATED_COMMAND(SHOW_APP_MENU),
ADD_UNTRANSLATED_COMMAND(MANAGE_EXTENSIONS),
ADD_UNTRANSLATED_COMMAND(DEV_TOOLS_INSPECT),
ADD_UNTRANSLATED_COMMAND(BOOKMARKS_MENU),
ADD_UNTRANSLATED_COMMAND(SHOW_AVATAR_MENU),
ADD_UNTRANSLATED_COMMAND(TOGGLE_REQUEST_TABLET_SITE),
ADD_UNTRANSLATED_COMMAND(DEV_TOOLS_TOGGLE),
ADD_UNTRANSLATED_COMMAND(TAKE_SCREENSHOT),
ADD_UNTRANSLATED_COMMAND(TOGGLE_FULLSCREEN_TOOLBAR),
ADD_UNTRANSLATED_COMMAND(INSTALL_PWA),
ADD_UNTRANSLATED_COMMAND(PASTE_AND_GO),
ADD_UNTRANSLATED_COMMAND(SHOW_FULL_URLS),
ADD_UNTRANSLATED_COMMAND(CARET_BROWSING_TOGGLE),
ADD_UNTRANSLATED_COMMAND(TOGGLE_QUICK_COMMANDS),

// Media
ADD_UNTRANSLATED_COMMAND(CONTENT_CONTEXT_PLAYPAUSE),
ADD_UNTRANSLATED_COMMAND(CONTENT_CONTEXT_MUTE),
ADD_UNTRANSLATED_COMMAND(CONTENT_CONTEXT_LOOP),
ADD_UNTRANSLATED_COMMAND(CONTENT_CONTEXT_CONTROLS),

#if BUILDFLAG(ENABLE_SCREEN_AI_SERVICE)
// Screen AI Visual Annotations.
ADD_UNTRANSLATED_COMMAND(RUN_SCREEN_AI_VISUAL_ANNOTATIONS),
#endif

// Tab search
ADD_UNTRANSLATED_COMMAND(TAB_SEARCH),
ADD_UNTRANSLATED_COMMAND(TAB_SEARCH_CLOSE),

// Brave Commands
ADD_UNTRANSLATED_COMMAND(SHOW_BRAVE_REWARDS),
ADD_UNTRANSLATED_COMMAND(NEW_TOR_CONNECTION_FOR_SITE),
ADD_UNTRANSLATED_COMMAND(NEW_OFFTHERECORD_WINDOW_TOR),
ADD_UNTRANSLATED_COMMAND(SHOW_BRAVE_SYNC),
ADD_UNTRANSLATED_COMMAND(SHOW_BRAVE_WALLET),
ADD_UNTRANSLATED_COMMAND(ADD_NEW_PROFILE),
ADD_UNTRANSLATED_COMMAND(OPEN_GUEST_PROFILE),
ADD_UNTRANSLATED_COMMAND(SHOW_BRAVE_WALLET_PANEL),
ADD_UNTRANSLATED_COMMAND(SHOW_BRAVE_VPN_PANEL),
ADD_UNTRANSLATED_COMMAND(TOGGLE_BRAVE_VPN_TOOLBAR_BUTTON),
ADD_UNTRANSLATED_COMMAND(MANAGE_BRAVE_VPN_PLAN),
ADD_UNTRANSLATED_COMMAND(TOGGLE_BRAVE_VPN),
ADD_UNTRANSLATED_COMMAND(COPY_CLEAN_LINK),
ADD_UNTRANSLATED_COMMAND(SIDEBAR_TOGGLE_POSITION),
ADD_UNTRANSLATED_COMMAND(TOGGLE_TAB_MUTE)
};
return kCommands;
}

std::vector<uint16_t> GetCommands() {
const auto& info = GetCommandInfo();
std::vector<uint16_t> result;
for (const auto& [id, _] : info) {
result.push_back(id);
}
return result;
}

std::string GetCommandName(int command_id) {
const auto& info = GetCommandInfo();
auto it = info.find(command_id);
CHECK(it != info.end());
return it->second;
}
} // namespace commands
25 changes: 25 additions & 0 deletions app/command_utils.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// Copyright (c) 2023 The Brave Authors. All rights reserved.
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this file,
// You can obtain one at https://mozilla.org/MPL/2.0/.

#ifndef BRAVE_APP_COMMAND_UTILS_H_
#define BRAVE_APP_COMMAND_UTILS_H_

#include <string>
#include <vector>

#define ADD_UNTRANSLATED_COMMAND(name) \
{ \
IDC_##name, { \
GetName(#name) \
} \
}

namespace commands {

std::vector<uint16_t> GetCommands();
std::string GetCommandName(int command_id);
} // namespace commands

#endif // BRAVE_APP_COMMAND_UTILS_H_
35 changes: 35 additions & 0 deletions app/command_utils_browsertest.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// Copyright (c) 2023 The Brave Authors. All rights reserved.
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this file,
// You can obtain one at https://mozilla.org/MPL/2.0/.

#include "brave/app/command_utils.h"

#include "base/test/scoped_feature_list.h"
#include "brave/components/commands/common/features.h"
#include "chrome/browser/ui/browser_commands.h"
#include "chrome/test/base/in_process_browser_test.h"
#include "chrome/test/base/ui_test_utils.h"
#include "content/public/test/browser_test.h"

class CommandUtilsBrowserTest : public InProcessBrowserTest {
public:
void SetUp() override {
features_.InitAndEnableFeature(commands::features::kBraveCommandsFeature);
InProcessBrowserTest::SetUp();
}

private:
base::test::ScopedFeatureList features_;
};

IN_PROC_BROWSER_TEST_F(CommandUtilsBrowserTest,
AllCommandsShouldBeExecutableWithoutCrash) {
ASSERT_TRUE(ui_test_utils::NavigateToURL(browser(), GURL("chrome://newtab")));
auto commands = commands::GetCommands();
for (const auto& command : commands) {
LOG(ERROR) << "Executing command: " << commands::GetCommandName(command);
chrome::ExecuteCommand(browser(), command);
LOG(ERROR) << "Executed!";
}
}
24 changes: 24 additions & 0 deletions app/command_utils_unittest.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// Copyright (c) 2023 The Brave Authors. All rights reserved.
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this file,
// You can obtain one at https://mozilla.org/MPL/2.0/.

#include "brave/app/command_utils.h"

#include "base/ranges/algorithm.h"
#include "chrome/browser/ui/views/accelerator_table.h"
#include "gtest/gtest.h"

// Note: If this test fails because an accelerated command isn't present just
// add the missing command to |commands::GetCommandInfo| in command_utils.h.
TEST(CommandUtilsUnitTest, AllAcceleratedCommandsShouldBeAvailable) {
auto accelerators = GetAcceleratorList();
auto commands = commands::GetCommands();

for (const auto& accelerator : accelerators) {
EXPECT_NE(base::ranges::find(commands, accelerator.command_id),
commands.end())
<< "Accelerated command '" << accelerator.command_id
<< "' was not present in the list of commands.";
}
}
13 changes: 13 additions & 0 deletions browser/about_flags.cc
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include "brave/components/brave_today/common/features.h"
#include "brave/components/brave_vpn/common/buildflags/buildflags.h"
#include "brave/components/brave_wallet/common/features.h"
#include "brave/components/commands/common/features.h"
#include "brave/components/de_amp/common/features.h"
#include "brave/components/debounce/common/features.h"
#include "brave/components/google_sign_in_permission/features.h"
Expand Down Expand Up @@ -208,6 +209,10 @@ constexpr char kBraveBlockScreenFingerprintingDescription[] =
"Prevents JavaScript and CSS from learning the user's screen dimensions "
"or window position.";

constexpr char kBraveCommandsName[] = "Brave Commands";
constexpr char kBraveCommandsDescription[] =
"Enable experimental page for viewing and executing commands in Brave";

constexpr char kBraveTorWindowsHttpsOnlyName[] =
"Use HTTPS-Only Mode in Private Windows with Tor";
constexpr char kBraveTorWindowsHttpsOnlyDescription[] =
Expand Down Expand Up @@ -611,6 +616,13 @@ constexpr char kRestrictEventSourcePoolDescription[] =
#define PLAYLIST_FEATURE_ENTRIES
#endif

#define BRAVE_COMMANDS_FEATURE_ENTRIES \
{"brave-commands", \
flag_descriptions::kBraveCommandsName, \
flag_descriptions::kBraveCommandsDescription, \
kOsDesktop, \
FEATURE_VALUE_TYPE(commands::features::kBraveCommandsFeature)},

#if defined(TOOLKIT_VIEWS)
#define BRAVE_VERTICAL_TABS_FEATURE_ENTRY \
{"brave-vertical-tabs", \
Expand Down Expand Up @@ -840,6 +852,7 @@ constexpr char kRestrictEventSourcePoolDescription[] =
SPEEDREADER_FEATURE_ENTRIES \
BRAVE_FEDERATED_FEATURE_ENTRIES \
PLAYLIST_FEATURE_ENTRIES \
BRAVE_COMMANDS_FEATURE_ENTRIES \
BRAVE_VERTICAL_TABS_FEATURE_ENTRY \
BRAVE_BACKGROUND_VIDEO_PLAYBACK_ANDROID \
BRAVE_SAFE_BROWSING_ANDROID \
Expand Down
7 changes: 7 additions & 0 deletions browser/brave_content_browser_client.cc
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
#include "brave/browser/profiles/brave_renderer_updater_factory.h"
#include "brave/browser/profiles/profile_util.h"
#include "brave/browser/skus/skus_service_factory.h"
#include "brave/browser/ui/webui/commands_ui.h"
#include "brave/components/brave_ads/common/features.h"
#include "brave/components/brave_federated/features.h"
#include "brave/components/brave_rewards/browser/rewards_protocol_handler.h"
Expand All @@ -56,6 +57,8 @@
#include "brave/components/brave_wallet/browser/solana_provider_impl.h"
#include "brave/components/brave_wallet/common/brave_wallet.mojom.h"
#include "brave/components/brave_webtorrent/browser/buildflags/buildflags.h"
#include "brave/components/commands/common/commands.mojom.h"
#include "brave/components/commands/common/features.h"
#include "brave/components/constants/pref_names.h"
#include "brave/components/constants/webui_url_constants.h"
#include "brave/components/cosmetic_filters/browser/cosmetic_filters_resources.h"
Expand Down Expand Up @@ -481,6 +484,10 @@ void BraveContentBrowserClient::RegisterWebUIInterfaceBrokers(
.Add<playlist::mojom::PageHandlerFactory>();
}
#endif

if (base::FeatureList::IsEnabled(commands::features::kBraveCommandsFeature)) {
registry.ForWebUI<commands::CommandsUI>().Add<CommandsService>();
}
}

bool BraveContentBrowserClient::AllowWorkerFingerprinting(
Expand Down
1 change: 1 addition & 0 deletions browser/sources.gni
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ brave_chrome_browser_deps = [
"//brave/components/brave_wallet/common:mojom",
"//brave/components/brave_wayback_machine/buildflags",
"//brave/components/brave_webtorrent/browser/buildflags",
"//brave/components/commands/browser",
"//brave/components/constants",
"//brave/components/cosmetic_filters/browser",
"//brave/components/cosmetic_filters/common:mojom",
Expand Down
Loading

0 comments on commit f2b5a87

Please sign in to comment.