Title: [168680] trunk/Source
Revision
168680
Author
[email protected]
Date
2014-05-13 07:44:50 -0700 (Tue, 13 May 2014)

Log Message

Make a few icon database improvements
https://bugs.webkit.org/show_bug.cgi?id=132812

Reviewed by Brady Eidson.

Source/WebCore:
* WebCore.exp.in: Export more IconDatabase functions, since they are now called
by WebKit2 through pointers to a class marked final.

* loader/icon/IconDatabase.cpp: Removed unneeded includes. Use override for
virtual functions.

* loader/icon/IconDatabase.h: Removed unneeded includes. Marked the class final.
Use override for virtual functions. Use a public constructor instead of a create
function.

* loader/icon/IconDatabaseBase.h: Removed unneeded includes.

Source/WebKit2:
* UIProcess/API/C/WKIconDatabase.cpp:
(WKIconDatabaseCopyIconDataForPageURL): Moved the actual implementation of this
out of the bindings into the WebIconDatabase class.

* UIProcess/API/C/WKIconDatabase.h: Fixed argument names that were inconsistent.

* UIProcess/WebIconDatabase.cpp: Removed unneeded includes.
(WebKit::WebIconDatabase::create): Pass a reference instead of a pointer.
(WebKit::WebIconDatabase::WebIconDatabase): Take a reference instead of a pointer.
(WebKit::WebIconDatabase::invalidate): Use nullptr.
(WebKit::WebIconDatabase::setDatabasePath): Use make_unique.
(WebKit::WebIconDatabase::setIconDataForIconURL): Removed unneeded local variable.
(WebKit::WebIconDatabase::imageForPageURL): Use nullptr.
(WebKit::WebIconDatabase::nativeImageForPageURL): Ditto.
(WebKit::WebIconDatabase::didFinishURLImport): Use a modern for loop.
(WebKit::WebIconDatabase::iconDataForPageURL): Added. Moved this here from
WKIconDatabase.cpp, but also changed to use createWithoutCopying to avoid making
another copy of the data for each icon.

* UIProcess/WebIconDatabase.h: Removed unneeded includes. Derive from
IconDatabaseClient privately. Use nullptr. Added iconDataForPageURL member
function. Use a reference for the constructor argument. Use override for
virtual functions. Use unique_ptr instead of OwnPtr.

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (168679 => 168680)


--- trunk/Source/WebCore/ChangeLog	2014-05-13 13:56:15 UTC (rev 168679)
+++ trunk/Source/WebCore/ChangeLog	2014-05-13 14:44:50 UTC (rev 168680)
@@ -1,3 +1,22 @@
+2014-05-12  Darin Adler  <[email protected]>
+
+        Make a few icon database improvements
+        https://bugs.webkit.org/show_bug.cgi?id=132812
+
+        Reviewed by Brady Eidson.
+
+        * WebCore.exp.in: Export more IconDatabase functions, since they are now called
+        by WebKit2 through pointers to a class marked final.
+
+        * loader/icon/IconDatabase.cpp: Removed unneeded includes. Use override for
+        virtual functions.
+
+        * loader/icon/IconDatabase.h: Removed unneeded includes. Marked the class final.
+        Use override for virtual functions. Use a public constructor instead of a create
+        function.
+
+        * loader/icon/IconDatabaseBase.h: Removed unneeded includes.
+
 2014-05-13  Kiran  <[email protected]>
 
         [MediaStream] MediaStream.addTrack Should not check for active state.

Modified: trunk/Source/WebCore/WebCore.exp.in (168679 => 168680)


--- trunk/Source/WebCore/WebCore.exp.in	2014-05-13 13:56:15 UTC (rev 168679)
+++ trunk/Source/WebCore/WebCore.exp.in	2014-05-13 14:44:50 UTC (rev 168680)
@@ -2991,16 +2991,23 @@
 __ZN7WebCore12IconDatabase20delayDatabaseCleanupEv
 __ZN7WebCore12IconDatabase20retainIconForPageURLERKN3WTF6StringE
 __ZN7WebCore12IconDatabase20retainedPageURLCountEv
+__ZN7WebCore12IconDatabase20setIconURLForPageURLERKN3WTF6StringES4_
 __ZN7WebCore12IconDatabase21releaseIconForPageURLERKN3WTF6StringE
