web_app.h revision 868fa2fe829687343ffae624259930155e16dbd8
10f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)// Copyright (c) 2012 The Chromium Authors. All rights reserved. 20f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be 30f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)// found in the LICENSE file. 40f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) 50f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)#ifndef CHROME_BROWSER_WEB_APPLICATIONS_WEB_APP_H_ 61320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci#define CHROME_BROWSER_WEB_APPLICATIONS_WEB_APP_H_ 70f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) 80f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)#include <string> 90f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)#include <vector> 100f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) 110f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)#include "base/files/file_path.h" 120f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)#include "base/strings/string16.h" 130f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)#include "build/build_config.h" 140f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)#include "chrome/browser/shell_integration.h" 150f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)#include "chrome/common/web_application_info.h" 160f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) 170f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)namespace extensions { 180f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)class Extension; 190f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)} 200f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) 21f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)namespace gfx { 22f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)class ImageFamily; 230f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)} 240f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) 250f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)namespace web_app { 260f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) 27f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)// Gets the user data directory for given web app. The path for the directory is 280f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)// 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