web_app.h revision 90dce4d38c5ff5333bea97d859d4e484e27edf0c
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#ifndef CHROME_BROWSER_WEB_APPLICATIONS_WEB_APP_H_ 6#define CHROME_BROWSER_WEB_APPLICATIONS_WEB_APP_H_ 7 8#include <string> 9#include <vector> 10 11#include "base/files/file_path.h" 12#include "base/string16.h" 13#include "build/build_config.h" 14#include "chrome/browser/shell_integration.h" 15#include "chrome/common/web_application_info.h" 16 17namespace extensions { 18class Extension; 19} 20 21namespace gfx { 22class ImageFamily; 23} 24 25namespace web_app { 26 27// Gets the user data directory for given web app. The path for the directory is 28// based on |extension_id|. If |extension_id| is empty then |url| is used 29// to construct a unique ID. 30base::FilePath GetWebAppDataDirectory(const base::FilePath& profile_path, 31 const std::string& extension_id, 32 const GURL& url); 33 34// Gets the user data directory to use for |extension| located inside 35// |profile_path|. 36base::FilePath GetWebAppDataDirectory(const base::FilePath& profile_path, 37 const extensions::Extension& extension); 38 39// Compute a deterministic name based on data in the shortcut_info. 40std::string GenerateApplicationNameFromInfo( 41 const ShellIntegration::ShortcutInfo& shortcut_info); 42 43// Compute a deterministic name based on the URL. We use this pseudo name 44// as a key to store window location per application URLs in Browser and 45// as app id for BrowserWindow, shortcut and jump list. 46std::string GenerateApplicationNameFromURL(const GURL& url); 47 48// Compute a deterministic name based on an extension/apps's id. 49std::string GenerateApplicationNameFromExtensionId(const std::string& id); 50 51// Extracts the extension id from the app name. 52std::string GetExtensionIdFromApplicationName(const std::string& app_name); 53 54// Creates shortcuts for web application based on given shortcut data. 55// |shortcut_info| contains information about the shortcuts to create, and 56// |creation_locations| contains information about where to create them. 57void CreateShortcuts( 58 const ShellIntegration::ShortcutInfo& shortcut_info, 59 const ShellIntegration::ShortcutLocations& creation_locations); 60 61// Delete all the shortcuts that have been created for the given 62// |shortcut_data| in the profile with |profile_path|. 63void DeleteAllShortcuts(const ShellIntegration::ShortcutInfo& shortcut_info); 64 65// Updates shortcuts for web application based on given shortcut data. This 66// refreshes existing shortcuts and their icons, but does not create new ones. 67// |old_app_title| contains the title of the app prior to this update. 68// |shortcut_info| contains information about the shortcuts to update. 69void UpdateAllShortcuts(const string16& old_app_title, 70 const ShellIntegration::ShortcutInfo& shortcut_info); 71 72// Creates a shortcut. Must be called on the file thread. This is used to 73// implement CreateShortcuts() above, and can also be used directly from the 74// file thread. |shortcut_info| contains info about the shortcut to create, and 75// |creation_locations| contains information about where to create them. 76bool CreateShortcutsOnFileThread( 77 const ShellIntegration::ShortcutInfo& shortcut_info, 78 const ShellIntegration::ShortcutLocations& creation_locations); 79 80// Returns true if given url is a valid web app url. 81bool IsValidUrl(const GURL& url); 82 83#if defined(TOOLKIT_VIEWS) 84// Extracts icons info from web app data. Take only square shaped icons and 85// sort them from smallest to largest. 86typedef std::vector<WebApplicationInfo::IconInfo> IconInfoList; 87void GetIconsInfo(const WebApplicationInfo& app_info, 88 IconInfoList* icons); 89#endif 90 91#if defined(TOOLKIT_GTK) 92// GTK+ windows that correspond to web apps need to have a deterministic (and 93// different) WMClass than normal chrome windows so the window manager groups 94// them as a separate application. 95std::string GetWMClassFromAppName(std::string app_name); 96#endif 97 98// Gets the name of the Chrome Apps menu folder in which to place app shortcuts. 99string16 GetAppShortcutsSubdirName(); 100 101namespace internals { 102 103#if defined(OS_WIN) 104bool CheckAndSaveIcon(const base::FilePath& icon_file, 105 const gfx::ImageFamily& image); 106 107std::vector<base::FilePath> GetShortcutPaths( 108 const ShellIntegration::ShortcutLocations& creation_locations); 109#endif 110 111// Implemented for each platform, does the platform specific parts of creating 112// shortcuts. Used internally by CreateShortcutsOnFileThread. 113// |shortcut_data_path| is where to store any resources created for the 114// shortcut, and is also used as the UserDataDir for platform app shortcuts. 115// |shortcut_info| contains info about the shortcut to create, and 116// |creation_locations| contains information about where to create them. 117bool CreatePlatformShortcuts( 118 const base::FilePath& shortcut_data_path, 119 const ShellIntegration::ShortcutInfo& shortcut_info, 120 const ShellIntegration::ShortcutLocations& creation_locations); 121 122// Delete all the shortcuts we have added for this extension. This is the 123// platform specific implementation of the DeleteAllShortcuts function, and 124// is executed on the FILE thread. 125void DeletePlatformShortcuts( 126 const base::FilePath& shortcut_data_path, 127 const ShellIntegration::ShortcutInfo& shortcut_info); 128 129// Updates all the shortcuts we have added for this extension. This is the 130// platform specific implementation of the UpdateAllShortcuts function, and 131// is executed on the FILE thread. 132void UpdatePlatformShortcuts( 133 const base::FilePath& shortcut_data_path, 134 const string16& old_app_title, 135 const ShellIntegration::ShortcutInfo& shortcut_info); 136 137// Sanitizes |name| and returns a version of it that is safe to use as an 138// on-disk file name . 139base::FilePath GetSanitizedFileName(const string16& name); 140 141} // namespace internals 142 143} // namespace web_app 144 145#endif // CHROME_BROWSER_WEB_APPLICATIONS_WEB_APP_H_ 146