Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(22)

Side by Side Diff: Source/modules/beacon/NavigatorBeacon.cpp

Issue 714123002: Use union type for NavigatorBeacon.sendBeacon()'s data argument (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: rebased Created 6 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « Source/modules/beacon/NavigatorBeacon.h ('k') | Source/modules/beacon/NavigatorBeacon.idl » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "bindings/modules/v8/UnionTypesModules.h"
9 #include "core/dom/DOMArrayBufferView.h" 10 #include "core/dom/DOMArrayBufferView.h"
10 #include "core/dom/ExceptionCode.h" 11 #include "core/dom/ExceptionCode.h"
11 #include "core/dom/ExecutionContext.h" 12 #include "core/dom/ExecutionContext.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/DOMFormData.h" 18 #include "core/html/DOMFormData.h"
18 #include "core/loader/BeaconLoader.h" 19 #include "core/loader/BeaconLoader.h"
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
81 { 82 {
82 if (allowed) { 83 if (allowed) {
83 ASSERT(sentBytes >= 0); 84 ASSERT(sentBytes >= 0);
84 m_transmittedBytes += sentBytes; 85 m_transmittedBytes += sentBytes;
85 } else { 86 } else {
86 UseCounter::count(context, UseCounter::SendBeaconQuotaExceeded); 87 UseCounter::count(context, UseCounter::SendBeaconQuotaExceeded);
87 } 88 }
88 return allowed; 89 return allowed;
89 } 90 }
90 91
91 bool NavigatorBeacon::sendBeacon(ExecutionContext* context, Navigator& navigator , const String& urlstring, const String& data, ExceptionState& exceptionState) 92 bool NavigatorBeacon::sendBeacon(ExecutionContext* context, Navigator& navigator , const String& urlstring, const ArrayBufferViewOrBlobOrStringOrFormData& data, ExceptionState& exceptionState)
92 { 93 {
93 return NavigatorBeacon::from(navigator).sendBeacon(context, urlstring, data, exceptionState); 94 NavigatorBeacon& impl = NavigatorBeacon::from(navigator);
94 }
95 95
96 bool NavigatorBeacon::sendBeacon(ExecutionContext* context, const String& urlstr ing, const String& data, ExceptionState& exceptionState)
97 {
98 KURL url = context->completeURL(urlstring); 96 KURL url = context->completeURL(urlstring);
99 if (!canSendBeacon(context, url, exceptionState)) 97 if (!impl.canSendBeacon(context, url, exceptionState))
100 return false; 98 return false;
101 99
100 int allowance = impl.maxAllowance();
102 int bytes = 0; 101 int bytes = 0;
103 bool result = BeaconLoader::sendBeacon(m_navigator.frame(), maxAllowance(), url, data, bytes); 102 bool allowed;
104 return beaconResult(context, result, bytes);
105 }
106 103
107 bool NavigatorBeacon::sendBeacon(ExecutionContext* context, Navigator& navigator , const String& urlstring, PassRefPtr<DOMArrayBufferView> data, ExceptionState& exceptionState) 104 if (data.isArrayBufferView())
108 { 105 allowed = BeaconLoader::sendBeacon(navigator.frame(), allowance, url, da ta.getAsArrayBufferView()->view(), bytes);
109 return NavigatorBeacon::from(navigator).sendBeacon(context, urlstring, data, exceptionState); 106 else if (data.isBlob())
110 } 107 allowed = BeaconLoader::sendBeacon(navigator.frame(), allowance, url, da ta.getAsBlob(), bytes);
108 else if (data.isString())
109 allowed = BeaconLoader::sendBeacon(navigator.frame(), allowance, url, da ta.getAsString(), bytes);
110 else if (data.isFormData())
111 allowed = BeaconLoader::sendBeacon(navigator.frame(), allowance, url, da ta.getAsFormData(), bytes);
112 else
113 allowed = BeaconLoader::sendBeacon(navigator.frame(), allowance, url, St ring(), bytes);
111 114
112 bool NavigatorBeacon::sendBeacon(ExecutionContext* context, const String& urlstr ing, PassRefPtr<DOMArrayBufferView> data, ExceptionState& exceptionState) 115 return impl.beaconResult(context, allowed, bytes);
113 {
114 KURL url = context->completeURL(urlstring);
115 if (!canSendBeacon(context, url, exceptionState))
116 return false;
117
118 int bytes = 0;
119 bool result = BeaconLoader::sendBeacon(m_navigator.frame(), maxAllowance(), url, data->view(), bytes);
120 return beaconResult(context, result, bytes);
121 }
122
123 bool NavigatorBeacon::sendBeacon(ExecutionContext* context, Navigator& navigator , const String& urlstring, Blob* data, ExceptionState& exceptionState)
124 {
125 return NavigatorBeacon::from(navigator).sendBeacon(context, urlstring, data, exceptionState);
126 }
127
128 bool NavigatorBeacon::sendBeacon(ExecutionContext* context, const String& urlstr ing, Blob* data, ExceptionState& exceptionState)
129 {
130 KURL url = context->completeURL(urlstring);
131 if (!canSendBeacon(context, url, exceptionState))
132 return false;
133
134 int bytes = 0;
135 bool result = BeaconLoader::sendBeacon(m_navigator.frame(), maxAllowance(), url, data, bytes);
136 return beaconResult(context, result, bytes);
137 }
138
139 bool NavigatorBeacon::sendBeacon(ExecutionContext* context, Navigator& navigator , const String& urlstring, PassRefPtrWillBeRawPtr<DOMFormData> data, ExceptionSt ate& exceptionState)
140 {
141 return NavigatorBeacon::from(navigator).sendBeacon(context, urlstring, data, exceptionState);
142 }
143
144 bool NavigatorBeacon::sendBeacon(ExecutionContext* context, const String& urlstr ing, PassRefPtrWillBeRawPtr<DOMFormData> data, ExceptionState& exceptionState)
145 {
146 KURL url = context->completeURL(urlstring);
147 if (!canSendBeacon(context, url, exceptionState))
148 return false;
149
150 int bytes = 0;
151 bool result = BeaconLoader::sendBeacon(m_navigator.frame(), maxAllowance(), url, data, bytes);
152 return beaconResult(context, result, bytes);
153 } 116 }
154 117
155 } // namespace blink 118 } // namespace blink
OLDNEW
« no previous file with comments | « Source/modules/beacon/NavigatorBeacon.h ('k') | Source/modules/beacon/NavigatorBeacon.idl » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698