| 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/web_applications/web_app.h" | 5 #include "chrome/browser/web_applications/web_app.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
| 9 #include "base/file_util.h" | 9 #include "base/file_util.h" |
| 10 #include "base/i18n/file_util_icu.h" | 10 #include "base/i18n/file_util_icu.h" |
| (...skipping 24 matching lines...) Expand all Loading... |
| 35 #include "ui/gfx/image/image_skia.h" | 35 #include "ui/gfx/image/image_skia.h" |
| 36 | 36 |
| 37 #if defined(OS_WIN) | 37 #if defined(OS_WIN) |
| 38 #include "ui/gfx/icon_util.h" | 38 #include "ui/gfx/icon_util.h" |
| 39 #endif | 39 #endif |
| 40 | 40 |
| 41 using content::BrowserThread; | 41 using content::BrowserThread; |
| 42 | 42 |
| 43 namespace { | 43 namespace { |
| 44 | 44 |
| 45 typedef base::Callback<void(const ShellIntegration::ShortcutInfo&, | 45 typedef base::Callback<void(const web_app::ShortcutInfo&, |
| 46 const extensions::FileHandlersInfo&)> InfoCallback; | 46 const extensions::FileHandlersInfo&)> InfoCallback; |
| 47 | 47 |
| 48 #if defined(OS_MACOSX) | 48 #if defined(OS_MACOSX) |
| 49 const int kDesiredSizes[] = {16, 32, 128, 256, 512}; | 49 const int kDesiredSizes[] = {16, 32, 128, 256, 512}; |
| 50 const size_t kNumDesiredSizes = arraysize(kDesiredSizes); | 50 const size_t kNumDesiredSizes = arraysize(kDesiredSizes); |
| 51 #elif defined(OS_LINUX) | 51 #elif defined(OS_LINUX) |
| 52 // Linux supports icons of any size. FreeDesktop Icon Theme Specification states | 52 // Linux supports icons of any size. FreeDesktop Icon Theme Specification states |
| 53 // that "Minimally you should install a 48x48 icon in the hicolor theme." | 53 // that "Minimally you should install a 48x48 icon in the hicolor theme." |
| 54 const int kDesiredSizes[] = {16, 32, 48, 128, 256, 512}; | 54 const int kDesiredSizes[] = {16, 32, 48, 128, 256, 512}; |
| 55 const size_t kNumDesiredSizes = arraysize(kDesiredSizes); | 55 const size_t kNumDesiredSizes = arraysize(kDesiredSizes); |
| 56 #elif defined(OS_WIN) | 56 #elif defined(OS_WIN) |
| 57 const int* kDesiredSizes = IconUtil::kIconDimensions; | 57 const int* kDesiredSizes = IconUtil::kIconDimensions; |
| 58 const size_t kNumDesiredSizes = IconUtil::kNumIconDimensions; | 58 const size_t kNumDesiredSizes = IconUtil::kNumIconDimensions; |
| 59 #else | 59 #else |
| 60 const int kDesiredSizes[] = {32}; | 60 const int kDesiredSizes[] = {32}; |
| 61 const size_t kNumDesiredSizes = arraysize(kDesiredSizes); | 61 const size_t kNumDesiredSizes = arraysize(kDesiredSizes); |
| 62 #endif | 62 #endif |
| 63 | 63 |
| 64 #if defined(TOOLKIT_VIEWS) | 64 #if defined(TOOLKIT_VIEWS) |
| 65 // Predicator for sorting images from largest to smallest. | 65 // Predicator for sorting images from largest to smallest. |
| 66 bool IconPrecedes(const WebApplicationInfo::IconInfo& left, | 66 bool IconPrecedes(const WebApplicationInfo::IconInfo& left, |
| 67 const WebApplicationInfo::IconInfo& right) { | 67 const WebApplicationInfo::IconInfo& right) { |
| 68 return left.width < right.width; | 68 return left.width < right.width; |
| 69 } | 69 } |
| 70 #endif | 70 #endif |
| 71 | 71 |
| 72 bool CreateShortcutsWithInfoOnFileThread( | 72 bool CreateShortcutsWithInfoOnFileThread( |
| 73 web_app::ShortcutCreationReason reason, | 73 web_app::ShortcutCreationReason reason, |
| 74 const ShellIntegration::ShortcutLocations& locations, | 74 const web_app::ShortcutLocations& locations, |
| 75 const ShellIntegration::ShortcutInfo& shortcut_info, | 75 const web_app::ShortcutInfo& shortcut_info, |
| 76 const extensions::FileHandlersInfo& file_handlers_info) { | 76 const extensions::FileHandlersInfo& file_handlers_info) { |
| 77 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); | 77 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
| 78 | 78 |
| 79 base::FilePath shortcut_data_dir = | 79 base::FilePath shortcut_data_dir = |
| 80 web_app::GetWebAppDataDirectory(shortcut_info.profile_path, | 80 web_app::GetWebAppDataDirectory(shortcut_info.profile_path, |
| 81 shortcut_info.extension_id, | 81 shortcut_info.extension_id, |
| 82 shortcut_info.url); | 82 shortcut_info.url); |
| 83 return web_app::internals::CreatePlatformShortcuts( | 83 return web_app::internals::CreatePlatformShortcuts( |
| 84 shortcut_data_dir, shortcut_info, file_handlers_info, locations, reason); | 84 shortcut_data_dir, shortcut_info, file_handlers_info, locations, reason); |
| 85 } | 85 } |
| 86 | 86 |
| 87 void DeleteShortcutsOnFileThread( | 87 void DeleteShortcutsOnFileThread( |
| 88 const ShellIntegration::ShortcutInfo& shortcut_info) { | 88 const web_app::ShortcutInfo& shortcut_info) { |
| 89 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); | 89 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
| 90 | 90 |
| 91 base::FilePath shortcut_data_dir = web_app::GetWebAppDataDirectory( | 91 base::FilePath shortcut_data_dir = web_app::GetWebAppDataDirectory( |
| 92 shortcut_info.profile_path, shortcut_info.extension_id, GURL()); | 92 shortcut_info.profile_path, shortcut_info.extension_id, GURL()); |
| 93 return web_app::internals::DeletePlatformShortcuts( | 93 return web_app::internals::DeletePlatformShortcuts( |
| 94 shortcut_data_dir, shortcut_info); | 94 shortcut_data_dir, shortcut_info); |
| 95 } | 95 } |
| 96 | 96 |
| 97 void UpdateShortcutsOnFileThread( | 97 void UpdateShortcutsOnFileThread( |
| 98 const base::string16& old_app_title, | 98 const base::string16& old_app_title, |
| 99 const ShellIntegration::ShortcutInfo& shortcut_info, | 99 const web_app::ShortcutInfo& shortcut_info, |
| 100 const extensions::FileHandlersInfo& file_handlers_info) { | 100 const extensions::FileHandlersInfo& file_handlers_info) { |
| 101 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); | 101 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
| 102 | 102 |
| 103 base::FilePath shortcut_data_dir = web_app::GetWebAppDataDirectory( | 103 base::FilePath shortcut_data_dir = web_app::GetWebAppDataDirectory( |
| 104 shortcut_info.profile_path, shortcut_info.extension_id, GURL()); | 104 shortcut_info.profile_path, shortcut_info.extension_id, GURL()); |
| 105 return web_app::internals::UpdatePlatformShortcuts( | 105 return web_app::internals::UpdatePlatformShortcuts( |
| 106 shortcut_data_dir, old_app_title, shortcut_info, file_handlers_info); | 106 shortcut_data_dir, old_app_title, shortcut_info, file_handlers_info); |
| 107 } | 107 } |
| 108 | 108 |
| 109 void CreateShortcutsWithInfo( | 109 void CreateShortcutsWithInfo( |
| 110 web_app::ShortcutCreationReason reason, | 110 web_app::ShortcutCreationReason reason, |
| 111 const ShellIntegration::ShortcutLocations& locations, | 111 const web_app::ShortcutLocations& locations, |
| 112 const ShellIntegration::ShortcutInfo& shortcut_info, | 112 const web_app::ShortcutInfo& shortcut_info, |
| 113 const extensions::FileHandlersInfo& file_handlers_info) { | 113 const extensions::FileHandlersInfo& file_handlers_info) { |
| 114 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 114 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 115 | 115 |
| 116 BrowserThread::PostTask( | 116 BrowserThread::PostTask( |
| 117 BrowserThread::FILE, | 117 BrowserThread::FILE, |
| 118 FROM_HERE, | 118 FROM_HERE, |
| 119 base::Bind( | 119 base::Bind( |
| 120 base::IgnoreResult(&CreateShortcutsWithInfoOnFileThread), | 120 base::IgnoreResult(&CreateShortcutsWithInfoOnFileThread), |
| 121 reason, locations, shortcut_info, file_handlers_info)); | 121 reason, locations, shortcut_info, file_handlers_info)); |
| 122 } | 122 } |
| 123 | 123 |
| 124 void UpdateAllShortcutsForShortcutInfo( | 124 void UpdateAllShortcutsForShortcutInfo( |
| 125 const base::string16& old_app_title, | 125 const base::string16& old_app_title, |
| 126 const ShellIntegration::ShortcutInfo& shortcut_info, | 126 const web_app::ShortcutInfo& shortcut_info, |
| 127 const extensions::FileHandlersInfo& file_handlers_info) { | 127 const extensions::FileHandlersInfo& file_handlers_info) { |
| 128 BrowserThread::PostTask( | 128 BrowserThread::PostTask( |
| 129 BrowserThread::FILE, | 129 BrowserThread::FILE, |
| 130 FROM_HERE, | 130 FROM_HERE, |
| 131 base::Bind(&UpdateShortcutsOnFileThread, | 131 base::Bind(&UpdateShortcutsOnFileThread, |
| 132 old_app_title, shortcut_info, file_handlers_info)); | 132 old_app_title, shortcut_info, file_handlers_info)); |
| 133 } | 133 } |
| 134 | 134 |
| 135 void OnImageLoaded(ShellIntegration::ShortcutInfo shortcut_info, | 135 void OnImageLoaded(web_app::ShortcutInfo shortcut_info, |
| 136 extensions::FileHandlersInfo file_handlers_info, | 136 extensions::FileHandlersInfo file_handlers_info, |
| 137 InfoCallback callback, | 137 InfoCallback callback, |
| 138 const gfx::ImageFamily& image_family) { | 138 const gfx::ImageFamily& image_family) { |
| 139 // If the image failed to load (e.g. if the resource being loaded was empty) | 139 // If the image failed to load (e.g. if the resource being loaded was empty) |
| 140 // use the standard application icon. | 140 // use the standard application icon. |
| 141 if (image_family.empty()) { | 141 if (image_family.empty()) { |
| 142 gfx::Image default_icon = | 142 gfx::Image default_icon = |
| 143 ResourceBundle::GetSharedInstance().GetImageNamed(IDR_APP_DEFAULT_ICON); | 143 ResourceBundle::GetSharedInstance().GetImageNamed(IDR_APP_DEFAULT_ICON); |
| 144 int size = kDesiredSizes[kNumDesiredSizes - 1]; | 144 int size = kDesiredSizes[kNumDesiredSizes - 1]; |
| 145 SkBitmap bmp = skia::ImageOperations::Resize( | 145 SkBitmap bmp = skia::ImageOperations::Resize( |
| 146 *default_icon.ToSkBitmap(), skia::ImageOperations::RESIZE_BEST, | 146 *default_icon.ToSkBitmap(), skia::ImageOperations::RESIZE_BEST, |
| 147 size, size); | 147 size, size); |
| 148 gfx::ImageSkia image_skia = gfx::ImageSkia::CreateFrom1xBitmap(bmp); | 148 gfx::ImageSkia image_skia = gfx::ImageSkia::CreateFrom1xBitmap(bmp); |
| 149 // We are on the UI thread, and this image is needed from the FILE thread, | 149 // We are on the UI thread, and this image is needed from the FILE thread, |
| 150 // for creating shortcut icon files. | 150 // for creating shortcut icon files. |
| 151 image_skia.MakeThreadSafe(); | 151 image_skia.MakeThreadSafe(); |
| 152 shortcut_info.favicon.Add(gfx::Image(image_skia)); | 152 shortcut_info.favicon.Add(gfx::Image(image_skia)); |
| 153 } else { | 153 } else { |
| 154 shortcut_info.favicon = image_family; | 154 shortcut_info.favicon = image_family; |
| 155 } | 155 } |
| 156 | 156 |
| 157 callback.Run(shortcut_info, file_handlers_info); | 157 callback.Run(shortcut_info, file_handlers_info); |
| 158 } | 158 } |
| 159 | 159 |
| 160 void GetInfoForApp(const extensions::Extension* extension, | 160 void GetInfoForApp(const extensions::Extension* extension, |
| 161 Profile* profile, | 161 Profile* profile, |
| 162 const InfoCallback& callback) { | 162 const InfoCallback& callback) { |
| 163 ShellIntegration::ShortcutInfo shortcut_info = | 163 web_app::ShortcutInfo shortcut_info = |
| 164 web_app::ShortcutInfoForExtensionAndProfile(extension, profile); | 164 web_app::ShortcutInfoForExtensionAndProfile(extension, profile); |
| 165 extensions::FileHandlersInfo file_handlers_info( | 165 extensions::FileHandlersInfo file_handlers_info( |
| 166 extensions::FileHandlers::GetFileHandlers(extension)); | 166 extensions::FileHandlers::GetFileHandlers(extension)); |
| 167 | 167 |
| 168 std::vector<extensions::ImageLoader::ImageRepresentation> info_list; | 168 std::vector<extensions::ImageLoader::ImageRepresentation> info_list; |
| 169 for (size_t i = 0; i < kNumDesiredSizes; ++i) { | 169 for (size_t i = 0; i < kNumDesiredSizes; ++i) { |
| 170 int size = kDesiredSizes[i]; | 170 int size = kDesiredSizes[i]; |
| 171 extensions::ExtensionResource resource = | 171 extensions::ExtensionResource resource = |
| 172 extensions::IconsInfo::GetIconResource( | 172 extensions::IconsInfo::GetIconResource( |
| 173 extension, size, ExtensionIconSet::MATCH_EXACTLY); | 173 extension, size, ExtensionIconSet::MATCH_EXACTLY); |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 205 // LoadImageFamilyAsync will call the OnImageLoaded callback with an empty | 205 // LoadImageFamilyAsync will call the OnImageLoaded callback with an empty |
| 206 // image and exit immediately. | 206 // image and exit immediately. |
| 207 extensions::ImageLoader::Get(profile)->LoadImageFamilyAsync( | 207 extensions::ImageLoader::Get(profile)->LoadImageFamilyAsync( |
| 208 extension, | 208 extension, |
| 209 info_list, | 209 info_list, |
| 210 base::Bind(&OnImageLoaded, shortcut_info, file_handlers_info, callback)); | 210 base::Bind(&OnImageLoaded, shortcut_info, file_handlers_info, callback)); |
| 211 } | 211 } |
| 212 | 212 |
| 213 void IgnoreFileHandlersInfo( | 213 void IgnoreFileHandlersInfo( |
| 214 const web_app::ShortcutInfoCallback& shortcut_info_callback, | 214 const web_app::ShortcutInfoCallback& shortcut_info_callback, |
| 215 const ShellIntegration::ShortcutInfo& shortcut_info, | 215 const web_app::ShortcutInfo& shortcut_info, |
| 216 const extensions::FileHandlersInfo& file_handlers_info) { | 216 const extensions::FileHandlersInfo& file_handlers_info) { |
| 217 shortcut_info_callback.Run(shortcut_info); | 217 shortcut_info_callback.Run(shortcut_info); |
| 218 } | 218 } |
| 219 | 219 |
| 220 } // namespace | 220 } // namespace |
| 221 | 221 |
| 222 namespace web_app { | 222 namespace web_app { |
| 223 | 223 |
| 224 // The following string is used to build the directory name for | 224 // The following string is used to build the directory name for |
| 225 // shortcuts to chrome applications (the kind which are installed | 225 // shortcuts to chrome applications (the kind which are installed |
| (...skipping 10 matching lines...) Expand all Loading... |
| 236 base::string16 file_name = name; | 236 base::string16 file_name = name; |
| 237 #else | 237 #else |
| 238 std::string file_name = base::UTF16ToUTF8(name); | 238 std::string file_name = base::UTF16ToUTF8(name); |
| 239 #endif | 239 #endif |
| 240 file_util::ReplaceIllegalCharactersInPath(&file_name, '_'); | 240 file_util::ReplaceIllegalCharactersInPath(&file_name, '_'); |
| 241 return base::FilePath(file_name); | 241 return base::FilePath(file_name); |
| 242 } | 242 } |
| 243 | 243 |
| 244 bool CreateShortcutsOnFileThread( | 244 bool CreateShortcutsOnFileThread( |
| 245 ShortcutCreationReason reason, | 245 ShortcutCreationReason reason, |
| 246 const ShellIntegration::ShortcutLocations& locations, | 246 const web_app::ShortcutLocations& locations, |
| 247 const ShellIntegration::ShortcutInfo& shortcut_info) { | 247 const web_app::ShortcutInfo& shortcut_info) { |
| 248 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); | 248 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
| 249 | 249 |
| 250 return CreateShortcutsWithInfoOnFileThread( | 250 return CreateShortcutsWithInfoOnFileThread( |
| 251 reason, locations, shortcut_info, extensions::FileHandlersInfo(NULL)); | 251 reason, locations, shortcut_info, extensions::FileHandlersInfo(NULL)); |
| 252 } | 252 } |
| 253 | 253 |
| 254 } // namespace internals | 254 } // namespace internals |
| 255 | 255 |
| 256 web_app::ShortcutInfo::ShortcutInfo() |
| 257 : is_platform_app(false) { |
| 258 } |
| 259 |
| 260 web_app::ShortcutInfo::~ShortcutInfo() {} |
| 261 |
| 262 web_app::ShortcutLocations::ShortcutLocations() |
| 263 : on_desktop(false), |
| 264 applications_menu_location(APP_MENU_LOCATION_NONE), |
| 265 in_quick_launch_bar(false) |
| 266 #if defined(OS_POSIX) |
| 267 , hidden(false) |
| 268 #endif |
| 269 { |
| 270 } |
| 271 |
| 256 void GetShortcutInfoForTab(content::WebContents* web_contents, | 272 void GetShortcutInfoForTab(content::WebContents* web_contents, |
| 257 ShellIntegration::ShortcutInfo* info) { | 273 web_app::ShortcutInfo* info) { |
| 258 DCHECK(info); // Must provide a valid info. | 274 DCHECK(info); // Must provide a valid info. |
| 259 | 275 |
| 260 const FaviconTabHelper* favicon_tab_helper = | 276 const FaviconTabHelper* favicon_tab_helper = |
| 261 FaviconTabHelper::FromWebContents(web_contents); | 277 FaviconTabHelper::FromWebContents(web_contents); |
| 262 const extensions::TabHelper* extensions_tab_helper = | 278 const extensions::TabHelper* extensions_tab_helper = |
| 263 extensions::TabHelper::FromWebContents(web_contents); | 279 extensions::TabHelper::FromWebContents(web_contents); |
| 264 const WebApplicationInfo& app_info = extensions_tab_helper->web_app_info(); | 280 const WebApplicationInfo& app_info = extensions_tab_helper->web_app_info(); |
| 265 | 281 |
| 266 info->url = app_info.app_url.is_empty() ? web_contents->GetURL() : | 282 info->url = app_info.app_url.is_empty() ? web_contents->GetURL() : |
| 267 app_info.app_url; | 283 app_info.app_url; |
| 268 info->title = app_info.title.empty() ? | 284 info->title = app_info.title.empty() ? |
| 269 (web_contents->GetTitle().empty() ? base::UTF8ToUTF16(info->url.spec()) : | 285 (web_contents->GetTitle().empty() ? base::UTF8ToUTF16(info->url.spec()) : |
| 270 web_contents->GetTitle()) : | 286 web_contents->GetTitle()) : |
| 271 app_info.title; | 287 app_info.title; |
| 272 info->description = app_info.description; | 288 info->description = app_info.description; |
| 273 info->favicon.Add(favicon_tab_helper->GetFavicon()); | 289 info->favicon.Add(favicon_tab_helper->GetFavicon()); |
| 274 | 290 |
| 275 Profile* profile = | 291 Profile* profile = |
| 276 Profile::FromBrowserContext(web_contents->GetBrowserContext()); | 292 Profile::FromBrowserContext(web_contents->GetBrowserContext()); |
| 277 info->profile_path = profile->GetPath(); | 293 info->profile_path = profile->GetPath(); |
| 278 } | 294 } |
| 279 | 295 |
| 280 #if !defined(OS_WIN) | 296 #if !defined(OS_WIN) |
| 281 void UpdateShortcutForTabContents(content::WebContents* web_contents) {} | 297 void UpdateShortcutForTabContents(content::WebContents* web_contents) {} |
| 282 #endif | 298 #endif |
| 283 | 299 |
| 284 ShellIntegration::ShortcutInfo ShortcutInfoForExtensionAndProfile( | 300 web_app::ShortcutInfo ShortcutInfoForExtensionAndProfile( |
| 285 const extensions::Extension* app, Profile* profile) { | 301 const extensions::Extension* app, Profile* profile) { |
| 286 ShellIntegration::ShortcutInfo shortcut_info; | 302 web_app::ShortcutInfo shortcut_info; |
| 287 shortcut_info.extension_id = app->id(); | 303 shortcut_info.extension_id = app->id(); |
| 288 shortcut_info.is_platform_app = app->is_platform_app(); | 304 shortcut_info.is_platform_app = app->is_platform_app(); |
| 289 shortcut_info.url = extensions::AppLaunchInfo::GetLaunchWebURL(app); | 305 shortcut_info.url = extensions::AppLaunchInfo::GetLaunchWebURL(app); |
| 290 shortcut_info.title = base::UTF8ToUTF16(app->name()); | 306 shortcut_info.title = base::UTF8ToUTF16(app->name()); |
| 291 shortcut_info.description = base::UTF8ToUTF16(app->description()); | 307 shortcut_info.description = base::UTF8ToUTF16(app->description()); |
| 292 shortcut_info.extension_path = app->path(); | 308 shortcut_info.extension_path = app->path(); |
| 293 shortcut_info.profile_path = profile->GetPath(); | 309 shortcut_info.profile_path = profile->GetPath(); |
| 294 shortcut_info.profile_name = | 310 shortcut_info.profile_name = |
| 295 profile->GetPrefs()->GetString(prefs::kProfileName); | 311 profile->GetPrefs()->GetString(prefs::kProfileName); |
| 296 return shortcut_info; | 312 return shortcut_info; |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 334 | 350 |
| 335 base::FilePath GetWebAppDataDirectory(const base::FilePath& profile_path, | 351 base::FilePath GetWebAppDataDirectory(const base::FilePath& profile_path, |
| 336 const extensions::Extension& extension) { | 352 const extensions::Extension& extension) { |
| 337 return GetWebAppDataDirectory( | 353 return GetWebAppDataDirectory( |
| 338 profile_path, | 354 profile_path, |
| 339 extension.id(), | 355 extension.id(), |
| 340 GURL(extensions::AppLaunchInfo::GetLaunchWebURL(&extension))); | 356 GURL(extensions::AppLaunchInfo::GetLaunchWebURL(&extension))); |
| 341 } | 357 } |
| 342 | 358 |
| 343 std::string GenerateApplicationNameFromInfo( | 359 std::string GenerateApplicationNameFromInfo( |
| 344 const ShellIntegration::ShortcutInfo& shortcut_info) { | 360 const web_app::ShortcutInfo& shortcut_info) { |
| 345 if (!shortcut_info.extension_id.empty()) { | 361 if (!shortcut_info.extension_id.empty()) { |
| 346 return web_app::GenerateApplicationNameFromExtensionId( | 362 return web_app::GenerateApplicationNameFromExtensionId( |
| 347 shortcut_info.extension_id); | 363 shortcut_info.extension_id); |
| 348 } else { | 364 } else { |
| 349 return web_app::GenerateApplicationNameFromURL( | 365 return web_app::GenerateApplicationNameFromURL( |
| 350 shortcut_info.url); | 366 shortcut_info.url); |
| 351 } | 367 } |
| 352 } | 368 } |
| 353 | 369 |
| 354 std::string GenerateApplicationNameFromURL(const GURL& url) { | 370 std::string GenerateApplicationNameFromURL(const GURL& url) { |
| (...skipping 12 matching lines...) Expand all Loading... |
| 367 | 383 |
| 368 std::string GetExtensionIdFromApplicationName(const std::string& app_name) { | 384 std::string GetExtensionIdFromApplicationName(const std::string& app_name) { |
| 369 std::string prefix(kCrxAppPrefix); | 385 std::string prefix(kCrxAppPrefix); |
| 370 if (app_name.substr(0, prefix.length()) != prefix) | 386 if (app_name.substr(0, prefix.length()) != prefix) |
| 371 return std::string(); | 387 return std::string(); |
| 372 return app_name.substr(prefix.length()); | 388 return app_name.substr(prefix.length()); |
| 373 } | 389 } |
| 374 | 390 |
| 375 void CreateShortcutsForShortcutInfo( | 391 void CreateShortcutsForShortcutInfo( |
| 376 web_app::ShortcutCreationReason reason, | 392 web_app::ShortcutCreationReason reason, |
| 377 const ShellIntegration::ShortcutLocations& locations, | 393 const web_app::ShortcutLocations& locations, |
| 378 const ShellIntegration::ShortcutInfo& shortcut_info) { | 394 const web_app::ShortcutInfo& shortcut_info) { |
| 379 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 395 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 380 | 396 |
| 381 BrowserThread::PostTask( | 397 BrowserThread::PostTask( |
| 382 BrowserThread::FILE, | 398 BrowserThread::FILE, |
| 383 FROM_HERE, | 399 FROM_HERE, |
| 384 base::Bind( | 400 base::Bind( |
| 385 base::IgnoreResult(&web_app::internals::CreateShortcutsOnFileThread), | 401 base::IgnoreResult(&web_app::internals::CreateShortcutsOnFileThread), |
| 386 reason, locations, shortcut_info)); | 402 reason, locations, shortcut_info)); |
| 387 } | 403 } |
| 388 | 404 |
| 389 void CreateShortcuts( | 405 void CreateShortcuts( |
| 390 ShortcutCreationReason reason, | 406 ShortcutCreationReason reason, |
| 391 const ShellIntegration::ShortcutLocations& locations, | 407 const web_app::ShortcutLocations& locations, |
| 392 Profile* profile, | 408 Profile* profile, |
| 393 const extensions::Extension* app) { | 409 const extensions::Extension* app) { |
| 394 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 410 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 395 | 411 |
| 396 GetInfoForApp(app, | 412 GetInfoForApp(app, |
| 397 profile, | 413 profile, |
| 398 base::Bind(&CreateShortcutsWithInfo, reason, locations)); | 414 base::Bind(&CreateShortcutsWithInfo, reason, locations)); |
| 399 } | 415 } |
| 400 | 416 |
| 401 void DeleteAllShortcuts(Profile* profile, const extensions::Extension* app) { | 417 void DeleteAllShortcuts(Profile* profile, const extensions::Extension* app) { |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 455 | 471 |
| 456 #if defined(OS_LINUX) | 472 #if defined(OS_LINUX) |
| 457 std::string GetWMClassFromAppName(std::string app_name) { | 473 std::string GetWMClassFromAppName(std::string app_name) { |
| 458 file_util::ReplaceIllegalCharactersInPath(&app_name, '_'); | 474 file_util::ReplaceIllegalCharactersInPath(&app_name, '_'); |
| 459 base::TrimString(app_name, "_", &app_name); | 475 base::TrimString(app_name, "_", &app_name); |
| 460 return app_name; | 476 return app_name; |
| 461 } | 477 } |
| 462 #endif | 478 #endif |
| 463 | 479 |
| 464 } // namespace web_app | 480 } // namespace web_app |
| OLD | NEW |