Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(305)

Side by Side Diff: content/browser/webui/shared_resources_data_source.cc

Issue 1932753006: Figure out the MIME type of shared WebUI resources more efficiently (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: dcheck Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « content/browser/webui/shared_resources_data_source.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/logging.h" 11 #include "base/logging.h"
11 #include "base/memory/ref_counted_memory.h" 12 #include "base/memory/ref_counted_memory.h"
12 #include "base/strings/string_piece.h" 13 #include "base/strings/string_piece.h"
13 #include "base/strings/string_util.h" 14 #include "base/strings/string_util.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"
18 #include "ui/base/layout.h" 17 #include "ui/base/layout.h"
19 #include "ui/base/webui/web_ui_util.h" 18 #include "ui/base/webui/web_ui_util.h"
20 #include "ui/resources/grit/webui_resources.h" 19 #include "ui/resources/grit/webui_resources.h"
21 #include "ui/resources/grit/webui_resources_map.h" 20 #include "ui/resources/grit/webui_resources_map.h"
22 21
23 namespace content { 22 namespace content {
24 23
25 namespace { 24 namespace {
26 25
27 using ResourcesMap = base::hash_map<std::string, int>; 26 using ResourcesMap = base::hash_map<std::string, int>;
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
96 std::string css = webui::GetWebUiCssTextDefaultsMd(); 95 std::string css = webui::GetWebUiCssTextDefaultsMd();
97 bytes = base::RefCountedString::TakeString(&css); 96 bytes = base::RefCountedString::TakeString(&css);
98 } else { 97 } else {
99 bytes = GetContentClient()->GetDataResourceBytes(idr); 98 bytes = GetContentClient()->GetDataResourceBytes(idr);
100 } 99 }
101 100
102 callback.Run(bytes.get()); 101 callback.Run(bytes.get());
103 } 102 }
104 103
105 std::string SharedResourcesDataSource::GetMimeType( 104 std::string SharedResourcesDataSource::GetMimeType(
106 const std::string& path) const { 105 const std::string& path) const {
groby-ooo-7-16 2016/04/29 23:39:15 I still fail to understand why we couldn't run thi
Dan Beam 2016/04/30 00:32:34 Done.
107 // Requests should not block on the disk! On POSIX this goes to disk. 106 if (path.empty())
108 // http://code.google.com/p/chromium/issues/detail?id=59849 107 return "text/html";
109 108
110 base::ThreadRestrictions::ScopedAllowIO allow_io; 109 base::FilePath filepath(path);
groby-ooo-7-16 2016/04/29 23:39:16 I'd minimally prefer getting the extension once (p
Dan Beam 2016/04/30 00:32:34 Done.
111 std::string mime_type; 110 if (filepath.MatchesExtension(".html"))
Dan Beam 2016/04/29 22:39:36 list derived via magic (`find ui/webui/resources/
112 net::GetMimeTypeFromFile(base::FilePath().AppendASCII(path), &mime_type); 111 return "text/html";
113 return mime_type; 112
113 if (filepath.MatchesExtension(".css"))
114 return "text/css";
115
116 if (filepath.MatchesExtension(".js"))
117 return "application/javascript";
118
119 if (filepath.MatchesExtension(".png"))
120 return "image/png";
121
122 if (filepath.MatchesExtension(".gif"))
123 return "image/gif";
124
125 if (filepath.MatchesExtension(".svg"))
126 return "image/svg+xml";
127
128 if (filepath.MatchesExtension(".woff2"))
129 return "application/font-woff2";
130
131 NOTREACHED();
groby-ooo-7-16 2016/04/29 23:39:15 You want to do a CHECK here to force people to not
Dan Beam 2016/04/30 00:32:34 Done.
132 return "text/plain";
114 } 133 }
115 134
116 std::string 135 std::string
117 SharedResourcesDataSource::GetAccessControlAllowOriginForOrigin( 136 SharedResourcesDataSource::GetAccessControlAllowOriginForOrigin(
118 const std::string& origin) const { 137 const std::string& origin) const {
119 // For now we give access only for "chrome://*" origins. 138 // For now we give access only for "chrome://*" origins.
120 // According to CORS spec, Access-Control-Allow-Origin header doesn't support 139 // According to CORS spec, Access-Control-Allow-Origin header doesn't support
121 // wildcards, so we need to set its value explicitly by passing the |origin| 140 // wildcards, so we need to set its value explicitly by passing the |origin|
122 // back. 141 // back.
123 std::string allowed_origin_prefix = kChromeUIScheme; 142 std::string allowed_origin_prefix = kChromeUIScheme;
124 allowed_origin_prefix += "://"; 143 allowed_origin_prefix += "://";
125 if (origin.find(allowed_origin_prefix) != 0) 144 if (origin.find(allowed_origin_prefix) != 0)
126 return "null"; 145 return "null";
127 return origin; 146 return origin;
128 } 147 }
129 148
130 } // namespace content 149 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/webui/shared_resources_data_source.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698