OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/ash/launcher/chrome_launcher_controller.h" | 5 #include "chrome/browser/ui/ash/launcher/chrome_launcher_controller.h" |
6 | 6 |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
9 #include "ash/ash_switches.h" | 9 #include "ash/ash_switches.h" |
10 #include "ash/desktop_background/desktop_background_controller.h" | 10 #include "ash/desktop_background/desktop_background_controller.h" |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
95 // static | 95 // static |
96 ChromeLauncherController* ChromeLauncherController::instance_ = NULL; | 96 ChromeLauncherController* ChromeLauncherController::instance_ = NULL; |
97 | 97 |
98 namespace { | 98 namespace { |
99 | 99 |
100 // This will be used as placeholder in the list of the pinned applciatons. | 100 // This will be used as placeholder in the list of the pinned applciatons. |
101 // Note that this is NOT a valid extension identifier so that pre M31 versions | 101 // Note that this is NOT a valid extension identifier so that pre M31 versions |
102 // will ignore it. | 102 // will ignore it. |
103 const char kAppLauncherIdPlaceholder[] = "AppLauncherIDPlaceholder--------"; | 103 const char kAppLauncherIdPlaceholder[] = "AppLauncherIDPlaceholder--------"; |
104 | 104 |
105 std::string GetPrefKeyForRootWindow(aura::RootWindow* root_window) { | 105 std::string GetPrefKeyForRootWindow(aura::Window* root_window) { |
106 gfx::Display display = gfx::Screen::GetScreenFor( | 106 gfx::Display display = gfx::Screen::GetScreenFor( |
107 root_window)->GetDisplayNearestWindow(root_window); | 107 root_window)->GetDisplayNearestWindow(root_window); |
108 DCHECK(display.is_valid()); | 108 DCHECK(display.is_valid()); |
109 | 109 |
110 return base::Int64ToString(display.id()); | 110 return base::Int64ToString(display.id()); |
111 } | 111 } |
112 | 112 |
113 void UpdatePerDisplayPref(PrefService* pref_service, | 113 void UpdatePerDisplayPref(PrefService* pref_service, |
114 aura::RootWindow* root_window, | 114 aura::Window* root_window, |
115 const char* pref_key, | 115 const char* pref_key, |
116 const std::string& value) { | 116 const std::string& value) { |
117 std::string key = GetPrefKeyForRootWindow(root_window); | 117 std::string key = GetPrefKeyForRootWindow(root_window); |
118 if (key.empty()) | 118 if (key.empty()) |
119 return; | 119 return; |
120 | 120 |
121 DictionaryPrefUpdate update(pref_service, prefs::kShelfPreferences); | 121 DictionaryPrefUpdate update(pref_service, prefs::kShelfPreferences); |
122 base::DictionaryValue* shelf_prefs = update.Get(); | 122 base::DictionaryValue* shelf_prefs = update.Get(); |
123 base::DictionaryValue* prefs = NULL; | 123 base::DictionaryValue* prefs = NULL; |
124 if (!shelf_prefs->GetDictionary(key, &prefs)) { | 124 if (!shelf_prefs->GetDictionary(key, &prefs)) { |
(...skipping 12 matching lines...) Expand all Loading... |
137 // * A user-set value for the specified display. | 137 // * A user-set value for the specified display. |
138 // * A user-set value in |local_path| or |path|, if no per-display settings are | 138 // * A user-set value in |local_path| or |path|, if no per-display settings are |
139 // ever specified (see http://crbug.com/173719 for why). |local_path| is | 139 // ever specified (see http://crbug.com/173719 for why). |local_path| is |
140 // preferred. See comment in |kShelfAlignment| as to why we consider two | 140 // preferred. See comment in |kShelfAlignment| as to why we consider two |
141 // prefs and why |local_path| is preferred. | 141 // prefs and why |local_path| is preferred. |
142 // * A value recommended by policy. This is a single value that applies to all | 142 // * A value recommended by policy. This is a single value that applies to all |
143 // root windows. | 143 // root windows. |
144 // * The default value for |local_path| if the value is not recommended by | 144 // * The default value for |local_path| if the value is not recommended by |
145 // policy. | 145 // policy. |
146 std::string GetPrefForRootWindow(PrefService* pref_service, | 146 std::string GetPrefForRootWindow(PrefService* pref_service, |
147 aura::RootWindow* root_window, | 147 aura::Window* root_window, |
148 const char* local_path, | 148 const char* local_path, |
149 const char* path) { | 149 const char* path) { |
150 const PrefService::Preference* local_pref = | 150 const PrefService::Preference* local_pref = |
151 pref_service->FindPreference(local_path); | 151 pref_service->FindPreference(local_path); |
152 const std::string value(pref_service->GetString(local_path)); | 152 const std::string value(pref_service->GetString(local_path)); |
153 if (local_pref->IsManaged()) | 153 if (local_pref->IsManaged()) |
154 return value; | 154 return value; |
155 | 155 |
156 std::string pref_key = GetPrefKeyForRootWindow(root_window); | 156 std::string pref_key = GetPrefKeyForRootWindow(root_window); |
157 bool has_per_display_prefs = false; | 157 bool has_per_display_prefs = false; |
(...skipping 506 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
664 if (index == -1) | 664 if (index == -1) |
665 continue; | 665 continue; |
666 ash::LauncherItem item = model_->items()[index]; | 666 ash::LauncherItem item = model_->items()[index]; |
667 item.image = image; | 667 item.image = image; |
668 model_->Set(index, item); | 668 model_->Set(index, item); |
669 // It's possible we're waiting on more than one item, so don't break. | 669 // It's possible we're waiting on more than one item, so don't break. |
670 } | 670 } |
671 } | 671 } |
672 | 672 |
673 void ChromeLauncherController::OnAutoHideBehaviorChanged( | 673 void ChromeLauncherController::OnAutoHideBehaviorChanged( |
674 aura::RootWindow* root_window, | 674 aura::Window* root_window, |
675 ash::ShelfAutoHideBehavior new_behavior) { | 675 ash::ShelfAutoHideBehavior new_behavior) { |
676 SetShelfAutoHideBehaviorPrefs(new_behavior, root_window); | 676 SetShelfAutoHideBehaviorPrefs(new_behavior, root_window); |
677 } | 677 } |
678 | 678 |
679 void ChromeLauncherController::SetLauncherItemImage( | 679 void ChromeLauncherController::SetLauncherItemImage( |
680 ash::LauncherID launcher_id, | 680 ash::LauncherID launcher_id, |
681 const gfx::ImageSkia& image) { | 681 const gfx::ImageSkia& image) { |
682 int index = model_->ItemIndexByID(launcher_id); | 682 int index = model_->ItemIndexByID(launcher_id); |
683 if (index == -1) | 683 if (index == -1) |
684 return; | 684 return; |
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
795 | 795 |
796 ash::LauncherModel* ChromeLauncherController::model() { | 796 ash::LauncherModel* ChromeLauncherController::model() { |
797 return model_; | 797 return model_; |
798 } | 798 } |
799 | 799 |
800 Profile* ChromeLauncherController::profile() { | 800 Profile* ChromeLauncherController::profile() { |
801 return profile_; | 801 return profile_; |
802 } | 802 } |
803 | 803 |
804 ash::ShelfAutoHideBehavior ChromeLauncherController::GetShelfAutoHideBehavior( | 804 ash::ShelfAutoHideBehavior ChromeLauncherController::GetShelfAutoHideBehavior( |
805 aura::RootWindow* root_window) const { | 805 aura::Window* root_window) const { |
806 // Don't show the shelf in app mode. | 806 // Don't show the shelf in app mode. |
807 if (chrome::IsRunningInAppMode()) | 807 if (chrome::IsRunningInAppMode()) |
808 return ash::SHELF_AUTO_HIDE_ALWAYS_HIDDEN; | 808 return ash::SHELF_AUTO_HIDE_ALWAYS_HIDDEN; |
809 | 809 |
810 // See comment in |kShelfAlignment| as to why we consider two prefs. | 810 // See comment in |kShelfAlignment| as to why we consider two prefs. |
811 const std::string behavior_value( | 811 const std::string behavior_value( |
812 GetPrefForRootWindow(profile_->GetPrefs(), | 812 GetPrefForRootWindow(profile_->GetPrefs(), |
813 root_window, | 813 root_window, |
814 prefs::kShelfAutoHideBehaviorLocal, | 814 prefs::kShelfAutoHideBehaviorLocal, |
815 prefs::kShelfAutoHideBehavior)); | 815 prefs::kShelfAutoHideBehavior)); |
816 | 816 |
817 // Note: To maintain sync compatibility with old images of chrome/chromeos | 817 // Note: To maintain sync compatibility with old images of chrome/chromeos |
818 // the set of values that may be encountered includes the now-extinct | 818 // the set of values that may be encountered includes the now-extinct |
819 // "Default" as well as "Never" and "Always", "Default" should now | 819 // "Default" as well as "Never" and "Always", "Default" should now |
820 // be treated as "Never" (http://crbug.com/146773). | 820 // be treated as "Never" (http://crbug.com/146773). |
821 if (behavior_value == ash::kShelfAutoHideBehaviorAlways) | 821 if (behavior_value == ash::kShelfAutoHideBehaviorAlways) |
822 return ash::SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS; | 822 return ash::SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS; |
823 return ash::SHELF_AUTO_HIDE_BEHAVIOR_NEVER; | 823 return ash::SHELF_AUTO_HIDE_BEHAVIOR_NEVER; |
824 } | 824 } |
825 | 825 |
826 bool ChromeLauncherController::CanUserModifyShelfAutoHideBehavior( | 826 bool ChromeLauncherController::CanUserModifyShelfAutoHideBehavior( |
827 aura::RootWindow* root_window) const { | 827 aura::Window* root_window) const { |
828 return profile_->GetPrefs()-> | 828 return profile_->GetPrefs()-> |
829 FindPreference(prefs::kShelfAutoHideBehaviorLocal)->IsUserModifiable(); | 829 FindPreference(prefs::kShelfAutoHideBehaviorLocal)->IsUserModifiable(); |
830 } | 830 } |
831 | 831 |
832 void ChromeLauncherController::ToggleShelfAutoHideBehavior( | 832 void ChromeLauncherController::ToggleShelfAutoHideBehavior( |
833 aura::RootWindow* root_window) { | 833 aura::Window* root_window) { |
834 ash::ShelfAutoHideBehavior behavior = GetShelfAutoHideBehavior(root_window) == | 834 ash::ShelfAutoHideBehavior behavior = GetShelfAutoHideBehavior(root_window) == |
835 ash::SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS ? | 835 ash::SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS ? |
836 ash::SHELF_AUTO_HIDE_BEHAVIOR_NEVER : | 836 ash::SHELF_AUTO_HIDE_BEHAVIOR_NEVER : |
837 ash::SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS; | 837 ash::SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS; |
838 SetShelfAutoHideBehaviorPrefs(behavior, root_window); | 838 SetShelfAutoHideBehaviorPrefs(behavior, root_window); |
839 return; | 839 return; |
840 } | 840 } |
841 | 841 |
842 void ChromeLauncherController::RemoveTabFromRunningApp( | 842 void ChromeLauncherController::RemoveTabFromRunningApp( |
843 WebContents* tab, | 843 WebContents* tab, |
(...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1076 } | 1076 } |
1077 } | 1077 } |
1078 break; | 1078 break; |
1079 } | 1079 } |
1080 default: | 1080 default: |
1081 NOTREACHED() << "Unexpected notification type=" << type; | 1081 NOTREACHED() << "Unexpected notification type=" << type; |
1082 } | 1082 } |
1083 } | 1083 } |
1084 | 1084 |
1085 void ChromeLauncherController::OnShelfAlignmentChanged( | 1085 void ChromeLauncherController::OnShelfAlignmentChanged( |
1086 aura::RootWindow* root_window) { | 1086 aura::Window* root_window) { |
1087 const char* pref_value = NULL; | 1087 const char* pref_value = NULL; |
1088 switch (ash::Shell::GetInstance()->GetShelfAlignment(root_window)) { | 1088 switch (ash::Shell::GetInstance()->GetShelfAlignment(root_window)) { |
1089 case ash::SHELF_ALIGNMENT_BOTTOM: | 1089 case ash::SHELF_ALIGNMENT_BOTTOM: |
1090 pref_value = ash::kShelfAlignmentBottom; | 1090 pref_value = ash::kShelfAlignmentBottom; |
1091 break; | 1091 break; |
1092 case ash::SHELF_ALIGNMENT_LEFT: | 1092 case ash::SHELF_ALIGNMENT_LEFT: |
1093 pref_value = ash::kShelfAlignmentLeft; | 1093 pref_value = ash::kShelfAlignmentLeft; |
1094 break; | 1094 break; |
1095 case ash::SHELF_ALIGNMENT_RIGHT: | 1095 case ash::SHELF_ALIGNMENT_RIGHT: |
1096 pref_value = ash::kShelfAlignmentRight; | 1096 pref_value = ash::kShelfAlignmentRight; |
(...skipping 399 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1496 } else { | 1496 } else { |
1497 int target_index = FindInsertionPoint(is_app_list); | 1497 int target_index = FindInsertionPoint(is_app_list); |
1498 MoveChromeOrApplistToFinalPosition( | 1498 MoveChromeOrApplistToFinalPosition( |
1499 is_chrome, is_app_list, target_index, &chrome_index, &app_list_index); | 1499 is_chrome, is_app_list, target_index, &chrome_index, &app_list_index); |
1500 } | 1500 } |
1501 } | 1501 } |
1502 } | 1502 } |
1503 | 1503 |
1504 void ChromeLauncherController::SetShelfAutoHideBehaviorPrefs( | 1504 void ChromeLauncherController::SetShelfAutoHideBehaviorPrefs( |
1505 ash::ShelfAutoHideBehavior behavior, | 1505 ash::ShelfAutoHideBehavior behavior, |
1506 aura::RootWindow* root_window) { | 1506 aura::Window* root_window) { |
1507 const char* value = NULL; | 1507 const char* value = NULL; |
1508 switch (behavior) { | 1508 switch (behavior) { |
1509 case ash::SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS: | 1509 case ash::SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS: |
1510 value = ash::kShelfAutoHideBehaviorAlways; | 1510 value = ash::kShelfAutoHideBehaviorAlways; |
1511 break; | 1511 break; |
1512 case ash::SHELF_AUTO_HIDE_BEHAVIOR_NEVER: | 1512 case ash::SHELF_AUTO_HIDE_BEHAVIOR_NEVER: |
1513 value = ash::kShelfAutoHideBehaviorNever; | 1513 value = ash::kShelfAutoHideBehaviorNever; |
1514 break; | 1514 break; |
1515 case ash::SHELF_AUTO_HIDE_ALWAYS_HIDDEN: | 1515 case ash::SHELF_AUTO_HIDE_ALWAYS_HIDDEN: |
1516 // This one should not be a valid preference option for now. We only want | 1516 // This one should not be a valid preference option for now. We only want |
(...skipping 363 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1880 } | 1880 } |
1881 | 1881 |
1882 void ChromeLauncherController::ReleaseProfile() { | 1882 void ChromeLauncherController::ReleaseProfile() { |
1883 if (app_sync_ui_state_) | 1883 if (app_sync_ui_state_) |
1884 app_sync_ui_state_->RemoveObserver(this); | 1884 app_sync_ui_state_->RemoveObserver(this); |
1885 | 1885 |
1886 PrefServiceSyncable::FromProfile(profile_)->RemoveObserver(this); | 1886 PrefServiceSyncable::FromProfile(profile_)->RemoveObserver(this); |
1887 | 1887 |
1888 pref_change_registrar_.RemoveAll(); | 1888 pref_change_registrar_.RemoveAll(); |
1889 } | 1889 } |
OLD | NEW |