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