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/utf_string_conversions.h" | 7 #include "base/utf_string_conversions.h" |
8 #include "chrome/browser/extensions/api/commands/command_service.h" | 8 #include "chrome/browser/extensions/api/commands/command_service.h" |
9 #include "chrome/browser/extensions/api/commands/command_service_factory.h" | 9 #include "chrome/browser/extensions/api/commands/command_service_factory.h" |
10 #include "chrome/browser/extensions/extension_context_menu_model.h" | 10 #include "chrome/browser/extensions/extension_context_menu_model.h" |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
77 | 77 |
78 extensions::CommandService* command_service = | 78 extensions::CommandService* command_service = |
79 extensions::CommandServiceFactory::GetForProfile( | 79 extensions::CommandServiceFactory::GetForProfile( |
80 browser_->profile()); | 80 browser_->profile()); |
81 extensions::Command page_action_command; | 81 extensions::Command page_action_command; |
82 if (command_service->GetPageActionCommand( | 82 if (command_service->GetPageActionCommand( |
83 extension->id(), | 83 extension->id(), |
84 extensions::CommandService::ACTIVE_ONLY, | 84 extensions::CommandService::ACTIVE_ONLY, |
85 &page_action_command, | 85 &page_action_command, |
86 NULL)) { | 86 NULL)) { |
87 keybinding_.reset(new ui::Accelerator(page_action_command.accelerator())); | 87 page_action_keybinding_.reset( |
| 88 new ui::Accelerator(page_action_command.accelerator())); |
88 owner_->GetFocusManager()->RegisterAccelerator( | 89 owner_->GetFocusManager()->RegisterAccelerator( |
89 *keybinding_.get(), ui::AcceleratorManager::kHighPriority, this); | 90 *page_action_keybinding_.get(), |
| 91 ui::AcceleratorManager::kHighPriority, |
| 92 this); |
| 93 } |
| 94 |
| 95 extensions::Command script_badge_command; |
| 96 if (command_service->GetScriptBadgeCommand( |
| 97 extension->id(), |
| 98 extensions::CommandService::ACTIVE_ONLY, |
| 99 &script_badge_command, |
| 100 NULL)) { |
| 101 |
| 102 script_badge_keybinding_.reset( |
| 103 new ui::Accelerator(script_badge_command.accelerator())); |
| 104 owner_->GetFocusManager()->RegisterAccelerator( |
| 105 *script_badge_keybinding_.get(), |
| 106 ui::AcceleratorManager::kHighPriority, |
| 107 this); |
90 } | 108 } |
91 } | 109 } |
92 | 110 |
93 PageActionImageView::~PageActionImageView() { | 111 PageActionImageView::~PageActionImageView() { |
94 if (keybinding_.get() && owner_->GetFocusManager()) | 112 if (owner_->GetFocusManager()) { |
95 owner_->GetFocusManager()->UnregisterAccelerator(*keybinding_.get(), this); | 113 if (page_action_keybinding_.get()) { |
| 114 owner_->GetFocusManager()->UnregisterAccelerator( |
| 115 *page_action_keybinding_.get(), this); |
| 116 } |
| 117 |
| 118 if (script_badge_keybinding_.get()) { |
| 119 owner_->GetFocusManager()->UnregisterAccelerator( |
| 120 *script_badge_keybinding_.get(), this); |
| 121 } |
| 122 } |
96 | 123 |
97 if (popup_) | 124 if (popup_) |
98 popup_->GetWidget()->RemoveObserver(this); | 125 popup_->GetWidget()->RemoveObserver(this); |
99 HidePopup(); | 126 HidePopup(); |
100 } | 127 } |
101 | 128 |
102 void PageActionImageView::ExecuteAction(int button) { | 129 void PageActionImageView::ExecuteAction(int button) { |
103 TabContents* tab_contents = owner_->GetTabContents(); | 130 TabContents* tab_contents = owner_->GetTabContents(); |
104 if (!tab_contents) | 131 if (!tab_contents) |
105 return; | 132 return; |
(...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
316 views::BubbleBorder::TOP_LEFT : views::BubbleBorder::TOP_RIGHT; | 343 views::BubbleBorder::TOP_LEFT : views::BubbleBorder::TOP_RIGHT; |
317 | 344 |
318 popup_ = ExtensionPopup::ShowPopup(popup_url, browser_, this, arrow_location); | 345 popup_ = ExtensionPopup::ShowPopup(popup_url, browser_, this, arrow_location); |
319 popup_->GetWidget()->AddObserver(this); | 346 popup_->GetWidget()->AddObserver(this); |
320 } | 347 } |
321 | 348 |
322 void PageActionImageView::HidePopup() { | 349 void PageActionImageView::HidePopup() { |
323 if (popup_) | 350 if (popup_) |
324 popup_->GetWidget()->Close(); | 351 popup_->GetWidget()->Close(); |
325 } | 352 } |
OLD | NEW |