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