string_source_map.cc 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. // Copyright 2016 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.
  4. #include "extensions/renderer/string_source_map.h"
  5. #include "gin/converter.h"
  6. #include "third_party/zlib/google/compression_utils.h"
  7. namespace extensions {
  8. StringSourceMap::StringSourceMap() {}
  9. StringSourceMap::~StringSourceMap() {}
  10. v8::Local<v8::String> StringSourceMap::GetSource(
  11. v8::Isolate* isolate,
  12. const std::string& name) const {
  13. const auto& iter = sources_.find(name);
  14. if (iter == sources_.end())
  15. return v8::Local<v8::String>();
  16. return gin::StringToV8(isolate, iter->second);
  17. }
  18. bool StringSourceMap::Contains(const std::string& name) const {
  19. return sources_.find(name) != sources_.end();
  20. }
  21. void StringSourceMap::RegisterModule(const std::string& name,
  22. const std::string& source,
  23. bool gzipped) {
  24. CHECK_EQ(0u, sources_.count(name)) << "A module for '" << name
  25. << "' already exists.";
  26. if (!gzipped) {
  27. sources_[name] = source;
  28. return;
  29. }
  30. std::string uncompressed;
  31. CHECK(compression::GzipUncompress(source, &uncompressed));
  32. sources_[name] = uncompressed;
  33. }
  34. } // namespace extensions