Chromium Code Reviews| 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), |
| 125 popup_owner_(nullptr), | 126 popup_owner_(nullptr), |
| 126 model_observer_(this), | 127 model_observer_(this), |
| 127 suppress_layout_(false), | 128 suppress_layout_(false), |
| 128 suppress_animation_(true), | 129 suppress_animation_(true), |
| 129 overflowed_action_wants_to_run_(false), | 130 overflowed_action_wants_to_run_(false), |
| 130 checked_extension_bubble_(false), | 131 checked_extension_bubble_(false), |
| 131 popped_out_action_(nullptr), | 132 popped_out_action_(nullptr), |
| 132 weak_ptr_factory_(this) { | 133 weak_ptr_factory_(this) { |
| (...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 251 // want to "slide" the action back in. | 252 // want to "slide" the action back in. |
| 252 size_t visible_icons = in_overflow_mode() ? | 253 size_t visible_icons = in_overflow_mode() ? |
| 253 toolbar_actions_.size() - model_->visible_icon_count() : | 254 toolbar_actions_.size() - model_->visible_icon_count() : |
| 254 model_->visible_icon_count() + pop_out_modifier; | 255 model_->visible_icon_count() + pop_out_modifier; |
| 255 | 256 |
| 256 #if DCHECK_IS_ON() | 257 #if DCHECK_IS_ON() |
| 257 // Good time for some sanity checks: We should never try to display more | 258 // 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. | 259 // 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.) | 260 // (The only exception is if this is in initialization.) |
| 260 if (!toolbar_actions_.empty() && !suppress_layout_ && | 261 if (!toolbar_actions_.empty() && !suppress_layout_ && |
| 261 model_->extensions_initialized()) { | 262 model_->actions_initialized()) { |
| 262 size_t num_extension_actions = 0u; | 263 size_t num_actions = 0u; |
| 263 for (ToolbarActionViewController* action : toolbar_actions_) { | 264 for (ToolbarActionViewController* action : toolbar_actions_) { |
| 264 // No component action should ever have a valid extension id, so we can | 265 // No component action should ever have a valid extension id, so we can |
| 265 // use this to check the extension amount. | 266 // use this to check the extension amount. |
| 266 if (crx_file::id_util::IdIsValid(action->GetId())) | 267 if (crx_file::id_util::IdIsValid(action->GetId()) || |
|
Devlin
2015/08/13 21:21:11
In updating these, it looks like the checks here a
apacible
2015/08/15 08:46:41
Done.
| |
| 267 ++num_extension_actions; | 268 model_->IsKnownActionWithType(action->GetId(), |
| 269 ToolbarActionsModel::COMPONENT_ACTION)) | |
| 270 ++num_actions; | |
| 268 } | 271 } |
| 269 | 272 |
| 270 int num_component_actions = | 273 DCHECK_LE(visible_icons, num_actions); |
| 271 ComponentToolbarActionsFactory::GetInstance()-> | 274 DCHECK_EQ(model_->toolbar_items().size(), num_actions); |
| 272 GetNumComponentActions(browser_); | |
| 273 size_t num_total_actions = num_extension_actions + num_component_actions; | |
| 274 | |
| 275 DCHECK_LE(visible_icons, num_total_actions); | |
| 276 DCHECK_EQ(model_->toolbar_items().size(), num_extension_actions); | |
| 277 } | 275 } |
| 278 #endif | 276 #endif |
| 279 | 277 |
| 280 return visible_icons; | 278 return visible_icons; |
| 281 } | 279 } |
| 282 | 280 |
| 283 gfx::Rect ToolbarActionsBar::GetFrameForIndex(size_t index) const { | 281 gfx::Rect ToolbarActionsBar::GetFrameForIndex(size_t index) const { |
| 284 size_t start_index = in_overflow_mode() ? | 282 size_t start_index = in_overflow_mode() ? |
| 285 toolbar_actions_.size() - GetIconCount() : 0u; | 283 toolbar_actions_.size() - GetIconCount() : 0u; |
| 286 | 284 |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 324 } | 322 } |
| 325 } | 323 } |
| 326 | 324 |
| 327 return actions; | 325 return actions; |
| 328 } | 326 } |
| 329 | 327 |
| 330 void ToolbarActionsBar::CreateActions() { | 328 void ToolbarActionsBar::CreateActions() { |
| 331 DCHECK(toolbar_actions_.empty()); | 329 DCHECK(toolbar_actions_.empty()); |
| 332 // We wait for the extension system to be initialized before we add any | 330 // We wait for the extension system to be initialized before we add any |
| 333 // actions, as they rely on the extension system to function. | 331 // actions, as they rely on the extension system to function. |
| 334 if (!model_ || !model_->extensions_initialized()) | 332 if (!model_ || !model_->actions_initialized()) |
| 335 return; | 333 return; |
| 336 | 334 |
| 337 { | 335 { |
| 338 // TODO(robliao): Remove ScopedTracker below once https://crbug.com/463337 | 336 // TODO(robliao): Remove ScopedTracker below once https://crbug.com/463337 |
| 339 // is fixed. | 337 // is fixed. |
| 340 tracked_objects::ScopedTracker tracking_profile1( | 338 tracked_objects::ScopedTracker tracking_profile1( |
| 341 FROM_HERE_WITH_EXPLICIT_FUNCTION("ToolbarActionsBar::CreateActions1")); | 339 FROM_HERE_WITH_EXPLICIT_FUNCTION("ToolbarActionsBar::CreateActions1")); |
| 342 // We don't redraw the view while creating actions. | 340 // We don't redraw the view while creating actions. |
| 343 base::AutoReset<bool> layout_resetter(&suppress_layout_, true); | 341 base::AutoReset<bool> layout_resetter(&suppress_layout_, true); |
| 344 | 342 |
| 345 // Extension actions come first. | 343 // Get the toolbar actions. |
| 346 extensions::ExtensionActionManager* action_manager = | 344 toolbar_actions_ = model_->CreateActions(browser_, this); |
| 347 extensions::ExtensionActionManager::Get(browser_->profile()); | |
| 348 const extensions::ExtensionList& toolbar_items = model_->toolbar_items(); | |
| 349 for (const scoped_refptr<const extensions::Extension>& extension : | |
| 350 toolbar_items) { | |
| 351 toolbar_actions_.push_back(new ExtensionActionViewController( | |
| 352 extension.get(), | |
| 353 browser_, | |
| 354 action_manager->GetExtensionAction(*extension), | |
| 355 this)); | |
| 356 } | |
| 357 | 345 |
| 358 // Component actions come second, and are suppressed if the extension | |
| 359 // actions are being highlighted. | |
| 360 if (!model_->is_highlighting()) { | 346 if (!model_->is_highlighting()) { |
| 361 // TODO(robliao): Remove ScopedTracker below once https://crbug.com/463337 | 347 // TODO(robliao): Remove ScopedTracker below once https://crbug.com/463337 |
| 362 // is fixed. | 348 // is fixed. |
| 363 tracked_objects::ScopedTracker tracking_profile2( | 349 tracked_objects::ScopedTracker tracking_profile2( |
| 364 FROM_HERE_WITH_EXPLICIT_FUNCTION( | 350 FROM_HERE_WITH_EXPLICIT_FUNCTION( |
| 365 "ToolbarActionsBar::CreateActions2")); | 351 "ToolbarActionsBar::CreateActions2")); |
| 366 | |
| 367 ScopedVector<ToolbarActionViewController> component_actions = | |
| 368 ComponentToolbarActionsFactory::GetInstance()-> | |
| 369 GetComponentToolbarActions(browser_); | |
| 370 DCHECK(component_actions.empty() || | |
| 371 extensions::FeatureSwitch::extension_action_redesign()->IsEnabled()); | |
| 372 toolbar_actions_.insert(toolbar_actions_.end(), | |
| 373 component_actions.begin(), | |
| 374 component_actions.end()); | |
| 375 component_actions.weak_clear(); | |
| 376 } | 352 } |
| 377 | 353 |
| 378 if (!toolbar_actions_.empty()) { | 354 if (!toolbar_actions_.empty()) { |
| 379 // TODO(robliao): Remove ScopedTracker below once https://crbug.com/463337 | 355 // TODO(robliao): Remove ScopedTracker below once https://crbug.com/463337 |
| 380 // is fixed. | 356 // is fixed. |
| 381 tracked_objects::ScopedTracker tracking_profile3( | 357 tracked_objects::ScopedTracker tracking_profile3( |
| 382 FROM_HERE_WITH_EXPLICIT_FUNCTION( | 358 FROM_HERE_WITH_EXPLICIT_FUNCTION( |
| 383 "ToolbarActionsBar::CreateActions3")); | 359 "ToolbarActionsBar::CreateActions3")); |
| 384 ReorderActions(); | 360 ReorderActions(); |
| 385 } | 361 } |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 455 if (in_overflow_mode()) { | 431 if (in_overflow_mode()) { |
| 456 main_bar_->OnDragDrop(dragged_index, dropped_index, drag_type); | 432 main_bar_->OnDragDrop(dragged_index, dropped_index, drag_type); |
| 457 return; | 433 return; |
| 458 } | 434 } |
| 459 | 435 |
| 460 int delta = 0; | 436 int delta = 0; |
| 461 if (drag_type == DRAG_TO_OVERFLOW) | 437 if (drag_type == DRAG_TO_OVERFLOW) |
| 462 delta = -1; | 438 delta = -1; |
| 463 else if (drag_type == DRAG_TO_MAIN) | 439 else if (drag_type == DRAG_TO_MAIN) |
| 464 delta = 1; | 440 delta = 1; |
| 465 model_->MoveExtensionIcon(toolbar_actions_[dragged_index]->GetId(), | 441 model_->MoveActionIcon(toolbar_actions_[dragged_index]->GetId(), |
| 466 dropped_index); | 442 dropped_index); |
| 467 if (delta) | 443 if (delta) |
| 468 model_->SetVisibleIconCount(model_->visible_icon_count() + delta); | 444 model_->SetVisibleIconCount(model_->visible_icon_count() + delta); |
| 469 } | 445 } |
| 470 | 446 |
| 471 void ToolbarActionsBar::OnAnimationEnded() { | 447 void ToolbarActionsBar::OnAnimationEnded() { |
| 472 // Check if we were waiting for animation to complete to either show a | 448 // Check if we were waiting for animation to complete to either show a |
| 473 // message bubble, or to show a popup. | 449 // message bubble, or to show a popup. |
| 474 if (pending_extension_bubble_controller_) { | 450 if (pending_extension_bubble_controller_) { |
| 475 MaybeShowExtensionBubble(pending_extension_bubble_controller_.Pass()); | 451 MaybeShowExtensionBubble(pending_extension_bubble_controller_.Pass()); |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 545 } | 521 } |
| 546 | 522 |
| 547 void ToolbarActionsBar::MaybeShowExtensionBubble( | 523 void ToolbarActionsBar::MaybeShowExtensionBubble( |
| 548 scoped_ptr<extensions::ExtensionMessageBubbleController> controller) { | 524 scoped_ptr<extensions::ExtensionMessageBubbleController> controller) { |
| 549 controller->HighlightExtensionsIfNecessary(); // Safe to call multiple times. | 525 controller->HighlightExtensionsIfNecessary(); // Safe to call multiple times. |
| 550 if (delegate_->IsAnimating()) { | 526 if (delegate_->IsAnimating()) { |
| 551 // If the toolbar is animating, we can't effectively anchor the bubble, | 527 // If the toolbar is animating, we can't effectively anchor the bubble, |
| 552 // so wait until animation stops. | 528 // so wait until animation stops. |
| 553 pending_extension_bubble_controller_ = controller.Pass(); | 529 pending_extension_bubble_controller_ = controller.Pass(); |
| 554 } else { | 530 } else { |
| 555 const extensions::ExtensionIdList& affected_extensions = | 531 const ActionIds& affected_extensions = controller->GetExtensionIdList(); |
| 556 controller->GetExtensionIdList(); | |
| 557 ToolbarActionViewController* anchor_action = nullptr; | 532 ToolbarActionViewController* anchor_action = nullptr; |
| 558 for (const std::string& id : affected_extensions) { | 533 for (const std::string& id : affected_extensions) { |
| 559 anchor_action = GetActionForId(id); | 534 anchor_action = GetActionForId(id); |
| 560 if (anchor_action) | 535 if (anchor_action) |
| 561 break; | 536 break; |
| 562 } | 537 } |
| 563 delegate_->ShowExtensionMessageBubble(controller.Pass(), anchor_action); | 538 delegate_->ShowExtensionMessageBubble(controller.Pass(), anchor_action); |
| 564 } | 539 } |
| 565 } | 540 } |
| 566 | 541 |
| 567 void ToolbarActionsBar::OnToolbarExtensionAdded( | 542 void ToolbarActionsBar::OnToolbarActionAdded(const std::string& action_id, |
| 568 const extensions::Extension* extension, | 543 int index) { |
| 569 int index) { | 544 DCHECK(GetActionForId(action_id) == nullptr) << |
| 570 DCHECK(GetActionForId(extension->id()) == nullptr) << | |
| 571 "Asked to add a toolbar action view for an extension that already exists"; | 545 "Asked to add a toolbar action view for an extension that already exists"; |
| 572 | 546 |
| 547 // TODO(rdevlin.cronin): This is a minor layering violation and the model | |
|
Devlin
2015/08/13 21:21:11
even though it's not the norm, my TODOs are (mostl
apacible
2015/08/15 08:46:41
Done.
| |
| 548 // should pass in an action directly. | |
| 549 const extensions::Extension* extension = | |
| 550 extensions::ExtensionRegistry::Get(browser_->profile())-> | |
| 551 enabled_extensions().GetByID(action_id); | |
|
Devlin
2015/08/13 21:21:11
// Only extensions should be added after initializ
apacible
2015/08/15 08:46:41
Done.
| |
| 552 | |
| 573 toolbar_actions_.insert( | 553 toolbar_actions_.insert( |
| 574 toolbar_actions_.begin() + index, | 554 toolbar_actions_.begin() + index, |
| 575 new ExtensionActionViewController( | 555 new ExtensionActionViewController( |
| 576 extension, | 556 extension, |
| 577 browser_, | 557 browser_, |
| 578 extensions::ExtensionActionManager::Get(browser_->profile())-> | 558 extensions::ExtensionActionManager::Get(browser_->profile())-> |
| 579 GetExtensionAction(*extension), | 559 GetExtensionAction(*extension), |
| 580 this)); | 560 this)); |
| 581 | 561 |
| 582 delegate_->AddViewForAction(toolbar_actions_[index], index); | 562 delegate_->AddViewForAction(toolbar_actions_[index], index); |
| 583 | 563 |
| 584 // If we are still initializing the container, don't bother animating. | 564 // If we are still initializing the container, don't bother animating. |
| 585 if (!model_->extensions_initialized()) | 565 if (!model_->actions_initialized()) |
| 586 return; | 566 return; |
| 587 | 567 |
| 588 // We may need to resize (e.g. to show the new icon, or the chevron). We don't | 568 // We may need to resize (e.g. to show the new icon, or the chevron). We don't |
| 589 // need to check if the extension is upgrading here, because ResizeDelegate() | 569 // need to check if the extension is upgrading here, because ResizeDelegate() |
| 590 // checks to see if the container is already the proper size, and because | 570 // checks to see if the container is already the proper size, and because |
| 591 // if the action is newly incognito enabled, even though it's a reload, it's | 571 // if the action is newly incognito enabled, even though it's a reload, it's |
| 592 // a new extension to this toolbar. | 572 // a new extension to this toolbar. |
| 593 // We suppress the chevron during animation because, if we're expanding to | 573 // We suppress the chevron during animation because, if we're expanding to |
| 594 // show a new icon, we don't want to have the chevron visible only for the | 574 // show a new icon, we don't want to have the chevron visible only for the |
| 595 // duration of the animation. | 575 // duration of the animation. |
| 596 ResizeDelegate(gfx::Tween::LINEAR, true); | 576 ResizeDelegate(gfx::Tween::LINEAR, true); |
| 597 } | 577 } |
| 598 | 578 |
| 599 void ToolbarActionsBar::OnToolbarExtensionRemoved( | 579 void ToolbarActionsBar::OnToolbarActionRemoved(const std::string& action_id) { |
| 600 const extensions::Extension* extension) { | |
| 601 ToolbarActions::iterator iter = toolbar_actions_.begin(); | 580 ToolbarActions::iterator iter = toolbar_actions_.begin(); |
| 602 while (iter != toolbar_actions_.end() && (*iter)->GetId() != extension->id()) | 581 while (iter != toolbar_actions_.end() && (*iter)->GetId() != action_id) |
| 603 ++iter; | 582 ++iter; |
| 604 | 583 |
| 605 if (iter == toolbar_actions_.end()) | 584 if (iter == toolbar_actions_.end()) |
| 606 return; | 585 return; |
| 607 | 586 |
| 608 // The action should outlive the UI element (which is owned by the delegate), | 587 // The action should outlive the UI element (which is owned by the delegate), |
| 609 // so we can't delete it just yet. But we should remove it from the list of | 588 // so we can't delete it just yet. But we should remove it from the list of |
| 610 // actions so that any width calculations are correct. | 589 // actions so that any width calculations are correct. |
| 611 scoped_ptr<ToolbarActionViewController> removed_action(*iter); | 590 scoped_ptr<ToolbarActionViewController> removed_action(*iter); |
| 612 toolbar_actions_.weak_erase(iter); | 591 toolbar_actions_.weak_erase(iter); |
| 613 delegate_->RemoveViewForAction(removed_action.get()); | 592 delegate_->RemoveViewForAction(removed_action.get()); |
| 614 removed_action.reset(); | 593 removed_action.reset(); |
| 615 | 594 |
| 616 // If the extension is being upgraded we don't want the bar to shrink | 595 // If the extension is being upgraded we don't want the bar to shrink |
| 617 // because the icon is just going to get re-added to the same location. | 596 // because the icon is just going to get re-added to the same location. |
| 618 // There is an exception if this is an off-the-record profile, and the | 597 // There is an exception if this is an off-the-record profile, and the |
| 619 // extension is no longer incognito-enabled. | 598 // extension is no longer incognito-enabled. |
| 620 if (!extensions::ExtensionSystem::Get(browser_->profile())->runtime_data()-> | 599 if (!extensions::ExtensionSystem::Get(browser_->profile())->runtime_data()-> |
| 621 IsBeingUpgraded(extension->id()) || | 600 IsBeingUpgraded(action_id) || |
| 622 (browser_->profile()->IsOffTheRecord() && | 601 (browser_->profile()->IsOffTheRecord() && |
| 623 !extensions::util::IsIncognitoEnabled(extension->id(), | 602 !extensions::util::IsIncognitoEnabled(action_id, |
| 624 browser_->profile()))) { | 603 browser_->profile()))) { |
| 625 if (toolbar_actions_.size() > model_->visible_icon_count()) { | 604 if (toolbar_actions_.size() > model_->visible_icon_count()) { |
| 626 // If we have more icons than we can show, then we must not be changing | 605 // If we have more icons than we can show, then we must not be changing |
| 627 // the container size (since we either removed an icon from the main | 606 // the container size (since we either removed an icon from the main |
| 628 // area and one from the overflow list will have shifted in, or we | 607 // area and one from the overflow list will have shifted in, or we |
| 629 // removed an entry directly from the overflow list). | 608 // removed an entry directly from the overflow list). |
| 630 delegate_->Redraw(false); | 609 delegate_->Redraw(false); |
| 631 } else { | 610 } else { |
| 632 delegate_->SetChevronVisibility(false); | 611 delegate_->SetChevronVisibility(false); |
| 633 // Either we went from overflow to no-overflow, or we shrunk the no- | 612 // Either we went from overflow to no-overflow, or we shrunk the no- |
| 634 // overflow container by 1. Either way the size changed, so animate. | 613 // overflow container by 1. Either way the size changed, so animate. |
| 635 ResizeDelegate(gfx::Tween::EASE_OUT, false); | 614 ResizeDelegate(gfx::Tween::EASE_OUT, false); |
| 636 } | 615 } |
| 637 } | 616 } |
| 638 | 617 |
| 639 SetOverflowedActionWantsToRun(); | 618 SetOverflowedActionWantsToRun(); |
| 640 } | 619 } |
| 641 | 620 |
| 642 void ToolbarActionsBar::OnToolbarExtensionMoved( | 621 void ToolbarActionsBar::OnToolbarActionMoved(const std::string& action_id, |
| 643 const extensions::Extension* extension, | 622 int index) { |
| 644 int index) { | |
| 645 DCHECK(index >= 0 && index < static_cast<int>(toolbar_actions_.size())); | 623 DCHECK(index >= 0 && index < static_cast<int>(toolbar_actions_.size())); |
| 646 // Unfortunately, |index| doesn't really mean a lot to us, because this | 624 // Unfortunately, |index| doesn't really mean a lot to us, because this |
| 647 // window's toolbar could be different (if actions are popped out). Just | 625 // window's toolbar could be different (if actions are popped out). Just |
| 648 // do a full reorder. | 626 // do a full reorder. |
| 649 ReorderActions(); | 627 ReorderActions(); |
| 650 } | 628 } |
| 651 | 629 |
| 652 void ToolbarActionsBar::OnToolbarExtensionUpdated( | 630 void ToolbarActionsBar::OnToolbarActionUpdated(const std::string& action_id) { |
| 653 const extensions::Extension* extension) { | 631 ToolbarActionViewController* action = GetActionForId(action_id); |
| 654 ToolbarActionViewController* action = GetActionForId(extension->id()); | |
| 655 // There might not be a view in cases where we are highlighting or if we | 632 // There might not be a view in cases where we are highlighting or if we |
| 656 // haven't fully initialized the actions. | 633 // haven't fully initialized the actions. |
| 657 if (action) { | 634 if (action) { |
| 658 action->UpdateState(); | 635 action->UpdateState(); |
| 659 SetOverflowedActionWantsToRun(); | 636 SetOverflowedActionWantsToRun(); |
| 660 } | 637 } |
| 661 } | 638 } |
| 662 | 639 |
| 663 bool ToolbarActionsBar::ShowExtensionActionPopup( | 640 bool ToolbarActionsBar::ShowToolbarActionPopup(const std::string& action_id, |
| 664 const extensions::Extension* extension, | 641 bool grant_active_tab) { |
| 665 bool grant_active_tab) { | |
| 666 // Don't override another popup, and only show in the active window. | 642 // Don't override another popup, and only show in the active window. |
| 667 if (popup_owner() || !browser_->window()->IsActive()) | 643 if (popup_owner() || !browser_->window()->IsActive()) |
| 668 return false; | 644 return false; |
| 669 | 645 |
| 670 ToolbarActionViewController* action = GetActionForId(extension->id()); | 646 ToolbarActionViewController* action = GetActionForId(action_id); |
| 671 return action && action->ExecuteAction(grant_active_tab); | 647 return action && action->ExecuteAction(grant_active_tab); |
| 672 } | 648 } |
| 673 | 649 |
| 674 void ToolbarActionsBar::OnToolbarVisibleCountChanged() { | 650 void ToolbarActionsBar::OnToolbarVisibleCountChanged() { |
| 675 ResizeDelegate(gfx::Tween::EASE_OUT, false); | 651 ResizeDelegate(gfx::Tween::EASE_OUT, false); |
| 676 SetOverflowedActionWantsToRun(); | 652 SetOverflowedActionWantsToRun(); |
| 677 } | 653 } |
| 678 | 654 |
| 679 void ToolbarActionsBar::ResizeDelegate(gfx::Tween::Type tween_type, | 655 void ToolbarActionsBar::ResizeDelegate(gfx::Tween::Type tween_type, |
| 680 bool suppress_chevron) { | 656 bool suppress_chevron) { |
| 681 int desired_width = GetPreferredSize().width(); | 657 int desired_width = GetPreferredSize().width(); |
| 682 if (desired_width != delegate_->GetWidth()) { | 658 if (desired_width != delegate_->GetWidth()) { |
| 683 delegate_->ResizeAndAnimate(tween_type, desired_width, suppress_chevron); | 659 delegate_->ResizeAndAnimate(tween_type, desired_width, suppress_chevron); |
| 684 } else if (delegate_->IsAnimating()) { | 660 } else if (delegate_->IsAnimating()) { |
| 685 // It's possible that we're right where we're supposed to be in terms of | 661 // It's possible that we're right where we're supposed to be in terms of |
| 686 // width, but that we're also currently resizing. If this is the case, end | 662 // width, but that we're also currently resizing. If this is the case, end |
| 687 // the current animation with the current width. | 663 // the current animation with the current width. |
| 688 delegate_->StopAnimating(); | 664 delegate_->StopAnimating(); |
| 689 } else { | 665 } else { |
| 690 // We may already be at the right size (this can happen frequently with | 666 // We may already be at the right size (this can happen frequently with |
| 691 // overflow, where we have a fixed width, and in tests, where we skip | 667 // overflow, where we have a fixed width, and in tests, where we skip |
| 692 // animations). If this is the case, we still need to Redraw(), because the | 668 // animations). If this is the case, we still need to Redraw(), because the |
| 693 // icons within the toolbar may have changed (e.g. if we removed one | 669 // icons within the toolbar may have changed (e.g. if we removed one |
| 694 // action and added a different one in quick succession). | 670 // action and added a different one in quick succession). |
| 695 delegate_->Redraw(false); | 671 delegate_->Redraw(false); |
| 696 } | 672 } |
| 697 } | 673 } |
| 698 | 674 |
| 699 void ToolbarActionsBar::OnToolbarHighlightModeChanged(bool is_highlighting) { | 675 void ToolbarActionsBar::OnToolbarHighlightModeChanged(bool is_highlighting) { |
| 700 if (!model_->extensions_initialized()) | 676 if (!model_->actions_initialized()) |
| 701 return; | 677 return; |
| 702 // It's a bit of a pain that we delete and recreate everything here, but given | 678 // It's a bit of a pain that we delete and recreate everything here, but given |
| 703 // everything else going on (the lack of highlight, [n] more extensions | 679 // everything else going on (the lack of highlight, [n] more extensions |
| 704 // appearing, etc), it's not worth the extra complexity to create and insert | 680 // appearing, etc), it's not worth the extra complexity to create and insert |
| 705 // only the new actions. | 681 // only the new actions. |
| 706 DeleteActions(); | 682 DeleteActions(); |
| 707 CreateActions(); | 683 CreateActions(); |
| 708 // Resize the delegate. We suppress the chevron so that we don't risk showing | 684 // Resize the delegate. We suppress the chevron so that we don't risk showing |
| 709 // it only for the duration of the animation. | 685 // it only for the duration of the animation. |
| 710 ResizeDelegate(gfx::Tween::LINEAR, true); | 686 ResizeDelegate(gfx::Tween::LINEAR, true); |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 726 Browser* ToolbarActionsBar::GetBrowser() { | 702 Browser* ToolbarActionsBar::GetBrowser() { |
| 727 return browser_; | 703 return browser_; |
| 728 } | 704 } |
| 729 | 705 |
| 730 void ToolbarActionsBar::ReorderActions() { | 706 void ToolbarActionsBar::ReorderActions() { |
| 731 if (toolbar_actions_.empty()) | 707 if (toolbar_actions_.empty()) |
| 732 return; | 708 return; |
| 733 | 709 |
| 734 // First, reset the order to that of the model. | 710 // First, reset the order to that of the model. |
| 735 auto compare = [](ToolbarActionViewController* const& action, | 711 auto compare = [](ToolbarActionViewController* const& action, |
| 736 const scoped_refptr<const extensions::Extension>& ext) { | 712 const std::string& id) { |
| 737 return action->GetId() == ext->id(); | 713 return action->GetId() == id; |
| 738 }; | 714 }; |
| 739 SortContainer(&toolbar_actions_.get(), model_->toolbar_items(), compare); | 715 SortContainer(&toolbar_actions_.get(), model_->toolbar_items(), compare); |
| 740 | 716 |
| 741 // Our visible browser actions may have changed - re-Layout() and check the | 717 // Our visible browser actions may have changed - re-Layout() and check the |
| 742 // size (if we aren't suppressing the layout). | 718 // size (if we aren't suppressing the layout). |
| 743 if (!suppress_layout_) { | 719 if (!suppress_layout_) { |
| 744 ResizeDelegate(gfx::Tween::EASE_OUT, false); | 720 ResizeDelegate(gfx::Tween::EASE_OUT, false); |
| 745 delegate_->Redraw(true); | 721 delegate_->Redraw(true); |
| 746 } | 722 } |
| 747 | 723 |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 762 | 738 |
| 763 if (overflowed_action_wants_to_run_ != overflowed_action_wants_to_run) { | 739 if (overflowed_action_wants_to_run_ != overflowed_action_wants_to_run) { |
| 764 overflowed_action_wants_to_run_ = overflowed_action_wants_to_run; | 740 overflowed_action_wants_to_run_ = overflowed_action_wants_to_run; |
| 765 if (send_overflowed_action_changes_) | 741 if (send_overflowed_action_changes_) |
| 766 delegate_->OnOverflowedActionWantsToRunChanged( | 742 delegate_->OnOverflowedActionWantsToRunChanged( |
| 767 overflowed_action_wants_to_run_); | 743 overflowed_action_wants_to_run_); |
| 768 } | 744 } |
| 769 } | 745 } |
| 770 | 746 |
| 771 ToolbarActionViewController* ToolbarActionsBar::GetActionForId( | 747 ToolbarActionViewController* ToolbarActionsBar::GetActionForId( |
| 772 const std::string& id) { | 748 const std::string& action_id) { |
| 773 for (ToolbarActionViewController* action : toolbar_actions_) { | 749 for (ToolbarActionViewController* action : toolbar_actions_) { |
| 774 if (action->GetId() == id) | 750 if (action->GetId() == action_id) |
| 775 return action; | 751 return action; |
| 776 } | 752 } |
| 777 return nullptr; | 753 return nullptr; |
| 778 } | 754 } |
| 779 | 755 |
| 780 content::WebContents* ToolbarActionsBar::GetCurrentWebContents() { | 756 content::WebContents* ToolbarActionsBar::GetCurrentWebContents() { |
| 781 return browser_->tab_strip_model()->GetActiveWebContents(); | 757 return browser_->tab_strip_model()->GetActiveWebContents(); |
| 782 } | 758 } |
| OLD | NEW |