| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2010 Google Inc. All rights reserved. | 2 * Copyright (C) 2010 Google Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
| 6 * met: | 6 * met: |
| 7 * | 7 * |
| 8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
| 10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 60 namespace blink { | 60 namespace blink { |
| 61 | 61 |
| 62 void PingLoader::loadImage(LocalFrame* frame, const KURL& url) | 62 void PingLoader::loadImage(LocalFrame* frame, const KURL& url) |
| 63 { | 63 { |
| 64 if (!frame->document()->securityOrigin()->canDisplay(url)) { | 64 if (!frame->document()->securityOrigin()->canDisplay(url)) { |
| 65 FrameLoader::reportLocalLoadFailed(frame, url.string()); | 65 FrameLoader::reportLocalLoadFailed(frame, url.string()); |
| 66 return; | 66 return; |
| 67 } | 67 } |
| 68 | 68 |
| 69 ResourceRequest request(url); | 69 ResourceRequest request(url); |
| 70 request.setRequestContext(blink::WebURLRequest::RequestContextPing); | 70 request.setRequestContext(WebURLRequest::RequestContextPing); |
| 71 request.setHTTPHeaderField("Cache-Control", "max-age=0"); | 71 request.setHTTPHeaderField("Cache-Control", "max-age=0"); |
| 72 frame->document()->fetcher()->context().addAdditionalRequestHeaders(request,
FetchSubresource); | 72 frame->document()->fetcher()->context().addAdditionalRequestHeaders(request,
FetchSubresource); |
| 73 frame->document()->fetcher()->context().setFirstPartyForCookies(request); | 73 frame->document()->fetcher()->context().setFirstPartyForCookies(request); |
| 74 | 74 |
| 75 FetchInitiatorInfo initiatorInfo; | 75 FetchInitiatorInfo initiatorInfo; |
| 76 initiatorInfo.name = FetchInitiatorTypeNames::ping; | 76 initiatorInfo.name = FetchInitiatorTypeNames::ping; |
| 77 PingLoader::start(frame, request, initiatorInfo); | 77 PingLoader::start(frame, request, initiatorInfo); |
| 78 } | 78 } |
| 79 | 79 |
| 80 // http://www.whatwg.org/specs/web-apps/current-work/multipage/links.html#hyperl
ink-auditing | 80 // http://www.whatwg.org/specs/web-apps/current-work/multipage/links.html#hyperl
ink-auditing |
| 81 void PingLoader::sendLinkAuditPing(LocalFrame* frame, const KURL& pingURL, const
KURL& destinationURL) | 81 void PingLoader::sendLinkAuditPing(LocalFrame* frame, const KURL& pingURL, const
KURL& destinationURL) |
| 82 { | 82 { |
| 83 ResourceRequest request(pingURL); | 83 ResourceRequest request(pingURL); |
| 84 request.setRequestContext(blink::WebURLRequest::RequestContextPing); | 84 request.setRequestContext(WebURLRequest::RequestContextPing); |
| 85 request.setHTTPMethod("POST"); | 85 request.setHTTPMethod("POST"); |
| 86 request.setHTTPContentType("text/ping"); | 86 request.setHTTPContentType("text/ping"); |
| 87 request.setHTTPBody(FormData::create("PING")); | 87 request.setHTTPBody(FormData::create("PING")); |
| 88 request.setHTTPHeaderField("Cache-Control", "max-age=0"); | 88 request.setHTTPHeaderField("Cache-Control", "max-age=0"); |
| 89 frame->document()->fetcher()->context().addAdditionalRequestHeaders(request,
FetchSubresource); | 89 frame->document()->fetcher()->context().addAdditionalRequestHeaders(request,
FetchSubresource); |
| 90 frame->document()->fetcher()->context().setFirstPartyForCookies(request); | 90 frame->document()->fetcher()->context().setFirstPartyForCookies(request); |
| 91 | 91 |
| 92 RefPtr<SecurityOrigin> pingOrigin = SecurityOrigin::create(pingURL); | 92 RefPtr<SecurityOrigin> pingOrigin = SecurityOrigin::create(pingURL); |
| 93 // addAdditionalRequestHeaders() will have added a referrer for same origin
requests, | 93 // addAdditionalRequestHeaders() will have added a referrer for same origin
requests, |
| 94 // but the spec omits the referrer for same origin. | 94 // but the spec omits the referrer for same origin. |
| 95 if (frame->document()->securityOrigin()->isSameSchemeHostPort(pingOrigin.get
())) | 95 if (frame->document()->securityOrigin()->isSameSchemeHostPort(pingOrigin.get
())) |
| 96 request.clearHTTPReferrer(); | 96 request.clearHTTPReferrer(); |
| 97 | 97 |
| 98 request.setHTTPHeaderField("Ping-To", AtomicString(destinationURL.string()))
; | 98 request.setHTTPHeaderField("Ping-To", AtomicString(destinationURL.string()))
; |
| 99 | 99 |
| 100 // Ping-From follows the same rules as the default referrer beahavior for su
bresource requests. | 100 // Ping-From follows the same rules as the default referrer beahavior for su
bresource requests. |
| 101 // FIXME: Should Ping-From obey ReferrerPolicy? | 101 // FIXME: Should Ping-From obey ReferrerPolicy? |
| 102 if (!SecurityPolicy::shouldHideReferrer(pingURL, frame->document()->url().st
ring())) | 102 if (!SecurityPolicy::shouldHideReferrer(pingURL, frame->document()->url().st
ring())) |
| 103 request.setHTTPHeaderField("Ping-From", AtomicString(frame->document()->
url().string())); | 103 request.setHTTPHeaderField("Ping-From", AtomicString(frame->document()->
url().string())); |
| 104 | 104 |
| 105 FetchInitiatorInfo initiatorInfo; | 105 FetchInitiatorInfo initiatorInfo; |
| 106 initiatorInfo.name = FetchInitiatorTypeNames::ping; | 106 initiatorInfo.name = FetchInitiatorTypeNames::ping; |
| 107 PingLoader::start(frame, request, initiatorInfo); | 107 PingLoader::start(frame, request, initiatorInfo); |
| 108 } | 108 } |
| 109 | 109 |
| 110 void PingLoader::sendViolationReport(LocalFrame* frame, const KURL& reportURL, P
assRefPtr<FormData> report, ViolationReportType type) | 110 void PingLoader::sendViolationReport(LocalFrame* frame, const KURL& reportURL, P
assRefPtr<FormData> report, ViolationReportType type) |
| 111 { | 111 { |
| 112 ResourceRequest request(reportURL); | 112 ResourceRequest request(reportURL); |
| 113 request.setRequestContext(blink::WebURLRequest::RequestContextPing); | 113 request.setRequestContext(WebURLRequest::RequestContextPing); |
| 114 request.setHTTPMethod("POST"); | 114 request.setHTTPMethod("POST"); |
| 115 request.setHTTPContentType(type == ContentSecurityPolicyViolationReport ? "a
pplication/csp-report" : "application/json"); | 115 request.setHTTPContentType(type == ContentSecurityPolicyViolationReport ? "a
pplication/csp-report" : "application/json"); |
| 116 request.setHTTPBody(report); | 116 request.setHTTPBody(report); |
| 117 frame->document()->fetcher()->context().addAdditionalRequestHeaders(request,
FetchSubresource); | 117 frame->document()->fetcher()->context().addAdditionalRequestHeaders(request,
FetchSubresource); |
| 118 frame->document()->fetcher()->context().setFirstPartyForCookies(request); | 118 frame->document()->fetcher()->context().setFirstPartyForCookies(request); |
| 119 | 119 |
| 120 FetchInitiatorInfo initiatorInfo; | 120 FetchInitiatorInfo initiatorInfo; |
| 121 initiatorInfo.name = FetchInitiatorTypeNames::violationreport; | 121 initiatorInfo.name = FetchInitiatorTypeNames::violationreport; |
| 122 PingLoader::start(frame, request, initiatorInfo, SecurityOrigin::create(repo
rtURL)->isSameSchemeHostPort(frame->document()->securityOrigin()) ? AllowStoredC
redentials : DoNotAllowStoredCredentials); | 122 PingLoader::start(frame, request, initiatorInfo, SecurityOrigin::create(repo
rtURL)->isSameSchemeHostPort(frame->document()->securityOrigin()) ? AllowStoredC
redentials : DoNotAllowStoredCredentials); |
| 123 } | 123 } |
| (...skipping 12 matching lines...) Expand all Loading... |
| 136 : PageLifecycleObserver(frame->page()) | 136 : PageLifecycleObserver(frame->page()) |
| 137 , m_timeout(this, &PingLoader::timeout) | 137 , m_timeout(this, &PingLoader::timeout) |
| 138 , m_url(request.url()) | 138 , m_url(request.url()) |
| 139 , m_identifier(createUniqueIdentifier()) | 139 , m_identifier(createUniqueIdentifier()) |
| 140 { | 140 { |
| 141 frame->loader().client()->didDispatchPingLoader(request.url()); | 141 frame->loader().client()->didDispatchPingLoader(request.url()); |
| 142 | 142 |
| 143 TRACE_EVENT_INSTANT1(TRACE_DISABLED_BY_DEFAULT("devtools.timeline"), "Resour
ceSendRequest", TRACE_EVENT_SCOPE_THREAD, "data", InspectorSendRequestEvent::dat
a(m_identifier, frame, request)); | 143 TRACE_EVENT_INSTANT1(TRACE_DISABLED_BY_DEFAULT("devtools.timeline"), "Resour
ceSendRequest", TRACE_EVENT_SCOPE_THREAD, "data", InspectorSendRequestEvent::dat
a(m_identifier, frame, request)); |
| 144 InspectorInstrumentation::willSendRequest(frame, m_identifier, frame->loader
().documentLoader(), request, ResourceResponse(), initiatorInfo); | 144 InspectorInstrumentation::willSendRequest(frame, m_identifier, frame->loader
().documentLoader(), request, ResourceResponse(), initiatorInfo); |
| 145 | 145 |
| 146 m_loader = adoptPtr(blink::Platform::current()->createURLLoader()); | 146 m_loader = adoptPtr(Platform::current()->createURLLoader()); |
| 147 ASSERT(m_loader); | 147 ASSERT(m_loader); |
| 148 blink::WrappedResourceRequest wrappedRequest(request); | 148 WrappedResourceRequest wrappedRequest(request); |
| 149 wrappedRequest.setAllowStoredCredentials(credentialsAllowed == AllowStoredCr
edentials); | 149 wrappedRequest.setAllowStoredCredentials(credentialsAllowed == AllowStoredCr
edentials); |
| 150 m_loader->loadAsynchronously(wrappedRequest, this); | 150 m_loader->loadAsynchronously(wrappedRequest, this); |
| 151 | 151 |
| 152 // If the server never responds, FrameLoader won't be able to cancel this lo
ad and | 152 // If the server never responds, FrameLoader won't be able to cancel this lo
ad and |
| 153 // we'll sit here waiting forever. Set a very generous timeout, just in case
. | 153 // we'll sit here waiting forever. Set a very generous timeout, just in case
. |
| 154 m_timeout.startOneShot(60000, FROM_HERE); | 154 m_timeout.startOneShot(60000, FROM_HERE); |
| 155 } | 155 } |
| 156 | 156 |
| 157 PingLoader::~PingLoader() | 157 PingLoader::~PingLoader() |
| 158 { | 158 { |
| 159 if (m_loader) | 159 if (m_loader) |
| 160 m_loader->cancel(); | 160 m_loader->cancel(); |
| 161 } | 161 } |
| 162 | 162 |
| 163 void PingLoader::dispose() | 163 void PingLoader::dispose() |
| 164 { | 164 { |
| 165 if (m_loader) { | 165 if (m_loader) { |
| 166 m_loader->cancel(); | 166 m_loader->cancel(); |
| 167 m_loader = nullptr; | 167 m_loader = nullptr; |
| 168 } | 168 } |
| 169 deref(); | 169 deref(); |
| 170 } | 170 } |
| 171 | 171 |
| 172 void PingLoader::didReceiveResponse(blink::WebURLLoader*, const blink::WebURLRes
ponse& response) | 172 void PingLoader::didReceiveResponse(WebURLLoader*, const WebURLResponse& respons
e) |
| 173 { | 173 { |
| 174 if (Page* page = this->page()) { | 174 if (Page* page = this->page()) { |
| 175 TRACE_EVENT_INSTANT1(TRACE_DISABLED_BY_DEFAULT("devtools.timeline"), "Re
sourceFinish", TRACE_EVENT_SCOPE_THREAD, "data", InspectorResourceFinishEvent::d
ata(m_identifier, 0, true)); | 175 TRACE_EVENT_INSTANT1(TRACE_DISABLED_BY_DEFAULT("devtools.timeline"), "Re
sourceFinish", TRACE_EVENT_SCOPE_THREAD, "data", InspectorResourceFinishEvent::d
ata(m_identifier, 0, true)); |
| 176 const ResourceResponse& resourceResponse = response.toResourceResponse()
; | 176 const ResourceResponse& resourceResponse = response.toResourceResponse()
; |
| 177 InspectorInstrumentation::didReceiveResourceResponse(page->deprecatedLoc
alMainFrame(), m_identifier, 0, resourceResponse, 0); | 177 InspectorInstrumentation::didReceiveResourceResponse(page->deprecatedLoc
alMainFrame(), m_identifier, 0, resourceResponse, 0); |
| 178 didFailLoading(page); | 178 didFailLoading(page); |
| 179 } | 179 } |
| 180 dispose(); | 180 dispose(); |
| 181 } | 181 } |
| 182 | 182 |
| 183 void PingLoader::didReceiveData(blink::WebURLLoader*, const char*, int, int) | 183 void PingLoader::didReceiveData(WebURLLoader*, const char*, int, int) |
| 184 { | 184 { |
| 185 if (Page* page = this->page()) { | 185 if (Page* page = this->page()) { |
| 186 TRACE_EVENT_INSTANT1(TRACE_DISABLED_BY_DEFAULT("devtools.timeline"), "Re
sourceFinish", TRACE_EVENT_SCOPE_THREAD, "data", InspectorResourceFinishEvent::d
ata(m_identifier, 0, true)); | 186 TRACE_EVENT_INSTANT1(TRACE_DISABLED_BY_DEFAULT("devtools.timeline"), "Re
sourceFinish", TRACE_EVENT_SCOPE_THREAD, "data", InspectorResourceFinishEvent::d
ata(m_identifier, 0, true)); |
| 187 didFailLoading(page); | 187 didFailLoading(page); |
| 188 } | 188 } |
| 189 dispose(); | 189 dispose(); |
| 190 } | 190 } |
| 191 | 191 |
| 192 void PingLoader::didFinishLoading(blink::WebURLLoader*, double, int64_t) | 192 void PingLoader::didFinishLoading(WebURLLoader*, double, int64_t) |
| 193 { | 193 { |
| 194 if (Page* page = this->page()) { | 194 if (Page* page = this->page()) { |
| 195 TRACE_EVENT_INSTANT1(TRACE_DISABLED_BY_DEFAULT("devtools.timeline"), "Re
sourceFinish", TRACE_EVENT_SCOPE_THREAD, "data", InspectorResourceFinishEvent::d
ata(m_identifier, 0, true)); | 195 TRACE_EVENT_INSTANT1(TRACE_DISABLED_BY_DEFAULT("devtools.timeline"), "Re
sourceFinish", TRACE_EVENT_SCOPE_THREAD, "data", InspectorResourceFinishEvent::d
ata(m_identifier, 0, true)); |
| 196 didFailLoading(page); | 196 didFailLoading(page); |
| 197 } | 197 } |
| 198 dispose(); | 198 dispose(); |
| 199 } | 199 } |
| 200 | 200 |
| 201 void PingLoader::didFail(blink::WebURLLoader*, const blink::WebURLError& resourc
eError) | 201 void PingLoader::didFail(WebURLLoader*, const WebURLError& resourceError) |
| 202 { | 202 { |
| 203 if (Page* page = this->page()) { | 203 if (Page* page = this->page()) { |
| 204 TRACE_EVENT_INSTANT1(TRACE_DISABLED_BY_DEFAULT("devtools.timeline"), "Re
sourceFinish", TRACE_EVENT_SCOPE_THREAD, "data", InspectorResourceFinishEvent::d
ata(m_identifier, 0, true)); | 204 TRACE_EVENT_INSTANT1(TRACE_DISABLED_BY_DEFAULT("devtools.timeline"), "Re
sourceFinish", TRACE_EVENT_SCOPE_THREAD, "data", InspectorResourceFinishEvent::d
ata(m_identifier, 0, true)); |
| 205 didFailLoading(page); | 205 didFailLoading(page); |
| 206 } | 206 } |
| 207 dispose(); | 207 dispose(); |
| 208 } | 208 } |
| 209 | 209 |
| 210 void PingLoader::timeout(Timer<PingLoader>*) | 210 void PingLoader::timeout(Timer<PingLoader>*) |
| 211 { | 211 { |
| 212 if (Page* page = this->page()) { | 212 if (Page* page = this->page()) { |
| 213 TRACE_EVENT_INSTANT1(TRACE_DISABLED_BY_DEFAULT("devtools.timeline"), "Re
sourceFinish", TRACE_EVENT_SCOPE_THREAD, "data", InspectorResourceFinishEvent::d
ata(m_identifier, 0, true)); | 213 TRACE_EVENT_INSTANT1(TRACE_DISABLED_BY_DEFAULT("devtools.timeline"), "Re
sourceFinish", TRACE_EVENT_SCOPE_THREAD, "data", InspectorResourceFinishEvent::d
ata(m_identifier, 0, true)); |
| 214 didFailLoading(page); | 214 didFailLoading(page); |
| 215 } | 215 } |
| 216 dispose(); | 216 dispose(); |
| 217 } | 217 } |
| 218 | 218 |
| 219 void PingLoader::didFailLoading(Page* page) | 219 void PingLoader::didFailLoading(Page* page) |
| 220 { | 220 { |
| 221 LocalFrame* frame = page->deprecatedLocalMainFrame(); | 221 LocalFrame* frame = page->deprecatedLocalMainFrame(); |
| 222 InspectorInstrumentation::didFailLoading(frame, m_identifier, ResourceError:
:cancelledError(m_url)); | 222 InspectorInstrumentation::didFailLoading(frame, m_identifier, ResourceError:
:cancelledError(m_url)); |
| 223 frame->console().didFailLoading(m_identifier, ResourceError::cancelledError(
m_url)); | 223 frame->console().didFailLoading(m_identifier, ResourceError::cancelledError(
m_url)); |
| 224 } | 224 } |
| 225 | 225 |
| 226 DEFINE_TRACE(PingLoader) | 226 DEFINE_TRACE(PingLoader) |
| 227 { | 227 { |
| 228 PageLifecycleObserver::trace(visitor); | 228 PageLifecycleObserver::trace(visitor); |
| 229 } | 229 } |
| 230 | 230 |
| 231 } | 231 } // namespace blink |
| OLD | NEW |