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 #include "modules/beacon/NavigatorBeacon.h" | 5 #include "modules/beacon/NavigatorBeacon.h" |
6 | 6 |
7 #include "bindings/core/v8/ExceptionState.h" | 7 #include "bindings/core/v8/ExceptionState.h" |
8 #include "bindings/modules/v8/ArrayBufferViewOrBlobOrStringOrFormData.h" | 8 #include "bindings/modules/v8/ArrayBufferViewOrBlobOrStringOrFormData.h" |
9 #include "core/dom/DOMArrayBufferView.h" | 9 #include "core/dom/DOMArrayBufferView.h" |
10 #include "core/dom/ExceptionCode.h" | 10 #include "core/dom/ExceptionCode.h" |
11 #include "core/dom/ExecutionContext.h" | 11 #include "core/dom/ExecutionContext.h" |
| 12 #include "core/fetch/FetchUtils.h" |
12 #include "core/fileapi/Blob.h" | 13 #include "core/fileapi/Blob.h" |
13 #include "core/frame/LocalFrame.h" | 14 #include "core/frame/LocalFrame.h" |
14 #include "core/frame/Settings.h" | 15 #include "core/frame/Settings.h" |
15 #include "core/frame/UseCounter.h" | 16 #include "core/frame/UseCounter.h" |
16 #include "core/frame/csp/ContentSecurityPolicy.h" | 17 #include "core/frame/csp/ContentSecurityPolicy.h" |
17 #include "core/html/FormData.h" | 18 #include "core/html/FormData.h" |
18 #include "core/loader/BeaconLoader.h" | 19 #include "core/loader/BeaconLoader.h" |
19 | 20 |
20 namespace blink { | 21 namespace blink { |
21 | 22 |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
104 NavigatorBeacon& impl = NavigatorBeacon::from(navigator); | 105 NavigatorBeacon& impl = NavigatorBeacon::from(navigator); |
105 | 106 |
106 KURL url = context->completeURL(urlstring); | 107 KURL url = context->completeURL(urlstring); |
107 if (!impl.canSendBeacon(context, url, exceptionState)) | 108 if (!impl.canSendBeacon(context, url, exceptionState)) |
108 return false; | 109 return false; |
109 | 110 |
110 int allowance = impl.maxAllowance(); | 111 int allowance = impl.maxAllowance(); |
111 int bytes = 0; | 112 int bytes = 0; |
112 bool allowed; | 113 bool allowed; |
113 | 114 |
114 if (data.isArrayBufferView()) | 115 if (data.isArrayBufferView()) { |
115 allowed = BeaconLoader::sendBeacon(impl.frame(), allowance, url, data.ge
tAsArrayBufferView(), bytes); | 116 allowed = BeaconLoader::sendBeacon(impl.frame(), allowance, url, data.ge
tAsArrayBufferView(), bytes); |
116 else if (data.isBlob()) | 117 } else if (data.isBlob()) { |
117 allowed = BeaconLoader::sendBeacon(impl.frame(), allowance, url, data.ge
tAsBlob(), bytes); | 118 Blob* blob = data.getAsBlob(); |
118 else if (data.isString()) | 119 if (!FetchUtils::isSimpleContentType(AtomicString(blob->type()))) { |
| 120 UseCounter::count(context, UseCounter::SendBeaconWithNonSimpleConten
tType); |
| 121 if (RuntimeEnabledFeatures::sendBeaconThrowForBlobWithNonSimpleTypeE
nabled()) { |
| 122 exceptionState.throwSecurityError("sendBeacon() with a Blob whos
e type is not CORS-safelisted MIME type is disallowed experimentally. See http:/
/crbug.com/490015 for details."); |
| 123 return false; |
| 124 } |
| 125 } |
| 126 allowed = BeaconLoader::sendBeacon(impl.frame(), allowance, url, blob, b
ytes); |
| 127 } else if (data.isString()) { |
119 allowed = BeaconLoader::sendBeacon(impl.frame(), allowance, url, data.ge
tAsString(), bytes); | 128 allowed = BeaconLoader::sendBeacon(impl.frame(), allowance, url, data.ge
tAsString(), bytes); |
120 else if (data.isFormData()) | 129 } else if (data.isFormData()) { |
121 allowed = BeaconLoader::sendBeacon(impl.frame(), allowance, url, data.ge
tAsFormData(), bytes); | 130 allowed = BeaconLoader::sendBeacon(impl.frame(), allowance, url, data.ge
tAsFormData(), bytes); |
122 else | 131 } else { |
123 allowed = BeaconLoader::sendBeacon(impl.frame(), allowance, url, String(
), bytes); | 132 allowed = BeaconLoader::sendBeacon(impl.frame(), allowance, url, String(
), bytes); |
| 133 } |
124 | 134 |
125 return impl.beaconResult(context, allowed, bytes); | 135 return impl.beaconResult(context, allowed, bytes); |
126 } | 136 } |
127 | 137 |
128 } // namespace blink | 138 } // namespace blink |
OLD | NEW |