Home | History | Annotate | Download | only in file_browser_handlers
      1 // Copyright 2013 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_API_FILE_BROWSER_HANDLERS_FILE_BROWSER_HANDLER_H_
      6 #define CHROME_COMMON_EXTENSIONS_API_FILE_BROWSER_HANDLERS_FILE_BROWSER_HANDLER_H_
      7 
      8 #include <string>
      9 #include <vector>
     10 
     11 #include "base/basictypes.h"
     12 #include "extensions/common/extension.h"
     13 #include "extensions/common/manifest_handler.h"
     14 #include "extensions/common/url_pattern.h"
     15 #include "extensions/common/url_pattern_set.h"
     16 
     17 class GURL;
     18 class URLPattern;
     19 
     20 // FileBrowserHandler encapsulates the state of a file browser action.
     21 class FileBrowserHandler {
     22  public:
     23   typedef std::vector<linked_ptr<FileBrowserHandler> > List;
     24 
     25   FileBrowserHandler();
     26   ~FileBrowserHandler();
     27 
     28   // extension id
     29   std::string extension_id() const { return extension_id_; }
     30   void set_extension_id(const std::string& extension_id) {
     31     extension_id_ = extension_id;
     32   }
     33 
     34   // action id
     35   const std::string& id() const { return id_; }
     36   void set_id(const std::string& id) { id_ = id; }
     37 
     38   // default title
     39   const std::string& title() const { return title_; }
     40   void set_title(const std::string& title) { title_ = title; }
     41 
     42   // File schema URL patterns.
     43   const extensions::URLPatternSet& file_url_patterns() const {
     44     return url_set_;
     45   }
     46   void AddPattern(const URLPattern& pattern);
     47   bool MatchesURL(const GURL& url) const;
     48   void ClearPatterns();
     49 
     50   // Action icon path.
     51   const std::string& icon_path() const { return default_icon_path_; }
     52   void set_icon_path(const std::string& path) {
     53     default_icon_path_ = path;
     54   }
     55 
     56   // File access permissions.
     57   // Adjusts file_access_permission_flags_ to allow specified permission.
     58   bool AddFileAccessPermission(const std::string& permission_str);
     59   // Checks that specified file access permissions are valid (all set
     60   // permissions are valid and there is no other permission specified with
     61   // "create")
     62   // If no access permissions were set, initialize them to default value.
     63   bool ValidateFileAccessPermissions();
     64   // Checks if handler has read access.
     65   bool CanRead() const;
     66   // Checks if handler has write access.
     67   bool CanWrite() const;
     68   // Checks if handler has "create" access specified.
     69   bool HasCreateAccessPermission() const;
     70 
     71   // Returns the file browser handlers associated with the |extension|.
     72   static List* GetHandlers(const extensions::Extension* extension);
     73 
     74  private:
     75   // The id for the extension this action belongs to (as defined in the
     76   // extension manifest).
     77   std::string extension_id_;
     78   std::string title_;
     79   std::string default_icon_path_;
     80   // The id for the FileBrowserHandler, for example: "PdfFileAction".
     81   std::string id_;
     82   unsigned int file_access_permission_flags_;
     83 
     84   // A list of file filters.
     85   extensions::URLPatternSet url_set_;
     86 };
     87 
     88 // Parses the "file_browser_handlers" extension manifest key.
     89 class FileBrowserHandlerParser : public extensions::ManifestHandler {
     90  public:
     91   FileBrowserHandlerParser();
     92   virtual ~FileBrowserHandlerParser();
     93 
     94   virtual bool Parse(extensions::Extension* extension,
     95                      base::string16* error) OVERRIDE;
     96 
     97  private:
     98   virtual const std::vector<std::string> Keys() const OVERRIDE;
     99 };
    100 
    101 #endif  // CHROME_COMMON_EXTENSIONS_API_FILE_BROWSER_HANDLERS_FILE_BROWSER_HANDLER_H_
    102