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 "chrome/common/extensions/extension.h"
     11 #include "chrome/common/extensions/manifest_handler.h"
     12 
     13 namespace extensions {
     14 
     15 // A structure to hold various URLs like devtools_page, homepage_url, etc
     16 // that may be specified in the manifest of an extension.
     17 struct ManifestURL : public Extension::ManifestData {
     18   GURL url_;
     19 
     20   // Returns the DevTools Page for this extension.
     21   static const GURL& GetDevToolsPage(const Extension* extension);
     22 
     23   // Returns the Homepage URL for this extension.
     24   // If homepage_url was not specified in the manifest,
     25   // this returns the Google Gallery URL. For third-party extensions,
     26   // this returns a blank GURL.
     27   static const GURL GetHomepageURL(const Extension* extension);
     28 
     29   // Returns the Update URL for this extension.
     30   static const GURL& GetUpdateURL(const Extension* extension);
     31 
     32   // Returns true if this extension's update URL is the extension gallery.
     33   static bool UpdatesFromGallery(const Extension* extension);
     34 
     35   // Returns the Options Page for this extension.
     36   static const GURL& GetOptionsPage(const Extension* extension);
     37 
     38   // Returns the webstore page URL for this extension.
     39   static const GURL GetDetailsURL(const Extension* extension);
     40 };
     41 
     42 // A structure to hold the chrome URL overrides that may be specified
     43 // in the manifest of an extension.
     44 struct URLOverrides : public Extension::ManifestData {
     45   typedef std::map<const std::string, GURL> URLOverrideMap;
     46 
     47   // Define out of line constructor/destructor to please Clang.
     48   URLOverrides();
     49   virtual ~URLOverrides();
     50 
     51   static const URLOverrideMap&
     52       GetChromeURLOverrides(const Extension* extension);
     53 
     54   // A map of chrome:// hostnames (newtab, downloads, etc.) to Extension URLs
     55   // which override the handling of those URLs. (see ExtensionOverrideUI).
     56   URLOverrideMap chrome_url_overrides_;
     57 };
     58 
     59 // Parses the "devtools_page" manifest key.
     60 class DevToolsPageHandler : public ManifestHandler {
     61  public:
     62   DevToolsPageHandler();
     63   virtual ~DevToolsPageHandler();
     64 
     65   virtual bool Parse(Extension* extension, string16* error) OVERRIDE;
     66 
     67  private:
     68   virtual const std::vector<std::string> Keys() const OVERRIDE;
     69 
     70   DISALLOW_COPY_AND_ASSIGN(DevToolsPageHandler);
     71 };
     72 
     73 // Parses the "homepage_url" manifest key.
     74 class HomepageURLHandler : public ManifestHandler {
     75  public:
     76   HomepageURLHandler();
     77   virtual ~HomepageURLHandler();
     78 
     79   virtual bool Parse(Extension* extension, string16* error) OVERRIDE;
     80 
     81  private:
     82   virtual const std::vector<std::string> Keys() const OVERRIDE;
     83 
     84   DISALLOW_COPY_AND_ASSIGN(HomepageURLHandler);
     85 };
     86 
     87 // Parses the "update_url" manifest key.
     88 class UpdateURLHandler : public ManifestHandler {
     89  public:
     90   UpdateURLHandler();
     91   virtual ~UpdateURLHandler();
     92 
     93   virtual bool Parse(Extension* extension, string16* error) OVERRIDE;
     94 
     95  private:
     96   virtual const std::vector<std::string> Keys() const OVERRIDE;
     97 
     98   DISALLOW_COPY_AND_ASSIGN(UpdateURLHandler);
     99 };
    100 
    101 // Parses the "options_page" manifest key.
    102 class OptionsPageHandler : public ManifestHandler {
    103  public:
    104   OptionsPageHandler();
    105   virtual ~OptionsPageHandler();
    106 
    107   virtual bool Parse(Extension* extension, string16* error) OVERRIDE;
    108   virtual bool Validate(const Extension* extension,
    109                         std::string* error,
    110                         std::vector<InstallWarning>* warnings) const OVERRIDE;
    111 
    112  private:
    113   virtual const std::vector<std::string> Keys() const OVERRIDE;
    114 
    115   DISALLOW_COPY_AND_ASSIGN(OptionsPageHandler);
    116 };
    117 
    118 // Parses the "chrome_url_overrides" manifest key.
    119 class URLOverridesHandler : public ManifestHandler {
    120  public:
    121   URLOverridesHandler();
    122   virtual ~URLOverridesHandler();
    123 
    124   virtual bool Parse(Extension* extension, string16* error) OVERRIDE;
    125 
    126  private:
    127   virtual const std::vector<std::string> Keys() const OVERRIDE;
    128 
    129   DISALLOW_COPY_AND_ASSIGN(URLOverridesHandler);
    130 };
    131 
    132 }  // namespace extensions
    133 
    134 #endif  // CHROME_COMMON_EXTENSIONS_MANIFEST_URL_HANDLER_H_
    135