Chromium Code Reviews| 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" |
| 11 #include "base/prefs/pref_service.h" | 11 #include "base/prefs/pref_service.h" |
| 12 #include "base/strings/string_util.h" | 12 #include "base/strings/string_util.h" |
| 13 #include "base/strings/utf_string_conversions.h" | 13 #include "base/strings/utf_string_conversions.h" |
| 14 #include "base/threading/thread.h" | 14 #include "base/threading/thread.h" |
| 15 #include "chrome/browser/browser_process.h" | |
| 16 #include "chrome/browser/extensions/extension_service.h" | |
| 17 #include "chrome/browser/extensions/extension_ui_util.h" | |
| 15 #include "chrome/browser/extensions/image_loader.h" | 18 #include "chrome/browser/extensions/image_loader.h" |
| 16 #include "chrome/browser/extensions/tab_helper.h" | 19 #include "chrome/browser/extensions/tab_helper.h" |
| 17 #include "chrome/browser/favicon/favicon_tab_helper.h" | 20 #include "chrome/browser/favicon/favicon_tab_helper.h" |
| 18 #include "chrome/browser/profiles/profile.h" | 21 #include "chrome/browser/profiles/profile.h" |
| 22 #include "chrome/browser/profiles/profile_manager.h" | |
| 19 #include "chrome/common/chrome_constants.h" | 23 #include "chrome/common/chrome_constants.h" |
| 20 #include "chrome/common/chrome_version_info.h" | 24 #include "chrome/common/chrome_version_info.h" |
| 21 #include "chrome/common/extensions/manifest_handlers/app_launch_info.h" | 25 #include "chrome/common/extensions/manifest_handlers/app_launch_info.h" |
| 22 #include "chrome/common/pref_names.h" | 26 #include "chrome/common/pref_names.h" |
| 23 #include "chrome/common/url_constants.h" | 27 #include "chrome/common/url_constants.h" |
| 24 #include "content/public/browser/browser_thread.h" | 28 #include "content/public/browser/browser_thread.h" |
| 29 #include "extensions/browser/extension_registry.h" | |
| 30 #include "extensions/browser/extension_system.h" | |
| 25 #include "extensions/common/constants.h" | 31 #include "extensions/common/constants.h" |
| 26 #include "extensions/common/extension.h" | 32 #include "extensions/common/extension.h" |
| 33 #include "extensions/common/extension_set.h" | |
| 27 #include "extensions/common/manifest_handlers/icons_handler.h" | 34 #include "extensions/common/manifest_handlers/icons_handler.h" |
| 28 #include "grit/theme_resources.h" | 35 #include "grit/theme_resources.h" |
| 29 #include "skia/ext/image_operations.h" | 36 #include "skia/ext/image_operations.h" |
| 30 #include "third_party/skia/include/core/SkBitmap.h" | 37 #include "third_party/skia/include/core/SkBitmap.h" |
| 31 #include "ui/base/resource/resource_bundle.h" | 38 #include "ui/base/resource/resource_bundle.h" |
| 32 #include "ui/gfx/image/image.h" | 39 #include "ui/gfx/image/image.h" |
| 33 #include "ui/gfx/image/image_family.h" | 40 #include "ui/gfx/image/image_family.h" |
| 34 #include "ui/gfx/image/image_skia.h" | 41 #include "ui/gfx/image/image_skia.h" |
| 35 | 42 |
| 36 #if defined(OS_WIN) | 43 #if defined(OS_WIN) |
| (...skipping 30 matching lines...) Expand all Loading... | |
| 67 return left.width < right.width; | 74 return left.width < right.width; |
| 68 } | 75 } |
| 69 #endif | 76 #endif |
| 70 | 77 |
| 71 base::FilePath GetShortcutDataDir(const web_app::ShortcutInfo& shortcut_info) { | 78 base::FilePath GetShortcutDataDir(const web_app::ShortcutInfo& shortcut_info) { |
| 72 return web_app::GetWebAppDataDirectory(shortcut_info.profile_path, | 79 return web_app::GetWebAppDataDirectory(shortcut_info.profile_path, |
| 73 shortcut_info.extension_id, | 80 shortcut_info.extension_id, |
| 74 shortcut_info.url); | 81 shortcut_info.url); |
| 75 } | 82 } |
| 76 | 83 |
| 84 bool ShouldCreateShortcutFor(Profile* profile, | |
| 85 const extensions::Extension* extension) { | |
| 86 return extension->is_platform_app() && | |
| 87 extension->location() != extensions::Manifest::COMPONENT && | |
| 88 extensions::ui_util::ShouldDisplayInAppLauncher(extension, profile); | |
| 89 } | |
| 90 | |
| 77 void CreateShortcutsWithInfo( | 91 void CreateShortcutsWithInfo( |
| 78 web_app::ShortcutCreationReason reason, | 92 web_app::ShortcutCreationReason reason, |
| 79 const web_app::ShortcutLocations& locations, | 93 const web_app::ShortcutLocations& locations, |
| 80 const web_app::ShortcutInfo& shortcut_info, | 94 const web_app::ShortcutInfo& shortcut_info, |
| 81 const extensions::FileHandlersInfo& file_handlers_info) { | 95 const extensions::FileHandlersInfo& file_handlers_info) { |
| 82 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 96 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 83 | 97 |
| 84 BrowserThread::PostTask( | 98 BrowserThread::PostTask( |
| 85 BrowserThread::FILE, | 99 BrowserThread::FILE, |
| 86 FROM_HERE, | 100 FROM_HERE, |
| (...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 196 // The following string is used to build the directory name for | 210 // The following string is used to build the directory name for |
| 197 // shortcuts to chrome applications (the kind which are installed | 211 // shortcuts to chrome applications (the kind which are installed |
| 198 // from a CRX). Application shortcuts to URLs use the {host}_{path} | 212 // from a CRX). Application shortcuts to URLs use the {host}_{path} |
| 199 // for the name of this directory. Hosts can't include an underscore. | 213 // for the name of this directory. Hosts can't include an underscore. |
| 200 // By starting this string with an underscore, we ensure that there | 214 // By starting this string with an underscore, we ensure that there |
| 201 // are no naming conflicts. | 215 // are no naming conflicts. |
| 202 static const char* kCrxAppPrefix = "_crx_"; | 216 static const char* kCrxAppPrefix = "_crx_"; |
| 203 | 217 |
| 204 namespace internals { | 218 namespace internals { |
| 205 | 219 |
| 220 void CallForProfileAndAppId( | |
| 221 const base::FilePath& profile_path, | |
| 222 const std::string app_id, | |
| 223 const ShortcutOperationCallback& callback) { | |
| 224 ProfileManager* profile_manager = g_browser_process->profile_manager(); | |
| 225 Profile* profile = profile_manager->GetProfileByPath(profile_path); | |
| 226 if (!profile || !profile_manager->IsValidProfile(profile)) | |
| 227 return; | |
| 228 | |
| 229 extensions::ExtensionRegistry* registry = | |
| 230 extensions::ExtensionRegistry::Get(profile); | |
| 231 const extensions::Extension* extension = registry->GetExtensionById( | |
| 232 app_id, extensions::ExtensionRegistry::ENABLED); | |
|
calamity
2014/05/29 03:03:10
Shouldn't we be excluding disabled/terminated exte
jackhou1
2014/05/29 04:23:47
I take it you mean including. UpdateShortcutsForAl
| |
| 233 if (!extension || !extension->is_platform_app()) | |
| 234 return; | |
| 235 | |
| 236 callback.Run(profile, extension); | |
| 237 } | |
| 238 | |
| 206 base::FilePath GetSanitizedFileName(const base::string16& name) { | 239 base::FilePath GetSanitizedFileName(const base::string16& name) { |
| 207 #if defined(OS_WIN) | 240 #if defined(OS_WIN) |
| 208 base::string16 file_name = name; | 241 base::string16 file_name = name; |
| 209 #else | 242 #else |
| 210 std::string file_name = base::UTF16ToUTF8(name); | 243 std::string file_name = base::UTF16ToUTF8(name); |
| 211 #endif | 244 #endif |
| 212 file_util::ReplaceIllegalCharactersInPath(&file_name, '_'); | 245 file_util::ReplaceIllegalCharactersInPath(&file_name, '_'); |
| 213 return base::FilePath(file_name); | 246 return base::FilePath(file_name); |
| 214 } | 247 } |
| 215 | 248 |
| (...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 367 base::IgnoreResult(&web_app::internals::CreateShortcutsOnFileThread), | 400 base::IgnoreResult(&web_app::internals::CreateShortcutsOnFileThread), |
| 368 reason, locations, shortcut_info)); | 401 reason, locations, shortcut_info)); |
| 369 } | 402 } |
| 370 | 403 |
| 371 void CreateShortcuts(ShortcutCreationReason reason, | 404 void CreateShortcuts(ShortcutCreationReason reason, |
| 372 const ShortcutLocations& locations, | 405 const ShortcutLocations& locations, |
| 373 Profile* profile, | 406 Profile* profile, |
| 374 const extensions::Extension* app) { | 407 const extensions::Extension* app) { |
| 375 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 408 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 376 | 409 |
| 410 if (!ShouldCreateShortcutFor(profile, app)) | |
| 411 return; | |
| 412 | |
| 377 GetInfoForApp(app, | 413 GetInfoForApp(app, |
| 378 profile, | 414 profile, |
| 379 base::Bind(&CreateShortcutsWithInfo, reason, locations)); | 415 base::Bind(&CreateShortcutsWithInfo, reason, locations)); |
| 380 } | 416 } |
| 381 | 417 |
| 382 void DeleteAllShortcuts(Profile* profile, const extensions::Extension* app) { | 418 void DeleteAllShortcuts(Profile* profile, const extensions::Extension* app) { |
| 383 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 419 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 384 | 420 |
| 385 ShortcutInfo shortcut_info = | 421 ShortcutInfo shortcut_info = |
| 386 ShortcutInfoForExtensionAndProfile(app, profile); | 422 ShortcutInfoForExtensionAndProfile(app, profile); |
| 387 BrowserThread::PostTask( | 423 BrowserThread::PostTask( |
| 388 BrowserThread::FILE, | 424 BrowserThread::FILE, |
| 389 FROM_HERE, | 425 FROM_HERE, |
| 390 base::Bind(&web_app::internals::DeletePlatformShortcuts, | 426 base::Bind(&web_app::internals::DeletePlatformShortcuts, |
| 391 GetShortcutDataDir(shortcut_info), shortcut_info)); | 427 GetShortcutDataDir(shortcut_info), shortcut_info)); |
| 392 } | 428 } |
| 393 | 429 |
| 394 void UpdateAllShortcuts(const base::string16& old_app_title, | 430 void UpdateAllShortcuts(const base::string16& old_app_title, |
| 395 Profile* profile, | 431 Profile* profile, |
| 396 const extensions::Extension* app) { | 432 const extensions::Extension* app) { |
| 397 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 433 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 398 | 434 |
| 399 GetInfoForApp(app, | 435 GetInfoForApp(app, |
| 400 profile, | 436 profile, |
| 401 base::Bind(&UpdateAllShortcutsForShortcutInfo, old_app_title)); | 437 base::Bind(&UpdateAllShortcutsForShortcutInfo, old_app_title)); |
| 402 } | 438 } |
| 403 | 439 |
| 440 void UpdateShortcutsForAllApps(Profile* profile) { | |
| 441 // Check if extension system/service are available. They might not be in | |
| 442 // tests. | |
| 443 extensions::ExtensionSystem* extension_system = | |
| 444 extensions::ExtensionSystem::Get(profile); | |
| 445 if (!extension_system) | |
| 446 return; | |
| 447 | |
| 448 ExtensionServiceInterface* extension_service = | |
| 449 extension_system->extension_service(); | |
| 450 if (!extension_service) | |
| 451 return; | |
| 452 | |
| 453 // Get a set of app ids. | |
| 454 const extensions::ExtensionSet* apps = extension_service->extensions(); | |
| 455 std::set<std::string> app_ids; | |
| 456 for (extensions::ExtensionSet::const_iterator it = apps->begin(); | |
| 457 it != apps->end(); ++it) { | |
| 458 if (ShouldCreateShortcutFor(profile, it->get())) | |
| 459 app_ids.insert((*it)->id()); | |
| 460 } | |
| 461 | |
| 462 BrowserThread::PostTask( | |
| 463 BrowserThread::FILE, | |
|
tapted
2014/05/29 08:56:40
I couldn't see why this needed to be on the file t
| |
| 464 FROM_HERE, | |
| 465 base::Bind( | |
| 466 &web_app::internals::UpdateShortcutsForAllAppsForProfile, | |
| 467 profile->GetPath(), app_ids)); | |
| 468 } | |
| 469 | |
| 404 bool IsValidUrl(const GURL& url) { | 470 bool IsValidUrl(const GURL& url) { |
| 405 static const char* const kValidUrlSchemes[] = { | 471 static const char* const kValidUrlSchemes[] = { |
| 406 content::kFileScheme, | 472 content::kFileScheme, |
| 407 content::kFileSystemScheme, | 473 content::kFileSystemScheme, |
| 408 content::kFtpScheme, | 474 content::kFtpScheme, |
| 409 url::kHttpScheme, | 475 url::kHttpScheme, |
| 410 url::kHttpsScheme, | 476 url::kHttpsScheme, |
| 411 extensions::kExtensionScheme, | 477 extensions::kExtensionScheme, |
| 412 }; | 478 }; |
| 413 | 479 |
| (...skipping 24 matching lines...) Expand all Loading... | |
| 438 | 504 |
| 439 #if defined(OS_LINUX) | 505 #if defined(OS_LINUX) |
| 440 std::string GetWMClassFromAppName(std::string app_name) { | 506 std::string GetWMClassFromAppName(std::string app_name) { |
| 441 file_util::ReplaceIllegalCharactersInPath(&app_name, '_'); | 507 file_util::ReplaceIllegalCharactersInPath(&app_name, '_'); |
| 442 base::TrimString(app_name, "_", &app_name); | 508 base::TrimString(app_name, "_", &app_name); |
| 443 return app_name; | 509 return app_name; |
| 444 } | 510 } |
| 445 #endif | 511 #endif |
| 446 | 512 |
| 447 } // namespace web_app | 513 } // namespace web_app |
| OLD | NEW |