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

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

Issue 9479008: Re-factor location bar/toolbar code to get rid of the browser dependency. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: call right overloaded method Created 8 years, 9 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) 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/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"
12 #include "chrome/browser/profiles/profile.h" 12 #include "chrome/browser/profiles/profile.h"
13 #include "chrome/browser/ui/browser_list.h" 13 #include "chrome/browser/ui/browser_list.h"
14 #include "chrome/browser/ui/views/frame/browser_view.h" 14 #include "chrome/browser/ui/views/frame/browser_view.h"
15 #include "chrome/browser/ui/views/location_bar/location_bar_view.h" 15 #include "chrome/browser/ui/views/location_bar/location_bar_view.h"
16 #include "chrome/common/chrome_notification_types.h" 16 #include "chrome/common/chrome_notification_types.h"
17 #include "chrome/common/extensions/extension.h" 17 #include "chrome/common/extensions/extension.h"
18 #include "chrome/common/extensions/extension_action.h" 18 #include "chrome/common/extensions/extension_action.h"
19 #include "chrome/common/extensions/extension_resource.h" 19 #include "chrome/common/extensions/extension_resource.h"
20 #include "content/public/browser/notification_details.h" 20 #include "content/public/browser/notification_details.h"
21 #include "content/public/browser/notification_source.h" 21 #include "content/public/browser/notification_source.h"
22 #include "ui/base/accessibility/accessible_view_state.h" 22 #include "ui/base/accessibility/accessible_view_state.h"
23 #include "ui/views/controls/menu/menu_item_view.h" 23 #include "ui/views/controls/menu/menu_item_view.h"
24 #include "ui/views/controls/menu/menu_model_adapter.h" 24 #include "ui/views/controls/menu/menu_model_adapter.h"
25 #include "ui/views/controls/menu/menu_runner.h" 25 #include "ui/views/controls/menu/menu_runner.h"
26 26
27 using content::WebContents; 27 using content::WebContents;
28 28
29 PageActionImageView::PageActionImageView(LocationBarView* owner, 29 PageActionImageView::PageActionImageView(LocationBarView* owner,
30 ExtensionAction* page_action) 30 ExtensionAction* page_action,
31 Browser* browser)
31 : owner_(owner), 32 : owner_(owner),
32 page_action_(page_action), 33 page_action_(page_action),
34 browser_(browser),
33 ALLOW_THIS_IN_INITIALIZER_LIST(tracker_(this)), 35 ALLOW_THIS_IN_INITIALIZER_LIST(tracker_(this)),
34 current_tab_id_(-1), 36 current_tab_id_(-1),
35 preview_enabled_(false), 37 preview_enabled_(false),
36 popup_(NULL) { 38 popup_(NULL) {
37 const Extension* extension = owner_->browser()->profile()-> 39 const Extension* extension = owner_->profile()->GetExtensionService()->
38 GetExtensionService()->GetExtensionById(page_action->extension_id(), 40 GetExtensionById(page_action->extension_id(), false);
39 false);
40 DCHECK(extension); 41 DCHECK(extension);
41 42
42 // Load all the icons declared in the manifest. This is the contents of the 43 // Load all the icons declared in the manifest. This is the contents of the
43 // icons array, plus the default_icon property, if any. 44 // icons array, plus the default_icon property, if any.
44 std::vector<std::string> icon_paths(*page_action->icon_paths()); 45 std::vector<std::string> icon_paths(*page_action->icon_paths());
45 if (!page_action_->default_icon_path().empty()) 46 if (!page_action_->default_icon_path().empty())
46 icon_paths.push_back(page_action_->default_icon_path()); 47 icon_paths.push_back(page_action_->default_icon_path());
47 48
48 for (std::vector<std::string>::iterator iter = icon_paths.begin(); 49 for (std::vector<std::string>::iterator iter = icon_paths.begin();
49 iter != icon_paths.end(); ++iter) { 50 iter != icon_paths.end(); ++iter) {
50 tracker_.LoadImage(extension, extension->GetResource(*iter), 51 tracker_.LoadImage(extension, extension->GetResource(*iter),
51 gfx::Size(Extension::kPageActionIconMaxSize, 52 gfx::Size(Extension::kPageActionIconMaxSize,
52 Extension::kPageActionIconMaxSize), 53 Extension::kPageActionIconMaxSize),
53 ImageLoadingTracker::DONT_CACHE); 54 ImageLoadingTracker::DONT_CACHE);
54 } 55 }
55 56
56 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UNLOADED, 57 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UNLOADED,
57 content::Source<Profile>( 58 content::Source<Profile>(
58 owner_->browser()->profile()->GetOriginalProfile())); 59 owner_->profile()->GetOriginalProfile()));
59 60
60 set_accessibility_focusable(true); 61 set_accessibility_focusable(true);
61 62
62 // Iterate through all the keybindings and see if one is assigned to the 63 // Iterate through all the keybindings and see if one is assigned to the
63 // pageAction. 64 // pageAction.
64 const std::vector<Extension::ExtensionKeybinding>& commands = 65 const std::vector<Extension::ExtensionKeybinding>& commands =
65 extension->keybindings(); 66 extension->keybindings();
66 for (size_t i = 0; i < commands.size(); ++i) { 67 for (size_t i = 0; i < commands.size(); ++i) {
67 if (commands[i].command_name() == 68 if (commands[i].command_name() ==
68 extension_manifest_values::kPageActionKeybindingEvent) { 69 extension_manifest_values::kPageActionKeybindingEvent) {
(...skipping 29 matching lines...) Expand all
98 99
99 // If we were already showing, then treat this click as a dismiss. 100 // If we were already showing, then treat this click as a dismiss.
100 if (popup_showing) 101 if (popup_showing)
101 return; 102 return;
102 103
103 views::BubbleBorder::ArrowLocation arrow_location = base::i18n::IsRTL() ? 104 views::BubbleBorder::ArrowLocation arrow_location = base::i18n::IsRTL() ?
104 views::BubbleBorder::TOP_LEFT : views::BubbleBorder::TOP_RIGHT; 105 views::BubbleBorder::TOP_LEFT : views::BubbleBorder::TOP_RIGHT;
105 106
106 popup_ = ExtensionPopup::ShowPopup( 107 popup_ = ExtensionPopup::ShowPopup(
107 page_action_->GetPopupUrl(current_tab_id_), 108 page_action_->GetPopupUrl(current_tab_id_),
108 owner_->browser(), 109 browser_,
109 this, 110 this,
110 arrow_location, 111 arrow_location,
111 inspect_with_devtools); 112 inspect_with_devtools);
112 popup_->GetWidget()->AddObserver(this); 113 popup_->GetWidget()->AddObserver(this);
113 } else { 114 } else {
114 Profile* profile = owner_->browser()->profile(); 115 Profile* profile = owner_->profile();
115 ExtensionService* service = profile->GetExtensionService(); 116 ExtensionService* service = profile->GetExtensionService();
116 service->browser_event_router()->PageActionExecuted( 117 service->browser_event_router()->PageActionExecuted(
117 profile, page_action_->extension_id(), page_action_->id(), 118 profile, page_action_->extension_id(), page_action_->id(),
118 current_tab_id_, current_url_.spec(), button); 119 current_tab_id_, current_url_.spec(), button);
119 } 120 }
120 } 121 }
121 122
122 void PageActionImageView::GetAccessibleState(ui::AccessibleViewState* state) { 123 void PageActionImageView::GetAccessibleState(ui::AccessibleViewState* state) {
123 state->role = ui::AccessibilityTypes::ROLE_PUSHBUTTON; 124 state->role = ui::AccessibilityTypes::ROLE_PUSHBUTTON;
124 state->name = UTF8ToUTF16(tooltip_); 125 state->name = UTF8ToUTF16(tooltip_);
(...skipping 27 matching lines...) Expand all
152 if (event.key_code() == ui::VKEY_SPACE || 153 if (event.key_code() == ui::VKEY_SPACE ||
153 event.key_code() == ui::VKEY_RETURN) { 154 event.key_code() == ui::VKEY_RETURN) {
154 ExecuteAction(1, false); 155 ExecuteAction(1, false);
155 return true; 156 return true;
156 } 157 }
157 return false; 158 return false;
158 } 159 }
159 160
160 void PageActionImageView::ShowContextMenu(const gfx::Point& p, 161 void PageActionImageView::ShowContextMenu(const gfx::Point& p,
161 bool is_mouse_gesture) { 162 bool is_mouse_gesture) {
162 const Extension* extension = owner_->browser()->profile()-> 163 const Extension* extension = owner_->profile()->GetExtensionService()->
163 GetExtensionService()->GetExtensionById(page_action()->extension_id(), 164 GetExtensionById(page_action()->extension_id(), false);
164 false);
165 if (!extension->ShowConfigureContextMenus()) 165 if (!extension->ShowConfigureContextMenus())
166 return; 166 return;
167 167
168 scoped_refptr<ExtensionContextMenuModel> context_menu_model( 168 scoped_refptr<ExtensionContextMenuModel> context_menu_model(
169 new ExtensionContextMenuModel(extension, owner_->browser(), this)); 169 new ExtensionContextMenuModel(extension, browser_, this));
170 views::MenuModelAdapter menu_model_adapter(context_menu_model.get()); 170 views::MenuModelAdapter menu_model_adapter(context_menu_model.get());
171 menu_runner_.reset(new views::MenuRunner(menu_model_adapter.CreateMenu())); 171 menu_runner_.reset(new views::MenuRunner(menu_model_adapter.CreateMenu()));
172 gfx::Point screen_loc; 172 gfx::Point screen_loc;
173 views::View::ConvertPointToScreen(this, &screen_loc); 173 views::View::ConvertPointToScreen(this, &screen_loc);
174 if (menu_runner_->RunMenuAt(GetWidget(), NULL, gfx::Rect(screen_loc, size()), 174 if (menu_runner_->RunMenuAt(GetWidget(), NULL, gfx::Rect(screen_loc, size()),
175 views::MenuItemView::TOPLEFT, views::MenuRunner::HAS_MNEMONICS) == 175 views::MenuItemView::TOPLEFT, views::MenuRunner::HAS_MNEMONICS) ==
176 views::MenuRunner::MENU_DELETED) 176 views::MenuRunner::MENU_DELETED)
177 return; 177 return;
178 } 178 }
179 179
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
281 const Extension* unloaded_extension = 281 const Extension* unloaded_extension =
282 content::Details<UnloadedExtensionInfo>(details)->extension; 282 content::Details<UnloadedExtensionInfo>(details)->extension;
283 if (page_action_ == unloaded_extension ->page_action()) 283 if (page_action_ == unloaded_extension ->page_action())
284 owner_->UpdatePageActions(); 284 owner_->UpdatePageActions();
285 } 285 }
286 286
287 void PageActionImageView::HidePopup() { 287 void PageActionImageView::HidePopup() {
288 if (popup_) 288 if (popup_)
289 popup_->GetWidget()->Close(); 289 popup_->GetWidget()->Close();
290 } 290 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/views/location_bar/page_action_image_view.h ('k') | chrome/browser/ui/views/omnibox/omnibox_view_win.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698