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..54b8c427f385fb7b7125e6e6e9b85c25e1c5edc3 100644 |
--- a/chrome/browser/ui/cocoa/profiles/profile_chooser_controller.mm |
+++ b/chrome/browser/ui/cocoa/profiles/profile_chooser_controller.mm |
@@ -11,6 +11,7 @@ |
#include "base/strings/string_util.h" |
#include "base/strings/sys_string_conversions.h" |
#include "base/strings/utf_string_conversions.h" |
+#include "chrome/app/chrome_command_ids.h" |
#include "chrome/browser/browser_process.h" |
#include "chrome/browser/chrome_notification_types.h" |
#include "chrome/browser/lifetime/application_lifetime.h" |
@@ -34,6 +35,7 @@ |
#include "chrome/browser/ui/browser_window.h" |
#include "chrome/browser/ui/chrome_pages.h" |
#include "chrome/browser/ui/chrome_style.h" |
+#import "chrome/browser/ui/cocoa/browser_window_utils.h" |
#import "chrome/browser/ui/cocoa/info_bubble_view.h" |
#import "chrome/browser/ui/cocoa/info_bubble_window.h" |
#import "chrome/browser/ui/cocoa/profiles/user_manager_mac.h" |
@@ -49,6 +51,7 @@ |
#include "components/signin/core/browser/profile_oauth2_token_service.h" |
#include "components/signin/core/browser/signin_manager.h" |
#include "components/signin/core/common/profile_management_switches.h" |
+#include "content/public/browser/native_web_keyboard_event.h" |
#include "content/public/browser/notification_service.h" |
#include "content/public/browser/render_widget_host_view.h" |
#include "content/public/browser/web_contents.h" |
@@ -247,6 +250,52 @@ bool HasAuthError(Profile* profile) { |
} // namespace |
+// Custom WebContentsDelegate that allows handling of hotkeys and suppresses |
+// the context menu. |
+class GaiaWebContentsDelegate : public content::WebContentsDelegate { |
+ public: |
+ GaiaWebContentsDelegate() {} |
+ |
Alexei Svitkine (slow)
2014/10/28 18:27:23
Nit: No need for empty line here.
guohui
2014/10/28 18:53:40
Done.
|
+ virtual ~GaiaWebContentsDelegate() {} |
Alexei Svitkine (slow)
2014/10/28 18:27:23
Nit: I think the preferred syntax is now:
~GaiaWe
guohui
2014/10/28 18:53:40
Done.
|
+ |
+ private: |
+ // Overridden from content::WebContentsDelegate. |
+ bool HandleContextMenu(const content::ContextMenuParams& params) override; |
+ void HandleKeyboardEvent( |
+ content::WebContents* source, |
+ const content::NativeWebKeyboardEvent& event) override; |
+}; |
Alexei Svitkine (slow)
2014/10/28 18:27:23
DISALLOW_COPY_AND_ASSIGN()
guohui
2014/10/28 18:53:40
Done.
|
+ |
+bool GaiaWebContentsDelegate::HandleContextMenu( |
+ const content::ContextMenuParams& params) { |
+ // Suppresses the context menu in non-debug mode. |
+#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]; |
Alexei Svitkine (slow)
2014/10/28 18:27:23
Use hacker_style in C++ classes.
guohui
2014/10/28 18:53:40
Done.
|
+ |
+ bool isTextEditingCommand = |
+ (event.modifiers & blink::WebInputEvent::MetaKey) && |
+ (event.windowsKeyCode == ui::VKEY_A || |
+ event.windowsKeyCode == ui::VKEY_V); |
Roger Tawa OOO till Jul 10th
2014/10/28 18:58:13
How about VKEY_C ?
|
+ |
+ // TODO(guohui): maybe should add an 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, |