blob: 1baa80b19a10f96f5e813f792b5dab5f66802e82 [file] [log] [blame]
[email protected]e6893672014-05-01 17:29:131// Copyright 2014 The Chromium Authors. All rights reserved.
[email protected]ecde1912012-03-16 06:25:312// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
[email protected]e6893672014-05-01 17:29:135#ifndef EXTENSIONS_RENDERER_RESOURCE_BUNDLE_SOURCE_MAP_H_
6#define EXTENSIONS_RENDERER_RESOURCE_BUNDLE_SOURCE_MAP_H_
[email protected]ecde1912012-03-16 06:25:317
8#include <map>
9#include <string>
10
rdevlin.cronin1ed2e892016-12-06 21:35:4311#include "base/macros.h"
12#include "extensions/renderer/source_map.h"
[email protected]e6893672014-05-01 17:29:1313#include "v8/include/v8.h"
14
[email protected]ecde1912012-03-16 06:25:3115namespace ui {
[email protected]e6893672014-05-01 17:29:1316class ResourceBundle;
[email protected]ecde1912012-03-16 06:25:3117}
18
[email protected]e6893672014-05-01 17:29:1319namespace extensions {
20
rdevlin.cronin1ed2e892016-12-06 21:35:4321class ResourceBundleSourceMap : public SourceMap {
[email protected]ecde1912012-03-16 06:25:3122 public:
23 explicit ResourceBundleSourceMap(const ui::ResourceBundle* resource_bundle);
dcheng9168b2f2014-10-21 12:38:2424 ~ResourceBundleSourceMap() override;
[email protected]ecde1912012-03-16 06:25:3125
rdevlin.cronin1ed2e892016-12-06 21:35:4326 v8::Local<v8::String> GetSource(v8::Isolate* isolate,
27 const std::string& name) const override;
lazyboyce333962016-04-12 18:22:0428 bool Contains(const std::string& name) const override;
[email protected]ecde1912012-03-16 06:25:3129
Yuzhu Shenbcd734d2017-11-15 20:40:5830 void RegisterSource(const char* const name,
31 int resource_id,
32 bool gzipped = false);
[email protected]ecde1912012-03-16 06:25:3133
34 private:
Yuzhu Shenbcd734d2017-11-15 20:40:5835 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]ecde1912012-03-16 06:25:3149 const ui::ResourceBundle* resource_bundle_;
Yuzhu Shenbcd734d2017-11-15 20:40:5850 std::map<std::string, ResourceInfo> resource_map_;
lazyboyce333962016-04-12 18:22:0451
52 DISALLOW_COPY_AND_ASSIGN(ResourceBundleSourceMap);
[email protected]ecde1912012-03-16 06:25:3153};
54
[email protected]e6893672014-05-01 17:29:1355} // namespace extensions
56
57#endif // EXTENSIONS_RENDERER_RESOURCE_BUNDLE_SOURCE_MAP_H_