Roll WebRTC 5699->5721.
[chromium-blink-merge.git] / chrome / renderer / resource_bundle_source_map.cc
blob6a7ff021ac7b14072181028c84edd95732c049ef
1 // Copyright (c) 2012 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 "chrome/renderer/resource_bundle_source_map.h"
7 #include "ui/base/resource/resource_bundle.h"
9 ResourceBundleSourceMap::ResourceBundleSourceMap(
10 const ui::ResourceBundle* resource_bundle)
11 : resource_bundle_(resource_bundle) {
14 ResourceBundleSourceMap::~ResourceBundleSourceMap() {
17 void ResourceBundleSourceMap::RegisterSource(const std::string& name,
18 int resource_id) {
19 resource_id_map_[name] = resource_id;
22 v8::Handle<v8::Value> ResourceBundleSourceMap::GetSource(
23 v8::Isolate* isolate,
24 const std::string& name) {
25 if (!Contains(name))
26 return v8::Undefined(isolate);
27 int resource_id = resource_id_map_[name];
28 return ConvertString(isolate,
29 resource_bundle_->GetRawDataResource(resource_id));
32 bool ResourceBundleSourceMap::Contains(const std::string& name) {
33 return !!resource_id_map_.count(name);
36 v8::Handle<v8::String> ResourceBundleSourceMap::ConvertString(
37 v8::Isolate* isolate,
38 const base::StringPiece& string) {
39 // v8 takes ownership of the StaticV8ExternalAsciiStringResource (see
40 // v8::String::NewExternal()).
41 return v8::String::NewExternal(
42 isolate, new StaticV8ExternalAsciiStringResource(string));