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

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

Issue 7574021: Remove frontend code that allows for dynamic profile setting, and read the profile off the browse... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 9 years, 4 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) 2011 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/platform_util.h" 10 #include "chrome/browser/platform_util.h"
11 #include "chrome/browser/profiles/profile.h" 11 #include "chrome/browser/profiles/profile.h"
12 #include "chrome/browser/ui/browser_list.h" 12 #include "chrome/browser/ui/browser_list.h"
13 #include "chrome/browser/ui/views/frame/browser_view.h" 13 #include "chrome/browser/ui/views/frame/browser_view.h"
14 #include "chrome/browser/ui/views/location_bar/location_bar_view.h" 14 #include "chrome/browser/ui/views/location_bar/location_bar_view.h"
15 #include "chrome/common/extensions/extension_action.h" 15 #include "chrome/common/extensions/extension_action.h"
16 #include "chrome/common/extensions/extension_resource.h" 16 #include "chrome/common/extensions/extension_resource.h"
17 #include "ui/base/accessibility/accessible_view_state.h" 17 #include "ui/base/accessibility/accessible_view_state.h"
18 #include "views/controls/menu/menu_item_view.h" 18 #include "views/controls/menu/menu_item_view.h"
19 #include "views/controls/menu/menu_model_adapter.h" 19 #include "views/controls/menu/menu_model_adapter.h"
20 20
21 PageActionImageView::PageActionImageView(LocationBarView* owner, 21 PageActionImageView::PageActionImageView(LocationBarView* owner,
22 Profile* profile,
23 ExtensionAction* page_action) 22 ExtensionAction* page_action)
24 : owner_(owner), 23 : owner_(owner),
25 profile_(profile),
26 page_action_(page_action), 24 page_action_(page_action),
27 ALLOW_THIS_IN_INITIALIZER_LIST(tracker_(this)), 25 ALLOW_THIS_IN_INITIALIZER_LIST(tracker_(this)),
28 current_tab_id_(-1), 26 current_tab_id_(-1),
29 preview_enabled_(false), 27 preview_enabled_(false),
30 popup_(NULL) { 28 popup_(NULL) {
31 const Extension* extension = profile->GetExtensionService()-> 29 const Extension* extension = owner_->browser()->profile()->
32 GetExtensionById(page_action->extension_id(), false); 30 GetExtensionService()->GetExtensionById(page_action->extension_id(),
31 false);
33 DCHECK(extension); 32 DCHECK(extension);
34 33
35 // Load all the icons declared in the manifest. This is the contents of the 34 // Load all the icons declared in the manifest. This is the contents of the
36 // icons array, plus the default_icon property, if any. 35 // icons array, plus the default_icon property, if any.
37 std::vector<std::string> icon_paths(*page_action->icon_paths()); 36 std::vector<std::string> icon_paths(*page_action->icon_paths());
38 if (!page_action_->default_icon_path().empty()) 37 if (!page_action_->default_icon_path().empty())
39 icon_paths.push_back(page_action_->default_icon_path()); 38 icon_paths.push_back(page_action_->default_icon_path());
40 39
41 for (std::vector<std::string>::iterator iter = icon_paths.begin(); 40 for (std::vector<std::string>::iterator iter = icon_paths.begin();
42 iter != icon_paths.end(); ++iter) { 41 iter != icon_paths.end(); ++iter) {
(...skipping 12 matching lines...) Expand all
55 } 54 }
56 55
57 void PageActionImageView::ExecuteAction(int button, 56 void PageActionImageView::ExecuteAction(int button,
58 bool inspect_with_devtools) { 57 bool inspect_with_devtools) {
59 if (current_tab_id_ < 0) { 58 if (current_tab_id_ < 0) {
60 NOTREACHED() << "No current tab."; 59 NOTREACHED() << "No current tab.";
61 return; 60 return;
62 } 61 }
63 62
64 if (page_action_->HasPopup(current_tab_id_)) { 63 if (page_action_->HasPopup(current_tab_id_)) {
65 // In tests, GetLastActive could return NULL, so we need to have
66 // a fallback.
67 // TODO(erikkay): Find a better way to get the Browser that this
68 // button is in.
69 Browser* browser = BrowserList::GetLastActiveWithProfile(profile_);
70 if (!browser)
71 browser = BrowserList::FindBrowserWithProfile(profile_);
72 DCHECK(browser);
73
74 bool popup_showing = popup_ != NULL; 64 bool popup_showing = popup_ != NULL;
75 65
76 // Always hide the current popup. Only one popup at a time. 66 // Always hide the current popup. Only one popup at a time.
77 HidePopup(); 67 HidePopup();
78 68
79 // If we were already showing, then treat this click as a dismiss. 69 // If we were already showing, then treat this click as a dismiss.
80 if (popup_showing) 70 if (popup_showing)
81 return; 71 return;
82 72
83 gfx::Rect screen_bounds(GetImageBounds()); 73 gfx::Rect screen_bounds(GetImageBounds());
84 gfx::Point origin(screen_bounds.origin()); 74 gfx::Point origin(screen_bounds.origin());
85 View::ConvertPointToScreen(this, &origin); 75 View::ConvertPointToScreen(this, &origin);
86 screen_bounds.set_origin(origin); 76 screen_bounds.set_origin(origin);
87 77
88 BubbleBorder::ArrowLocation arrow_location = base::i18n::IsRTL() ? 78 BubbleBorder::ArrowLocation arrow_location = base::i18n::IsRTL() ?
89 BubbleBorder::TOP_LEFT : BubbleBorder::TOP_RIGHT; 79 BubbleBorder::TOP_LEFT : BubbleBorder::TOP_RIGHT;
90 80
91 popup_ = ExtensionPopup::Show( 81 popup_ = ExtensionPopup::Show(
92 page_action_->GetPopupUrl(current_tab_id_), 82 page_action_->GetPopupUrl(current_tab_id_),
93 browser, 83 owner_->browser(),
94 screen_bounds, 84 screen_bounds,
95 arrow_location, 85 arrow_location,
96 inspect_with_devtools, 86 inspect_with_devtools,
97 this); // ExtensionPopup::Observer 87 this); // ExtensionPopup::Observer
98 } else { 88 } else {
99 ExtensionService* service = profile_->GetExtensionService(); 89 Profile* profile = owner_->browser()->profile();
90 ExtensionService* service = profile->GetExtensionService();
100 service->browser_event_router()->PageActionExecuted( 91 service->browser_event_router()->PageActionExecuted(
101 profile_, page_action_->extension_id(), page_action_->id(), 92 profile, page_action_->extension_id(), page_action_->id(),
102 current_tab_id_, current_url_.spec(), button); 93 current_tab_id_, current_url_.spec(), button);
103 } 94 }
104 } 95 }
105 96
106 void PageActionImageView::GetAccessibleState(ui::AccessibleViewState* state) { 97 void PageActionImageView::GetAccessibleState(ui::AccessibleViewState* state) {
107 state->role = ui::AccessibilityTypes::ROLE_PUSHBUTTON; 98 state->role = ui::AccessibilityTypes::ROLE_PUSHBUTTON;
108 state->name = UTF8ToUTF16(tooltip_); 99 state->name = UTF8ToUTF16(tooltip_);
109 } 100 }
110 101
111 bool PageActionImageView::OnMousePressed(const views::MouseEvent& event) { 102 bool PageActionImageView::OnMousePressed(const views::MouseEvent& event) {
(...skipping 24 matching lines...) Expand all
136 if (event.key_code() == ui::VKEY_SPACE || 127 if (event.key_code() == ui::VKEY_SPACE ||
137 event.key_code() == ui::VKEY_RETURN) { 128 event.key_code() == ui::VKEY_RETURN) {
138 ExecuteAction(1, false); 129 ExecuteAction(1, false);
139 return true; 130 return true;
140 } 131 }
141 return false; 132 return false;
142 } 133 }
143 134
144 void PageActionImageView::ShowContextMenu(const gfx::Point& p, 135 void PageActionImageView::ShowContextMenu(const gfx::Point& p,
145 bool is_mouse_gesture) { 136 bool is_mouse_gesture) {
146 const Extension* extension = profile_->GetExtensionService()-> 137 const Extension* extension = owner_->browser()->profile()->
147 GetExtensionById(page_action()->extension_id(), false); 138 GetExtensionService()->GetExtensionById(page_action()->extension_id(),
139 false);
148 if (!extension->ShowConfigureContextMenus()) 140 if (!extension->ShowConfigureContextMenus())
149 return; 141 return;
150 142
151 Browser* browser = BrowserView::GetBrowserViewForNativeWindow(
152 platform_util::GetTopLevel(GetWidget()->GetNativeView()))->browser();
153
154 scoped_refptr<ExtensionContextMenuModel> context_menu_model( 143 scoped_refptr<ExtensionContextMenuModel> context_menu_model(
155 new ExtensionContextMenuModel(extension, browser, this)); 144 new ExtensionContextMenuModel(extension, owner_->browser(), this));
156 views::MenuModelAdapter menu_model_adapter(context_menu_model.get()); 145 views::MenuModelAdapter menu_model_adapter(context_menu_model.get());
157 views::MenuItemView menu(&menu_model_adapter); 146 views::MenuItemView menu(&menu_model_adapter);
158 menu_model_adapter.BuildMenu(&menu); 147 menu_model_adapter.BuildMenu(&menu);
159 148
160 gfx::Point screen_loc; 149 gfx::Point screen_loc;
161 views::View::ConvertPointToScreen(this, &screen_loc); 150 views::View::ConvertPointToScreen(this, &screen_loc);
162 menu.RunMenuAt(GetWidget(), NULL, gfx::Rect(screen_loc ,size()), 151 menu.RunMenuAt(GetWidget(), NULL, gfx::Rect(screen_loc, size()),
163 views::MenuItemView::TOPLEFT, true); 152 views::MenuItemView::TOPLEFT, true);
164 } 153 }
165 154
166 void PageActionImageView::OnImageLoaded( 155 void PageActionImageView::OnImageLoaded(
167 SkBitmap* image, const ExtensionResource& resource, int index) { 156 SkBitmap* image, const ExtensionResource& resource, int index) {
168 // We loaded icons()->size() icons, plus one extra if the page action had 157 // We loaded icons()->size() icons, plus one extra if the page action had
169 // a default icon. 158 // a default icon.
170 int total_icons = static_cast<int>(page_action_->icon_paths()->size()); 159 int total_icons = static_cast<int>(page_action_->icon_paths()->size());
171 if (!page_action_->default_icon_path().empty()) 160 if (!page_action_->default_icon_path().empty())
172 total_icons++; 161 total_icons++;
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
241 void PageActionImageView::ExtensionPopupIsClosing(ExtensionPopup* popup) { 230 void PageActionImageView::ExtensionPopupIsClosing(ExtensionPopup* popup) {
242 DCHECK_EQ(popup_, popup); 231 DCHECK_EQ(popup_, popup);
243 // ExtensionPopup is ref-counted, so we don't need to delete it. 232 // ExtensionPopup is ref-counted, so we don't need to delete it.
244 popup_ = NULL; 233 popup_ = NULL;
245 } 234 }
246 235
247 void PageActionImageView::HidePopup() { 236 void PageActionImageView::HidePopup() {
248 if (popup_) 237 if (popup_)
249 popup_->Close(); 238 popup_->Close();
250 } 239 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698