Home | History | Annotate | Download | only in web_applications
      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
      3 // found in the LICENSE file.
      4 
      5 #include "chrome/browser/web_applications/web_app.h"
      6 
      7 #include "base/environment.h"
      8 #include "base/logging.h"
      9 #include "chrome/browser/shell_integration_linux.h"
     10 #include "content/public/browser/browser_thread.h"
     11 
     12 namespace web_app {
     13 
     14 void UpdateShortcutsForAllApps(Profile* profile,
     15                                const base::Closure& callback) {
     16   callback.Run();
     17 }
     18 
     19 namespace internals {
     20 
     21 bool CreatePlatformShortcuts(
     22     const base::FilePath& web_app_path,
     23     const ShortcutInfo& shortcut_info,
     24     const extensions::FileHandlersInfo& file_handlers_info,
     25     const ShortcutLocations& creation_locations,
     26     ShortcutCreationReason /*creation_reason*/) {
     27 #if !defined(OS_CHROMEOS)
     28   DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::FILE));
     29   return shell_integration_linux::CreateDesktopShortcut(
     30       shortcut_info, creation_locations);
     31 #else
     32   return false;
     33 #endif
     34 }
     35 
     36 void DeletePlatformShortcuts(const base::FilePath& web_app_path,
     37                              const ShortcutInfo& shortcut_info) {
     38 #if !defined(OS_CHROMEOS)
     39   shell_integration_linux::DeleteDesktopShortcuts(shortcut_info.profile_path,
     40       shortcut_info.extension_id);
     41 #endif
     42 }
     43 
     44 void UpdatePlatformShortcuts(
     45     const base::FilePath& web_app_path,
     46     const base::string16& /*old_app_title*/,
     47     const ShortcutInfo& shortcut_info,
     48     const extensions::FileHandlersInfo& file_handlers_info) {
     49   DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::FILE));
     50 
     51   scoped_ptr<base::Environment> env(base::Environment::Create());
     52 
     53   // Find out whether shortcuts are already installed.
     54   ShortcutLocations creation_locations =
     55       shell_integration_linux::GetExistingShortcutLocations(
     56           env.get(), shortcut_info.profile_path, shortcut_info.extension_id);
     57 
     58   // Always create a hidden shortcut in applications if a visible one is not
     59   // being created. This allows the operating system to identify the app, but
     60   // not show it in the menu.
     61   if (creation_locations.applications_menu_location == APP_MENU_LOCATION_NONE)
     62     creation_locations.applications_menu_location = APP_MENU_LOCATION_HIDDEN;
     63 
     64   CreatePlatformShortcuts(web_app_path,
     65                           shortcut_info,
     66                           file_handlers_info,
     67                           creation_locations,
     68                           SHORTCUT_CREATION_AUTOMATED);
     69 }
     70 
     71 void DeleteAllShortcutsForProfile(const base::FilePath& profile_path) {
     72 #if !defined(OS_CHROMEOS)
     73   shell_integration_linux::DeleteAllDesktopShortcuts(profile_path);
     74 #endif
     75 }
     76 
     77 }  // namespace internals
     78 
     79 }  // namespace web_app
     80