Chromium Code Reviews| Index: content/browser/webui/shared_resources_data_source.cc |
| diff --git a/content/browser/webui/shared_resources_data_source.cc b/content/browser/webui/shared_resources_data_source.cc |
| index 2ce6e147b098dc598f75b2d7e0577de0256f26cb..0708094803d35e8419bc168454f5f6ec6599404d 100644 |
| --- a/content/browser/webui/shared_resources_data_source.cc |
| +++ b/content/browser/webui/shared_resources_data_source.cc |
| @@ -6,13 +6,18 @@ |
| #include "base/logging.h" |
| #include "base/memory/ref_counted_memory.h" |
| +#include "base/strings/string_piece.h" |
| #include "base/strings/string_util.h" |
| #include "base/threading/thread_restrictions.h" |
| #include "content/public/common/content_client.h" |
| #include "content/public/common/url_constants.h" |
| #include "net/base/mime_util.h" |
| +#include "ui/base/layout.h" |
| +#include "ui/resources/grit/webui_resources.h" |
| #include "ui/resources/grit/webui_resources_map.h" |
| +namespace content { |
| + |
| namespace { |
| const char kAppImagesPath[] = "images/apps/"; |
| @@ -63,18 +68,34 @@ SharedResourcesDataSource::~SharedResourcesDataSource() { |
| } |
| std::string SharedResourcesDataSource::GetSource() const { |
| - return content::kChromeUIResourcesHost; |
| + return kChromeUIResourcesHost; |
| } |
| void SharedResourcesDataSource::StartDataRequest( |
| const std::string& path, |
| int render_process_id, |
| int render_frame_id, |
| - const content::URLDataSource::GotDataCallback& callback) { |
| + const URLDataSource::GotDataCallback& callback) { |
| int idr = PathToIDR(path); |
| DCHECK_NE(-1, idr) << " path: " << path; |
| - scoped_refptr<base::RefCountedStaticMemory> bytes( |
| - content::GetContentClient()->GetDataResourceBytes(idr)); |
| + scoped_refptr<base::RefCountedMemory> bytes; |
| + |
| + ContentClient* content_client = GetContentClient(); |
| + if (idr == IDR_WEBUI_CSS_TEXT_DEFAULTS) { |
|
davidben
2014/11/25 22:29:34
It is also a little puzzling to me why this hooks
Dan Beam
2014/11/25 22:49:31
creis@ nor I know the preferred mechanism here (pa
|
| + std::vector<std::string> placeholders; |
| + WebUITextStyles text_styles = content_client->GetWebUITextStyles(); |
| + placeholders.push_back(text_styles.text_direction); // $1 |
| + placeholders.push_back(text_styles.font_family); // $2 |
| + placeholders.push_back(text_styles.font_size); // $3 |
| + |
| + const std::string& chrome_shared = |
| + content_client->GetDataResource(idr, ui::SCALE_FACTOR_NONE).as_string(); |
| + std::string replaced = |
| + ReplaceStringPlaceholders(chrome_shared, placeholders, nullptr); |
| + bytes = base::RefCountedString::TakeString(&replaced); |
| + } else { |
| + bytes = content_client->GetDataResourceBytes(idr); |
| + } |
| callback.Run(bytes.get()); |
| } |
| @@ -97,9 +118,11 @@ SharedResourcesDataSource::GetAccessControlAllowOriginForOrigin( |
| // According to CORS spec, Access-Control-Allow-Origin header doesn't support |
| // wildcards, so we need to set its value explicitly by passing the |origin| |
| // back. |
| - std::string allowed_origin_prefix = content::kChromeUIScheme; |
| + std::string allowed_origin_prefix = kChromeUIScheme; |
| allowed_origin_prefix += "://"; |
| if (origin.find(allowed_origin_prefix) != 0) |
| return "none"; |
| return origin; |
| } |
| + |
| +} // namespace content |