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.
5 #ifndef XWALK_APPLICATION_COMMON_APPLICATION_RESOURCE_H_
6 #define XWALK_APPLICATION_COMMON_APPLICATION_RESOURCE_H_
11 #include "base/files/file_path.h"
14 namespace application {
16 // Represents a resource inside an application. For example, an image, or a
17 // JavaScript file. This is more complicated than just a simple FilePath
18 // because application resources can come from multiple physical file locations
19 // depending on locale.
20 class ApplicationResource {
22 // SymlinkPolicy decides whether we'll allow resources to be a symlink to
23 // anywhere, or whether they must end up within the application root.
25 SYMLINKS_MUST_RESOLVE_WITHIN_ROOT,
26 FOLLOW_SYMLINKS_ANYWHERE,
29 ApplicationResource();
31 ApplicationResource(const std::string& application_id,
32 const base::FilePath& application_root,
33 const base::FilePath& relative_path);
35 ~ApplicationResource();
37 // set_follow_symlinks_anywhere allows the resource to be a symlink to
38 // anywhere in the filesystem. By default, resources have to be within
39 // |application_root| after resolving symlinks.
40 void set_follow_symlinks_anywhere();
42 // Returns actual path to the resource (default or locale specific). In the
43 // browser process, this will DCHECK if not called on the file thread. To
44 // easily load application images on the UI thread, see ImageLoader.
45 const base::FilePath& GetFilePath() const;
47 // Gets the physical file path for the application resource, taking into
48 // account localization. In the browser process, this will DCHECK if not
49 // called on the file thread. To easily load application images on the UI
50 // thread, see ImageLoader.
52 // The relative path must not resolve to a location outside of
53 // |application_root|. Iff |file_can_symlink_outside_root| is true, then the
54 // file can be a symlink that links outside of |application_root|.
55 static base::FilePath GetFilePath(const base::FilePath& application_root,
56 const base::FilePath& relative_path,
57 SymlinkPolicy symlink_policy);
60 const std::string& application_id() const { return application_id_; }
61 const base::FilePath& application_root() const { return application_root_; }
62 const base::FilePath& relative_path() const { return relative_path_; }
65 void SetLocales(const std::list<std::string>& locales) {
67 full_resource_path_.clear();
70 bool empty() const { return application_root().empty(); }
73 base::FilePath::StringType NormalizeSeperators(
74 const base::FilePath::StringType& path) const;
75 bool ComparePathWithDefault(const base::FilePath& path) const;
78 // The id of the application that this resource is associated with.
79 std::string application_id_;
82 base::FilePath application_root_;
84 // Relative path to resource.
85 base::FilePath relative_path_;
87 // If |follow_symlinks_anywhere_| is true then the resource itself must be
88 // within |application_root|, but it can be a symlink to a file that is not.
89 bool follow_symlinks_anywhere_;
91 // Full path to application resource. Starts empty.
92 mutable base::FilePath full_resource_path_;
94 // The User Agent localization information.
95 std::list<std::string> locales_;
98 } // namespace application
101 #endif // XWALK_APPLICATION_COMMON_APPLICATION_RESOURCE_H_