| 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 "base/containers/hash_tables.h" | 9 #include "base/containers/hash_tables.h" |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| 11 #include "base/memory/ref_counted_memory.h" | 11 #include "base/memory/ref_counted_memory.h" |
| 12 #include "base/strings/string_piece.h" | 12 #include "base/strings/string_piece.h" |
| 13 #include "base/strings/string_util.h" | 13 #include "base/strings/string_util.h" |
| 14 #include "base/threading/thread_restrictions.h" | 14 #include "base/threading/thread_restrictions.h" |
| 15 #include "content/public/common/content_client.h" | 15 #include "content/public/common/content_client.h" |
| 16 #include "content/public/common/url_constants.h" | 16 #include "content/public/common/url_constants.h" |
| 17 #include "net/base/mime_util.h" | 17 #include "net/base/mime_util.h" |
| 18 #include "ui/base/layout.h" | 18 #include "ui/base/layout.h" |
| 19 #include "ui/base/webui/web_ui_util.h" | 19 #include "ui/base/webui/web_ui_util.h" |
| 20 #include "ui/resources/grit/webui_resources.h" | 20 #include "ui/resources/grit/webui_resources.h" |
| 21 #include "ui/resources/grit/webui_resources_map.h" | 21 #include "ui/resources/grit/webui_resources_map.h" |
| 22 | 22 |
| 23 namespace content { | 23 namespace content { |
| 24 | 24 |
| 25 namespace { | 25 namespace { |
| 26 | 26 |
| 27 using ResourcesMap = base::hash_map<std::string, int>; | 27 using ResourcesMap = base::hash_map<std::string, int>; |
| 28 | 28 |
| 29 // TODO(rkc): Once we have a separate source for apps, remove '*/apps/' aliases. | 29 // TODO(rkc): Once we have a separate source for apps, remove '*/apps/' aliases. |
| 30 const char* kPathAliases[][2] = { | 30 const char* const kPathAliases[][2] = { |
| 31 {"../../../third_party/polymer/v1_0/components-chromium/", "polymer/v1_0/"}, | 31 {"../../../third_party/polymer/v1_0/components-chromium/", "polymer/v1_0/"}, |
| 32 {"../../../third_party/web-animations-js/sources/", | 32 {"../../../third_party/web-animations-js/sources/", |
| 33 "polymer/v1_0/web-animations-js/"}, | 33 "polymer/v1_0/web-animations-js/"}, |
| 34 {"../../views/resources/default_100_percent/common/", "images/apps/"}, | 34 {"../../views/resources/default_100_percent/common/", "images/apps/"}, |
| 35 {"../../views/resources/default_200_percent/common/", "images/2x/apps/"}, | 35 {"../../views/resources/default_200_percent/common/", "images/2x/apps/"}, |
| 36 {"../../webui/resources/cr_elements/", "cr_elements/"}}; | 36 {"../../webui/resources/cr_elements/", "cr_elements/"}}; |
| 37 | 37 |
| 38 void AddResource(const std::string& path, | 38 void AddResource(const std::string& path, |
| 39 int resource_id, | 39 int resource_id, |
| 40 ResourcesMap* resources_map) { | 40 ResourcesMap* resources_map) { |
| 41 if (!resources_map->insert(std::make_pair(path, resource_id)).second) | 41 if (!resources_map->insert(std::make_pair(path, resource_id)).second) |
| 42 NOTREACHED() << "Redefinition of '" << path << "'"; | 42 NOTREACHED() << "Redefinition of '" << path << "'"; |
| 43 } | 43 } |
| 44 | 44 |
| 45 const ResourcesMap* CreateResourcesMap() { | 45 const ResourcesMap* CreateResourcesMap() { |
| 46 ResourcesMap* result = new ResourcesMap(); | 46 ResourcesMap* result = new ResourcesMap(); |
| 47 for (size_t i = 0; i < kWebuiResourcesSize; ++i) { | 47 for (size_t i = 0; i < kWebuiResourcesSize; ++i) { |
| 48 const std::string resource_name = kWebuiResources[i].name; | 48 const std::string resource_name = kWebuiResources[i].name; |
| 49 const int resource_id = kWebuiResources[i].value; | 49 const int resource_id = kWebuiResources[i].value; |
| 50 AddResource(resource_name, resource_id, result); | 50 AddResource(resource_name, resource_id, result); |
| 51 for (const char* (&alias)[2]: kPathAliases) { | 51 for (const char* const (&alias)[2] : kPathAliases) { |
| 52 if (base::StartsWith(resource_name, alias[0], | 52 if (base::StartsWith(resource_name, alias[0], |
| 53 base::CompareCase::SENSITIVE)) { | 53 base::CompareCase::SENSITIVE)) { |
| 54 AddResource(alias[1] + resource_name.substr(strlen(alias[0])), | 54 AddResource(alias[1] + resource_name.substr(strlen(alias[0])), |
| 55 resource_id, result); | 55 resource_id, result); |
| 56 } | 56 } |
| 57 } | 57 } |
| 58 } | 58 } |
| 59 | 59 |
| 60 return result; | 60 return result; |
| 61 } | 61 } |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 121 // wildcards, so we need to set its value explicitly by passing the |origin| | 121 // wildcards, so we need to set its value explicitly by passing the |origin| |
| 122 // back. | 122 // back. |
| 123 std::string allowed_origin_prefix = kChromeUIScheme; | 123 std::string allowed_origin_prefix = kChromeUIScheme; |
| 124 allowed_origin_prefix += "://"; | 124 allowed_origin_prefix += "://"; |
| 125 if (origin.find(allowed_origin_prefix) != 0) | 125 if (origin.find(allowed_origin_prefix) != 0) |
| 126 return "null"; | 126 return "null"; |
| 127 return origin; | 127 return origin; |
| 128 } | 128 } |
| 129 | 129 |
| 130 } // namespace content | 130 } // namespace content |
| OLD | NEW |