Share more code between updateWidget implementations in HTMLEmbedElement and HTMLObje...
authoreric@webkit.org <eric@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 25 Jan 2012 23:29:53 +0000 (23:29 +0000)
committereric@webkit.org <eric@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 25 Jan 2012 23:29:53 +0000 (23:29 +0000)
https://bugs.webkit.org/show_bug.cgi?id=74340

Reviewed by Adam Barth.

I'm preparing to unify these two methods, and starting by sharing more code between them.

* html/HTMLEmbedElement.cpp:
(WebCore::HTMLEmbedElement::updateWidget):
* html/HTMLObjectElement.cpp:
(WebCore::HTMLObjectElement::updateWidget):
* html/HTMLPlugInElement.cpp:
(WebCore::HTMLPlugInElement::guardedDispatchBeforeLoadEvent):
* html/HTMLPlugInElement.h:

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

Source/WebCore/ChangeLog
Source/WebCore/html/HTMLEmbedElement.cpp
Source/WebCore/html/HTMLObjectElement.cpp
Source/WebCore/html/HTMLPlugInElement.cpp
Source/WebCore/html/HTMLPlugInElement.h

index 9f55caf..d5e5e0c 100644 (file)
@@ -1,3 +1,20 @@
+2012-01-25  Eric Seidel  <eric@webkit.org>
+
+        Share more code between updateWidget implementations in HTMLEmbedElement and HTMLObjectElement
+        https://bugs.webkit.org/show_bug.cgi?id=74340
+
+        Reviewed by Adam Barth.
+
+        I'm preparing to unify these two methods, and starting by sharing more code between them.
+
+        * html/HTMLEmbedElement.cpp:
+        (WebCore::HTMLEmbedElement::updateWidget):
+        * html/HTMLObjectElement.cpp:
+        (WebCore::HTMLObjectElement::updateWidget):
+        * html/HTMLPlugInElement.cpp:
+        (WebCore::HTMLPlugInElement::guardedDispatchBeforeLoadEvent):
+        * html/HTMLPlugInElement.h:
+
 2012-01-25  Eric Uhrhane  <ericu@chromium.org>
 
         Add full support for filesystem URLs.
index e8991a1..6b95ab6 100644 (file)
@@ -154,11 +154,7 @@ void HTMLEmbedElement::updateWidget(PluginCreationOption pluginCreationOption)
     Vector<String> paramValues;
     parametersForPlugin(paramNames, paramValues);
 
-    ASSERT(!m_inBeforeLoadEventHandler);
-    m_inBeforeLoadEventHandler = true;
-    bool beforeLoadAllowedLoad = dispatchBeforeLoadEvent(m_url);
-    m_inBeforeLoadEventHandler = false;
-
+    bool beforeLoadAllowedLoad = guardedDispatchBeforeLoadEvent(m_url);
     if (!beforeLoadAllowedLoad) {
         if (document()->isPluginDocument()) {
             // Plugins inside plugin documents load differently than other plugins. By the time
index 336ca67..3344761 100644 (file)
@@ -289,11 +289,7 @@ void HTMLObjectElement::updateWidget(PluginCreationOption pluginCreationOption)
     if (pluginCreationOption == CreateOnlyNonNetscapePlugins && wouldLoadAsNetscapePlugin(url, serviceType))
         return;
 
-    ASSERT(!m_inBeforeLoadEventHandler);
-    m_inBeforeLoadEventHandler = true;
-    bool beforeLoadAllowedLoad = dispatchBeforeLoadEvent(url);
-    m_inBeforeLoadEventHandler = false;
-
+    bool beforeLoadAllowedLoad = guardedDispatchBeforeLoadEvent(url);
     // beforeload events can modify the DOM, potentially causing
     // RenderWidget::destroy() to be called.  Ensure we haven't been
     // destroyed before continuing.
index cc6f3de..6229d2e 100644 (file)
@@ -110,6 +110,17 @@ PassScriptInstance HTMLPlugInElement::getInstance()
     return m_instance;
 }
 
+bool HTMLPlugInElement::guardedDispatchBeforeLoadEvent(const String& sourceURL)
+{
+    ASSERT(!m_inBeforeLoadEventHandler);
+    m_inBeforeLoadEventHandler = true;
+    // static_cast is used to avoid a compile error since dispatchBeforeLoadEvent
+    // is intentionally undefined on this class.
+    bool beforeLoadAllowedLoad = static_cast<HTMLFrameOwnerElement*>(this)->dispatchBeforeLoadEvent(sourceURL);
+    m_inBeforeLoadEventHandler = false;
+    return beforeLoadAllowedLoad;
+}
+
 Widget* HTMLPlugInElement::pluginWidget()
 {
     if (m_inBeforeLoadEventHandler) {
index 7dadfda..a10af61 100644 (file)
@@ -62,8 +62,12 @@ protected:
     virtual void parseMappedAttribute(Attribute*);
 
     bool m_inBeforeLoadEventHandler;
+    // Subclasses should use guardedDispatchBeforeLoadEvent instead of calling dispatchBeforeLoadEvent directly.
+    bool guardedDispatchBeforeLoadEvent(const String& sourceURL);
 
 private:
+    bool dispatchBeforeLoadEvent(const String& sourceURL); // Not implemented, generates a compile error if subclasses call this by mistake.
+
     virtual void defaultEventHandler(Event*);
 
     virtual RenderWidget* renderWidgetForJSBindings() = 0;