+__ZN7WebCore12IconDatabase21setIconDataForIconURLEN3WTF10PassRefPtrINS_12SharedBufferEEERKNS1_6StringE
 __ZN7WebCore12IconDatabase23defaultDatabaseFilenameEv
 __ZN7WebCore12IconDatabase23iconRecordCountWithDataEv
 __ZN7WebCore12IconDatabase25setPrivateBrowsingEnabledEb
+__ZN7WebCore12IconDatabase25synchronousIconForPageURLERKN3WTF6StringERKNS_7IntSizeE
 __ZN7WebCore12IconDatabase27checkIntegrityBeforeOpeningEv
+__ZN7WebCore12IconDatabase28synchronousIconURLForPageURLERKN3WTF6StringE
+__ZN7WebCore12IconDatabase33synchronousLoadDecisionForIconURLERKN3WTF6StringEPNS_14DocumentLoaderE
+__ZN7WebCore12IconDatabase4openERKN3WTF6StringES4_
 __ZN7WebCore12IconDatabase5closeEv
 __ZN7WebCore12IconDatabase9setClientEPNS_18IconDatabaseClientE
 __ZN7WebCore12IconDatabaseC1Ev
 __ZNK7WebCore12IconDatabase12databasePathEv
 __ZNK7WebCore12IconDatabase24shouldStopThreadActivityEv
+__ZNK7WebCore12IconDatabase6isOpenEv
 __ZNK7WebCore12IconDatabase9isEnabledEv
 #endif
 

Modified: trunk/Source/WebCore/loader/icon/IconDatabase.cpp (168679 => 168680)


--- trunk/Source/WebCore/loader/icon/IconDatabase.cpp	2014-05-13 13:56:15 UTC (rev 168679)
+++ trunk/Source/WebCore/loader/icon/IconDatabase.cpp	2014-05-13 14:44:50 UTC (rev 168680)
@@ -34,16 +34,13 @@
 #include "IconDatabaseClient.h"
 #include "IconRecord.h"
 #include "Image.h"
-#include "IntSize.h"
 #include "Logging.h"
 #include "SQLiteStatement.h"
 #include "SQLiteTransaction.h"
 #include "SuddenTermination.h"
 #include <wtf/AutodrainedPool.h>
-#include <wtf/CurrentTime.h>
 #include <wtf/MainThread.h>
 #include <wtf/StdLibExtras.h>
-#include <wtf/text/CString.h>
 
 // For methods that are meant to support API from the main thread - should not be called internally
 #define ASSERT_NOT_SYNC_THREAD() ASSERT(!m_syncThreadRunning || !IS_ICON_SYNC_THREAD())
@@ -90,19 +87,19 @@
 }
 #endif
 
