Adding Peter Thatcher to the owners file.
[chromium-blink-merge.git] / extensions / renderer / resource_bundle_source_map.cc
blob9b0a85adbbfb0b005decb6486009412ac700f7be
1 // Copyright 2014 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 #include "extensions/renderer/resource_bundle_source_map.h"
7 #include "ui/base/resource/resource_bundle.h"
9 namespace extensions {
11 ResourceBundleSourceMap::ResourceBundleSourceMap(
12 const ui::ResourceBundle* resource_bundle)
13 : resource_bundle_(resource_bundle) {
16 ResourceBundleSourceMap::~ResourceBundleSourceMap() {
19 void ResourceBundleSourceMap::RegisterSource(const std::string& name,
20 int resource_id) {
21 resource_id_map_[name] = resource_id;
24 v8::Handle<v8::Value> ResourceBundleSourceMap::GetSource(
25 v8::Isolate* isolate,
26 const std::string& name) {
27 if (!Contains(name))
28 return v8::Undefined(isolate);
29 int resource_id = resource_id_map_[name];
30 return ConvertString(isolate,
31 resource_bundle_->GetRawDataResource(resource_id));
34 bool ResourceBundleSourceMap::Contains(const std::string& name) {
35 return !!resource_id_map_.count(name);
38 v8::Handle<v8::String> ResourceBundleSourceMap::ConvertString(
39 v8::Isolate* isolate,
40 const base::StringPiece& string) {
41 // v8 takes ownership of the StaticV8ExternalOneByteStringResource (see
42 // v8::String::NewExternal()).
43 return v8::String::NewExternal(
44 isolate, new StaticV8ExternalOneByteStringResource(string));
47 } // namespace extensions