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_COMMON_EXTENSIONS_MANIFEST_URL_HANDLER_H_
6#define CHROME_COMMON_EXTENSIONS_MANIFEST_URL_HANDLER_H_
7
8#include <string>
9
10#include "extensions/common/extension.h"
11#include "extensions/common/manifest_handler.h"
12
13namespace base {
14class DictionaryValue;
15}
16
17namespace extensions {
18
19// A structure to hold various URLs like devtools_page, homepage_url, etc
20// that may be specified in the manifest of an extension.
21struct ManifestURL : public Extension::ManifestData {
22  GURL url_;
23
24  // Returns the DevTools Page for this extension.
25  static const GURL& GetDevToolsPage(const Extension* extension);
26
27  // Returns the Homepage URL for this extension.
28  // If homepage_url was not specified in the manifest,
29  // this returns the Google Gallery URL. For third-party extensions,
30  // this returns a blank GURL.
31  static const GURL GetHomepageURL(const Extension* extension);
32
33  // Returns the Update URL for this extension.
34  static const GURL& GetUpdateURL(const Extension* extension);
35
36  // Returns true if this extension's update URL is the extension gallery.
37  static bool UpdatesFromGallery(const Extension* extension);
38  static bool UpdatesFromGallery(const base::DictionaryValue* manifest);
39
40  // Returns the Options Page for this extension.
41  static const GURL& GetOptionsPage(const Extension* extension);
42
43  // Returns the webstore page URL for this extension.
44  static const GURL GetDetailsURL(const Extension* extension);
45};
46
47// A structure to hold the chrome URL overrides that may be specified
48// in the manifest of an extension.
49struct URLOverrides : public Extension::ManifestData {
50  typedef std::map<const std::string, GURL> URLOverrideMap;
51
52  // Define out of line constructor/destructor to please Clang.
53  URLOverrides();
54  virtual ~URLOverrides();
55
56  static const URLOverrideMap&
57      GetChromeURLOverrides(const Extension* extension);
58
59  // A map of chrome:// hostnames (newtab, downloads, etc.) to Extension URLs
60  // which override the handling of those URLs. (see ExtensionOverrideUI).
61  URLOverrideMap chrome_url_overrides_;
62};
63
64// Parses the "devtools_page" manifest key.
65class DevToolsPageHandler : public ManifestHandler {
66 public:
67  DevToolsPageHandler();
68  virtual ~DevToolsPageHandler();
69
70  virtual bool Parse(Extension* extension, base::string16* error) OVERRIDE;
71
72 private:
73  virtual const std::vector<std::string> Keys() const OVERRIDE;
74
75  DISALLOW_COPY_AND_ASSIGN(DevToolsPageHandler);
76};
77
78// Parses the "homepage_url" manifest key.
79class HomepageURLHandler : public ManifestHandler {
80 public:
81  HomepageURLHandler();
82  virtual ~HomepageURLHandler();
83
84  virtual bool Parse(Extension* extension, base::string16* error) OVERRIDE;
85
86 private:
87  virtual const std::vector<std::string> Keys() const OVERRIDE;
88
89  DISALLOW_COPY_AND_ASSIGN(HomepageURLHandler);
90};
91
92// Parses the "update_url" manifest key.
93class UpdateURLHandler : public ManifestHandler {
94 public:
95  UpdateURLHandler();
96  virtual ~UpdateURLHandler();
97
98  virtual bool Parse(Extension* extension, base::string16* error) OVERRIDE;
99
100 private:
101  virtual const std::vector<std::string> Keys() const OVERRIDE;
102
103  DISALLOW_COPY_AND_ASSIGN(UpdateURLHandler);
104};
105
106// Parses the "options_page" manifest key.
107class OptionsPageHandler : public ManifestHandler {
108 public:
109  OptionsPageHandler();
110  virtual ~OptionsPageHandler();
111
112  virtual bool Parse(Extension* extension, base::string16* error) OVERRIDE;
113  virtual bool Validate(const Extension* extension,
114                        std::string* error,
115                        std::vector<InstallWarning>* warnings) const OVERRIDE;
116
117 private:
118  virtual const std::vector<std::string> Keys() const OVERRIDE;
119
120  DISALLOW_COPY_AND_ASSIGN(OptionsPageHandler);
121};
122
123// Parses the "chrome_url_overrides" manifest key.
124class URLOverridesHandler : public ManifestHandler {
125 public:
126  URLOverridesHandler();
127  virtual ~URLOverridesHandler();
128
129  virtual bool Parse(Extension* extension, base::string16* error) OVERRIDE;
130
131 private:
132  virtual const std::vector<std::string> Keys() const OVERRIDE;
133
134  DISALLOW_COPY_AND_ASSIGN(URLOverridesHandler);
135};
136
137}  // namespace extensions
138
139#endif  // CHROME_COMMON_EXTENSIONS_MANIFEST_URL_HANDLER_H_
140