Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(211)

Side by Side Diff: chrome/browser/guest_view/web_view/web_view_guest.cc

Issue 288113005: <webview>: Cleanup Pointer Lock & Simplify HandleKeyboardEvent (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Removed unnecessary braces Created 6 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/guest_view/web_view/web_view_guest.h" 5 #include "chrome/browser/guest_view/web_view/web_view_guest.h"
6 6
7 #include "base/message_loop/message_loop.h" 7 #include "base/message_loop/message_loop.h"
8 #include "base/strings/stringprintf.h" 8 #include "base/strings/stringprintf.h"
9 #include "chrome/browser/chrome_notification_types.h" 9 #include "chrome/browser/chrome_notification_types.h"
10 #include "chrome/browser/extensions/api/web_request/web_request_api.h" 10 #include "chrome/browser/extensions/api/web_request/web_request_api.h"
(...skipping 384 matching lines...) Expand 10 before | Expand all | Expand 10 after
395 // Cancel all find sessions in progress. 395 // Cancel all find sessions in progress.
396 find_helper_.CancelAllFindSessions(); 396 find_helper_.CancelAllFindSessions();
397 397
398 scoped_ptr<base::DictionaryValue> args(new base::DictionaryValue()); 398 scoped_ptr<base::DictionaryValue> args(new base::DictionaryValue());
399 args->SetInteger(webview::kProcessId, 399 args->SetInteger(webview::kProcessId,
400 guest_web_contents()->GetRenderProcessHost()->GetID()); 400 guest_web_contents()->GetRenderProcessHost()->GetID());
401 args->SetString(webview::kReason, TerminationStatusToString(status)); 401 args->SetString(webview::kReason, TerminationStatusToString(status));
402 DispatchEvent(new GuestViewBase::Event(webview::kEventExit, args.Pass())); 402 DispatchEvent(new GuestViewBase::Event(webview::kEventExit, args.Pass()));
403 } 403 }
404 404
405 bool WebViewGuest::HandleKeyboardEvent( 405 void WebViewGuest::HandleKeyboardEvent(
406 const content::NativeWebKeyboardEvent& event) { 406 const content::NativeWebKeyboardEvent& event) {
407 if (event.type != blink::WebInputEvent::RawKeyDown) 407 if (!attached())
408 return false; 408 return;
409 409
410 #if defined(OS_MACOSX) 410 if (HandleKeyboardShortcuts(event))
411 if (event.modifiers != blink::WebInputEvent::MetaKey) 411 return;
412 return false;
413 412
414 if (event.windowsKeyCode == ui::VKEY_OEM_4) { 413 // Send the unhandled keyboard events back to the embedder to reprocess them.
415 Go(-1); 414 // TODO(fsamuel): This introduces the possibility of out-of-order keyboard
416 return true; 415 // events because the guest may be arbitrarily delayed when responding to
417 } 416 // keyboard events. In that time, the embedder may have received and processed
418 417 // additional key events. This needs to be fixed as soon as possible.
419 if (event.windowsKeyCode == ui::VKEY_OEM_6) { 418 // See http://crbug.com/229882.
420 Go(1); 419 embedder_web_contents()->GetDelegate()->HandleKeyboardEvent(
421 return true; 420 web_contents(), event);
422 }
423 #else
424 if (event.windowsKeyCode == ui::VKEY_BROWSER_BACK) {
425 Go(-1);
426 return true;
427 }
428
429 if (event.windowsKeyCode == ui::VKEY_BROWSER_FORWARD) {
430 Go(1);
431 return true;
432 }
433 #endif
434 return false;
435 } 421 }
436 422
437 bool WebViewGuest::IsDragAndDropEnabled() { 423 bool WebViewGuest::IsDragAndDropEnabled() {
438 return true; 424 return true;
439 } 425 }
440 426
441 bool WebViewGuest::IsOverridingUserAgent() const { 427 bool WebViewGuest::IsOverridingUserAgent() const {
442 return is_overriding_user_agent_; 428 return is_overriding_user_agent_;
443 } 429 }
444 430
(...skipping 630 matching lines...) Expand 10 before | Expand all | Expand 10 after
1075 args->SetString(webview::kPermission, 1061 args->SetString(webview::kPermission,
1076 PermissionTypeToString(permission_type)); 1062 PermissionTypeToString(permission_type));
1077 DispatchEvent(new GuestViewBase::Event(webview::kEventPermissionRequest, 1063 DispatchEvent(new GuestViewBase::Event(webview::kEventPermissionRequest,
1078 args.Pass())); 1064 args.Pass()));
1079 break; 1065 break;
1080 } 1066 }
1081 } 1067 }
1082 return request_id; 1068 return request_id;
1083 } 1069 }
1084 1070
1071 bool WebViewGuest::HandleKeyboardShortcuts(
1072 const content::NativeWebKeyboardEvent& event) {
1073 if (event.type != blink::WebInputEvent::RawKeyDown)
1074 return false;
1075
1076 // If the user hits the escape key without any modifiers then unlock the
1077 // mouse if necessary.
1078 if ((event.windowsKeyCode == ui::VKEY_ESCAPE) &&
1079 !(event.modifiers & blink::WebInputEvent::InputModifiers)) {
1080 return guest_web_contents()->GotResponseToLockMouseRequest(false);
1081 }
1082
1083 #if defined(OS_MACOSX)
1084 if (event.modifiers != blink::WebInputEvent::MetaKey)
1085 return false;
1086
1087 if (event.windowsKeyCode == ui::VKEY_OEM_4) {
1088 Go(-1);
1089 return true;
1090 }
1091
1092 if (event.windowsKeyCode == ui::VKEY_OEM_6) {
1093 Go(1);
1094 return true;
1095 }
1096 #else
1097 if (event.windowsKeyCode == ui::VKEY_BROWSER_BACK) {
1098 Go(-1);
1099 return true;
1100 }
1101
1102 if (event.windowsKeyCode == ui::VKEY_BROWSER_FORWARD) {
1103 Go(1);
1104 return true;
1105 }
1106 #endif
1107
1108 return false;
1109 }
1110
1085 WebViewGuest::PermissionResponseInfo::PermissionResponseInfo() 1111 WebViewGuest::PermissionResponseInfo::PermissionResponseInfo()
1086 : permission_type(BROWSER_PLUGIN_PERMISSION_TYPE_UNKNOWN), 1112 : permission_type(BROWSER_PLUGIN_PERMISSION_TYPE_UNKNOWN),
1087 allowed_by_default(false) { 1113 allowed_by_default(false) {
1088 } 1114 }
1089 1115
1090 WebViewGuest::PermissionResponseInfo::PermissionResponseInfo( 1116 WebViewGuest::PermissionResponseInfo::PermissionResponseInfo(
1091 const PermissionResponseCallback& callback, 1117 const PermissionResponseCallback& callback,
1092 BrowserPluginPermissionType permission_type, 1118 BrowserPluginPermissionType permission_type,
1093 bool allowed_by_default) 1119 bool allowed_by_default)
1094 : callback(callback), 1120 : callback(callback),
(...skipping 13 matching lines...) Expand all
1108 if (request_id != pending_context_menu_request_id_) 1134 if (request_id != pending_context_menu_request_id_)
1109 return; 1135 return;
1110 1136
1111 // TODO(lazyboy): Implement. 1137 // TODO(lazyboy): Implement.
1112 DCHECK(!items); 1138 DCHECK(!items);
1113 1139
1114 ContextMenuDelegate* menu_delegate = 1140 ContextMenuDelegate* menu_delegate =
1115 ContextMenuDelegate::FromWebContents(guest_web_contents()); 1141 ContextMenuDelegate::FromWebContents(guest_web_contents());
1116 menu_delegate->ShowMenu(pending_menu_.Pass()); 1142 menu_delegate->ShowMenu(pending_menu_.Pass());
1117 } 1143 }
OLDNEW
« no previous file with comments | « chrome/browser/guest_view/web_view/web_view_guest.h ('k') | content/browser/browser_plugin/browser_plugin_embedder.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698