| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 // An implementation of WebURLLoader in terms of ResourceLoaderBridge. | 5 // An implementation of WebURLLoader in terms of ResourceLoaderBridge. |
| 6 | 6 |
| 7 #include "content/child/web_url_loader_impl.h" | 7 #include "content/child/web_url_loader_impl.h" |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/files/file_path.h" | 10 #include "base/files/file_path.h" |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 57 using webkit_glue::MultipartResponseDelegate; | 57 using webkit_glue::MultipartResponseDelegate; |
| 58 using webkit_glue::ResourceDevToolsInfo; | 58 using webkit_glue::ResourceDevToolsInfo; |
| 59 using webkit_glue::ResourceLoaderBridge; | 59 using webkit_glue::ResourceLoaderBridge; |
| 60 using webkit_glue::ResourceResponseInfo; | 60 using webkit_glue::ResourceResponseInfo; |
| 61 using webkit_glue::WebURLResponseExtraDataImpl; | 61 using webkit_glue::WebURLResponseExtraDataImpl; |
| 62 | 62 |
| 63 namespace content { | 63 namespace content { |
| 64 | 64 |
| 65 // Utilities ------------------------------------------------------------------ | 65 // Utilities ------------------------------------------------------------------ |
| 66 | 66 |
| 67 bool GetInfoFromDataURL(const GURL& url, |
| 68 ResourceResponseInfo* info, |
| 69 std::string* data, |
| 70 int* error_code) { |
| 71 std::string mime_type; |
| 72 std::string charset; |
| 73 if (!net::DataURL::Parse(url, &mime_type, &charset, data)) { |
| 74 *error_code = net::ERR_INVALID_URL; |
| 75 return false; |
| 76 } |
| 77 |
| 78 DCHECK(!mime_type.empty()); |
| 79 DCHECK(!charset.empty()); |
| 80 |
| 81 // mime_type set by net::DataURL::Parse() is guaranteed to be in |
| 82 // token "/" token |
| 83 // form. Now just ensure charset is token. The grammar for charset is not |
| 84 // specially defined in RFC2045 and RFC2397. It just need to be token or |
| 85 // quoted-string since it's an attibute value of media type. But charset in |
| 86 // Content-Type header is specified explicitly to follow token ABNF in |
| 87 // httpbis spec. |
| 88 if (!net::HttpUtil::IsToken(charset)) { |
| 89 *error_code = net::ERR_INVALID_URL; |
| 90 return false; |
| 91 } |
| 92 |
| 93 *error_code = net::OK; |
| 94 // Assure same time for all time fields of data: URLs. |
| 95 Time now = Time::Now(); |
| 96 info->load_timing.request_start = TimeTicks::Now(); |
| 97 info->load_timing.request_start_time = now; |
| 98 info->request_time = now; |
| 99 info->response_time = now; |
| 100 |
| 101 scoped_refptr<net::HttpResponseHeaders> headers( |
| 102 new net::HttpResponseHeaders(std::string())); |
| 103 headers->ReplaceStatusLine("HTTP/1.1 200 OK"); |
| 104 std::string content_type_header = |
| 105 "Content-Type: " + mime_type + ";charset=" + charset; |
| 106 headers->AddHeader(content_type_header); |
| 107 headers->AddHeader("Access-Control-Allow-Origin: *"); |
| 108 headers->AddHeader("Access-Control-Allow-Credentials: true"); |
| 109 info->headers = headers; |
| 110 |
| 111 info->mime_type.swap(mime_type); |
| 112 info->charset.swap(charset); |
| 113 info->security_info.clear(); |
| 114 info->content_length = data->length(); |
| 115 info->encoded_data_length = 0; |
| 116 |
| 117 return true; |
| 118 } |
| 119 |
| 67 namespace { | 120 namespace { |
| 68 | 121 |
| 69 const char kThrottledErrorDescription[] = | 122 const char kThrottledErrorDescription[] = |
| 70 "Request throttled. Visit http://dev.chromium.org/throttling for more " | 123 "Request throttled. Visit http://dev.chromium.org/throttling for more " |
| 71 "information."; | 124 "information."; |
| 72 | 125 |
| 73 class HeaderFlattener : public WebHTTPHeaderVisitor { | 126 class HeaderFlattener : public WebHTTPHeaderVisitor { |
| 74 public: | 127 public: |
| 75 explicit HeaderFlattener(int load_flags) | 128 explicit HeaderFlattener(int load_flags) |
| 76 : load_flags_(load_flags), | 129 : load_flags_(load_flags), |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 116 } | 169 } |
| 117 return buffer_; | 170 return buffer_; |
| 118 } | 171 } |
| 119 | 172 |
| 120 private: | 173 private: |
| 121 int load_flags_; | 174 int load_flags_; |
| 122 std::string buffer_; | 175 std::string buffer_; |
| 123 bool has_accept_header_; | 176 bool has_accept_header_; |
| 124 }; | 177 }; |
| 125 | 178 |
| 126 // Extracts the information from a data: url. | |
| 127 bool GetInfoFromDataURL(const GURL& url, | |
| 128 ResourceResponseInfo* info, | |
| 129 std::string* data, | |
| 130 int* error_code) { | |
| 131 std::string mime_type; | |
| 132 std::string charset; | |
| 133 if (net::DataURL::Parse(url, &mime_type, &charset, data)) { | |
| 134 *error_code = net::OK; | |
| 135 // Assure same time for all time fields of data: URLs. | |
| 136 Time now = Time::Now(); | |
| 137 info->load_timing.request_start = TimeTicks::Now(); | |
| 138 info->load_timing.request_start_time = now; | |
| 139 info->request_time = now; | |
| 140 info->response_time = now; | |
| 141 info->headers = NULL; | |
| 142 info->mime_type.swap(mime_type); | |
| 143 info->charset.swap(charset); | |
| 144 info->security_info.clear(); | |
| 145 info->content_length = data->length(); | |
| 146 info->encoded_data_length = 0; | |
| 147 | |
| 148 return true; | |
| 149 } | |
| 150 | |
| 151 *error_code = net::ERR_INVALID_URL; | |
| 152 return false; | |
| 153 } | |
| 154 | |
| 155 typedef ResourceDevToolsInfo::HeadersVector HeadersVector; | 179 typedef ResourceDevToolsInfo::HeadersVector HeadersVector; |
| 156 | 180 |
| 157 // Converts timing data from |load_timing| to the format used by WebKit. | 181 // Converts timing data from |load_timing| to the format used by WebKit. |
| 158 void PopulateURLLoadTiming(const net::LoadTimingInfo& load_timing, | 182 void PopulateURLLoadTiming(const net::LoadTimingInfo& load_timing, |
| 159 WebURLLoadTiming* url_timing) { | 183 WebURLLoadTiming* url_timing) { |
| 160 DCHECK(!load_timing.request_start.is_null()); | 184 DCHECK(!load_timing.request_start.is_null()); |
| 161 | 185 |
| 162 const TimeTicks kNullTicks; | 186 const TimeTicks kNullTicks; |
| 163 url_timing->initialize(); | 187 url_timing->initialize(); |
| 164 url_timing->setRequestTime( | 188 url_timing->setRequestTime( |
| (...skipping 699 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 864 | 888 |
| 865 void WebURLLoaderImpl::setDefersLoading(bool value) { | 889 void WebURLLoaderImpl::setDefersLoading(bool value) { |
| 866 context_->SetDefersLoading(value); | 890 context_->SetDefersLoading(value); |
| 867 } | 891 } |
| 868 | 892 |
| 869 void WebURLLoaderImpl::didChangePriority(WebURLRequest::Priority new_priority) { | 893 void WebURLLoaderImpl::didChangePriority(WebURLRequest::Priority new_priority) { |
| 870 context_->DidChangePriority(new_priority); | 894 context_->DidChangePriority(new_priority); |
| 871 } | 895 } |
| 872 | 896 |
| 873 } // namespace content | 897 } // namespace content |
| OLD | NEW |