Index: chrome/browser/extensions/global_shortcut_listener_chromeos.cc |
diff --git a/chrome/browser/extensions/global_shortcut_listener_chromeos.cc b/chrome/browser/extensions/global_shortcut_listener_chromeos.cc |
index 14f40c7e96052350e72f4630bc7ca65f6a1f9507..aaa15f2c329092ab9899f239f38fcae6d21048f2 100644 |
--- a/chrome/browser/extensions/global_shortcut_listener_chromeos.cc |
+++ b/chrome/browser/extensions/global_shortcut_listener_chromeos.cc |
@@ -4,6 +4,8 @@ |
#include "chrome/browser/extensions/global_shortcut_listener_chromeos.h" |
+#include "ash/accelerators/accelerator_controller.h" |
+#include "ash/shell.h" |
#include "content/public/browser/browser_thread.h" |
using content::BrowserThread; |
@@ -21,9 +23,6 @@ GlobalShortcutListener* GlobalShortcutListener::GetInstance() { |
GlobalShortcutListenerChromeOS::GlobalShortcutListenerChromeOS() |
: is_listening_(false) { |
CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
- |
- // TODO(implementor): Remove this. |
- LOG(ERROR) << "GlobalShortcutListenerChromeOS object created"; |
} |
GlobalShortcutListenerChromeOS::~GlobalShortcutListenerChromeOS() { |
@@ -33,32 +32,52 @@ GlobalShortcutListenerChromeOS::~GlobalShortcutListenerChromeOS() { |
void GlobalShortcutListenerChromeOS::StartListening() { |
DCHECK(!is_listening_); // Don't start twice. |
- NOTIMPLEMENTED(); |
is_listening_ = true; |
} |
void GlobalShortcutListenerChromeOS::StopListening() { |
DCHECK(is_listening_); // No point if we are not already listening. |
- NOTIMPLEMENTED(); |
is_listening_ = false; |
} |
bool GlobalShortcutListenerChromeOS::RegisterAcceleratorImpl( |
const ui::Accelerator& accelerator) { |
- NOTIMPLEMENTED(); |
- // To implement: |
- // 1) Convert modifiers to platform specific modifiers. |
- // 2) Register for the hotkey. |
- // 3) If not successful, return false. |
- // 4) Else, return true. |
+ ash::AcceleratorController* controller = |
+ ash::Shell::GetInstance()->accelerator_controller(); |
+ if (controller->IsReservedAccelerator(accelerator)) |
+ return false; |
- return false; |
+ // TODO(dtseng): Support search key mapping. |
+ controller->Register(accelerator, this); |
+ return controller->IsRegistered(accelerator); |
oshima
2014/06/27 18:40:41
AcceleratorManager has DCHECKs for duplicated acce
David Tseng
2014/06/27 21:47:16
I'll let finnur handle this case (it's not specifi
Finnur
2014/06/27 22:23:44
Almost. :) The expected behavior when extension A
oshima
2014/07/01 17:48:25
How/where this is controlled? by permission?
oshima
2014/07/01 17:48:25
Not sure if I understand. This CL is for ChromeOS,
David Tseng
2014/07/01 18:34:42
The commands API has already shipped for all platf
David Tseng
2014/07/01 20:20:35
@finnur, looks like the tests do fail after I adde
oshima
2014/07/02 00:51:36
Ah, sorry, I somehow mixed up with my question abo
Finnur
2014/07/02 12:41:25
Not sure exactly what to disregard, so I'll addres
oshima
2014/07/02 23:01:13
I had the question only because the original CL di
|
} |
void GlobalShortcutListenerChromeOS::UnregisterAcceleratorImpl( |
const ui::Accelerator& accelerator) { |
- NOTIMPLEMENTED(); |
- // To implement: Unregister for the hotkey. |
+ // This code path gets called during object destruction. |
+ if (!ash::Shell::HasInstance()) |
+ return; |
+ ash::Shell::GetInstance()->accelerator_controller()->Unregister(accelerator, |
+ this); |
oshima
2014/07/01 17:48:25
I assume the accelerators registered by an extensi
oshima
2014/07/02 00:51:36
Can you answer this question? I want to make sure
Finnur
2014/07/02 12:41:25
I can't speak for the ChromeOS accelerators, but o
|
+} |
+ |
+bool GlobalShortcutListenerChromeOS::AcceleratorPressed( |
+ const ui::Accelerator& accelerator) { |
+ DCHECK(is_listening_); |
+ ash::AcceleratorController* controller = |
+ ash::Shell::GetInstance()->accelerator_controller(); |
+ ash::AcceleratorController::AcceleratorProcessingRestriction restriction = |
+ controller->GetAcceleratorProcessingRestriction(-1, accelerator); |
oshima
2014/06/27 18:40:41
shouldn't this always return NONE? (related to my
David Tseng
2014/06/27 21:47:16
Why? When an extension is running within the locke
Finnur
2014/06/27 22:23:44
Funny. I actually had the opposite reaction to thi
David Tseng
2014/06/28 14:17:50
I'm happy to change the naming/logic given suggest
oshima
2014/07/01 17:48:25
Hmm, passing -1 is not intuitive. Here is my recom
David Tseng
2014/07/01 18:34:42
Done.
|
+ if (restriction == ash::AcceleratorController::RESTRICTION_NONE) { |
+ NotifyKeyPressed(accelerator); |
+ return true; |
+ } |
+ return restriction == ash::AcceleratorController:: |
+ RESTRICTION_PREVENT_PROCESSING_AND_PROPAGATION; |
+} |
+ |
+bool GlobalShortcutListenerChromeOS::CanHandleAccelerators() const { |
+ return is_listening_; |
} |
} // namespace extensions |