fix: navigator.keyboard.lock() not working (#31572)
* fix: navigator.keyboard.lock() not working * chore: address review feedback
This commit is contained in:
parent
120cff38c5
commit
639f4428a5
6 changed files with 155 additions and 1 deletions
|
@ -26,6 +26,7 @@
|
|||
#include "base/threading/thread_task_runner_handle.h"
|
||||
#include "base/values.h"
|
||||
#include "chrome/browser/browser_process.h"
|
||||
#include "chrome/browser/ui/exclusive_access/exclusive_access_manager.h"
|
||||
#include "chrome/browser/ui/views/eye_dropper/eye_dropper.h"
|
||||
#include "chrome/common/pref_names.h"
|
||||
#include "components/prefs/pref_service.h"
|
||||
|
@ -630,6 +631,7 @@ WebContents::WebContents(v8::Isolate* isolate,
|
|||
id_(GetAllWebContents().Add(this)),
|
||||
devtools_file_system_indexer_(
|
||||
base::MakeRefCounted<DevToolsFileSystemIndexer>()),
|
||||
exclusive_access_manager_(std::make_unique<ExclusiveAccessManager>(this)),
|
||||
file_task_runner_(
|
||||
base::ThreadPool::CreateSequencedTaskRunner({base::MayBlock()}))
|
||||
#if BUILDFLAG(ENABLE_PRINTING)
|
||||
|
@ -668,6 +670,7 @@ WebContents::WebContents(v8::Isolate* isolate,
|
|||
id_(GetAllWebContents().Add(this)),
|
||||
devtools_file_system_indexer_(
|
||||
base::MakeRefCounted<DevToolsFileSystemIndexer>()),
|
||||
exclusive_access_manager_(std::make_unique<ExclusiveAccessManager>(this)),
|
||||
file_task_runner_(
|
||||
base::ThreadPool::CreateSequencedTaskRunner({base::MayBlock()}))
|
||||
#if BUILDFLAG(ENABLE_PRINTING)
|
||||
|
@ -688,6 +691,7 @@ WebContents::WebContents(v8::Isolate* isolate,
|
|||
: id_(GetAllWebContents().Add(this)),
|
||||
devtools_file_system_indexer_(
|
||||
base::MakeRefCounted<DevToolsFileSystemIndexer>()),
|
||||
exclusive_access_manager_(std::make_unique<ExclusiveAccessManager>(this)),
|
||||
file_task_runner_(
|
||||
base::ThreadPool::CreateSequencedTaskRunner({base::MayBlock()}))
|
||||
#if BUILDFLAG(ENABLE_PRINTING)
|
||||
|
@ -1252,6 +1256,40 @@ void WebContents::ContentsZoomChange(bool zoom_in) {
|
|||
Emit("zoom-changed", zoom_in ? "in" : "out");
|
||||
}
|
||||
|
||||
Profile* WebContents::GetProfile() {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
bool WebContents::IsFullscreen() const {
|
||||
return owner_window_ && owner_window_->IsFullscreen();
|
||||
}
|
||||
|
||||
void WebContents::EnterFullscreen(const GURL& url,
|
||||
ExclusiveAccessBubbleType bubble_type,
|
||||
const int64_t display_id) {}
|
||||
|
||||
void WebContents::ExitFullscreen() {}
|
||||
|
||||
void WebContents::UpdateExclusiveAccessExitBubbleContent(
|
||||
const GURL& url,
|
||||
ExclusiveAccessBubbleType bubble_type,
|
||||
ExclusiveAccessBubbleHideCallback bubble_first_hide_callback,
|
||||
bool force_update) {}
|
||||
|
||||
void WebContents::OnExclusiveAccessUserInput() {}
|
||||
|
||||
content::WebContents* WebContents::GetActiveWebContents() {
|
||||
return web_contents();
|
||||
}
|
||||
|
||||
bool WebContents::CanUserExitFullscreen() const {
|
||||
return true;
|
||||
}
|
||||
|
||||
bool WebContents::IsExclusiveAccessBubbleDisplayed() const {
|
||||
return false;
|
||||
}
|
||||
|
||||
void WebContents::EnterFullscreenModeForTab(
|
||||
content::RenderFrameHost* requesting_frame,
|
||||
const blink::mojom::FullscreenOptions& options) {
|
||||
|
@ -1262,6 +1300,8 @@ void WebContents::EnterFullscreenModeForTab(
|
|||
base::BindRepeating(&WebContents::OnEnterFullscreenModeForTab,
|
||||
base::Unretained(this), requesting_frame, options);
|
||||
permission_helper->RequestFullscreenPermission(callback);
|
||||
exclusive_access_manager_->fullscreen_controller()->EnterFullscreenModeForTab(
|
||||
requesting_frame, options.display_id);
|
||||
}
|
||||
|
||||
void WebContents::OnEnterFullscreenModeForTab(
|
||||
|
@ -1298,6 +1338,9 @@ void WebContents::ExitFullscreenModeForTab(content::WebContents* source) {
|
|||
// `chrome/browser/ui/exclusive_access/fullscreen_controller.cc`.
|
||||
source->GetRenderViewHost()->GetWidget()->SynchronizeVisualProperties();
|
||||
}
|
||||
|
||||
exclusive_access_manager_->fullscreen_controller()->ExitFullscreenModeForTab(
|
||||
source);
|
||||
}
|
||||
|
||||
void WebContents::RendererUnresponsive(
|
||||
|
@ -1346,6 +1389,18 @@ void WebContents::FindReply(content::WebContents* web_contents,
|
|||
Emit("found-in-page", result.GetHandle());
|
||||
}
|
||||
|
||||
void WebContents::RequestKeyboardLock(content::WebContents* web_contents,
|
||||
bool esc_key_locked) {
|
||||
exclusive_access_manager_->keyboard_lock_controller()->RequestKeyboardLock(
|
||||
web_contents, esc_key_locked);
|
||||
}
|
||||
|
||||
void WebContents::CancelKeyboardLockRequest(
|
||||
content::WebContents* web_contents) {
|
||||
exclusive_access_manager_->keyboard_lock_controller()
|
||||
->CancelKeyboardLockRequest(web_contents);
|
||||
}
|
||||
|
||||
bool WebContents::CheckMediaAccessPermission(
|
||||
content::RenderFrameHost* render_frame_host,
|
||||
const GURL& security_origin,
|
||||
|
|
|
@ -16,6 +16,7 @@
|
|||
#include "base/observer_list_types.h"
|
||||
#include "chrome/browser/devtools/devtools_eye_dropper.h"
|
||||
#include "chrome/browser/devtools/devtools_file_system_indexer.h"
|
||||
#include "chrome/browser/ui/exclusive_access/exclusive_access_context.h" // nogncheck
|
||||
#include "content/common/cursors/webcursor.h"
|
||||
#include "content/common/frame.mojom.h"
|
||||
#include "content/public/browser/devtools_agent_host.h"
|
||||
|
@ -74,6 +75,8 @@ namespace gin {
|
|||
class Arguments;
|
||||
}
|
||||
|
||||
class ExclusiveAccessManager;
|
||||
|
||||
namespace electron {
|
||||
|
||||
class ElectronBrowserContext;
|
||||
|
@ -98,7 +101,8 @@ using DevicePermissionMap = std::map<
|
|||
std::map<url::Origin, std::vector<std::unique_ptr<base::Value>>>>>;
|
||||
|
||||
// Wrapper around the content::WebContents.
|
||||
class WebContents : public gin::Wrappable<WebContents>,
|
||||
class WebContents : public ExclusiveAccessContext,
|
||||
public gin::Wrappable<WebContents>,
|
||||
public gin_helper::EventEmitterMixin<WebContents>,
|
||||
public gin_helper::Constructible<WebContents>,
|
||||
public gin_helper::Pinnable<WebContents>,
|
||||
|
@ -549,6 +553,9 @@ class WebContents : public gin::Wrappable<WebContents>,
|
|||
const gfx::Rect& selection_rect,
|
||||
int active_match_ordinal,
|
||||
bool final_update) override;
|
||||
void RequestKeyboardLock(content::WebContents* web_contents,
|
||||
bool esc_key_locked) override;
|
||||
void CancelKeyboardLockRequest(content::WebContents* web_contents) override;
|
||||
bool CheckMediaAccessPermission(content::RenderFrameHost* render_frame_host,
|
||||
const GURL& security_origin,
|
||||
blink::mojom::MediaStreamType type) override;
|
||||
|
@ -647,6 +654,24 @@ class WebContents : public gin::Wrappable<WebContents>,
|
|||
void EnumerateDirectory(content::WebContents* web_contents,
|
||||
scoped_refptr<content::FileSelectListener> listener,
|
||||
const base::FilePath& path) override;
|
||||
|
||||
// ExclusiveAccessContext:
|
||||
Profile* GetProfile() override;
|
||||
bool IsFullscreen() const override;
|
||||
void EnterFullscreen(const GURL& url,
|
||||
ExclusiveAccessBubbleType bubble_type,
|
||||
const int64_t display_id) override;
|
||||
void ExitFullscreen() override;
|
||||
void UpdateExclusiveAccessExitBubbleContent(
|
||||
const GURL& url,
|
||||
ExclusiveAccessBubbleType bubble_type,
|
||||
ExclusiveAccessBubbleHideCallback bubble_first_hide_callback,
|
||||
bool force_update) override;
|
||||
void OnExclusiveAccessUserInput() override;
|
||||
content::WebContents* GetActiveWebContents() override;
|
||||
bool CanUserExitFullscreen() const override;
|
||||
bool IsExclusiveAccessBubbleDisplayed() const override;
|
||||
|
||||
bool IsFullscreenForTabOrPending(const content::WebContents* source) override;
|
||||
blink::SecurityStyle GetSecurityStyle(
|
||||
content::WebContents* web_contents,
|
||||
|
@ -760,6 +785,8 @@ class WebContents : public gin::Wrappable<WebContents>,
|
|||
|
||||
scoped_refptr<DevToolsFileSystemIndexer> devtools_file_system_indexer_;
|
||||
|
||||
std::unique_ptr<ExclusiveAccessManager> exclusive_access_manager_;
|
||||
|
||||
std::unique_ptr<DevToolsEyeDropper> eye_dropper_;
|
||||
|
||||
ElectronBrowserContext* browser_context_;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue