OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/views/browser_actions_container.h" | 5 #include "chrome/browser/views/browser_actions_container.h" |
6 | 6 |
7 #include "app/l10n_util.h" | 7 #include "app/l10n_util.h" |
8 #include "app/resource_bundle.h" | 8 #include "app/resource_bundle.h" |
9 #include "app/slide_animation.h" | 9 #include "app/slide_animation.h" |
10 #include "base/stl_util-inl.h" | 10 #include "base/stl_util-inl.h" |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
91 bool BrowserActionsContainer::disable_animations_during_testing_ = false; | 91 bool BrowserActionsContainer::disable_animations_during_testing_ = false; |
92 | 92 |
93 //////////////////////////////////////////////////////////////////////////////// | 93 //////////////////////////////////////////////////////////////////////////////// |
94 // BrowserActionButton | 94 // BrowserActionButton |
95 | 95 |
96 BrowserActionButton::BrowserActionButton(Extension* extension, | 96 BrowserActionButton::BrowserActionButton(Extension* extension, |
97 BrowserActionsContainer* panel) | 97 BrowserActionsContainer* panel) |
98 : ALLOW_THIS_IN_INITIALIZER_LIST(MenuButton(this, L"", NULL, false)), | 98 : ALLOW_THIS_IN_INITIALIZER_LIST(MenuButton(this, L"", NULL, false)), |
99 browser_action_(extension->browser_action()), | 99 browser_action_(extension->browser_action()), |
100 extension_(extension), | 100 extension_(extension), |
101 tracker_(NULL), | 101 ALLOW_THIS_IN_INITIALIZER_LIST(tracker_(this)), |
102 showing_context_menu_(false), | 102 showing_context_menu_(false), |
103 panel_(panel) { | 103 panel_(panel) { |
104 set_alignment(TextButton::ALIGN_CENTER); | 104 set_alignment(TextButton::ALIGN_CENTER); |
105 | 105 |
106 // No UpdateState() here because View hierarchy not setup yet. Our parent | 106 // No UpdateState() here because View hierarchy not setup yet. Our parent |
107 // should call UpdateState() after creation. | 107 // should call UpdateState() after creation. |
108 | 108 |
109 registrar_.Add(this, NotificationType::EXTENSION_BROWSER_ACTION_UPDATED, | 109 registrar_.Add(this, NotificationType::EXTENSION_BROWSER_ACTION_UPDATED, |
110 Source<ExtensionAction>(browser_action_)); | 110 Source<ExtensionAction>(browser_action_)); |
111 | 111 |
112 // The Browser Action API does not allow the default icon path to be changed | 112 // The Browser Action API does not allow the default icon path to be changed |
113 // at runtime, so we can load this now and cache it. | 113 // at runtime, so we can load this now and cache it. |
114 std::string relative_path = browser_action_->default_icon_path(); | 114 std::string relative_path = browser_action_->default_icon_path(); |
115 if (relative_path.empty()) | 115 if (relative_path.empty()) |
116 return; | 116 return; |
117 | 117 |
118 // This is a bit sketchy because if ImageLoadingTracker calls | 118 // This is a bit sketchy because if ImageLoadingTracker calls |
119 // ::OnImageLoaded() before our creator appends up to the view hierarchy, we | 119 // ::OnImageLoaded() before our creator appends up to the view hierarchy, we |
120 // will crash. But since we know that ImageLoadingTracker is asynchronous, | 120 // will crash. But since we know that ImageLoadingTracker is asynchronous, |
121 // this should be OK. And doing this in the constructor means that we don't | 121 // this should be OK. And doing this in the constructor means that we don't |
122 // have to protect against it getting done multiple times. | 122 // have to protect against it getting done multiple times. |
123 tracker_ = new ImageLoadingTracker(this, 1); | 123 tracker_.PostLoadImageTask( |
124 tracker_->PostLoadImageTask( | |
125 extension->GetResource(relative_path), | 124 extension->GetResource(relative_path), |
126 gfx::Size(Extension::kBrowserActionIconMaxSize, | 125 gfx::Size(Extension::kBrowserActionIconMaxSize, |
127 Extension::kBrowserActionIconMaxSize)); | 126 Extension::kBrowserActionIconMaxSize), |
| 127 0); // |index| == 0, since we only ever load one image. |
128 } | 128 } |
129 | 129 |
130 BrowserActionButton::~BrowserActionButton() { | 130 BrowserActionButton::~BrowserActionButton() { |
131 if (tracker_) | |
132 tracker_->StopTrackingImageLoad(); | |
133 } | 131 } |
134 | 132 |
135 gfx::Insets BrowserActionButton::GetInsets() const { | 133 gfx::Insets BrowserActionButton::GetInsets() const { |
136 static gfx::Insets zero_inset; | 134 static gfx::Insets zero_inset; |
137 return zero_inset; | 135 return zero_inset; |
138 } | 136 } |
139 | 137 |
140 void BrowserActionButton::ButtonPressed(views::Button* sender, | 138 void BrowserActionButton::ButtonPressed(views::Button* sender, |
141 const views::Event& event) { | 139 const views::Event& event) { |
142 panel_->OnBrowserActionExecuted(this, false); // inspect_with_devtools | 140 panel_->OnBrowserActionExecuted(this, false); // inspect_with_devtools |
143 } | 141 } |
144 | 142 |
145 void BrowserActionButton::OnImageLoaded(SkBitmap* image, size_t index) { | 143 void BrowserActionButton::OnImageLoaded(SkBitmap* image, int index) { |
146 if (image) | 144 if (image) |
147 default_icon_ = *image; | 145 default_icon_ = *image; |
148 | 146 |
149 tracker_ = NULL; // The tracker object will delete itself when we return. | |
150 | |
151 // Call back to UpdateState() because a more specific icon might have been set | 147 // Call back to UpdateState() because a more specific icon might have been set |
152 // while the load was outstanding. | 148 // while the load was outstanding. |
153 UpdateState(); | 149 UpdateState(); |
154 } | 150 } |
155 | 151 |
156 void BrowserActionButton::UpdateState() { | 152 void BrowserActionButton::UpdateState() { |
157 int tab_id = panel_->GetCurrentTabId(); | 153 int tab_id = panel_->GetCurrentTabId(); |
158 if (tab_id < 0) | 154 if (tab_id < 0) |
159 return; | 155 return; |
160 | 156 |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
200 if (tab_id < 0) { | 196 if (tab_id < 0) { |
201 NOTREACHED() << "Button is not on a specific tab."; | 197 NOTREACHED() << "Button is not on a specific tab."; |
202 GURL empty_url; | 198 GURL empty_url; |
203 return empty_url; | 199 return empty_url; |
204 } | 200 } |
205 return browser_action_->GetPopupUrl(tab_id); | 201 return browser_action_->GetPopupUrl(tab_id); |
206 } | 202 } |
207 | 203 |
208 bool BrowserActionButton::Activate() { | 204 bool BrowserActionButton::Activate() { |
209 if (IsPopup()) { | 205 if (IsPopup()) { |
210 panel_->OnBrowserActionExecuted(this, false); // inspect_with_devtools | 206 panel_->OnBrowserActionExecuted(this, false); // |inspect_with_devtools|. |
211 | 207 |
212 // TODO(erikkay): Run a nested modal loop while the mouse is down to | 208 // TODO(erikkay): Run a nested modal loop while the mouse is down to |
213 // enable menu-like drag-select behavior. | 209 // enable menu-like drag-select behavior. |
214 | 210 |
215 // The return value of this method is returned via OnMousePressed. | 211 // The return value of this method is returned via OnMousePressed. |
216 // We need to return false here since we're handing off focus to another | 212 // We need to return false here since we're handing off focus to another |
217 // widget/view, and true will grab it right back and try to send events | 213 // widget/view, and true will grab it right back and try to send events |
218 // to us. | 214 // to us. |
219 return false; | 215 return false; |
220 } | 216 } |
(...skipping 283 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
504 owner_view_->SchedulePaint(); | 500 owner_view_->SchedulePaint(); |
505 } | 501 } |
506 | 502 |
507 void BrowserActionsContainer::HidePopup() { | 503 void BrowserActionsContainer::HidePopup() { |
508 if (popup_) | 504 if (popup_) |
509 popup_->Close(); | 505 popup_->Close(); |
510 } | 506 } |
511 | 507 |
512 void BrowserActionsContainer::TestExecuteBrowserAction(int index) { | 508 void BrowserActionsContainer::TestExecuteBrowserAction(int index) { |
513 BrowserActionButton* button = browser_action_views_[index]->button(); | 509 BrowserActionButton* button = browser_action_views_[index]->button(); |
514 OnBrowserActionExecuted(button, false); // inspect_with_devtools | 510 OnBrowserActionExecuted(button, false); // |inspect_with_devtools|. |
515 } | 511 } |
516 | 512 |
517 void BrowserActionsContainer::TestSetIconVisibilityCount(size_t icons) { | 513 void BrowserActionsContainer::TestSetIconVisibilityCount(size_t icons) { |
518 chevron_->SetVisible(icons < browser_action_views_.size()); | 514 chevron_->SetVisible(icons < browser_action_views_.size()); |
519 container_size_.set_width(IconCountToWidth(icons)); | 515 container_size_.set_width(IconCountToWidth(icons)); |
520 Layout(); | 516 Layout(); |
521 SchedulePaint(); | 517 SchedulePaint(); |
522 } | 518 } |
523 | 519 |
524 void BrowserActionsContainer::OnBrowserActionExecuted( | 520 void BrowserActionsContainer::OnBrowserActionExecuted( |
(...skipping 582 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1107 | 1103 |
1108 void BrowserActionsContainer::NotifyMenuDeleted( | 1104 void BrowserActionsContainer::NotifyMenuDeleted( |
1109 BrowserActionOverflowMenuController* controller) { | 1105 BrowserActionOverflowMenuController* controller) { |
1110 DCHECK(controller == overflow_menu_); | 1106 DCHECK(controller == overflow_menu_); |
1111 overflow_menu_ = NULL; | 1107 overflow_menu_ = NULL; |
1112 } | 1108 } |
1113 | 1109 |
1114 void BrowserActionsContainer::InspectPopup( | 1110 void BrowserActionsContainer::InspectPopup( |
1115 ExtensionAction* action) { | 1111 ExtensionAction* action) { |
1116 OnBrowserActionExecuted(GetBrowserActionView(action)->button(), | 1112 OnBrowserActionExecuted(GetBrowserActionView(action)->button(), |
1117 true); // inspect_with_devtools | 1113 true); // |inspect_with_devtools|. |
1118 } | 1114 } |
1119 | 1115 |
1120 void BrowserActionsContainer::ExtensionPopupClosed(ExtensionPopup* popup) { | 1116 void BrowserActionsContainer::ExtensionPopupClosed(ExtensionPopup* popup) { |
1121 // ExtensionPopup is ref-counted, so we don't need to delete it. | 1117 // ExtensionPopup is ref-counted, so we don't need to delete it. |
1122 DCHECK_EQ(popup_, popup); | 1118 DCHECK_EQ(popup_, popup); |
1123 popup_ = NULL; | 1119 popup_ = NULL; |
1124 popup_button_->SetButtonNotPushed(); | 1120 popup_button_->SetButtonNotPushed(); |
1125 popup_button_ = NULL; | 1121 popup_button_ = NULL; |
1126 } | 1122 } |
1127 | 1123 |
1128 bool BrowserActionsContainer::ShouldDisplayBrowserAction(Extension* extension) { | 1124 bool BrowserActionsContainer::ShouldDisplayBrowserAction(Extension* extension) { |
1129 // Only display incognito-enabled extensions while in incognito mode. | 1125 // Only display incognito-enabled extensions while in incognito mode. |
1130 return (!profile_->IsOffTheRecord() || | 1126 return (!profile_->IsOffTheRecord() || |
1131 profile_->GetExtensionsService()->IsIncognitoEnabled(extension)); | 1127 profile_->GetExtensionsService()->IsIncognitoEnabled(extension)); |
1132 } | 1128 } |
OLD | NEW |