-class DefaultIconDatabaseClient : public IconDatabaseClient {
+class DefaultIconDatabaseClient final : public IconDatabaseClient {
     WTF_MAKE_FAST_ALLOCATED;
 public:
-    virtual void didImportIconURLForPageURL(const String&) { } 
-    virtual void didImportIconDataForPageURL(const String&) { }
-    virtual void didChangeIconForPageURL(const String&) { }
-    virtual void didRemoveAllIcons() { }
-    virtual void didFinishURLImport() { }
+    virtual void didImportIconURLForPageURL(const String&) override { }
+    virtual void didImportIconDataForPageURL(const String&) override { }
+    virtual void didChangeIconForPageURL(const String&) override { }
+    virtual void didRemoveAllIcons() override { }
+    virtual void didFinishURLImport() override { }
 };
 
 static IconDatabaseClient* defaultClient() 
 {
-    static IconDatabaseClient* defaultClient = new DefaultIconDatabaseClient();
+    static IconDatabaseClient* defaultClient = new DefaultIconDatabaseClient;
     return defaultClient;
 }
 

Modified: trunk/Source/WebCore/loader/icon/IconDatabase.h (168679 => 168680)


--- trunk/Source/WebCore/loader/icon/IconDatabase.h	2014-05-13 13:56:15 UTC (rev 168679)
+++ trunk/Source/WebCore/loader/icon/IconDatabase.h	2014-05-13 14:44:50 UTC (rev 168680)
@@ -28,99 +28,84 @@
 #define IconDatabase_h
 
 #include "IconDatabaseBase.h"
+
+#if ENABLE(ICONDATABASE)
+#include "SQLiteDatabase.h"
 #include "Timer.h"
 #include <wtf/HashCountedSet.h>
 #include <wtf/HashMap.h>
 #include <wtf/HashSet.h>
-#include <wtf/Noncopyable.h>
-#include <wtf/OwnPtr.h>
-#include <wtf/PassOwnPtr.h>
-#include <wtf/text/StringHash.h>
-#include <wtf/text/WTFString.h>
+#endif
 
-#if ENABLE(ICONDATABASE)
-#include "SQLiteDatabase.h"
-#include <wtf/Threading.h>
-#endif // ENABLE(ICONDATABASE)
-
 namespace WebCore { 
 
-class DocumentLoader;
-class Image;
-class IntSize;
-class IconDatabaseClient;
-class IconRecord;
-class IconSnapshot;
-class URL;
-class PageURLRecord;
-class PageURLSnapshot;
-class SharedBuffer;
-class SuddenTerminationDisabler;
-
-#if ENABLE(ICONDATABASE)
-class SQLTransaction;
-#endif
-
 #if !ENABLE(ICONDATABASE)
-// For builds with IconDatabase disabled, they'll just use a default derivation of IconDatabaseBase. Which does nothing.
-class IconDatabase : public IconDatabaseBase {
+
+// Dummy version of IconDatabase that does nothing.
+class IconDatabase final : public IconDatabaseBase {
+    WTF_MAKE_FAST_ALLOCATED;
 public:
-    static PassOwnPtr<IconDatabase> create() { return adoptPtr(new IconDatabase); }
     static void delayDatabaseCleanup() { }
     static void allowDatabaseCleanup() { }
     static void checkIntegrityBeforeOpening() { }
     static String defaultDatabaseFilename() { return "WebpageIcons.db"; }
 };
-#else 
 
-class IconDatabase : public IconDatabaseBase {
+#else
+
+class IconRecord;
+class IconSnapshot;
+class PageURLRecord;
+class PageURLSnapshot;
+class SuddenTerminationDisabler;
+
+class IconDatabase final : public IconDatabaseBase {
     WTF_MAKE_FAST_ALLOCATED;
     
 // *** Main Thread Only ***
 public:
-    static PassOwnPtr<IconDatabase> create() { return adoptPtr(new IconDatabase); }
+    IconDatabase();
     ~IconDatabase();
 
-    virtual void setClient(IconDatabaseClient*);
+    virtual void setClient(IconDatabaseClient*) override;
 
-    virtual bool open(const String& directory, const String& filename);
-    virtual void close();
+    virtual bool open(const String& directory, const String& filename) override;
+    virtual void close() override;
             
-    virtual void removeAllIcons();
+    virtual void removeAllIcons() override;
 
     void readIconForPageURLFromDisk(const String&);
 
-    virtual Image* defaultIcon(const IntSize&);
+    virtual Image* defaultIcon(const IntSize&) override;
 
-    virtual void retainIconForPageURL(const String&);
-    virtual void releaseIconForPageURL(const String&);
-    virtual void setIconDataForIconURL(PassRefPtr<SharedBuffer> data, const String&);
-    virtual void setIconURLForPageURL(const String& iconURL, const String& pageURL);
+    virtual void retainIconForPageURL(const String&) override;
+    virtual void releaseIconForPageURL(const String&) override;
+    virtual void setIconDataForIconURL(PassRefPtr<SharedBuffer> data, const String&) override;
+    virtual void setIconURLForPageURL(const String& iconURL, const String& pageURL) override;
 
-    virtual Image* synchronousIconForPageURL(const String&, const IntSize&);
-    virtual PassNativeImagePtr synchronousNativeIconForPageURL(const String& pageURLOriginal, const IntSize&);
-    virtual String synchronousIconURLForPageURL(const String&);
-    virtual bool synchronousIconDataKnownForIconURL(const String&);
-    virtual IconLoadDecision synchronousLoadDecisionForIconURL(const String&, DocumentLoader*);    
-    
-    virtual void setEnabled(bool);
-    virtual bool isEnabled() const;
-    
-    virtual void setPrivateBrowsingEnabled(bool flag);
+    virtual Image* synchronousIconForPageURL(const String&, const IntSize&) override;
+    virtual PassNativeImagePtr synchronousNativeIconForPageURL(const String& pageURLOriginal, const IntSize&) override;
+    virtual String synchronousIconURLForPageURL(const String&) override;
+    virtual bool synchronousIconDataKnownForIconURL(const String&) override;
+    virtual IconLoadDecision synchronousLoadDecisionForIconURL(const String&, DocumentLoader*) override;
+
+    virtual void setEnabled(bool) override;
+    virtual bool isEnabled() const override;
+
+    virtual void setPrivateBrowsingEnabled(bool flag) override;
     bool isPrivateBrowsingEnabled() const;
-    
+
     static void delayDatabaseCleanup();
     static void allowDatabaseCleanup();
     static void checkIntegrityBeforeOpening();
-        
+
     // Support for WebCoreStatistics in WebKit
-    virtual size_t pageURLMappingCount();
-    virtual size_t retainedPageURLCount();
-    virtual size_t iconRecordCount();
-    virtual size_t iconRecordCountWithData();
+    virtual size_t pageURLMappingCount() override;
+    virtual size_t retainedPageURLCount() override;
+    virtual size_t iconRecordCount() override;
+    virtual size_t iconRecordCountWithData() override;
 
 private:
-    IconDatabase();
     friend IconDatabaseBase& iconDatabase();
 
     static void notifyPendingLoadDecisionsOnMainThread(void*);

Modified: trunk/Source/WebCore/loader/icon/IconDatabaseBase.h (168679 => 168680)


--- trunk/Source/WebCore/loader/icon/IconDatabaseBase.h	2014-05-13 13:56:15 UTC (rev 168679)
+++ trunk/Source/WebCore/loader/icon/IconDatabaseBase.h	2014-05-13 14:44:50 UTC (rev 168680)
@@ -26,12 +26,11 @@
 #ifndef IconDatabaseBase_h
 #define IconDatabaseBase_h
 
-#include "ImageSource.h"
-#include "SharedBuffer.h"
-
+#include "NativeImagePtr.h"
 #include <wtf/Forward.h>
 #include <wtf/Noncopyable.h>
 #include <wtf/PassRefPtr.h>
+#include <wtf/RefCounted.h>
 
 namespace WebCore {
 
@@ -39,6 +38,7 @@
 class IconDatabaseClient;
 class Image;
 class IntSize;
+class SharedBuffer;
 
 enum IconLoadDecision {
     IconLoadYes,

Modified: trunk/Source/WebKit2/ChangeLog (168679 => 168680)


--- trunk/Source/WebKit2/ChangeLog	2014-05-13 13:56:15 UTC (rev 168679)
+++ trunk/Source/WebKit2/ChangeLog	2014-05-13 14:44:50 UTC (rev 168680)
@@ -1,3 +1,34 @@
+2014-05-12  Darin Adler  <[email protected]>
+
+        Make a few icon database improvements
+        https://bugs.webkit.org/show_bug.cgi?id=132812
+
+        Reviewed by Brady Eidson.
+
+        * UIProcess/API/C/WKIconDatabase.cpp:
+        (WKIconDatabaseCopyIconDataForPageURL): Moved the actual implementation of this
+        out of the bindings into the WebIconDatabase class.
+
+        * UIProcess/API/C/WKIconDatabase.h: Fixed argument names that were inconsistent.
+
+        * UIProcess/WebIconDatabase.cpp: Removed unneeded includes.
+        (WebKit::WebIconDatabase::create): Pass a reference instead of a pointer.
+        (WebKit::WebIconDatabase::WebIconDatabase): Take a reference instead of a pointer.
+        (WebKit::WebIconDatabase::invalidate): Use nullptr.
+        (WebKit::WebIconDatabase::setDatabasePath): Use make_unique.
+        (WebKit::WebIconDatabase::setIconDataForIconURL): Removed unneeded local variable.
+        (WebKit::WebIconDatabase::imageForPageURL): Use nullptr.
+        (WebKit::WebIconDatabase::nativeImageForPageURL): Ditto.
+        (WebKit::WebIconDatabase::didFinishURLImport): Use a modern for loop.
+        (WebKit::WebIconDatabase::iconDataForPageURL): Added. Moved this here from
+        WKIconDatabase.cpp, but also changed to use createWithoutCopying to avoid making
+        another copy of the data for each icon.
+
+        * UIProcess/WebIconDatabase.h: Removed unneeded includes. Derive from
+        IconDatabaseClient privately. Use nullptr. Added iconDataForPageURL member
+        function. Use a reference for the constructor argument. Use override for
+        virtual functions. Use unique_ptr instead of OwnPtr.
+
 2014-05-12  Mark Lam  <[email protected]>
 
         WebKit2 on iOS needs to capture the main thread's floating point environment.

Modified: trunk/Source/WebKit2/UIProcess/API/C/WKIconDatabase.cpp (168679 => 168680)


--- trunk/Source/WebKit2/UIProcess/API/C/WKIconDatabase.cpp	2014-05-13 13:56:15 UTC (rev 168679)
+++ trunk/Source/WebKit2/UIProcess/API/C/WKIconDatabase.cpp	2014-05-13 14:44:50 UTC (rev 168680)
@@ -29,9 +29,6 @@
 #include "APIData.h"
 #include "WKAPICast.h"
 #include "WebIconDatabase.h"
-#include <WebCore/Image.h>
-#include <WebCore/SharedBuffer.h>
-#include <WebKit/WKData.h>
 
 using namespace WebKit;
 
@@ -74,15 +71,7 @@
 
 WKDataRef WKIconDatabaseCopyIconDataForPageURL(WKIconDatabaseRef iconDatabaseRef, WKURLRef pageURL)
 {
-    WebCore::Image* image = toImpl(iconDatabaseRef)->imageForPageURL(toWTFString(pageURL));
-    if (!image)
-        return nullptr;
-
-    WebCore::SharedBuffer* iconData = image->data();
-    if (!iconData)
-        return nullptr;
-
-    return WKDataCreate(reinterpret_cast<const unsigned char*>(iconData->data()), iconData->size());
+    return toAPI(toImpl(iconDatabaseRef)->iconDataForPageURL(toWTFString(pageURL)).leakRef());
 }
 
 void WKIconDatabaseEnableDatabaseCleanup(WKIconDatabaseRef iconDatabaseRef)

Modified: trunk/Source/WebKit2/UIProcess/API/C/WKIconDatabase.h (168679 => 168680)


--- trunk/Source/WebKit2/UIProcess/API/C/WKIconDatabase.h	2014-05-13 13:56:15 UTC (rev 168679)
+++ trunk/Source/WebKit2/UIProcess/API/C/WKIconDatabase.h	2014-05-13 14:44:50 UTC (rev 168680)
@@ -81,9 +81,9 @@
 WK_EXPORT void WKIconDatabaseRetainIconForURL(WKIconDatabaseRef iconDatabase, WKURLRef pageURL);
 WK_EXPORT void WKIconDatabaseReleaseIconForURL(WKIconDatabaseRef iconDatabase, WKURLRef pageURL);
 WK_EXPORT void WKIconDatabaseSetIconDataForIconURL(WKIconDatabaseRef iconDatabase, WKDataRef iconData, WKURLRef iconURL);
-WK_EXPORT void WKIconDatabaseSetIconURLForPageURL(WKIconDatabaseRef iconDatabaseRef, WKURLRef iconURLRef, WKURLRef pageURLRef);
-WK_EXPORT WKURLRef WKIconDatabaseCopyIconURLForPageURL(WKIconDatabaseRef iconDatabaseRef, WKURLRef pageURLRef);
-WK_EXPORT WKDataRef WKIconDatabaseCopyIconDataForPageURL(WKIconDatabaseRef iconDatabaseRef, WKURLRef pageURL);
+WK_EXPORT void WKIconDatabaseSetIconURLForPageURL(WKIconDatabaseRef iconDatabase, WKURLRef iconURL, WKURLRef pageURL);
+WK_EXPORT WKURLRef WKIconDatabaseCopyIconURLForPageURL(WKIconDatabaseRef iconDatabase, WKURLRef pageURL);
+WK_EXPORT WKDataRef WKIconDatabaseCopyIconDataForPageURL(WKIconDatabaseRef iconDatabase, WKURLRef pageURL);
 
 WK_EXPORT void WKIconDatabaseEnableDatabaseCleanup(WKIconDatabaseRef iconDatabase);
 

Modified: trunk/Source/WebKit2/UIProcess/WebIconDatabase.cpp (168679 => 168680)


--- trunk/Source/WebKit2/UIProcess/WebIconDatabase.cpp	2014-05-13 13:56:15 UTC (rev 168679)
+++ trunk/Source/WebKit2/UIProcess/WebIconDatabase.cpp	2014-05-13 14:44:50 UTC (rev 168680)
@@ -26,17 +26,14 @@
 #include "config.h"
 #include "WebIconDatabase.h"
 
-#include "DataReference.h"
 #include "Logging.h"
 #include "WebContext.h"
 #include "WebIconDatabaseMessages.h"
 #include "WebIconDatabaseProxyMessages.h"
-#include "WebPreferences.h"
 #include <WebCore/FileSystem.h>
 #include <WebCore/IconDatabase.h>
-#include <WebCore/IconDatabaseBase.h>
-#include <wtf/text/CString.h>
-#include <wtf/text/WTFString.h>
+#include <WebCore/Image.h>
+#include <WebCore/SharedBuffer.h>
 
 using namespace WebCore;
 
@@ -44,15 +41,15 @@
 
 PassRefPtr<WebIconDatabase> WebIconDatabase::create(WebContext* context)
 {
-    return adoptRef(new WebIconDatabase(context));
+    return adoptRef(new WebIconDatabase(*context));
 }
 
 WebIconDatabase::~WebIconDatabase()
 {
 }
 
-WebIconDatabase::WebIconDatabase(WebContext* context)
-    : m_webContext(context)
+WebIconDatabase::WebIconDatabase(WebContext& context)
+    : m_webContext(&context)
     , m_urlImportCompleted(false)
     , m_databaseCleanupDisabled(false)
 {
@@ -61,7 +58,7 @@
 
 void WebIconDatabase::invalidate()
 {
-    setGlobalIconDatabase(0);
+    setGlobalIconDatabase(nullptr);
 }
 
 void WebIconDatabase::setDatabasePath(const String& path)
@@ -71,7 +68,7 @@
         return;
     }
 
-    m_iconDatabaseImpl =  IconDatabase::create();
+    m_iconDatabaseImpl = std::make_unique<IconDatabase>();
     m_iconDatabaseImpl->setClient(this);
     IconDatabase::delayDatabaseCleanup();
     m_databaseCleanupDisabled = true;
@@ -83,8 +80,8 @@
 
     if (!m_iconDatabaseImpl->open(directoryName(path), pathGetFileName(path))) {
         LOG_ERROR("Unable to open WebKit2 icon database on disk");
-        m_iconDatabaseImpl.clear();
-        setGlobalIconDatabase(0);
+        m_iconDatabaseImpl = nullptr;
+        setGlobalIconDatabase(nullptr);
         IconDatabase::allowDatabaseCleanup();
         m_databaseCleanupDisabled = false;
     }
@@ -103,7 +100,7 @@
         ASSERT_NOT_REACHED();
         return;
     }
-    
+
     IconDatabase::allowDatabaseCleanup();
     m_databaseCleanupDisabled = false;
 }
@@ -132,9 +129,7 @@
     LOG(IconDatabase, "WK2 UIProcess setting icon data (%i bytes) for page URL %s", (int)iconData.size(), iconURL.ascii().data());
     if (!m_iconDatabaseImpl)
         return;
-
-    RefPtr<SharedBuffer> buffer = SharedBuffer::create(iconData.data(), iconData.size());
-    m_iconDatabaseImpl->setIconDataForIconURL(buffer.release(), iconURL);
+    m_iconDatabaseImpl->setIconDataForIconURL(SharedBuffer::create(iconData.data(), iconData.size()), iconURL);
 }
 
 void WebIconDatabase::synchronousIconDataForPageURL(const String&, IPC::DataReference& iconData)
@@ -148,7 +143,6 @@
         iconURL = String();
         return;
     }
-
     iconURL = m_iconDatabaseImpl->synchronousIconURLForPageURL(pageURL);
 }
 
@@ -182,7 +176,7 @@
         ASSERT(!m_urlImportCompleted);
         
         m_pendingLoadDecisionURLMap.set(callbackID, iconURL);
-        return;    
+        return;
     }
 
     // FIXME (Multi-WebProcess): <rdar://problem/12240223> We need to know which connection to send this message to.
@@ -194,20 +188,20 @@
     notifyIconDataReadyForPageURL(pageURL);
 }
 
