2011-06-22 Dimitri Glazkov <dglazkov@chromium.org>
authordglazkov@chromium.org <dglazkov@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 23 Jun 2011 03:55:53 +0000 (03:55 +0000)
committerdglazkov@chromium.org <dglazkov@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 23 Jun 2011 03:55:53 +0000 (03:55 +0000)
        Reviewed by Kent Tamura.

        Convert FileIconLoaderClient to "smart client" pattern, just like FileChooserClient.
        https://bugs.webkit.org/show_bug.cgi?id=63224

        Refactoring, covered by existing tests.

        * platform/FileIconLoader.cpp:
        (WebCore::FileIconLoaderClient::~FileIconLoaderClient): Changed to discard loader.
        (WebCore::FileIconLoaderClient::newFileIconLoader): Added.
        (WebCore::FileIconLoaderClient::discardLoader): Added.
        * platform/FileIconLoader.h: Updated defs.
        * rendering/RenderFileUploadControl.cpp:
        (WebCore::RenderFileUploadControl::RenderFileUploadControl): Removed initialization of icon loader.
        (WebCore::RenderFileUploadControl::~RenderFileUploadControl): Remove discarding of loader.
        (WebCore::RenderFileUploadControl::requestIcon): Changed to use newFileIconLoader.
        * rendering/RenderFileUploadControl.h: Updated defs.

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

Source/WebCore/ChangeLog
Source/WebCore/platform/FileIconLoader.cpp
Source/WebCore/platform/FileIconLoader.h
Source/WebCore/rendering/RenderFileUploadControl.cpp
Source/WebCore/rendering/RenderFileUploadControl.h

index 92050ce..2185c83 100644 (file)
@@ -1,3 +1,23 @@
+2011-06-22  Dimitri Glazkov  <dglazkov@chromium.org>
+
+        Reviewed by Kent Tamura.
+
+        Convert FileIconLoaderClient to "smart client" pattern, just like FileChooserClient.
+        https://bugs.webkit.org/show_bug.cgi?id=63224
+
+        Refactoring, covered by existing tests.
+
+        * platform/FileIconLoader.cpp:
+        (WebCore::FileIconLoaderClient::~FileIconLoaderClient): Changed to discard loader.
+        (WebCore::FileIconLoaderClient::newFileIconLoader): Added.
+        (WebCore::FileIconLoaderClient::discardLoader): Added.
+        * platform/FileIconLoader.h: Updated defs.
+        * rendering/RenderFileUploadControl.cpp:
+        (WebCore::RenderFileUploadControl::RenderFileUploadControl): Removed initialization of icon loader.
+        (WebCore::RenderFileUploadControl::~RenderFileUploadControl): Remove discarding of loader.
+        (WebCore::RenderFileUploadControl::requestIcon): Changed to use newFileIconLoader.
+        * rendering/RenderFileUploadControl.h: Updated defs.
+
 2011-06-22  Yael Aharon  <yael.aharon@nokia.com>
 
         Another unreviewed build fix after r89472.
index 34de8a5..16b5792 100644 (file)
@@ -36,6 +36,21 @@ namespace WebCore {
 
 FileIconLoaderClient::~FileIconLoaderClient()
 {
+    discardLoader();
+}
+
+FileIconLoader* FileIconLoaderClient::newFileIconLoader()
+{
+    discardLoader();
+
+    m_loader = FileIconLoader::create(this);
+    return m_loader.get();
+}
+
+void FileIconLoaderClient::discardLoader()
+{
+    if (m_loader)
+        m_loader->disconnectClient();
 }
 
 PassRefPtr<FileIconLoader> FileIconLoader::create(FileIconLoaderClient* client)
index dc394d1..da8ca2a 100644 (file)
 #ifndef FileIconLoader_h
 #define FileIconLoader_h
 
-#include <wtf/PassRefPtr.h>
+#include <wtf/RefPtr.h>
 #include <wtf/RefCounted.h>
 
 namespace WebCore {
 
+class FileIconLoader;
 class Icon;
 
 class FileIconLoaderClient {
 public:
     virtual void updateRendering(PassRefPtr<Icon>) = 0;
     virtual ~FileIconLoaderClient();
+
+protected:
+    FileIconLoader* newFileIconLoader();
+
+private:
+    void discardLoader();
+
+    RefPtr<FileIconLoader> m_loader;
 };
 
 class FileIconLoader : public RefCounted<FileIconLoader> {
index b22ab75..974a622 100644 (file)
@@ -56,7 +56,6 @@ const int buttonShadowHeight = 2;
 
 RenderFileUploadControl::RenderFileUploadControl(HTMLInputElement* input)
     : RenderBlock(input)
-    , m_iconLoader(FileIconLoader::create(this))
 {
     ASSERT(input->files());
     requestIcon(input->files()->filenames());
@@ -64,16 +63,15 @@ RenderFileUploadControl::RenderFileUploadControl(HTMLInputElement* input)
 
 RenderFileUploadControl::~RenderFileUploadControl()
 {
-    m_iconLoader->disconnectClient();
 }
 
-void RenderFileUploadControl::requestIcon(const Vector<String>& filenames) const
+void RenderFileUploadControl::requestIcon(const Vector<String>& filenames)
 {
     if (!filenames.size())
         return;
 
     if (Chrome* chrome = this->chrome())
-        chrome->loadIconForFiles(filenames, m_iconLoader.get());
+        chrome->loadIconForFiles(filenames, newFileIconLoader());
 }
 
 void RenderFileUploadControl::filesChosen(const Vector<String>& filenames)
index 9165910..25f9ac7 100644 (file)
@@ -73,9 +73,8 @@ private:
     virtual VisiblePosition positionForPoint(const IntPoint&);
 
     HTMLInputElement* uploadButton() const;
-    void requestIcon(const Vector<String>&) const;
+    void requestIcon(const Vector<String>&);
 
-    RefPtr<FileIconLoader> m_iconLoader;
     RefPtr<Icon> m_icon;
 };