OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/toolbar/browser_action_view.h" | 5 #include "chrome/browser/ui/views/toolbar/browser_action_view.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "base/strings/utf_string_conversions.h" | |
10 #include "chrome/browser/chrome_notification_types.h" | 9 #include "chrome/browser/chrome_notification_types.h" |
11 #include "chrome/browser/extensions/extension_action.h" | |
12 #include "chrome/browser/profiles/profile.h" | 10 #include "chrome/browser/profiles/profile.h" |
| 11 #include "chrome/browser/sessions/session_tab_helper.h" |
13 #include "chrome/browser/themes/theme_service.h" | 12 #include "chrome/browser/themes/theme_service.h" |
14 #include "chrome/browser/themes/theme_service_factory.h" | 13 #include "chrome/browser/themes/theme_service_factory.h" |
15 #include "chrome/browser/ui/browser.h" | 14 #include "chrome/browser/ui/browser.h" |
| 15 #include "chrome/browser/ui/toolbar/toolbar_action_view_controller.h" |
16 #include "chrome/browser/ui/view_ids.h" | 16 #include "chrome/browser/ui/view_ids.h" |
17 #include "chrome/browser/ui/views/frame/browser_view.h" | 17 #include "chrome/browser/ui/views/frame/browser_view.h" |
18 #include "chrome/browser/ui/views/toolbar/browser_actions_container.h" | 18 #include "chrome/browser/ui/views/toolbar/browser_actions_container.h" |
19 #include "chrome/browser/ui/views/toolbar/toolbar_view.h" | 19 #include "chrome/browser/ui/views/toolbar/toolbar_view.h" |
20 #include "chrome/grit/generated_resources.h" | 20 #include "chrome/grit/generated_resources.h" |
21 #include "extensions/common/extension.h" | |
22 #include "extensions/common/manifest_constants.h" | |
23 #include "grit/theme_resources.h" | 21 #include "grit/theme_resources.h" |
24 #include "ui/accessibility/ax_view_state.h" | 22 #include "ui/accessibility/ax_view_state.h" |
25 #include "ui/base/l10n/l10n_util.h" | |
26 #include "ui/base/resource/resource_bundle.h" | |
27 #include "ui/events/event.h" | 23 #include "ui/events/event.h" |
28 #include "ui/gfx/image/image_skia.h" | 24 #include "ui/gfx/image/image_skia.h" |
29 #include "ui/gfx/image/image_skia_operations.h" | 25 #include "ui/gfx/image/image_skia_operations.h" |
30 #include "ui/gfx/image/image_skia_source.h" | 26 #include "ui/gfx/image/image_skia_source.h" |
31 #include "ui/views/controls/button/label_button_border.h" | 27 #include "ui/views/controls/button/label_button_border.h" |
32 | 28 |
33 using extensions::Extension; | |
34 using views::LabelButtonBorder; | 29 using views::LabelButtonBorder; |
35 | 30 |
36 namespace { | 31 namespace { |
37 | 32 |
38 // We have smaller insets than normal STYLE_TEXTBUTTON buttons so that we can | 33 // We have smaller insets than normal STYLE_TEXTBUTTON buttons so that we can |
39 // fit user supplied icons in without clipping them. | 34 // fit user supplied icons in without clipping them. |
40 const int kBorderInset = 4; | 35 const int kBorderInset = 4; |
41 | 36 |
42 } // namespace | 37 } // namespace |
43 | 38 |
44 //////////////////////////////////////////////////////////////////////////////// | 39 //////////////////////////////////////////////////////////////////////////////// |
45 // BrowserActionView | 40 // BrowserActionView |
46 | 41 |
47 BrowserActionView::BrowserActionView(const Extension* extension, | 42 BrowserActionView::BrowserActionView( |
48 ExtensionAction* extension_action, | 43 scoped_ptr<ToolbarActionViewController> view_controller, |
49 Browser* browser, | 44 Browser* browser, |
50 BrowserActionView::Delegate* delegate) | 45 BrowserActionView::Delegate* delegate) |
51 : MenuButton(this, base::string16(), NULL, false), | 46 : MenuButton(this, base::string16(), NULL, false), |
52 view_controller_(new ExtensionActionViewController( | 47 view_controller_(view_controller.Pass()), |
53 extension, | 48 browser_(browser), |
54 browser, | |
55 extension_action, | |
56 this)), | |
57 delegate_(delegate), | 49 delegate_(delegate), |
58 called_registered_extension_command_(false), | 50 called_register_command_(false) { |
59 icon_observer_(NULL) { | |
60 set_id(VIEW_ID_BROWSER_ACTION); | 51 set_id(VIEW_ID_BROWSER_ACTION); |
| 52 view_controller_->SetDelegate(this); |
61 SetHorizontalAlignment(gfx::ALIGN_CENTER); | 53 SetHorizontalAlignment(gfx::ALIGN_CENTER); |
62 set_context_menu_controller(view_controller_.get()); | 54 if (view_controller_->CanDrag()) |
63 set_drag_controller(delegate_); | 55 set_drag_controller(delegate_); |
64 | |
65 content::NotificationSource notification_source = | |
66 content::Source<Profile>(browser->profile()->GetOriginalProfile()); | |
67 registrar_.Add(this, | |
68 extensions::NOTIFICATION_EXTENSION_COMMAND_ADDED, | |
69 notification_source); | |
70 registrar_.Add(this, | |
71 extensions::NOTIFICATION_EXTENSION_COMMAND_REMOVED, | |
72 notification_source); | |
73 | 56 |
74 // We also listen for browser theme changes on linux because a switch from or | 57 // We also listen for browser theme changes on linux because a switch from or |
75 // to GTK requires that we regrab our browser action images. | 58 // to GTK requires that we regrab our browser action images. |
76 registrar_.Add( | 59 registrar_.Add( |
77 this, | 60 this, |
78 chrome::NOTIFICATION_BROWSER_THEME_CHANGED, | 61 chrome::NOTIFICATION_BROWSER_THEME_CHANGED, |
79 content::Source<ThemeService>( | 62 content::Source<ThemeService>( |
80 ThemeServiceFactory::GetForProfile(browser->profile()))); | 63 ThemeServiceFactory::GetForProfile(browser->profile()))); |
81 | 64 |
82 UpdateState(); | 65 UpdateState(); |
83 } | 66 } |
84 | 67 |
85 BrowserActionView::~BrowserActionView() { | 68 BrowserActionView::~BrowserActionView() { |
86 } | 69 } |
87 | 70 |
88 void BrowserActionView::ViewHierarchyChanged( | 71 void BrowserActionView::ViewHierarchyChanged( |
89 const ViewHierarchyChangedDetails& details) { | 72 const ViewHierarchyChangedDetails& details) { |
90 if (details.is_add && !called_registered_extension_command_ && | 73 if (details.is_add && !called_register_command_ && GetFocusManager()) { |
91 GetFocusManager()) { | |
92 view_controller_->RegisterCommand(); | 74 view_controller_->RegisterCommand(); |
93 called_registered_extension_command_ = true; | 75 called_register_command_ = true; |
94 } | 76 } |
95 | 77 |
96 MenuButton::ViewHierarchyChanged(details); | 78 MenuButton::ViewHierarchyChanged(details); |
97 } | 79 } |
98 | 80 |
99 void BrowserActionView::OnDragDone() { | 81 void BrowserActionView::OnDragDone() { |
100 delegate_->OnBrowserActionViewDragDone(); | 82 delegate_->OnBrowserActionViewDragDone(); |
101 } | 83 } |
102 | 84 |
103 gfx::Size BrowserActionView::GetPreferredSize() const { | 85 gfx::Size BrowserActionView::GetPreferredSize() const { |
104 return gfx::Size(BrowserActionsContainer::IconWidth(false), | 86 return gfx::Size(BrowserActionsContainer::IconWidth(false), |
105 BrowserActionsContainer::IconHeight()); | 87 BrowserActionsContainer::IconHeight()); |
106 } | 88 } |
107 | 89 |
108 void BrowserActionView::PaintChildren(gfx::Canvas* canvas, | 90 void BrowserActionView::PaintChildren(gfx::Canvas* canvas, |
109 const views::CullSet& cull_set) { | 91 const views::CullSet& cull_set) { |
110 View::PaintChildren(canvas, cull_set); | 92 View::PaintChildren(canvas, cull_set); |
111 int tab_id = view_controller_->GetCurrentTabId(); | 93 view_controller_->PaintExtra( |
112 if (tab_id >= 0) | 94 canvas, GetLocalBounds(), GetCurrentWebContents()); |
113 extension_action()->PaintBadge(canvas, GetLocalBounds(), tab_id); | |
114 } | 95 } |
115 | 96 |
116 void BrowserActionView::GetAccessibleState(ui::AXViewState* state) { | 97 void BrowserActionView::GetAccessibleState(ui::AXViewState* state) { |
117 views::MenuButton::GetAccessibleState(state); | 98 views::MenuButton::GetAccessibleState(state); |
118 state->role = ui::AX_ROLE_BUTTON; | 99 state->role = ui::AX_ROLE_BUTTON; |
119 } | 100 } |
120 | 101 |
121 void BrowserActionView::ButtonPressed(views::Button* sender, | 102 void BrowserActionView::ButtonPressed(views::Button* sender, |
122 const ui::Event& event) { | 103 const ui::Event& event) { |
123 view_controller_->ExecuteActionByUser(); | 104 view_controller_->ExecuteAction(true); |
124 } | 105 } |
125 | 106 |
126 void BrowserActionView::UpdateState() { | 107 void BrowserActionView::UpdateState() { |
127 int tab_id = view_controller_->GetCurrentTabId(); | 108 content::WebContents* web_contents = GetCurrentWebContents(); |
128 if (tab_id < 0) | 109 if (SessionTabHelper::IdForTab(web_contents) < 0) |
129 return; | 110 return; |
130 | 111 |
131 if (!IsEnabled(tab_id)) | 112 bool enabled = view_controller_->IsEnabled(web_contents); |
| 113 if (!enabled) |
132 SetState(views::CustomButton::STATE_DISABLED); | 114 SetState(views::CustomButton::STATE_DISABLED); |
133 | 115 |
134 gfx::ImageSkia icon = *view_controller_->GetIcon(tab_id).ToImageSkia(); | 116 gfx::ImageSkia icon = *view_controller_->GetIcon(web_contents).ToImageSkia(); |
135 | 117 |
136 if (!icon.isNull()) { | 118 if (!icon.isNull()) { |
137 if (!extension_action()->GetIsVisible(tab_id)) | 119 if (!enabled) |
138 icon = gfx::ImageSkiaOperations::CreateTransparentImage(icon, .25); | 120 icon = gfx::ImageSkiaOperations::CreateTransparentImage(icon, .25); |
139 | 121 |
140 ThemeService* theme = ThemeServiceFactory::GetForProfile( | 122 ThemeService* theme = |
141 view_controller_->browser()->profile()); | 123 ThemeServiceFactory::GetForProfile(browser_->profile()); |
142 | 124 |
143 gfx::ImageSkia bg = *theme->GetImageSkiaNamed(IDR_BROWSER_ACTION); | 125 gfx::ImageSkia bg = *theme->GetImageSkiaNamed(IDR_BROWSER_ACTION); |
144 SetImage(views::Button::STATE_NORMAL, | 126 SetImage(views::Button::STATE_NORMAL, |
145 gfx::ImageSkiaOperations::CreateSuperimposedImage(bg, icon)); | 127 gfx::ImageSkiaOperations::CreateSuperimposedImage(bg, icon)); |
146 } | 128 } |
147 | 129 |
148 // If the browser action name is empty, show the extension name instead. | 130 SetTooltipText(view_controller_->GetTooltip(web_contents)); |
149 std::string title = extension_action()->GetTitle(tab_id); | 131 SetAccessibleName(view_controller_->GetAccessibleName(web_contents)); |
150 base::string16 name = | |
151 base::UTF8ToUTF16(title.empty() ? extension()->name() : title); | |
152 SetTooltipText(name); | |
153 SetAccessibleName(name); | |
154 | 132 |
155 Layout(); // We need to layout since we may have added an icon as a result. | 133 Layout(); // We need to layout since we may have added an icon as a result. |
156 SchedulePaint(); | 134 SchedulePaint(); |
157 } | 135 } |
158 | 136 |
159 bool BrowserActionView::IsPopup() { | |
160 int tab_id = view_controller_->GetCurrentTabId(); | |
161 return (tab_id < 0) ? false : extension_action()->HasPopup(tab_id); | |
162 } | |
163 | |
164 void BrowserActionView::Observe(int type, | 137 void BrowserActionView::Observe(int type, |
165 const content::NotificationSource& source, | 138 const content::NotificationSource& source, |
166 const content::NotificationDetails& details) { | 139 const content::NotificationDetails& details) { |
167 switch (type) { | 140 DCHECK_EQ(chrome::NOTIFICATION_BROWSER_THEME_CHANGED, type); |
168 case extensions::NOTIFICATION_EXTENSION_COMMAND_ADDED: | 141 UpdateState(); |
169 case extensions::NOTIFICATION_EXTENSION_COMMAND_REMOVED: { | |
170 std::pair<const std::string, const std::string>* payload = | |
171 content::Details<std::pair<const std::string, const std::string> >( | |
172 details).ptr(); | |
173 if (extension()->id() == payload->first && | |
174 payload->second == | |
175 extensions::manifest_values::kBrowserActionCommandEvent) { | |
176 if (type == extensions::NOTIFICATION_EXTENSION_COMMAND_ADDED) | |
177 view_controller_->RegisterCommand(); | |
178 else | |
179 view_controller_->UnregisterCommand(true); | |
180 } | |
181 break; | |
182 } | |
183 case chrome::NOTIFICATION_BROWSER_THEME_CHANGED: | |
184 UpdateState(); | |
185 break; | |
186 default: | |
187 NOTREACHED(); | |
188 break; | |
189 } | |
190 } | 142 } |
191 | 143 |
192 bool BrowserActionView::Activate() { | 144 bool BrowserActionView::Activate() { |
193 if (!IsPopup()) | 145 if (!view_controller_->HasPopup(GetCurrentWebContents())) |
194 return true; | 146 return true; |
195 | 147 |
196 view_controller_->ExecuteActionByUser(); | 148 view_controller_->ExecuteAction(true); |
197 | 149 |
198 // TODO(erikkay): Run a nested modal loop while the mouse is down to | 150 // TODO(erikkay): Run a nested modal loop while the mouse is down to |
199 // enable menu-like drag-select behavior. | 151 // enable menu-like drag-select behavior. |
200 | 152 |
201 // The return value of this method is returned via OnMousePressed. | 153 // The return value of this method is returned via OnMousePressed. |
202 // We need to return false here since we're handing off focus to another | 154 // We need to return false here since we're handing off focus to another |
203 // widget/view, and true will grab it right back and try to send events | 155 // widget/view, and true will grab it right back and try to send events |
204 // to us. | 156 // to us. |
205 return false; | 157 return false; |
206 } | 158 } |
207 | 159 |
208 bool BrowserActionView::OnMousePressed(const ui::MouseEvent& event) { | 160 bool BrowserActionView::OnMousePressed(const ui::MouseEvent& event) { |
209 if (!event.IsRightMouseButton()) { | 161 if (!event.IsRightMouseButton()) { |
210 return IsPopup() ? MenuButton::OnMousePressed(event) : | 162 return view_controller_->HasPopup(GetCurrentWebContents()) ? |
211 LabelButton::OnMousePressed(event); | 163 MenuButton::OnMousePressed(event) : LabelButton::OnMousePressed(event); |
212 } | 164 } |
213 return false; | 165 return false; |
214 } | 166 } |
215 | 167 |
216 void BrowserActionView::OnMouseReleased(const ui::MouseEvent& event) { | 168 void BrowserActionView::OnMouseReleased(const ui::MouseEvent& event) { |
217 if (IsPopup() || view_controller_->is_menu_running()) { | 169 if (view_controller_->HasPopup(GetCurrentWebContents()) || |
| 170 view_controller_->IsMenuRunning()) { |
218 // TODO(erikkay) this never actually gets called (probably because of the | 171 // TODO(erikkay) this never actually gets called (probably because of the |
219 // loss of focus). | 172 // loss of focus). |
220 MenuButton::OnMouseReleased(event); | 173 MenuButton::OnMouseReleased(event); |
221 } else { | 174 } else { |
222 LabelButton::OnMouseReleased(event); | 175 LabelButton::OnMouseReleased(event); |
223 } | 176 } |
224 } | 177 } |
225 | 178 |
226 void BrowserActionView::OnMouseExited(const ui::MouseEvent& event) { | 179 void BrowserActionView::OnMouseExited(const ui::MouseEvent& event) { |
227 if (IsPopup() || view_controller_->is_menu_running()) | 180 if (view_controller_->HasPopup(GetCurrentWebContents()) || |
| 181 view_controller_->IsMenuRunning()) |
228 MenuButton::OnMouseExited(event); | 182 MenuButton::OnMouseExited(event); |
229 else | 183 else |
230 LabelButton::OnMouseExited(event); | 184 LabelButton::OnMouseExited(event); |
231 } | 185 } |
232 | 186 |
233 bool BrowserActionView::OnKeyReleased(const ui::KeyEvent& event) { | 187 bool BrowserActionView::OnKeyReleased(const ui::KeyEvent& event) { |
234 return IsPopup() ? MenuButton::OnKeyReleased(event) : | 188 return view_controller_->HasPopup(GetCurrentWebContents()) ? |
235 LabelButton::OnKeyReleased(event); | 189 MenuButton::OnKeyReleased(event) : LabelButton::OnKeyReleased(event); |
236 } | 190 } |
237 | 191 |
238 void BrowserActionView::OnGestureEvent(ui::GestureEvent* event) { | 192 void BrowserActionView::OnGestureEvent(ui::GestureEvent* event) { |
239 if (IsPopup()) | 193 if (view_controller_->HasPopup(GetCurrentWebContents())) |
240 MenuButton::OnGestureEvent(event); | 194 MenuButton::OnGestureEvent(event); |
241 else | 195 else |
242 LabelButton::OnGestureEvent(event); | 196 LabelButton::OnGestureEvent(event); |
243 } | 197 } |
244 | 198 |
245 scoped_ptr<LabelButtonBorder> BrowserActionView::CreateDefaultBorder() const { | 199 scoped_ptr<LabelButtonBorder> BrowserActionView::CreateDefaultBorder() const { |
246 scoped_ptr<LabelButtonBorder> border = LabelButton::CreateDefaultBorder(); | 200 scoped_ptr<LabelButtonBorder> border = LabelButton::CreateDefaultBorder(); |
247 border->set_insets(gfx::Insets(kBorderInset, kBorderInset, | 201 border->set_insets(gfx::Insets(kBorderInset, kBorderInset, |
248 kBorderInset, kBorderInset)); | 202 kBorderInset, kBorderInset)); |
249 return border.Pass(); | 203 return border.Pass(); |
250 } | 204 } |
251 | 205 |
252 bool BrowserActionView::IsEnabled(int tab_id) const { | |
253 return view_controller_->extension_action()->GetIsVisible(tab_id); | |
254 } | |
255 | |
256 gfx::ImageSkia BrowserActionView::GetIconWithBadge() { | |
257 int tab_id = view_controller_->GetCurrentTabId(); | |
258 gfx::Size spacing(0, ToolbarView::kVertSpacing); | |
259 gfx::ImageSkia icon = *view_controller_->GetIcon(tab_id).ToImageSkia(); | |
260 if (!IsEnabled(tab_id)) | |
261 icon = gfx::ImageSkiaOperations::CreateTransparentImage(icon, .25); | |
262 return extension_action()->GetIconWithBadge(icon, tab_id, spacing); | |
263 } | |
264 | |
265 gfx::ImageSkia BrowserActionView::GetIconForTest() { | 206 gfx::ImageSkia BrowserActionView::GetIconForTest() { |
266 return GetImage(views::Button::STATE_NORMAL); | 207 return GetImage(views::Button::STATE_NORMAL); |
267 } | 208 } |
268 | 209 |
269 void BrowserActionView::OnIconUpdated() { | 210 void BrowserActionView::OnIconUpdated() { |
270 UpdateState(); | 211 UpdateState(); |
271 if (icon_observer_) | |
272 icon_observer_->OnIconUpdated(GetIconWithBadge()); | |
273 } | 212 } |
274 | 213 |
275 views::View* BrowserActionView::GetAsView() { | 214 views::View* BrowserActionView::GetAsView() { |
276 return this; | 215 return this; |
277 } | 216 } |
278 | 217 |
279 bool BrowserActionView::IsShownInMenu() { | 218 bool BrowserActionView::IsShownInMenu() { |
280 return delegate_->ShownInsideMenu(); | 219 return delegate_->ShownInsideMenu(); |
281 } | 220 } |
282 | 221 |
283 views::FocusManager* BrowserActionView::GetFocusManagerForAccelerator() { | 222 views::FocusManager* BrowserActionView::GetFocusManagerForAccelerator() { |
284 return GetFocusManager(); | 223 return GetFocusManager(); |
285 } | 224 } |
286 | 225 |
287 views::Widget* BrowserActionView::GetParentForContextMenu() { | 226 views::Widget* BrowserActionView::GetParentForContextMenu() { |
288 // RunMenuAt expects a nested menu to be parented by the same widget as the | 227 // RunMenuAt expects a nested menu to be parented by the same widget as the |
289 // already visible menu, in this case the Chrome menu. | 228 // already visible menu, in this case the Chrome menu. |
290 return delegate_->ShownInsideMenu() ? | 229 return delegate_->ShownInsideMenu() ? |
291 BrowserView::GetBrowserViewForBrowser(view_controller_->browser()) | 230 BrowserView::GetBrowserViewForBrowser(browser_) |
292 ->toolbar()->app_menu()->GetWidget() : | 231 ->toolbar()->app_menu()->GetWidget() : |
293 GetWidget(); | 232 GetWidget(); |
294 } | 233 } |
295 | 234 |
296 ExtensionActionViewController* | 235 ToolbarActionViewController* |
297 BrowserActionView::GetPreferredPopupViewController() { | 236 BrowserActionView::GetPreferredPopupViewController() { |
298 return delegate_->ShownInsideMenu() ? | 237 return delegate_->ShownInsideMenu() ? |
299 delegate_->GetMainViewForExtension(extension())->view_controller() : | 238 delegate_->GetMainViewForAction(this)->view_controller() : |
300 view_controller(); | 239 view_controller(); |
301 } | 240 } |
302 | 241 |
303 views::View* BrowserActionView::GetReferenceViewForPopup() { | 242 views::View* BrowserActionView::GetReferenceViewForPopup() { |
304 // Browser actions in the overflow menu can still show popups, so we may need | 243 // Browser actions in the overflow menu can still show popups, so we may need |
305 // a reference view other than this button's parent. If so, use the overflow | 244 // a reference view other than this button's parent. If so, use the overflow |
306 // view. | 245 // view. |
307 return visible() ? this : delegate_->GetOverflowReferenceView(); | 246 return visible() ? this : delegate_->GetOverflowReferenceView(); |
308 } | 247 } |
309 | 248 |
310 views::MenuButton* BrowserActionView::GetContextMenuButton() { | 249 views::MenuButton* BrowserActionView::GetContextMenuButton() { |
311 DCHECK(visible()); // We should never show a context menu for a hidden item. | 250 DCHECK(visible()); // We should never show a context menu for a hidden item. |
312 return this; | 251 return this; |
313 } | 252 } |
314 | 253 |
315 content::WebContents* BrowserActionView::GetCurrentWebContents() { | 254 content::WebContents* BrowserActionView::GetCurrentWebContents() const { |
316 return delegate_->GetCurrentWebContents(); | 255 return delegate_->GetCurrentWebContents(); |
317 } | 256 } |
318 | 257 |
319 void BrowserActionView::HideActivePopup() { | 258 void BrowserActionView::HideActivePopup() { |
320 delegate_->HideActivePopup(); | 259 delegate_->HideActivePopup(); |
321 } | 260 } |
322 | 261 |
323 void BrowserActionView::OnPopupShown(bool grant_tab_permissions) { | 262 void BrowserActionView::OnPopupShown(bool grant_tab_permissions) { |
324 delegate_->SetPopupOwner(this); | 263 delegate_->SetPopupOwner(this); |
325 // If this was through direct user action, we press the menu button. | 264 // If this was through direct user action, we press the menu button. |
326 if (grant_tab_permissions) { | 265 if (grant_tab_permissions) { |
327 // We set the state of the menu button we're using as a reference view, | 266 // We set the state of the menu button we're using as a reference view, |
328 // which is either this or the overflow reference view. | 267 // which is either this or the overflow reference view. |
329 // This cast is safe because GetReferenceViewForPopup returns either |this| | 268 // This cast is safe because GetReferenceViewForPopup returns either |this| |
330 // or delegate_->GetOverflowReferenceView(), which returns a MenuButton. | 269 // or delegate_->GetOverflowReferenceView(), which returns a MenuButton. |
331 views::MenuButton* reference_view = | 270 views::MenuButton* reference_view = |
332 static_cast<views::MenuButton*>(GetReferenceViewForPopup()); | 271 static_cast<views::MenuButton*>(GetReferenceViewForPopup()); |
333 pressed_lock_.reset(new views::MenuButton::PressedLock(reference_view)); | 272 pressed_lock_.reset(new views::MenuButton::PressedLock(reference_view)); |
334 } | 273 } |
335 } | 274 } |
336 | 275 |
337 void BrowserActionView::CleanupPopup() { | 276 void BrowserActionView::CleanupPopup() { |
338 // We need to do these actions synchronously (instead of closing and then | 277 // We need to do these actions synchronously (instead of closing and then |
339 // performing the rest of the cleanup in OnWidgetDestroyed()) because | 278 // performing the rest of the cleanup in OnWidgetDestroyed()) because |
340 // OnWidgetDestroyed() can be called asynchronously from Close(), and we need | 279 // OnWidgetDestroyed() can be called asynchronously from Close(), and we need |
341 // to keep the delegate's popup owner up-to-date. | 280 // to keep the delegate's popup owner up-to-date. |
342 delegate_->SetPopupOwner(NULL); | 281 delegate_->SetPopupOwner(NULL); |
343 pressed_lock_.reset(); // Unpress the menu button if it was pressed. | 282 pressed_lock_.reset(); // Unpress the menu button if it was pressed. |
344 } | 283 } |
OLD | NEW |