mirror of
https://bitbucket.org/chromiumembedded/cef
synced 2025-06-05 21:39:12 +02:00
chrome: Add ability to hide toolbar and app menu contents (see issue #3280)
This change adds new CefCommandHandler callbacks for optionally hiding specific Chrome toolbar icons, buttons and app menu items. To test: Run `cefclient --enable-chrome-runtime --filter-chrome-commands`. Most icons, buttons and app/context menu items will be hidden.
This commit is contained in:
@@ -9,6 +9,7 @@
|
||||
#include <memory>
|
||||
|
||||
#include "base/memory/scoped_refptr.h"
|
||||
#include "chrome/browser/ui/page_action/page_action_icon_type.h"
|
||||
#include "content/public/browser/web_contents_delegate.h"
|
||||
#include "ui/base/window_open_disposition.h"
|
||||
|
||||
@@ -65,6 +66,32 @@ class BrowserDelegate : public content::WebContentsDelegate {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Return true if the app menu item should be visible. ID values come from
|
||||
// chrome/app/chrome_command_ids.h.
|
||||
virtual bool IsAppMenuItemVisible(int command_id) { return true; }
|
||||
|
||||
// Return true if the app menu item should be enabled. ID values come from
|
||||
// chrome/app/chrome_command_ids.h.
|
||||
virtual bool IsAppMenuItemEnabled(int command_id) { return true; }
|
||||
|
||||
// Return true if the page action icon should be visible.
|
||||
virtual bool IsPageActionIconVisible(PageActionIconType icon_type) {
|
||||
return true;
|
||||
}
|
||||
|
||||
enum class ToolbarButtonType {
|
||||
kCast = 0,
|
||||
kDownload,
|
||||
kSendTabToSelf,
|
||||
kSidePanel,
|
||||
kMaxValue = kSidePanel,
|
||||
};
|
||||
|
||||
// Return true if the toolbar button should be visible.
|
||||
virtual bool IsToolbarButtonVisible(ToolbarButtonType button_type) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// Same as RequestMediaAccessPermission but returning |callback| if the
|
||||
// request is unhandled.
|
||||
[[nodiscard]] virtual content::MediaResponseCallback
|
||||
|
@@ -122,6 +122,60 @@ bool ChromeBrowserDelegate::HandleCommand(int command_id,
|
||||
return false;
|
||||
}
|
||||
|
||||
bool ChromeBrowserDelegate::IsAppMenuItemVisible(int command_id) {
|
||||
if (auto browser = ChromeBrowserHostImpl::GetBrowserForBrowser(browser_)) {
|
||||
if (auto client = browser->GetClient()) {
|
||||
if (auto handler = client->GetCommandHandler()) {
|
||||
return handler->IsChromeAppMenuItemVisible(browser.get(), command_id);
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool ChromeBrowserDelegate::IsAppMenuItemEnabled(int command_id) {
|
||||
if (auto browser = ChromeBrowserHostImpl::GetBrowserForBrowser(browser_)) {
|
||||
if (auto client = browser->GetClient()) {
|
||||
if (auto handler = client->GetCommandHandler()) {
|
||||
return handler->IsChromeAppMenuItemEnabled(browser.get(), command_id);
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool ChromeBrowserDelegate::IsPageActionIconVisible(
|
||||
PageActionIconType icon_type) {
|
||||
// Verify that our enum matches Chromium's values.
|
||||
static_assert(static_cast<int>(CEF_CPAIT_MAX_VALUE) ==
|
||||
static_cast<int>(PageActionIconType::kMaxValue),
|
||||
"enum mismatch");
|
||||
|
||||
if (auto client = create_params_.client) {
|
||||
if (auto handler = client->GetCommandHandler()) {
|
||||
return handler->IsChromePageActionIconVisible(
|
||||
static_cast<cef_chrome_page_action_icon_type_t>(icon_type));
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool ChromeBrowserDelegate::IsToolbarButtonVisible(
|
||||
ToolbarButtonType button_type) {
|
||||
// Verify that our enum matches BrowserDelegate's values.
|
||||
static_assert(static_cast<int>(CEF_CTBT_MAX_VALUE) ==
|
||||
static_cast<int>(ToolbarButtonType::kMaxValue),
|
||||
"enum mismatch");
|
||||
|
||||
if (auto client = create_params_.client) {
|
||||
if (auto handler = client->GetCommandHandler()) {
|
||||
return handler->IsChromeToolbarButtonVisible(
|
||||
static_cast<cef_chrome_toolbar_button_type_t>(button_type));
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
content::MediaResponseCallback
|
||||
ChromeBrowserDelegate::RequestMediaAccessPermissionEx(
|
||||
content::WebContents* web_contents,
|
||||
|
@@ -56,6 +56,10 @@ class ChromeBrowserDelegate : public cef::BrowserDelegate {
|
||||
bool ShowStatusBubble(bool show_by_default) override;
|
||||
bool HandleCommand(int command_id,
|
||||
WindowOpenDisposition disposition) override;
|
||||
bool IsAppMenuItemVisible(int command_id) override;
|
||||
bool IsAppMenuItemEnabled(int command_id) override;
|
||||
bool IsPageActionIconVisible(PageActionIconType icon_type) override;
|
||||
bool IsToolbarButtonVisible(ToolbarButtonType button_type) override;
|
||||
[[nodiscard]] content::MediaResponseCallback RequestMediaAccessPermissionEx(
|
||||
content::WebContents* web_contents,
|
||||
const content::MediaStreamRequest& request,
|
||||
|
Reference in New Issue
Block a user