summaryrefslogtreecommitdiffstats
path: root/chrome/renderer/resource_bundle_source_map.h
blob: a88b1650698851a890acb22179cf59a8f967bbd4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef CHROME_RENDERER_RESOURCE_BUNDLE_SOURCE_MAP_H_
#define CHROME_RENDERER_RESOURCE_BUNDLE_SOURCE_MAP_H_

#include "base/compiler_specific.h"
#include "base/memory/linked_ptr.h"
#include "base/strings/string_piece.h"
#include "chrome/renderer/extensions/module_system.h"
#include "chrome/renderer/static_v8_external_string_resource.h"
#include "v8/include/v8.h"

#include <map>
#include <string>

namespace ui {
  class ResourceBundle;
}

class ResourceBundleSourceMap : public extensions::ModuleSystem::SourceMap {
 public:
  explicit ResourceBundleSourceMap(const ui::ResourceBundle* resource_bundle);
  virtual ~ResourceBundleSourceMap();

  virtual v8::Handle<v8::Value> GetSource(v8::Isolate* isolate,
                                          const std::string& name) OVERRIDE;
  virtual bool Contains(const std::string& name) OVERRIDE;

  void RegisterSource(const std::string& name, int resource_id);

 private:
  v8::Handle<v8::String> ConvertString(v8::Isolate* isolate,
                                       const base::StringPiece& string);

  const ui::ResourceBundle* resource_bundle_;
  std::map<std::string, int> resource_id_map_;
};

#endif  // CHROME_RENDERER_RESOURCE_BUNDLE_SOURCE_MAP_H_