Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/ui/views/location_bar/page_action_image_view.h" | 5 #include "chrome/browser/ui/views/location_bar/page_action_image_view.h" |
| 6 | 6 |
| 7 #include "base/strings/utf_string_conversions.h" | 7 #include "base/strings/utf_string_conversions.h" |
| 8 #include "chrome/app/chrome_command_ids.h" | |
| 8 #include "chrome/browser/extensions/api/commands/command_service.h" | 9 #include "chrome/browser/extensions/api/commands/command_service.h" |
| 9 #include "chrome/browser/extensions/extension_action.h" | 10 #include "chrome/browser/extensions/extension_action.h" |
| 10 #include "chrome/browser/extensions/extension_action_icon_factory.h" | 11 #include "chrome/browser/extensions/extension_action_icon_factory.h" |
| 11 #include "chrome/browser/extensions/extension_action_manager.h" | 12 #include "chrome/browser/extensions/extension_action_manager.h" |
| 12 #include "chrome/browser/extensions/extension_context_menu_model.h" | 13 #include "chrome/browser/extensions/extension_context_menu_model.h" |
| 13 #include "chrome/browser/extensions/extension_tab_util.h" | 14 #include "chrome/browser/extensions/extension_tab_util.h" |
| 14 #include "chrome/browser/extensions/location_bar_controller.h" | 15 #include "chrome/browser/extensions/location_bar_controller.h" |
| 15 #include "chrome/browser/extensions/tab_helper.h" | 16 #include "chrome/browser/extensions/tab_helper.h" |
| 16 #include "chrome/browser/platform_util.h" | 17 #include "chrome/browser/platform_util.h" |
| 17 #include "chrome/browser/profiles/profile.h" | 18 #include "chrome/browser/profiles/profile.h" |
| 18 #include "chrome/browser/sessions/session_id.h" | 19 #include "chrome/browser/sessions/session_id.h" |
| 20 #include "chrome/browser/ui/accelerator_utils.h" | |
| 19 #include "chrome/browser/ui/browser_list.h" | 21 #include "chrome/browser/ui/browser_list.h" |
| 20 #include "chrome/browser/ui/views/frame/browser_view.h" | 22 #include "chrome/browser/ui/views/frame/browser_view.h" |
| 21 #include "chrome/browser/ui/views/location_bar/location_bar_view.h" | 23 #include "chrome/browser/ui/views/location_bar/location_bar_view.h" |
| 22 #include "chrome/browser/ui/webui/extensions/extension_info_ui.h" | 24 #include "chrome/browser/ui/webui/extensions/extension_info_ui.h" |
| 25 #include "chrome/common/extensions/manifest_handlers/ui_overrides_handler.h" | |
| 23 #include "extensions/browser/extension_registry.h" | 26 #include "extensions/browser/extension_registry.h" |
| 24 #include "extensions/common/extension.h" | 27 #include "extensions/common/extension.h" |
| 25 #include "ui/accessibility/ax_view_state.h" | 28 #include "ui/accessibility/ax_view_state.h" |
| 26 #include "ui/events/event.h" | 29 #include "ui/events/event.h" |
| 27 #include "ui/gfx/canvas.h" | 30 #include "ui/gfx/canvas.h" |
| 28 #include "ui/gfx/image/image.h" | 31 #include "ui/gfx/image/image.h" |
| 29 #include "ui/views/controls/menu/menu_runner.h" | 32 #include "ui/views/controls/menu/menu_runner.h" |
| 30 | 33 |
| 31 using content::WebContents; | 34 using content::WebContents; |
| 32 using extensions::LocationBarController; | 35 using extensions::LocationBarController; |
| (...skipping 21 matching lines...) Expand all Loading... | |
| 54 set_context_menu_controller(this); | 57 set_context_menu_controller(this); |
| 55 | 58 |
| 56 extensions::CommandService* command_service = | 59 extensions::CommandService* command_service = |
| 57 extensions::CommandService::Get(browser_->profile()); | 60 extensions::CommandService::Get(browser_->profile()); |
| 58 extensions::Command page_action_command; | 61 extensions::Command page_action_command; |
| 59 if (command_service->GetPageActionCommand( | 62 if (command_service->GetPageActionCommand( |
| 60 extension->id(), | 63 extension->id(), |
| 61 extensions::CommandService::ACTIVE_ONLY, | 64 extensions::CommandService::ACTIVE_ONLY, |
| 62 &page_action_command, | 65 &page_action_command, |
| 63 NULL)) { | 66 NULL)) { |
| 67 ui::AcceleratorManager::HandlerPriority priority = | |
| 68 ui::AcceleratorManager::kHighPriority; | |
| 69 // Extensions overriding the bookmark shortcut need normal priority to | |
| 70 // preserve the built-in processing order of the key and not override | |
| 71 // WebContents key handling. | |
| 72 if (page_action_command.accelerator() == | |
| 73 chrome::GetPrimaryChromeAcceleratorForCommandId(IDC_BOOKMARK_PAGE) && | |
| 74 extensions::UIOverrides::RemovesBookmarkShortcut(extension)) { | |
| 75 priority = ui::AcceleratorManager::kNormalPriority; | |
| 76 } | |
| 64 page_action_keybinding_.reset( | 77 page_action_keybinding_.reset( |
| 65 new ui::Accelerator(page_action_command.accelerator())); | 78 new ui::Accelerator(page_action_command.accelerator())); |
| 66 owner_->GetFocusManager()->RegisterAccelerator( | 79 owner_->GetFocusManager()->RegisterAccelerator( |
| 67 *page_action_keybinding_.get(), | 80 *page_action_keybinding_.get(), |
| 68 ui::AcceleratorManager::kHighPriority, | 81 priority, |
|
Finnur
2014/07/02 11:56:16
Same here, and below. Lots of opportunities to sim
Mike Wittman
2014/07/02 21:56:19
Done.
| |
| 69 this); | 82 this); |
| 70 } | 83 } |
| 71 } | 84 } |
| 72 | 85 |
| 73 PageActionImageView::~PageActionImageView() { | 86 PageActionImageView::~PageActionImageView() { |
| 74 if (owner_->GetFocusManager()) { | 87 if (owner_->GetFocusManager()) { |
| 75 if (page_action_keybinding_.get()) { | 88 if (page_action_keybinding_.get()) { |
| 76 owner_->GetFocusManager()->UnregisterAccelerator( | 89 owner_->GetFocusManager()->UnregisterAccelerator( |
| 77 *page_action_keybinding_.get(), this); | 90 *page_action_keybinding_.get(), this); |
| 78 } | 91 } |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 170 views::MenuRunner::HAS_MNEMONICS | views::MenuRunner::CONTEXT_MENU) == | 183 views::MenuRunner::HAS_MNEMONICS | views::MenuRunner::CONTEXT_MENU) == |
| 171 views::MenuRunner::MENU_DELETED) { | 184 views::MenuRunner::MENU_DELETED) { |
| 172 return; | 185 return; |
| 173 } | 186 } |
| 174 } | 187 } |
| 175 | 188 |
| 176 bool PageActionImageView::AcceleratorPressed( | 189 bool PageActionImageView::AcceleratorPressed( |
| 177 const ui::Accelerator& accelerator) { | 190 const ui::Accelerator& accelerator) { |
| 178 DCHECK(visible()); // Should not have happened due to CanHandleAccelerator. | 191 DCHECK(visible()); // Should not have happened due to CanHandleAccelerator. |
| 179 | 192 |
| 193 // As a special case, if the extension removes and reassigns the bookmark | |
| 194 // shortcut we don't respond here but instead allow it to be handled by the | |
| 195 // standard browser command processing. This preserves the same shortcut key | |
| 196 // handling of Chrome's built-in bookmarking function, which can be overridden | |
| 197 // by key handling on web pages. | |
| 198 const extensions::Extension* extension = | |
| 199 extensions::ExtensionRegistry::Get(owner_->profile())-> | |
| 200 enabled_extensions().GetByID(page_action()->extension_id()); | |
|
Finnur
2014/07/02 11:56:16
Actually, I do wonder if we should have two Comman
Mike Wittman
2014/07/02 21:56:19
Done.
| |
| 201 if (accelerator == | |
| 202 chrome::GetPrimaryChromeAcceleratorForCommandId(IDC_BOOKMARK_PAGE) && | |
| 203 extensions::UIOverrides::RemovesBookmarkShortcut(extension)) { | |
| 204 return false; | |
| 205 } | |
| 206 | |
| 180 ExecuteAction(ExtensionPopup::SHOW); | 207 ExecuteAction(ExtensionPopup::SHOW); |
| 181 return true; | 208 return true; |
| 182 } | 209 } |
| 183 | 210 |
| 184 bool PageActionImageView::CanHandleAccelerators() const { | 211 bool PageActionImageView::CanHandleAccelerators() const { |
| 185 // While visible, we don't handle accelerators and while so we also don't | 212 // While visible, we don't handle accelerators and while so we also don't |
| 186 // count as a priority accelerator handler. | 213 // count as a priority accelerator handler. |
| 187 return visible(); | 214 return visible(); |
| 188 } | 215 } |
| 189 | 216 |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 253 | 280 |
| 254 popup_ = ExtensionPopup::ShowPopup(popup_url, browser_, this, arrow, | 281 popup_ = ExtensionPopup::ShowPopup(popup_url, browser_, this, arrow, |
| 255 show_action); | 282 show_action); |
| 256 popup_->GetWidget()->AddObserver(this); | 283 popup_->GetWidget()->AddObserver(this); |
| 257 } | 284 } |
| 258 | 285 |
| 259 void PageActionImageView::HidePopup() { | 286 void PageActionImageView::HidePopup() { |
| 260 if (popup_) | 287 if (popup_) |
| 261 popup_->GetWidget()->Close(); | 288 popup_->GetWidget()->Close(); |
| 262 } | 289 } |
| OLD | NEW |