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