feat: keyboard.lock() should use permissions helper (#40369)
		
	feat: `keyboard.lock()` should use permissions helper
This commit is contained in:
		
					parent
					
						
							
								ee108903a0
							
						
					
				
			
			
				commit
				
					
						7999ea39e2
					
				
			
		
					 6 changed files with 45 additions and 13 deletions
				
			
		| 
						 | 
					@ -901,6 +901,7 @@ win.webContents.session.setCertificateVerifyProc((request, callback) => {
 | 
				
			||||||
    * `midiSysex` - Request the use of system exclusive messages in the [Web MIDI API](https://developer.mozilla.org/en-US/docs/Web/API/Web_MIDI_API).
 | 
					    * `midiSysex` - Request the use of system exclusive messages in the [Web MIDI API](https://developer.mozilla.org/en-US/docs/Web/API/Web_MIDI_API).
 | 
				
			||||||
    * `notifications` - Request notification creation and the ability to display them in the user's system tray using the [Notifications API](https://developer.mozilla.org/en-US/docs/Web/API/notification)
 | 
					    * `notifications` - Request notification creation and the ability to display them in the user's system tray using the [Notifications API](https://developer.mozilla.org/en-US/docs/Web/API/notification)
 | 
				
			||||||
    * `pointerLock` - Request to directly interpret mouse movements as an input method via the [Pointer Lock API](https://developer.mozilla.org/en-US/docs/Web/API/Pointer_Lock_API). These requests always appear to originate from the main frame.
 | 
					    * `pointerLock` - Request to directly interpret mouse movements as an input method via the [Pointer Lock API](https://developer.mozilla.org/en-US/docs/Web/API/Pointer_Lock_API). These requests always appear to originate from the main frame.
 | 
				
			||||||
 | 
					    * `keyboardLock` - Request capture of keypresses for any or all of the keys on the physical keyboard via the [Keyboard Lock API](https://developer.mozilla.org/en-US/docs/Web/API/Keyboard/lock). These requests always appear to originate from the main frame.
 | 
				
			||||||
    * `openExternal` - Request to open links in external applications.
 | 
					    * `openExternal` - Request to open links in external applications.
 | 
				
			||||||
    * `window-management` - Request access to enumerate screens using the [`getScreenDetails`](https://developer.chrome.com/en/articles/multi-screen-window-placement/) API.
 | 
					    * `window-management` - Request access to enumerate screens using the [`getScreenDetails`](https://developer.chrome.com/en/articles/multi-screen-window-placement/) API.
 | 
				
			||||||
    * `unknown` - An unrecognized permission request.
 | 
					    * `unknown` - An unrecognized permission request.
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -1511,11 +1511,10 @@ void WebContents::FindReply(content::WebContents* web_contents,
 | 
				
			||||||
  Emit("found-in-page", result.GetHandle());
 | 
					  Emit("found-in-page", result.GetHandle());
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void WebContents::RequestExclusivePointerAccess(
 | 
					void WebContents::OnRequestToLockMouse(content::WebContents* web_contents,
 | 
				
			||||||
    content::WebContents* web_contents,
 | 
					                                       bool user_gesture,
 | 
				
			||||||
    bool user_gesture,
 | 
					                                       bool last_unlocked_by_target,
 | 
				
			||||||
    bool last_unlocked_by_target,
 | 
					                                       bool allowed) {
 | 
				
			||||||
    bool allowed) {
 | 
					 | 
				
			||||||
  if (allowed) {
 | 
					  if (allowed) {
 | 
				
			||||||
    exclusive_access_manager_.mouse_lock_controller()->RequestToLockMouse(
 | 
					    exclusive_access_manager_.mouse_lock_controller()->RequestToLockMouse(
 | 
				
			||||||
        web_contents, user_gesture, last_unlocked_by_target);
 | 
					        web_contents, user_gesture, last_unlocked_by_target);
 | 
				
			||||||
| 
						 | 
					@ -1532,7 +1531,7 @@ void WebContents::RequestToLockMouse(content::WebContents* web_contents,
 | 
				
			||||||
      WebContentsPermissionHelper::FromWebContents(web_contents);
 | 
					      WebContentsPermissionHelper::FromWebContents(web_contents);
 | 
				
			||||||
  permission_helper->RequestPointerLockPermission(
 | 
					  permission_helper->RequestPointerLockPermission(
 | 
				
			||||||
      user_gesture, last_unlocked_by_target,
 | 
					      user_gesture, last_unlocked_by_target,
 | 
				
			||||||
      base::BindOnce(&WebContents::RequestExclusivePointerAccess,
 | 
					      base::BindOnce(&WebContents::OnRequestToLockMouse,
 | 
				
			||||||
                     base::Unretained(this)));
 | 
					                     base::Unretained(this)));
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -1540,10 +1539,24 @@ void WebContents::LostMouseLock() {
 | 
				
			||||||
  exclusive_access_manager_.mouse_lock_controller()->LostMouseLock();
 | 
					  exclusive_access_manager_.mouse_lock_controller()->LostMouseLock();
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					void WebContents::OnRequestKeyboardLock(content::WebContents* web_contents,
 | 
				
			||||||
 | 
					                                        bool esc_key_locked,
 | 
				
			||||||
 | 
					                                        bool allowed) {
 | 
				
			||||||
 | 
					  if (allowed) {
 | 
				
			||||||
 | 
					    exclusive_access_manager_.keyboard_lock_controller()->RequestKeyboardLock(
 | 
				
			||||||
 | 
					        web_contents, esc_key_locked);
 | 
				
			||||||
 | 
					  } else {
 | 
				
			||||||
 | 
					    web_contents->GotResponseToKeyboardLockRequest(false);
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void WebContents::RequestKeyboardLock(content::WebContents* web_contents,
 | 
					void WebContents::RequestKeyboardLock(content::WebContents* web_contents,
 | 
				
			||||||
                                      bool esc_key_locked) {
 | 
					                                      bool esc_key_locked) {
 | 
				
			||||||
  exclusive_access_manager_.keyboard_lock_controller()->RequestKeyboardLock(
 | 
					  auto* permission_helper =
 | 
				
			||||||
      web_contents, esc_key_locked);
 | 
					      WebContentsPermissionHelper::FromWebContents(web_contents);
 | 
				
			||||||
 | 
					  permission_helper->RequestKeyboardLockPermission(
 | 
				
			||||||
 | 
					      esc_key_locked, base::BindOnce(&WebContents::OnRequestKeyboardLock,
 | 
				
			||||||
 | 
					                                     base::Unretained(this)));
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void WebContents::CancelKeyboardLockRequest(
 | 
					void WebContents::CancelKeyboardLockRequest(
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -568,14 +568,17 @@ class WebContents : public ExclusiveAccessContext,
 | 
				
			||||||
                 const gfx::Rect& selection_rect,
 | 
					                 const gfx::Rect& selection_rect,
 | 
				
			||||||
                 int active_match_ordinal,
 | 
					                 int active_match_ordinal,
 | 
				
			||||||
                 bool final_update) override;
 | 
					                 bool final_update) override;
 | 
				
			||||||
  void RequestExclusivePointerAccess(content::WebContents* web_contents,
 | 
					  void OnRequestToLockMouse(content::WebContents* web_contents,
 | 
				
			||||||
                                     bool user_gesture,
 | 
					                            bool user_gesture,
 | 
				
			||||||
                                     bool last_unlocked_by_target,
 | 
					                            bool last_unlocked_by_target,
 | 
				
			||||||
                                     bool allowed);
 | 
					                            bool allowed);
 | 
				
			||||||
  void RequestToLockMouse(content::WebContents* web_contents,
 | 
					  void RequestToLockMouse(content::WebContents* web_contents,
 | 
				
			||||||
                          bool user_gesture,
 | 
					                          bool user_gesture,
 | 
				
			||||||
                          bool last_unlocked_by_target) override;
 | 
					                          bool last_unlocked_by_target) override;
 | 
				
			||||||
  void LostMouseLock() override;
 | 
					  void LostMouseLock() override;
 | 
				
			||||||
 | 
					  void OnRequestKeyboardLock(content::WebContents* web_contents,
 | 
				
			||||||
 | 
					                             bool esc_key_locked,
 | 
				
			||||||
 | 
					                             bool allowed);
 | 
				
			||||||
  void RequestKeyboardLock(content::WebContents* web_contents,
 | 
					  void RequestKeyboardLock(content::WebContents* web_contents,
 | 
				
			||||||
                           bool esc_key_locked) override;
 | 
					                           bool esc_key_locked) override;
 | 
				
			||||||
  void CancelKeyboardLockRequest(content::WebContents* web_contents) override;
 | 
					  void CancelKeyboardLockRequest(content::WebContents* web_contents) override;
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -253,6 +253,15 @@ void WebContentsPermissionHelper::RequestPointerLockPermission(
 | 
				
			||||||
      user_gesture);
 | 
					      user_gesture);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					void WebContentsPermissionHelper::RequestKeyboardLockPermission(
 | 
				
			||||||
 | 
					    bool esc_key_locked,
 | 
				
			||||||
 | 
					    base::OnceCallback<void(content::WebContents*, bool, bool)> callback) {
 | 
				
			||||||
 | 
					  RequestPermission(
 | 
				
			||||||
 | 
					      web_contents_->GetPrimaryMainFrame(),
 | 
				
			||||||
 | 
					      static_cast<blink::PermissionType>(PermissionType::KEYBOARD_LOCK),
 | 
				
			||||||
 | 
					      base::BindOnce(std::move(callback), web_contents_, esc_key_locked));
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void WebContentsPermissionHelper::RequestOpenExternalPermission(
 | 
					void WebContentsPermissionHelper::RequestOpenExternalPermission(
 | 
				
			||||||
    content::RenderFrameHost* requesting_frame,
 | 
					    content::RenderFrameHost* requesting_frame,
 | 
				
			||||||
    base::OnceCallback<void(bool)> callback,
 | 
					    base::OnceCallback<void(bool)> callback,
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -31,7 +31,8 @@ class WebContentsPermissionHelper
 | 
				
			||||||
    OPEN_EXTERNAL,
 | 
					    OPEN_EXTERNAL,
 | 
				
			||||||
    SERIAL,
 | 
					    SERIAL,
 | 
				
			||||||
    HID,
 | 
					    HID,
 | 
				
			||||||
    USB
 | 
					    USB,
 | 
				
			||||||
 | 
					    KEYBOARD_LOCK
 | 
				
			||||||
  };
 | 
					  };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  // Asynchronous Requests
 | 
					  // Asynchronous Requests
 | 
				
			||||||
| 
						 | 
					@ -44,6 +45,9 @@ class WebContentsPermissionHelper
 | 
				
			||||||
      bool last_unlocked_by_target,
 | 
					      bool last_unlocked_by_target,
 | 
				
			||||||
      base::OnceCallback<void(content::WebContents*, bool, bool, bool)>
 | 
					      base::OnceCallback<void(content::WebContents*, bool, bool, bool)>
 | 
				
			||||||
          callback);
 | 
					          callback);
 | 
				
			||||||
 | 
					  void RequestKeyboardLockPermission(
 | 
				
			||||||
 | 
					      bool esc_key_locked,
 | 
				
			||||||
 | 
					      base::OnceCallback<void(content::WebContents*, bool, bool)> callback);
 | 
				
			||||||
  void RequestWebNotificationPermission(
 | 
					  void RequestWebNotificationPermission(
 | 
				
			||||||
      content::RenderFrameHost* requesting_frame,
 | 
					      content::RenderFrameHost* requesting_frame,
 | 
				
			||||||
      base::OnceCallback<void(bool)> callback);
 | 
					      base::OnceCallback<void(bool)> callback);
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -300,6 +300,8 @@ v8::Local<v8::Value> Converter<blink::PermissionType>::ToV8(
 | 
				
			||||||
  switch (static_cast<PermissionType>(val)) {
 | 
					  switch (static_cast<PermissionType>(val)) {
 | 
				
			||||||
    case PermissionType::POINTER_LOCK:
 | 
					    case PermissionType::POINTER_LOCK:
 | 
				
			||||||
      return StringToV8(isolate, "pointerLock");
 | 
					      return StringToV8(isolate, "pointerLock");
 | 
				
			||||||
 | 
					    case PermissionType::KEYBOARD_LOCK:
 | 
				
			||||||
 | 
					      return StringToV8(isolate, "keyboardLock");
 | 
				
			||||||
    case PermissionType::FULLSCREEN:
 | 
					    case PermissionType::FULLSCREEN:
 | 
				
			||||||
      return StringToV8(isolate, "fullscreen");
 | 
					      return StringToV8(isolate, "fullscreen");
 | 
				
			||||||
    case PermissionType::OPEN_EXTERNAL:
 | 
					    case PermissionType::OPEN_EXTERNAL:
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue