Index: chrome/browser/ui/cocoa/profiles/profile_chooser_controller.mm |
diff --git a/chrome/browser/ui/cocoa/profiles/profile_chooser_controller.mm b/chrome/browser/ui/cocoa/profiles/profile_chooser_controller.mm |
index 589447d39dee96bb8edb8cfdbb4dd39e9e89c21d..b39f7481be63f2be2d216422e649dc57b4437a88 100644 |
--- a/chrome/browser/ui/cocoa/profiles/profile_chooser_controller.mm |
+++ b/chrome/browser/ui/cocoa/profiles/profile_chooser_controller.mm |
@@ -70,6 +70,10 @@ |
#include "ui/native_theme/common_theme.h" |
#include "ui/native_theme/native_theme.h" |
+#include "chrome/app/chrome_command_ids.h" |
+#include "content/public/browser/native_web_keyboard_event.h" |
+#import "chrome/browser/ui/cocoa/browser_window_utils.h" |
+ |
namespace { |
// Constants taken from the Windows/Views implementation at: |
@@ -247,6 +251,51 @@ bool HasAuthError(Profile* profile) { |
} // namespace |
+// Custom WebContentsDelegate that allows handling of hotkeys and suppresses |
+// the context menu |
+class GaiaWebContentsDelegate : public content::WebContentsDelegate { |
+ public: |
+ GaiaWebContentsDelegate() {} |
+ |
+ virtual ~GaiaWebContentsDelegate() {} |
+ |
+ private: |
+ // Overridden from content::WebContentsDelegate. |
+ bool HandleContextMenu(const content::ContextMenuParams& params) override; |
+ void HandleKeyboardEvent( |
+ content::WebContents* source, |
+ const content::NativeWebKeyboardEvent& event) override; |
+}; |
+ |
+bool GaiaWebContentsDelegate::HandleContextMenu( |
+ const content::ContextMenuParams& params) { |
+ #ifndef NDEBUG |
+ return false; |
+ #else |
+ return true; |
+ #endif |
+} |
+ |
+void GaiaWebContentsDelegate::HandleKeyboardEvent( |
+ content::WebContents* source, |
+ const content::NativeWebKeyboardEvent& event) { |
+ if (![BrowserWindowUtils shouldHandleKeyboardEvent:event]) |
+ return; |
+ |
+ int chromeCommandId = [BrowserWindowUtils getCommandId:event]; |
+ |
+ bool isTextEditingCommand = |
+ (event.modifiers & blink::WebInputEvent::MetaKey) && |
+ (event.windowsKeyCode == ui::VKEY_A || |
+ event.windowsKeyCode == ui::VKEY_V); |
+ |
+ // TODO(guohui): maybe should add accelerator for the back button. |
+ if (chromeCommandId == IDC_CLOSE_WINDOW || chromeCommandId == IDC_EXIT || |
+ isTextEditingCommand) { |
+ [[NSApp mainMenu] performKeyEquivalent:event.os_event]; |
+ } |
+} |
+ |
// Class that listens to changes to the OAuth2Tokens for the active profile, |
// changes to the avatar menu model or browser close notifications. |
class ActiveProfileObserverBridge : public AvatarMenuObserver, |
@@ -1905,6 +1954,9 @@ class ActiveProfileObserverBridge : public AvatarMenuObserver, |
webContents_.reset(content::WebContents::Create( |
content::WebContents::CreateParams(browser_->profile()))); |
+ |
+ webContentsDelegate_.reset(new GaiaWebContentsDelegate()); |
+ webContents_->SetDelegate(webContentsDelegate_.get()); |
webContents_->GetController().LoadURL(url, |
content::Referrer(), |
ui::PAGE_TRANSITION_AUTO_TOPLEVEL, |