Changeset 224206 in webkit
- Timestamp:
- Oct 30, 2017 3:42:23 PM (6 years ago)
- Location:
- trunk
- Files:
-
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/ChangeLog
r224202 r224206 1 2017-10-30 Michael Catanzaro <mcatanzaro@igalia.com> 2 3 WKBundlePageWillSendSubmitEventCallback is called with incorrect frame parameter 4 https://bugs.webkit.org/show_bug.cgi?id=176719 5 6 Reviewed by Chris Dumez. 7 8 WKBundlePageWillSendSubmitEventCallback is clearly intended to parallel 9 WKBundlePageWillSubmitFormCallback, since almost all the parameters are the same. Now, in 10 WKBundlePageWillSubmitFormCallback, the first WKBundleFrameRef, "frame", is the frame of the 11 form target, and the second WKBundleFrameRef, sourceFrame, is the frame containing the form. 12 That's correct. But in WKBundlePageWillSendSubmitEventCallback, both frame and sourceFrame 13 are always identical. The problem is that the FrameLoaderClient delegate is called on the 14 wrong FrameLoaderClient. It should be called on the FrameLoaderClient of the target frame, 15 but HTMLFormElement calls it on the FrameLoaderClient of the source frame instead. 16 17 Fix this by factoring the target frame computation out of FormSubmission into some helpers. 18 19 * html/HTMLFormElement.cpp: 20 (WebCore::HTMLFormElement::prepareForSubmission): 21 (WebCore::HTMLFormElement::effectiveTarget const): 22 (WebCore::HTMLFormElement::findSubmitButton const): 23 * html/HTMLFormElement.h: 24 * loader/FormSubmission.cpp: 25 (WebCore::FormSubmission::create): 26 1 27 2017-10-30 Alex Christensen <achristensen@webkit.org> 2 28 -
trunk/Source/WebCore/html/HTMLFormElement.cpp
r223802 r224206 280 280 } 281 281 282 auto targetFrame = frame->loader().findFrameForNavigation(effectiveTarget(&event), &document()); 283 if (!targetFrame) 284 targetFrame = frame.get(); 282 285 auto formState = FormState::create(*this, textFieldValues(), document(), NotSubmittedByJavaScript); 283 frame->loader().client().dispatchWillSendSubmitEvent(WTFMove(formState));286 targetFrame->loader().client().dispatchWillSendSubmitEvent(WTFMove(formState)); 284 287 285 288 Ref<HTMLFormElement> protectedThis(*this); … … 643 646 } 644 647 648 String HTMLFormElement::effectiveTarget(const Event* event) const 649 { 650 if (auto* submitButton = findSubmitButton(event)) { 651 auto targetValue = submitButton->attributeWithoutSynchronization(formtargetAttr); 652 if (!targetValue.isNull()) 653 return targetValue; 654 } 655 656 auto targetValue = target(); 657 if (!targetValue.isNull()) 658 return targetValue; 659 660 return document().baseTarget(); 661 } 662 645 663 bool HTMLFormElement::wasUserSubmitted() const 646 664 { 647 665 return m_wasUserSubmitted; 666 } 667 668 HTMLFormControlElement* HTMLFormElement::findSubmitButton(const Event* event) const 669 { 670 if (event && event->target()) { 671 for (auto node = event->target()->toNode(); node; node = node->parentNode()) { 672 if (is<HTMLFormControlElement>(*node)) 673 return downcast<HTMLFormControlElement>(node.get()); 674 } 675 } 676 return nullptr; 648 677 } 649 678 -
trunk/Source/WebCore/html/HTMLFormElement.h
r223802 r224206 103 103 104 104 String target() const final; 105 String effectiveTarget(const Event*) const; 105 106 106 107 bool wasUserSubmitted() const; 108 109 HTMLFormControlElement* findSubmitButton(const Event*) const; 107 110 108 111 HTMLFormControlElement* defaultButton() const; -
trunk/Source/WebCore/loader/FormSubmission.cpp
r223644 r224206 148 148 Ref<FormSubmission> FormSubmission::create(HTMLFormElement& form, const Attributes& attributes, Event* event, LockHistory lockHistory, FormSubmissionTrigger trigger) 149 149 { 150 HTMLFormControlElement* submitButton = nullptr;151 if (event && event->target()) {152 for (auto node = event->target()->toNode(); node; node = node->parentNode()) {153 if (is<HTMLFormControlElement>(*node)) {154 submitButton = downcast<HTMLFormControlElement>(node.get());155 break;156 }157 }158 }159 160 150 auto copiedAttributes = attributes; 161 if (submitButton) { 151 152 if (auto* submitButton = form.findSubmitButton(event)) { 162 153 AtomicString attributeValue; 163 154 if (!(attributeValue = submitButton->attributeWithoutSynchronization(formactionAttr)).isNull()) … … 229 220 formData->setContainsPasswordData(containsPasswordData); 230 221 231 String targetOrBaseTarget = copiedAttributes.target().isEmpty() ? document.baseTarget() : copiedAttributes.target();232 233 222 auto formState = FormState::create(form, WTFMove(formValues), document, trigger); 234 223 235 return adoptRef(*new FormSubmission(copiedAttributes.method(), actionURL, targetOrBaseTarget, encodingType, WTFMove(formState), formData.releaseNonNull(), boundary, lockHistory, event));224 return adoptRef(*new FormSubmission(copiedAttributes.method(), actionURL, form.effectiveTarget(event), encodingType, WTFMove(formState), formData.releaseNonNull(), boundary, lockHistory, event)); 236 225 } 237 226 -
trunk/Tools/ChangeLog
r224202 r224206 1 2017-10-30 Michael Catanzaro <mcatanzaro@igalia.com> 2 3 WKBundlePageWillSendSubmitEventCallback is called with incorrect frame parameter 4 https://bugs.webkit.org/show_bug.cgi?id=176719 5 6 Reviewed by Chris Dumez. 7 8 Test that WKBundlePageWillSendSubmitEventCallback is called with separate frame and 9 sourceFrame parameters when the target frame of the form submission is not the source frame. 10 11 * TestWebKitAPI/Tests/WebKit/WillSendSubmitEvent.cpp: 12 (TestWebKitAPI::didReceiveMessageFromInjectedBundle): 13 * TestWebKitAPI/Tests/WebKit/WillSendSubmitEvent_Bundle.cpp: 14 (TestWebKitAPI::willSendSubmitEvent): 15 * TestWebKitAPI/Tests/WebKit/auto-submitting-form.html: 16 1 17 2017-10-30 Alex Christensen <achristensen@webkit.org> 2 18 -
trunk/Tools/TestWebKitAPI/Tests/WebKit/WillSendSubmitEvent.cpp
r221505 r224206 57 57 WKStringRef hiddenFieldValueWK = static_cast<WKStringRef>(WKDictionaryGetItemForKey(values, hiddenFieldKey.get())); 58 58 EXPECT_NULL(hiddenFieldValueWK); 59 60 WKRetainPtr<WKStringRef> targetFrameKey(AdoptWK, WKStringCreateWithUTF8CString("targetFrameIsMainFrame")); 61 WKBooleanRef targetFrameIsMainFrame = static_cast<WKBooleanRef>(WKDictionaryGetItemForKey(values, targetFrameKey.get())); 62 EXPECT_FALSE(WKBooleanGetValue(targetFrameIsMainFrame)); 63 64 WKRetainPtr<WKStringRef> sourceFrameKey(AdoptWK, WKStringCreateWithUTF8CString("sourceFrameIsMainFrame")); 65 WKBooleanRef sourceFrameIsMainFrame = static_cast<WKBooleanRef>(WKDictionaryGetItemForKey(values, sourceFrameKey.get())); 66 EXPECT_TRUE(WKBooleanGetValue(sourceFrameIsMainFrame)); 59 67 } 60 68 -
trunk/Tools/TestWebKitAPI/Tests/WebKit/WillSendSubmitEvent_Bundle.cpp
r179409 r224206 31 31 32 32 #include "PlatformUtilities.h" 33 #include <WebKit/WKBundleFrame.h> 33 34 #include <WebKit/WKBundlePage.h> 34 35 … … 44 45 static InjectedBundleTest::Register<WillSendSubmitEventTest> registrar("WillSendSubmitEventTest"); 45 46 46 static void willSendSubmitEvent(WKBundlePageRef, WKBundleNodeHandleRef, WKBundleFrameRef , WKBundleFrameRef, WKDictionaryRef values, const void*)47 static void willSendSubmitEvent(WKBundlePageRef, WKBundleNodeHandleRef, WKBundleFrameRef targetFrame, WKBundleFrameRef sourceFrame, WKDictionaryRef values, const void*) 47 48 { 49 auto messageBody = const_cast<WKMutableDictionaryRef>(values); 50 51 auto targetFrameKey = Util::toWK("targetFrameIsMainFrame"); 52 auto targetFrameValue = adoptWK(WKBooleanCreate(WKBundleFrameIsMainFrame(targetFrame))); 53 WKDictionarySetItem(messageBody, targetFrameKey.get(), targetFrameValue.get()); 54 55 auto sourceFrameKey = Util::toWK("sourceFrameIsMainFrame"); 56 auto sourceFrameValue = adoptWK(WKBooleanCreate(WKBundleFrameIsMainFrame(sourceFrame))); 57 WKDictionarySetItem(messageBody, sourceFrameKey.get(), sourceFrameValue.get()); 58 48 59 WKBundlePostMessage(InjectedBundleController::singleton().bundle(), Util::toWK("DidReceiveWillSendSubmitEvent").get(), values); 49 60 } -
trunk/Tools/TestWebKitAPI/Tests/WebKit/auto-submitting-form.html
r116016 r224206 11 11 </head> 12 12 <body onload="submitFormIfNecessary()"> 13 <form action="#" method="GET" >13 <form action="#" method="GET" target="target_frame"> 14 14 <input type="text" name="textField" value="text field"> 15 15 <input type="password" name="passwordField" value="password field"> … … 17 17 <input type="submit" name="submit"> 18 18 </form> 19 <iframe name="target_frame"></iframe> 19 20 </body> 20 21 </html>
Note: See TracChangeset
for help on using the changeset viewer.