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/browser_actions_container.h" | 5 #include "chrome/browser/ui/views/browser_actions_container.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/stl_util.h" | 8 #include "base/stl_util.h" |
9 #include "base/string_util.h" | 9 #include "base/string_util.h" |
10 #include "base/utf_string_conversions.h" | 10 #include "base/utf_string_conversions.h" |
11 #include "chrome/browser/extensions/extension_browser_event_router.h" | 11 #include "chrome/browser/extensions/extension_browser_event_router.h" |
12 #include "chrome/browser/extensions/extension_host.h" | 12 #include "chrome/browser/extensions/extension_host.h" |
13 #include "chrome/browser/extensions/extension_service.h" | 13 #include "chrome/browser/extensions/extension_service.h" |
14 #include "chrome/browser/extensions/extension_tabs_module.h" | 14 #include "chrome/browser/extensions/extension_tabs_module.h" |
15 #include "chrome/browser/profiles/profile.h" | 15 #include "chrome/browser/profiles/profile.h" |
16 #include "chrome/browser/sessions/restore_tab_helper.h" | 16 #include "chrome/browser/sessions/restore_tab_helper.h" |
17 #include "chrome/browser/ui/browser.h" | 17 #include "chrome/browser/ui/browser.h" |
18 #include "chrome/browser/ui/browser_window.h" | 18 #include "chrome/browser/ui/browser_window.h" |
19 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" | 19 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" |
20 #include "chrome/browser/ui/view_ids.h" | 20 #include "chrome/browser/ui/view_ids.h" |
21 #include "chrome/browser/ui/views/detachable_toolbar_view.h" | 21 #include "chrome/browser/ui/views/detachable_toolbar_view.h" |
22 #include "chrome/browser/ui/views/extensions/browser_action_drag_data.h" | 22 #include "chrome/browser/ui/views/extensions/browser_action_drag_data.h" |
23 #include "chrome/browser/ui/views/extensions/extension_popup.h" | 23 #include "chrome/browser/ui/views/extensions/extension_popup.h" |
24 #include "chrome/browser/ui/views/toolbar_view.h" | 24 #include "chrome/browser/ui/views/toolbar_view.h" |
25 #include "chrome/common/chrome_notification_types.h" | 25 #include "chrome/common/chrome_notification_types.h" |
| 26 #include "chrome/common/extensions/extension.h" |
26 #include "chrome/common/extensions/extension_action.h" | 27 #include "chrome/common/extensions/extension_action.h" |
27 #include "chrome/common/extensions/extension_resource.h" | 28 #include "chrome/common/extensions/extension_resource.h" |
28 #include "chrome/common/pref_names.h" | 29 #include "chrome/common/pref_names.h" |
29 #include "content/browser/renderer_host/render_view_host.h" | 30 #include "content/browser/renderer_host/render_view_host.h" |
30 #include "content/browser/renderer_host/render_widget_host_view.h" | 31 #include "content/browser/renderer_host/render_widget_host_view.h" |
31 #include "content/public/browser/notification_source.h" | 32 #include "content/public/browser/notification_source.h" |
32 #include "grit/generated_resources.h" | 33 #include "grit/generated_resources.h" |
33 #include "grit/theme_resources.h" | 34 #include "grit/theme_resources.h" |
34 #include "grit/theme_resources_standard.h" | 35 #include "grit/theme_resources_standard.h" |
35 #include "grit/ui_resources.h" | 36 #include "grit/ui_resources.h" |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
76 set_alignment(TextButton::ALIGN_CENTER); | 77 set_alignment(TextButton::ALIGN_CENTER); |
77 | 78 |
78 // No UpdateState() here because View hierarchy not setup yet. Our parent | 79 // No UpdateState() here because View hierarchy not setup yet. Our parent |
79 // should call UpdateState() after creation. | 80 // should call UpdateState() after creation. |
80 | 81 |
81 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_BROWSER_ACTION_UPDATED, | 82 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_BROWSER_ACTION_UPDATED, |
82 content::Source<ExtensionAction>(browser_action_)); | 83 content::Source<ExtensionAction>(browser_action_)); |
83 } | 84 } |
84 | 85 |
85 void BrowserActionButton::Destroy() { | 86 void BrowserActionButton::Destroy() { |
| 87 if (keybinding_.get() && panel_->GetFocusManager()) |
| 88 panel_->GetFocusManager()->UnregisterAccelerator(*keybinding_.get(), this); |
| 89 |
86 if (context_menu_) { | 90 if (context_menu_) { |
87 context_menu_->Cancel(); | 91 context_menu_->Cancel(); |
88 MessageLoop::current()->DeleteSoon(FROM_HERE, this); | 92 MessageLoop::current()->DeleteSoon(FROM_HERE, this); |
89 } else { | 93 } else { |
90 delete this; | 94 delete this; |
91 } | 95 } |
92 } | 96 } |
93 | 97 |
94 void BrowserActionButton::ViewHierarchyChanged( | 98 void BrowserActionButton::ViewHierarchyChanged( |
95 bool is_add, View* parent, View* child) { | 99 bool is_add, View* parent, View* child) { |
96 if (is_add && child == this) { | 100 if (is_add && child == this) { |
97 // The Browser Action API does not allow the default icon path to be | 101 // The Browser Action API does not allow the default icon path to be |
98 // changed at runtime, so we can load this now and cache it. | 102 // changed at runtime, so we can load this now and cache it. |
99 std::string relative_path = browser_action_->default_icon_path(); | 103 std::string relative_path = browser_action_->default_icon_path(); |
100 if (relative_path.empty()) | 104 if (relative_path.empty()) |
101 return; | 105 return; |
102 | 106 |
103 // LoadImage is not guaranteed to be synchronous, so we might see the | 107 // LoadImage is not guaranteed to be synchronous, so we might see the |
104 // callback OnImageLoaded execute immediately. It (through UpdateState) | 108 // callback OnImageLoaded execute immediately. It (through UpdateState) |
105 // expects parent() to return the owner for this button, so this | 109 // expects parent() to return the owner for this button, so this |
106 // function is as early as we can start this request. | 110 // function is as early as we can start this request. |
107 tracker_.LoadImage(extension_, extension_->GetResource(relative_path), | 111 tracker_.LoadImage(extension_, extension_->GetResource(relative_path), |
108 gfx::Size(Extension::kBrowserActionIconMaxSize, | 112 gfx::Size(Extension::kBrowserActionIconMaxSize, |
109 Extension::kBrowserActionIconMaxSize), | 113 Extension::kBrowserActionIconMaxSize), |
110 ImageLoadingTracker::DONT_CACHE); | 114 ImageLoadingTracker::DONT_CACHE); |
| 115 |
| 116 // Iterate through all the keybindings and see if one is assigned to the |
| 117 // browserAction. |
| 118 const std::vector<Extension::ExtensionKeybinding>& commands = |
| 119 extension_->keybindings(); |
| 120 for (size_t i = 0; i < commands.size(); ++i) { |
| 121 if (commands[i].command_name() == |
| 122 extension_manifest_values::kBrowserActionKeybindingEvent) { |
| 123 keybinding_.reset(new ui::Accelerator(commands[i].accelerator())); |
| 124 panel_->GetFocusManager()->RegisterAccelerator( |
| 125 *keybinding_.get(), ui::AcceleratorManager::kHighPriority, this); |
| 126 break; |
| 127 } |
| 128 } |
111 } | 129 } |
112 | 130 |
113 MenuButton::ViewHierarchyChanged(is_add, parent, child); | 131 MenuButton::ViewHierarchyChanged(is_add, parent, child); |
114 } | 132 } |
115 | 133 |
116 void BrowserActionButton::ButtonPressed(views::Button* sender, | 134 void BrowserActionButton::ButtonPressed(views::Button* sender, |
117 const views::Event& event) { | 135 const views::Event& event) { |
118 panel_->OnBrowserActionExecuted(this, false); | 136 panel_->OnBrowserActionExecuted(this, false); |
119 } | 137 } |
120 | 138 |
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
264 views::View::ConvertPointToScreen(this, &screen_loc); | 282 views::View::ConvertPointToScreen(this, &screen_loc); |
265 if (menu_runner.RunMenuAt(GetWidget(), NULL, gfx::Rect(screen_loc, size()), | 283 if (menu_runner.RunMenuAt(GetWidget(), NULL, gfx::Rect(screen_loc, size()), |
266 views::MenuItemView::TOPLEFT, views::MenuRunner::HAS_MNEMONICS) == | 284 views::MenuItemView::TOPLEFT, views::MenuRunner::HAS_MNEMONICS) == |
267 views::MenuRunner::MENU_DELETED) | 285 views::MenuRunner::MENU_DELETED) |
268 return; | 286 return; |
269 | 287 |
270 SetButtonNotPushed(); | 288 SetButtonNotPushed(); |
271 context_menu_ = NULL; | 289 context_menu_ = NULL; |
272 } | 290 } |
273 | 291 |
| 292 bool BrowserActionButton::AcceleratorPressed( |
| 293 const ui::Accelerator& accelerator) { |
| 294 panel_->OnBrowserActionExecuted(this, false); |
| 295 return true; |
| 296 } |
| 297 |
274 void BrowserActionButton::SetButtonPushed() { | 298 void BrowserActionButton::SetButtonPushed() { |
275 SetState(views::CustomButton::BS_PUSHED); | 299 SetState(views::CustomButton::BS_PUSHED); |
276 menu_visible_ = true; | 300 menu_visible_ = true; |
277 } | 301 } |
278 | 302 |
279 void BrowserActionButton::SetButtonNotPushed() { | 303 void BrowserActionButton::SetButtonNotPushed() { |
280 SetState(views::CustomButton::BS_NORMAL); | 304 SetState(views::CustomButton::BS_NORMAL); |
281 menu_visible_ = false; | 305 menu_visible_ = false; |
282 } | 306 } |
283 | 307 |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
352 View* owner_view) | 376 View* owner_view) |
353 : profile_(browser->profile()), | 377 : profile_(browser->profile()), |
354 browser_(browser), | 378 browser_(browser), |
355 owner_view_(owner_view), | 379 owner_view_(owner_view), |
356 popup_(NULL), | 380 popup_(NULL), |
357 popup_button_(NULL), | 381 popup_button_(NULL), |
358 model_(NULL), | 382 model_(NULL), |
359 container_width_(0), | 383 container_width_(0), |
360 chevron_(NULL), | 384 chevron_(NULL), |
361 overflow_menu_(NULL), | 385 overflow_menu_(NULL), |
| 386 extension_keybinding_registry_(browser->profile(), |
| 387 owner_view->GetFocusManager()), |
362 suppress_chevron_(false), | 388 suppress_chevron_(false), |
363 resize_amount_(0), | 389 resize_amount_(0), |
364 animation_target_size_(0), | 390 animation_target_size_(0), |
365 drop_indicator_position_(-1), | 391 drop_indicator_position_(-1), |
366 ALLOW_THIS_IN_INITIALIZER_LIST(task_factory_(this)), | 392 ALLOW_THIS_IN_INITIALIZER_LIST(task_factory_(this)), |
367 ALLOW_THIS_IN_INITIALIZER_LIST(show_menu_task_factory_(this)) { | 393 ALLOW_THIS_IN_INITIALIZER_LIST(show_menu_task_factory_(this)) { |
368 set_id(VIEW_ID_BROWSER_ACTION_TOOLBAR); | 394 set_id(VIEW_ID_BROWSER_ACTION_TOOLBAR); |
369 | 395 |
370 if (profile_->GetExtensionService()) { | 396 if (profile_->GetExtensionService()) { |
371 model_ = profile_->GetExtensionService()->toolbar_model(); | 397 model_ = profile_->GetExtensionService()->toolbar_model(); |
(...skipping 722 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1094 } | 1120 } |
1095 } | 1121 } |
1096 | 1122 |
1097 bool BrowserActionsContainer::ShouldDisplayBrowserAction( | 1123 bool BrowserActionsContainer::ShouldDisplayBrowserAction( |
1098 const Extension* extension) { | 1124 const Extension* extension) { |
1099 // Only display incognito-enabled extensions while in incognito mode. | 1125 // Only display incognito-enabled extensions while in incognito mode. |
1100 return | 1126 return |
1101 (!profile_->IsOffTheRecord() || | 1127 (!profile_->IsOffTheRecord() || |
1102 profile_->GetExtensionService()->IsIncognitoEnabled(extension->id())); | 1128 profile_->GetExtensionService()->IsIncognitoEnabled(extension->id())); |
1103 } | 1129 } |
OLD | NEW |