[email protected] | e689367 | 2014-05-01 17:29:13 | [diff] [blame] | 1 | // Copyright 2014 The Chromium Authors. All rights reserved. |
[email protected] | ecde191 | 2012-03-16 06:25:31 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
3 | // found in the LICENSE file. | ||||
4 | |||||
[email protected] | e689367 | 2014-05-01 17:29:13 | [diff] [blame] | 5 | #ifndef EXTENSIONS_RENDERER_RESOURCE_BUNDLE_SOURCE_MAP_H_ |
6 | #define EXTENSIONS_RENDERER_RESOURCE_BUNDLE_SOURCE_MAP_H_ | ||||
[email protected] | ecde191 | 2012-03-16 06:25:31 | [diff] [blame] | 7 | |
8 | #include <map> | ||||
9 | #include <string> | ||||
10 | |||||
rdevlin.cronin | 1ed2e89 | 2016-12-06 21:35:43 | [diff] [blame] | 11 | #include "base/macros.h" |
12 | #include "extensions/renderer/source_map.h" | ||||
[email protected] | e689367 | 2014-05-01 17:29:13 | [diff] [blame] | 13 | #include "v8/include/v8.h" |
14 | |||||
[email protected] | ecde191 | 2012-03-16 06:25:31 | [diff] [blame] | 15 | namespace ui { |
[email protected] | e689367 | 2014-05-01 17:29:13 | [diff] [blame] | 16 | class ResourceBundle; |
[email protected] | ecde191 | 2012-03-16 06:25:31 | [diff] [blame] | 17 | } |
18 | |||||
[email protected] | e689367 | 2014-05-01 17:29:13 | [diff] [blame] | 19 | namespace extensions { |
20 | |||||
rdevlin.cronin | 1ed2e89 | 2016-12-06 21:35:43 | [diff] [blame] | 21 | class ResourceBundleSourceMap : public SourceMap { |
[email protected] | ecde191 | 2012-03-16 06:25:31 | [diff] [blame] | 22 | public: |
23 | explicit ResourceBundleSourceMap(const ui::ResourceBundle* resource_bundle); | ||||
dcheng | 9168b2f | 2014-10-21 12:38:24 | [diff] [blame] | 24 | ~ResourceBundleSourceMap() override; |
[email protected] | ecde191 | 2012-03-16 06:25:31 | [diff] [blame] | 25 | |
rdevlin.cronin | 1ed2e89 | 2016-12-06 21:35:43 | [diff] [blame] | 26 | v8::Local<v8::String> GetSource(v8::Isolate* isolate, |
27 | const std::string& name) const override; | ||||
lazyboy | ce33396 | 2016-04-12 18:22:04 | [diff] [blame] | 28 | bool Contains(const std::string& name) const override; |
[email protected] | ecde191 | 2012-03-16 06:25:31 | [diff] [blame] | 29 | |
Yuzhu Shen | bcd734d | 2017-11-15 20:40:58 | [diff] [blame] | 30 | void RegisterSource(const char* const name, |
31 | int resource_id, | ||||
32 | bool gzipped = false); | ||||
[email protected] | ecde191 | 2012-03-16 06:25:31 | [diff] [blame] | 33 | |
34 | private: | ||||
Yuzhu Shen | bcd734d | 2017-11-15 20:40:58 | [diff] [blame] | 35 | struct ResourceInfo { |
36 | ResourceInfo(); | ||||
37 | ResourceInfo(int in_id, bool in_gzipped); | ||||
38 | ResourceInfo(ResourceInfo&& other); | ||||
39 | ~ResourceInfo(); | ||||
40 | |||||
41 | ResourceInfo& operator=(ResourceInfo&& other); | ||||
42 | |||||
43 | int id = 0; | ||||
44 | bool gzipped = false; | ||||
45 | // Used to cache the uncompressed contents if |gzipped| is true. | ||||
46 | mutable std::unique_ptr<std::string> cached; | ||||
47 | }; | ||||
48 | |||||
[email protected] | ecde191 | 2012-03-16 06:25:31 | [diff] [blame] | 49 | const ui::ResourceBundle* resource_bundle_; |
Yuzhu Shen | bcd734d | 2017-11-15 20:40:58 | [diff] [blame] | 50 | std::map<std::string, ResourceInfo> resource_map_; |
lazyboy | ce33396 | 2016-04-12 18:22:04 | [diff] [blame] | 51 | |
52 | DISALLOW_COPY_AND_ASSIGN(ResourceBundleSourceMap); | ||||
[email protected] | ecde191 | 2012-03-16 06:25:31 | [diff] [blame] | 53 | }; |
54 | |||||
[email protected] | e689367 | 2014-05-01 17:29:13 | [diff] [blame] | 55 | } // namespace extensions |
56 | |||||
57 | #endif // EXTENSIONS_RENDERER_RESOURCE_BUNDLE_SOURCE_MAP_H_ |