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/extensions/app_shortcut_manager.h" | 5 #include "chrome/browser/extensions/app_shortcut_manager.h" |
6 | 6 |
7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/utf_string_conversions.h" | 8 #include "base/utf_string_conversions.h" |
9 #include "chrome/browser/profiles/profile.h" | 9 #include "chrome/browser/profiles/profile.h" |
10 #include "chrome/browser/web_applications/web_app.h" | 10 #include "chrome/browser/web_applications/web_app.h" |
(...skipping 18 matching lines...) Expand all Loading... | |
29 #else | 29 #else |
30 const int kDesiredSizes[] = {32}; | 30 const int kDesiredSizes[] = {32}; |
31 #endif | 31 #endif |
32 } // namespace | 32 } // namespace |
33 | 33 |
34 AppShortcutManager::AppShortcutManager(Profile* profile) | 34 AppShortcutManager::AppShortcutManager(Profile* profile) |
35 : profile_(profile), | 35 : profile_(profile), |
36 tracker_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) { | 36 tracker_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) { |
37 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_INSTALLED, | 37 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_INSTALLED, |
38 content::Source<Profile>(profile_)); | 38 content::Source<Profile>(profile_)); |
39 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UNINSTALLED, | |
40 content::Source<Profile>(profile_)); | |
39 } | 41 } |
40 | 42 |
41 void AppShortcutManager::OnImageLoaded(const gfx::Image& image, | 43 void AppShortcutManager::OnImageLoaded(const gfx::Image& image, |
42 const std::string& extension_id, | 44 const std::string& extension_id, |
43 int index) { | 45 int index) { |
44 // If the image failed to load (e.g. if the resource being loaded was empty) | 46 // If the image failed to load (e.g. if the resource being loaded was empty) |
45 // use the standard application icon. | 47 // use the standard application icon. |
46 if (image.IsEmpty()) { | 48 if (image.IsEmpty()) { |
47 gfx::Image default_icon = | 49 gfx::Image default_icon = |
48 ResourceBundle::GetSharedInstance().GetImageNamed(IDR_APP_DEFAULT_ICON); | 50 ResourceBundle::GetSharedInstance().GetImageNamed(IDR_APP_DEFAULT_ICON); |
49 int size = kDesiredSizes[arraysize(kDesiredSizes) - 1]; | 51 int size = kDesiredSizes[arraysize(kDesiredSizes) - 1]; |
50 SkBitmap bmp = skia::ImageOperations::Resize( | 52 SkBitmap bmp = skia::ImageOperations::Resize( |
51 *default_icon.ToSkBitmap(), skia::ImageOperations::RESIZE_BEST, | 53 *default_icon.ToSkBitmap(), skia::ImageOperations::RESIZE_BEST, |
52 size, size); | 54 size, size); |
53 shortcut_info_.favicon = gfx::Image(bmp); | 55 shortcut_info_.favicon = gfx::Image(bmp); |
54 } else { | 56 } else { |
55 shortcut_info_.favicon = image; | 57 shortcut_info_.favicon = image; |
56 } | 58 } |
57 | 59 |
58 web_app::CreateShortcut(profile_->GetPath(), shortcut_info_); | 60 web_app::CreateShortcut(profile_->GetPath(), shortcut_info_); |
59 } | 61 } |
60 | 62 |
61 void AppShortcutManager::Observe(int type, | 63 void AppShortcutManager::Observe(int type, |
62 const content::NotificationSource& source, | 64 const content::NotificationSource& source, |
63 const content::NotificationDetails& details) { | 65 const content::NotificationDetails& details) { |
64 DCHECK(type == chrome::NOTIFICATION_EXTENSION_INSTALLED); | 66 #if !defined(OS_MACOSX) |
65 #if !defined(OS_MACOSX) | 67 if (type == chrome::NOTIFICATION_EXTENSION_INSTALLED) { |
koz (OOO until 15th September)
2012/07/10 00:23:52
if / else if / else -> switch?
| |
66 const Extension* extension = content::Details<const Extension>( | 68 const Extension* extension = content::Details<const Extension>( |
67 details).ptr(); | 69 details).ptr(); |
68 if (!disable_shortcut_creation_for_tests && | 70 if (!disable_shortcut_creation_for_tests && |
69 extension->is_platform_app() && | 71 extension->is_platform_app() && |
70 extension->location() != Extension::LOAD) | 72 extension->location() != Extension::LOAD) { |
71 InstallApplicationShortcuts(extension); | 73 InstallApplicationShortcuts(extension); |
72 #endif | 74 } |
75 } else if (type == chrome::NOTIFICATION_EXTENSION_UNINSTALLED) { | |
76 std::string extension_id = *content::Details<std::string>(details).ptr(); | |
77 if (!disable_shortcut_creation_for_tests) | |
78 web_app::DeleteAllShortcuts(profile_->GetPath(), extension_id); | |
79 } else { | |
80 NOTREACHED(); | |
81 } | |
82 #endif | |
73 } | 83 } |
74 | 84 |
75 // static | 85 // static |
76 void AppShortcutManager::SetShortcutCreationDisabledForTesting(bool disabled) { | 86 void AppShortcutManager::SetShortcutCreationDisabledForTesting(bool disabled) { |
77 disable_shortcut_creation_for_tests = disabled; | 87 disable_shortcut_creation_for_tests = disabled; |
78 } | 88 } |
79 | 89 |
80 void AppShortcutManager::InstallApplicationShortcuts( | 90 void AppShortcutManager::InstallApplicationShortcuts( |
81 const Extension* extension) { | 91 const Extension* extension) { |
82 shortcut_info_.extension_id = extension->id(); | 92 shortcut_info_.extension_id = extension->id(); |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
116 } | 126 } |
117 info_list.push_back( | 127 info_list.push_back( |
118 ImageLoadingTracker::ImageInfo(resource, gfx::Size(size, size))); | 128 ImageLoadingTracker::ImageInfo(resource, gfx::Size(size, size))); |
119 } | 129 } |
120 | 130 |
121 // |icon_resources| may still be empty at this point, in which case LoadImage | 131 // |icon_resources| may still be empty at this point, in which case LoadImage |
122 // will call the OnImageLoaded callback with an empty image and exit | 132 // will call the OnImageLoaded callback with an empty image and exit |
123 // immediately. | 133 // immediately. |
124 tracker_.LoadImages(extension, info_list, ImageLoadingTracker::DONT_CACHE); | 134 tracker_.LoadImages(extension, info_list, ImageLoadingTracker::DONT_CACHE); |
125 } | 135 } |
OLD | NEW |