Cleanup static_cast<HTMLFormElement*> by using toHTMLFormElement()
authorgyuyoung.kim@samsung.com <gyuyoung.kim@samsung.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 31 Dec 2013 02:58:28 +0000 (02:58 +0000)
committergyuyoung.kim@samsung.com <gyuyoung.kim@samsung.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 31 Dec 2013 02:58:28 +0000 (02:58 +0000)
https://bugs.webkit.org/show_bug.cgi?id=126309

Reviewed by Andreas Kling.

To detect bad type casts, it would be good to use toHTMLFormElement() instead of
using manual type cast. Additionally FORM_ASSOCIATED_ELEMENT_TYPE_CASTS is introduced newly
to do it.

Source/WebCore:

No new tests, no behavior changes.

* html/FormAssociatedElement.h:
* html/HTMLFormControlElement.h:
* html/HTMLFormElement.cpp:
(WebCore::HTMLFormElement::submitImplicitly):
(WebCore::HTMLFormElement::validateInteractively):
(WebCore::HTMLFormElement::submit):
(WebCore::HTMLFormElement::reset):
(WebCore::HTMLFormElement::defaultButton):
(WebCore::HTMLFormElement::checkInvalidControlsAndCollectUnhandled):
(WebCore::HTMLFormElement::documentDidResumeFromPageCache):
* loader/FormSubmission.cpp:
(WebCore::FormSubmission::create):

Source/WebKit/blackberry:

* WebCoreSupport/CredentialTransformData.cpp:
(WebCore::CredentialTransformData::findPasswordFormFields):
* WebKitSupport/DOMSupport.cpp:
(BlackBerry::WebKit::DOMSupport::toTextControlElement):
* WebKitSupport/InputHandler.cpp:
(BlackBerry::WebKit::InputHandler::updateFormState):
(BlackBerry::WebKit::InputHandler::submitForm):

Source/WebKit/win:

* WebFrame.cpp:
(WebFrame::elementWithName):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@161166 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/WebCore/ChangeLog
Source/WebCore/html/FormAssociatedElement.h
Source/WebCore/html/HTMLFormControlElement.h
Source/WebCore/html/HTMLFormElement.cpp
Source/WebCore/loader/FormSubmission.cpp
Source/WebKit/blackberry/ChangeLog
Source/WebKit/blackberry/WebCoreSupport/CredentialTransformData.cpp
Source/WebKit/blackberry/WebKitSupport/DOMSupport.cpp
Source/WebKit/blackberry/WebKitSupport/InputHandler.cpp
Source/WebKit/win/ChangeLog
Source/WebKit/win/WebFrame.cpp

index e8f7ba1..03016f8 100644 (file)
@@ -1,3 +1,29 @@
+2013-12-30  Gyuyoung Kim  <gyuyoung.kim@samsung.com>
+
+        Cleanup static_cast<HTMLFormElement*> by using toHTMLFormElement()
+        https://bugs.webkit.org/show_bug.cgi?id=126309
+
+        Reviewed by Andreas Kling.
+
+        To detect bad type casts, it would be good to use toHTMLFormElement() instead of
+        using manual type cast. Additionally FORM_ASSOCIATED_ELEMENT_TYPE_CASTS is introduced newly
+        to do it.
+
+        No new tests, no behavior changes.
+
+        * html/FormAssociatedElement.h:
+        * html/HTMLFormControlElement.h:
+        * html/HTMLFormElement.cpp:
+        (WebCore::HTMLFormElement::submitImplicitly):
+        (WebCore::HTMLFormElement::validateInteractively):
+        (WebCore::HTMLFormElement::submit):
+        (WebCore::HTMLFormElement::reset):
+        (WebCore::HTMLFormElement::defaultButton):
+        (WebCore::HTMLFormElement::checkInvalidControlsAndCollectUnhandled):
+        (WebCore::HTMLFormElement::documentDidResumeFromPageCache):
+        * loader/FormSubmission.cpp:
+        (WebCore::FormSubmission::create):
+
 2013-12-30  Anders Carlsson  <andersca@apple.com>
 
         Replace yield() and pauseBriefly() with std::this_thread::yield()
index 57ddf47..64e3f66 100644 (file)
@@ -118,6 +118,9 @@ private:
     String m_customValidationMessage;
 };
 
+#define FORM_ASSOCIATED_ELEMENT_TYPE_CASTS(ToClassName, predicate) \
+    TYPE_CASTS_BASE(ToClassName, FormAssociatedElement, element, element->predicate, element.predicate)
+
 } // namespace
 
 #endif // FormAssociatedElement_h
index efbbb58..c3fac17 100644 (file)
@@ -193,6 +193,8 @@ template <> inline bool isElementOfType<const HTMLFormControlElement>(const Elem
 
 NODE_TYPE_CASTS(HTMLFormControlElement)
 
+FORM_ASSOCIATED_ELEMENT_TYPE_CASTS(HTMLFormControlElement, isFormControlElement())
+
 } // namespace
 
 #endif
