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 "chrome/browser/ui/views/ash/launcher/chrome_launcher_delegate.h" | 5 #include "chrome/browser/ui/views/ash/launcher/chrome_launcher_delegate.h" |
6 | 6 |
7 #include "ash/launcher/launcher_model.h" | 7 #include "ash/launcher/launcher_model.h" |
8 #include "ash/launcher/launcher_types.h" | 8 #include "ash/launcher/launcher_types.h" |
9 #include "ash/wm/window_util.h" | 9 #include "ash/wm/window_util.h" |
10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
115 | 115 |
116 // static | 116 // static |
117 void ChromeLauncherDelegate::RegisterUserPrefs(PrefService* user_prefs) { | 117 void ChromeLauncherDelegate::RegisterUserPrefs(PrefService* user_prefs) { |
118 // TODO: If we want to support multiple profiles this will likely need to be | 118 // TODO: If we want to support multiple profiles this will likely need to be |
119 // pushed to local state and we'll need to track profile per item. | 119 // pushed to local state and we'll need to track profile per item. |
120 user_prefs->RegisterListPref(prefs::kPinnedLauncherApps, | 120 user_prefs->RegisterListPref(prefs::kPinnedLauncherApps, |
121 PrefService::SYNCABLE_PREF); | 121 PrefService::SYNCABLE_PREF); |
122 } | 122 } |
123 | 123 |
124 ash::LauncherID ChromeLauncherDelegate::CreateTabbedLauncherItem( | 124 ash::LauncherID ChromeLauncherDelegate::CreateTabbedLauncherItem( |
125 LauncherUpdater* updater) { | 125 LauncherUpdater* updater, |
126 IncognitoState is_incognito) { | |
126 // Tabbed items always get a new item. Put the tabbed item before the app | 127 // Tabbed items always get a new item. Put the tabbed item before the app |
127 // tabs. If there are no app tabs put it at the end. | 128 // tabs. If there are no app tabs put it at the end. |
128 int index = static_cast<int>(model_->items().size()); | 129 int index = static_cast<int>(model_->items().size()); |
129 for (IDToItemMap::const_iterator i = id_to_item_map_.begin(); | 130 for (IDToItemMap::const_iterator i = id_to_item_map_.begin(); |
130 i != id_to_item_map_.end(); ++i) { | 131 i != id_to_item_map_.end(); ++i) { |
131 if (i->second.updater == updater) { | 132 if (i->second.updater == updater) { |
132 DCHECK_EQ(TYPE_APP, i->second.item_type); | 133 DCHECK_EQ(TYPE_APP, i->second.item_type); |
133 index = std::min(index, model_->ItemIndexByID(i->first)); | 134 index = std::min(index, model_->ItemIndexByID(i->first)); |
134 } | 135 } |
135 } | 136 } |
136 ash::LauncherID id = model_->next_id(); | 137 ash::LauncherID id = model_->next_id(); |
137 ash::LauncherItem item(ash::TYPE_TABBED); | 138 ash::LauncherItem item; |
139 item.type = ash::TYPE_TABBED; | |
140 item.is_incognito = (is_incognito == STATE_INCOGNITO); | |
138 model_->Add(index, item); | 141 model_->Add(index, item); |
139 DCHECK(id_to_item_map_.find(id) == id_to_item_map_.end()); | 142 DCHECK(id_to_item_map_.find(id) == id_to_item_map_.end()); |
140 id_to_item_map_[id].item_type = TYPE_TABBED_BROWSER; | 143 id_to_item_map_[id].item_type = TYPE_TABBED_BROWSER; |
141 id_to_item_map_[id].updater = updater; | 144 id_to_item_map_[id].updater = updater; |
142 return id; | 145 return id; |
143 } | 146 } |
144 | 147 |
145 ash::LauncherID ChromeLauncherDelegate::CreateAppLauncherItem( | 148 ash::LauncherID ChromeLauncherDelegate::CreateAppLauncherItem( |
146 LauncherUpdater* updater, | 149 LauncherUpdater* updater, |
147 const std::string& app_id, | 150 const std::string& app_id, |
(...skipping 25 matching lines...) Expand all Loading... | |
173 } else { | 176 } else { |
174 min_tab_index = | 177 min_tab_index = |
175 std::min(min_app_index, model_->ItemIndexByID(i->first)); | 178 std::min(min_app_index, model_->ItemIndexByID(i->first)); |
176 } | 179 } |
177 } | 180 } |
178 } | 181 } |
179 } | 182 } |
180 int insert_index = min_app_index != item_count ? | 183 int insert_index = min_app_index != item_count ? |
181 min_app_index : std::min(item_count, min_tab_index + 1); | 184 min_app_index : std::min(item_count, min_tab_index + 1); |
182 ash::LauncherID id = model_->next_id(); | 185 ash::LauncherID id = model_->next_id(); |
183 ash::LauncherItem item(ash::TYPE_APP); | 186 ash::LauncherItem item; |
187 item.type = ash::TYPE_APP; | |
188 item.is_incognito = false; | |
184 item.image = Extension::GetDefaultIcon(true); | 189 item.image = Extension::GetDefaultIcon(true); |
185 model_->Add(insert_index, item); | 190 model_->Add(insert_index, item); |
186 DCHECK(id_to_item_map_.find(id) == id_to_item_map_.end()); | 191 DCHECK(id_to_item_map_.find(id) == id_to_item_map_.end()); |
187 id_to_item_map_[id].item_type = TYPE_APP; | 192 id_to_item_map_[id].item_type = TYPE_APP; |
188 id_to_item_map_[id].app_type = app_type; | 193 id_to_item_map_[id].app_type = app_type; |
189 id_to_item_map_[id].app_id = app_id; | 194 id_to_item_map_[id].app_id = app_id; |
190 id_to_item_map_[id].updater = updater; | 195 id_to_item_map_[id].updater = updater; |
191 id_to_item_map_[id].pinned = updater == NULL; | 196 id_to_item_map_[id].pinned = updater == NULL; |
192 | 197 |
193 if (app_type != APP_TYPE_PANEL) | 198 if (app_type != APP_TYPE_PANEL) |
194 app_icon_loader_->FetchImage(app_id); | 199 app_icon_loader_->FetchImage(app_id); |
195 return id; | 200 return id; |
196 } | 201 } |
197 | 202 |
198 void ChromeLauncherDelegate::ConvertAppToTabbed(ash::LauncherID id) { | 203 void ChromeLauncherDelegate::ConvertAppToTabbed(ash::LauncherID id) { |
sky
2012/03/10 00:13:11
Does this need to take incognito too?
Zachary Kuznia
2012/03/10 00:28:36
I don't think so. The LauncherItem is updated by
| |
199 DCHECK(id_to_item_map_.find(id) != id_to_item_map_.end()); | 204 DCHECK(id_to_item_map_.find(id) != id_to_item_map_.end()); |
200 DCHECK_EQ(TYPE_APP, id_to_item_map_[id].item_type); | 205 DCHECK_EQ(TYPE_APP, id_to_item_map_[id].item_type); |
201 DCHECK(!id_to_item_map_[id].pinned); | 206 DCHECK(!id_to_item_map_[id].pinned); |
202 id_to_item_map_[id].item_type = TYPE_TABBED_BROWSER; | 207 id_to_item_map_[id].item_type = TYPE_TABBED_BROWSER; |
203 id_to_item_map_[id].app_id.clear(); | 208 id_to_item_map_[id].app_id.clear(); |
204 } | 209 } |
205 | 210 |
206 void ChromeLauncherDelegate::ConvertTabbedToApp(ash::LauncherID id, | 211 void ChromeLauncherDelegate::ConvertTabbedToApp(ash::LauncherID id, |
207 const std::string& app_id, | 212 const std::string& app_id, |
208 AppType app_type) { | 213 AppType app_type) { |
209 DCHECK(id_to_item_map_.find(id) != id_to_item_map_.end()); | 214 DCHECK(id_to_item_map_.find(id) != id_to_item_map_.end()); |
210 DCHECK_EQ(TYPE_TABBED_BROWSER, id_to_item_map_[id].item_type); | 215 DCHECK_EQ(TYPE_TABBED_BROWSER, id_to_item_map_[id].item_type); |
211 DCHECK(!id_to_item_map_[id].pinned); | 216 DCHECK(!id_to_item_map_[id].pinned); |
212 id_to_item_map_[id].item_type = TYPE_APP; | 217 id_to_item_map_[id].item_type = TYPE_APP; |
213 id_to_item_map_[id].app_type = app_type; | 218 id_to_item_map_[id].app_type = app_type; |
214 id_to_item_map_[id].app_id = app_id; | 219 id_to_item_map_[id].app_id = app_id; |
215 | 220 |
216 ash::LauncherItem item(ash::TYPE_APP); | 221 ash::LauncherItem item; |
222 item.type = ash::TYPE_APP; | |
223 item.is_incognito = false; | |
217 item.id = id; | 224 item.id = id; |
218 model_->Set(model_->ItemIndexByID(id), item); | 225 model_->Set(model_->ItemIndexByID(id), item); |
219 | 226 |
220 app_icon_loader_->FetchImage(app_id); | 227 app_icon_loader_->FetchImage(app_id); |
221 } | 228 } |
222 | 229 |
223 void ChromeLauncherDelegate::LauncherItemClosed(ash::LauncherID id) { | 230 void ChromeLauncherDelegate::LauncherItemClosed(ash::LauncherID id) { |
224 DCHECK(id_to_item_map_.find(id) != id_to_item_map_.end()); | 231 DCHECK(id_to_item_map_.find(id) != id_to_item_map_.end()); |
225 if (id_to_item_map_[id].pinned) { | 232 if (id_to_item_map_[id].pinned) { |
226 // The item is pinned, leave it in the launcher. | 233 // The item is pinned, leave it in the launcher. |
(...skipping 262 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
489 Profile* ChromeLauncherDelegate::GetProfileForNewWindows() { | 496 Profile* ChromeLauncherDelegate::GetProfileForNewWindows() { |
490 Profile* profile = ProfileManager::GetDefaultProfile(); | 497 Profile* profile = ProfileManager::GetDefaultProfile(); |
491 if (browser_defaults::kAlwaysOpenIncognitoWindow && | 498 if (browser_defaults::kAlwaysOpenIncognitoWindow && |
492 IncognitoModePrefs::ShouldLaunchIncognito( | 499 IncognitoModePrefs::ShouldLaunchIncognito( |
493 *CommandLine::ForCurrentProcess(), | 500 *CommandLine::ForCurrentProcess(), |
494 profile->GetPrefs())) { | 501 profile->GetPrefs())) { |
495 profile = profile->GetOffTheRecordProfile(); | 502 profile = profile->GetOffTheRecordProfile(); |
496 } | 503 } |
497 return profile; | 504 return profile; |
498 } | 505 } |
OLD | NEW |