-Image* WebIconDatabase::imageForPageURL(const String& pageURL, const WebCore::IntSize& iconSize)
+Image* WebIconDatabase::imageForPageURL(const String& pageURL, const IntSize& iconSize)
 {
     if (!m_webContext || !m_iconDatabaseImpl || !m_iconDatabaseImpl->isOpen() || pageURL.isEmpty())
-        return 0;    
+        return nullptr;
 
     // The WebCore IconDatabase ignores the passed in size parameter.
     // If that changes we'll need to rethink how this API is exposed.
     return m_iconDatabaseImpl->synchronousIconForPageURL(pageURL, iconSize);
 }
 
-WebCore::NativeImagePtr WebIconDatabase::nativeImageForPageURL(const String& pageURL, const WebCore::IntSize& iconSize)
+NativeImagePtr WebIconDatabase::nativeImageForPageURL(const String& pageURL, const IntSize& iconSize)
 {
     if (!m_webContext || !m_iconDatabaseImpl || !m_iconDatabaseImpl->isOpen() || pageURL.isEmpty())
-        return 0;
+        return nullptr;
 
     return m_iconDatabaseImpl->synchronousNativeIconForPageURL(pageURL, iconSize);
 }
@@ -224,7 +218,7 @@
 
 void WebIconDatabase::removeAllIcons()
 {
-    m_iconDatabaseImpl->removeAllIcons();   
+    m_iconDatabaseImpl->removeAllIcons();
 }
 
 void WebIconDatabase::checkIntegrityBeforeOpening()
