Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(31)

Side by Side Diff: chrome/browser/web_applications/web_app.cc

Issue 777543002: Create hosted app shims on Mac. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addressed further comments and refactored code Created 6 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/files/file_util.h" 9 #include "base/files/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"
15 #include "chrome/browser/extensions/extension_ui_util.h" 16 #include "chrome/browser/extensions/extension_ui_util.h"
16 #include "chrome/browser/profiles/profile.h" 17 #include "chrome/browser/profiles/profile.h"
18 #include "chrome/browser/profiles/profile_manager.h"
17 #include "chrome/common/chrome_constants.h" 19 #include "chrome/common/chrome_constants.h"
18 #include "chrome/common/chrome_version_info.h" 20 #include "chrome/common/chrome_version_info.h"
19 #include "chrome/common/extensions/manifest_handlers/app_launch_info.h" 21 #include "chrome/common/extensions/manifest_handlers/app_launch_info.h"
20 #include "chrome/common/pref_names.h" 22 #include "chrome/common/pref_names.h"
21 #include "content/public/browser/browser_thread.h" 23 #include "content/public/browser/browser_thread.h"
22 #include "extensions/browser/extension_registry.h" 24 #include "extensions/browser/extension_registry.h"
23 #include "extensions/browser/image_loader.h" 25 #include "extensions/browser/image_loader.h"
24 #include "extensions/common/constants.h" 26 #include "extensions/common/constants.h"
25 #include "extensions/common/extension.h" 27 #include "extensions/common/extension.h"
26 #include "extensions/common/extension_set.h" 28 #include "extensions/common/extension_set.h"
(...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after
261 263
262 void GetShortcutInfoForApp(const extensions::Extension* extension, 264 void GetShortcutInfoForApp(const extensions::Extension* extension,
263 Profile* profile, 265 Profile* profile,
264 const ShortcutInfoCallback& callback) { 266 const ShortcutInfoCallback& callback) {
265 GetInfoForApp( 267 GetInfoForApp(
266 extension, profile, base::Bind(&IgnoreFileHandlersInfo, callback)); 268 extension, profile, base::Bind(&IgnoreFileHandlersInfo, callback));
267 } 269 }
268 270
269 bool ShouldCreateShortcutFor(Profile* profile, 271 bool ShouldCreateShortcutFor(Profile* profile,
270 const extensions::Extension* extension) { 272 const extensions::Extension* extension) {
271 return extension->is_platform_app() && 273 bool platform_app = extension->is_platform_app();
272 extension->location() != extensions::Manifest::COMPONENT && 274 #if defined(OS_MACOSX)
273 extensions::ui_util::CanDisplayInAppLauncher(extension, profile); 275 platform_app = platform_app || extension->is_hosted_app();
calamity 2014/12/05 02:22:21 Drive-by nit: If this is the mac-needs-shims-alway
mitchellj 2014/12/05 05:07:48 Done.
276 #endif
277
278 return (platform_app &&
279 extension->location() != extensions::Manifest::COMPONENT &&
280 extensions::ui_util::CanDisplayInAppLauncher(extension, profile));
274 } 281 }
275 282
276 base::FilePath GetWebAppDataDirectory(const base::FilePath& profile_path, 283 base::FilePath GetWebAppDataDirectory(const base::FilePath& profile_path,
277 const std::string& extension_id, 284 const std::string& extension_id,
278 const GURL& url) { 285 const GURL& url) {
279 DCHECK(!profile_path.empty()); 286 DCHECK(!profile_path.empty());
280 base::FilePath app_data_dir(profile_path.Append(chrome::kWebAppDirname)); 287 base::FilePath app_data_dir(profile_path.Append(chrome::kWebAppDirname));
281 288
282 if (!extension_id.empty()) { 289 if (!extension_id.empty()) {
283 return app_data_dir.AppendASCII( 290 return app_data_dir.AppendASCII(
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
336 return app_name.substr(prefix.length()); 343 return app_name.substr(prefix.length());
337 } 344 }
338 345
339 void CreateShortcutsWithInfo( 346 void CreateShortcutsWithInfo(
340 ShortcutCreationReason reason, 347 ShortcutCreationReason reason,
341 const ShortcutLocations& locations, 348 const ShortcutLocations& locations,
342 const ShortcutInfo& shortcut_info, 349 const ShortcutInfo& shortcut_info,
343 const extensions::FileHandlersInfo& file_handlers_info) { 350 const extensions::FileHandlersInfo& file_handlers_info) {
344 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 351 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
345 352
353 // It's possible for the extension to be deleted before we get here.
354 // For example, creating a hosted app from a website. Double check that
355 // it still exists.
356 Profile* profile = g_browser_process->profile_manager()->GetProfileByPath(
357 shortcut_info.profile_path);
358 if (!profile)
359 return;
360
361 extensions::ExtensionRegistry* registry =
362 extensions::ExtensionRegistry::Get(profile);
363 const extensions::Extension* extension = registry->GetExtensionById(
364 shortcut_info.extension_id, extensions::ExtensionRegistry::ENABLED);
365 if (!extension)
366 return;
367
346 BrowserThread::PostTask( 368 BrowserThread::PostTask(
347 BrowserThread::FILE, 369 BrowserThread::FILE,
348 FROM_HERE, 370 FROM_HERE,
349 base::Bind(base::IgnoreResult(&internals::CreatePlatformShortcuts), 371 base::Bind(base::IgnoreResult(&internals::CreatePlatformShortcuts),
350 GetShortcutDataDir(shortcut_info), 372 GetShortcutDataDir(shortcut_info),
351 shortcut_info, 373 shortcut_info,
352 file_handlers_info, 374 file_handlers_info,
353 locations, 375 locations,
354 reason)); 376 reason));
355 } 377 }
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
426 448
427 #if defined(OS_LINUX) 449 #if defined(OS_LINUX)
428 std::string GetWMClassFromAppName(std::string app_name) { 450 std::string GetWMClassFromAppName(std::string app_name) {
429 base::i18n::ReplaceIllegalCharactersInPath(&app_name, '_'); 451 base::i18n::ReplaceIllegalCharactersInPath(&app_name, '_');
430 base::TrimString(app_name, "_", &app_name); 452 base::TrimString(app_name, "_", &app_name);
431 return app_name; 453 return app_name;
432 } 454 }
433 #endif 455 #endif
434 456
435 } // namespace web_app 457 } // namespace web_app
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698