Home | History | Annotate | Download | only in extensions
      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 
     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 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 About Page for this extension.
     44   static const GURL& GetAboutPage(const Extension* extension);
     45 
     46   // Returns the webstore page URL for this extension.
     47   static const GURL GetDetailsURL(const Extension* extension);
     48 };
     49 
     50 // A structure to hold the chrome URL overrides that may be specified
     51 // in the manifest of an extension.
     52 struct URLOverrides : public Extension::ManifestData {
     53   typedef std::map<const std::string, GURL> URLOverrideMap;
     54 
     55   // Define out of line constructor/destructor to please Clang.
     56   URLOverrides();
     57   virtual ~URLOverrides();
     58 
     59   static const URLOverrideMap&
     60       GetChromeURLOverrides(const Extension* extension);
     61 
     62   // A map of chrome:// hostnames (newtab, downloads, etc.) to Extension URLs
     63   // which override the handling of those URLs. (see ExtensionOverrideUI).
     64   URLOverrideMap chrome_url_overrides_;
     65 };
     66 
     67 // Parses the "devtools_page" manifest key.
     68 class DevToolsPageHandler : public ManifestHandler {
     69  public:
     70   DevToolsPageHandler();
     71   virtual ~DevToolsPageHandler();
     72 
     73   virtual bool Parse(Extension* extension, base::string16* error) OVERRIDE;
     74 
     75  private:
     76   virtual const std::vector<std::string> Keys() const OVERRIDE;
     77 
     78   DISALLOW_COPY_AND_ASSIGN(DevToolsPageHandler);
     79 };
     80 
     81 // Parses the "homepage_url" manifest key.
     82 class HomepageURLHandler : public ManifestHandler {
     83  public:
     84   HomepageURLHandler();
     85   virtual ~HomepageURLHandler();
     86 
     87   virtual bool Parse(Extension* extension, base::string16* error) OVERRIDE;
     88 
     89  private:
     90   virtual const std::vector<std::string> Keys() const OVERRIDE;
     91 
     92   DISALLOW_COPY_AND_ASSIGN(HomepageURLHandler);
     93 };
     94 
     95 // Parses the "update_url" manifest key.
     96 class UpdateURLHandler : public ManifestHandler {
     97  public:
     98   UpdateURLHandler();
     99   virtual ~UpdateURLHandler();
    100 
    101   virtual bool Parse(Extension* extension, base::string16* error) OVERRIDE;
    102 
    103  private:
    104   virtual const std::vector<std::string> Keys() const OVERRIDE;
    105 
    106   DISALLOW_COPY_AND_ASSIGN(UpdateURLHandler);
    107 };
    108 
    109 // Parses the "options_page" manifest key.
    110 class OptionsPageHandler : public ManifestHandler {
    111  public:
    112   OptionsPageHandler();
    113   virtual ~OptionsPageHandler();
    114 
    115   virtual bool Parse(Extension* extension, base::string16* error) OVERRIDE;
    116   virtual bool Validate(const Extension* extension,
    117                         std::string* error,
    118                         std::vector<InstallWarning>* warnings) const OVERRIDE;
    119 
    120  private:
    121   virtual const std::vector<std::string> Keys() const OVERRIDE;
    122 
    123   DISALLOW_COPY_AND_ASSIGN(OptionsPageHandler);
    124 };
    125 
    126 // Parses the "about_page" manifest key.
    127 // TODO(sashab): Make this and any other similar handlers extend from the same
    128 // abstract class, URLManifestHandler, which has pure virtual methods for
    129 // detecting the required URL type (relative or absolute) and abstracts the
    130 // URL parsing logic away.
    131 class AboutPageHandler : public ManifestHandler {
    132  public:
    133   AboutPageHandler();
    134   virtual ~AboutPageHandler();
    135 
    136   virtual bool Parse(Extension* extension, base::string16* error) OVERRIDE;
    137   virtual bool Validate(const Extension* extension,
    138                         std::string* error,
    139                         std::vector<InstallWarning>* warnings) const OVERRIDE;
    140 
    141  private:
    142   virtual const std::vector<std::string> Keys() const OVERRIDE;
    143 
    144   DISALLOW_COPY_AND_ASSIGN(AboutPageHandler);
    145 };
    146 
    147 // Parses the "chrome_url_overrides" manifest key.
    148 class URLOverridesHandler : public ManifestHandler {
    149  public:
    150   URLOverridesHandler();
    151   virtual ~URLOverridesHandler();
    152 
    153   virtual bool Parse(Extension* extension, base::string16* error) OVERRIDE;
    154 
    155  private:
    156   virtual const std::vector<std::string> Keys() const OVERRIDE;
    157 
    158   DISALLOW_COPY_AND_ASSIGN(URLOverridesHandler);
    159 };
    160 
    161 }  // namespace extensions
    162 
    163 #endif  // CHROME_COMMON_EXTENSIONS_MANIFEST_URL_HANDLER_H_
    164