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 "config.h" | 5 #include "config.h" |
6 #include "modules/beacon/NavigatorBeacon.h" | 6 #include "modules/beacon/NavigatorBeacon.h" |
7 | 7 |
8 #include "bindings/core/v8/ExceptionState.h" | 8 #include "bindings/core/v8/ExceptionState.h" |
9 #include "core/dom/ExceptionCode.h" | 9 #include "core/dom/ExceptionCode.h" |
10 #include "core/dom/ExecutionContext.h" | 10 #include "core/dom/ExecutionContext.h" |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
52 return false; | 52 return false; |
53 } | 53 } |
54 // FIXME: CSP is not enforced on redirects, crbug.com/372197 | 54 // FIXME: CSP is not enforced on redirects, crbug.com/372197 |
55 if (!ContentSecurityPolicy::shouldBypassMainWorld(context) && !context->cont
entSecurityPolicy()->allowConnectToSource(url)) { | 55 if (!ContentSecurityPolicy::shouldBypassMainWorld(context) && !context->cont
entSecurityPolicy()->allowConnectToSource(url)) { |
56 // We can safely expose the URL to JavaScript, as these checks happen sy
nchronously before redirection. JavaScript receives no new information. | 56 // We can safely expose the URL to JavaScript, as these checks happen sy
nchronously before redirection. JavaScript receives no new information. |
57 exceptionState.throwSecurityError("Refused to send beacon to '" + url.el
idedString() + "' because it violates the document's Content Security Policy."); | 57 exceptionState.throwSecurityError("Refused to send beacon to '" + url.el
idedString() + "' because it violates the document's Content Security Policy."); |
58 return false; | 58 return false; |
59 } | 59 } |
60 | 60 |
61 // Do not allow sending Beacons over a Navigator that is detached. | 61 // Do not allow sending Beacons over a Navigator that is detached. |
62 if (!m_navigator.frame()) | 62 if (!m_navigator.frame() || !m_navigator.frame()->client()) |
63 return false; | 63 return false; |
64 | 64 |
65 return true; | 65 return true; |
66 } | 66 } |
67 | 67 |
68 int NavigatorBeacon::maxAllowance() const | 68 int NavigatorBeacon::maxAllowance() const |
69 { | 69 { |
70 const Settings* settings = m_navigator.frame()->settings(); | 70 const Settings* settings = m_navigator.frame()->settings(); |
71 if (settings) { | 71 if (settings) { |
72 int maxAllowed = settings->maxBeaconTransmission(); | 72 int maxAllowed = settings->maxBeaconTransmission(); |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
146 KURL url = context->completeURL(urlstring); | 146 KURL url = context->completeURL(urlstring); |
147 if (!canSendBeacon(context, url, exceptionState)) | 147 if (!canSendBeacon(context, url, exceptionState)) |
148 return false; | 148 return false; |
149 | 149 |
150 int bytes = 0; | 150 int bytes = 0; |
151 bool result = BeaconLoader::sendBeacon(m_navigator.frame(), maxAllowance(),
url, data, bytes); | 151 bool result = BeaconLoader::sendBeacon(m_navigator.frame(), maxAllowance(),
url, data, bytes); |
152 return beaconResult(context, result, bytes); | 152 return beaconResult(context, result, bytes); |
153 } | 153 } |
154 | 154 |
155 } // namespace blink | 155 } // namespace blink |
OLD | NEW |