Changeset 61546 in webkit
- Timestamp:
- Jun 21, 2010 9:36:40 AM (11 years ago)
- Location:
- trunk/WebCore
- Files:
-
- 7 edited
-
ChangeLog (modified) (1 diff)
-
html/HTMLFormElement.cpp (modified) (3 diffs)
-
loader/FormSubmission.cpp (modified) (3 diffs)
-
loader/FormSubmission.h (modified) (5 diffs)
-
loader/FrameLoader.cpp (modified) (4 diffs)
-
loader/RedirectScheduler.cpp (modified) (6 diffs)
-
loader/RedirectScheduler.h (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/WebCore/ChangeLog
r61545 r61546 1 2010-06-03 Dimitri Glazkov <dglazkov@chromium.org> 2 3 Reviewed by Darin Adler. 4 5 Plumb FormSubmission through to ScheduledFormSubmission. 6 https://bugs.webkit.org/show_bug.cgi?id=40137 7 8 No behavior change, covered by existing tests. 9 10 * html/HTMLFormElement.cpp: 11 (WebCore::HTMLFormElement::prepareFormSubmission): Moved creation of action URL 12 instance here from FrameLoader::submit, because it makes more sense here, 13 also added a FIXME to investigate existing code later. 14 * loader/FormSubmission.cpp: 15 (WebCore::FormSubmission::FormSubmission): Changed action to be a KURL, not a String. 16 (WebCore::FormSubmission::create): Ditto. 17 (WebCore::FormSubmission::populateFrameLoadRequest): Added, moving the logic from 18 FrameLoader::submit closer to the data. 19 * loader/FormSubmission.h: 20 (WebCore::FormSubmission::action): Changed type to KURL. 21 (WebCore::FormSubmission::clearTarget): Added. 22 (WebCore::FormSubmission::referrer): Added. 23 (WebCore::FormSubmission::setReferrer): Added. 24 (WebCore::FormSubmission::origin): Added. 25 (WebCore::FormSubmission::setOrigin): Added. 26 * loader/FrameLoader.cpp: 27 (WebCore::FrameLoader::submitForm): Cleaned up to make it more about decision-making, 28 not data manipulation. 29 * loader/RedirectScheduler.cpp: 30 (WebCore::ScheduledFormSubmission::ScheduledFormSubmission): Changed to accept FormSubmission as argument. 31 (WebCore::ScheduledFormSubmission::fire): Changed to use FormSubmission. 32 (WebCore::RedirectScheduler::scheduleFormSubmission): Removed assert that no longer makes sense, 33 changed to use FormSubmission. 34 * loader/RedirectScheduler.h: Updated ScheduledFormSubmission decl to hold FormSubmission ref. 35 1 36 2010-06-21 Satish Sampath <satish@chromium.org> 2 37 -
trunk/WebCore/html/HTMLFormElement.cpp
r61511 r61546 253 253 RefPtr<FormData> formData; 254 254 String boundary; 255 // FIXME: Figure out whether m_url.isNull check is necessary. 256 KURL actionURL = document()->completeURL(m_url.isNull() ? "" : m_url); 255 257 256 258 if (m_formDataBuilder.isMultiPartForm()) { … … 261 263 if (m_formDataBuilder.isPostMethod() && isMailtoForm()) { 262 264 // Convert the form data into a string that we put into the URL. 263 KURL url = document()->completeURL(m_url);264 appendMailtoPostFormDataToURL(url, *formData, m_formDataBuilder.encodingType());265 m_url = url.string();265 appendMailtoPostFormDataToURL(actionURL, *formData, m_formDataBuilder.encodingType()); 266 // FIXME: Why is setting m_url necessary here? This seems wrong if mail form is submitted multiple times? 267 m_url = actionURL.string(); 266 268 267 269 formData = FormData::create(); … … 271 273 formData->setIdentifier(generateFormDataIdentifier()); 272 274 FormSubmission::Method method = m_formDataBuilder.isPostMethod() ? FormSubmission::PostMethod : FormSubmission::GetMethod; 273 return FormSubmission::create(method, m_url, m_target, m_formDataBuilder.encodingType(), FormState::create(this, formValues, document()->frame(), trigger), formData.release(), boundary, lockHistory, event); 275 String targetOrBaseTarget = m_target.isEmpty() ? document()->baseTarget() : m_target; 276 return FormSubmission::create(method, actionURL, targetOrBaseTarget, m_formDataBuilder.encodingType(), FormState::create(this, formValues, document()->frame(), trigger), formData.release(), boundary, lockHistory, event); 274 277 } 275 278 -
trunk/WebCore/loader/FormSubmission.cpp
r61511 r61546 36 36 #include "FormState.h" 37 37 #include "Frame.h" 38 #include "FrameLoadRequest.h" 39 #include "FrameLoader.h" 38 40 #include "HTMLFormElement.h" 39 41 #include <wtf/PassRefPtr.h> … … 41 43 namespace WebCore { 42 44 43 FormSubmission::FormSubmission(Method method, const String& action, const String& target, const String& contentType, PassRefPtr<FormState> state, PassRefPtr<FormData> data, const String& boundary, bool lockHistory, PassRefPtr<Event> event)45 FormSubmission::FormSubmission(Method method, const KURL& action, const String& target, const String& contentType, PassRefPtr<FormState> state, PassRefPtr<FormData> data, const String& boundary, bool lockHistory, PassRefPtr<Event> event) 44 46 : m_method(method) 45 47 , m_action(action) … … 54 56 } 55 57 56 57 PassRefPtr<FormSubmission> FormSubmission::create(Method method, const String& action, const String& target, const String& contentType, PassRefPtr<FormState> state, PassRefPtr<FormData> data, const String& boundary, bool lockHistory, PassRefPtr<Event> event) 58 PassRefPtr<FormSubmission> FormSubmission::create(Method method, const KURL& action, const String& target, const String& contentType, PassRefPtr<FormState> state, PassRefPtr<FormData> data, const String& boundary, bool lockHistory, PassRefPtr<Event> event) 58 59 { 59 60 return adoptRef(new FormSubmission(method, action, target, contentType, state, data, boundary, lockHistory, event)); 60 61 } 61 62 63 void FormSubmission::populateFrameLoadRequest(FrameLoadRequest& frameRequest) 64 { 65 if (!m_target.isEmpty()) 66 frameRequest.setFrameName(m_target); 67 68 if (!m_referrer.isEmpty()) 69 frameRequest.resourceRequest().setHTTPReferrer(m_referrer); 70 71 if (m_method == FormSubmission::GetMethod) 72 m_action.setQuery(m_formData->flattenToString()); 73 else { 74 frameRequest.resourceRequest().setHTTPMethod("POST"); 75 frameRequest.resourceRequest().setHTTPBody(m_formData); 76 77 // construct some user headers if necessary 78 if (m_contentType.isNull() || m_contentType == "application/x-www-form-urlencoded") 79 frameRequest.resourceRequest().setHTTPContentType(m_contentType); 80 else // contentType must be "multipart/form-data" 81 frameRequest.resourceRequest().setHTTPContentType(m_contentType + "; boundary=" + m_boundary); 82 } 83 84 frameRequest.resourceRequest().setURL(m_action); 85 FrameLoader::addHTTPOriginIfNeeded(frameRequest.resourceRequest(), m_origin); 62 86 } 87 88 } -
trunk/WebCore/loader/FormSubmission.h
r61511 r61546 32 32 #define FormSubmission_h 33 33 34 #include "PlatformString.h" 35 #include <wtf/Forward.h> 36 #include <wtf/RefCounted.h> 34 #include "KURL.h" 37 35 38 36 namespace WebCore { … … 41 39 class FormData; 42 40 class FormState; 41 class FrameLoadRequest; 43 42 44 43 class FormSubmission : public RefCounted<FormSubmission> { … … 49 48 }; 50 49 51 static PassRefPtr<FormSubmission> create(Method, const String& action, const String& target, const String& contentType, PassRefPtr<FormState>, PassRefPtr<FormData>, const String& boundary, bool lockHistory, PassRefPtr<Event>); 50 static PassRefPtr<FormSubmission> create(Method, const KURL& action, const String& target, const String& contentType, PassRefPtr<FormState>, PassRefPtr<FormData>, const String& boundary, bool lockHistory, PassRefPtr<Event>); 51 52 void populateFrameLoadRequest(FrameLoadRequest&); 52 53 53 54 Method method() const { return m_method; } 54 Stringaction() const { return m_action; }55 const KURL& action() const { return m_action; } 55 56 String target() const { return m_target; } 57 void clearTarget() { m_target = String(); } 56 58 String contentType() const { return m_contentType; } 57 59 FormState* state() const { return m_formState.get(); } … … 61 63 Event* event() const { return m_event.get(); } 62 64 65 const String& referrer() const { return m_referrer; } 66 void setReferrer(const String& referrer) { m_referrer = referrer; } 67 const String& origin() const { return m_origin; } 68 void setOrigin(const String& origin) { m_origin = origin; } 69 63 70 private: 64 FormSubmission(Method, const String& action, const String& target, const String& contentType, PassRefPtr<FormState>, PassRefPtr<FormData>, const String& boundary, bool lockHistory, PassRefPtr<Event>);71 FormSubmission(Method, const KURL& action, const String& target, const String& contentType, PassRefPtr<FormState>, PassRefPtr<FormData>, const String& boundary, bool lockHistory, PassRefPtr<Event>); 65 72 66 73 Method m_method; 67 Stringm_action;74 KURL m_action; 68 75 String m_target; 69 76 String m_contentType; … … 73 80 bool m_lockHistory; 74 81 RefPtr<Event> m_event; 82 String m_referrer; 83 String m_origin; 75 84 }; 76 85 -
trunk/WebCore/loader/FrameLoader.cpp
r61511 r61546 464 464 void FrameLoader::submitForm(PassRefPtr<FormSubmission> submission) 465 465 { 466 // FIXME: Plumb this further in. 467 const char* action = submission->method() == FormSubmission::PostMethod ? "POST" : "GET"; 468 RefPtr<FormData> formData = submission->data(); 469 RefPtr<FormState> formState = submission->state(); 470 String url = submission->action(); 471 String target = submission->target(); 472 String boundary = submission->boundary(); 473 String contentType = submission->contentType(); 474 bool lockHistory = submission->lockHistory(); 475 RefPtr<Event> event = submission->event(); 476 477 ASSERT(action); 478 ASSERT(strcmp(action, "GET") == 0 || strcmp(action, "POST") == 0); 479 ASSERT(formData); 480 ASSERT(formState); 481 ASSERT(formState->sourceFrame() == m_frame); 466 ASSERT(submission->method() == FormSubmission::PostMethod || submission->method() == FormSubmission::GetMethod); 467 468 // FIXME: Find a good spot for these. 469 ASSERT(submission->data()); 470 ASSERT(submission->state()); 471 ASSERT(submission->state()->sourceFrame() == m_frame); 482 472 483 473 if (!m_frame->page()) 484 474 return; 485 475 486 KURL u = completeURL(url.isNull() ? "" : url); 487 if (u.isEmpty()) 476 if (submission->action().isEmpty()) 488 477 return; 489 478 … … 491 480 return; 492 481 493 if (protocolIsJavaScript( u)) {482 if (protocolIsJavaScript(submission->action())) { 494 483 m_isExecutingJavaScriptFormAction = true; 495 m_frame->script()->executeIfJavaScriptURL( u, false, DoNotReplaceDocumentIfJavaScriptURL);484 m_frame->script()->executeIfJavaScriptURL(submission->action(), false, DoNotReplaceDocumentIfJavaScriptURL); 496 485 m_isExecutingJavaScriptFormAction = false; 497 486 return; 498 487 } 499 488 500 FrameLoadRequest frameRequest; 501 502 String targetOrBaseTarget = target.isEmpty() ? m_frame->document()->baseTarget() : target; 503 Frame* targetFrame = m_frame->tree()->find(targetOrBaseTarget); 489 Frame* targetFrame = m_frame->tree()->find(submission->target()); 504 490 if (!shouldAllowNavigation(targetFrame)) 505 491 return; … … 509 495 510 496 targetFrame = m_frame; 511 frameRequest.setFrameName(targetOrBaseTarget); 512 } 497 } else 498 submission->clearTarget(); 499 513 500 if (!targetFrame->page()) 514 501 return; … … 527 514 528 515 if (m_frame->tree()->isDescendantOf(targetFrame)) { 529 if (m_submittedFormURL == u)516 if (m_submittedFormURL == submission->action()) 530 517 return; 531 m_submittedFormURL = u; 532 } 533 534 formData->generateFiles(m_frame->document()); 535 536 if (!m_outgoingReferrer.isEmpty()) 537 frameRequest.resourceRequest().setHTTPReferrer(m_outgoingReferrer); 538 539 if (strcmp(action, "GET") == 0) 540 u.setQuery(formData->flattenToString()); 541 else { 542 frameRequest.resourceRequest().setHTTPMethod("POST"); 543 frameRequest.resourceRequest().setHTTPBody(formData); 544 545 // construct some user headers if necessary 546 if (contentType.isNull() || contentType == "application/x-www-form-urlencoded") 547 frameRequest.resourceRequest().setHTTPContentType(contentType); 548 else // contentType must be "multipart/form-data" 549 frameRequest.resourceRequest().setHTTPContentType(contentType + "; boundary=" + boundary); 550 } 551 552 frameRequest.resourceRequest().setURL(u); 553 addHTTPOriginIfNeeded(frameRequest.resourceRequest(), outgoingOrigin()); 554 555 targetFrame->redirectScheduler()->scheduleFormSubmission(frameRequest, lockHistory, event, formState); 518 m_submittedFormURL = submission->action(); 519 } 520 521 submission->data()->generateFiles(m_frame->document()); 522 submission->setReferrer(m_outgoingReferrer); 523 submission->setOrigin(outgoingOrigin()); 524 525 targetFrame->redirectScheduler()->scheduleFormSubmission(submission); 556 526 } 557 527 -
trunk/WebCore/loader/RedirectScheduler.cpp
r59462 r61546 37 37 #include "Event.h" 38 38 #include "FormState.h" 39 #include "FormSubmission.h" 39 40 #include "Frame.h" 40 41 #include "FrameLoadRequest.h" … … 171 172 class ScheduledFormSubmission : public ScheduledNavigation { 172 173 public: 173 ScheduledFormSubmission(const FrameLoadRequest& frameRequest, bool lockHistory, bool lockBackForwardList, PassRefPtr<Event> event, PassRefPtr<FormState> formState, bool duringLoad) 174 : ScheduledNavigation(0, lockHistory, lockBackForwardList, duringLoad, true) 175 , m_frameRequest(frameRequest) 176 , m_event(event) 177 , m_formState(formState) 174 ScheduledFormSubmission(PassRefPtr<FormSubmission> submission, bool lockBackForwardList, bool duringLoad) 175 : ScheduledNavigation(0, submission->lockHistory(), lockBackForwardList, duringLoad, true) 176 , m_submission(submission) 178 177 , m_wasProcessingUserGesture(UserGestureIndicator::processingUserGesture()) 179 178 { 180 ASSERT(!frameRequest.isEmpty()); 181 ASSERT(m_formState); 179 ASSERT(m_submission->state()); 182 180 } 183 181 … … 190 188 // selecting a target, in case conditions have changed. Other code paths avoid this by targeting 191 189 // without leaving a time window. If we fail the check just silently drop the form submission. 192 if (!m_ formState->sourceFrame()->loader()->shouldAllowNavigation(frame))190 if (!m_submission->state()->sourceFrame()->loader()->shouldAllowNavigation(frame)) 193 191 return; 194 frame->loader()->loadFrameRequest(m_frameRequest, lockHistory(), lockBackForwardList(), m_event, m_formState, SendReferrer); 192 FrameLoadRequest frameRequest; 193 m_submission->populateFrameLoadRequest(frameRequest); 194 frame->loader()->loadFrameRequest(frameRequest, lockHistory(), lockBackForwardList(), m_submission->event(), m_submission->state(), SendReferrer); 195 195 } 196 196 … … 201 201 202 202 private: 203 const FrameLoadRequest m_frameRequest; 204 const RefPtr<Event> m_event; 205 const RefPtr<FormState> m_formState; 203 RefPtr<FormSubmission> m_submission; 206 204 bool m_wasProcessingUserGesture; 207 205 }; … … 287 285 } 288 286 289 void RedirectScheduler::scheduleFormSubmission(const FrameLoadRequest& frameRequest, 290 bool lockHistory, PassRefPtr<Event> event, PassRefPtr<FormState> formState) 287 void RedirectScheduler::scheduleFormSubmission(PassRefPtr<FormSubmission> submission) 291 288 { 292 289 ASSERT(m_frame->page()); 293 ASSERT(!frameRequest.isEmpty());294 290 295 291 // FIXME: Do we need special handling for form submissions where the URL is the same … … 304 300 // See https://bugs.webkit.org/show_bug.cgi?id=32383 for the original motivation for this. 305 301 306 bool lockBackForwardList = mustLockBackForwardList(m_frame) || ( formState->formSubmissionTrigger() == SubmittedByJavaScript && m_frame->tree()->parent());307 308 schedule(new ScheduledFormSubmission( frameRequest, lockHistory, lockBackForwardList, event, formState, duringLoad));302 bool lockBackForwardList = mustLockBackForwardList(m_frame) || (submission->state()->formSubmissionTrigger() == SubmittedByJavaScript && m_frame->tree()->parent()); 303 304 schedule(new ScheduledFormSubmission(submission, lockBackForwardList, duringLoad)); 309 305 } 310 306 -
trunk/WebCore/loader/RedirectScheduler.h
r56875 r61546 41 41 42 42 class FormState; 43 class FormSubmission; 43 44 class Frame; 44 45 class String; … … 57 58 void scheduleRedirect(double delay, const String& url); 58 59 void scheduleLocationChange(const String& url, const String& referrer, bool lockHistory = true, bool lockBackForwardList = true, bool userGesture = false); 59 void scheduleFormSubmission( const FrameLoadRequest&, bool lockHistory, PassRefPtr<Event>, PassRefPtr<FormState>);60 void scheduleFormSubmission(PassRefPtr<FormSubmission>); 60 61 void scheduleRefresh(bool userGesture = false); 61 62 void scheduleHistoryNavigation(int steps);
Note: See TracChangeset
for help on using the changeset viewer.