| 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/url_data_manager_backend.h" | 5 #include "content/browser/webui/url_data_manager_backend.h" |
| 6 | 6 |
| 7 #include <set> | 7 #include <set> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
| (...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 178 } | 178 } |
| 179 | 179 |
| 180 void set_send_content_type_header(bool send_content_type_header) { | 180 void set_send_content_type_header(bool send_content_type_header) { |
| 181 send_content_type_header_ = send_content_type_header; | 181 send_content_type_header_ = send_content_type_header; |
| 182 } | 182 } |
| 183 | 183 |
| 184 void set_access_control_allow_origin(const std::string& value) { | 184 void set_access_control_allow_origin(const std::string& value) { |
| 185 access_control_allow_origin_ = value; | 185 access_control_allow_origin_ = value; |
| 186 } | 186 } |
| 187 | 187 |
| 188 void set_preload_headers(const std::vector<std::string>& preload_headers) { |
| 189 preload_headers_ = preload_headers; |
| 190 } |
| 191 |
| 188 // Returns true when job was generated from an incognito profile. | 192 // Returns true when job was generated from an incognito profile. |
| 189 bool is_incognito() const { | 193 bool is_incognito() const { |
| 190 return is_incognito_; | 194 return is_incognito_; |
| 191 } | 195 } |
| 192 | 196 |
| 193 private: | 197 private: |
| 194 ~URLRequestChromeJob() override; | 198 ~URLRequestChromeJob() override; |
| 195 | 199 |
| 196 // Helper for Start(), to let us start asynchronously. | 200 // Helper for Start(), to let us start asynchronously. |
| 197 // (This pattern is shared by most net::URLRequestJob implementations.) | 201 // (This pattern is shared by most net::URLRequestJob implementations.) |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 240 // If true, sets the "Content-Type: <mime-type>" header. | 244 // If true, sets the "Content-Type: <mime-type>" header. |
| 241 bool send_content_type_header_; | 245 bool send_content_type_header_; |
| 242 | 246 |
| 243 // If not empty, "Access-Control-Allow-Origin:" is set to the value of this | 247 // If not empty, "Access-Control-Allow-Origin:" is set to the value of this |
| 244 // string. | 248 // string. |
| 245 std::string access_control_allow_origin_; | 249 std::string access_control_allow_origin_; |
| 246 | 250 |
| 247 // True when job is generated from an incognito profile. | 251 // True when job is generated from an incognito profile. |
| 248 const bool is_incognito_; | 252 const bool is_incognito_; |
| 249 | 253 |
| 254 std::vector<std::string> preload_headers_; |
| 255 |
| 250 // The backend is owned by net::URLRequestContext and always outlives us. | 256 // The backend is owned by net::URLRequestContext and always outlives us. |
| 251 URLDataManagerBackend* backend_; | 257 URLDataManagerBackend* backend_; |
| 252 | 258 |
| 253 base::WeakPtrFactory<URLRequestChromeJob> weak_factory_; | 259 base::WeakPtrFactory<URLRequestChromeJob> weak_factory_; |
| 254 | 260 |
| 255 DISALLOW_COPY_AND_ASSIGN(URLRequestChromeJob); | 261 DISALLOW_COPY_AND_ASSIGN(URLRequestChromeJob); |
| 256 }; | 262 }; |
| 257 | 263 |
| 258 URLRequestChromeJob::URLRequestChromeJob(net::URLRequest* request, | 264 URLRequestChromeJob::URLRequestChromeJob(net::URLRequest* request, |
| 259 net::NetworkDelegate* network_delegate, | 265 net::NetworkDelegate* network_delegate, |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 348 base::StringPrintf("%s:%s", net::HttpRequestHeaders::kContentType, | 354 base::StringPrintf("%s:%s", net::HttpRequestHeaders::kContentType, |
| 349 mime_type_.c_str()); | 355 mime_type_.c_str()); |
| 350 info->headers->AddHeader(content_type); | 356 info->headers->AddHeader(content_type); |
| 351 } | 357 } |
| 352 | 358 |
| 353 if (!access_control_allow_origin_.empty()) { | 359 if (!access_control_allow_origin_.empty()) { |
| 354 info->headers->AddHeader("Access-Control-Allow-Origin: " + | 360 info->headers->AddHeader("Access-Control-Allow-Origin: " + |
| 355 access_control_allow_origin_); | 361 access_control_allow_origin_); |
| 356 info->headers->AddHeader("Vary: Origin"); | 362 info->headers->AddHeader("Vary: Origin"); |
| 357 } | 363 } |
| 364 |
| 365 for (const std::string& preload_header : preload_headers_) { |
| 366 info->headers->AddHeader(preload_header); |
| 367 } |
| 358 } | 368 } |
| 359 | 369 |
| 360 void URLRequestChromeJob::MimeTypeAvailable(const std::string& mime_type) { | 370 void URLRequestChromeJob::MimeTypeAvailable(const std::string& mime_type) { |
| 361 set_mime_type(mime_type); | 371 set_mime_type(mime_type); |
| 362 NotifyHeadersComplete(); | 372 NotifyHeadersComplete(); |
| 363 } | 373 } |
| 364 | 374 |
| 365 void URLRequestChromeJob::DataAvailable(base::RefCountedMemory* bytes) { | 375 void URLRequestChromeJob::DataAvailable(base::RefCountedMemory* bytes) { |
| 366 TRACE_EVENT_ASYNC_END0("browser", "DataManager:Request", this); | 376 TRACE_EVENT_ASYNC_END0("browser", "DataManager:Request", this); |
| 367 if (bytes) { | 377 if (bytes) { |
| (...skipping 260 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 628 job->set_content_security_policy_child_source( | 638 job->set_content_security_policy_child_source( |
| 629 source->source()->GetContentSecurityPolicyChildSrc()); | 639 source->source()->GetContentSecurityPolicyChildSrc()); |
| 630 job->set_content_security_policy_style_source( | 640 job->set_content_security_policy_style_source( |
| 631 source->source()->GetContentSecurityPolicyStyleSrc()); | 641 source->source()->GetContentSecurityPolicyStyleSrc()); |
| 632 job->set_content_security_policy_image_source( | 642 job->set_content_security_policy_image_source( |
| 633 source->source()->GetContentSecurityPolicyImgSrc()); | 643 source->source()->GetContentSecurityPolicyImgSrc()); |
| 634 job->set_deny_xframe_options( | 644 job->set_deny_xframe_options( |
| 635 source->source()->ShouldDenyXFrameOptions()); | 645 source->source()->ShouldDenyXFrameOptions()); |
| 636 job->set_send_content_type_header( | 646 job->set_send_content_type_header( |
| 637 source->source()->ShouldServeMimeTypeAsContentTypeHeader()); | 647 source->source()->ShouldServeMimeTypeAsContentTypeHeader()); |
| 648 job->set_preload_headers(source->source()->GetPreloadHeaders()); |
| 638 | 649 |
| 639 std::string origin = GetOriginHeaderValue(request); | 650 std::string origin = GetOriginHeaderValue(request); |
| 640 if (!origin.empty()) { | 651 if (!origin.empty()) { |
| 641 std::string header = | 652 std::string header = |
| 642 source->source()->GetAccessControlAllowOriginForOrigin(origin); | 653 source->source()->GetAccessControlAllowOriginForOrigin(origin); |
| 643 DCHECK(header.empty() || header == origin || header == "*" || | 654 DCHECK(header.empty() || header == origin || header == "*" || |
| 644 header == "null"); | 655 header == "null"); |
| 645 job->set_access_control_allow_origin(header); | 656 job->set_access_control_allow_origin(header); |
| 646 } | 657 } |
| 647 | 658 |
| (...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 794 | 805 |
| 795 } // namespace | 806 } // namespace |
| 796 | 807 |
| 797 net::URLRequestJobFactory::ProtocolHandler* | 808 net::URLRequestJobFactory::ProtocolHandler* |
| 798 CreateDevToolsProtocolHandler(content::ResourceContext* resource_context, | 809 CreateDevToolsProtocolHandler(content::ResourceContext* resource_context, |
| 799 bool is_incognito) { | 810 bool is_incognito) { |
| 800 return new DevToolsJobFactory(resource_context, is_incognito); | 811 return new DevToolsJobFactory(resource_context, is_incognito); |
| 801 } | 812 } |
| 802 | 813 |
| 803 } // namespace content | 814 } // namespace content |
| OLD | NEW |