OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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/browser_shortcut_launcher_item_controll
er.h" | 5 #include "chrome/browser/ui/ash/launcher/browser_shortcut_launcher_item_controll
er.h" |
6 | 6 |
7 #include <limits> | 7 #include <limits> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
| 10 #include "ash/public/cpp/window_properties.h" |
10 #include "ash/resources/grit/ash_resources.h" | 11 #include "ash/resources/grit/ash_resources.h" |
11 #include "ash/shelf/shelf_model.h" | 12 #include "ash/shelf/shelf_model.h" |
12 #include "ash/wm/window_properties.h" | |
13 #include "ash/wm_window.h" | 13 #include "ash/wm_window.h" |
14 #include "base/memory/ptr_util.h" | 14 #include "base/memory/ptr_util.h" |
15 #include "chrome/browser/chrome_notification_types.h" | 15 #include "chrome/browser/chrome_notification_types.h" |
16 #include "chrome/browser/profiles/profile.h" | 16 #include "chrome/browser/profiles/profile.h" |
17 #include "chrome/browser/ui/ash/launcher/chrome_launcher_controller.h" | 17 #include "chrome/browser/ui/ash/launcher/chrome_launcher_controller.h" |
18 #include "chrome/browser/ui/ash/launcher/chrome_launcher_controller_util.h" | 18 #include "chrome/browser/ui/ash/launcher/chrome_launcher_controller_util.h" |
19 #include "chrome/browser/ui/ash/launcher/launcher_context_menu.h" | 19 #include "chrome/browser/ui/ash/launcher/launcher_context_menu.h" |
20 #include "chrome/browser/ui/ash/multi_user/multi_user_util.h" | 20 #include "chrome/browser/ui/ash/multi_user/multi_user_util.h" |
21 #include "chrome/browser/ui/browser.h" | 21 #include "chrome/browser/ui/browser.h" |
22 #include "chrome/browser/ui/browser_commands.h" | 22 #include "chrome/browser/ui/browser_commands.h" |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
98 // If |web_contents| has not loaded, returns "New Tab". | 98 // If |web_contents| has not loaded, returns "New Tab". |
99 base::string16 GetBrowserListTitle(content::WebContents* web_contents) { | 99 base::string16 GetBrowserListTitle(content::WebContents* web_contents) { |
100 const base::string16& title = web_contents->GetTitle(); | 100 const base::string16& title = web_contents->GetTitle(); |
101 return title.empty() ? l10n_util::GetStringUTF16(IDS_NEW_TAB_TITLE) : title; | 101 return title.empty() ? l10n_util::GetStringUTF16(IDS_NEW_TAB_TITLE) : title; |
102 } | 102 } |
103 | 103 |
104 } // namespace | 104 } // namespace |
105 | 105 |
106 BrowserShortcutLauncherItemController::BrowserShortcutLauncherItemController( | 106 BrowserShortcutLauncherItemController::BrowserShortcutLauncherItemController( |
107 ash::ShelfModel* shelf_model) | 107 ash::ShelfModel* shelf_model) |
108 : ash::ShelfItemDelegate(ash::AppLaunchId(extension_misc::kChromeAppId)), | 108 : ash::ShelfItemDelegate(ash::ShelfID(extension_misc::kChromeAppId)), |
109 shelf_model_(shelf_model) { | 109 shelf_model_(shelf_model) { |
110 // Tag all open browser windows with the appropriate shelf id property. This | 110 // Tag all open browser windows with the appropriate shelf id property. This |
111 // associates each window with the shelf item for the active web contents. | 111 // associates each window with the shelf item for the active web contents. |
112 for (auto* browser : *BrowserList::GetInstance()) { | 112 for (auto* browser : *BrowserList::GetInstance()) { |
113 if (IsBrowserRepresentedInBrowserList(browser) && | 113 if (IsBrowserRepresentedInBrowserList(browser) && |
114 browser->tab_strip_model()->GetActiveWebContents()) { | 114 browser->tab_strip_model()->GetActiveWebContents()) { |
115 SetShelfIDForBrowserWindowContents( | 115 SetShelfIDForBrowserWindowContents( |
116 browser, browser->tab_strip_model()->GetActiveWebContents()); | 116 browser, browser->tab_strip_model()->GetActiveWebContents()); |
117 } | 117 } |
118 } | 118 } |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
167 // We need to set the window ShelfID for V1 applications since they are | 167 // We need to set the window ShelfID for V1 applications since they are |
168 // content which might change and as such change the application type. | 168 // content which might change and as such change the application type. |
169 // The browser window may not exist in unit tests. | 169 // The browser window may not exist in unit tests. |
170 if (!browser || !browser->window() || !browser->window()->GetNativeWindow() || | 170 if (!browser || !browser->window() || !browser->window()->GetNativeWindow() || |
171 !IsBrowserFromActiveUser(browser) || IsSettingsBrowser(browser)) { | 171 !IsBrowserFromActiveUser(browser) || IsSettingsBrowser(browser)) { |
172 return; | 172 return; |
173 } | 173 } |
174 | 174 |
175 browser->window()->GetNativeWindow()->SetProperty( | 175 browser->window()->GetNativeWindow()->SetProperty( |
176 ash::kShelfIDKey, | 176 ash::kShelfIDKey, |
177 ChromeLauncherController::instance()->GetShelfIDForWebContents( | 177 new ash::ShelfID( |
178 web_contents)); | 178 ChromeLauncherController::instance()->GetShelfIDForWebContents( |
| 179 web_contents))); |
179 } | 180 } |
180 | 181 |
181 void BrowserShortcutLauncherItemController::ItemSelected( | 182 void BrowserShortcutLauncherItemController::ItemSelected( |
182 std::unique_ptr<ui::Event> event, | 183 std::unique_ptr<ui::Event> event, |
183 int64_t display_id, | 184 int64_t display_id, |
184 ash::ShelfLaunchSource source, | 185 ash::ShelfLaunchSource source, |
185 const ItemSelectedCallback& callback) { | 186 const ItemSelectedCallback& callback) { |
186 if (event && (event->flags() & ui::EF_CONTROL_DOWN)) { | 187 if (event && (event->flags() & ui::EF_CONTROL_DOWN)) { |
187 chrome::NewEmptyWindow(ChromeLauncherController::instance()->profile()); | 188 chrome::NewEmptyWindow(ChromeLauncherController::instance()->profile()); |
188 callback.Run(ash::SHELF_ACTION_NEW_WINDOW_CREATED, base::nullopt); | 189 callback.Run(ash::SHELF_ACTION_NEW_WINDOW_CREATED, base::nullopt); |
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
352 } | 353 } |
353 | 354 |
354 bool BrowserShortcutLauncherItemController::IsBrowserRepresentedInBrowserList( | 355 bool BrowserShortcutLauncherItemController::IsBrowserRepresentedInBrowserList( |
355 Browser* browser) { | 356 Browser* browser) { |
356 // Only Ash desktop browser windows for the active user are represented. | 357 // Only Ash desktop browser windows for the active user are represented. |
357 if (!browser || !IsBrowserFromActiveUser(browser)) | 358 if (!browser || !IsBrowserFromActiveUser(browser)) |
358 return false; | 359 return false; |
359 | 360 |
360 // v1 App popup windows with a valid app id have their own icon. | 361 // v1 App popup windows with a valid app id have their own icon. |
361 if (browser->is_app() && browser->is_type_popup() && | 362 if (browser->is_app() && browser->is_type_popup() && |
362 shelf_model_->GetShelfIDForAppID( | 363 !shelf_model_ |
363 web_app::GetExtensionIdFromApplicationName(browser->app_name())) != | 364 ->GetShelfIDForAppID( |
364 ash::kInvalidShelfID) { | 365 web_app::GetExtensionIdFromApplicationName(browser->app_name())) |
| 366 .IsNull()) { |
365 return false; | 367 return false; |
366 } | 368 } |
367 | 369 |
368 // Settings browsers have their own icon. | 370 // Settings browsers have their own icon. |
369 if (IsSettingsBrowser(browser)) | 371 if (IsSettingsBrowser(browser)) |
370 return false; | 372 return false; |
371 | 373 |
372 // Tabbed browser and other popup windows are all represented. | 374 // Tabbed browser and other popup windows are all represented. |
373 return true; | 375 return true; |
374 } | 376 } |
(...skipping 26 matching lines...) Expand all Loading... |
401 Browser* browser = content::Source<Browser>(source).ptr(); | 403 Browser* browser = content::Source<Browser>(source).ptr(); |
402 DCHECK(browser); | 404 DCHECK(browser); |
403 BrowserList::BrowserVector::iterator item = std::find( | 405 BrowserList::BrowserVector::iterator item = std::find( |
404 browser_menu_items_.begin(), browser_menu_items_.end(), browser); | 406 browser_menu_items_.begin(), browser_menu_items_.end(), browser); |
405 DCHECK(item != browser_menu_items_.end()); | 407 DCHECK(item != browser_menu_items_.end()); |
406 // Clear the entry for the closed browser and leave other indices intact. | 408 // Clear the entry for the closed browser and leave other indices intact. |
407 *item = nullptr; | 409 *item = nullptr; |
408 registrar_.Remove(this, chrome::NOTIFICATION_BROWSER_CLOSING, | 410 registrar_.Remove(this, chrome::NOTIFICATION_BROWSER_CLOSING, |
409 content::Source<Browser>(browser)); | 411 content::Source<Browser>(browser)); |
410 } | 412 } |
OLD | NEW |