Upstream version 11.40.271.0
[platform/framework/web/crosswalk.git] / src / extensions / common / manifest_url_handlers.h
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 EXTENSIONS_COMMON_MANIFEST_URL_HANDLERS_H_
6 #define EXTENSIONS_COMMON_MANIFEST_URL_HANDLERS_H_
7
8 #include <string>
9
10 #include "extensions/common/extension.h"
11 #include "extensions/common/manifest_handler.h"
12
13 namespace base {
14 class DictionaryValue;
15 }
16
17 namespace 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.
21 struct ManifestURL : public Extension::ManifestData {
22   GURL url_;
23
24   // Returns the value of a URL key for an extension, or an empty URL if unset.
25   static const GURL& Get(const Extension* extension, const std::string& key);
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 true if the extension specified a valid home page url in the
34   // manifest.
35   static bool SpecifiedHomepageURL(const Extension* extension);
36
37   // Returns the Update URL for this extension.
38   static const GURL& GetUpdateURL(const Extension* extension);
39
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);
43
44   // Returns the About Page for this extension.
45   static const GURL& GetAboutPage(const Extension* extension);
46
47   // Returns the webstore page URL for this extension.
48   static const GURL GetDetailsURL(const Extension* extension);
49 };
50
51 // Parses the "homepage_url" manifest key.
52 class HomepageURLHandler : public ManifestHandler {
53  public:
54   HomepageURLHandler();
55   ~HomepageURLHandler() override;
56
57   bool Parse(Extension* extension, base::string16* error) override;
58
59  private:
60   const std::vector<std::string> Keys() const override;
61
62   DISALLOW_COPY_AND_ASSIGN(HomepageURLHandler);
63 };
64
65 // Parses the "update_url" manifest key.
66 class UpdateURLHandler : public ManifestHandler {
67  public:
68   UpdateURLHandler();
69   ~UpdateURLHandler() override;
70
71   bool Parse(Extension* extension, base::string16* error) override;
72
73  private:
74   const std::vector<std::string> Keys() const override;
75
76   DISALLOW_COPY_AND_ASSIGN(UpdateURLHandler);
77 };
78
79 // Parses the "about_page" manifest key.
80 // TODO(sashab): Make this and any other similar handlers extend from the same
81 // abstract class, URLManifestHandler, which has pure virtual methods for
82 // detecting the required URL type (relative or absolute) and abstracts the
83 // URL parsing logic away.
84 class AboutPageHandler : public ManifestHandler {
85  public:
86   AboutPageHandler();
87   ~AboutPageHandler() override;
88
89   bool Parse(Extension* extension, base::string16* error) override;
90   bool Validate(const Extension* extension,
91                 std::string* error,
92                 std::vector<InstallWarning>* warnings) const override;
93
94  private:
95   const std::vector<std::string> Keys() const override;
96
97   DISALLOW_COPY_AND_ASSIGN(AboutPageHandler);
98 };
99
100 }  // namespace extensions
101
102 #endif  // EXTENSIONS_COMMON_MANIFEST_URL_HANDLERS_H_