index 0e82ec3..0839386 100644 (file)
@@ -177,7 +177,7 @@ void HTMLFormElement::submitImplicitly(Event* event, bool fromImplicitSubmission
         FormAssociatedElement* formAssociatedElement = m_associatedElements[i];
         if (!formAssociatedElement->isFormControlElement())
             continue;
-        HTMLFormControlElement* formElement = static_cast<HTMLFormControlElement*>(formAssociatedElement);
+        HTMLFormControlElement* formElement = toHTMLFormControlElement(formAssociatedElement);
         if (formElement->isSuccessfulSubmitButton()) {
             if (formElement->renderer()) {
                 formElement->dispatchSimulatedClick(event);
@@ -217,7 +217,7 @@ bool HTMLFormElement::validateInteractively(Event* event)
 
     for (unsigned i = 0; i < m_associatedElements.size(); ++i) {
         if (m_associatedElements[i]->isFormControlElement())
-            static_cast<HTMLFormControlElement*>(m_associatedElements[i])->hideVisibleValidationMessage();
+            toHTMLFormControlElement(m_associatedElements[i])->hideVisibleValidationMessage();
     }
 
     Vector<RefPtr<FormAssociatedElement>> unhandledInvalidControls;
@@ -341,7 +341,7 @@ void HTMLFormElement::submit(Event* event, bool activateSubmitButton, bool proce
         if (!associatedElement->isFormControlElement())
             continue;
         if (needButtonActivation) {
-            HTMLFormControlElement* control = static_cast<HTMLFormControlElement*>(associatedElement);
+            HTMLFormControlElement* control = toHTMLFormControlElement(associatedElement);
             if (control->isActivatedSubmit())
                 needButtonActivation = false;
             else if (firstSuccessfulSubmitButton == 0 && control->isSuccessfulSubmitButton())
@@ -377,7 +377,7 @@ void HTMLFormElement::reset()
 
     for (unsigned i = 0; i < m_associatedElements.size(); ++i) {
         if (m_associatedElements[i]->isFormControlElement())
-            static_cast<HTMLFormControlElement*>(m_associatedElements[i])->reset();
+            toHTMLFormControlElement(m_associatedElements[i])->reset();
     }
 
     m_isInResetFunction = false;
@@ -624,7 +624,7 @@ HTMLFormControlElement* HTMLFormElement::defaultButton() const
     for (unsigned i = 0; i < m_associatedElements.size(); ++i) {
         if (!m_associatedElements[i]->isFormControlElement())
             continue;
-        HTMLFormControlElement* control = static_cast<HTMLFormControlElement*>(m_associatedElements[i]);
+        HTMLFormControlElement* control = toHTMLFormControlElement(m_associatedElements[i]);
         if (control->isSuccessfulSubmitButton())
             return control;
     }
@@ -650,7 +650,7 @@ bool HTMLFormElement::checkInvalidControlsAndCollectUnhandled(Vector<RefPtr<Form
     bool hasInvalidControls = false;
     for (unsigned i = 0; i < elements.size(); ++i) {
         if (elements[i]->form() == this && elements[i]->isFormControlElement()) {
-            HTMLFormControlElement* control = static_cast<HTMLFormControlElement*>(elements[i].get());
+            HTMLFormControlElement* control = toHTMLFormControlElement(elements[i].get());
             if (!control->checkValidity(&unhandledInvalidControls) && control->form() == this)
                 hasInvalidControls = true;
         }
@@ -737,7 +737,7 @@ void HTMLFormElement::documentDidResumeFromPageCache()
 
     for (unsigned i = 0; i < m_associatedElements.size(); ++i) {
         if (m_associatedElements[i]->isFormControlElement())
-            static_cast<HTMLFormControlElement*>(m_associatedElements[i])->reset();
+            toHTMLFormControlElement(m_associatedElements[i])->reset();
     }
 }
 
index a895168..f25931b 100644 (file)
@@ -145,7 +145,7 @@ PassRefPtr<FormSubmission> FormSubmission::create(HTMLFormElement* form, const A
     if (event && event->target()) {
         for (Node* node = event->target()->toNode(); node; node = node->parentNode()) {
             if (node->isElementNode() && toElement(node)->isFormControlElement()) {
-                submitButton = static_cast<HTMLFormControlElement*>(node);
+                submitButton = toHTMLFormControlElement(node);
                 break;
             }
         }
index 9d6f107..9c576b9 100644 (file)
@@ -1,3 +1,22 @@
+2013-12-30  Gyuyoung Kim  <gyuyoung.kim@samsung.com>
+
+        Cleanup static_cast<HTMLFormElement*> by using toHTMLFormElement()
+        https://bugs.webkit.org/show_bug.cgi?id=126309
+
+        Reviewed by Andreas Kling.
+
+        To detect bad type casts, it would be good to use toHTMLFormElement() instead of
+        using manual type cast. Additionally FORM_ASSOCIATED_ELEMENT_TYPE_CASTS is introduced newly
+        to do it.
+
+        * WebCoreSupport/CredentialTransformData.cpp:
+        (WebCore::CredentialTransformData::findPasswordFormFields):
+        * WebKitSupport/DOMSupport.cpp:
+        (BlackBerry::WebKit::DOMSupport::toTextControlElement):
+        * WebKitSupport/InputHandler.cpp:
+        (BlackBerry::WebKit::InputHandler::updateFormState):
+        (BlackBerry::WebKit::InputHandler::submitForm):
+
 2013-12-16  Peter Szanka  <h868064@stud.u-szeged.hu>
 
         Delete RVCT related code parts.
index 60b7dcc..77607b3 100644 (file)
@@ -143,7 +143,7 @@ bool CredentialTransformData::findPasswordFormFields(const HTMLFormElement* form
     for (size_t i = 0; i < formElements.size(); i++) {
         if (!formElements[i]->isFormControlElement())
             continue;
-        HTMLFormControlElement* formElement = static_cast<HTMLFormControlElement*>(formElements[i]);
+        HTMLFormControlElement* formElement = toHTMLFormControlElement(formElements[i]);
         if (!isHTMLInputElement(formElement))
             continue;
 
@@ -165,7 +165,7 @@ bool CredentialTransformData::findPasswordFormFields(const HTMLFormElement* form
         for (int i = firstPasswordIndex - 1; i >= 0; i--) {
             if (!formElements[i]->isFormControlElement())
                 continue;
-            HTMLFormControlElement* formElement = static_cast<HTMLFormControlElement*>(formElements[i]);
+            HTMLFormControlElement* formElement = toHTMLFormControlElement(formElements[i]);
             if (!isHTMLInputElement(formElement))
                 continue;
 
index f28368b..41935f7 100644 (file)
@@ -166,7 +166,7 @@ HTMLTextFormControlElement* toTextControlElement(Node* node)
     if (!element->isFormControlElement())
         return 0;
 
-    HTMLFormControlElement* formElement = static_cast<HTMLFormControlElement*>(element);
+    HTMLFormControlElement* formElement = toHTMLFormControlElement(element);
     if (!formElement->isTextFormControl())
         return 0;
 
index d52aef7..b8ce632 100644 (file)
@@ -940,7 +940,7 @@ void InputHandler::updateFormState()
     if (!m_currentFocusElement || !m_currentFocusElement->isFormControlElement())
         return;
 
-    HTMLFormElement* formElement = static_cast<HTMLFormControlElement*>(m_currentFocusElement.get())->form();
+    HTMLFormElement* formElement = toHTMLFormControlElement(m_currentFocusElement.get())->form();
     if (!formElement)
         return;
 
@@ -1074,7 +1074,7 @@ void InputHandler::submitForm()
     if (!m_hasSubmitButton)
         return;
 
-    HTMLFormElement* formElement = static_cast<HTMLFormControlElement*>(m_currentFocusElement.get())->form();
+    HTMLFormElement* formElement = toHTMLFormControlElement(m_currentFocusElement.get())->form();
     if (!formElement)
         return;
 
index 3edbae4..0a4d26d 100644 (file)
@@ -1,3 +1,17 @@
+2013-12-30  Gyuyoung Kim  <gyuyoung.kim@samsung.com>
+
+        Cleanup static_cast<HTMLFormElement*> by using toHTMLFormElement()
+        https://bugs.webkit.org/show_bug.cgi?id=126309
+
+        Reviewed by Andreas Kling.
+
+        To detect bad type casts, it would be good to use toHTMLFormElement() instead of
+        using manual type cast. Additionally FORM_ASSOCIATED_ELEMENT_TYPE_CASTS is introduced newly
+        to do it.
+
+        * WebFrame.cpp:
+        (WebFrame::elementWithName):
+
 2013-12-17  Alex Christensen  <achristensen@webkit.org>
 
         [WinCairo] Compile fixes for GStreamer on Windows.
index 49d66cc..36b2b89 100644 (file)
@@ -1150,7 +1150,7 @@ HRESULT WebFrame::elementWithName(BSTR name, IDOMElement* form, IDOMElement** el
         for (unsigned int i = 0; i < elements.size(); i++) {
             if (!elements[i]->isFormControlElement())
                 continue;
-            HTMLFormControlElement* elt = static_cast<HTMLFormControlElement*>(elements[i]);
+            HTMLFormControlElement* elt = toHTMLFormControlElement(elements[i]);
             // Skip option elements, other duds
             if (elt->name() == targetName) {
                 *element = DOMElement::createInstance(elt);