| 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/files/file_path.h" | 10 #include "base/files/file_path.h" |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 105 callback.Run(bytes.get()); | 105 callback.Run(bytes.get()); |
| 106 } | 106 } |
| 107 | 107 |
| 108 std::string SharedResourcesDataSource::GetMimeType( | 108 std::string SharedResourcesDataSource::GetMimeType( |
| 109 const std::string& path) const { | 109 const std::string& path) const { |
| 110 if (path.empty()) | 110 if (path.empty()) |
| 111 return "text/html"; | 111 return "text/html"; |
| 112 | 112 |
| 113 #if defined(OS_WIN) | 113 #if defined(OS_WIN) |
| 114 base::FilePath file(base::UTF8ToWide(path)); | 114 base::FilePath file(base::UTF8ToWide(path)); |
| 115 std::string extension = base::WideToUTF8(file.FinalExtension()).substr(1); | 115 std::string extension = base::WideToUTF8(file.FinalExtension()); |
| 116 #else | 116 #else |
| 117 base::FilePath file(path); | 117 base::FilePath file(path); |
| 118 std::string extension = file.FinalExtension().substr(1); | 118 std::string extension = file.FinalExtension(); |
| 119 #endif | 119 #endif |
| 120 | 120 |
| 121 if (!extension.empty()) |
| 122 extension.erase(0, 1); |
| 123 |
| 121 if (extension == "html") | 124 if (extension == "html") |
| 122 return "text/html"; | 125 return "text/html"; |
| 123 | 126 |
| 124 if (extension == "css") | 127 if (extension == "css") |
| 125 return "text/css"; | 128 return "text/css"; |
| 126 | 129 |
| 127 if (extension == "js") | 130 if (extension == "js") |
| 128 return "application/javascript"; | 131 return "application/javascript"; |
| 129 | 132 |
| 130 if (extension == "png") | 133 if (extension == "png") |
| 131 return "image/png"; | 134 return "image/png"; |
| 132 | 135 |
| 133 if (extension == "gif") | 136 if (extension == "gif") |
| 134 return "image/gif"; | 137 return "image/gif"; |
| 135 | 138 |
| 136 if (extension == "svg") | 139 if (extension == "svg") |
| 137 return "image/svg+xml"; | 140 return "image/svg+xml"; |
| 138 | 141 |
| 139 if (extension == "woff2") | 142 if (extension == "woff2") |
| 140 return "application/font-woff2"; | 143 return "application/font-woff2"; |
| 141 | 144 |
| 142 CHECK(false) << path; | 145 NOTREACHED() << path; |
| 143 return "text/plain"; | 146 return "text/plain"; |
| 144 } | 147 } |
| 145 | 148 |
| 146 base::MessageLoop* SharedResourcesDataSource::MessageLoopForRequestPath( | 149 base::MessageLoop* SharedResourcesDataSource::MessageLoopForRequestPath( |
| 147 const std::string& path) const { | 150 const std::string& path) const { |
| 148 return nullptr; | 151 return nullptr; |
| 149 } | 152 } |
| 150 | 153 |
| 151 std::string | 154 std::string |
| 152 SharedResourcesDataSource::GetAccessControlAllowOriginForOrigin( | 155 SharedResourcesDataSource::GetAccessControlAllowOriginForOrigin( |
| 153 const std::string& origin) const { | 156 const std::string& origin) const { |
| 154 // For now we give access only for "chrome://*" origins. | 157 // For now we give access only for "chrome://*" origins. |
| 155 // According to CORS spec, Access-Control-Allow-Origin header doesn't support | 158 // According to CORS spec, Access-Control-Allow-Origin header doesn't support |
| 156 // wildcards, so we need to set its value explicitly by passing the |origin| | 159 // wildcards, so we need to set its value explicitly by passing the |origin| |
| 157 // back. | 160 // back. |
| 158 std::string allowed_origin_prefix = kChromeUIScheme; | 161 std::string allowed_origin_prefix = kChromeUIScheme; |
| 159 allowed_origin_prefix += "://"; | 162 allowed_origin_prefix += "://"; |
| 160 if (origin.find(allowed_origin_prefix) != 0) | 163 if (origin.find(allowed_origin_prefix) != 0) |
| 161 return "null"; | 164 return "null"; |
| 162 return origin; | 165 return origin; |
| 163 } | 166 } |
| 164 | 167 |
| 165 } // namespace content | 168 } // namespace content |
| OLD | NEW |