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 script_badge_keybinding_.reset( |
| 102 new ui::Accelerator(script_badge_command.accelerator())); |
| 103 owner_->GetFocusManager()->RegisterAccelerator( |
| 104 *script_badge_keybinding_.get(), |
| 105 ui::AcceleratorManager::kHighPriority, |
| 106 this); |
90 } | 107 } |
91 } | 108 } |
92 | 109 |
93 PageActionImageView::~PageActionImageView() { | 110 PageActionImageView::~PageActionImageView() { |
94 if (keybinding_.get() && owner_->GetFocusManager()) | 111 if (owner_->GetFocusManager()) { |
95 owner_->GetFocusManager()->UnregisterAccelerator(*keybinding_.get(), this); | 112 if (page_action_keybinding_.get()) { |
| 113 owner_->GetFocusManager()->UnregisterAccelerator( |
| 114 *page_action_keybinding_.get(), this); |
| 115 } |
| 116 |
| 117 if (script_badge_keybinding_.get()) { |
| 118 owner_->GetFocusManager()->UnregisterAccelerator( |
| 119 *script_badge_keybinding_.get(), this); |
| 120 } |
| 121 } |
96 | 122 |
97 if (popup_) | 123 if (popup_) |
98 popup_->GetWidget()->RemoveObserver(this); | 124 popup_->GetWidget()->RemoveObserver(this); |
99 HidePopup(); | 125 HidePopup(); |
100 } | 126 } |
101 | 127 |
102 void PageActionImageView::ExecuteAction(int button) { | 128 void PageActionImageView::ExecuteAction(int button) { |
103 TabContents* tab_contents = owner_->GetTabContents(); | 129 TabContents* tab_contents = owner_->GetTabContents(); |
104 if (!tab_contents) | 130 if (!tab_contents) |
105 return; | 131 return; |
(...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
316 views::BubbleBorder::TOP_LEFT : views::BubbleBorder::TOP_RIGHT; | 342 views::BubbleBorder::TOP_LEFT : views::BubbleBorder::TOP_RIGHT; |
317 | 343 |
318 popup_ = ExtensionPopup::ShowPopup(popup_url, browser_, this, arrow_location); | 344 popup_ = ExtensionPopup::ShowPopup(popup_url, browser_, this, arrow_location); |
319 popup_->GetWidget()->AddObserver(this); | 345 popup_->GetWidget()->AddObserver(this); |
320 } | 346 } |
321 | 347 |
322 void PageActionImageView::HidePopup() { | 348 void PageActionImageView::HidePopup() { |
323 if (popup_) | 349 if (popup_) |
324 popup_->GetWidget()->Close(); | 350 popup_->GetWidget()->Close(); |
325 } | 351 } |
OLD | NEW |