| 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 48 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 59 | 59 | 
| 60 #if defined(TOOLKIT_VIEWS) | 60 #if defined(TOOLKIT_VIEWS) | 
| 61 // Predicator for sorting images from largest to smallest. | 61 // Predicator for sorting images from largest to smallest. | 
| 62 bool IconPrecedes(const WebApplicationInfo::IconInfo& left, | 62 bool IconPrecedes(const WebApplicationInfo::IconInfo& left, | 
| 63                   const WebApplicationInfo::IconInfo& right) { | 63                   const WebApplicationInfo::IconInfo& right) { | 
| 64   return left.width < right.width; | 64   return left.width < right.width; | 
| 65 } | 65 } | 
| 66 #endif | 66 #endif | 
| 67 | 67 | 
| 68 void DeleteShortcutsOnFileThread( | 68 void DeleteShortcutsOnFileThread( | 
| 69     const ShellIntegration::ShortcutInfo& shortcut_info) { | 69     const web_app::ShortcutInfo& shortcut_info) { | 
| 70   DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); | 70   DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); | 
| 71 | 71 | 
| 72   base::FilePath shortcut_data_dir = web_app::GetWebAppDataDirectory( | 72   base::FilePath shortcut_data_dir = web_app::GetWebAppDataDirectory( | 
| 73       shortcut_info.profile_path, shortcut_info.extension_id, GURL()); | 73       shortcut_info.profile_path, shortcut_info.extension_id, GURL()); | 
| 74   return web_app::internals::DeletePlatformShortcuts( | 74   return web_app::internals::DeletePlatformShortcuts( | 
| 75       shortcut_data_dir, shortcut_info); | 75       shortcut_data_dir, shortcut_info); | 
| 76 } | 76 } | 
| 77 | 77 | 
| 78 void UpdateShortcutsOnFileThread( | 78 void UpdateShortcutsOnFileThread( | 
| 79     const base::string16& old_app_title, | 79     const base::string16& old_app_title, | 
| 80     const ShellIntegration::ShortcutInfo& shortcut_info) { | 80     const web_app::ShortcutInfo& shortcut_info) { | 
| 81   DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); | 81   DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); | 
| 82 | 82 | 
| 83   base::FilePath shortcut_data_dir = web_app::GetWebAppDataDirectory( | 83   base::FilePath shortcut_data_dir = web_app::GetWebAppDataDirectory( | 
| 84       shortcut_info.profile_path, shortcut_info.extension_id, GURL()); | 84       shortcut_info.profile_path, shortcut_info.extension_id, GURL()); | 
| 85   return web_app::internals::UpdatePlatformShortcuts( | 85   return web_app::internals::UpdatePlatformShortcuts( | 
| 86       shortcut_data_dir, old_app_title, shortcut_info); | 86       shortcut_data_dir, old_app_title, shortcut_info); | 
| 87 } | 87 } | 
| 88 | 88 | 
| 89 void UpdateAllShortcutsForShortcutInfo( | 89 void UpdateAllShortcutsForShortcutInfo( | 
| 90     const base::string16& old_app_title, | 90     const base::string16& old_app_title, | 
| 91     const ShellIntegration::ShortcutInfo& shortcut_info) { | 91     const web_app::ShortcutInfo& shortcut_info) { | 
| 92   DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 92   DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 
| 93 | 93 | 
| 94   BrowserThread::PostTask( | 94   BrowserThread::PostTask( | 
| 95       BrowserThread::FILE, | 95       BrowserThread::FILE, | 
| 96       FROM_HERE, | 96       FROM_HERE, | 
| 97       base::Bind(&UpdateShortcutsOnFileThread, old_app_title, shortcut_info)); | 97       base::Bind(&UpdateShortcutsOnFileThread, old_app_title, shortcut_info)); | 
| 98 } | 98 } | 
| 99 | 99 | 
| 100 void OnImageLoaded(ShellIntegration::ShortcutInfo shortcut_info, | 100 void OnImageLoaded(web_app::ShortcutInfo shortcut_info, | 
| 101                    web_app::ShortcutInfoCallback callback, | 101                    web_app::ShortcutInfoCallback callback, | 
| 102                    const gfx::ImageFamily& image_family) { | 102                    const gfx::ImageFamily& image_family) { | 
| 103   // If the image failed to load (e.g. if the resource being loaded was empty) | 103   // If the image failed to load (e.g. if the resource being loaded was empty) | 
| 104   // use the standard application icon. | 104   // use the standard application icon. | 
| 105   if (image_family.empty()) { | 105   if (image_family.empty()) { | 
| 106     gfx::Image default_icon = | 106     gfx::Image default_icon = | 
| 107         ResourceBundle::GetSharedInstance().GetImageNamed(IDR_APP_DEFAULT_ICON); | 107         ResourceBundle::GetSharedInstance().GetImageNamed(IDR_APP_DEFAULT_ICON); | 
| 108     int size = kDesiredSizes[kNumDesiredSizes - 1]; | 108     int size = kDesiredSizes[kNumDesiredSizes - 1]; | 
| 109     SkBitmap bmp = skia::ImageOperations::Resize( | 109     SkBitmap bmp = skia::ImageOperations::Resize( | 
| 110           *default_icon.ToSkBitmap(), skia::ImageOperations::RESIZE_BEST, | 110           *default_icon.ToSkBitmap(), skia::ImageOperations::RESIZE_BEST, | 
| (...skipping 29 matching lines...) Expand all  Loading... | 
| 140   base::string16 file_name = name; | 140   base::string16 file_name = name; | 
| 141 #else | 141 #else | 
| 142   std::string file_name = base::UTF16ToUTF8(name); | 142   std::string file_name = base::UTF16ToUTF8(name); | 
| 143 #endif | 143 #endif | 
| 144   file_util::ReplaceIllegalCharactersInPath(&file_name, '_'); | 144   file_util::ReplaceIllegalCharactersInPath(&file_name, '_'); | 
| 145   return base::FilePath(file_name); | 145   return base::FilePath(file_name); | 
| 146 } | 146 } | 
| 147 | 147 | 
| 148 bool CreateShortcutsOnFileThread( | 148 bool CreateShortcutsOnFileThread( | 
| 149     ShortcutCreationReason reason, | 149     ShortcutCreationReason reason, | 
| 150     const ShellIntegration::ShortcutLocations& locations, | 150     const web_app::ShortcutLocations& locations, | 
| 151     const ShellIntegration::ShortcutInfo& shortcut_info) { | 151     const web_app::ShortcutInfo& shortcut_info) { | 
| 152   DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); | 152   DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); | 
| 153 | 153 | 
| 154   base::FilePath shortcut_data_dir = GetWebAppDataDirectory( | 154   base::FilePath shortcut_data_dir = GetWebAppDataDirectory( | 
| 155       shortcut_info.profile_path, shortcut_info.extension_id, | 155       shortcut_info.profile_path, shortcut_info.extension_id, | 
| 156       shortcut_info.url); | 156       shortcut_info.url); | 
| 157   return internals::CreatePlatformShortcuts( | 157   return internals::CreatePlatformShortcuts( | 
| 158       shortcut_data_dir, shortcut_info, locations, reason); | 158       shortcut_data_dir, shortcut_info, locations, reason); | 
| 159 } | 159 } | 
| 160 | 160 | 
| 161 }  // namespace internals | 161 }  // namespace internals | 
| 162 | 162 | 
|  | 163 web_app::ShortcutInfo::ShortcutInfo() | 
|  | 164     : is_platform_app(false) { | 
|  | 165 } | 
|  | 166 | 
|  | 167 web_app::ShortcutInfo::~ShortcutInfo() {} | 
|  | 168 | 
|  | 169 web_app::ShortcutLocations::ShortcutLocations() | 
|  | 170     : on_desktop(false), | 
|  | 171       applications_menu_location(APP_MENU_LOCATION_NONE), | 
|  | 172       in_quick_launch_bar(false) | 
|  | 173 #if defined(OS_POSIX) | 
|  | 174       , hidden(false) | 
|  | 175 #endif | 
|  | 176       { | 
|  | 177 } | 
|  | 178 | 
| 163 void GetShortcutInfoForTab(content::WebContents* web_contents, | 179 void GetShortcutInfoForTab(content::WebContents* web_contents, | 
| 164                            ShellIntegration::ShortcutInfo* info) { | 180                            web_app::ShortcutInfo* info) { | 
| 165   DCHECK(info);  // Must provide a valid info. | 181   DCHECK(info);  // Must provide a valid info. | 
| 166 | 182 | 
| 167   const FaviconTabHelper* favicon_tab_helper = | 183   const FaviconTabHelper* favicon_tab_helper = | 
| 168       FaviconTabHelper::FromWebContents(web_contents); | 184       FaviconTabHelper::FromWebContents(web_contents); | 
| 169   const extensions::TabHelper* extensions_tab_helper = | 185   const extensions::TabHelper* extensions_tab_helper = | 
| 170       extensions::TabHelper::FromWebContents(web_contents); | 186       extensions::TabHelper::FromWebContents(web_contents); | 
| 171   const WebApplicationInfo& app_info = extensions_tab_helper->web_app_info(); | 187   const WebApplicationInfo& app_info = extensions_tab_helper->web_app_info(); | 
| 172 | 188 | 
| 173   info->url = app_info.app_url.is_empty() ? web_contents->GetURL() : | 189   info->url = app_info.app_url.is_empty() ? web_contents->GetURL() : | 
| 174                                             app_info.app_url; | 190                                             app_info.app_url; | 
| 175   info->title = app_info.title.empty() ? | 191   info->title = app_info.title.empty() ? | 
| 176       (web_contents->GetTitle().empty() ? base::UTF8ToUTF16(info->url.spec()) : | 192       (web_contents->GetTitle().empty() ? base::UTF8ToUTF16(info->url.spec()) : | 
| 177                                           web_contents->GetTitle()) : | 193                                           web_contents->GetTitle()) : | 
| 178       app_info.title; | 194       app_info.title; | 
| 179   info->description = app_info.description; | 195   info->description = app_info.description; | 
| 180   info->favicon.Add(favicon_tab_helper->GetFavicon()); | 196   info->favicon.Add(favicon_tab_helper->GetFavicon()); | 
| 181 | 197 | 
| 182   Profile* profile = | 198   Profile* profile = | 
| 183       Profile::FromBrowserContext(web_contents->GetBrowserContext()); | 199       Profile::FromBrowserContext(web_contents->GetBrowserContext()); | 
| 184   info->profile_path = profile->GetPath(); | 200   info->profile_path = profile->GetPath(); | 
| 185 } | 201 } | 
| 186 | 202 | 
| 187 #if !defined(OS_WIN) | 203 #if !defined(OS_WIN) | 
| 188 void UpdateShortcutForTabContents(content::WebContents* web_contents) {} | 204 void UpdateShortcutForTabContents(content::WebContents* web_contents) {} | 
| 189 #endif | 205 #endif | 
| 190 | 206 | 
| 191 ShellIntegration::ShortcutInfo ShortcutInfoForExtensionAndProfile( | 207 web_app::ShortcutInfo ShortcutInfoForExtensionAndProfile( | 
| 192     const extensions::Extension* app, Profile* profile) { | 208     const extensions::Extension* app, Profile* profile) { | 
| 193   ShellIntegration::ShortcutInfo shortcut_info; | 209   web_app::ShortcutInfo shortcut_info; | 
| 194   shortcut_info.extension_id = app->id(); | 210   shortcut_info.extension_id = app->id(); | 
| 195   shortcut_info.is_platform_app = app->is_platform_app(); | 211   shortcut_info.is_platform_app = app->is_platform_app(); | 
| 196   shortcut_info.url = extensions::AppLaunchInfo::GetLaunchWebURL(app); | 212   shortcut_info.url = extensions::AppLaunchInfo::GetLaunchWebURL(app); | 
| 197   shortcut_info.title = base::UTF8ToUTF16(app->name()); | 213   shortcut_info.title = base::UTF8ToUTF16(app->name()); | 
| 198   shortcut_info.description = base::UTF8ToUTF16(app->description()); | 214   shortcut_info.description = base::UTF8ToUTF16(app->description()); | 
| 199   shortcut_info.extension_path = app->path(); | 215   shortcut_info.extension_path = app->path(); | 
| 200   shortcut_info.profile_path = profile->GetPath(); | 216   shortcut_info.profile_path = profile->GetPath(); | 
| 201   shortcut_info.profile_name = | 217   shortcut_info.profile_name = | 
| 202       profile->GetPrefs()->GetString(prefs::kProfileName); | 218       profile->GetPrefs()->GetString(prefs::kProfileName); | 
| 203   return shortcut_info; | 219   return shortcut_info; | 
| 204 } | 220 } | 
| 205 | 221 | 
| 206 void UpdateShortcutInfoAndIconForApp( | 222 void UpdateShortcutInfoAndIconForApp( | 
| 207     const extensions::Extension* extension, | 223     const extensions::Extension* extension, | 
| 208     Profile* profile, | 224     Profile* profile, | 
| 209     const web_app::ShortcutInfoCallback& callback) { | 225     const web_app::ShortcutInfoCallback& callback) { | 
| 210   ShellIntegration::ShortcutInfo shortcut_info = | 226   web_app::ShortcutInfo shortcut_info = | 
| 211       ShortcutInfoForExtensionAndProfile(extension, profile); | 227       ShortcutInfoForExtensionAndProfile(extension, profile); | 
| 212 | 228 | 
| 213   std::vector<extensions::ImageLoader::ImageRepresentation> info_list; | 229   std::vector<extensions::ImageLoader::ImageRepresentation> info_list; | 
| 214   for (size_t i = 0; i < kNumDesiredSizes; ++i) { | 230   for (size_t i = 0; i < kNumDesiredSizes; ++i) { | 
| 215     int size = kDesiredSizes[i]; | 231     int size = kDesiredSizes[i]; | 
| 216     extensions::ExtensionResource resource = | 232     extensions::ExtensionResource resource = | 
| 217         extensions::IconsInfo::GetIconResource( | 233         extensions::IconsInfo::GetIconResource( | 
| 218             extension, size, ExtensionIconSet::MATCH_EXACTLY); | 234             extension, size, ExtensionIconSet::MATCH_EXACTLY); | 
| 219     if (!resource.empty()) { | 235     if (!resource.empty()) { | 
| 220       info_list.push_back(extensions::ImageLoader::ImageRepresentation( | 236       info_list.push_back(extensions::ImageLoader::ImageRepresentation( | 
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 284 | 300 | 
| 285 base::FilePath GetWebAppDataDirectory(const base::FilePath& profile_path, | 301 base::FilePath GetWebAppDataDirectory(const base::FilePath& profile_path, | 
| 286                                       const extensions::Extension& extension) { | 302                                       const extensions::Extension& extension) { | 
| 287   return GetWebAppDataDirectory( | 303   return GetWebAppDataDirectory( | 
| 288       profile_path, | 304       profile_path, | 
| 289       extension.id(), | 305       extension.id(), | 
| 290       GURL(extensions::AppLaunchInfo::GetLaunchWebURL(&extension))); | 306       GURL(extensions::AppLaunchInfo::GetLaunchWebURL(&extension))); | 
| 291 } | 307 } | 
| 292 | 308 | 
| 293 std::string GenerateApplicationNameFromInfo( | 309 std::string GenerateApplicationNameFromInfo( | 
| 294     const ShellIntegration::ShortcutInfo& shortcut_info) { | 310     const web_app::ShortcutInfo& shortcut_info) { | 
| 295   if (!shortcut_info.extension_id.empty()) { | 311   if (!shortcut_info.extension_id.empty()) { | 
| 296     return web_app::GenerateApplicationNameFromExtensionId( | 312     return web_app::GenerateApplicationNameFromExtensionId( | 
| 297         shortcut_info.extension_id); | 313         shortcut_info.extension_id); | 
| 298   } else { | 314   } else { | 
| 299     return web_app::GenerateApplicationNameFromURL( | 315     return web_app::GenerateApplicationNameFromURL( | 
| 300         shortcut_info.url); | 316         shortcut_info.url); | 
| 301   } | 317   } | 
| 302 } | 318 } | 
| 303 | 319 | 
| 304 std::string GenerateApplicationNameFromURL(const GURL& url) { | 320 std::string GenerateApplicationNameFromURL(const GURL& url) { | 
| (...skipping 12 matching lines...) Expand all  Loading... | 
| 317 | 333 | 
| 318 std::string GetExtensionIdFromApplicationName(const std::string& app_name) { | 334 std::string GetExtensionIdFromApplicationName(const std::string& app_name) { | 
| 319   std::string prefix(kCrxAppPrefix); | 335   std::string prefix(kCrxAppPrefix); | 
| 320   if (app_name.substr(0, prefix.length()) != prefix) | 336   if (app_name.substr(0, prefix.length()) != prefix) | 
| 321     return std::string(); | 337     return std::string(); | 
| 322   return app_name.substr(prefix.length()); | 338   return app_name.substr(prefix.length()); | 
| 323 } | 339 } | 
| 324 | 340 | 
| 325 void CreateShortcutsForShortcutInfo( | 341 void CreateShortcutsForShortcutInfo( | 
| 326     web_app::ShortcutCreationReason reason, | 342     web_app::ShortcutCreationReason reason, | 
| 327     const ShellIntegration::ShortcutLocations& locations, | 343     const web_app::ShortcutLocations& locations, | 
| 328     const ShellIntegration::ShortcutInfo& shortcut_info) { | 344     const web_app::ShortcutInfo& shortcut_info) { | 
| 329   DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 345   DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 
| 330 | 346 | 
| 331   BrowserThread::PostTask( | 347   BrowserThread::PostTask( | 
| 332       BrowserThread::FILE, | 348       BrowserThread::FILE, | 
| 333       FROM_HERE, | 349       FROM_HERE, | 
| 334       base::Bind( | 350       base::Bind( | 
| 335           base::IgnoreResult(&web_app::internals::CreateShortcutsOnFileThread), | 351           base::IgnoreResult(&web_app::internals::CreateShortcutsOnFileThread), | 
| 336           reason, locations, shortcut_info)); | 352           reason, locations, shortcut_info)); | 
| 337 } | 353 } | 
| 338 | 354 | 
| 339 void CreateShortcuts( | 355 void CreateShortcuts( | 
| 340     ShortcutCreationReason reason, | 356     ShortcutCreationReason reason, | 
| 341     const ShellIntegration::ShortcutLocations& locations, | 357     const web_app::ShortcutLocations& locations, | 
| 342     Profile* profile, | 358     Profile* profile, | 
| 343     const extensions::Extension* app) { | 359     const extensions::Extension* app) { | 
| 344   DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 360   DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 
| 345 | 361 | 
| 346   web_app::UpdateShortcutInfoAndIconForApp( | 362   web_app::UpdateShortcutInfoAndIconForApp( | 
| 347       app, | 363       app, | 
| 348       profile, | 364       profile, | 
| 349       base::Bind(&CreateShortcutsForShortcutInfo, reason, locations)); | 365       base::Bind(&CreateShortcutsForShortcutInfo, reason, locations)); | 
| 350 } | 366 } | 
| 351 | 367 | 
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 407 | 423 | 
| 408 #if defined(OS_LINUX) | 424 #if defined(OS_LINUX) | 
| 409 std::string GetWMClassFromAppName(std::string app_name) { | 425 std::string GetWMClassFromAppName(std::string app_name) { | 
| 410   file_util::ReplaceIllegalCharactersInPath(&app_name, '_'); | 426   file_util::ReplaceIllegalCharactersInPath(&app_name, '_'); | 
| 411   base::TrimString(app_name, "_", &app_name); | 427   base::TrimString(app_name, "_", &app_name); | 
| 412   return app_name; | 428   return app_name; | 
| 413 } | 429 } | 
| 414 #endif | 430 #endif | 
| 415 | 431 | 
| 416 }  // namespace web_app | 432 }  // namespace web_app | 
| OLD | NEW | 
|---|