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 "chrome/browser/ui/webui/chrome_url_data_manager_backend.h" | 5 #include "chrome/browser/ui/webui/chrome_url_data_manager_backend.h" |
6 | 6 |
7 #include <set> | 7 #include <set> |
8 | 8 |
9 #include "base/basictypes.h" | 9 #include "base/basictypes.h" |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
119 g_chrome_url_content_security_policy_object_tag_set.Pointer(); | 119 g_chrome_url_content_security_policy_object_tag_set.Pointer(); |
120 | 120 |
121 base.append(object_tag_set->find(url.host()) == object_tag_set->end() ? | 121 base.append(object_tag_set->find(url.host()) == object_tag_set->end() ? |
122 "object-src 'none';" : | 122 "object-src 'none';" : |
123 "object-src 'self';"); | 123 "object-src 'self';"); |
124 | 124 |
125 headers->AddHeader(base); | 125 headers->AddHeader(base); |
126 } | 126 } |
127 } | 127 } |
128 | 128 |
| 129 const char kChromeURLXFrameOptionsHeader[] = "X-Frame-Options: DENY"; |
| 130 |
| 131 // It is OK to add exceptions to this set as needed. |
| 132 class ChromeURLXFrameOptionsExceptionSet |
| 133 : public std::set<std::string> { |
| 134 public: |
| 135 ChromeURLXFrameOptionsExceptionSet() : std::set<std::string>() { |
| 136 insert(chrome::kChromeUIExtensionsFrameHost); |
| 137 insert(chrome::kChromeUIHelpFrameHost); |
| 138 insert(chrome::kChromeUIHistoryFrameHost); |
| 139 insert(chrome::kChromeUISettingsFrameHost); |
| 140 insert(chrome::kChromeUIUberFrameHost); |
| 141 } |
| 142 }; |
| 143 |
| 144 base::LazyInstance<ChromeURLXFrameOptionsExceptionSet> |
| 145 g_chrome_url_x_frame_options_exception_set = LAZY_INSTANCE_INITIALIZER; |
| 146 |
| 147 void AddXFrameOptionsHeader( |
| 148 const GURL& url, net::HttpResponseHeaders* headers) { |
| 149 ChromeURLXFrameOptionsExceptionSet* exceptions = |
| 150 g_chrome_url_x_frame_options_exception_set.Pointer(); |
| 151 if (exceptions->find(url.host()) == exceptions->end()) |
| 152 headers->AddHeader(kChromeURLXFrameOptionsHeader); |
| 153 } |
| 154 |
129 // Parse a URL into the components used to resolve its request. |source_name| | 155 // Parse a URL into the components used to resolve its request. |source_name| |
130 // is the hostname and |path| is the remaining portion of the URL. | 156 // is the hostname and |path| is the remaining portion of the URL. |
131 void URLToRequest(const GURL& url, std::string* source_name, | 157 void URLToRequest(const GURL& url, std::string* source_name, |
132 std::string* path) { | 158 std::string* path) { |
133 DCHECK(url.SchemeIs(chrome::kChromeDevToolsScheme) || | 159 DCHECK(url.SchemeIs(chrome::kChromeDevToolsScheme) || |
134 url.SchemeIs(chrome::kChromeUIScheme)); | 160 url.SchemeIs(chrome::kChromeUIScheme)); |
135 | 161 |
136 if (!url.is_valid()) { | 162 if (!url.is_valid()) { |
137 NOTREACHED(); | 163 NOTREACHED(); |
138 return; | 164 return; |
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
258 return !mime_type_.empty(); | 284 return !mime_type_.empty(); |
259 } | 285 } |
260 | 286 |
261 void URLRequestChromeJob::GetResponseInfo(net::HttpResponseInfo* info) { | 287 void URLRequestChromeJob::GetResponseInfo(net::HttpResponseInfo* info) { |
262 DCHECK(!info->headers); | 288 DCHECK(!info->headers); |
263 // Set the headers so that requests serviced by ChromeURLDataManager return a | 289 // Set the headers so that requests serviced by ChromeURLDataManager return a |
264 // status code of 200. Without this they return a 0, which makes the status | 290 // status code of 200. Without this they return a 0, which makes the status |
265 // indistiguishable from other error types. Instant relies on getting a 200. | 291 // indistiguishable from other error types. Instant relies on getting a 200. |
266 info->headers = new net::HttpResponseHeaders("HTTP/1.1 200 OK"); | 292 info->headers = new net::HttpResponseHeaders("HTTP/1.1 200 OK"); |
267 AddContentSecurityPolicyHeader(request_->url(), info->headers); | 293 AddContentSecurityPolicyHeader(request_->url(), info->headers); |
| 294 AddXFrameOptionsHeader(request_->url(), info->headers); |
268 if (!allow_caching_) | 295 if (!allow_caching_) |
269 info->headers->AddHeader("Cache-Control: no-cache"); | 296 info->headers->AddHeader("Cache-Control: no-cache"); |
270 } | 297 } |
271 | 298 |
272 void URLRequestChromeJob::MimeTypeAvailable(const std::string& mime_type) { | 299 void URLRequestChromeJob::MimeTypeAvailable(const std::string& mime_type) { |
273 set_mime_type(mime_type); | 300 set_mime_type(mime_type); |
274 NotifyHeadersComplete(); | 301 NotifyHeadersComplete(); |
275 } | 302 } |
276 | 303 |
277 void URLRequestChromeJob::DataAvailable(base::RefCountedMemory* bytes) { | 304 void URLRequestChromeJob::DataAvailable(base::RefCountedMemory* bytes) { |
(...skipping 326 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
604 return new URLRequestChromeJob(request, backend_); | 631 return new URLRequestChromeJob(request, backend_); |
605 } | 632 } |
606 | 633 |
607 } // namespace | 634 } // namespace |
608 | 635 |
609 net::URLRequestJobFactory::ProtocolHandler* | 636 net::URLRequestJobFactory::ProtocolHandler* |
610 CreateDevToolsProtocolHandler(ChromeURLDataManagerBackend* backend, | 637 CreateDevToolsProtocolHandler(ChromeURLDataManagerBackend* backend, |
611 net::NetworkDelegate* network_delegate) { | 638 net::NetworkDelegate* network_delegate) { |
612 return new DevToolsJobFactory(backend, network_delegate); | 639 return new DevToolsJobFactory(backend, network_delegate); |
613 } | 640 } |
OLD | NEW |