@@ -269,27 +263,24 @@
 {
     if (!m_webContext)
         return;
-    
+
     ASSERT(!m_urlImportCompleted);
 
     LOG(IconDatabase, "WK2 UIProcess URL import complete, notifying all %i pending page URL load decisions", m_pendingLoadDecisionURLMap.size());
-
-    HashMap<uint64_t, String>::iterator i = m_pendingLoadDecisionURLMap.begin();
-    HashMap<uint64_t, String>::iterator end = m_pendingLoadDecisionURLMap.end();
     
-    for (; i != end; ++i) {
-        LOG(IconDatabase, "WK2 UIProcess performing delayed callback on callback ID %i for page url %s", (int)i->key, i->value.ascii().data());
-        IconLoadDecision decision = m_iconDatabaseImpl->synchronousLoadDecisionForIconURL(i->value, 0);
+    for (auto& slot : m_pendingLoadDecisionURLMap) {
+        LOG(IconDatabase, "WK2 UIProcess performing delayed callback on callback ID %i for page url %s", (int)slot.key, slot.value.ascii().data());
+        IconLoadDecision decision = m_iconDatabaseImpl->synchronousLoadDecisionForIconURL(slot.value, nullptr);
 
-        // Decisions should never be unknown after the inital import is complete
+        // Decisions should never be unknown after the inital import is complete.
         ASSERT(decision != IconLoadUnknown);
 
         // FIXME (Multi-WebProcess): <rdar://problem/12240223> We need to know which connection to send this message to.
-        m_webContext->sendToAllProcesses(Messages::WebIconDatabaseProxy::ReceivedIconLoadDecision(static_cast<int>(decision), i->key));
+        m_webContext->sendToAllProcesses(Messages::WebIconDatabaseProxy::ReceivedIconLoadDecision(static_cast<int>(decision), slot.key));
     }
-    
+
     m_pendingLoadDecisionURLMap.clear();
-    
+
     m_urlImportCompleted = true;
 }
 
@@ -305,4 +296,23 @@
         m_iconDatabaseImpl->setPrivateBrowsingEnabled(privateBrowsingEnabled);
 }
 
