Specifiy that this supports M47
[platform/framework/web/crosswalk-tizen.git] / common / resource_manager.h
1 /*
2  * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved
3  *
4  *    Licensed under the Apache License, Version 2.0 (the "License");
5  *    you may not use this file except in compliance with the License.
6  *    You may obtain a copy of the License at
7  *
8  *        http://www.apache.org/licenses/LICENSE-2.0
9  *
10  *    Unless required by applicable law or agreed to in writing, software
11  *    distributed under the License is distributed on an "AS IS" BASIS,
12  *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  *    See the License for the specific language governing permissions and
14  *    limitations under the License.
15  */
16
17 #ifndef XWALK_COMMON_RESOURCE_MANAGER_H_
18 #define XWALK_COMMON_RESOURCE_MANAGER_H_
19
20 #include <map>
21 #include <memory>
22 #include <string>
23
24 namespace wgt {
25 namespace parse {
26 class AppControlInfo;
27 }  // namespace parse
28 }  // namespace wgt
29
30 namespace common {
31
32 class ApplicationData;
33 class LocaleManager;
34 class AppControl;
35
36 class ResourceManager {
37  public:
38   class Resource {
39    public:
40     explicit Resource(const std::string& uri);
41     Resource(const std::string& uri, bool should_reset);
42     Resource(const std::string& uri, const std::string& mime,
43              const std::string& encoding);
44     Resource(const Resource& res);
45     ~Resource() {}
46
47     Resource& operator=(const Resource& res);
48     bool operator==(const Resource& res);
49
50     void set_uri(const std::string& uri) { uri_ = uri; }
51     void set_mime(const std::string& mime) { mime_ = mime; }
52     void set_should_reset(bool should_reset) { should_reset_ = should_reset; }
53     void set_encoding(const std::string& encoding) { encoding_ = encoding; }
54
55     std::string uri() const { return uri_; }
56     std::string mime() const { return mime_; }
57     bool should_reset() const { return should_reset_; }
58     std::string encoding() const { return encoding_; }
59
60    private:
61     std::string uri_;
62     std::string mime_;
63     bool should_reset_;
64     std::string encoding_;
65   };
66
67   ResourceManager(ApplicationData* application_data,
68                   LocaleManager* locale_manager);
69   ~ResourceManager() {}
70
71   // input : file:///..... , app://[appid]/....
72   // output : /[system path]/.../locales/.../
73   std::string GetLocalizedPath(const std::string& origin);
74   std::unique_ptr<Resource> GetStartResource(const AppControl* app_control);
75   bool AllowNavigation(const std::string& url);
76   bool AllowedResource(const std::string& url);
77
78   bool IsEncrypted(const std::string& url);
79   std::string DecryptResource(const std::string& path);
80
81   void set_base_resource_path(const std::string& base_path);
82
83  private:
84   std::unique_ptr<Resource> GetMatchedResource(
85     const wgt::parse::AppControlInfo&);
86   std::unique_ptr<Resource> GetDefaultResource();
87
88   // for localization
89   bool Exists(const std::string& path);
90   bool CheckWARP(const std::string& url);
91   bool CheckAllowNavigation(const std::string& url);
92   std::string RemoveLocalePath(const std::string& path);
93
94   std::string resource_base_path_;
95   std::string appid_;
96   std::map<const std::string, bool> file_existed_cache_;
97   std::map<const std::string, std::string> locale_cache_;
98   std::map<const std::string, bool> warp_cache_;
99
100   ApplicationData* application_data_;
101   LocaleManager* locale_manager_;
102   int security_model_version_;
103 };
104
105 }  // namespace common
106
107 #endif  // XWALK_COMMON_RESOURCE_MANAGER_H_