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_EXTENSIONS_MANIFEST_URL_HANDLER_H_
6 #define CHROME_COMMON_EXTENSIONS_MANIFEST_URL_HANDLER_H_
10 #include "extensions/common/extension.h"
11 #include "extensions/common/manifest_handler.h"
14 class DictionaryValue
;
17 namespace extensions
{
19 // A structure to hold various URLs like devtools_page, homepage_url, etc
20 // that may be specified in the manifest of an extension.
21 struct ManifestURL
: public Extension::ManifestData
{
24 // Returns the DevTools Page for this extension.
25 static const GURL
& GetDevToolsPage(const Extension
* extension
);
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
);
33 // Returns true if the extension specified a valid home page url in the
35 static bool SpecifiedHomepageURL(const Extension
* extension
);
37 // Returns the Update URL for this extension.
38 static const GURL
& GetUpdateURL(const Extension
* extension
);
40 // Returns true if this extension's update URL is the extension gallery.
41 static bool UpdatesFromGallery(const Extension
* extension
);
42 static bool UpdatesFromGallery(const base::DictionaryValue
* manifest
);
44 // Returns the About Page for this extension.
45 static const GURL
& GetAboutPage(const Extension
* extension
);
47 // Returns the webstore page URL for this extension.
48 static const GURL
GetDetailsURL(const Extension
* extension
);
51 // A structure to hold the chrome URL overrides that may be specified
52 // in the manifest of an extension.
53 struct URLOverrides
: public Extension::ManifestData
{
54 typedef std::map
<const std::string
, GURL
> URLOverrideMap
;
56 // Define out of line constructor/destructor to please Clang.
58 virtual ~URLOverrides();
60 static const URLOverrideMap
&
61 GetChromeURLOverrides(const Extension
* extension
);
63 // A map of chrome:// hostnames (newtab, downloads, etc.) to Extension URLs
64 // which override the handling of those URLs. (see ExtensionOverrideUI).
65 URLOverrideMap chrome_url_overrides_
;
68 // Parses the "devtools_page" manifest key.
69 class DevToolsPageHandler
: public ManifestHandler
{
71 DevToolsPageHandler();
72 virtual ~DevToolsPageHandler();
74 virtual bool Parse(Extension
* extension
, base::string16
* error
) OVERRIDE
;
77 virtual const std::vector
<std::string
> Keys() const OVERRIDE
;
79 DISALLOW_COPY_AND_ASSIGN(DevToolsPageHandler
);
82 // Parses the "homepage_url" manifest key.
83 class HomepageURLHandler
: public ManifestHandler
{
86 virtual ~HomepageURLHandler();
88 virtual bool Parse(Extension
* extension
, base::string16
* error
) OVERRIDE
;
91 virtual const std::vector
<std::string
> Keys() const OVERRIDE
;
93 DISALLOW_COPY_AND_ASSIGN(HomepageURLHandler
);
96 // Parses the "update_url" manifest key.
97 class UpdateURLHandler
: public ManifestHandler
{
100 virtual ~UpdateURLHandler();
102 virtual bool Parse(Extension
* extension
, base::string16
* error
) OVERRIDE
;
105 virtual const std::vector
<std::string
> Keys() const OVERRIDE
;
107 DISALLOW_COPY_AND_ASSIGN(UpdateURLHandler
);
110 // Parses the "about_page" manifest key.
111 // TODO(sashab): Make this and any other similar handlers extend from the same
112 // abstract class, URLManifestHandler, which has pure virtual methods for
113 // detecting the required URL type (relative or absolute) and abstracts the
114 // URL parsing logic away.
115 class AboutPageHandler
: public ManifestHandler
{
118 virtual ~AboutPageHandler();
120 virtual bool Parse(Extension
* extension
, base::string16
* error
) OVERRIDE
;
121 virtual bool Validate(const Extension
* extension
,
123 std::vector
<InstallWarning
>* warnings
) const OVERRIDE
;
126 virtual const std::vector
<std::string
> Keys() const OVERRIDE
;
128 DISALLOW_COPY_AND_ASSIGN(AboutPageHandler
);
131 // Parses the "chrome_url_overrides" manifest key.
132 class URLOverridesHandler
: public ManifestHandler
{
134 URLOverridesHandler();
135 virtual ~URLOverridesHandler();
137 virtual bool Parse(Extension
* extension
, base::string16
* error
) OVERRIDE
;
140 virtual const std::vector
<std::string
> Keys() const OVERRIDE
;
142 DISALLOW_COPY_AND_ASSIGN(URLOverridesHandler
);
145 } // namespace extensions
147 #endif // CHROME_COMMON_EXTENSIONS_MANIFEST_URL_HANDLER_H_