OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/child/appcache/web_application_cache_host_impl.h" | 5 #include "content/child/appcache/web_application_cache_host_impl.h" |
6 | 6 |
7 #include "base/compiler_specific.h" | 7 #include "base/compiler_specific.h" |
8 #include "base/id_map.h" | 8 #include "base/id_map.h" |
9 #include "base/strings/string_util.h" | 9 #include "base/strings/string_util.h" |
10 #include "base/strings/stringprintf.h" | 10 #include "base/strings/stringprintf.h" |
| 11 #include "third_party/WebKit/public/platform/WebString.h" |
11 #include "third_party/WebKit/public/platform/WebURL.h" | 12 #include "third_party/WebKit/public/platform/WebURL.h" |
12 #include "third_party/WebKit/public/platform/WebURLRequest.h" | 13 #include "third_party/WebKit/public/platform/WebURLRequest.h" |
13 #include "third_party/WebKit/public/platform/WebURLResponse.h" | 14 #include "third_party/WebKit/public/platform/WebURLResponse.h" |
14 | 15 |
15 using blink::WebApplicationCacheHost; | 16 using blink::WebApplicationCacheHost; |
16 using blink::WebApplicationCacheHostClient; | 17 using blink::WebApplicationCacheHostClient; |
| 18 using blink::WebString; |
17 using blink::WebURLRequest; | 19 using blink::WebURLRequest; |
18 using blink::WebURL; | 20 using blink::WebURL; |
19 using blink::WebURLResponse; | 21 using blink::WebURLResponse; |
20 using blink::WebVector; | 22 using blink::WebVector; |
21 using appcache::AppCacheBackend; | 23 using appcache::AppCacheBackend; |
22 using appcache::AppCacheResourceInfo; | 24 using appcache::AppCacheResourceInfo; |
23 | 25 |
24 namespace content { | 26 namespace content { |
25 | 27 |
26 namespace { | 28 namespace { |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
126 // deleted within the script event handler. | 128 // deleted within the script event handler. |
127 const char* kFormatString = "Application Cache Progress event (%d of %d) %s"; | 129 const char* kFormatString = "Application Cache Progress event (%d of %d) %s"; |
128 std::string message = base::StringPrintf(kFormatString, num_complete, | 130 std::string message = base::StringPrintf(kFormatString, num_complete, |
129 num_total, url.spec().c_str()); | 131 num_total, url.spec().c_str()); |
130 OnLogMessage(appcache::LOG_INFO, message); | 132 OnLogMessage(appcache::LOG_INFO, message); |
131 status_ = appcache::DOWNLOADING; | 133 status_ = appcache::DOWNLOADING; |
132 client_->notifyProgressEventListener(url, num_total, num_complete); | 134 client_->notifyProgressEventListener(url, num_total, num_complete); |
133 } | 135 } |
134 | 136 |
135 void WebApplicationCacheHostImpl::OnErrorEventRaised( | 137 void WebApplicationCacheHostImpl::OnErrorEventRaised( |
136 const std::string& message) { | 138 const appcache::ErrorDetails& details) { |
137 // Emit logging output prior to calling out to script as we can get | 139 // Emit logging output prior to calling out to script as we can get |
138 // deleted within the script event handler. | 140 // deleted within the script event handler. |
139 const char* kFormatString = "Application Cache Error event: %s"; | 141 const char* kFormatString = "Application Cache Error event: %s"; |
140 std::string full_message = base::StringPrintf(kFormatString, | 142 std::string full_message = |
141 message.c_str()); | 143 base::StringPrintf(kFormatString, details.message.c_str()); |
142 OnLogMessage(appcache::LOG_ERROR, full_message); | 144 OnLogMessage(appcache::LOG_ERROR, full_message); |
143 | 145 |
144 status_ = cache_info_.is_complete ? appcache::IDLE : appcache::UNCACHED; | 146 status_ = cache_info_.is_complete ? appcache::IDLE : appcache::UNCACHED; |
145 client_->notifyEventListener(static_cast<EventID>(appcache::ERROR_EVENT)); | 147 if (details.is_cross_origin) { |
| 148 // Don't leak detailed information to script for cross-origin resources. |
| 149 DCHECK_EQ(appcache::RESOURCE_ERROR, details.reason); |
| 150 client_->notifyErrorEventListener( |
| 151 static_cast<ErrorReason>(details.reason), details.url, 0, WebString()); |
| 152 } else { |
| 153 client_->notifyErrorEventListener(static_cast<ErrorReason>(details.reason), |
| 154 details.url, |
| 155 details.status, |
| 156 WebString::fromUTF8(details.message)); |
| 157 } |
146 } | 158 } |
147 | 159 |
148 void WebApplicationCacheHostImpl::willStartMainResourceRequest( | 160 void WebApplicationCacheHostImpl::willStartMainResourceRequest( |
149 WebURLRequest& request, const WebApplicationCacheHost* spawning_host) { | 161 WebURLRequest& request, const WebApplicationCacheHost* spawning_host) { |
150 request.setAppCacheHostID(host_id_); | 162 request.setAppCacheHostID(host_id_); |
151 | 163 |
152 original_main_resource_url_ = ClearUrlRef(request.url()); | 164 original_main_resource_url_ = ClearUrlRef(request.url()); |
153 | 165 |
154 std::string method = request.httpMethod().utf8(); | 166 std::string method = request.httpMethod().utf8(); |
155 is_get_method_ = (method == appcache::kHttpGETMethod); | 167 is_get_method_ = (method == appcache::kHttpGETMethod); |
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
299 web_resources[i].isExplicit = resource_infos[i].is_explicit; | 311 web_resources[i].isExplicit = resource_infos[i].is_explicit; |
300 web_resources[i].isManifest = resource_infos[i].is_manifest; | 312 web_resources[i].isManifest = resource_infos[i].is_manifest; |
301 web_resources[i].isForeign = resource_infos[i].is_foreign; | 313 web_resources[i].isForeign = resource_infos[i].is_foreign; |
302 web_resources[i].isFallback = resource_infos[i].is_fallback; | 314 web_resources[i].isFallback = resource_infos[i].is_fallback; |
303 web_resources[i].url = resource_infos[i].url; | 315 web_resources[i].url = resource_infos[i].url; |
304 } | 316 } |
305 resources->swap(web_resources); | 317 resources->swap(web_resources); |
306 } | 318 } |
307 | 319 |
308 } // namespace content | 320 } // namespace content |
OLD | NEW |