| Index: extensions/renderer/resource_bundle_source_map.cc
|
| diff --git a/extensions/renderer/resource_bundle_source_map.cc b/extensions/renderer/resource_bundle_source_map.cc
|
| index 88fc5372185d0ebd511fc7c8cd716914701480e3..a260b543f341693e63358994f4cb13e95b88582d 100644
|
| --- a/extensions/renderer/resource_bundle_source_map.cc
|
| +++ b/extensions/renderer/resource_bundle_source_map.cc
|
| @@ -5,10 +5,24 @@
|
| #include "extensions/renderer/resource_bundle_source_map.h"
|
|
|
| #include "base/logging.h"
|
| +#include "base/strings/string_piece.h"
|
| +#include "extensions/renderer/static_v8_external_one_byte_string_resource.h"
|
| #include "ui/base/resource/resource_bundle.h"
|
|
|
| namespace extensions {
|
|
|
| +namespace {
|
| +
|
| +v8::Local<v8::String> ConvertString(v8::Isolate* isolate,
|
| + const base::StringPiece& string) {
|
| + // v8 takes ownership of the StaticV8ExternalOneByteStringResource (see
|
| + // v8::String::NewExternal()).
|
| + return v8::String::NewExternal(
|
| + isolate, new StaticV8ExternalOneByteStringResource(string));
|
| +}
|
| +
|
| +} // namespace
|
| +
|
| ResourceBundleSourceMap::ResourceBundleSourceMap(
|
| const ui::ResourceBundle* resource_bundle)
|
| : resource_bundle_(resource_bundle) {
|
| @@ -24,13 +38,14 @@ void ResourceBundleSourceMap::RegisterSource(const std::string& name,
|
|
|
| v8::Local<v8::Value> ResourceBundleSourceMap::GetSource(
|
| v8::Isolate* isolate,
|
| - const std::string& name) {
|
| - if (!Contains(name)) {
|
| + const std::string& name) const {
|
| + const auto& resource_id_iter = resource_id_map_.find(name);
|
| + if (resource_id_iter == resource_id_map_.end()) {
|
| NOTREACHED() << "No module is registered with name \"" << name << "\"";
|
| return v8::Undefined(isolate);
|
| }
|
| base::StringPiece resource =
|
| - resource_bundle_->GetRawDataResource(resource_id_map_[name]);
|
| + resource_bundle_->GetRawDataResource(resource_id_iter->second);
|
| if (resource.empty()) {
|
| NOTREACHED()
|
| << "Module resource registered as \"" << name << "\" not found";
|
| @@ -39,17 +54,8 @@ v8::Local<v8::Value> ResourceBundleSourceMap::GetSource(
|
| return ConvertString(isolate, resource);
|
| }
|
|
|
| -bool ResourceBundleSourceMap::Contains(const std::string& name) {
|
| +bool ResourceBundleSourceMap::Contains(const std::string& name) const {
|
| return !!resource_id_map_.count(name);
|
| }
|
|
|
| -v8::Local<v8::String> ResourceBundleSourceMap::ConvertString(
|
| - v8::Isolate* isolate,
|
| - const base::StringPiece& string) {
|
| - // v8 takes ownership of the StaticV8ExternalOneByteStringResource (see
|
| - // v8::String::NewExternal()).
|
| - return v8::String::NewExternal(
|
| - isolate, new StaticV8ExternalOneByteStringResource(string));
|
| -}
|
| -
|
| } // namespace extensions
|
|
|