Chromium Code Reviews| 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 "content/browser/webui/shared_resources_data_source.h" | 5 #include "content/browser/webui/shared_resources_data_source.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <set> | |
| 10 | |
| 9 #include "base/containers/hash_tables.h" | 11 #include "base/containers/hash_tables.h" |
| 10 #include "base/files/file_path.h" | 12 #include "base/files/file_path.h" |
| 11 #include "base/logging.h" | 13 #include "base/logging.h" |
| 12 #include "base/memory/ref_counted_memory.h" | 14 #include "base/memory/ref_counted_memory.h" |
| 13 #include "base/strings/string_piece.h" | 15 #include "base/strings/string_piece.h" |
| 14 #include "base/strings/string_util.h" | 16 #include "base/strings/string_util.h" |
| 15 #include "content/public/browser/browser_thread.h" | 17 #include "content/public/browser/browser_thread.h" |
| 16 #include "content/public/common/content_client.h" | 18 #include "content/public/common/content_client.h" |
| 17 #include "content/public/common/url_constants.h" | 19 #include "content/public/common/url_constants.h" |
| 18 #include "ui/base/layout.h" | 20 #include "ui/base/layout.h" |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 39 {"../../views/resources/default_200_percent/common/", "images/2x/apps/"}, | 41 {"../../views/resources/default_200_percent/common/", "images/2x/apps/"}, |
| 40 {"../../webui/resources/cr_elements/", "cr_elements/"}}; | 42 {"../../webui/resources/cr_elements/", "cr_elements/"}}; |
| 41 | 43 |
| 42 const struct { | 44 const struct { |
| 43 const char* const path; | 45 const char* const path; |
| 44 const int resource_id; | 46 const int resource_id; |
| 45 } kAdditionalResourceMapEntries[] = { | 47 } kAdditionalResourceMapEntries[] = { |
| 46 {"js/mojo_bindings.js", IDR_WEBUI_MOJO_BINDINGS_JS}, | 48 {"js/mojo_bindings.js", IDR_WEBUI_MOJO_BINDINGS_JS}, |
| 47 }; | 49 }; |
| 48 | 50 |
| 51 const char* const kGzippedPaths[] = {"js/mojo_bindings.js"}; | |
| 52 | |
| 49 void AddResource(const std::string& path, | 53 void AddResource(const std::string& path, |
| 50 int resource_id, | 54 int resource_id, |
| 51 ResourcesMap* resources_map) { | 55 ResourcesMap* resources_map) { |
| 52 if (!resources_map->insert(std::make_pair(path, resource_id)).second) | 56 if (!resources_map->insert(std::make_pair(path, resource_id)).second) |
| 53 NOTREACHED() << "Redefinition of '" << path << "'"; | 57 NOTREACHED() << "Redefinition of '" << path << "'"; |
| 54 } | 58 } |
| 55 | 59 |
| 56 const ResourcesMap* CreateResourcesMap() { | 60 const ResourcesMap* CreateResourcesMap() { |
| 57 ResourcesMap* result = new ResourcesMap(); | 61 ResourcesMap* result = new ResourcesMap(); |
| 58 for (size_t i = 0; i < kWebuiResourcesSize; ++i) { | 62 for (size_t i = 0; i < kWebuiResourcesSize; ++i) { |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 79 static const ResourcesMap* resources_map = CreateResourcesMap(); | 83 static const ResourcesMap* resources_map = CreateResourcesMap(); |
| 80 return *resources_map; | 84 return *resources_map; |
| 81 } | 85 } |
| 82 | 86 |
| 83 int GetIdrForPath(const std::string& path) { | 87 int GetIdrForPath(const std::string& path) { |
| 84 const ResourcesMap& resources_map = GetResourcesMap(); | 88 const ResourcesMap& resources_map = GetResourcesMap(); |
| 85 auto it = resources_map.find(path); | 89 auto it = resources_map.find(path); |
| 86 return it != resources_map.end() ? it->second : -1; | 90 return it != resources_map.end() ? it->second : -1; |
| 87 } | 91 } |
| 88 | 92 |
| 93 const std::set<std::string>* CreateGzippedPathSet() { | |
| 94 std::set<std::string>* result = new std::set<std::string>(); | |
| 95 for (size_t i = 0; i < arraysize(kGzippedPaths); ++i) | |
| 96 result->insert(std::string(kGzippedPaths[i])); | |
| 97 return result; | |
| 98 } | |
| 99 | |
| 100 const std::set<std::string>& GetGzippedPathSet() { | |
| 101 // This pointer will be intentionally leaked on shutdown. | |
| 102 static const std::set<std::string>* gzipped_path_set = CreateGzippedPathSet(); | |
| 103 return *gzipped_path_set; | |
| 104 } | |
| 105 | |
| 89 } // namespace | 106 } // namespace |
| 90 | 107 |
| 91 SharedResourcesDataSource::SharedResourcesDataSource() { | 108 SharedResourcesDataSource::SharedResourcesDataSource() { |
| 92 } | 109 } |
| 93 | 110 |
| 94 SharedResourcesDataSource::~SharedResourcesDataSource() { | 111 SharedResourcesDataSource::~SharedResourcesDataSource() { |
| 95 } | 112 } |
| 96 | 113 |
| 97 std::string SharedResourcesDataSource::GetSource() const { | 114 std::string SharedResourcesDataSource::GetSource() const { |
| 98 return kChromeUIResourcesHost; | 115 return kChromeUIResourcesHost; |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 189 // back. | 206 // back. |
| 190 std::string allowed_origin_prefix = kChromeUIScheme; | 207 std::string allowed_origin_prefix = kChromeUIScheme; |
| 191 allowed_origin_prefix += "://"; | 208 allowed_origin_prefix += "://"; |
| 192 if (!base::StartsWith(origin, allowed_origin_prefix, | 209 if (!base::StartsWith(origin, allowed_origin_prefix, |
| 193 base::CompareCase::SENSITIVE)) { | 210 base::CompareCase::SENSITIVE)) { |
| 194 return "null"; | 211 return "null"; |
| 195 } | 212 } |
| 196 return origin; | 213 return origin; |
| 197 } | 214 } |
| 198 | 215 |
| 216 bool SharedResourcesDataSource::IsGzipped(const std::string& path) const { | |
| 217 const auto& gzipped_path_set = GetGzippedPathSet(); | |
| 218 return gzipped_path_set.find(path) != gzipped_path_set.end(); | |
|
Dan Beam
2017/06/09 01:05:28
can't this all just be
return path == "js/mojo_bi
yzshen1
2017/06/09 07:07:10
Yes. It can. :) Done.
| |
| 219 } | |
| 220 | |
| 199 } // namespace content | 221 } // namespace content |
| OLD | NEW |