| 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 "base/containers/hash_tables.h" | 7 #include "base/containers/hash_tables.h" |
| 8 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "base/memory/ref_counted_memory.h" | 9 #include "base/memory/ref_counted_memory.h" |
| 10 #include "base/strings/string_piece.h" | 10 #include "base/strings/string_piece.h" |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 78 int render_process_id, | 78 int render_process_id, |
| 79 int render_frame_id, | 79 int render_frame_id, |
| 80 const URLDataSource::GotDataCallback& callback) { | 80 const URLDataSource::GotDataCallback& callback) { |
| 81 const ResourcesMap& resources_map = GetResourcesMap(); | 81 const ResourcesMap& resources_map = GetResourcesMap(); |
| 82 auto it = resources_map.find(path); | 82 auto it = resources_map.find(path); |
| 83 int idr = (it != resources_map.end()) ? it->second : -1; | 83 int idr = (it != resources_map.end()) ? it->second : -1; |
| 84 DCHECK_NE(-1, idr) << " path: " << path; | 84 DCHECK_NE(-1, idr) << " path: " << path; |
| 85 scoped_refptr<base::RefCountedMemory> bytes; | 85 scoped_refptr<base::RefCountedMemory> bytes; |
| 86 | 86 |
| 87 if (idr == IDR_WEBUI_CSS_TEXT_DEFAULTS) { | 87 if (idr == IDR_WEBUI_CSS_TEXT_DEFAULTS) { |
| 88 std::vector<std::string> placeholders; | 88 std::string css = webui::GetWebUICSSTextDefaults(); |
| 89 placeholders.push_back(webui::GetTextDirection()); // $1 | 89 bytes = base::RefCountedString::TakeString(&css); |
| 90 placeholders.push_back(webui::GetFontFamily()); // $2 | |
| 91 placeholders.push_back(webui::GetFontSize()); // $3 | |
| 92 | |
| 93 ContentClient* content_client = GetContentClient(); | |
| 94 const std::string& chrome_shared = | |
| 95 content_client->GetDataResource(idr, ui::SCALE_FACTOR_NONE).as_string(); | |
| 96 std::string replaced = | |
| 97 ReplaceStringPlaceholders(chrome_shared, placeholders, nullptr); | |
| 98 bytes = base::RefCountedString::TakeString(&replaced); | |
| 99 } else { | 90 } else { |
| 100 bytes = GetContentClient()->GetDataResourceBytes(idr); | 91 bytes = GetContentClient()->GetDataResourceBytes(idr); |
| 101 } | 92 } |
| 102 | 93 |
| 103 callback.Run(bytes.get()); | 94 callback.Run(bytes.get()); |
| 104 } | 95 } |
| 105 | 96 |
| 106 std::string SharedResourcesDataSource::GetMimeType( | 97 std::string SharedResourcesDataSource::GetMimeType( |
| 107 const std::string& path) const { | 98 const std::string& path) const { |
| 108 // Requests should not block on the disk! On POSIX this goes to disk. | 99 // Requests should not block on the disk! On POSIX this goes to disk. |
| (...skipping 13 matching lines...) Expand all Loading... |
| 122 // wildcards, so we need to set its value explicitly by passing the |origin| | 113 // wildcards, so we need to set its value explicitly by passing the |origin| |
| 123 // back. | 114 // back. |
| 124 std::string allowed_origin_prefix = kChromeUIScheme; | 115 std::string allowed_origin_prefix = kChromeUIScheme; |
| 125 allowed_origin_prefix += "://"; | 116 allowed_origin_prefix += "://"; |
| 126 if (origin.find(allowed_origin_prefix) != 0) | 117 if (origin.find(allowed_origin_prefix) != 0) |
| 127 return "null"; | 118 return "null"; |
| 128 return origin; | 119 return origin; |
| 129 } | 120 } |
| 130 | 121 |
| 131 } // namespace content | 122 } // namespace content |
| OLD | NEW |