Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(467)

Side by Side Diff: chrome/browser/ui/views/location_bar/page_action_image_view.cc

Issue 9402018: Experimental Extension Keybinding (first cut). (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 8 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 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/extension_browser_event_router.h" 8 #include "chrome/browser/extensions/extension_browser_event_router.h"
9 #include "chrome/browser/extensions/extension_service.h" 9 #include "chrome/browser/extensions/extension_service.h"
10 #include "chrome/browser/extensions/extension_tab_util.h" 10 #include "chrome/browser/extensions/extension_tab_util.h"
11 #include "chrome/browser/platform_util.h" 11 #include "chrome/browser/platform_util.h"
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
51 gfx::Size(Extension::kPageActionIconMaxSize, 51 gfx::Size(Extension::kPageActionIconMaxSize,
52 Extension::kPageActionIconMaxSize), 52 Extension::kPageActionIconMaxSize),
53 ImageLoadingTracker::DONT_CACHE); 53 ImageLoadingTracker::DONT_CACHE);
54 } 54 }
55 55
56 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UNLOADED, 56 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UNLOADED,
57 content::Source<Profile>( 57 content::Source<Profile>(
58 owner_->browser()->profile()->GetOriginalProfile())); 58 owner_->browser()->profile()->GetOriginalProfile()));
59 59
60 set_accessibility_focusable(true); 60 set_accessibility_focusable(true);
61
62 // Iterate through all the keybindings and see if one is assigned to the
63 // pageAction.
64 const std::vector<Extension::ExtensionKeybinding>& commands =
65 extension->keybindings();
66 for (size_t i = 0; i < commands.size(); ++i) {
67 if (commands[i].command_name() ==
68 extension_manifest_values::kPageActionKeybindingEvent) {
69 keybinding_.reset(new ui::Accelerator(commands[i].accelerator()));
70 owner_->GetFocusManager()->RegisterAccelerator(
71 *keybinding_.get(), ui::AcceleratorManager::kHighPriority, this);
72 break;
73 }
74 }
61 } 75 }
62 76
63 PageActionImageView::~PageActionImageView() { 77 PageActionImageView::~PageActionImageView() {
78 if (keybinding_.get() && owner_->GetFocusManager())
79 owner_->GetFocusManager()->UnregisterAccelerator(*keybinding_.get(), this);
80
64 if (popup_) 81 if (popup_)
65 popup_->GetWidget()->RemoveObserver(this); 82 popup_->GetWidget()->RemoveObserver(this);
66 HidePopup(); 83 HidePopup();
67 } 84 }
68 85
69 void PageActionImageView::ExecuteAction(int button, 86 void PageActionImageView::ExecuteAction(int button,
70 bool inspect_with_devtools) { 87 bool inspect_with_devtools) {
71 if (current_tab_id_ < 0) { 88 if (current_tab_id_ < 0) {
72 NOTREACHED() << "No current tab."; 89 NOTREACHED() << "No current tab.";
73 return; 90 return;
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
178 page_action_icons_[page_action_->default_icon_path()] = *image; 195 page_action_icons_[page_action_->default_icon_path()] = *image;
179 } 196 }
180 197
181 // During object construction (before the parent has been set) we are already 198 // During object construction (before the parent has been set) we are already
182 // in a UpdatePageActions call, so we don't need to start another one (and 199 // in a UpdatePageActions call, so we don't need to start another one (and
183 // doing so causes crash described in http://crbug.com/57333). 200 // doing so causes crash described in http://crbug.com/57333).
184 if (parent()) 201 if (parent())
185 owner_->UpdatePageActions(); 202 owner_->UpdatePageActions();
186 } 203 }
187 204
205 bool PageActionImageView::AcceleratorPressed(
206 const ui::Accelerator& accelerator) {
207 DCHECK(visible()); // Should not have happened due to CanHandleAccelerator.
208
209 ExecuteAction(1, false); // 1 means left-click, false means "don't inspect".
210 return true;
211 }
212
213 bool PageActionImageView::CanHandleAccelerators() const {
214 // While visible, we don't handle accelerators and while so we also don't
215 // count as a priority accelerator handler.
216 return visible();
217 }
218
188 void PageActionImageView::UpdateVisibility(WebContents* contents, 219 void PageActionImageView::UpdateVisibility(WebContents* contents,
189 const GURL& url) { 220 const GURL& url) {
190 // Save this off so we can pass it back to the extension when the action gets 221 // Save this off so we can pass it back to the extension when the action gets
191 // executed. See PageActionImageView::OnMousePressed. 222 // executed. See PageActionImageView::OnMousePressed.
192 current_tab_id_ = contents ? ExtensionTabUtil::GetTabId(contents) : -1; 223 current_tab_id_ = contents ? ExtensionTabUtil::GetTabId(contents) : -1;
193 current_url_ = url; 224 current_url_ = url;
194 225
195 if (!contents || 226 if (!contents ||
196 (!preview_enabled_ && !page_action_->GetIsVisible(current_tab_id_))) { 227 (!preview_enabled_ && !page_action_->GetIsVisible(current_tab_id_))) {
197 SetVisible(false); 228 SetVisible(false);
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
248 const Extension* unloaded_extension = 279 const Extension* unloaded_extension =
249 content::Details<UnloadedExtensionInfo>(details)->extension; 280 content::Details<UnloadedExtensionInfo>(details)->extension;
250 if (page_action_ == unloaded_extension ->page_action()) 281 if (page_action_ == unloaded_extension ->page_action())
251 owner_->UpdatePageActions(); 282 owner_->UpdatePageActions();
252 } 283 }
253 284
254 void PageActionImageView::HidePopup() { 285 void PageActionImageView::HidePopup() {
255 if (popup_) 286 if (popup_)
256 popup_->GetWidget()->Close(); 287 popup_->GetWidget()->Close();
257 } 288 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/views/location_bar/page_action_image_view.h ('k') | chrome/chrome_browser.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698