Extract SIGPIPE ignoring code to a common place.
[chromium-blink-merge.git] / chrome / common / web_apps.h
blobb3ea03949e0778476052fa14484152d8709b9d33
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.
5 #ifndef CHROME_COMMON_WEB_APPS_H_
6 #define CHROME_COMMON_WEB_APPS_H_
8 #include <string>
9 #include <vector>
11 #include "base/string16.h"
12 #include "googleurl/src/gurl.h"
13 #include "third_party/skia/include/core/SkBitmap.h"
14 #include "ui/gfx/size.h"
16 namespace WebKit {
17 class WebDocument;
18 class WebFrame;
21 namespace base {
22 class Value;
25 // Structure used when installing a web page as an app.
26 struct WebApplicationInfo {
27 struct IconInfo {
28 GURL url;
29 int width;
30 int height;
31 SkBitmap data;
34 static const char kInvalidDefinitionURL[];
35 static const char kInvalidLaunchURL[];
36 static const char kInvalidURL[];
37 static const char kInvalidIconSize[];
38 static const char kInvalidIconURL[];
40 WebApplicationInfo();
41 ~WebApplicationInfo();
43 // URL to a manifest that defines the application. If specified, all other
44 // attributes are derived from this manifest, and the manifest is the unique
45 // ID of the application.
46 GURL manifest_url;
48 // Setting indicating this application is artificially constructed. If set,
49 // the application was created from bookmark-style data (title, url, possibly
50 // icon), and not from an official manifest file. In that case, the app_url
51 // can be checked for the later creation of an official manifest instead of
52 // reloading the manifest_url.
53 bool is_bookmark_app;
55 // Title of the application.
56 string16 title;
58 // Description of the application.
59 string16 description;
61 // The launch URL for the app.
62 GURL app_url;
64 // Set of available icons.
65 std::vector<IconInfo> icons;
67 // The permissions the app requests. Only supported with manifest-based apps.
68 std::vector<std::string> permissions;
70 // Set of URLs that comprise the app. Only supported with manifest-based apps.
71 // All these must be of the same origin as manifest_url.
72 std::vector<GURL> urls;
74 // The type of launch container to use with the app. Currently supported
75 // values are 'tab' and 'panel'. Only supported with manifest-based apps.
76 std::string launch_container;
78 // This indicates if the app is functional in offline mode or not.
79 bool is_offline_enabled;
83 namespace web_apps {
85 // Parses an icon size. An icon size must match the following regex:
86 // [1-9][0-9]*x[1-9][0-9]*.
87 // If the input couldn't be parsed, a size with a width/height == 0 is returned.
88 gfx::Size ParseIconSize(const string16& text);
90 // Parses the icon's size attribute as defined in the HTML 5 spec. Returns true
91 // on success, false on errors. On success either all the sizes specified in
92 // the attribute are added to sizes, or is_any is set to true.
94 // You shouldn't have a need to invoke this directly, it's public for testing.
95 bool ParseIconSizes(const string16& text, std::vector<gfx::Size>* sizes,
96 bool* is_any);
98 // Parses |web_app| information out of the document in frame. Returns true on
99 // success, or false and |error| on failure. Note that the document may contain
100 // no web application information, in which case |web_app| is unchanged and the
101 // function returns true.
103 // Documents can also contain a link to a application 'definition'. In this case
104 // web_app will have manifest_url set and nothing else. The caller must fetch
105 // this URL and pass the result to ParseWebAppFromDefinitionFile() for further
106 // processing.
107 bool ParseWebAppFromWebDocument(WebKit::WebFrame* frame,
108 WebApplicationInfo* web_app,
109 string16* error);
111 // Parses |web_app| information out of |definition|. Returns true on success, or
112 // false and |error| on failure. This function assumes that |web_app| has a
113 // valid manifest_url.
114 bool ParseWebAppFromDefinitionFile(base::Value* definition,
115 WebApplicationInfo* web_app,
116 string16* error);
118 } // namespace web_apps
120 #endif // CHROME_COMMON_WEB_APPS_H_