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 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
61 #endif | 61 #endif |
62 | 62 |
63 #if defined(TOOLKIT_VIEWS) | 63 #if defined(TOOLKIT_VIEWS) |
64 // Predicator for sorting images from largest to smallest. | 64 // Predicator for sorting images from largest to smallest. |
65 bool IconPrecedes(const WebApplicationInfo::IconInfo& left, | 65 bool IconPrecedes(const WebApplicationInfo::IconInfo& left, |
66 const WebApplicationInfo::IconInfo& right) { | 66 const WebApplicationInfo::IconInfo& right) { |
67 return left.width < right.width; | 67 return left.width < right.width; |
68 } | 68 } |
69 #endif | 69 #endif |
70 | 70 |
71 bool CreateShortcutsWithInfoOnFileThread( | 71 base::FilePath GetShortcutDataDir(const web_app::ShortcutInfo& shortcut_info) { |
72 web_app::ShortcutCreationReason reason, | 72 return web_app::GetWebAppDataDirectory(shortcut_info.profile_path, |
73 const web_app::ShortcutLocations& locations, | 73 shortcut_info.extension_id, |
74 const web_app::ShortcutInfo& shortcut_info, | 74 shortcut_info.url); |
75 const extensions::FileHandlersInfo& file_handlers_info) { | |
76 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); | |
77 | |
78 base::FilePath shortcut_data_dir = | |
79 web_app::GetWebAppDataDirectory(shortcut_info.profile_path, | |
80 shortcut_info.extension_id, | |
81 shortcut_info.url); | |
82 return web_app::internals::CreatePlatformShortcuts( | |
83 shortcut_data_dir, shortcut_info, file_handlers_info, locations, reason); | |
84 } | |
85 | |
86 void DeleteShortcutsOnFileThread( | |
87 const web_app::ShortcutInfo& shortcut_info) { | |
88 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); | |
89 | |
90 base::FilePath shortcut_data_dir = web_app::GetWebAppDataDirectory( | |
91 shortcut_info.profile_path, shortcut_info.extension_id, GURL()); | |
92 return web_app::internals::DeletePlatformShortcuts( | |
93 shortcut_data_dir, shortcut_info); | |
94 } | |
95 | |
96 void UpdateShortcutsOnFileThread( | |
97 const base::string16& old_app_title, | |
98 const web_app::ShortcutInfo& shortcut_info, | |
99 const extensions::FileHandlersInfo& file_handlers_info) { | |
100 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); | |
101 | |
102 base::FilePath shortcut_data_dir = web_app::GetWebAppDataDirectory( | |
103 shortcut_info.profile_path, shortcut_info.extension_id, GURL()); | |
104 return web_app::internals::UpdatePlatformShortcuts( | |
105 shortcut_data_dir, old_app_title, shortcut_info, file_handlers_info); | |
106 } | 75 } |
107 | 76 |
108 void CreateShortcutsWithInfo( | 77 void CreateShortcutsWithInfo( |
109 web_app::ShortcutCreationReason reason, | 78 web_app::ShortcutCreationReason reason, |
110 const web_app::ShortcutLocations& locations, | 79 const web_app::ShortcutLocations& locations, |
111 const web_app::ShortcutInfo& shortcut_info, | 80 const web_app::ShortcutInfo& shortcut_info, |
112 const extensions::FileHandlersInfo& file_handlers_info) { | 81 const extensions::FileHandlersInfo& file_handlers_info) { |
113 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 82 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
114 | 83 |
115 BrowserThread::PostTask( | 84 BrowserThread::PostTask( |
116 BrowserThread::FILE, | 85 BrowserThread::FILE, |
117 FROM_HERE, | 86 FROM_HERE, |
118 base::Bind( | 87 base::Bind( |
119 base::IgnoreResult(&CreateShortcutsWithInfoOnFileThread), | 88 base::IgnoreResult(&web_app::internals::CreatePlatformShortcuts), |
120 reason, locations, shortcut_info, file_handlers_info)); | 89 GetShortcutDataDir(shortcut_info), |
| 90 shortcut_info, file_handlers_info, locations, reason)); |
121 } | 91 } |
122 | 92 |
123 void UpdateAllShortcutsForShortcutInfo( | 93 void UpdateAllShortcutsForShortcutInfo( |
124 const base::string16& old_app_title, | 94 const base::string16& old_app_title, |
125 const web_app::ShortcutInfo& shortcut_info, | 95 const web_app::ShortcutInfo& shortcut_info, |
126 const extensions::FileHandlersInfo& file_handlers_info) { | 96 const extensions::FileHandlersInfo& file_handlers_info) { |
127 BrowserThread::PostTask( | 97 BrowserThread::PostTask( |
128 BrowserThread::FILE, | 98 BrowserThread::FILE, |
129 FROM_HERE, | 99 FROM_HERE, |
130 base::Bind(&UpdateShortcutsOnFileThread, | 100 base::Bind(&web_app::internals::UpdatePlatformShortcuts, |
| 101 GetShortcutDataDir(shortcut_info), |
131 old_app_title, shortcut_info, file_handlers_info)); | 102 old_app_title, shortcut_info, file_handlers_info)); |
132 } | 103 } |
133 | 104 |
134 void OnImageLoaded(web_app::ShortcutInfo shortcut_info, | 105 void OnImageLoaded(web_app::ShortcutInfo shortcut_info, |
135 extensions::FileHandlersInfo file_handlers_info, | 106 extensions::FileHandlersInfo file_handlers_info, |
136 InfoCallback callback, | 107 InfoCallback callback, |
137 const gfx::ImageFamily& image_family) { | 108 const gfx::ImageFamily& image_family) { |
138 // If the image failed to load (e.g. if the resource being loaded was empty) | 109 // If the image failed to load (e.g. if the resource being loaded was empty) |
139 // use the standard application icon. | 110 // use the standard application icon. |
140 if (image_family.empty()) { | 111 if (image_family.empty()) { |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
240 #endif | 211 #endif |
241 file_util::ReplaceIllegalCharactersInPath(&file_name, '_'); | 212 file_util::ReplaceIllegalCharactersInPath(&file_name, '_'); |
242 return base::FilePath(file_name); | 213 return base::FilePath(file_name); |
243 } | 214 } |
244 | 215 |
245 bool CreateShortcutsOnFileThread(ShortcutCreationReason reason, | 216 bool CreateShortcutsOnFileThread(ShortcutCreationReason reason, |
246 const ShortcutLocations& locations, | 217 const ShortcutLocations& locations, |
247 const ShortcutInfo& shortcut_info) { | 218 const ShortcutInfo& shortcut_info) { |
248 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); | 219 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
249 | 220 |
250 return CreateShortcutsWithInfoOnFileThread( | 221 return CreatePlatformShortcuts( |
251 reason, locations, shortcut_info, extensions::FileHandlersInfo()); | 222 GetShortcutDataDir(shortcut_info), |
| 223 shortcut_info, extensions::FileHandlersInfo(), locations, reason); |
252 } | 224 } |
253 | 225 |
254 } // namespace internals | 226 } // namespace internals |
255 | 227 |
256 ShortcutInfo::ShortcutInfo() | 228 ShortcutInfo::ShortcutInfo() |
257 : is_platform_app(false) { | 229 : is_platform_app(false) { |
258 } | 230 } |
259 | 231 |
260 ShortcutInfo::~ShortcutInfo() {} | 232 ShortcutInfo::~ShortcutInfo() {} |
261 | 233 |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
349 | 321 |
350 base::FilePath GetWebAppDataDirectory(const base::FilePath& profile_path, | 322 base::FilePath GetWebAppDataDirectory(const base::FilePath& profile_path, |
351 const extensions::Extension& extension) { | 323 const extensions::Extension& extension) { |
352 return GetWebAppDataDirectory( | 324 return GetWebAppDataDirectory( |
353 profile_path, | 325 profile_path, |
354 extension.id(), | 326 extension.id(), |
355 GURL(extensions::AppLaunchInfo::GetLaunchWebURL(&extension))); | 327 GURL(extensions::AppLaunchInfo::GetLaunchWebURL(&extension))); |
356 } | 328 } |
357 | 329 |
358 std::string GenerateApplicationNameFromInfo(const ShortcutInfo& shortcut_info) { | 330 std::string GenerateApplicationNameFromInfo(const ShortcutInfo& shortcut_info) { |
359 if (!shortcut_info.extension_id.empty()) { | 331 if (!shortcut_info.extension_id.empty()) |
360 return GenerateApplicationNameFromExtensionId(shortcut_info.extension_id); | 332 return GenerateApplicationNameFromExtensionId(shortcut_info.extension_id); |
361 } else { | 333 else |
362 return GenerateApplicationNameFromURL(shortcut_info.url); | 334 return GenerateApplicationNameFromURL(shortcut_info.url); |
363 } | |
364 } | 335 } |
365 | 336 |
366 std::string GenerateApplicationNameFromURL(const GURL& url) { | 337 std::string GenerateApplicationNameFromURL(const GURL& url) { |
367 std::string t; | 338 std::string t; |
368 t.append(url.host()); | 339 t.append(url.host()); |
369 t.append("_"); | 340 t.append("_"); |
370 t.append(url.path()); | 341 t.append(url.path()); |
371 return t; | 342 return t; |
372 } | 343 } |
373 | 344 |
(...skipping 30 matching lines...) Expand all Loading... |
404 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 375 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
405 | 376 |
406 GetInfoForApp(app, | 377 GetInfoForApp(app, |
407 profile, | 378 profile, |
408 base::Bind(&CreateShortcutsWithInfo, reason, locations)); | 379 base::Bind(&CreateShortcutsWithInfo, reason, locations)); |
409 } | 380 } |
410 | 381 |
411 void DeleteAllShortcuts(Profile* profile, const extensions::Extension* app) { | 382 void DeleteAllShortcuts(Profile* profile, const extensions::Extension* app) { |
412 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 383 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
413 | 384 |
| 385 ShortcutInfo shortcut_info = |
| 386 ShortcutInfoForExtensionAndProfile(app, profile); |
414 BrowserThread::PostTask( | 387 BrowserThread::PostTask( |
415 BrowserThread::FILE, | 388 BrowserThread::FILE, |
416 FROM_HERE, | 389 FROM_HERE, |
417 base::Bind(&DeleteShortcutsOnFileThread, | 390 base::Bind(&web_app::internals::DeletePlatformShortcuts, |
418 ShortcutInfoForExtensionAndProfile(app, profile))); | 391 GetShortcutDataDir(shortcut_info), shortcut_info)); |
419 } | 392 } |
420 | 393 |
421 void UpdateAllShortcuts(const base::string16& old_app_title, | 394 void UpdateAllShortcuts(const base::string16& old_app_title, |
422 Profile* profile, | 395 Profile* profile, |
423 const extensions::Extension* app) { | 396 const extensions::Extension* app) { |
424 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 397 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
425 | 398 |
426 GetInfoForApp(app, | 399 GetInfoForApp(app, |
427 profile, | 400 profile, |
428 base::Bind(&UpdateAllShortcutsForShortcutInfo, old_app_title)); | 401 base::Bind(&UpdateAllShortcutsForShortcutInfo, old_app_title)); |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
465 | 438 |
466 #if defined(OS_LINUX) | 439 #if defined(OS_LINUX) |
467 std::string GetWMClassFromAppName(std::string app_name) { | 440 std::string GetWMClassFromAppName(std::string app_name) { |
468 file_util::ReplaceIllegalCharactersInPath(&app_name, '_'); | 441 file_util::ReplaceIllegalCharactersInPath(&app_name, '_'); |
469 base::TrimString(app_name, "_", &app_name); | 442 base::TrimString(app_name, "_", &app_name); |
470 return app_name; | 443 return app_name; |
471 } | 444 } |
472 #endif | 445 #endif |
473 | 446 |
474 } // namespace web_app | 447 } // namespace web_app |
OLD | NEW |