Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "chrome/browser/media/window_icon_util.h" | |
| 6 | |
| 7 #include "chrome/browser/ui/views/frame/browser_view.h" | |
| 8 #include "content/public/browser/desktop_media_id.h" | |
| 9 #include "extensions/grit/extensions_browser_resources.h" | |
| 10 #include "grit/theme_resources.h" | |
| 11 #include "ui/aura/client/aura_constants.h" | |
| 12 #include "ui/aura/window.h" | |
| 13 #include "ui/base/resource/resource_bundle.h" | |
| 14 | |
| 15 gfx::ImageSkia GetWindowIcon(content::DesktopMediaID id) { | |
| 16 DCHECK(id.type == content::DesktopMediaID::TYPE_WINDOW); | |
|
sky
2016/08/25 15:44:51
DCHECK_EQ
qiangchen
2016/08/25 17:07:59
Done.
| |
| 17 aura::Window* window = content::DesktopMediaID::GetAuraWindowById(id); | |
| 18 if (!window) | |
| 19 return gfx::ImageSkia(); | |
| 20 | |
| 21 const gfx::ImageSkia* icon_image_ptr = | |
| 22 window->GetProperty(aura::client::kWindowIconKey); | |
| 23 | |
| 24 if (icon_image_ptr) | |
| 25 return *icon_image_ptr; | |
| 26 | |
| 27 // The following code deals with the default icon case: | |
| 28 // As aura framework uses empty icon to represent default icon, it relies on | |
| 29 // the caller to handle the case. | |
| 30 // Here we are going to display default app icon for app windows without an | |
| 31 // icon, and display product logo for chrome browser windows. | |
| 32 | |
| 33 BrowserView* browser_view = | |
| 34 BrowserView::GetBrowserViewForNativeWindow(window); | |
| 35 Browser* browser = browser_view ? browser_view->browser() : nullptr; | |
| 36 | |
| 37 // Apps could be launched in a view other than BrowserView, so we count those | |
| 38 // windows without Browser association as apps. | |
| 39 // Technically dev tool is actually a special app, but we would like to | |
| 40 // display product logo for it, because intuitively it is internal to browser. | |
| 41 bool is_app = browser ? browser->is_app() && !browser->is_devtools() : true; | |
| 42 int idr = is_app ? IDR_APP_DEFAULT_ICON : IDR_PRODUCT_LOGO_32; | |
| 43 | |
| 44 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); | |
| 45 icon_image_ptr = rb.GetImageSkiaNamed(idr); | |
|
sky
2016/08/25 15:44:51
GetImageSkiaNamed always returns non-null.
qiangchen
2016/08/25 17:07:59
Done.
| |
| 46 if (icon_image_ptr) | |
| 47 return *icon_image_ptr; | |
| 48 return gfx::ImageSkia(); | |
| 49 } | |
| OLD | NEW |