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

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

Issue 23819007: Have Node::document() return a reference instead of a pointer (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Rebase on master Created 7 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/DocumentLoader.cpp ('k') | Source/core/loader/ImageLoader.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 144 matching lines...) Expand 10 before | Expand all | Expand 10 after
155 if (!(attributeValue = submitButton->getAttribute(formactionAttr)).isNul l()) 155 if (!(attributeValue = submitButton->getAttribute(formactionAttr)).isNul l())
156 copiedAttributes.parseAction(attributeValue); 156 copiedAttributes.parseAction(attributeValue);
157 if (!(attributeValue = submitButton->getAttribute(formenctypeAttr)).isNu ll()) 157 if (!(attributeValue = submitButton->getAttribute(formenctypeAttr)).isNu ll())
158 copiedAttributes.updateEncodingType(attributeValue); 158 copiedAttributes.updateEncodingType(attributeValue);
159 if (!(attributeValue = submitButton->getAttribute(formmethodAttr)).isNul l()) 159 if (!(attributeValue = submitButton->getAttribute(formmethodAttr)).isNul l())
160 copiedAttributes.updateMethodType(attributeValue); 160 copiedAttributes.updateMethodType(attributeValue);
161 if (!(attributeValue = submitButton->getAttribute(formtargetAttr)).isNul l()) 161 if (!(attributeValue = submitButton->getAttribute(formtargetAttr)).isNul l())
162 copiedAttributes.setTarget(attributeValue); 162 copiedAttributes.setTarget(attributeValue);
163 } 163 }
164 164
165 Document* document = form->document(); 165 Document& document = form->document();
166 KURL actionURL = document->completeURL(copiedAttributes.action().isEmpty() ? document->url().string() : copiedAttributes.action()); 166 KURL actionURL = document.completeURL(copiedAttributes.action().isEmpty() ? document.url().string() : copiedAttributes.action());
167 bool isMailtoForm = actionURL.protocolIs("mailto"); 167 bool isMailtoForm = actionURL.protocolIs("mailto");
168 bool isMultiPartForm = false; 168 bool isMultiPartForm = false;
169 String encodingType = copiedAttributes.encodingType(); 169 String encodingType = copiedAttributes.encodingType();
170 170
171 if (copiedAttributes.method() == PostMethod) { 171 if (copiedAttributes.method() == PostMethod) {
172 isMultiPartForm = copiedAttributes.isMultiPartForm(); 172 isMultiPartForm = copiedAttributes.isMultiPartForm();
173 if (isMultiPartForm && isMailtoForm) { 173 if (isMultiPartForm && isMailtoForm) {
174 encodingType = "application/x-www-form-urlencoded"; 174 encodingType = "application/x-www-form-urlencoded";
175 isMultiPartForm = false; 175 isMultiPartForm = false;
176 } 176 }
177 } 177 }
178 178
179 WTF::TextEncoding dataEncoding = isMailtoForm ? UTF8Encoding() : FormDataBui lder::encodingFromAcceptCharset(copiedAttributes.acceptCharset(), document); 179 WTF::TextEncoding dataEncoding = isMailtoForm ? UTF8Encoding() : FormDataBui lder::encodingFromAcceptCharset(copiedAttributes.acceptCharset(), &document);
180 RefPtr<DOMFormData> domFormData = DOMFormData::create(dataEncoding.encodingF orFormSubmission()); 180 RefPtr<DOMFormData> domFormData = DOMFormData::create(dataEncoding.encodingF orFormSubmission());
181 Vector<pair<String, String> > formValues; 181 Vector<pair<String, String> > formValues;
182 182
183 bool containsPasswordData = false; 183 bool containsPasswordData = false;
184 for (unsigned i = 0; i < form->associatedElements().size(); ++i) { 184 for (unsigned i = 0; i < form->associatedElements().size(); ++i) {
185 FormAssociatedElement* control = form->associatedElements()[i]; 185 FormAssociatedElement* control = form->associatedElements()[i];
186 HTMLElement* element = toHTMLElement(control); 186 HTMLElement* element = toHTMLElement(control);
187 if (!element->isDisabledFormControl()) 187 if (!element->isDisabledFormControl())
188 control->appendFormData(*domFormData, isMultiPartForm); 188 control->appendFormData(*domFormData, isMultiPartForm);
189 if (element->hasTagName(inputTag)) { 189 if (element->hasTagName(inputTag)) {
190 HTMLInputElement* input = toHTMLInputElement(element); 190 HTMLInputElement* input = toHTMLInputElement(element);
191 if (input->isTextField()) 191 if (input->isTextField())
192 formValues.append(pair<String, String>(input->name().string(), i nput->value())); 192 formValues.append(pair<String, String>(input->name().string(), i nput->value()));
193 if (input->isPasswordField() && !input->value().isEmpty()) 193 if (input->isPasswordField() && !input->value().isEmpty())
194 containsPasswordData = true; 194 containsPasswordData = true;
195 } 195 }
196 } 196 }
197 197
198 RefPtr<FormData> formData; 198 RefPtr<FormData> formData;
199 String boundary; 199 String boundary;
200 200
201 if (isMultiPartForm) { 201 if (isMultiPartForm) {
202 formData = FormData::createMultiPart(*(static_cast<FormDataList*>(domFor mData.get())), domFormData->encoding(), document); 202 formData = FormData::createMultiPart(*(static_cast<FormDataList*>(domFor mData.get())), domFormData->encoding(), &document);
203 boundary = formData->boundary().data(); 203 boundary = formData->boundary().data();
204 } else { 204 } else {
205 formData = FormData::create(*(static_cast<FormDataList*>(domFormData.get ())), domFormData->encoding(), attributes.method() == GetMethod ? FormData::Form URLEncoded : FormData::parseEncodingType(encodingType)); 205 formData = FormData::create(*(static_cast<FormDataList*>(domFormData.get ())), domFormData->encoding(), attributes.method() == GetMethod ? FormData::Form URLEncoded : FormData::parseEncodingType(encodingType));
206 if (copiedAttributes.method() == PostMethod && isMailtoForm) { 206 if (copiedAttributes.method() == PostMethod && isMailtoForm) {
207 // Convert the form data into a string that we put into the URL. 207 // Convert the form data into a string that we put into the URL.
208 appendMailtoPostFormDataToURL(actionURL, *formData, encodingType); 208 appendMailtoPostFormDataToURL(actionURL, *formData, encodingType);
209 formData = FormData::create(); 209 formData = FormData::create();
210 } 210 }
211 } 211 }
212 212
213 formData->setIdentifier(generateFormDataIdentifier()); 213 formData->setIdentifier(generateFormDataIdentifier());
214 formData->setContainsPasswordData(containsPasswordData); 214 formData->setContainsPasswordData(containsPasswordData);
215 String targetOrBaseTarget = copiedAttributes.target().isEmpty() ? document-> baseTarget() : copiedAttributes.target(); 215 String targetOrBaseTarget = copiedAttributes.target().isEmpty() ? document.b aseTarget() : copiedAttributes.target();
216 RefPtr<FormState> formState = FormState::create(form, formValues, document, trigger); 216 RefPtr<FormState> formState = FormState::create(form, formValues, &document, trigger);
217 return adoptRef(new FormSubmission(copiedAttributes.method(), actionURL, tar getOrBaseTarget, encodingType, formState.release(), formData.release(), boundary , event)); 217 return adoptRef(new FormSubmission(copiedAttributes.method(), actionURL, tar getOrBaseTarget, encodingType, formState.release(), formData.release(), boundary , event));
218 } 218 }
219 219
220 KURL FormSubmission::requestURL() const 220 KURL FormSubmission::requestURL() const
221 { 221 {
222 if (m_method == FormSubmission::PostMethod) 222 if (m_method == FormSubmission::PostMethod)
223 return m_action; 223 return m_action;
224 224
225 KURL requestURL(m_action); 225 KURL requestURL(m_action);
226 requestURL.setQuery(m_formData->flattenToString()); 226 requestURL.setQuery(m_formData->flattenToString());
(...skipping 17 matching lines...) Expand all
244 frameRequest.resourceRequest().setHTTPContentType(m_contentType); 244 frameRequest.resourceRequest().setHTTPContentType(m_contentType);
245 else 245 else
246 frameRequest.resourceRequest().setHTTPContentType(m_contentType + "; boundary=" + m_boundary); 246 frameRequest.resourceRequest().setHTTPContentType(m_contentType + "; boundary=" + m_boundary);
247 } 247 }
248 248
249 frameRequest.resourceRequest().setURL(requestURL()); 249 frameRequest.resourceRequest().setURL(requestURL());
250 FrameLoader::addHTTPOriginIfNeeded(frameRequest.resourceRequest(), m_origin) ; 250 FrameLoader::addHTTPOriginIfNeeded(frameRequest.resourceRequest(), m_origin) ;
251 } 251 }
252 252
253 } 253 }
OLDNEW
« no previous file with comments | « Source/core/loader/DocumentLoader.cpp ('k') | Source/core/loader/ImageLoader.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698