1// Copyright (c) 2011 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#pragma once 8 9#include <vector> 10 11#include "base/callback.h" 12#include "base/file_path.h" 13#include "build/build_config.h" 14#include "chrome/browser/shell_integration.h" 15#include "chrome/common/web_apps.h" 16 17class Profile; 18 19namespace web_app { 20 21// Compute a deterministic name based on data in the shortcut_info. 22std::string GenerateApplicationNameFromInfo( 23 const ShellIntegration::ShortcutInfo& shortcut_info); 24 25// Compute a deterministic name based on the URL. We use this pseudo name 26// as a key to store window location per application URLs in Browser and 27// as app id for BrowserWindow, shortcut and jump list. 28std::string GenerateApplicationNameFromURL(const GURL& url); 29 30// Compute a deterministic name based on an extension/apps's id. 31std::string GenerateApplicationNameFromExtensionId(const std::string& id); 32 33// Callback after user dismisses CreateShortcutView. "true" indicates 34// shortcut is created successfully. Otherwise, it is false. 35typedef Callback1<bool>::Type CreateShortcutCallback; 36 37// Creates a shortcut for web application based on given shortcut data. 38// |profile_path| is used as root directory for persisted data such as icon. 39// Directory layout is similar to what Gears has, i.e. an web application's 40// file is stored under "#/host_name/scheme_port", where '#' is the 41// |root_dir|. A crx based app uses a directory named _crx_<app id>. 42void CreateShortcut( 43 const FilePath& profile_path, 44 const ShellIntegration::ShortcutInfo& shortcut_info, 45 CreateShortcutCallback* callback); 46 47// Returns true if given url is a valid web app url. 48bool IsValidUrl(const GURL& url); 49 50// Returns data dir for web apps for given profile path. 51FilePath GetDataDir(const FilePath& profile_path); 52 53#if defined(TOOLKIT_VIEWS) 54// Extracts icons info from web app data. Take only square shaped icons and 55// sort them from smallest to largest. 56typedef std::vector<WebApplicationInfo::IconInfo> IconInfoList; 57void GetIconsInfo(const WebApplicationInfo& app_info, 58 IconInfoList* icons); 59#endif 60 61#if defined(TOOLKIT_USES_GTK) 62// GTK+ windows that correspond to web apps need to have a deterministic (and 63// different) WMClass than normal chrome windows so the window manager groups 64// them as a separate application. 65std::string GetWMClassFromAppName(std::string app_name); 66#endif 67 68namespace internals { 69 70#if defined(OS_WIN) 71FilePath GetSanitizedFileName(const string16& name); 72 73bool CheckAndSaveIcon(const FilePath& icon_file, const SkBitmap& image); 74#endif 75 76FilePath GetWebAppDataDirectory(const FilePath& root_dir, 77 const ShellIntegration::ShortcutInfo& info); 78} // namespace internals 79 80} // namespace web_app 81 82#endif // CHROME_BROWSER_WEB_APPLICATIONS_WEB_APP_H_ 83