| 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 #include <utility> | 8 #include <utility> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| (...skipping 13 matching lines...) Expand all Loading... |
| 24 #include "base/strings/string_util.h" | 24 #include "base/strings/string_util.h" |
| 25 #include "base/strings/stringprintf.h" | 25 #include "base/strings/stringprintf.h" |
| 26 #include "base/threading/thread_task_runner_handle.h" | 26 #include "base/threading/thread_task_runner_handle.h" |
| 27 #include "base/threading/worker_pool.h" | 27 #include "base/threading/worker_pool.h" |
| 28 #include "base/trace_event/trace_event.h" | 28 #include "base/trace_event/trace_event.h" |
| 29 #include "content/browser/blob_storage/chrome_blob_storage_context.h" | 29 #include "content/browser/blob_storage/chrome_blob_storage_context.h" |
| 30 #include "content/browser/histogram_internals_request_job.h" | 30 #include "content/browser/histogram_internals_request_job.h" |
| 31 #include "content/browser/net/view_blob_internals_job_factory.h" | 31 #include "content/browser/net/view_blob_internals_job_factory.h" |
| 32 #include "content/browser/net/view_http_cache_job_factory.h" | 32 #include "content/browser/net/view_http_cache_job_factory.h" |
| 33 #include "content/browser/resource_context_impl.h" | 33 #include "content/browser/resource_context_impl.h" |
| 34 #include "content/browser/webui/i18n_source_stream.h" |
| 34 #include "content/browser/webui/shared_resources_data_source.h" | 35 #include "content/browser/webui/shared_resources_data_source.h" |
| 35 #include "content/browser/webui/url_data_source_impl.h" | 36 #include "content/browser/webui/url_data_source_impl.h" |
| 36 #include "content/public/browser/browser_context.h" | 37 #include "content/public/browser/browser_context.h" |
| 37 #include "content/public/browser/browser_thread.h" | 38 #include "content/public/browser/browser_thread.h" |
| 38 #include "content/public/browser/content_browser_client.h" | 39 #include "content/public/browser/content_browser_client.h" |
| 39 #include "content/public/browser/render_process_host.h" | 40 #include "content/public/browser/render_process_host.h" |
| 40 #include "content/public/browser/resource_request_info.h" | 41 #include "content/public/browser/resource_request_info.h" |
| 41 #include "content/public/common/url_constants.h" | 42 #include "content/public/common/url_constants.h" |
| 42 #include "net/base/io_buffer.h" | 43 #include "net/base/io_buffer.h" |
| 43 #include "net/base/net_errors.h" | 44 #include "net/base/net_errors.h" |
| 44 #include "net/filter/gzip_source_stream.h" | 45 #include "net/filter/gzip_source_stream.h" |
| 45 #include "net/filter/source_stream.h" | 46 #include "net/filter/source_stream.h" |
| 46 #include "net/http/http_response_headers.h" | 47 #include "net/http/http_response_headers.h" |
| 47 #include "net/http/http_status_code.h" | 48 #include "net/http/http_status_code.h" |
| 48 #include "net/log/net_log_util.h" | 49 #include "net/log/net_log_util.h" |
| 49 #include "net/url_request/url_request.h" | 50 #include "net/url_request/url_request.h" |
| 50 #include "net/url_request/url_request_context.h" | 51 #include "net/url_request/url_request_context.h" |
| 51 #include "net/url_request/url_request_error_job.h" | 52 #include "net/url_request/url_request_error_job.h" |
| 52 #include "net/url_request/url_request_job.h" | 53 #include "net/url_request/url_request_job.h" |
| 53 #include "net/url_request/url_request_job_factory.h" | 54 #include "net/url_request/url_request_job_factory.h" |
| 55 #include "ui/base/template_expressions.h" |
| 54 #include "url/url_util.h" | 56 #include "url/url_util.h" |
| 55 | 57 |
| 56 namespace content { | 58 namespace content { |
| 57 | 59 |
| 58 namespace { | 60 namespace { |
| 59 | 61 |
| 60 const char kChromeURLContentSecurityPolicyHeaderBase[] = | 62 const char kChromeURLContentSecurityPolicyHeaderBase[] = |
| 61 "Content-Security-Policy: "; | 63 "Content-Security-Policy: "; |
| 62 | 64 |
| 63 const char kChromeURLXFrameOptionsHeader[] = "X-Frame-Options: DENY"; | 65 const char kChromeURLXFrameOptionsHeader[] = "X-Frame-Options: DENY"; |
| (...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 202 } | 204 } |
| 203 | 205 |
| 204 void set_access_control_allow_origin(const std::string& value) { | 206 void set_access_control_allow_origin(const std::string& value) { |
| 205 access_control_allow_origin_ = value; | 207 access_control_allow_origin_ = value; |
| 206 } | 208 } |
| 207 | 209 |
| 208 void set_is_gzipped(bool is_gzipped) { | 210 void set_is_gzipped(bool is_gzipped) { |
| 209 is_gzipped_ = is_gzipped; | 211 is_gzipped_ = is_gzipped; |
| 210 } | 212 } |
| 211 | 213 |
| 214 void SetReplacements(const ui::TemplateReplacements* replacements) { |
| 215 replacements_ = replacements; |
| 216 } |
| 217 |
| 212 // Returns true when job was generated from an incognito profile. | 218 // Returns true when job was generated from an incognito profile. |
| 213 bool is_incognito() const { | 219 bool is_incognito() const { |
| 214 return is_incognito_; | 220 return is_incognito_; |
| 215 } | 221 } |
| 216 | 222 |
| 217 private: | 223 private: |
| 218 ~URLRequestChromeJob() override; | 224 ~URLRequestChromeJob() override; |
| 219 | 225 |
| 220 // Helper for Start(), to let us start asynchronously. | 226 // Helper for Start(), to let us start asynchronously. |
| 221 // (This pattern is shared by most net::URLRequestJob implementations.) | 227 // (This pattern is shared by most net::URLRequestJob implementations.) |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 272 // string. | 278 // string. |
| 273 std::string access_control_allow_origin_; | 279 std::string access_control_allow_origin_; |
| 274 | 280 |
| 275 // True when job is generated from an incognito profile. | 281 // True when job is generated from an incognito profile. |
| 276 const bool is_incognito_; | 282 const bool is_incognito_; |
| 277 | 283 |
| 278 // True when gzip encoding should be used. NOTE: this requires the original | 284 // True when gzip encoding should be used. NOTE: this requires the original |
| 279 // resources in resources.pak use compress="gzip". | 285 // resources in resources.pak use compress="gzip". |
| 280 bool is_gzipped_; | 286 bool is_gzipped_; |
| 281 | 287 |
| 288 // Replacement dictionary for i18n. |
| 289 const ui::TemplateReplacements* replacements_; |
| 290 |
| 282 // The backend is owned by net::URLRequestContext and always outlives us. | 291 // The backend is owned by net::URLRequestContext and always outlives us. |
| 283 URLDataManagerBackend* const backend_; | 292 URLDataManagerBackend* const backend_; |
| 284 | 293 |
| 285 base::WeakPtrFactory<URLRequestChromeJob> weak_factory_; | 294 base::WeakPtrFactory<URLRequestChromeJob> weak_factory_; |
| 286 | 295 |
| 287 DISALLOW_COPY_AND_ASSIGN(URLRequestChromeJob); | 296 DISALLOW_COPY_AND_ASSIGN(URLRequestChromeJob); |
| 288 }; | 297 }; |
| 289 | 298 |
| 290 URLRequestChromeJob::URLRequestChromeJob(net::URLRequest* request, | 299 URLRequestChromeJob::URLRequestChromeJob(net::URLRequest* request, |
| 291 net::NetworkDelegate* network_delegate, | 300 net::NetworkDelegate* network_delegate, |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 388 info->headers->AddHeader("Access-Control-Allow-Origin: " + | 397 info->headers->AddHeader("Access-Control-Allow-Origin: " + |
| 389 access_control_allow_origin_); | 398 access_control_allow_origin_); |
| 390 info->headers->AddHeader("Vary: Origin"); | 399 info->headers->AddHeader("Vary: Origin"); |
| 391 } | 400 } |
| 392 | 401 |
| 393 if (is_gzipped_) | 402 if (is_gzipped_) |
| 394 info->headers->AddHeader("Content-Encoding: gzip"); | 403 info->headers->AddHeader("Content-Encoding: gzip"); |
| 395 } | 404 } |
| 396 | 405 |
| 397 std::unique_ptr<net::SourceStream> URLRequestChromeJob::SetUpSourceStream() { | 406 std::unique_ptr<net::SourceStream> URLRequestChromeJob::SetUpSourceStream() { |
| 398 std::unique_ptr<net::SourceStream> source = | 407 std::unique_ptr<net::SourceStream> source_stream = |
| 399 net::URLRequestJob::SetUpSourceStream(); | 408 net::URLRequestJob::SetUpSourceStream(); |
| 400 return is_gzipped_ ? net::GzipSourceStream::Create( | 409 |
| 401 std::move(source), net::SourceStream::TYPE_GZIP) | 410 if (is_gzipped_) { |
| 402 : std::move(source); | 411 source_stream = net::GzipSourceStream::Create(std::move(source_stream), |
| 412 net::SourceStream::TYPE_GZIP); |
| 413 } |
| 414 |
| 415 if (replacements_) { |
| 416 source_stream = content::I18nSourceStream::Create( |
| 417 std::move(source_stream), net::SourceStream::TYPE_NONE, replacements_); |
| 418 } |
| 419 |
| 420 return source_stream; |
| 403 } | 421 } |
| 404 | 422 |
| 405 void URLRequestChromeJob::MimeTypeAvailable(const std::string& mime_type) { | 423 void URLRequestChromeJob::MimeTypeAvailable(const std::string& mime_type) { |
| 406 set_mime_type(mime_type); | 424 set_mime_type(mime_type); |
| 407 NotifyHeadersComplete(); | 425 NotifyHeadersComplete(); |
| 408 } | 426 } |
| 409 | 427 |
| 410 void URLRequestChromeJob::DataAvailable(base::RefCountedMemory* bytes) { | 428 void URLRequestChromeJob::DataAvailable(base::RefCountedMemory* bytes) { |
| 411 TRACE_EVENT_ASYNC_END0("browser", "DataManager:Request", this); | 429 TRACE_EVENT_ASYNC_END0("browser", "DataManager:Request", this); |
| 412 DCHECK(!data_); | 430 DCHECK(!data_); |
| (...skipping 278 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 691 source->source()->GetContentSecurityPolicyChildSrc()); | 709 source->source()->GetContentSecurityPolicyChildSrc()); |
| 692 job->set_content_security_policy_style_source( | 710 job->set_content_security_policy_style_source( |
| 693 source->source()->GetContentSecurityPolicyStyleSrc()); | 711 source->source()->GetContentSecurityPolicyStyleSrc()); |
| 694 job->set_content_security_policy_image_source( | 712 job->set_content_security_policy_image_source( |
| 695 source->source()->GetContentSecurityPolicyImgSrc()); | 713 source->source()->GetContentSecurityPolicyImgSrc()); |
| 696 job->set_deny_xframe_options( | 714 job->set_deny_xframe_options( |
| 697 source->source()->ShouldDenyXFrameOptions()); | 715 source->source()->ShouldDenyXFrameOptions()); |
| 698 job->set_send_content_type_header( | 716 job->set_send_content_type_header( |
| 699 source->source()->ShouldServeMimeTypeAsContentTypeHeader()); | 717 source->source()->ShouldServeMimeTypeAsContentTypeHeader()); |
| 700 job->set_is_gzipped(source->source()->IsGzipped(path)); | 718 job->set_is_gzipped(source->source()->IsGzipped(path)); |
| 719 job->SetReplacements(source->GetReplacements()); |
| 701 | 720 |
| 702 std::string origin = GetOriginHeaderValue(request); | 721 std::string origin = GetOriginHeaderValue(request); |
| 703 if (!origin.empty()) { | 722 if (!origin.empty()) { |
| 704 std::string header = | 723 std::string header = |
| 705 source->source()->GetAccessControlAllowOriginForOrigin(origin); | 724 source->source()->GetAccessControlAllowOriginForOrigin(origin); |
| 706 DCHECK(header.empty() || header == origin || header == "*" || | 725 DCHECK(header.empty() || header == origin || header == "*" || |
| 707 header == "null"); | 726 header == "null"); |
| 708 job->set_access_control_allow_origin(header); | 727 job->set_access_control_allow_origin(header); |
| 709 } | 728 } |
| 710 | 729 |
| (...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 856 | 875 |
| 857 } // namespace | 876 } // namespace |
| 858 | 877 |
| 859 net::URLRequestJobFactory::ProtocolHandler* CreateDevToolsProtocolHandler( | 878 net::URLRequestJobFactory::ProtocolHandler* CreateDevToolsProtocolHandler( |
| 860 ResourceContext* resource_context, | 879 ResourceContext* resource_context, |
| 861 bool is_incognito) { | 880 bool is_incognito) { |
| 862 return new DevToolsJobFactory(resource_context, is_incognito); | 881 return new DevToolsJobFactory(resource_context, is_incognito); |
| 863 } | 882 } |
| 864 | 883 |
| 865 } // namespace content | 884 } // namespace content |
| OLD | NEW |