| 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 20 matching lines...) Expand all Loading... |
| 31 #include "content/browser/webui/shared_resources_data_source.h" | 31 #include "content/browser/webui/shared_resources_data_source.h" |
| 32 #include "content/browser/webui/url_data_source_impl.h" | 32 #include "content/browser/webui/url_data_source_impl.h" |
| 33 #include "content/public/browser/browser_context.h" | 33 #include "content/public/browser/browser_context.h" |
| 34 #include "content/public/browser/browser_thread.h" | 34 #include "content/public/browser/browser_thread.h" |
| 35 #include "content/public/browser/content_browser_client.h" | 35 #include "content/public/browser/content_browser_client.h" |
| 36 #include "content/public/browser/render_process_host.h" | 36 #include "content/public/browser/render_process_host.h" |
| 37 #include "content/public/browser/resource_request_info.h" | 37 #include "content/public/browser/resource_request_info.h" |
| 38 #include "content/public/common/url_constants.h" | 38 #include "content/public/common/url_constants.h" |
| 39 #include "net/base/io_buffer.h" | 39 #include "net/base/io_buffer.h" |
| 40 #include "net/base/net_errors.h" | 40 #include "net/base/net_errors.h" |
| 41 #include "net/filter/filter.h" |
| 41 #include "net/http/http_response_headers.h" | 42 #include "net/http/http_response_headers.h" |
| 42 #include "net/http/http_status_code.h" | 43 #include "net/http/http_status_code.h" |
| 43 #include "net/log/net_log_util.h" | 44 #include "net/log/net_log_util.h" |
| 44 #include "net/url_request/url_request.h" | 45 #include "net/url_request/url_request.h" |
| 45 #include "net/url_request/url_request_context.h" | 46 #include "net/url_request/url_request_context.h" |
| 46 #include "net/url_request/url_request_error_job.h" | 47 #include "net/url_request/url_request_error_job.h" |
| 47 #include "net/url_request/url_request_job.h" | 48 #include "net/url_request/url_request_job.h" |
| 48 #include "net/url_request/url_request_job_factory.h" | 49 #include "net/url_request/url_request_job_factory.h" |
| 49 #include "url/url_util.h" | 50 #include "url/url_util.h" |
| 50 | 51 |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 118 URLDataManagerBackend* backend, | 119 URLDataManagerBackend* backend, |
| 119 bool is_incognito); | 120 bool is_incognito); |
| 120 | 121 |
| 121 // net::URLRequestJob implementation. | 122 // net::URLRequestJob implementation. |
| 122 void Start() override; | 123 void Start() override; |
| 123 void Kill() override; | 124 void Kill() override; |
| 124 int ReadRawData(net::IOBuffer* buf, int buf_size) override; | 125 int ReadRawData(net::IOBuffer* buf, int buf_size) override; |
| 125 bool GetMimeType(std::string* mime_type) const override; | 126 bool GetMimeType(std::string* mime_type) const override; |
| 126 int GetResponseCode() const override; | 127 int GetResponseCode() const override; |
| 127 void GetResponseInfo(net::HttpResponseInfo* info) override; | 128 void GetResponseInfo(net::HttpResponseInfo* info) override; |
| 129 std::unique_ptr<net::Filter> SetupFilter() const override; |
| 128 | 130 |
| 129 // Used to notify that the requested data's |mime_type| is ready. | 131 // Used to notify that the requested data's |mime_type| is ready. |
| 130 void MimeTypeAvailable(const std::string& mime_type); | 132 void MimeTypeAvailable(const std::string& mime_type); |
| 131 | 133 |
| 132 // Called by ChromeURLDataManager to notify us that the data blob is ready | 134 // Called by ChromeURLDataManager to notify us that the data blob is ready |
| 133 // for us. | 135 // for us. |
| 134 void DataAvailable(base::RefCountedMemory* bytes); | 136 void DataAvailable(base::RefCountedMemory* bytes); |
| 135 | 137 |
| 136 // Returns a weak pointer to the job. | 138 // Returns a weak pointer to the job. |
| 137 base::WeakPtr<URLRequestChromeJob> AsWeakPtr(); | 139 base::WeakPtr<URLRequestChromeJob> AsWeakPtr(); |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 178 } | 180 } |
| 179 | 181 |
| 180 void set_send_content_type_header(bool send_content_type_header) { | 182 void set_send_content_type_header(bool send_content_type_header) { |
| 181 send_content_type_header_ = send_content_type_header; | 183 send_content_type_header_ = send_content_type_header; |
| 182 } | 184 } |
| 183 | 185 |
| 184 void set_access_control_allow_origin(const std::string& value) { | 186 void set_access_control_allow_origin(const std::string& value) { |
| 185 access_control_allow_origin_ = value; | 187 access_control_allow_origin_ = value; |
| 186 } | 188 } |
| 187 | 189 |
| 190 void set_is_gzipped(bool is_gzipped) { |
| 191 is_gzipped_ = is_gzipped; |
| 192 } |
| 193 |
| 188 // Returns true when job was generated from an incognito profile. | 194 // Returns true when job was generated from an incognito profile. |
| 189 bool is_incognito() const { | 195 bool is_incognito() const { |
| 190 return is_incognito_; | 196 return is_incognito_; |
| 191 } | 197 } |
| 192 | 198 |
| 193 private: | 199 private: |
| 194 ~URLRequestChromeJob() override; | 200 ~URLRequestChromeJob() override; |
| 195 | 201 |
| 196 // Helper for Start(), to let us start asynchronously. | 202 // Helper for Start(), to let us start asynchronously. |
| 197 // (This pattern is shared by most net::URLRequestJob implementations.) | 203 // (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. | 246 // If true, sets the "Content-Type: <mime-type>" header. |
| 241 bool send_content_type_header_; | 247 bool send_content_type_header_; |
| 242 | 248 |
| 243 // If not empty, "Access-Control-Allow-Origin:" is set to the value of this | 249 // If not empty, "Access-Control-Allow-Origin:" is set to the value of this |
| 244 // string. | 250 // string. |
| 245 std::string access_control_allow_origin_; | 251 std::string access_control_allow_origin_; |
| 246 | 252 |
| 247 // True when job is generated from an incognito profile. | 253 // True when job is generated from an incognito profile. |
| 248 const bool is_incognito_; | 254 const bool is_incognito_; |
| 249 | 255 |
| 256 // True when gzip encoding should be used. NOTE: this requires the original |
| 257 // resources in resources.pak use compress="gzip". |
| 258 bool is_gzipped_; |
| 259 |
| 250 // The backend is owned by net::URLRequestContext and always outlives us. | 260 // The backend is owned by net::URLRequestContext and always outlives us. |
| 251 URLDataManagerBackend* backend_; | 261 URLDataManagerBackend* backend_; |
| 252 | 262 |
| 253 base::WeakPtrFactory<URLRequestChromeJob> weak_factory_; | 263 base::WeakPtrFactory<URLRequestChromeJob> weak_factory_; |
| 254 | 264 |
| 255 DISALLOW_COPY_AND_ASSIGN(URLRequestChromeJob); | 265 DISALLOW_COPY_AND_ASSIGN(URLRequestChromeJob); |
| 256 }; | 266 }; |
| 257 | 267 |
| 258 URLRequestChromeJob::URLRequestChromeJob(net::URLRequest* request, | 268 URLRequestChromeJob::URLRequestChromeJob(net::URLRequest* request, |
| 259 net::NetworkDelegate* network_delegate, | 269 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, | 358 base::StringPrintf("%s:%s", net::HttpRequestHeaders::kContentType, |
| 349 mime_type_.c_str()); | 359 mime_type_.c_str()); |
| 350 info->headers->AddHeader(content_type); | 360 info->headers->AddHeader(content_type); |
| 351 } | 361 } |
| 352 | 362 |
| 353 if (!access_control_allow_origin_.empty()) { | 363 if (!access_control_allow_origin_.empty()) { |
| 354 info->headers->AddHeader("Access-Control-Allow-Origin: " + | 364 info->headers->AddHeader("Access-Control-Allow-Origin: " + |
| 355 access_control_allow_origin_); | 365 access_control_allow_origin_); |
| 356 info->headers->AddHeader("Vary: Origin"); | 366 info->headers->AddHeader("Vary: Origin"); |
| 357 } | 367 } |
| 368 |
| 369 if (is_gzipped_) |
| 370 info->headers->AddHeader("Content-Encoding: gzip"); |
| 371 } |
| 372 |
| 373 std::unique_ptr<net::Filter> URLRequestChromeJob::SetupFilter() const { |
| 374 return is_gzipped_ ? net::Filter::GZipFactory() : nullptr; |
| 358 } | 375 } |
| 359 | 376 |
| 360 void URLRequestChromeJob::MimeTypeAvailable(const std::string& mime_type) { | 377 void URLRequestChromeJob::MimeTypeAvailable(const std::string& mime_type) { |
| 361 set_mime_type(mime_type); | 378 set_mime_type(mime_type); |
| 362 NotifyHeadersComplete(); | 379 NotifyHeadersComplete(); |
| 363 } | 380 } |
| 364 | 381 |
| 365 void URLRequestChromeJob::DataAvailable(base::RefCountedMemory* bytes) { | 382 void URLRequestChromeJob::DataAvailable(base::RefCountedMemory* bytes) { |
| 366 TRACE_EVENT_ASYNC_END0("browser", "DataManager:Request", this); | 383 TRACE_EVENT_ASYNC_END0("browser", "DataManager:Request", this); |
| 367 if (bytes) { | 384 if (bytes) { |
| (...skipping 260 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 628 job->set_content_security_policy_child_source( | 645 job->set_content_security_policy_child_source( |
| 629 source->source()->GetContentSecurityPolicyChildSrc()); | 646 source->source()->GetContentSecurityPolicyChildSrc()); |
| 630 job->set_content_security_policy_style_source( | 647 job->set_content_security_policy_style_source( |
| 631 source->source()->GetContentSecurityPolicyStyleSrc()); | 648 source->source()->GetContentSecurityPolicyStyleSrc()); |
| 632 job->set_content_security_policy_image_source( | 649 job->set_content_security_policy_image_source( |
| 633 source->source()->GetContentSecurityPolicyImgSrc()); | 650 source->source()->GetContentSecurityPolicyImgSrc()); |
| 634 job->set_deny_xframe_options( | 651 job->set_deny_xframe_options( |
| 635 source->source()->ShouldDenyXFrameOptions()); | 652 source->source()->ShouldDenyXFrameOptions()); |
| 636 job->set_send_content_type_header( | 653 job->set_send_content_type_header( |
| 637 source->source()->ShouldServeMimeTypeAsContentTypeHeader()); | 654 source->source()->ShouldServeMimeTypeAsContentTypeHeader()); |
| 655 job->set_is_gzipped(source->source()->IsGzipped(path)); |
| 638 | 656 |
| 639 std::string origin = GetOriginHeaderValue(request); | 657 std::string origin = GetOriginHeaderValue(request); |
| 640 if (!origin.empty()) { | 658 if (!origin.empty()) { |
| 641 std::string header = | 659 std::string header = |
| 642 source->source()->GetAccessControlAllowOriginForOrigin(origin); | 660 source->source()->GetAccessControlAllowOriginForOrigin(origin); |
| 643 DCHECK(header.empty() || header == origin || header == "*" || | 661 DCHECK(header.empty() || header == origin || header == "*" || |
| 644 header == "null"); | 662 header == "null"); |
| 645 job->set_access_control_allow_origin(header); | 663 job->set_access_control_allow_origin(header); |
| 646 } | 664 } |
| 647 | 665 |
| (...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 794 | 812 |
| 795 } // namespace | 813 } // namespace |
| 796 | 814 |
| 797 net::URLRequestJobFactory::ProtocolHandler* | 815 net::URLRequestJobFactory::ProtocolHandler* |
| 798 CreateDevToolsProtocolHandler(content::ResourceContext* resource_context, | 816 CreateDevToolsProtocolHandler(content::ResourceContext* resource_context, |
| 799 bool is_incognito) { | 817 bool is_incognito) { |
| 800 return new DevToolsJobFactory(resource_context, is_incognito); | 818 return new DevToolsJobFactory(resource_context, is_incognito); |
| 801 } | 819 } |
| 802 | 820 |
| 803 } // namespace content | 821 } // namespace content |
| OLD | NEW |