Home | History | Annotate | Download | only in extensions
      1 // Copyright (c) 2011 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_EXTENSION_RESOURCE_H_
      6 #define CHROME_COMMON_EXTENSIONS_EXTENSION_RESOURCE_H_
      7 #pragma once
      8 
      9 #include <string>
     10 
     11 #include "base/file_path.h"
     12 
     13 // Represents a resource inside an extension. For example, an image, or a
     14 // JavaScript file. This is more complicated than just a simple FilePath
     15 // because extension resources can come from multiple physical file locations
     16 // depending on locale.
     17 class ExtensionResource {
     18  public:
     19   ExtensionResource();
     20 
     21   ExtensionResource(const std::string& extension_id,
     22                     const FilePath& extension_root,
     23                     const FilePath& relative_path);
     24 
     25   ~ExtensionResource();
     26 
     27   // Returns actual path to the resource (default or locale specific). In the
     28   // browser process, this will DCHECK if not called on the file thread. To
     29   // easily load extension images on the UI thread, see ImageLoadingTracker.
     30   const FilePath& GetFilePath() const;
     31 
     32   // Gets the physical file path for the extension resource, taking into account
     33   // localization. In the browser process, this will DCHECK if not called on the
     34   // file thread. To easily load extension images on the UI thread, see
     35   // ImageLoadingTracker.
     36   static FilePath GetFilePath(const FilePath& extension_root,
     37                               const FilePath& relative_path);
     38 
     39   // Getters
     40   const std::string& extension_id() const { return extension_id_; }
     41   const FilePath& extension_root() const { return extension_root_; }
     42   const FilePath& relative_path() const { return relative_path_; }
     43 
     44   bool empty() { return extension_root().empty(); }
     45 
     46   // Unit test helpers.
     47   FilePath::StringType NormalizeSeperators(
     48       const FilePath::StringType& path) const;
     49   bool ComparePathWithDefault(const FilePath& path) const;
     50 
     51  private:
     52   // The id of the extension that this resource is associated with.
     53   std::string extension_id_;
     54 
     55   // Extension root.
     56   FilePath extension_root_;
     57 
     58   // Relative path to resource.
     59   FilePath relative_path_;
     60 
     61   // Full path to extension resource. Starts empty.
     62   mutable FilePath full_resource_path_;
     63 };
     64 
     65 #endif  // CHROME_COMMON_EXTENSIONS_EXTENSION_RESOURCE_H_
     66