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#include <vector>
10
11#include "base/macros.h"
12#include "extensions/common/extension.h"
13#include "extensions/common/manifest_handler.h"
14
15namespace base {
16class DictionaryValue;
17}
18
19namespace extensions {
20
21// A structure to hold various URLs like devtools_page, homepage_url, etc
22// that may be specified in the manifest of an extension.
23struct ManifestURL : public Extension::ManifestData {
24 GURL url_;
25
26 // Returns the value of a URL key for an extension, or an empty URL if unset.
27 static const GURL& Get(const Extension* extension, const std::string& key);
28
29 // Returns the Homepage URL for this extension.
30 // If homepage_url was not specified in the manifest,
31 // this returns the Google Gallery URL. For third-party extensions,
32 // this returns a blank GURL.
33 // See also: GetManifestHomePageURL(), SpecifiedHomepageURL()
34 static const GURL GetHomepageURL(const Extension* extension);
35
36 // Returns true if the extension specified a valid home page url in the
37 // manifest.
38 static bool SpecifiedHomepageURL(const Extension* extension);
39
40 // Returns the homepage specified by the extension in its manifest, if it
41 // specifies a homepage. Otherwise, returns an empty url.
42 // See also: GetHomepageURL()
43 static const GURL GetManifestHomePageURL(const Extension* extension);
44
45 // Returns the Chrome Web Store URL for this extension if it is hosted in the
46 // webstore; otherwise returns an empty url.
47 // See also: GetHomepageURL()
48 static const GURL GetWebStoreURL(const Extension* extension);
49
50 // Returns the Update URL for this extension.
51 static const GURL& GetUpdateURL(const Extension* extension);
52
53 // Returns true if this extension's update URL is the extension gallery.
54 static bool UpdatesFromGallery(const Extension* extension);
55 static bool UpdatesFromGallery(const base::DictionaryValue* manifest);
56
57 // Returns the About Page for this extension.
58 static const GURL& GetAboutPage(const Extension* extension);
59
60 // Returns the webstore page URL for this extension.
61 static const GURL GetDetailsURL(const Extension* extension);
62};
63
64// Parses the "homepage_url" manifest key.
65class HomepageURLHandler : public ManifestHandler {
66 public:
67 HomepageURLHandler();
68 ~HomepageURLHandler() override;
69
70 bool Parse(Extension* extension, base::string16* error) override;
71
72 private:
73 base::span<const char* const> Keys() const override;
74
75 DISALLOW_COPY_AND_ASSIGN(HomepageURLHandler);
76};
77
78// Parses the "update_url" manifest key.
79class UpdateURLHandler : public ManifestHandler {
80 public:
81 UpdateURLHandler();
82 ~UpdateURLHandler() override;
83
84 bool Parse(Extension* extension, base::string16* error) override;
85
86 private:
87 base::span<const char* const> Keys() const override;
88
89 DISALLOW_COPY_AND_ASSIGN(UpdateURLHandler);
90};
91
92// Parses the "about_page" manifest key.
93// TODO(sashab): Make this and any other similar handlers extend from the same
94// abstract class, URLManifestHandler, which has pure virtual methods for
95// detecting the required URL type (relative or absolute) and abstracts the
96// URL parsing logic away.
97class AboutPageHandler : public ManifestHandler {
98 public:
99 AboutPageHandler();
100 ~AboutPageHandler() override;
101
102 bool Parse(Extension* extension, base::string16* error) override;
103 bool Validate(const Extension* extension,
104 std::string* error,
105 std::vector<InstallWarning>* warnings) const override;
106
107 private:
108 base::span<const char* const> Keys() const override;
109
110 DISALLOW_COPY_AND_ASSIGN(AboutPageHandler);
111};
112
113} // namespace extensions
114
115#endif // EXTENSIONS_COMMON_MANIFEST_URL_HANDLERS_H_
116