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 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// A structure to hold the chrome URL overrides that may be specified 52// in the manifest of an extension. 53struct URLOverrides : public Extension::ManifestData { 54 typedef std::map<const std::string, GURL> URLOverrideMap; 55 56 // Define out of line constructor/destructor to please Clang. 57 URLOverrides(); 58 virtual ~URLOverrides(); 59 60 static const URLOverrideMap& 61 GetChromeURLOverrides(const Extension* extension); 62 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_; 66}; 67 68// Parses the "devtools_page" manifest key. 69class DevToolsPageHandler : public ManifestHandler { 70 public: 71 DevToolsPageHandler(); 72 virtual ~DevToolsPageHandler(); 73 74 virtual bool Parse(Extension* extension, base::string16* error) OVERRIDE; 75 76 private: 77 virtual const std::vector<std::string> Keys() const OVERRIDE; 78 79 DISALLOW_COPY_AND_ASSIGN(DevToolsPageHandler); 80}; 81 82// Parses the "homepage_url" manifest key. 83class HomepageURLHandler : public ManifestHandler { 84 public: 85 HomepageURLHandler(); 86 virtual ~HomepageURLHandler(); 87 88 virtual bool Parse(Extension* extension, base::string16* error) OVERRIDE; 89 90 private: 91 virtual const std::vector<std::string> Keys() const OVERRIDE; 92 93 DISALLOW_COPY_AND_ASSIGN(HomepageURLHandler); 94}; 95 96// Parses the "update_url" manifest key. 97class UpdateURLHandler : public ManifestHandler { 98 public: 99 UpdateURLHandler(); 100 virtual ~UpdateURLHandler(); 101 102 virtual bool Parse(Extension* extension, base::string16* error) OVERRIDE; 103 104 private: 105 virtual const std::vector<std::string> Keys() const OVERRIDE; 106 107 DISALLOW_COPY_AND_ASSIGN(UpdateURLHandler); 108}; 109 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. 115class AboutPageHandler : public ManifestHandler { 116 public: 117 AboutPageHandler(); 118 virtual ~AboutPageHandler(); 119 120 virtual bool Parse(Extension* extension, base::string16* error) OVERRIDE; 121 virtual bool Validate(const Extension* extension, 122 std::string* error, 123 std::vector<InstallWarning>* warnings) const OVERRIDE; 124 125 private: 126 virtual const std::vector<std::string> Keys() const OVERRIDE; 127 128 DISALLOW_COPY_AND_ASSIGN(AboutPageHandler); 129}; 130 131// Parses the "chrome_url_overrides" manifest key. 132class URLOverridesHandler : public ManifestHandler { 133 public: 134 URLOverridesHandler(); 135 virtual ~URLOverridesHandler(); 136 137 virtual bool Parse(Extension* extension, base::string16* error) OVERRIDE; 138 139 private: 140 virtual const std::vector<std::string> Keys() const OVERRIDE; 141 142 DISALLOW_COPY_AND_ASSIGN(URLOverridesHandler); 143}; 144 145} // namespace extensions 146 147#endif // CHROME_COMMON_EXTENSIONS_MANIFEST_URL_HANDLER_H_ 148