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/gtk/create_application_shortcuts_dialog_gtk.h" | 5 #include "chrome/browser/ui/gtk/create_application_shortcuts_dialog_gtk.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/environment.h" | 10 #include "base/environment.h" |
11 #include "base/utf_string_conversions.h" | 11 #include "base/utf_string_conversions.h" |
12 #include "chrome/browser/shell_integration.h" | 12 #include "chrome/browser/shell_integration.h" |
13 #include "chrome/browser/ui/gtk/gtk_util.h" | 13 #include "chrome/browser/ui/gtk/gtk_util.h" |
14 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" | 14 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" |
15 #include "chrome/browser/ui/web_applications/web_app_ui.h" | 15 #include "chrome/browser/ui/web_applications/web_app_ui.h" |
16 #include "chrome/browser/ui/webui/extensions/extension_icon_source.h" | 16 #include "chrome/browser/ui/webui/extensions/extension_icon_source.h" |
17 #include "chrome/common/extensions/extension.h" | 17 #include "chrome/common/extensions/extension.h" |
18 #include "chrome/common/extensions/extension_resource.h" | 18 #include "chrome/common/extensions/extension_resource.h" |
19 #include "content/public/browser/browser_thread.h" | 19 #include "content/public/browser/browser_thread.h" |
20 #include "content/public/browser/web_contents.h" | 20 #include "content/public/browser/web_contents.h" |
21 #include "content/public/browser/web_contents_delegate.h" | 21 #include "content/public/browser/web_contents_delegate.h" |
22 #include "grit/chromium_strings.h" | 22 #include "grit/chromium_strings.h" |
23 #include "grit/generated_resources.h" | 23 #include "grit/generated_resources.h" |
24 #include "grit/locale_settings.h" | 24 #include "grit/locale_settings.h" |
25 #include "grit/theme_resources.h" | 25 #include "grit/theme_resources.h" |
26 #include "ui/base/gtk/gtk_hig_constants.h" | 26 #include "ui/base/gtk/gtk_hig_constants.h" |
27 #include "ui/base/l10n/l10n_util.h" | 27 #include "ui/base/l10n/l10n_util.h" |
| 28 #include "ui/base/resource/resource_bundle.h" |
28 #include "ui/gfx/gtk_util.h" | 29 #include "ui/gfx/gtk_util.h" |
29 | 30 |
30 using content::BrowserThread; | 31 using content::BrowserThread; |
31 | 32 |
32 namespace { | 33 namespace { |
33 | 34 |
34 // Size (in pixels) of the icon preview. | 35 // Size (in pixels) of the icon preview. |
35 const int kIconPreviewSizePixels = 32; | 36 const int kIconPreviewSizePixels = 32; |
36 | 37 |
37 // Height (in lines) of the shortcut description label. | 38 // Height (in lines) of the shortcut description label. |
(...skipping 21 matching lines...) Expand all Loading... |
59 favicon_pixbuf_(NULL), | 60 favicon_pixbuf_(NULL), |
60 create_dialog_(NULL), | 61 create_dialog_(NULL), |
61 error_dialog_(NULL) { | 62 error_dialog_(NULL) { |
62 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 63 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
63 | 64 |
64 // Will be balanced by Release later. | 65 // Will be balanced by Release later. |
65 AddRef(); | 66 AddRef(); |
66 } | 67 } |
67 | 68 |
68 void CreateApplicationShortcutsDialogGtk::CreateIconPixBuf( | 69 void CreateApplicationShortcutsDialogGtk::CreateIconPixBuf( |
69 const SkBitmap& bitmap) { | 70 const gfx::Image& image) { |
70 // Prepare the icon. Try to scale it if it's too small, otherwise it would | 71 // Prepare the icon. Try to scale it if it's too small, otherwise it would |
71 // look weird. | 72 // look weird. |
72 GdkPixbuf* pixbuf = gfx::GdkPixbufFromSkBitmap(&shortcut_info_.favicon); | 73 GdkPixbuf* pixbuf = image.ToGdkPixbuf(); |
73 int pixbuf_width = gdk_pixbuf_get_width(pixbuf); | 74 int pixbuf_width = gdk_pixbuf_get_width(pixbuf); |
74 int pixbuf_height = gdk_pixbuf_get_height(pixbuf); | 75 int pixbuf_height = gdk_pixbuf_get_height(pixbuf); |
75 if (pixbuf_width == pixbuf_height && pixbuf_width < kIconPreviewSizePixels) { | 76 if (pixbuf_width == pixbuf_height && pixbuf_width < kIconPreviewSizePixels) { |
76 // Only scale the pixbuf if it's a square (for simplicity). | 77 // Only scale the pixbuf if it's a square (for simplicity). |
77 // Generally it should be square, if it's a favicon or app icon. | 78 // Generally it should be square, if it's a favicon or app icon. |
78 // Use the highest quality interpolation. The scaling is | 79 // Use the highest quality interpolation. The scaling is |
79 // going to have low quality anyway, because the initial image | 80 // going to have low quality anyway, because the initial image |
80 // is likely small. | 81 // is likely small. |
81 favicon_pixbuf_ = gdk_pixbuf_scale_simple(pixbuf, | 82 favicon_pixbuf_ = gdk_pixbuf_scale_simple(pixbuf, |
82 kIconPreviewSizePixels, | 83 kIconPreviewSizePixels, |
(...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
325 // if the image is cached. This is very rare. Do not do anything after | 326 // if the image is cached. This is very rare. Do not do anything after |
326 // calling LoadImage() that OnImageLoaded() depends on. | 327 // calling LoadImage() that OnImageLoaded() depends on. |
327 tracker_.LoadImage(app_, | 328 tracker_.LoadImage(app_, |
328 icon_resource, | 329 icon_resource, |
329 max_size, | 330 max_size, |
330 ImageLoadingTracker::DONT_CACHE); | 331 ImageLoadingTracker::DONT_CACHE); |
331 } | 332 } |
332 | 333 |
333 // Called by tracker_ when the app's icon is loaded. | 334 // Called by tracker_ when the app's icon is loaded. |
334 void CreateChromeApplicationShortcutsDialogGtk::OnImageLoaded( | 335 void CreateChromeApplicationShortcutsDialogGtk::OnImageLoaded( |
335 SkBitmap* image, const ExtensionResource& resource, int index) { | 336 const gfx::Image& image, |
336 if (!image || image->isNull()) | 337 const std::string& extension_id, |
337 image = ExtensionIconSource::LoadImageByResourceId(IDR_APP_DEFAULT_ICON); | 338 int index) { |
| 339 if (image.IsEmpty()) { |
| 340 shortcut_info_.favicon = |
| 341 ResourceBundle::GetSharedInstance().GetImageNamed(IDR_APP_DEFAULT_ICON); |
| 342 } else { |
| 343 shortcut_info_.favicon = image; |
| 344 } |
338 | 345 |
339 shortcut_info_.favicon = *image; | 346 CreateIconPixBuf(shortcut_info_.favicon); |
340 | |
341 CreateIconPixBuf(*image); | |
342 CreateDialogBox(parent_); | 347 CreateDialogBox(parent_); |
343 } | 348 } |
OLD | NEW |