| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/renderer/resource_bundle_source_map.h" | 5 #include "chrome/renderer/resource_bundle_source_map.h" |
| 6 | 6 |
| 7 #include "ui/base/resource/resource_bundle.h" | 7 #include "ui/base/resource/resource_bundle.h" |
| 8 | 8 |
| 9 ResourceBundleSourceMap::ResourceBundleSourceMap( | 9 ResourceBundleSourceMap::ResourceBundleSourceMap( |
| 10 const ui::ResourceBundle* resource_bundle) | 10 const ui::ResourceBundle* resource_bundle) |
| (...skipping 10 matching lines...) Expand all Loading... |
| 21 | 21 |
| 22 v8::Handle<v8::Value> ResourceBundleSourceMap::GetSource( | 22 v8::Handle<v8::Value> ResourceBundleSourceMap::GetSource( |
| 23 const std::string& name) { | 23 const std::string& name) { |
| 24 if (!Contains(name)) | 24 if (!Contains(name)) |
| 25 return v8::Undefined(); | 25 return v8::Undefined(); |
| 26 int resource_id = resource_id_map_[name]; | 26 int resource_id = resource_id_map_[name]; |
| 27 return ConvertString(resource_bundle_->GetRawDataResource(resource_id)); | 27 return ConvertString(resource_bundle_->GetRawDataResource(resource_id)); |
| 28 } | 28 } |
| 29 | 29 |
| 30 bool ResourceBundleSourceMap::Contains(const std::string& name) { | 30 bool ResourceBundleSourceMap::Contains(const std::string& name) { |
| 31 return resource_id_map_.count(name) > 0; | 31 return !!resource_id_map_.count(name); |
| 32 } | 32 } |
| 33 | 33 |
| 34 v8::Handle<v8::String> ResourceBundleSourceMap::ConvertString( | 34 v8::Handle<v8::String> ResourceBundleSourceMap::ConvertString( |
| 35 const base::StringPiece& string) { | 35 const base::StringPiece& string) { |
| 36 // v8 takes ownership of the StaticV8ExternalAsciiStringResource (see | 36 // v8 takes ownership of the StaticV8ExternalAsciiStringResource (see |
| 37 // v8::String::NewExternal()). | 37 // v8::String::NewExternal()). |
| 38 return v8::String::NewExternal( | 38 return v8::String::NewExternal( |
| 39 new StaticV8ExternalAsciiStringResource(string)); | 39 new StaticV8ExternalAsciiStringResource(string)); |
| 40 } | 40 } |
| OLD | NEW |