OLD | NEW |
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 "ash/shell.h" | 5 #include "ash/shell.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "ash/app_list/app_list.h" | 9 #include "ash/app_list/app_list.h" |
10 #include "ash/ash_switches.h" | 10 #include "ash/ash_switches.h" |
(...skipping 463 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
474 std::string* toup_url) OVERRIDE { | 474 std::string* toup_url) OVERRIDE { |
475 return false; | 475 return false; |
476 } | 476 } |
477 | 477 |
478 virtual void ShowCellularTopupURL(const std::string& topup_url) OVERRIDE { | 478 virtual void ShowCellularTopupURL(const std::string& topup_url) OVERRIDE { |
479 } | 479 } |
480 | 480 |
481 virtual void ChangeProxySettings() OVERRIDE { | 481 virtual void ChangeProxySettings() OVERRIDE { |
482 } | 482 } |
483 | 483 |
| 484 virtual void OnTrayDestroyed() OVERRIDE { |
| 485 } |
| 486 |
484 bool muted_; | 487 bool muted_; |
485 bool wifi_enabled_; | 488 bool wifi_enabled_; |
486 bool cellular_enabled_; | 489 bool cellular_enabled_; |
487 bool bluetooth_enabled_; | 490 bool bluetooth_enabled_; |
488 float volume_; | 491 float volume_; |
489 SkBitmap null_image_; | 492 SkBitmap null_image_; |
490 | 493 |
491 DISALLOW_COPY_AND_ASSIGN(DummySystemTrayDelegate); | 494 DISALLOW_COPY_AND_ASSIGN(DummySystemTrayDelegate); |
492 }; | 495 }; |
493 | 496 |
(...skipping 29 matching lines...) Expand all Loading... |
523 //////////////////////////////////////////////////////////////////////////////// | 526 //////////////////////////////////////////////////////////////////////////////// |
524 // Shell, public: | 527 // Shell, public: |
525 | 528 |
526 Shell::Shell(ShellDelegate* delegate) | 529 Shell::Shell(ShellDelegate* delegate) |
527 : root_window_(aura::MonitorManager::CreateRootWindowForPrimaryMonitor()), | 530 : root_window_(aura::MonitorManager::CreateRootWindowForPrimaryMonitor()), |
528 screen_(new ScreenAsh(root_window_.get())), | 531 screen_(new ScreenAsh(root_window_.get())), |
529 root_filter_(NULL), | 532 root_filter_(NULL), |
530 delegate_(delegate), | 533 delegate_(delegate), |
531 shelf_(NULL), | 534 shelf_(NULL), |
532 root_window_layout_(NULL), | 535 root_window_layout_(NULL), |
533 status_widget_(NULL) { | 536 status_widget_(NULL), |
| 537 shutdown_(false) { |
534 gfx::Screen::SetInstance(screen_); | 538 gfx::Screen::SetInstance(screen_); |
535 ui_controls::InstallUIControlsAura(CreateUIControlsAura(root_window_.get())); | 539 ui_controls::InstallUIControlsAura(CreateUIControlsAura(root_window_.get())); |
536 } | 540 } |
537 | 541 |
538 Shell::~Shell() { | 542 Shell::~Shell() { |
539 RemoveRootWindowEventFilter(key_rewriter_filter_.get()); | 543 if (!shutdown_) |
540 RemoveRootWindowEventFilter(partial_screenshot_filter_.get()); | 544 Shutdown(); |
541 RemoveRootWindowEventFilter(input_method_filter_.get()); | |
542 RemoveRootWindowEventFilter(window_modality_controller_.get()); | |
543 RemoveRootWindowEventFilter(system_gesture_filter_.get()); | |
544 #if !defined(OS_MACOSX) | |
545 RemoveRootWindowEventFilter(accelerator_filter_.get()); | |
546 #endif | |
547 | |
548 // Close background widget now so that the focus manager of the | |
549 // widget gets deleted in the final message loop run. | |
550 root_window_layout_->SetBackgroundWidget(NULL); | |
551 | |
552 // TooltipController is deleted with the Shell so removing its references. | |
553 RemoveRootWindowEventFilter(tooltip_controller_.get()); | |
554 aura::client::SetTooltipClient(GetRootWindow(), NULL); | |
555 | |
556 // Make sure we delete WorkspaceController before launcher is | |
557 // deleted as it has a reference to launcher model. | |
558 workspace_controller_.reset(); | |
559 | |
560 // The system tray needs to be reset before all the windows are destroyed. | |
561 tray_.reset(); | |
562 | |
563 // Desroy secondary monitor's widgets before all the windows are destroyed. | |
564 monitor_controller_.reset(); | |
565 | |
566 // Delete containers now so that child windows does not access | |
567 // observers when they are destructed. | |
568 aura::RootWindow* root_window = GetRootWindow(); | |
569 while (!root_window->children().empty()) { | |
570 aura::Window* child = root_window->children()[0]; | |
571 delete child; | |
572 } | |
573 | |
574 // These need a valid Shell instance to clean up properly, so explicitly | |
575 // delete them before invalidating the instance. | |
576 // Alphabetical. | |
577 activation_controller_.reset(); | |
578 drag_drop_controller_.reset(); | |
579 resize_shadow_controller_.reset(); | |
580 shadow_controller_.reset(); | |
581 window_cycle_controller_.reset(); | |
582 event_client_.reset(); | |
583 monitor_controller_.reset(); | |
584 | |
585 // Launcher widget has a InputMethodBridge that references to | |
586 // input_method_filter_'s input_method_. So explicitly release launcher_ | |
587 // before input_method_filter_. And this needs to be after we delete all | |
588 // containers in case there are still live browser windows which access | |
589 // LauncherModel during close. | |
590 launcher_.reset(); | |
591 | |
592 DCHECK(instance_ == this); | 545 DCHECK(instance_ == this); |
593 instance_ = NULL; | 546 instance_ = NULL; |
594 } | 547 } |
595 | 548 |
596 // static | 549 // static |
597 Shell* Shell::CreateInstance(ShellDelegate* delegate) { | 550 Shell* Shell::CreateInstance(ShellDelegate* delegate) { |
598 CHECK(!instance_); | 551 CHECK(!instance_); |
599 aura::Env::GetInstance()->SetMonitorManager( | 552 aura::Env::GetInstance()->SetMonitorManager( |
600 new internal::MultiMonitorManager()); | 553 new internal::MultiMonitorManager()); |
601 instance_ = new Shell(delegate); | 554 instance_ = new Shell(delegate); |
(...skipping 17 matching lines...) Expand all Loading... |
619 delete instance_; | 572 delete instance_; |
620 instance_ = NULL; | 573 instance_ = NULL; |
621 } | 574 } |
622 | 575 |
623 // static | 576 // static |
624 aura::RootWindow* Shell::GetRootWindow() { | 577 aura::RootWindow* Shell::GetRootWindow() { |
625 return GetInstance()->root_window_.get(); | 578 return GetInstance()->root_window_.get(); |
626 } | 579 } |
627 | 580 |
628 void Shell::Init() { | 581 void Shell::Init() { |
| 582 DCHECK(!shutdown_); |
629 aura::RootWindow* root_window = GetRootWindow(); | 583 aura::RootWindow* root_window = GetRootWindow(); |
630 root_filter_ = new internal::RootWindowEventFilter(root_window); | 584 root_filter_ = new internal::RootWindowEventFilter(root_window); |
631 #if !defined(OS_MACOSX) | 585 #if !defined(OS_MACOSX) |
632 nested_dispatcher_controller_.reset(new NestedDispatcherController); | 586 nested_dispatcher_controller_.reset(new NestedDispatcherController); |
633 accelerator_controller_.reset(new AcceleratorController); | 587 accelerator_controller_.reset(new AcceleratorController); |
634 #endif | 588 #endif |
635 // Pass ownership of the filter to the root window. | 589 // Pass ownership of the filter to the root window. |
636 GetRootWindow()->SetEventFilter(root_filter_); | 590 GetRootWindow()->SetEventFilter(root_filter_); |
637 | 591 |
638 // KeyRewriterEventFilter must be the first one. | 592 // KeyRewriterEventFilter must be the first one. |
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
779 | 733 |
780 aura::Window* Shell::GetContainer(int container_id) { | 734 aura::Window* Shell::GetContainer(int container_id) { |
781 return const_cast<aura::Window*>( | 735 return const_cast<aura::Window*>( |
782 const_cast<const Shell*>(this)->GetContainer(container_id)); | 736 const_cast<const Shell*>(this)->GetContainer(container_id)); |
783 } | 737 } |
784 | 738 |
785 const aura::Window* Shell::GetContainer(int container_id) const { | 739 const aura::Window* Shell::GetContainer(int container_id) const { |
786 return GetRootWindow()->GetChildById(container_id); | 740 return GetRootWindow()->GetChildById(container_id); |
787 } | 741 } |
788 | 742 |
| 743 void Shell::Shutdown() { |
| 744 DCHECK(!shutdown_); |
| 745 shutdown_ = true; |
| 746 |
| 747 RemoveRootWindowEventFilter(key_rewriter_filter_.get()); |
| 748 RemoveRootWindowEventFilter(partial_screenshot_filter_.get()); |
| 749 RemoveRootWindowEventFilter(input_method_filter_.get()); |
| 750 RemoveRootWindowEventFilter(window_modality_controller_.get()); |
| 751 RemoveRootWindowEventFilter(system_gesture_filter_.get()); |
| 752 #if !defined(OS_MACOSX) |
| 753 RemoveRootWindowEventFilter(accelerator_filter_.get()); |
| 754 #endif |
| 755 |
| 756 // Close background widget now so that the focus manager of the |
| 757 // widget gets deleted in the final message loop run. |
| 758 root_window_layout_->SetBackgroundWidget(NULL); |
| 759 |
| 760 // TooltipController is deleted with the Shell so removing its references. |
| 761 RemoveRootWindowEventFilter(tooltip_controller_.get()); |
| 762 aura::client::SetTooltipClient(GetRootWindow(), NULL); |
| 763 |
| 764 // Make sure we delete WorkspaceController before launcher is |
| 765 // deleted as it has a reference to launcher model. |
| 766 workspace_controller_.reset(); |
| 767 |
| 768 // The system tray needs to be reset before all the windows are destroyed. |
| 769 tray_.reset(); |
| 770 tray_delegate_->OnTrayDestroyed(); |
| 771 |
| 772 // Desroy secondary monitor's widgets before all the windows are destroyed. |
| 773 monitor_controller_.reset(); |
| 774 |
| 775 // Delete containers now so that child windows does not access |
| 776 // observers when they are destructed. |
| 777 aura::RootWindow* root_window = GetRootWindow(); |
| 778 while (!root_window->children().empty()) { |
| 779 aura::Window* child = root_window->children()[0]; |
| 780 delete child; |
| 781 } |
| 782 |
| 783 // These need a valid Shell instance to clean up properly, so explicitly |
| 784 // delete them before invalidating the instance. |
| 785 // Alphabetical. |
| 786 activation_controller_.reset(); |
| 787 drag_drop_controller_.reset(); |
| 788 resize_shadow_controller_.reset(); |
| 789 shadow_controller_.reset(); |
| 790 window_cycle_controller_.reset(); |
| 791 event_client_.reset(); |
| 792 monitor_controller_.reset(); |
| 793 tooltip_controller_.reset(); |
| 794 |
| 795 // Launcher widget has a InputMethodBridge that references to |
| 796 // input_method_filter_'s input_method_. So explicitly release launcher_ |
| 797 // before input_method_filter_. And this needs to be after we delete all |
| 798 // containers in case there are still live browser windows which access |
| 799 // LauncherModel during close. |
| 800 launcher_.reset(); |
| 801 } |
| 802 |
789 void Shell::AddRootWindowEventFilter(aura::EventFilter* filter) { | 803 void Shell::AddRootWindowEventFilter(aura::EventFilter* filter) { |
790 static_cast<internal::RootWindowEventFilter*>( | 804 static_cast<internal::RootWindowEventFilter*>( |
791 GetRootWindow()->event_filter())->AddFilter(filter); | 805 GetRootWindow()->event_filter())->AddFilter(filter); |
792 } | 806 } |
793 | 807 |
794 void Shell::RemoveRootWindowEventFilter(aura::EventFilter* filter) { | 808 void Shell::RemoveRootWindowEventFilter(aura::EventFilter* filter) { |
795 static_cast<internal::RootWindowEventFilter*>( | 809 static_cast<internal::RootWindowEventFilter*>( |
796 GetRootWindow()->event_filter())->RemoveFilter(filter); | 810 GetRootWindow()->event_filter())->RemoveFilter(filter); |
797 } | 811 } |
798 | 812 |
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
938 desktop_background_controller_->SetDesktopBackgroundImageMode( | 952 desktop_background_controller_->SetDesktopBackgroundImageMode( |
939 GetWallpaper(index), GetWallpaperInfo(index).layout); | 953 GetWallpaper(index), GetWallpaperInfo(index).layout); |
940 } | 954 } |
941 | 955 |
942 void Shell::DisableWorkspaceGridLayout() { | 956 void Shell::DisableWorkspaceGridLayout() { |
943 if (workspace_controller_.get()) | 957 if (workspace_controller_.get()) |
944 workspace_controller_->workspace_manager()->set_grid_size(0); | 958 workspace_controller_->workspace_manager()->set_grid_size(0); |
945 } | 959 } |
946 | 960 |
947 } // namespace ash | 961 } // namespace ash |
OLD | NEW |