Home | History | Annotate | Download | only in manifest_handlers
      1 // Copyright 2014 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_HANDLERS_OPTIONS_PAGE_INFO_H_
      6 #define EXTENSIONS_COMMON_MANIFEST_HANDLERS_OPTIONS_PAGE_INFO_H_
      7 
      8 #include <string>
      9 #include <vector>
     10 
     11 #include "base/values.h"
     12 #include "extensions/common/extension.h"
     13 #include "extensions/common/manifest_handler.h"
     14 #include "url/gurl.h"
     15 
     16 namespace base {
     17 class Value;
     18 }
     19 
     20 namespace extensions {
     21 
     22 // A class to provide options page configuration settings from the manifest.
     23 class OptionsPageInfo : public Extension::ManifestData {
     24  public:
     25   OptionsPageInfo(const GURL& options_page,
     26                   bool chrome_styles,
     27                   bool open_in_tab);
     28   virtual ~OptionsPageInfo();
     29 
     30   // Returns the URL to the given extension's options page. This method supports
     31   // both the "options_ui.page" field and the legacy "options_page" field. If
     32   // both are present, it will return the value of "options_ui.page".
     33   static const GURL& GetOptionsPage(const Extension* extension);
     34 
     35   // Returns true if the given extension has an options page. An extension has
     36   // an options page if one or both of "options_ui.page" and "options_page"
     37   // specify a valid options page.
     38   static bool HasOptionsPage(const Extension* extension);
     39 
     40   // Returns whether the Chrome user agent stylesheet should be applied to the
     41   // given extension's options page.
     42   static bool ShouldUseChromeStyle(const Extension* extension);
     43 
     44   // Returns whether the given extension's options page should be opened in a
     45   // new tab instead of an embedded popup.
     46   static bool ShouldOpenInTab(const Extension* extension);
     47 
     48   static scoped_ptr<OptionsPageInfo> Create(
     49       Extension* extension,
     50       const base::Value* options_ui_value,
     51       const std::string& options_page_string,
     52       std::vector<InstallWarning>* install_warnings,
     53       base::string16* error);
     54 
     55  private:
     56   // The URL to the options page of this extension. We only store one options
     57   // URL, either options_page or options_ui.page. options_ui.page is preferred
     58   // if both are present.
     59   GURL options_page_;
     60 
     61   bool chrome_styles_;
     62 
     63   bool open_in_tab_;
     64 
     65   DISALLOW_COPY_AND_ASSIGN(OptionsPageInfo);
     66 };
     67 
     68 // Parses the "options_ui" manifest key and the legacy "options_page" key.
     69 class OptionsPageManifestHandler : public ManifestHandler {
     70  public:
     71   OptionsPageManifestHandler();
     72   virtual ~OptionsPageManifestHandler();
     73 
     74   virtual bool Parse(Extension* extension, base::string16* error) OVERRIDE;
     75   virtual bool Validate(const Extension* extension,
     76                         std::string* error,
     77                         std::vector<InstallWarning>* warnings) const OVERRIDE;
     78 
     79  private:
     80   virtual const std::vector<std::string> Keys() const OVERRIDE;
     81 
     82   DISALLOW_COPY_AND_ASSIGN(OptionsPageManifestHandler);
     83 };
     84 
     85 }  // namespace extensions
     86 
     87 #endif  // EXTENSIONS_COMMON_MANIFEST_HANDLERS_OPTIONS_PAGE_INFO_H_
     88