| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/toolbar/toolbar_actions_bar.h" | 5 #include "chrome/browser/ui/toolbar/toolbar_actions_bar.h" |
| 6 | 6 |
| 7 #include "base/auto_reset.h" | 7 #include "base/auto_reset.h" |
| 8 #include "base/location.h" | 8 #include "base/location.h" |
| 9 #include "base/profiler/scoped_tracker.h" | 9 #include "base/profiler/scoped_tracker.h" |
| 10 #include "base/single_thread_task_runner.h" | 10 #include "base/single_thread_task_runner.h" |
| 11 #include "base/thread_task_runner_handle.h" | 11 #include "base/thread_task_runner_handle.h" |
| 12 #include "chrome/browser/extensions/extension_action_manager.h" | 12 #include "chrome/browser/extensions/extension_action_manager.h" |
| 13 #include "chrome/browser/extensions/extension_message_bubble_controller.h" | 13 #include "chrome/browser/extensions/extension_message_bubble_controller.h" |
| 14 #include "chrome/browser/extensions/extension_util.h" | 14 #include "chrome/browser/extensions/extension_util.h" |
| 15 #include "chrome/browser/profiles/profile.h" | 15 #include "chrome/browser/profiles/profile.h" |
| 16 #include "chrome/browser/sessions/session_tab_helper.h" | 16 #include "chrome/browser/sessions/session_tab_helper.h" |
| 17 #include "chrome/browser/ui/browser.h" | 17 #include "chrome/browser/ui/browser.h" |
| 18 #include "chrome/browser/ui/browser_window.h" | 18 #include "chrome/browser/ui/browser_window.h" |
| 19 #include "chrome/browser/ui/extensions/extension_action_view_controller.h" | 19 #include "chrome/browser/ui/extensions/extension_action_view_controller.h" |
| 20 #include "chrome/browser/ui/extensions/extension_message_bubble_factory.h" | 20 #include "chrome/browser/ui/extensions/extension_message_bubble_factory.h" |
| 21 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 21 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| 22 #include "chrome/browser/ui/toolbar/component_toolbar_actions_factory.h" | 22 #include "chrome/browser/ui/toolbar/component_toolbar_actions_factory.h" |
| 23 #include "chrome/browser/ui/toolbar/toolbar_action_view_controller.h" | 23 #include "chrome/browser/ui/toolbar/toolbar_action_view_controller.h" |
| 24 #include "chrome/browser/ui/toolbar/toolbar_actions_bar_delegate.h" | 24 #include "chrome/browser/ui/toolbar/toolbar_actions_bar_delegate.h" |
| 25 #include "chrome/common/pref_names.h" | 25 #include "chrome/common/pref_names.h" |
| 26 #include "components/crx_file/id_util.h" | 26 #include "components/crx_file/id_util.h" |
| 27 #include "components/pref_registry/pref_registry_syncable.h" | 27 #include "components/pref_registry/pref_registry_syncable.h" |
| 28 #include "extensions/browser/extension_registry.h" |
| 28 #include "extensions/browser/extension_system.h" | 29 #include "extensions/browser/extension_system.h" |
| 29 #include "extensions/browser/runtime_data.h" | 30 #include "extensions/browser/runtime_data.h" |
| 30 #include "extensions/common/extension.h" | 31 #include "extensions/common/extension.h" |
| 31 #include "extensions/common/feature_switch.h" | 32 #include "extensions/common/feature_switch.h" |
| 32 #include "grit/theme_resources.h" | 33 #include "grit/theme_resources.h" |
| 33 #include "ui/base/resource/resource_bundle.h" | 34 #include "ui/base/resource/resource_bundle.h" |
| 34 #include "ui/gfx/image/image_skia.h" | 35 #include "ui/gfx/image/image_skia.h" |
| 35 | 36 |
| 36 namespace { | 37 namespace { |
| 37 | 38 |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 112 icons_per_overflow_menu_row(1), | 113 icons_per_overflow_menu_row(1), |
| 113 chevron_enabled(!extensions::FeatureSwitch::extension_action_redesign()-> | 114 chevron_enabled(!extensions::FeatureSwitch::extension_action_redesign()-> |
| 114 IsEnabled()) { | 115 IsEnabled()) { |
| 115 } | 116 } |
| 116 | 117 |
| 117 ToolbarActionsBar::ToolbarActionsBar(ToolbarActionsBarDelegate* delegate, | 118 ToolbarActionsBar::ToolbarActionsBar(ToolbarActionsBarDelegate* delegate, |
| 118 Browser* browser, | 119 Browser* browser, |
| 119 ToolbarActionsBar* main_bar) | 120 ToolbarActionsBar* main_bar) |
| 120 : delegate_(delegate), | 121 : delegate_(delegate), |
| 121 browser_(browser), | 122 browser_(browser), |
| 122 model_(extensions::ExtensionToolbarModel::Get(browser_->profile())), | 123 model_(ToolbarActionsModel::Get(browser_->profile())), |
| 123 main_bar_(main_bar), | 124 main_bar_(main_bar), |
| 124 platform_settings_(main_bar != nullptr), | 125 platform_settings_(main_bar != nullptr), |
| 126 component_ids_(ComponentToolbarActionsFactory::GetComponentIds()), |
| 125 popup_owner_(nullptr), | 127 popup_owner_(nullptr), |
| 126 model_observer_(this), | 128 model_observer_(this), |
| 127 suppress_layout_(false), | 129 suppress_layout_(false), |
| 128 suppress_animation_(true), | 130 suppress_animation_(true), |
| 129 overflowed_action_wants_to_run_(false), | 131 overflowed_action_wants_to_run_(false), |
| 130 checked_extension_bubble_(false), | 132 checked_extension_bubble_(false), |
| 131 popped_out_action_(nullptr), | 133 popped_out_action_(nullptr), |
| 132 weak_ptr_factory_(this) { | 134 weak_ptr_factory_(this) { |
| 133 if (model_) // |model_| can be null in unittests. | 135 if (model_) // |model_| can be null in unittests. |
| 134 model_observer_.Add(model_); | 136 model_observer_.Add(model_); |
| (...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 251 // want to "slide" the action back in. | 253 // want to "slide" the action back in. |
| 252 size_t visible_icons = in_overflow_mode() ? | 254 size_t visible_icons = in_overflow_mode() ? |
| 253 toolbar_actions_.size() - model_->visible_icon_count() : | 255 toolbar_actions_.size() - model_->visible_icon_count() : |
| 254 model_->visible_icon_count() + pop_out_modifier; | 256 model_->visible_icon_count() + pop_out_modifier; |
| 255 | 257 |
| 256 #if DCHECK_IS_ON() | 258 #if DCHECK_IS_ON() |
| 257 // Good time for some sanity checks: We should never try to display more | 259 // Good time for some sanity checks: We should never try to display more |
| 258 // icons than we have, and we should always have a view per item in the model. | 260 // icons than we have, and we should always have a view per item in the model. |
| 259 // (The only exception is if this is in initialization.) | 261 // (The only exception is if this is in initialization.) |
| 260 if (!toolbar_actions_.empty() && !suppress_layout_ && | 262 if (!toolbar_actions_.empty() && !suppress_layout_ && |
| 261 model_->extensions_initialized()) { | 263 model_->actions_initialized()) { |
| 262 size_t num_extension_actions = 0u; | 264 size_t num_extension_actions = 0u; |
| 263 for (ToolbarActionViewController* action : toolbar_actions_) { | 265 for (ToolbarActionViewController* action : toolbar_actions_) { |
| 264 // No component action should ever have a valid extension id, so we can | 266 // No component action should ever have a valid extension id, so we can |
| 265 // use this to check the extension amount. | 267 // use this to check the extension amount. |
| 266 if (crx_file::id_util::IdIsValid(action->GetId())) | 268 if (crx_file::id_util::IdIsValid(action->GetId())) |
| 267 ++num_extension_actions; | 269 ++num_extension_actions; |
| 268 } | 270 } |
| 269 | 271 |
| 270 int num_component_actions = | 272 int num_component_actions = |
| 271 ComponentToolbarActionsFactory::GetInstance()-> | 273 ComponentToolbarActionsFactory::GetInstance()-> |
| 272 GetNumComponentActions(browser_); | 274 GetNumComponentActions(browser_); |
| 273 size_t num_total_actions = num_extension_actions + num_component_actions; | 275 size_t num_total_actions = num_extension_actions + num_component_actions; |
| 274 | 276 |
| 275 DCHECK_LE(visible_icons, num_total_actions); | 277 DCHECK_LE(visible_icons, num_total_actions); |
| 276 DCHECK_EQ(model_->toolbar_items().size(), num_extension_actions); | 278 DCHECK_EQ(model_->toolbar_items().size(), num_total_actions); |
| 277 } | 279 } |
| 278 #endif | 280 #endif |
| 279 | 281 |
| 280 return visible_icons; | 282 return visible_icons; |
| 281 } | 283 } |
| 282 | 284 |
| 283 std::vector<ToolbarActionViewController*> | 285 std::vector<ToolbarActionViewController*> |
| 284 ToolbarActionsBar::GetActions() const { | 286 ToolbarActionsBar::GetActions() const { |
| 285 std::vector<ToolbarActionViewController*> actions = toolbar_actions_.get(); | 287 std::vector<ToolbarActionViewController*> actions = toolbar_actions_.get(); |
| 286 | 288 |
| (...skipping 13 matching lines...) Expand all Loading... |
| 300 } | 302 } |
| 301 } | 303 } |
| 302 | 304 |
| 303 return actions; | 305 return actions; |
| 304 } | 306 } |
| 305 | 307 |
| 306 void ToolbarActionsBar::CreateActions() { | 308 void ToolbarActionsBar::CreateActions() { |
| 307 DCHECK(toolbar_actions_.empty()); | 309 DCHECK(toolbar_actions_.empty()); |
| 308 // We wait for the extension system to be initialized before we add any | 310 // We wait for the extension system to be initialized before we add any |
| 309 // actions, as they rely on the extension system to function. | 311 // actions, as they rely on the extension system to function. |
| 310 if (!model_ || !model_->extensions_initialized()) | 312 if (!model_ || !model_->actions_initialized()) |
| 311 return; | 313 return; |
| 312 | 314 |
| 313 { | 315 { |
| 314 // TODO(robliao): Remove ScopedTracker below once https://crbug.com/463337 | 316 // TODO(robliao): Remove ScopedTracker below once https://crbug.com/463337 |
| 315 // is fixed. | 317 // is fixed. |
| 316 tracked_objects::ScopedTracker tracking_profile1( | 318 tracked_objects::ScopedTracker tracking_profile1( |
| 317 FROM_HERE_WITH_EXPLICIT_FUNCTION("ToolbarActionsBar::CreateActions1")); | 319 FROM_HERE_WITH_EXPLICIT_FUNCTION("ToolbarActionsBar::CreateActions1")); |
| 318 // We don't redraw the view while creating actions. | 320 // We don't redraw the view while creating actions. |
| 319 base::AutoReset<bool> layout_resetter(&suppress_layout_, true); | 321 base::AutoReset<bool> layout_resetter(&suppress_layout_, true); |
| 320 | 322 |
| 321 // Extension actions come first. | 323 // Get the toolbar actions. |
| 322 extensions::ExtensionActionManager* action_manager = | 324 toolbar_actions_ = model_->GetActions(browser_, this); |
| 323 extensions::ExtensionActionManager::Get(browser_->profile()); | |
| 324 const extensions::ExtensionList& toolbar_items = model_->toolbar_items(); | |
| 325 for (const scoped_refptr<const extensions::Extension>& extension : | |
| 326 toolbar_items) { | |
| 327 toolbar_actions_.push_back(new ExtensionActionViewController( | |
| 328 extension.get(), | |
| 329 browser_, | |
| 330 action_manager->GetExtensionAction(*extension), | |
| 331 this)); | |
| 332 } | |
| 333 | 325 |
| 334 // Component actions come second, and are suppressed if the extension | |
| 335 // actions are being highlighted. | |
| 336 if (!model_->is_highlighting()) { | 326 if (!model_->is_highlighting()) { |
| 337 // TODO(robliao): Remove ScopedTracker below once https://crbug.com/463337 | 327 // TODO(robliao): Remove ScopedTracker below once https://crbug.com/463337 |
| 338 // is fixed. | 328 // is fixed. |
| 339 tracked_objects::ScopedTracker tracking_profile2( | 329 tracked_objects::ScopedTracker tracking_profile2( |
| 340 FROM_HERE_WITH_EXPLICIT_FUNCTION( | 330 FROM_HERE_WITH_EXPLICIT_FUNCTION( |
| 341 "ToolbarActionsBar::CreateActions2")); | 331 "ToolbarActionsBar::CreateActions2")); |
| 342 | |
| 343 ScopedVector<ToolbarActionViewController> component_actions = | |
| 344 ComponentToolbarActionsFactory::GetInstance()-> | |
| 345 GetComponentToolbarActions(browser_); | |
| 346 DCHECK(component_actions.empty() || | |
| 347 extensions::FeatureSwitch::extension_action_redesign()->IsEnabled()); | |
| 348 toolbar_actions_.insert(toolbar_actions_.end(), | |
| 349 component_actions.begin(), | |
| 350 component_actions.end()); | |
| 351 component_actions.weak_clear(); | |
| 352 } | 332 } |
| 353 | 333 |
| 354 if (!toolbar_actions_.empty()) { | 334 if (!toolbar_actions_.empty()) { |
| 355 // TODO(robliao): Remove ScopedTracker below once https://crbug.com/463337 | 335 // TODO(robliao): Remove ScopedTracker below once https://crbug.com/463337 |
| 356 // is fixed. | 336 // is fixed. |
| 357 tracked_objects::ScopedTracker tracking_profile3( | 337 tracked_objects::ScopedTracker tracking_profile3( |
| 358 FROM_HERE_WITH_EXPLICIT_FUNCTION( | 338 FROM_HERE_WITH_EXPLICIT_FUNCTION( |
| 359 "ToolbarActionsBar::CreateActions3")); | 339 "ToolbarActionsBar::CreateActions3")); |
| 360 ReorderActions(); | 340 ReorderActions(); |
| 361 } | 341 } |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 431 if (in_overflow_mode()) { | 411 if (in_overflow_mode()) { |
| 432 main_bar_->OnDragDrop(dragged_index, dropped_index, drag_type); | 412 main_bar_->OnDragDrop(dragged_index, dropped_index, drag_type); |
| 433 return; | 413 return; |
| 434 } | 414 } |
| 435 | 415 |
| 436 int delta = 0; | 416 int delta = 0; |
| 437 if (drag_type == DRAG_TO_OVERFLOW) | 417 if (drag_type == DRAG_TO_OVERFLOW) |
| 438 delta = -1; | 418 delta = -1; |
| 439 else if (drag_type == DRAG_TO_MAIN) | 419 else if (drag_type == DRAG_TO_MAIN) |
| 440 delta = 1; | 420 delta = 1; |
| 441 model_->MoveExtensionIcon(toolbar_actions_[dragged_index]->GetId(), | 421 model_->MoveActionIcon(toolbar_actions_[dragged_index]->GetId(), |
| 442 dropped_index); | 422 dropped_index); |
| 443 if (delta) | 423 if (delta) |
| 444 model_->SetVisibleIconCount(model_->visible_icon_count() + delta); | 424 model_->SetVisibleIconCount(model_->visible_icon_count() + delta); |
| 445 } | 425 } |
| 446 | 426 |
| 447 void ToolbarActionsBar::OnAnimationEnded() { | 427 void ToolbarActionsBar::OnAnimationEnded() { |
| 448 // Check if we were waiting for animation to complete to either show a | 428 // Check if we were waiting for animation to complete to either show a |
| 449 // message bubble, or to show a popup. | 429 // message bubble, or to show a popup. |
| 450 if (pending_extension_bubble_controller_) { | 430 if (pending_extension_bubble_controller_) { |
| 451 MaybeShowExtensionBubble(pending_extension_bubble_controller_.Pass()); | 431 MaybeShowExtensionBubble(pending_extension_bubble_controller_.Pass()); |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 516 } | 496 } |
| 517 | 497 |
| 518 void ToolbarActionsBar::MaybeShowExtensionBubble( | 498 void ToolbarActionsBar::MaybeShowExtensionBubble( |
| 519 scoped_ptr<extensions::ExtensionMessageBubbleController> controller) { | 499 scoped_ptr<extensions::ExtensionMessageBubbleController> controller) { |
| 520 controller->HighlightExtensionsIfNecessary(); // Safe to call multiple times. | 500 controller->HighlightExtensionsIfNecessary(); // Safe to call multiple times. |
| 521 if (delegate_->IsAnimating()) { | 501 if (delegate_->IsAnimating()) { |
| 522 // If the toolbar is animating, we can't effectively anchor the bubble, | 502 // If the toolbar is animating, we can't effectively anchor the bubble, |
| 523 // so wait until animation stops. | 503 // so wait until animation stops. |
| 524 pending_extension_bubble_controller_ = controller.Pass(); | 504 pending_extension_bubble_controller_ = controller.Pass(); |
| 525 } else { | 505 } else { |
| 526 const extensions::ExtensionIdList& affected_extensions = | 506 const ActionIdList& affected_extensions = controller->GetExtensionIdList(); |
| 527 controller->GetExtensionIdList(); | |
| 528 ToolbarActionViewController* anchor_action = nullptr; | 507 ToolbarActionViewController* anchor_action = nullptr; |
| 529 for (const std::string& id : affected_extensions) { | 508 for (const std::string& id : affected_extensions) { |
| 530 anchor_action = GetActionForId(id); | 509 anchor_action = GetActionForId(id); |
| 531 if (anchor_action) | 510 if (anchor_action) |
| 532 break; | 511 break; |
| 533 } | 512 } |
| 534 delegate_->ShowExtensionMessageBubble(controller.Pass(), anchor_action); | 513 delegate_->ShowExtensionMessageBubble(controller.Pass(), anchor_action); |
| 535 } | 514 } |
| 536 } | 515 } |
| 537 | 516 |
| 538 void ToolbarActionsBar::OnToolbarExtensionAdded( | 517 void ToolbarActionsBar::OnToolbarActionAdded(const ActionId action_id, |
| 539 const extensions::Extension* extension, | 518 int index) { |
| 540 int index) { | 519 DCHECK(GetActionForId(action_id) == nullptr) << |
| 541 DCHECK(GetActionForId(extension->id()) == nullptr) << | |
| 542 "Asked to add a toolbar action view for an extension that already exists"; | 520 "Asked to add a toolbar action view for an extension that already exists"; |
| 543 | 521 |
| 522 // Check that |action_id| is not a component action since |
| 523 // OnToolbarActionAdded is only called after the toolbar model has been |
| 524 // initialized. |
| 525 if (std::find(component_ids_.begin(), component_ids_.end(), action_id) != |
| 526 component_ids_.end()) |
| 527 return; |
| 528 |
| 529 const extensions::Extension* extension = |
| 530 extensions::ExtensionRegistry::Get(browser_->profile())-> |
| 531 enabled_extensions().GetByID(action_id); |
| 532 |
| 544 toolbar_actions_.insert( | 533 toolbar_actions_.insert( |
| 545 toolbar_actions_.begin() + index, | 534 toolbar_actions_.begin() + index, |
| 546 new ExtensionActionViewController( | 535 new ExtensionActionViewController( |
| 547 extension, | 536 extension, |
| 548 browser_, | 537 browser_, |
| 549 extensions::ExtensionActionManager::Get(browser_->profile())-> | 538 extensions::ExtensionActionManager::Get(browser_->profile())-> |
| 550 GetExtensionAction(*extension), | 539 GetExtensionAction(*extension), |
| 551 this)); | 540 this)); |
| 552 | 541 |
| 553 delegate_->AddViewForAction(toolbar_actions_[index], index); | 542 delegate_->AddViewForAction(toolbar_actions_[index], index); |
| 554 | 543 |
| 555 // If we are still initializing the container, don't bother animating. | 544 // If we are still initializing the container, don't bother animating. |
| 556 if (!model_->extensions_initialized()) | 545 if (!model_->actions_initialized()) |
| 557 return; | 546 return; |
| 558 | 547 |
| 559 // We may need to resize (e.g. to show the new icon, or the chevron). We don't | 548 // We may need to resize (e.g. to show the new icon, or the chevron). We don't |
| 560 // need to check if the extension is upgrading here, because ResizeDelegate() | 549 // need to check if the extension is upgrading here, because ResizeDelegate() |
| 561 // checks to see if the container is already the proper size, and because | 550 // checks to see if the container is already the proper size, and because |
| 562 // if the action is newly incognito enabled, even though it's a reload, it's | 551 // if the action is newly incognito enabled, even though it's a reload, it's |
| 563 // a new extension to this toolbar. | 552 // a new extension to this toolbar. |
| 564 // We suppress the chevron during animation because, if we're expanding to | 553 // We suppress the chevron during animation because, if we're expanding to |
| 565 // show a new icon, we don't want to have the chevron visible only for the | 554 // show a new icon, we don't want to have the chevron visible only for the |
| 566 // duration of the animation. | 555 // duration of the animation. |
| 567 ResizeDelegate(gfx::Tween::LINEAR, true); | 556 ResizeDelegate(gfx::Tween::LINEAR, true); |
| 568 } | 557 } |
| 569 | 558 |
| 570 void ToolbarActionsBar::OnToolbarExtensionRemoved( | 559 void ToolbarActionsBar::OnToolbarActionRemoved(const ActionId action_id) { |
| 571 const extensions::Extension* extension) { | |
| 572 ToolbarActions::iterator iter = toolbar_actions_.begin(); | 560 ToolbarActions::iterator iter = toolbar_actions_.begin(); |
| 573 while (iter != toolbar_actions_.end() && (*iter)->GetId() != extension->id()) | 561 while (iter != toolbar_actions_.end() && (*iter)->GetId() != action_id) |
| 574 ++iter; | 562 ++iter; |
| 575 | 563 |
| 576 if (iter == toolbar_actions_.end()) | 564 if (iter == toolbar_actions_.end()) |
| 577 return; | 565 return; |
| 578 | 566 |
| 567 // Component actions cannot be removed. |
| 568 if (std::find(component_ids_.begin(), component_ids_.end(), action_id) != |
| 569 component_ids_.end()) |
| 570 return; |
| 571 |
| 579 // The action should outlive the UI element (which is owned by the delegate), | 572 // The action should outlive the UI element (which is owned by the delegate), |
| 580 // so we can't delete it just yet. But we should remove it from the list of | 573 // so we can't delete it just yet. But we should remove it from the list of |
| 581 // actions so that any width calculations are correct. | 574 // actions so that any width calculations are correct. |
| 582 scoped_ptr<ToolbarActionViewController> removed_action(*iter); | 575 scoped_ptr<ToolbarActionViewController> removed_action(*iter); |
| 583 toolbar_actions_.weak_erase(iter); | 576 toolbar_actions_.weak_erase(iter); |
| 584 delegate_->RemoveViewForAction(removed_action.get()); | 577 delegate_->RemoveViewForAction(removed_action.get()); |
| 585 removed_action.reset(); | 578 removed_action.reset(); |
| 586 | 579 |
| 587 // If the extension is being upgraded we don't want the bar to shrink | 580 // If the extension is being upgraded we don't want the bar to shrink |
| 588 // because the icon is just going to get re-added to the same location. | 581 // because the icon is just going to get re-added to the same location. |
| 589 // There is an exception if this is an off-the-record profile, and the | 582 // There is an exception if this is an off-the-record profile, and the |
| 590 // extension is no longer incognito-enabled. | 583 // extension is no longer incognito-enabled. |
| 591 if (!extensions::ExtensionSystem::Get(browser_->profile())->runtime_data()-> | 584 if (!extensions::ExtensionSystem::Get(browser_->profile())->runtime_data()-> |
| 592 IsBeingUpgraded(extension->id()) || | 585 IsBeingUpgraded(action_id) || |
| 593 (browser_->profile()->IsOffTheRecord() && | 586 (browser_->profile()->IsOffTheRecord() && |
| 594 !extensions::util::IsIncognitoEnabled(extension->id(), | 587 !extensions::util::IsIncognitoEnabled(action_id, |
| 595 browser_->profile()))) { | 588 browser_->profile()))) { |
| 596 if (toolbar_actions_.size() > model_->visible_icon_count()) { | 589 if (toolbar_actions_.size() > model_->visible_icon_count()) { |
| 597 // If we have more icons than we can show, then we must not be changing | 590 // If we have more icons than we can show, then we must not be changing |
| 598 // the container size (since we either removed an icon from the main | 591 // the container size (since we either removed an icon from the main |
| 599 // area and one from the overflow list will have shifted in, or we | 592 // area and one from the overflow list will have shifted in, or we |
| 600 // removed an entry directly from the overflow list). | 593 // removed an entry directly from the overflow list). |
| 601 delegate_->Redraw(false); | 594 delegate_->Redraw(false); |
| 602 } else { | 595 } else { |
| 603 delegate_->SetChevronVisibility(false); | 596 delegate_->SetChevronVisibility(false); |
| 604 // Either we went from overflow to no-overflow, or we shrunk the no- | 597 // Either we went from overflow to no-overflow, or we shrunk the no- |
| 605 // overflow container by 1. Either way the size changed, so animate. | 598 // overflow container by 1. Either way the size changed, so animate. |
| 606 ResizeDelegate(gfx::Tween::EASE_OUT, false); | 599 ResizeDelegate(gfx::Tween::EASE_OUT, false); |
| 607 } | 600 } |
| 608 } | 601 } |
| 609 } | 602 } |
| 610 | 603 |
| 611 void ToolbarActionsBar::OnToolbarExtensionMoved( | 604 void ToolbarActionsBar::OnToolbarActionMoved(const ActionId action_id, |
| 612 const extensions::Extension* extension, | 605 int index) { |
| 613 int index) { | |
| 614 DCHECK(index >= 0 && index < static_cast<int>(toolbar_actions_.size())); | 606 DCHECK(index >= 0 && index < static_cast<int>(toolbar_actions_.size())); |
| 615 // Unfortunately, |index| doesn't really mean a lot to us, because this | 607 // Unfortunately, |index| doesn't really mean a lot to us, because this |
| 616 // window's toolbar could be different (if actions are popped out). Just | 608 // window's toolbar could be different (if actions are popped out). Just |
| 617 // do a full reorder. | 609 // do a full reorder. |
| 618 ReorderActions(); | 610 ReorderActions(); |
| 619 } | 611 } |
| 620 | 612 |
| 621 void ToolbarActionsBar::OnToolbarExtensionUpdated( | 613 void ToolbarActionsBar::OnToolbarActionUpdated(const ActionId action_id) { |
| 622 const extensions::Extension* extension) { | 614 ToolbarActionViewController* action = GetActionForId(action_id); |
| 623 ToolbarActionViewController* action = GetActionForId(extension->id()); | |
| 624 // There might not be a view in cases where we are highlighting or if we | 615 // There might not be a view in cases where we are highlighting or if we |
| 625 // haven't fully initialized the actions. | 616 // haven't fully initialized the actions. |
| 626 if (action) { | 617 if (action) { |
| 627 action->UpdateState(); | 618 action->UpdateState(); |
| 628 SetOverflowedActionWantsToRun(); | 619 SetOverflowedActionWantsToRun(); |
| 629 } | 620 } |
| 630 } | 621 } |
| 631 | 622 |
| 632 bool ToolbarActionsBar::ShowExtensionActionPopup( | 623 bool ToolbarActionsBar::ShowToolbarActionPopup(const ActionId action_id, |
| 633 const extensions::Extension* extension, | 624 bool grant_active_tab) { |
| 634 bool grant_active_tab) { | |
| 635 // Don't override another popup, and only show in the active window. | 625 // Don't override another popup, and only show in the active window. |
| 636 if (popup_owner() || !browser_->window()->IsActive()) | 626 if (popup_owner() || !browser_->window()->IsActive()) |
| 637 return false; | 627 return false; |
| 638 | 628 |
| 639 ToolbarActionViewController* action = GetActionForId(extension->id()); | 629 ToolbarActionViewController* action = GetActionForId(action_id); |
| 640 return action && action->ExecuteAction(grant_active_tab); | 630 return action && action->ExecuteAction(grant_active_tab); |
| 641 } | 631 } |
| 642 | 632 |
| 643 void ToolbarActionsBar::OnToolbarVisibleCountChanged() { | 633 void ToolbarActionsBar::OnToolbarVisibleCountChanged() { |
| 644 ResizeDelegate(gfx::Tween::EASE_OUT, false); | 634 ResizeDelegate(gfx::Tween::EASE_OUT, false); |
| 645 SetOverflowedActionWantsToRun(); | 635 SetOverflowedActionWantsToRun(); |
| 646 } | 636 } |
| 647 | 637 |
| 648 void ToolbarActionsBar::ResizeDelegate(gfx::Tween::Type tween_type, | 638 void ToolbarActionsBar::ResizeDelegate(gfx::Tween::Type tween_type, |
| 649 bool suppress_chevron) { | 639 bool suppress_chevron) { |
| 650 int desired_width = GetPreferredSize().width(); | 640 int desired_width = GetPreferredSize().width(); |
| 651 if (desired_width != delegate_->GetWidth()) { | 641 if (desired_width != delegate_->GetWidth()) { |
| 652 delegate_->ResizeAndAnimate(tween_type, desired_width, suppress_chevron); | 642 delegate_->ResizeAndAnimate(tween_type, desired_width, suppress_chevron); |
| 653 } else if (delegate_->IsAnimating()) { | 643 } else if (delegate_->IsAnimating()) { |
| 654 // It's possible that we're right where we're supposed to be in terms of | 644 // It's possible that we're right where we're supposed to be in terms of |
| 655 // width, but that we're also currently resizing. If this is the case, end | 645 // width, but that we're also currently resizing. If this is the case, end |
| 656 // the current animation with the current width. | 646 // the current animation with the current width. |
| 657 delegate_->StopAnimating(); | 647 delegate_->StopAnimating(); |
| 658 } else { | 648 } else { |
| 659 // We may already be at the right size (this can happen frequently with | 649 // We may already be at the right size (this can happen frequently with |
| 660 // overflow, where we have a fixed width, and in tests, where we skip | 650 // overflow, where we have a fixed width, and in tests, where we skip |
| 661 // animations). If this is the case, we still need to Redraw(), because the | 651 // animations). If this is the case, we still need to Redraw(), because the |
| 662 // icons within the toolbar may have changed (e.g. if we removed one | 652 // icons within the toolbar may have changed (e.g. if we removed one |
| 663 // action and added a different one in quick succession). | 653 // action and added a different one in quick succession). |
| 664 delegate_->Redraw(false); | 654 delegate_->Redraw(false); |
| 665 } | 655 } |
| 666 } | 656 } |
| 667 | 657 |
| 668 void ToolbarActionsBar::OnToolbarHighlightModeChanged(bool is_highlighting) { | 658 void ToolbarActionsBar::OnToolbarHighlightModeChanged(bool is_highlighting) { |
| 669 if (!model_->extensions_initialized()) | 659 if (!model_->actions_initialized()) |
| 670 return; | 660 return; |
| 671 // It's a bit of a pain that we delete and recreate everything here, but given | 661 // It's a bit of a pain that we delete and recreate everything here, but given |
| 672 // everything else going on (the lack of highlight, [n] more extensions | 662 // everything else going on (the lack of highlight, [n] more extensions |
| 673 // appearing, etc), it's not worth the extra complexity to create and insert | 663 // appearing, etc), it's not worth the extra complexity to create and insert |
| 674 // only the new actions. | 664 // only the new actions. |
| 675 DeleteActions(); | 665 DeleteActions(); |
| 676 CreateActions(); | 666 CreateActions(); |
| 677 // Resize the delegate. We suppress the chevron so that we don't risk showing | 667 // Resize the delegate. We suppress the chevron so that we don't risk showing |
| 678 // it only for the duration of the animation. | 668 // it only for the duration of the animation. |
| 679 ResizeDelegate(gfx::Tween::LINEAR, true); | 669 ResizeDelegate(gfx::Tween::LINEAR, true); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 695 Browser* ToolbarActionsBar::GetBrowser() { | 685 Browser* ToolbarActionsBar::GetBrowser() { |
| 696 return browser_; | 686 return browser_; |
| 697 } | 687 } |
| 698 | 688 |
| 699 void ToolbarActionsBar::ReorderActions() { | 689 void ToolbarActionsBar::ReorderActions() { |
| 700 if (toolbar_actions_.empty()) | 690 if (toolbar_actions_.empty()) |
| 701 return; | 691 return; |
| 702 | 692 |
| 703 // First, reset the order to that of the model. | 693 // First, reset the order to that of the model. |
| 704 auto compare = [](ToolbarActionViewController* const& action, | 694 auto compare = [](ToolbarActionViewController* const& action, |
| 705 const scoped_refptr<const extensions::Extension>& ext) { | 695 const std::string ext) { |
| 706 return action->GetId() == ext->id(); | 696 return action->GetId() == ext; |
| 707 }; | 697 }; |
| 708 SortContainer(&toolbar_actions_.get(), model_->toolbar_items(), compare); | 698 SortContainer(&toolbar_actions_.get(), model_->toolbar_items(), compare); |
| 709 | 699 |
| 710 // Our visible browser actions may have changed - re-Layout() and check the | 700 // Our visible browser actions may have changed - re-Layout() and check the |
| 711 // size (if we aren't suppressing the layout). | 701 // size (if we aren't suppressing the layout). |
| 712 if (!suppress_layout_) { | 702 if (!suppress_layout_) { |
| 713 ResizeDelegate(gfx::Tween::EASE_OUT, false); | 703 ResizeDelegate(gfx::Tween::EASE_OUT, false); |
| 714 delegate_->Redraw(true); | 704 delegate_->Redraw(true); |
| 715 } | 705 } |
| 716 | 706 |
| (...skipping 14 matching lines...) Expand all Loading... |
| 731 | 721 |
| 732 if (overflowed_action_wants_to_run_ != overflowed_action_wants_to_run) { | 722 if (overflowed_action_wants_to_run_ != overflowed_action_wants_to_run) { |
| 733 overflowed_action_wants_to_run_ = overflowed_action_wants_to_run; | 723 overflowed_action_wants_to_run_ = overflowed_action_wants_to_run; |
| 734 if (send_overflowed_action_changes_) | 724 if (send_overflowed_action_changes_) |
| 735 delegate_->OnOverflowedActionWantsToRunChanged( | 725 delegate_->OnOverflowedActionWantsToRunChanged( |
| 736 overflowed_action_wants_to_run_); | 726 overflowed_action_wants_to_run_); |
| 737 } | 727 } |
| 738 } | 728 } |
| 739 | 729 |
| 740 ToolbarActionViewController* ToolbarActionsBar::GetActionForId( | 730 ToolbarActionViewController* ToolbarActionsBar::GetActionForId( |
| 741 const std::string& id) { | 731 const ActionId& action_id) { |
| 742 for (ToolbarActionViewController* action : toolbar_actions_) { | 732 for (ToolbarActionViewController* action : toolbar_actions_) { |
| 743 if (action->GetId() == id) | 733 if (action->GetId() == action_id) |
| 744 return action; | 734 return action; |
| 745 } | 735 } |
| 746 return nullptr; | 736 return nullptr; |
| 747 } | 737 } |
| 748 | 738 |
| 749 content::WebContents* ToolbarActionsBar::GetCurrentWebContents() { | 739 content::WebContents* ToolbarActionsBar::GetCurrentWebContents() { |
| 750 return browser_->tab_strip_model()->GetActiveWebContents(); | 740 return browser_->tab_strip_model()->GetActiveWebContents(); |
| 751 } | 741 } |
| OLD | NEW |