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

Side by Side Diff: Source/core/loader/FormSubmission.cpp

Issue 1311923004: Rename FormData/FormDataBuilder to EncodedFormData/FormDataEncoder respectively. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: update comments Created 5 years, 3 months 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 | Annotate | Revision Log
« no previous file with comments | « Source/core/loader/FormSubmission.h ('k') | Source/core/loader/FrameLoader.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 25 matching lines...) Expand all
36 #include "core/dom/Document.h" 36 #include "core/dom/Document.h"
37 #include "core/events/Event.h" 37 #include "core/events/Event.h"
38 #include "core/html/DOMFormData.h" 38 #include "core/html/DOMFormData.h"
39 #include "core/html/HTMLFormControlElement.h" 39 #include "core/html/HTMLFormControlElement.h"
40 #include "core/html/HTMLFormElement.h" 40 #include "core/html/HTMLFormElement.h"
41 #include "core/html/HTMLInputElement.h" 41 #include "core/html/HTMLInputElement.h"
42 #include "core/html/parser/HTMLParserIdioms.h" 42 #include "core/html/parser/HTMLParserIdioms.h"
43 #include "core/loader/FrameLoadRequest.h" 43 #include "core/loader/FrameLoadRequest.h"
44 #include "core/loader/FrameLoader.h" 44 #include "core/loader/FrameLoader.h"
45 #include "platform/heap/Handle.h" 45 #include "platform/heap/Handle.h"
46 #include "platform/network/FormData.h" 46 #include "platform/network/EncodedFormData.h"
47 #include "platform/network/FormDataBuilder.h" 47 #include "platform/network/FormDataEncoder.h"
48 #include "wtf/CurrentTime.h" 48 #include "wtf/CurrentTime.h"
49 #include "wtf/text/StringBuilder.h" 49 #include "wtf/text/StringBuilder.h"
50 #include "wtf/text/TextEncoding.h" 50 #include "wtf/text/TextEncoding.h"
51 51
52 namespace blink { 52 namespace blink {
53 53
54 using namespace HTMLNames; 54 using namespace HTMLNames;
55 55
56 static int64_t generateFormDataIdentifier() 56 static int64_t generateFormDataIdentifier()
57 { 57 {
58 // Initialize to the current time to reduce the likelihood of generating 58 // Initialize to the current time to reduce the likelihood of generating
59 // identifiers that overlap with those from past/future browser sessions. 59 // identifiers that overlap with those from past/future browser sessions.
60 static int64_t nextIdentifier = static_cast<int64_t>(currentTime() * 1000000 .0); 60 static int64_t nextIdentifier = static_cast<int64_t>(currentTime() * 1000000 .0);
61 return ++nextIdentifier; 61 return ++nextIdentifier;
62 } 62 }
63 63
64 static void appendMailtoPostFormDataToURL(KURL& url, const FormData& data, const String& encodingType) 64 static void appendMailtoPostFormDataToURL(KURL& url, const EncodedFormData& data , const String& encodingType)
65 { 65 {
66 String body = data.flattenToString(); 66 String body = data.flattenToString();
67 67
68 if (equalIgnoringCase(encodingType, "text/plain")) { 68 if (equalIgnoringCase(encodingType, "text/plain")) {
69 // Convention seems to be to decode, and s/&/\r\n/. Also, spaces are enc oded as %20. 69 // Convention seems to be to decode, and s/&/\r\n/. Also, spaces are enc oded as %20.
70 body = decodeURLEscapeSequences(body.replaceWithLiteral('&', "\r\n").rep lace('+', ' ') + "\r\n"); 70 body = decodeURLEscapeSequences(body.replaceWithLiteral('&', "\r\n").rep lace('+', ' ') + "\r\n");
71 } 71 }
72 72
73 Vector<char> bodyData; 73 Vector<char> bodyData;
74 bodyData.append("body=", 5); 74 bodyData.append("body=", 5);
75 FormDataBuilder::encodeStringAsFormData(bodyData, body.utf8()); 75 FormDataEncoder::encodeStringAsFormData(bodyData, body.utf8());
76 body = String(bodyData.data(), bodyData.size()).replaceWithLiteral('+', "%20 "); 76 body = String(bodyData.data(), bodyData.size()).replaceWithLiteral('+', "%20 ");
77 77
78 StringBuilder query; 78 StringBuilder query;
79 query.append(url.query()); 79 query.append(url.query());
80 if (!query.isEmpty()) 80 if (!query.isEmpty())
81 query.append('&'); 81 query.append('&');
82 query.append(body); 82 query.append(body);
83 url.setQuery(query.toString()); 83 url.setQuery(query.toString());
84 } 84 }
85 85
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
136 { 136 {
137 m_method = other.m_method; 137 m_method = other.m_method;
138 m_isMultiPartForm = other.m_isMultiPartForm; 138 m_isMultiPartForm = other.m_isMultiPartForm;
139 139
140 m_action = other.m_action; 140 m_action = other.m_action;
141 m_target = other.m_target; 141 m_target = other.m_target;
142 m_encodingType = other.m_encodingType; 142 m_encodingType = other.m_encodingType;
143 m_acceptCharset = other.m_acceptCharset; 143 m_acceptCharset = other.m_acceptCharset;
144 } 144 }
145 145
146 inline FormSubmission::FormSubmission(Method method, const KURL& action, const A tomicString& target, const AtomicString& contentType, HTMLFormElement* form, Pas sRefPtr<FormData> data, const String& boundary, PassRefPtrWillBeRawPtr<Event> ev ent) 146 inline FormSubmission::FormSubmission(Method method, const KURL& action, const A tomicString& target, const AtomicString& contentType, HTMLFormElement* form, Pas sRefPtr<EncodedFormData> data, const String& boundary, PassRefPtrWillBeRawPtr<Ev ent> event)
147 : m_method(method) 147 : m_method(method)
148 , m_action(action) 148 , m_action(action)
149 , m_target(target) 149 , m_target(target)
150 , m_contentType(contentType) 150 , m_contentType(contentType)
151 , m_form(form) 151 , m_form(form)
152 , m_formData(data) 152 , m_formData(data)
153 , m_boundary(boundary) 153 , m_boundary(boundary)
154 , m_event(event) 154 , m_event(event)
155 { 155 {
156 } 156 }
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
201 bool isMultiPartForm = false; 201 bool isMultiPartForm = false;
202 AtomicString encodingType = copiedAttributes.encodingType(); 202 AtomicString encodingType = copiedAttributes.encodingType();
203 203
204 if (copiedAttributes.method() == PostMethod) { 204 if (copiedAttributes.method() == PostMethod) {
205 isMultiPartForm = copiedAttributes.isMultiPartForm(); 205 isMultiPartForm = copiedAttributes.isMultiPartForm();
206 if (isMultiPartForm && isMailtoForm) { 206 if (isMultiPartForm && isMailtoForm) {
207 encodingType = AtomicString("application/x-www-form-urlencoded", Ato micString::ConstructFromLiteral); 207 encodingType = AtomicString("application/x-www-form-urlencoded", Ato micString::ConstructFromLiteral);
208 isMultiPartForm = false; 208 isMultiPartForm = false;
209 } 209 }
210 } 210 }
211 WTF::TextEncoding dataEncoding = isMailtoForm ? UTF8Encoding() : FormDataBui lder::encodingFromAcceptCharset(copiedAttributes.acceptCharset(), document.chars et(), document.defaultCharset()); 211 WTF::TextEncoding dataEncoding = isMailtoForm ? UTF8Encoding() : FormDataEnc oder::encodingFromAcceptCharset(copiedAttributes.acceptCharset(), document.chars et(), document.defaultCharset());
212 DOMFormData* domFormData = DOMFormData::create(dataEncoding.encodingForFormS ubmission()); 212 DOMFormData* domFormData = DOMFormData::create(dataEncoding.encodingForFormS ubmission());
213 213
214 bool containsPasswordData = false; 214 bool containsPasswordData = false;
215 for (unsigned i = 0; i < form->associatedElements().size(); ++i) { 215 for (unsigned i = 0; i < form->associatedElements().size(); ++i) {
216 FormAssociatedElement* control = form->associatedElements()[i]; 216 FormAssociatedElement* control = form->associatedElements()[i];
217 ASSERT(control); 217 ASSERT(control);
218 HTMLElement& element = toHTMLElement(*control); 218 HTMLElement& element = toHTMLElement(*control);
219 if (!element.isDisabledFormControl()) 219 if (!element.isDisabledFormControl())
220 control->appendFormData(*domFormData, isMultiPartForm); 220 control->appendFormData(*domFormData, isMultiPartForm);
221 if (isHTMLInputElement(element)) { 221 if (isHTMLInputElement(element)) {
222 HTMLInputElement& input = toHTMLInputElement(element); 222 HTMLInputElement& input = toHTMLInputElement(element);
223 if (input.type() == InputTypeNames::password && !input.value().isEmp ty()) 223 if (input.type() == InputTypeNames::password && !input.value().isEmp ty())
224 containsPasswordData = true; 224 containsPasswordData = true;
225 } 225 }
226 } 226 }
227 227
228 RefPtr<FormData> formData; 228 RefPtr<EncodedFormData> formData;
229 String boundary; 229 String boundary;
230 230
231 if (isMultiPartForm) { 231 if (isMultiPartForm) {
232 formData = domFormData->createMultiPartFormData(); 232 formData = domFormData->createMultiPartFormData();
233 boundary = formData->boundary().data(); 233 boundary = formData->boundary().data();
234 } else { 234 } else {
235 formData = domFormData->createFormData(attributes.method() == GetMethod ? FormData::FormURLEncoded : FormData::parseEncodingType(encodingType)); 235 formData = domFormData->createFormData(attributes.method() == GetMethod ? EncodedFormData::FormURLEncoded : EncodedFormData::parseEncodingType(encodingT ype));
236 if (copiedAttributes.method() == PostMethod && isMailtoForm) { 236 if (copiedAttributes.method() == PostMethod && isMailtoForm) {
237 // Convert the form data into a string that we put into the URL. 237 // Convert the form data into a string that we put into the URL.
238 appendMailtoPostFormDataToURL(actionURL, *formData, encodingType); 238 appendMailtoPostFormDataToURL(actionURL, *formData, encodingType);
239 formData = FormData::create(); 239 formData = EncodedFormData::create();
240 } 240 }
241 } 241 }
242 242
243 formData->setIdentifier(generateFormDataIdentifier()); 243 formData->setIdentifier(generateFormDataIdentifier());
244 formData->setContainsPasswordData(containsPasswordData); 244 formData->setContainsPasswordData(containsPasswordData);
245 AtomicString targetOrBaseTarget = copiedAttributes.target().isEmpty() ? docu ment.baseTarget() : copiedAttributes.target(); 245 AtomicString targetOrBaseTarget = copiedAttributes.target().isEmpty() ? docu ment.baseTarget() : copiedAttributes.target();
246 return adoptRefWillBeNoop(new FormSubmission(copiedAttributes.method(), acti onURL, targetOrBaseTarget, encodingType, form, formData.release(), boundary, eve nt)); 246 return adoptRefWillBeNoop(new FormSubmission(copiedAttributes.method(), acti onURL, targetOrBaseTarget, encodingType, form, formData.release(), boundary, eve nt));
247 } 247 }
248 248
249 DEFINE_TRACE(FormSubmission) 249 DEFINE_TRACE(FormSubmission)
(...skipping 25 matching lines...) Expand all
275 if (m_boundary.isEmpty()) 275 if (m_boundary.isEmpty())
276 frameRequest.resourceRequest().setHTTPContentType(m_contentType); 276 frameRequest.resourceRequest().setHTTPContentType(m_contentType);
277 else 277 else
278 frameRequest.resourceRequest().setHTTPContentType(m_contentType + "; boundary=" + m_boundary); 278 frameRequest.resourceRequest().setHTTPContentType(m_contentType + "; boundary=" + m_boundary);
279 } 279 }
280 280
281 frameRequest.resourceRequest().setURL(requestURL()); 281 frameRequest.resourceRequest().setURL(requestURL());
282 } 282 }
283 283
284 } 284 }
OLDNEW
« no previous file with comments | « Source/core/loader/FormSubmission.h ('k') | Source/core/loader/FrameLoader.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698