Chromium Code Reviews| 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..cf870dc22ef5e70351389311f64cde073f804613 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) { |
| + const std::string& name) const { |
| if (!Contains(name)) { |
|
Devlin
2016/04/12 17:01:25
nit: another double-lookup.
lazyboy
2016/04/12 17:29:28
Done.
|
| NOTREACHED() << "No module is registered with name \"" << name << "\""; |
| return v8::Undefined(isolate); |
| } |
| + int resource_id = resource_id_map_.find(name)->second; |
| base::StringPiece resource = |
| - resource_bundle_->GetRawDataResource(resource_id_map_[name]); |
| + resource_bundle_->GetRawDataResource(resource_id); |
| 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 |