Remove an unused function from Harfbuzz.
[chromium-blink-merge.git] / extensions / renderer / resource_bundle_source_map.cc
blob88fc5372185d0ebd511fc7c8cd716914701480e3
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 "base/logging.h"
8 #include "ui/base/resource/resource_bundle.h"
10 namespace extensions {
12 ResourceBundleSourceMap::ResourceBundleSourceMap(
13 const ui::ResourceBundle* resource_bundle)
14 : resource_bundle_(resource_bundle) {
17 ResourceBundleSourceMap::~ResourceBundleSourceMap() {
20 void ResourceBundleSourceMap::RegisterSource(const std::string& name,
21 int resource_id) {
22 resource_id_map_[name] = resource_id;
25 v8::Local<v8::Value> ResourceBundleSourceMap::GetSource(
26 v8::Isolate* isolate,
27 const std::string& name) {
28 if (!Contains(name)) {
29 NOTREACHED() << "No module is registered with name \"" << name << "\"";
30 return v8::Undefined(isolate);
32 base::StringPiece resource =
33 resource_bundle_->GetRawDataResource(resource_id_map_[name]);
34 if (resource.empty()) {
35 NOTREACHED()
36 << "Module resource registered as \"" << name << "\" not found";
37 return v8::Undefined(isolate);
39 return ConvertString(isolate, resource);
42 bool ResourceBundleSourceMap::Contains(const std::string& name) {
43 return !!resource_id_map_.count(name);
46 v8::Local<v8::String> ResourceBundleSourceMap::ConvertString(
47 v8::Isolate* isolate,
48 const base::StringPiece& string) {
49 // v8 takes ownership of the StaticV8ExternalOneByteStringResource (see
50 // v8::String::NewExternal()).
51 return v8::String::NewExternal(
52 isolate, new StaticV8ExternalOneByteStringResource(string));
55 } // namespace extensions