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 "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" |
| 11 #include "base/logging.h" | 11 #include "base/logging.h" |
| 12 #include "base/memory/ref_counted_memory.h" | 12 #include "base/memory/ref_counted_memory.h" |
| 13 #include "base/strings/string_piece.h" | 13 #include "base/strings/string_piece.h" |
| 14 #include "base/strings/string_util.h" | 14 #include "base/strings/string_util.h" |
| 15 #include "content/public/browser/browser_thread.h" | |
| 15 #include "content/public/common/content_client.h" | 16 #include "content/public/common/content_client.h" |
| 16 #include "content/public/common/url_constants.h" | 17 #include "content/public/common/url_constants.h" |
| 17 #include "ui/base/layout.h" | 18 #include "ui/base/layout.h" |
| 18 #include "ui/base/webui/web_ui_util.h" | 19 #include "ui/base/webui/web_ui_util.h" |
| 19 #include "ui/resources/grit/webui_resources.h" | 20 #include "ui/resources/grit/webui_resources.h" |
| 20 #include "ui/resources/grit/webui_resources_map.h" | 21 #include "ui/resources/grit/webui_resources_map.h" |
| 21 | 22 |
| 22 #if defined(OS_WIN) | 23 #if defined(OS_WIN) |
| 23 #include "base/strings/utf_string_conversions.h" | 24 #include "base/strings/utf_string_conversions.h" |
| 24 #endif | 25 #endif |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 89 auto it = resources_map.find(path); | 90 auto it = resources_map.find(path); |
| 90 int idr = (it != resources_map.end()) ? it->second : -1; | 91 int idr = (it != resources_map.end()) ? it->second : -1; |
| 91 DCHECK_NE(-1, idr) << " path: " << path; | 92 DCHECK_NE(-1, idr) << " path: " << path; |
| 92 scoped_refptr<base::RefCountedMemory> bytes; | 93 scoped_refptr<base::RefCountedMemory> bytes; |
| 93 | 94 |
| 94 if (idr == IDR_WEBUI_CSS_TEXT_DEFAULTS) { | 95 if (idr == IDR_WEBUI_CSS_TEXT_DEFAULTS) { |
| 95 std::string css = webui::GetWebUiCssTextDefaults(); | 96 std::string css = webui::GetWebUiCssTextDefaults(); |
| 96 bytes = base::RefCountedString::TakeString(&css); | 97 bytes = base::RefCountedString::TakeString(&css); |
| 97 } else if (idr == IDR_WEBUI_CSS_TEXT_DEFAULTS_MD) { | 98 } else if (idr == IDR_WEBUI_CSS_TEXT_DEFAULTS_MD) { |
| 98 std::string css = webui::GetWebUiCssTextDefaultsMd(); | 99 std::string css = webui::GetWebUiCssTextDefaultsMd(); |
| 99 bytes = base::RefCountedString::TakeString(&css); | 100 bytes = base::RefCountedString::TakeString(&css); |
|
Dan Beam
2017/02/23 00:27:56
these are the calls that actually ask for a gfx::F
| |
| 100 } else { | 101 } else { |
| 101 bytes = GetContentClient()->GetDataResourceBytes(idr); | 102 bytes = GetContentClient()->GetDataResourceBytes(idr); |
| 102 } | 103 } |
| 103 | 104 |
| 104 callback.Run(bytes.get()); | 105 callback.Run(bytes.get()); |
| 105 } | 106 } |
| 106 | 107 |
| 107 std::string SharedResourcesDataSource::GetMimeType( | 108 std::string SharedResourcesDataSource::GetMimeType( |
| 108 const std::string& path) const { | 109 const std::string& path) const { |
| 109 if (path.empty()) | 110 if (path.empty()) |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 141 if (extension == "woff2") | 142 if (extension == "woff2") |
| 142 return "application/font-woff2"; | 143 return "application/font-woff2"; |
| 143 | 144 |
| 144 NOTREACHED() << path; | 145 NOTREACHED() << path; |
| 145 return "text/plain"; | 146 return "text/plain"; |
| 146 } | 147 } |
| 147 | 148 |
| 148 scoped_refptr<base::SingleThreadTaskRunner> | 149 scoped_refptr<base::SingleThreadTaskRunner> |
| 149 SharedResourcesDataSource::TaskRunnerForRequestPath( | 150 SharedResourcesDataSource::TaskRunnerForRequestPath( |
| 150 const std::string& path) const { | 151 const std::string& path) const { |
| 152 // Use UI thread to load CSS since its construction touches non-thread-safe | |
| 153 // gfx::Font names in ui::ResourceBundle. | |
| 154 if (GetMimeType(path) == "text/css") | |
| 155 return BrowserThread::GetTaskRunnerForThread(BrowserThread::UI); | |
|
Dan Beam
2017/02/23 00:27:56
sorry, don't do this
Dan Beam
2017/02/23 00:32:26
and by that i mean, push all text/css to the UI th
tzik
2017/02/23 00:58:19
Updated.
tzik
2017/02/23 00:58:19
Hmm, I think it's unclear from this code that the
Dan Beam
2017/02/23 02:11:30
i'm fine with either
| |
| 151 return nullptr; | 156 return nullptr; |
| 152 } | 157 } |
| 153 | 158 |
| 154 std::string | 159 std::string |
| 155 SharedResourcesDataSource::GetAccessControlAllowOriginForOrigin( | 160 SharedResourcesDataSource::GetAccessControlAllowOriginForOrigin( |
| 156 const std::string& origin) const { | 161 const std::string& origin) const { |
| 157 // For now we give access only for "chrome://*" origins. | 162 // For now we give access only for "chrome://*" origins. |
| 158 // According to CORS spec, Access-Control-Allow-Origin header doesn't support | 163 // According to CORS spec, Access-Control-Allow-Origin header doesn't support |
| 159 // wildcards, so we need to set its value explicitly by passing the |origin| | 164 // wildcards, so we need to set its value explicitly by passing the |origin| |
| 160 // back. | 165 // back. |
| 161 std::string allowed_origin_prefix = kChromeUIScheme; | 166 std::string allowed_origin_prefix = kChromeUIScheme; |
| 162 allowed_origin_prefix += "://"; | 167 allowed_origin_prefix += "://"; |
| 163 if (!base::StartsWith(origin, allowed_origin_prefix, | 168 if (!base::StartsWith(origin, allowed_origin_prefix, |
| 164 base::CompareCase::SENSITIVE)) { | 169 base::CompareCase::SENSITIVE)) { |
| 165 return "null"; | 170 return "null"; |
| 166 } | 171 } |
| 167 return origin; | 172 return origin; |
| 168 } | 173 } |
| 169 | 174 |
| 170 } // namespace content | 175 } // namespace content |
| OLD | NEW |