+PassRefPtr<API::Data> WebIconDatabase::iconDataForPageURL(const String& pageURL)
+{
+    auto* image = imageForPageURL(pageURL);
+    if (!image)
+        return nullptr;
+
+    SharedBuffer* sharedBuffer = image->data();
+    if (!sharedBuffer)
+        return nullptr;
+
+    // Balanced by deref() below.
+    sharedBuffer->ref();
+    return API::Data::createWithoutCopying(reinterpret_cast<const unsigned char*>(sharedBuffer->data()), sharedBuffer->size(),
+        [](unsigned char*, const void* untypedSharedBuffer) {
+            // Balanced by ref() above.
+            static_cast<SharedBuffer*>(const_cast<void*>(untypedSharedBuffer))->deref();
+        }, sharedBuffer);
+}
+
 } // namespace WebKit

Modified: trunk/Source/WebKit2/UIProcess/WebIconDatabase.h (168679 => 168680)


--- trunk/Source/WebKit2/UIProcess/WebIconDatabase.h	2014-05-13 13:56:15 UTC (rev 168679)
+++ trunk/Source/WebKit2/UIProcess/WebIconDatabase.h	2014-05-13 14:44:50 UTC (rev 168680)
@@ -27,21 +27,14 @@
 #define WebIconDatabase_h
 
 #include "APIObject.h"
