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

Side by Side Diff: chrome/browser/ui/views/browser_action_view.cc

Issue 10834275: Fixed Issue 141873. Crash when BrowserActionButton get disabled or hidden. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix for 141873 Created 8 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
« no previous file with comments | « chrome/browser/ui/views/browser_action_view.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/browser_action_view.h" 5 #include "chrome/browser/ui/views/browser_action_view.h"
6 6
7 #include "base/utf_string_conversions.h" 7 #include "base/utf_string_conversions.h"
8 #include "chrome/browser/extensions/api/commands/command_service.h" 8 #include "chrome/browser/extensions/api/commands/command_service.h"
9 #include "chrome/browser/extensions/api/commands/command_service_factory.h" 9 #include "chrome/browser/extensions/api/commands/command_service_factory.h"
10 #include "chrome/browser/extensions/extension_context_menu_model.h" 10 #include "chrome/browser/extensions/extension_context_menu_model.h"
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
52 return true; 52 return true;
53 } 53 }
54 54
55 BrowserActionView::BrowserActionView(const Extension* extension, 55 BrowserActionView::BrowserActionView(const Extension* extension,
56 Browser* browser, 56 Browser* browser,
57 BrowserActionView::Delegate* delegate) 57 BrowserActionView::Delegate* delegate)
58 : browser_(browser), 58 : browser_(browser),
59 delegate_(delegate), 59 delegate_(delegate),
60 button_(NULL), 60 button_(NULL),
61 extension_(extension) { 61 extension_(extension) {
62 button_ = new BrowserActionButton(extension_, browser_, delegate_);
63 button_->set_drag_controller(delegate_);
64 AddChildView(button_);
65 button_->UpdateState();
62 } 66 }
63 67
64 BrowserActionView::~BrowserActionView() { 68 BrowserActionView::~BrowserActionView() {
69 RemoveChildView(button_);
70 button_->Destroy();
65 } 71 }
66 72
67 gfx::Canvas* BrowserActionView::GetIconWithBadge() { 73 gfx::Canvas* BrowserActionView::GetIconWithBadge() {
68 int tab_id = delegate_->GetCurrentTabId(); 74 int tab_id = delegate_->GetCurrentTabId();
69 75
70 SkBitmap icon = 76 SkBitmap icon =
71 *button_->extension()->browser_action()->GetIcon(tab_id).ToSkBitmap(); 77 *button_->extension()->browser_action()->GetIcon(tab_id).ToSkBitmap();
72 78
73 // Dim the icon if our button is disabled. 79 // Dim the icon if our button is disabled.
74 if (!button_->IsEnabled(tab_id)) 80 if (!button_->IsEnabled(tab_id))
(...skipping 14 matching lines...) Expand all
89 // BrowserActionsContainer::RefreshBrowserActionViews(), whereas this can be 95 // BrowserActionsContainer::RefreshBrowserActionViews(), whereas this can be
90 // called before that when the initial bounds are set (and then not after, 96 // called before that when the initial bounds are set (and then not after,
91 // since the bounds don't change). So instead of setting the height from the 97 // since the bounds don't change). So instead of setting the height from the
92 // button's preferred size, we use IconHeight(), since that's how big the 98 // button's preferred size, we use IconHeight(), since that's how big the
93 // button should be regardless of what it's displaying. 99 // button should be regardless of what it's displaying.
94 gfx::Point offset = delegate_->GetViewContentOffset(); 100 gfx::Point offset = delegate_->GetViewContentOffset();
95 button_->SetBounds(offset.x(), offset.y(), width() - offset.x(), 101 button_->SetBounds(offset.x(), offset.y(), width() - offset.x(),
96 BrowserActionsContainer::IconHeight()); 102 BrowserActionsContainer::IconHeight());
97 } 103 }
98 104
99 void BrowserActionView::ViewHierarchyChanged(bool is_add,
100 View* parent,
101 View* child) {
102 if (is_add && (child == this)) {
103 button_ = new BrowserActionButton(extension_, browser_, delegate_);
104 button_->set_drag_controller(delegate_);
105
106 AddChildView(button_);
107 button_->UpdateState();
108 }
109 }
110
111 void BrowserActionView::GetAccessibleState(ui::AccessibleViewState* state) { 105 void BrowserActionView::GetAccessibleState(ui::AccessibleViewState* state) {
112 state->name = l10n_util::GetStringUTF16( 106 state->name = l10n_util::GetStringUTF16(
113 IDS_ACCNAME_EXTENSIONS_BROWSER_ACTION); 107 IDS_ACCNAME_EXTENSIONS_BROWSER_ACTION);
114 state->role = ui::AccessibilityTypes::ROLE_GROUPING; 108 state->role = ui::AccessibilityTypes::ROLE_GROUPING;
115 } 109 }
116 110
117 gfx::Size BrowserActionView::GetPreferredSize() { 111 gfx::Size BrowserActionView::GetPreferredSize() {
118 return gfx::Size(BrowserActionsContainer::IconWidth(false), 112 return gfx::Size(BrowserActionsContainer::IconWidth(false),
119 BrowserActionsContainer::IconHeight()); 113 BrowserActionsContainer::IconHeight());
120 } 114 }
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
224 218
225 context_menu_ = menu_runner_->GetMenu(); 219 context_menu_ = menu_runner_->GetMenu();
226 gfx::Point screen_loc; 220 gfx::Point screen_loc;
227 views::View::ConvertPointToScreen(this, &screen_loc); 221 views::View::ConvertPointToScreen(this, &screen_loc);
228 if (menu_runner_->RunMenuAt(GetWidget(), NULL, gfx::Rect(screen_loc, size()), 222 if (menu_runner_->RunMenuAt(GetWidget(), NULL, gfx::Rect(screen_loc, size()),
229 views::MenuItemView::TOPLEFT, views::MenuRunner::HAS_MNEMONICS) == 223 views::MenuItemView::TOPLEFT, views::MenuRunner::HAS_MNEMONICS) ==
230 views::MenuRunner::MENU_DELETED) { 224 views::MenuRunner::MENU_DELETED) {
231 return; 225 return;
232 } 226 }
233 227
234 menu_runner_.reset();
235 SetButtonNotPushed(); 228 SetButtonNotPushed();
236 context_menu_ = NULL; 229 context_menu_ = NULL;
237 } 230 }
238 231
239 void BrowserActionButton::OnImageLoaded(const gfx::Image& image, 232 void BrowserActionButton::OnImageLoaded(const gfx::Image& image,
240 const std::string& extension_id, 233 const std::string& extension_id,
241 int index) { 234 int index) {
242 browser_action_->CacheIcon(browser_action_->default_icon_path(), image); 235 browser_action_->CacheIcon(browser_action_->default_icon_path(), image);
243 236
244 // Call back to UpdateState() because a more specific icon might have been set 237 // Call back to UpdateState() because a more specific icon might have been set
(...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after
430 &browser_action_command, 423 &browser_action_command,
431 NULL)) { 424 NULL)) {
432 keybinding_.reset(new ui::Accelerator( 425 keybinding_.reset(new ui::Accelerator(
433 browser_action_command.accelerator())); 426 browser_action_command.accelerator()));
434 GetFocusManager()->RegisterAccelerator( 427 GetFocusManager()->RegisterAccelerator(
435 *keybinding_.get(), ui::AcceleratorManager::kHighPriority, this); 428 *keybinding_.get(), ui::AcceleratorManager::kHighPriority, this);
436 } 429 }
437 } 430 }
438 431
439 void BrowserActionButton::MaybeUnregisterExtensionCommand(bool only_if_active) { 432 void BrowserActionButton::MaybeUnregisterExtensionCommand(bool only_if_active) {
440 if (!keybinding_.get() || !GetFocusManager()) 433 if (!keybinding_.get() || !GetFocusManager())
sky 2012/08/10 23:21:52 The way you have the code node GetFocusManager wil
441 return; 434 return;
442 435
443 extensions::CommandService* command_service = 436 extensions::CommandService* command_service =
444 extensions::CommandServiceFactory::GetForProfile(browser_->profile()); 437 extensions::CommandServiceFactory::GetForProfile(browser_->profile());
445 438
446 extensions::Command browser_action_command; 439 extensions::Command browser_action_command;
447 if (!only_if_active || !command_service->GetBrowserActionCommand( 440 if (!only_if_active || !command_service->GetBrowserActionCommand(
448 extension_->id(), 441 extension_->id(),
449 extensions::CommandService::ACTIVE_ONLY, 442 extensions::CommandService::ACTIVE_ONLY,
450 &browser_action_command, 443 &browser_action_command,
451 NULL)) { 444 NULL)) {
452 GetFocusManager()->UnregisterAccelerator(*keybinding_.get(), this); 445 GetFocusManager()->UnregisterAccelerator(*keybinding_.get(), this);
453 } 446 }
454 } 447 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/views/browser_action_view.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698