Home | History | Annotate | Download | only in common
      1 // Copyright (c) 2010 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_COMMON_WEB_APPS_H_
      6 #define CHROME_COMMON_WEB_APPS_H_
      7 #pragma once
      8 
      9 #include <string>
     10 #include <vector>
     11 
     12 #include "base/string16.h"
     13 #include "googleurl/src/gurl.h"
     14 #include "third_party/skia/include/core/SkBitmap.h"
     15 #include "ui/gfx/size.h"
     16 
     17 namespace WebKit {
     18 class WebDocument;
     19 class WebFrame;
     20 }
     21 
     22 class Value;
     23 
     24 // Structure used when installing a web page as an app.
     25 struct WebApplicationInfo {
     26   struct IconInfo {
     27     GURL url;
     28     int width;
     29     int height;
     30     SkBitmap data;
     31   };
     32 
     33   static const char kInvalidDefinitionURL[];
     34   static const char kInvalidLaunchURL[];
     35   static const char kInvalidURL[];
     36   static const char kInvalidIconSize[];
     37   static const char kInvalidIconURL[];
     38 
     39   WebApplicationInfo();
     40   ~WebApplicationInfo();
     41 
     42   // URL to a manifest that defines the application. If specified, all other
     43   // attributes are derived from this manifest, and the manifest is the unique
     44   // ID of the application.
     45   GURL manifest_url;
     46 
     47   // Title of the application.
     48   string16 title;
     49 
     50   // Description of the application.
     51   string16 description;
     52 
     53   // The launch URL for the app.
     54   GURL app_url;
     55 
     56   // Set of available icons.
     57   std::vector<IconInfo> icons;
     58 
     59   // The permissions the app requests. Only supported with manifest-based apps.
     60   std::vector<std::string> permissions;
     61 
     62   // Set of URLs that comprise the app. Only supported with manifest-based apps.
     63   // All these must be of the same origin as manifest_url.
     64   std::vector<GURL> urls;
     65 
     66   // The type of launch container to use with the app. Currently supported
     67   // values are 'tab' and 'panel'. Only supported with manifest-based apps.
     68   std::string launch_container;
     69 };
     70 
     71 
     72 namespace web_apps {
     73 
     74 // Parses an icon size. An icon size must match the following regex:
     75 // [1-9][0-9]*x[1-9][0-9]*.
     76 // If the input couldn't be parsed, a size with a width/height == 0 is returned.
     77 gfx::Size ParseIconSize(const string16& text);
     78 
     79 // Parses the icon's size attribute as defined in the HTML 5 spec. Returns true
     80 // on success, false on errors. On success either all the sizes specified in
     81 // the attribute are added to sizes, or is_any is set to true.
     82 //
     83 // You shouldn't have a need to invoke this directly, it's public for testing.
     84 bool ParseIconSizes(const string16& text, std::vector<gfx::Size>* sizes,
     85                     bool* is_any);
     86 
     87 // Parses |web_app| information out of the document in frame. Returns true on
     88 // success, or false and |error| on failure. Note that the document may contain
     89 // no web application information, in which case |web_app| is unchanged and the
     90 // function returns true.
     91 //
     92 // Documents can also contain a link to a application 'definition'. In this case
     93 // web_app will have manifest_url set and nothing else. The caller must fetch
     94 // this URL and pass the result to ParseWebAppFromDefinitionFile() for further
     95 // processing.
     96 bool ParseWebAppFromWebDocument(WebKit::WebFrame* frame,
     97                                 WebApplicationInfo* web_app,
     98                                 string16* error);
     99 
    100 // Parses |web_app| information out of |definition|. Returns true on success, or
    101 // false and |error| on failure. This function assumes that |web_app| has a
    102 // valid manifest_url.
    103 bool ParseWebAppFromDefinitionFile(Value* definition,
    104                                    WebApplicationInfo* web_app,
    105                                    string16* error);
    106 
    107 }  // namespace web_apps
    108 
    109 #endif  // CHROME_COMMON_WEB_APPS_H_
    110