-
 #include "Connection.h"
 #include "WebIconDatabaseClient.h"
 #include <WebCore/IconDatabaseClient.h>
-#include <WebCore/ImageSource.h>
 #include <WebCore/IntSize.h>
-#include <wtf/Forward.h>
-#include <wtf/PassRefPtr.h>
-#include <wtf/RefPtr.h>
-#include <wtf/Vector.h>
-#include <wtf/text/StringHash.h>
+#include <WebCore/NativeImagePtr.h>
 
-namespace IPC {
-class ArgumentDecoder;
-class DataReference;
+namespace API {
+class Data;
 }
 
 namespace WebCore {
@@ -53,13 +46,13 @@
 
 class WebContext;
 
-class WebIconDatabase : public API::ObjectImpl<API::Object::Type::IconDatabase>, public WebCore::IconDatabaseClient, private IPC::MessageReceiver {
+class WebIconDatabase : public API::ObjectImpl<API::Object::Type::IconDatabase>, private WebCore::IconDatabaseClient, private IPC::MessageReceiver {
 public:
     static PassRefPtr<WebIconDatabase> create(WebContext*);
     virtual ~WebIconDatabase();
 
     void invalidate();
-    void clearContext() { m_webContext = 0; }
+    void clearContext() { m_webContext = nullptr; }
     void setDatabasePath(const String&);
     void enableDatabaseCleanup();
 
@@ -67,17 +60,19 @@
     void releaseIconForPageURL(const String&);
     void setIconURLForPageURL(const String&, const String&);
     void setIconDataForIconURL(const IPC::DataReference&, const String&);
-    
+
     void synchronousIconDataForPageURL(const String&, IPC::DataReference&);
     void synchronousIconURLForPageURL(const String&, String&);
     void synchronousIconDataKnownForIconURL(const String&, bool&) const;
     void synchronousLoadDecisionForIconURL(const String&, int&) const;
-    
+
     void getLoadDecisionForIconURL(const String&, uint64_t callbackID);
     void didReceiveIconForPageURL(const String&);
 
     WebCore::Image* imageForPageURL(const String&, const WebCore::IntSize& iconSize = WebCore::IntSize(32, 32));
     WebCore::NativeImagePtr nativeImageForPageURL(const String&, const WebCore::IntSize& iconSize = WebCore::IntSize(32, 32));
+    PassRefPtr<API::Data> iconDataForPageURL(const String& pageURL);
+
     bool isOpen();
     bool isUrlImportCompleted();
 
@@ -88,16 +83,16 @@
     void initializeIconDatabaseClient(const WKIconDatabaseClientBase*);
 
     void setPrivateBrowsingEnabled(bool);
-    
+
 private:
-    WebIconDatabase(WebContext*);
+    explicit WebIconDatabase(WebContext&);
 
     // WebCore::IconDatabaseClient
-    virtual void didImportIconURLForPageURL(const String&);
-    virtual void didImportIconDataForPageURL(const String&);
-    virtual void didChangeIconForPageURL(const String&);
-    virtual void didRemoveAllIcons();
-    virtual void didFinishURLImport();
+    virtual void didImportIconURLForPageURL(const String&) override;
+    virtual void didImportIconDataForPageURL(const String&) override;
+    virtual void didChangeIconForPageURL(const String&) override;
+    virtual void didRemoveAllIcons() override;
+    virtual void didFinishURLImport() override;
 
     // IPC::MessageReceiver
     virtual void didReceiveMessage(IPC::Connection*, IPC::MessageDecoder&) override;
@@ -106,8 +101,8 @@
     void notifyIconDataReadyForPageURL(const String&);
 
     WebContext* m_webContext;
-    
-    OwnPtr<WebCore::IconDatabase> m_iconDatabaseImpl;
+
+    std::unique_ptr<WebCore::IconDatabase> m_iconDatabaseImpl;
     bool m_urlImportCompleted;
     bool m_databaseCleanupDisabled;
     HashMap<uint64_t, String> m_pendingLoadDecisionURLMap;
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to