Use unique_ptr instead of delete in a few places
authordarin@apple.com <darin@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 12 Oct 2013 14:15:33 +0000 (14:15 +0000)
committerdarin@apple.com <darin@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 12 Oct 2013 14:15:33 +0000 (14:15 +0000)
https://bugs.webkit.org/show_bug.cgi?id=122639

Reviewed by Anders Carlsson.

Source/WebCore:

* Modules/webdatabase/DatabaseBackendBase.cpp:
(WebCore::guidToDatabaseMap): Use NeverDestroyed instead of DEFINE_STATIC_LOCAL.
(WebCore::guidForOriginAndName): Ditto.
(WebCore::DatabaseBackendBase::DatabaseBackendBase): Removed unneeded initialization
of m_guid, which is set in the body of the constructor explicitly anyway. Use emptyString.
Use unique_ptr for the values in the map. Use the add idiom instead of the get/set idiom.
(WebCore::DatabaseBackendBase::closeDatabase): Use the find/remove idiom instead of the
get/remove idiom.
(WebCore::DatabaseBackendBase::performOpenAndVerify): Use auto here to avoid having to
use the map type by name.

* loader/cache/CachedFont.cpp:
(WebCore::CachedFont::CachedFont): Don't initialize m_fontData to 0; unique_ptr will do that.
(WebCore::CachedFont::~CachedFont): Don't delete m_fontData. unique_ptr will do that.
(WebCore::CachedFont::ensureCustomFontData): Add a get.
(WebCore::CachedFont::allClientsRemoved): Don't delete m_fontData. Use nullptr instead of 0.
* loader/cache/CachedFont.h: Changed m_fontData to a unique_ptr.

* platform/graphics/BitmapImage.cpp:
(WebCore::BitmapImage::BitmapImage): Don't initialize m_frameTimer to 0; unique_ptr will do that.
(WebCore::BitmapImage::startAnimation): Use make_unique to create the timer.
(WebCore::BitmapImage::stopAnimation): Don't delete m_frameTimer. Use nullptr instead of 0.
* platform/graphics/BitmapImage.h: Changed m_FrameTimer to a unique_ptr.
* platform/graphics/cg/BitmapImageCG.cpp:
(WebCore::BitmapImage::BitmapImage): Don't initialize m_frameTimer to 0; unique_ptr will do that.

* platform/graphics/mac/FontCustomPlatformData.cpp:
(WebCore::FontCustomPlatformData::~FontCustomPlatformData): Don't call CGFontRelease on m_cgFont.
(WebCore::FontCustomPlatformData::fontPlatformData): Use get on m_cgFont.
(WebCore::createFontCustomPlatformData): Use nullptr instead of 0, and make_unique instead of new.
* platform/graphics/mac/FontCustomPlatformData.h: Chnaged m_cgFont to be a RetainPtr, and the
return value from createFontCustomPlatformData to be a unique_ptr.

* platform/graphics/blackberry/FontCustomPlatformData.h:
* platform/graphics/blackberry/FontCustomPlatformDataBlackBerry.cpp:
(WebCore::createFontCustomPlatformData):
* platform/graphics/cairo/BitmapImageCairo.cpp:
(WebCore::BitmapImage::BitmapImage):
* platform/graphics/cairo/FontCustomPlatformData.h:
* platform/graphics/cg/BitmapImageCG.cpp:
(WebCore::BitmapImage::BitmapImage):
* platform/graphics/freetype/FontCustomPlatformDataFreeType.cpp:
(WebCore::createFontCustomPlatformData):
* platform/graphics/win/FontCustomPlatformData.cpp:
(WebCore::createFontCustomPlatformData):
* platform/graphics/win/FontCustomPlatformData.h:
* platform/graphics/win/FontCustomPlatformDataCairo.cpp:
(WebCore::createFontCustomPlatformData):
* platform/graphics/wince/FontCustomPlatformData.cpp:
(WebCore::createFontCustomPlatformData):
* platform/graphics/wince/FontCustomPlatformData.h:
Same thing on all the other platforms.

* platform/network/NetworkStorageSession.h: Changed return value of createPrivateBrowsingSession
to a unique_ptr, and made constructors public.

* platform/network/cf/NetworkStorageSessionCFNet.cpp:
(WebCore::NetworkStorageSession::createPrivateBrowsingSession): Use make_unique.

* platform/network/soup/NetworkStorageSessionSoup.cpp:
(WebCore::defaultSession):
(WebCore::NetworkStorageSession::defaultStorageSession):
(WebCore::NetworkStorageSession::createPrivateBrowsingSession):
(WebCore::NetworkStorageSession::switchToNewTestingSession):
Same thing on all the other platforms.

Source/WebKit/mac:

* History/WebHistory.mm:
(-[WebHistoryPrivate init]): Use make_unique.
(-[WebHistoryPrivate dealloc]): Don't delete.
(-[WebHistoryPrivate finalize]): Don't delete.
(-[WebHistoryPrivate data]): Use get.

* WebCoreSupport/WebFrameNetworkingContext.mm:
(privateSession): Use NeverDestroyed here instead of a raw pointer.
(WebFrameNetworkingContext::ensurePrivateBrowsingSession): Use the
new function instead of direct global variable access.
(WebFrameNetworkingContext::destroyPrivateBrowsingSession): Ditto.
(WebFrameNetworkingContext::storageSession): Ditto.

* WebView/WebFrame.mm:
(-[WebFramePrivate dealloc]): Don't delete.
(-[WebFramePrivate finalize]): Don't delete.
(-[WebFrame _attachScriptDebugger]): Use make_unique.
(-[WebFrame _detachScriptDebugger]): Don't delete.
* WebView/WebFrameInternal.h: Use unique_ptr.

Source/WebKit/win:

* WebCoreSupport/WebFrameNetworkingContext.cpp:
(privateSession):
(identifierBase):
(WebFrameNetworkingContext::setCookieAcceptPolicyForAllContexts):
(WebFrameNetworkingContext::setPrivateBrowsingStorageSessionIdentifierBase):
(WebFrameNetworkingContext::ensurePrivateBrowsingSession):
(WebFrameNetworkingContext::destroyPrivateBrowsingSession):
(WebFrameNetworkingContext::storageSession):

Source/WebKit2:

* NetworkProcess/mac/RemoteNetworkingContext.mm:
(WebKit::privateBrowsingStorageSession): Use NeverDestroyed and unique_ptr.
(WebKit::RemoteNetworkingContext::ensurePrivateBrowsingSession): Use std::move.

* Shared/Downloads/DownloadManager.cpp:
(WebKit::DownloadManager::startDownload): Use std::move. Also add instead of set.
(WebKit::DownloadManager::convertHandleToDownload): Ditto.
(WebKit::DownloadManager::downloadFinished): Don't delete.

* Shared/Downloads/DownloadManager.h: Changed m_downloads to hold unique_ptr instead
of raw pointers.

* Shared/SandboxExtension.h: Use std::unique_ptr for m_data.

* Shared/mac/SandboxExtensionMac.mm:
(WebKit::SandboxExtension::HandleArray::HandleArray): Don't initialize m_data to 0.
(WebKit::SandboxExtension::HandleArray::~HandleArray): Don't delete m_data.
(WebKit::SandboxExtension::HandleArray::allocate): Use make_unique to allocate m_data.

* WebProcess/WebCoreSupport/mac/WebFrameNetworkingContext.mm:
(WebKit::privateSession): Use NeverDestroyed and unique_ptr.
(WebKit::identifierBase): Use NeverDestroyed.
(WebKit::WebFrameNetworkingContext::setPrivateBrowsingStorageSessionIdentifierBase):
Updated to use the above.
(WebKit::WebFrameNetworkingContext::ensurePrivateBrowsingSession): Ditto.
(WebKit::WebFrameNetworkingContext::destroyPrivateBrowsingSession): Ditto.
(WebKit::WebFrameNetworkingContext::setCookieAcceptPolicyForAllContexts): Ditto.
(WebKit::WebFrameNetworkingContext::storageSession): Ditto.

* WebProcess/WebCoreSupport/soup/WebFrameNetworkingContext.cpp:
(WebKit::privateSession):
(WebKit::WebFrameNetworkingContext::ensurePrivateBrowsingSession):
(WebKit::WebFrameNetworkingContext::destroyPrivateBrowsingSession):
(WebKit::WebFrameNetworkingContext::storageSession):
(WebKit::WebFrameNetworkingContext::webFrameLoaderClient):
More of the same.

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

37 files changed:
Source/WebCore/ChangeLog
Source/WebCore/Modules/webdatabase/DatabaseBackendBase.cpp
Source/WebCore/loader/cache/CachedFont.cpp
Source/WebCore/loader/cache/CachedFont.h
Source/WebCore/platform/graphics/BitmapImage.cpp
Source/WebCore/platform/graphics/BitmapImage.h
Source/WebCore/platform/graphics/blackberry/FontCustomPlatformData.h
Source/WebCore/platform/graphics/blackberry/FontCustomPlatformDataBlackBerry.cpp
Source/WebCore/platform/graphics/cairo/BitmapImageCairo.cpp
Source/WebCore/platform/graphics/cairo/FontCustomPlatformData.h
Source/WebCore/platform/graphics/cg/BitmapImageCG.cpp
Source/WebCore/platform/graphics/freetype/FontCustomPlatformDataFreeType.cpp
Source/WebCore/platform/graphics/mac/FontCustomPlatformData.cpp
Source/WebCore/platform/graphics/mac/FontCustomPlatformData.h
Source/WebCore/platform/graphics/win/FontCustomPlatformData.cpp
Source/WebCore/platform/graphics/win/FontCustomPlatformData.h
Source/WebCore/platform/graphics/win/FontCustomPlatformDataCairo.cpp
Source/WebCore/platform/graphics/wince/FontCustomPlatformData.cpp
Source/WebCore/platform/graphics/wince/FontCustomPlatformData.h
Source/WebCore/platform/network/NetworkStorageSession.h
Source/WebCore/platform/network/cf/NetworkStorageSessionCFNet.cpp
Source/WebCore/platform/network/soup/NetworkStorageSessionSoup.cpp
Source/WebKit/mac/ChangeLog
Source/WebKit/mac/History/WebHistory.mm
Source/WebKit/mac/WebCoreSupport/WebFrameNetworkingContext.mm
Source/WebKit/mac/WebView/WebFrame.mm
Source/WebKit/mac/WebView/WebFrameInternal.h
Source/WebKit/win/ChangeLog
Source/WebKit/win/WebCoreSupport/WebFrameNetworkingContext.cpp
Source/WebKit2/ChangeLog
Source/WebKit2/NetworkProcess/mac/RemoteNetworkingContext.mm
Source/WebKit2/Shared/Downloads/DownloadManager.cpp
Source/WebKit2/Shared/Downloads/DownloadManager.h
Source/WebKit2/Shared/SandboxExtension.h
Source/WebKit2/Shared/mac/SandboxExtensionMac.mm
Source/WebKit2/WebProcess/WebCoreSupport/mac/WebFrameNetworkingContext.mm
Source/WebKit2/WebProcess/WebCoreSupport/soup/WebFrameNetworkingContext.cpp

index 0919064..ddb94d1 100644 (file)
@@ -1,3 +1,76 @@
+2013-10-12  Darin Adler  <darin@apple.com>
+
+        Use unique_ptr instead of delete in a few places
+        https://bugs.webkit.org/show_bug.cgi?id=122639
+
+        Reviewed by Anders Carlsson.
+
+        * Modules/webdatabase/DatabaseBackendBase.cpp:
+        (WebCore::guidToDatabaseMap): Use NeverDestroyed instead of DEFINE_STATIC_LOCAL.
+        (WebCore::guidForOriginAndName): Ditto.
+        (WebCore::DatabaseBackendBase::DatabaseBackendBase): Removed unneeded initialization
+        of m_guid, which is set in the body of the constructor explicitly anyway. Use emptyString.
+        Use unique_ptr for the values in the map. Use the add idiom instead of the get/set idiom.
+        (WebCore::DatabaseBackendBase::closeDatabase): Use the find/remove idiom instead of the
+        get/remove idiom.
+        (WebCore::DatabaseBackendBase::performOpenAndVerify): Use auto here to avoid having to
+        use the map type by name.
+
+        * loader/cache/CachedFont.cpp:
+        (WebCore::CachedFont::CachedFont): Don't initialize m_fontData to 0; unique_ptr will do that.
+        (WebCore::CachedFont::~CachedFont): Don't delete m_fontData. unique_ptr will do that.
+        (WebCore::CachedFont::ensureCustomFontData): Add a get.
+        (WebCore::CachedFont::allClientsRemoved): Don't delete m_fontData. Use nullptr instead of 0.
+        * loader/cache/CachedFont.h: Changed m_fontData to a unique_ptr.
+
+        * platform/graphics/BitmapImage.cpp:
+        (WebCore::BitmapImage::BitmapImage): Don't initialize m_frameTimer to 0; unique_ptr will do that.
+        (WebCore::BitmapImage::startAnimation): Use make_unique to create the timer.
+        (WebCore::BitmapImage::stopAnimation): Don't delete m_frameTimer. Use nullptr instead of 0.
+        * platform/graphics/BitmapImage.h: Changed m_FrameTimer to a unique_ptr.
+        * platform/graphics/cg/BitmapImageCG.cpp:
+        (WebCore::BitmapImage::BitmapImage): Don't initialize m_frameTimer to 0; unique_ptr will do that.
+
+        * platform/graphics/mac/FontCustomPlatformData.cpp:
+        (WebCore::FontCustomPlatformData::~FontCustomPlatformData): Don't call CGFontRelease on m_cgFont.
+        (WebCore::FontCustomPlatformData::fontPlatformData): Use get on m_cgFont.
+        (WebCore::createFontCustomPlatformData): Use nullptr instead of 0, and make_unique instead of new.
+        * platform/graphics/mac/FontCustomPlatformData.h: Chnaged m_cgFont to be a RetainPtr, and the
+        return value from createFontCustomPlatformData to be a unique_ptr.
+
+        * platform/graphics/blackberry/FontCustomPlatformData.h:
+        * platform/graphics/blackberry/FontCustomPlatformDataBlackBerry.cpp:
+        (WebCore::createFontCustomPlatformData):
+        * platform/graphics/cairo/BitmapImageCairo.cpp:
+        (WebCore::BitmapImage::BitmapImage):
+        * platform/graphics/cairo/FontCustomPlatformData.h:
+        * platform/graphics/cg/BitmapImageCG.cpp:
+        (WebCore::BitmapImage::BitmapImage):
+        * platform/graphics/freetype/FontCustomPlatformDataFreeType.cpp:
+        (WebCore::createFontCustomPlatformData):
+        * platform/graphics/win/FontCustomPlatformData.cpp:
+        (WebCore::createFontCustomPlatformData):
+        * platform/graphics/win/FontCustomPlatformData.h:
+        * platform/graphics/win/FontCustomPlatformDataCairo.cpp:
+        (WebCore::createFontCustomPlatformData):
+        * platform/graphics/wince/FontCustomPlatformData.cpp:
+        (WebCore::createFontCustomPlatformData):
+        * platform/graphics/wince/FontCustomPlatformData.h:
+        Same thing on all the other platforms.
+
+        * platform/network/NetworkStorageSession.h: Changed return value of createPrivateBrowsingSession
+        to a unique_ptr, and made constructors public.
+
+        * platform/network/cf/NetworkStorageSessionCFNet.cpp:
+        (WebCore::NetworkStorageSession::createPrivateBrowsingSession): Use make_unique.
+
+        * platform/network/soup/NetworkStorageSessionSoup.cpp:
+        (WebCore::defaultSession):
+        (WebCore::NetworkStorageSession::defaultStorageSession):
+        (WebCore::NetworkStorageSession::createPrivateBrowsingSession):
+        (WebCore::NetworkStorageSession::switchToNewTestingSession):
+        Same thing on all the other platforms.
+
 2013-10-11  Andreas Kling  <akling@apple.com>
 
         Make LayoutState not arena-allocated.
index b5abe10..5a9f71e 100644 (file)
@@ -45,6 +45,7 @@
 #include "SecurityOrigin.h"
 #include <wtf/HashMap.h>
 #include <wtf/HashSet.h>
+#include <wtf/NeverDestroyed.h>
 #include <wtf/PassRefPtr.h>
 #include <wtf/RefPtr.h>
 #include <wtf/StdLibExtras.h>
@@ -167,12 +168,13 @@ static inline void updateGuidVersionMap(DatabaseGuid guid, String newVersion)
     guidToVersionMap().set(guid, newVersion.isEmpty() ? String() : newVersion.isolatedCopy());
 }
 
-typedef HashMap<DatabaseGuid, HashSet<DatabaseBackendBase*>*> GuidDatabaseMap;
+typedef HashMap<DatabaseGuid, std::unique_ptr<HashSet<DatabaseBackendBase*>>> GuidDatabaseMap;
+
 static GuidDatabaseMap& guidToDatabaseMap()
 {
     // Ensure the the mutex is locked.
     ASSERT(!guidMutex().tryLock());
-    DEFINE_STATIC_LOCAL(GuidDatabaseMap, map, ());
+    static NeverDestroyed<GuidDatabaseMap> map;
     return map;
 }
 
@@ -184,12 +186,12 @@ static DatabaseGuid guidForOriginAndName(const String& origin, const String& nam
     String stringID = origin + "/" + name;
 
     typedef HashMap<String, int> IDGuidMap;
-    DEFINE_STATIC_LOCAL(IDGuidMap, stringIdentifierToGUIDMap, ());
-    DatabaseGuid guid = stringIdentifierToGUIDMap.get(stringID);
+    static NeverDestroyed<HashMap<String, int>> map;
+    DatabaseGuid guid = map.get().get(stringID);
     if (!guid) {
         static int currentNewGUID = 1;
         guid = currentNewGUID++;
-        stringIdentifierToGUIDMap.set(stringID, guid);
+        map.get().set(stringID, guid);
     }
 
     return guid;
@@ -215,7 +217,6 @@ DatabaseBackendBase::DatabaseBackendBase(PassRefPtr<DatabaseBackendContext> data
     , m_expectedVersion(expectedVersion.isolatedCopy())
     , m_displayName(displayName.isolatedCopy())
     , m_estimatedSize(estimatedSize)
-    , m_guid(0)
     , m_opened(false)
     , m_new(false)
     , m_isSyncDatabase(databaseType == DatabaseType::Sync)
@@ -225,17 +226,14 @@ DatabaseBackendBase::DatabaseBackendBase(PassRefPtr<DatabaseBackendContext> data
     m_databaseAuthorizer = DatabaseAuthorizer::create(infoTableName);
 
     if (m_name.isNull())
-        m_name = "";
+        m_name = emptyString();
 
     {
         MutexLocker locker(guidMutex());
         m_guid = guidForOriginAndName(securityOrigin()->toString(), name);
-        HashSet<DatabaseBackendBase*>* hashSet = guidToDatabaseMap().get(m_guid);
-        if (!hashSet) {
-            hashSet = new HashSet<DatabaseBackendBase*>;
-            guidToDatabaseMap().set(m_guid, hashSet);
-        }
-
+        std::unique_ptr<HashSet<DatabaseBackendBase*>>& hashSet = guidToDatabaseMap().add(m_guid, nullptr).iterator->value;
+        if (!hashSet)
+            hashSet = std::make_unique<HashSet<DatabaseBackendBase*>>();
         hashSet->add(this);
     }
 
@@ -268,13 +266,13 @@ void DatabaseBackendBase::closeDatabase()
     {
         MutexLocker locker(guidMutex());
 
-        HashSet<DatabaseBackendBase*>* hashSet = guidToDatabaseMap().get(m_guid);
-        ASSERT(hashSet);
-        ASSERT(hashSet->contains(this));
-        hashSet->remove(this);
-        if (hashSet->isEmpty()) {
-            guidToDatabaseMap().remove(m_guid);
-            delete hashSet;
+        auto it = guidToDatabaseMap().find(m_guid);
+        ASSERT(it != guidToDatabaseMap().end());
+        ASSERT(it->value);
+        ASSERT(it->value->contains(this));
+        it->value->remove(this);
+        if (it->value->isEmpty()) {
+            guidToDatabaseMap().remove(it);
             guidToVersionMap().remove(m_guid);
         }
     }
@@ -329,7 +327,7 @@ bool DatabaseBackendBase::performOpenAndVerify(bool shouldSetVersionInNewDatabas
     {
         MutexLocker locker(guidMutex());
 
-        GuidVersionMap::iterator entry = guidToVersionMap().find(m_guid);
+        auto entry = guidToVersionMap().find(m_guid);
         if (entry != guidToVersionMap().end()) {
             // Map null string to empty string (see updateGuidVersionMap()).
             currentVersion = entry->value.isNull() ? emptyString() : entry->value.isolatedCopy();
index 8c55dd1..e07010a 100644 (file)
@@ -50,7 +50,6 @@ namespace WebCore {
 
 CachedFont::CachedFont(const ResourceRequest& resourceRequest)
     : CachedResource(resourceRequest, FontResource)
-    , m_fontData(0)
     , m_loadInitiated(false)
     , m_hasCreatedFontData(false)
 {
@@ -58,7 +57,6 @@ CachedFont::CachedFont(const ResourceRequest& resourceRequest)
 
 CachedFont::~CachedFont()
 {
-    delete m_fontData;
 }
 
 void CachedFont::load(CachedResourceLoader*, const ResourceLoaderOptions& options)
@@ -100,7 +98,7 @@ bool CachedFont::ensureCustomFontData()
         else
             setStatus(DecodeError);
     }
-    return m_fontData;
+    return m_fontData.get();
 }
 
 FontPlatformData CachedFont::platformDataFromCustomData(float size, bool bold, bool italic, FontOrientation orientation, FontWidthVariant widthVariant, FontRenderingMode renderingMode)
@@ -164,10 +162,7 @@ SVGFontElement* CachedFont::getSVGFontById(const String& fontName) const
 
 void CachedFont::allClientsRemoved()
 {
-    if (m_fontData) {
-        delete m_fontData;
-        m_fontData = 0;
-    }
+    m_fontData = nullptr;
 }
 
 void CachedFont::checkNotify()
index 548179f..ca433b6 100644 (file)
@@ -67,7 +67,7 @@ private:
 
     virtual void allClientsRemoved() OVERRIDE;
 
-    FontCustomPlatformData* m_fontData;
+    std::unique_ptr<FontCustomPlatformData> m_fontData;
     bool m_loadInitiated;
     bool m_hasCreatedFontData;
 
index c835b92..8005d8e 100644 (file)
@@ -43,7 +43,6 @@ BitmapImage::BitmapImage(ImageObserver* observer)
     : Image(observer)
     , m_currentFrame(0)
     , m_frames(0)
-    , m_frameTimer(0)
     , m_repetitionCount(cAnimationNone)
     , m_repetitionCountStatus(Unknown)
     , m_repetitionsComplete(0)
@@ -429,7 +428,7 @@ void BitmapImage::startAnimation(bool catchUpIfNecessary)
 
     if (!catchUpIfNecessary || time < m_desiredFrameStartTime) {
         // Haven't yet reached time for next frame to start; delay until then.
-        m_frameTimer = new Timer<BitmapImage>(this, &BitmapImage::advanceAnimation);
+        m_frameTimer = std::make_unique<Timer<BitmapImage>>(this, &BitmapImage::advanceAnimation);
         m_frameTimer->startOneShot(std::max(m_desiredFrameStartTime - time, 0.));
     } else {
         // We've already reached or passed the time for the next frame to start.
@@ -479,8 +478,7 @@ void BitmapImage::stopAnimation()
 {
     // This timer is used to animate all occurrences of this image.  Don't invalidate
     // the timer unless all renderers have stopped drawing.
-    delete m_frameTimer;
-    m_frameTimer = 0;
+    m_frameTimer = nullptr;
 }
 
 void BitmapImage::resetAnimation()
index bc9a63f..fecc7bf 100644 (file)
@@ -272,7 +272,7 @@ private:
     size_t m_currentFrame; // The index of the current frame of animation.
     Vector<FrameData, 1> m_frames; // An array of the cached frames of the animation. We have to ref frames to pin them in the cache.
 
-    Timer<BitmapImage>* m_frameTimer;
+    std::unique_ptr<Timer<BitmapImage>> m_frameTimer;
     int m_repetitionCount; // How many total animation loops we should do.  This will be cAnimationNone if this image type is incapable of animation.
     RepetitionCountStatus m_repetitionCountStatus;
     int m_repetitionsComplete;  // How many repetitions we've finished.
index 1f5600e..b5c9855 100644 (file)
@@ -48,7 +48,7 @@ public:
     RefPtr<SharedBuffer> m_buffer;
 };
 
-FontCustomPlatformData* createFontCustomPlatformData(SharedBuffer*);
+std::unique_ptr<FontCustomPlatformData> createFontCustomPlatformData(SharedBuffer*);
 
 } // namespace WebCore
 
index d16784c..24a02fb 100644 (file)
@@ -56,7 +56,7 @@ bool FontCustomPlatformData::supportsFormat(const String& format)
     return isSupported;
 }
 
-FontCustomPlatformData* createFontCustomPlatformData(SharedBuffer* buffer)
+std::unique_ptr<FontCustomPlatformData> createFontCustomPlatformData(SharedBuffer* buffer)
 {
     ASSERT_ARG(buffer, buffer);
 
@@ -64,16 +64,16 @@ FontCustomPlatformData* createFontCustomPlatformData(SharedBuffer* buffer)
     OpenTypeSanitizer sanitizer(buffer);
     RefPtr<SharedBuffer> transcodeBuffer = sanitizer.sanitize();
     if (!transcodeBuffer)
-        return 0; // validation failed.
+        return nullptr; // validation failed.
     buffer = transcodeBuffer.get();
 #endif
 
     FILECHAR name[MAX_FONT_NAME_LEN+1];
     memset(name, 0, MAX_FONT_NAME_LEN+1);
     if (FS_load_font(BlackBerry::Platform::Graphics::getIType(), 0, const_cast<FS_BYTE*>(reinterpret_cast<const FS_BYTE*>(buffer->data())), 0, MAX_FONT_NAME_LEN, name) != SUCCESS)
-        return 0;
+        return nullptr;
 
-    return new FontCustomPlatformData(name, buffer);
+    return std::make_unique<FontCustomPlatformData>(name, buffer);
 }
 
 }
index 00a03de..8e5627f 100644 (file)
@@ -31,6 +31,7 @@
 #include "CairoUtilities.h"
 #include "ImageObserver.h"
 #include "PlatformContextCairo.h"
+#include "Timer.h"
 #include <cairo.h>
 
 namespace WebCore {
@@ -39,12 +40,10 @@ BitmapImage::BitmapImage(PassRefPtr<cairo_surface_t> nativeImage, ImageObserver*
     : Image(observer)
     , m_size(cairoSurfaceSize(nativeImage.get()))
     , m_currentFrame(0)
-    , m_frames(0)
-    , m_frameTimer(0)
     , m_repetitionCount(cAnimationNone)
     , m_repetitionCountStatus(Unknown)
     , m_repetitionsComplete(0)
-    , m_decodedSize(0)
+    , m_decodedSize(m_size.width() * m_size.height() * 4)
     , m_frameCount(1)
     , m_isSolidColor(false)
     , m_checkedForSolidColor(false)
@@ -54,12 +53,11 @@ BitmapImage::BitmapImage(PassRefPtr<cairo_surface_t> nativeImage, ImageObserver*
     , m_sizeAvailable(true)
     , m_haveFrameCount(true)
 {
-    m_decodedSize = m_size.width() * m_size.height() * 4;
-
     m_frames.grow(1);
     m_frames[0].m_hasAlpha = cairo_surface_get_content(nativeImage.get()) != CAIRO_CONTENT_COLOR;
     m_frames[0].m_frame = nativeImage;
     m_frames[0].m_haveMetadata = true;
+
     checkForSolidColor();
 }
 
index 5807102..f7a055a 100644 (file)
@@ -49,7 +49,7 @@ private:
     cairo_font_face_t* m_fontFace;
 };
 
-FontCustomPlatformData* createFontCustomPlatformData(SharedBuffer* buffer);
+std::unique_ptr<FontCustomPlatformData> createFontCustomPlatformData(SharedBuffer*);
 
 }
 
index 6c69ce0..92ccfda 100644 (file)
@@ -67,7 +67,6 @@ BitmapImage::BitmapImage(CGImageRef cgImage, ImageObserver* observer)
     : Image(observer)
     , m_currentFrame(0)
     , m_frames(0)
-    , m_frameTimer(0)
     , m_repetitionCount(cAnimationNone)
     , m_repetitionCountStatus(Unknown)
     , m_repetitionsComplete(0)
index 841c8a3..e139aa5 100644 (file)
@@ -64,7 +64,7 @@ FontPlatformData FontCustomPlatformData::fontPlatformData(int size, bool bold, b
     return FontPlatformData(m_fontFace, size, bold, italic);
 }
 
-FontCustomPlatformData* createFontCustomPlatformData(SharedBuffer* buffer)
+std::unique_ptr<FontCustomPlatformData> createFontCustomPlatformData(SharedBuffer* buffer)
 {
     ASSERT_ARG(buffer, buffer);
 
@@ -72,22 +72,22 @@ FontCustomPlatformData* createFontCustomPlatformData(SharedBuffer* buffer)
     if (isWOFF(buffer)) {
         Vector<char> sfnt;
         if (!convertWOFFToSfnt(buffer, sfnt))
-            return 0;
+            return nullptr;
 
         sfntBuffer = SharedBuffer::adoptVector(sfnt);
         buffer = sfntBuffer.get();
     }
 
-    static FT_Library library = 0;
+    static FT_Library library;
     if (!library && FT_Init_FreeType(&library)) {
-        library = 0;
-        return 0;
+        library = nullptr;
+        return nullptr;
     }
 
     FT_Face freeTypeFace;
     if (FT_New_Memory_Face(library, reinterpret_cast<const FT_Byte*>(buffer->data()), buffer->size(), 0, &freeTypeFace))
-        return 0;
-    return new FontCustomPlatformData(freeTypeFace, buffer);
+        return nullptr;
+    return std::make_unique<FontCustomPlatformData>(freeTypeFace, buffer);
 }
 
 bool FontCustomPlatformData::supportsFormat(const String& format)
index d562118..7b1f898 100644 (file)
@@ -31,15 +31,14 @@ namespace WebCore {
 
 FontCustomPlatformData::~FontCustomPlatformData()
 {
-    CGFontRelease(m_cgFont);
 }
 
 FontPlatformData FontCustomPlatformData::fontPlatformData(int size, bool bold, bool italic, FontOrientation orientation, FontWidthVariant widthVariant, FontRenderingMode)
 {
-    return FontPlatformData(m_cgFont, size, bold, italic, orientation, widthVariant);
+    return FontPlatformData(m_cgFont.get(), size, bold, italic, orientation, widthVariant);
 }
 
-FontCustomPlatformData* createFontCustomPlatformData(SharedBuffer* buffer)
+std::unique_ptr<FontCustomPlatformData> createFontCustomPlatformData(SharedBuffer* buffer)
 {
     ASSERT_ARG(buffer, buffer);
 
@@ -47,14 +46,14 @@ FontCustomPlatformData* createFontCustomPlatformData(SharedBuffer* buffer)
     OpenTypeSanitizer sanitizer(buffer);
     RefPtr<SharedBuffer> transcodeBuffer = sanitizer.sanitize();
     if (!transcodeBuffer)
-        return 0; // validation failed.
+        return nullptr; // validation failed.
     buffer = transcodeBuffer.get();
 #else
     RefPtr<SharedBuffer> sfntBuffer;
     if (isWOFF(buffer)) {
         Vector<char> sfnt;
         if (!convertWOFFToSfnt(buffer, sfnt))
-            return 0;
+            return nullptr;
 
         sfntBuffer = SharedBuffer::adoptVector(sfnt);
         buffer = sfntBuffer.get();
@@ -68,10 +67,9 @@ FontCustomPlatformData* createFontCustomPlatformData(SharedBuffer* buffer)
 
     RetainPtr<CGFontRef> cgFontRef = adoptCF(CGFontCreateWithDataProvider(dataProvider.get()));
     if (!cgFontRef)
-        return 0;
+        return nullptr;
 
-    FontCustomPlatformData* fontCustomPlatformData = new FontCustomPlatformData(containerRef, cgFontRef.leakRef());
-    return fontCustomPlatformData;
+    return std::make_unique<FontCustomPlatformData>(containerRef, cgFontRef.get());
 }
 
 bool FontCustomPlatformData::supportsFormat(const String& format)
index c7ae1ca..c87ccd8 100644 (file)
@@ -27,6 +27,7 @@
 #include <CoreFoundation/CFBase.h>
 #include <wtf/Forward.h>
 #include <wtf/Noncopyable.h>
+#include <wtf/RetainPtr.h>
 
 typedef struct CGFont* CGFontRef;
 typedef UInt32 ATSFontContainerRef;
@@ -53,10 +54,10 @@ public:
     static bool supportsFormat(const String&);
 
     ATSFontContainerRef m_atsContainer;
-    CGFontRef m_cgFont;
+    RetainPtr<CGFontRef> m_cgFont;
 };
 
-FontCustomPlatformData* createFontCustomPlatformData(SharedBuffer*);
+std::unique_ptr<FontCustomPlatformData> createFontCustomPlatformData(SharedBuffer*);
 
 }
 
index 2e54124..4975648 100644 (file)
@@ -81,7 +81,7 @@ static String createUniqueFontName()
     return fontName;
 }
 
-FontCustomPlatformData* createFontCustomPlatformData(SharedBuffer* buffer)
+std::unique_ptr<FontCustomPlatformData> createFontCustomPlatformData(SharedBuffer* buffer)
 {
     ASSERT_ARG(buffer, buffer);
 
@@ -89,7 +89,7 @@ FontCustomPlatformData* createFontCustomPlatformData(SharedBuffer* buffer)
     if (isWOFF(buffer)) {
         Vector<char> sfnt;
         if (!convertWOFFToSfnt(buffer, sfnt))
-            return 0;
+            return nullptr;
 
         sfntBuffer = SharedBuffer::adoptVector(sfnt);
         buffer = sfntBuffer.get();
@@ -99,8 +99,8 @@ FontCustomPlatformData* createFontCustomPlatformData(SharedBuffer* buffer)
     HANDLE fontReference;
     fontReference = renameAndActivateFont(buffer, fontName);
     if (!fontReference)
-        return 0;
-    return new FontCustomPlatformData(fontReference, fontName);
+        return nullptr;
+    return std::make_unique<FontCustomPlatformData>(fontReference, fontName);
 }
 
 bool FontCustomPlatformData::supportsFormat(const String& format)
index 188951b..2280949 100644 (file)
@@ -56,7 +56,7 @@ public:
     String m_name;
 };
 
-FontCustomPlatformData* createFontCustomPlatformData(SharedBuffer*);
+std::unique_ptr<FontCustomPlatformData> createFontCustomPlatformData(SharedBuffer*);
 
 }
 
index f1a8225..7fc55fa 100644 (file)
@@ -80,7 +80,7 @@ static String createUniqueFontName()
     return fontName;
 }
 
-FontCustomPlatformData* createFontCustomPlatformData(SharedBuffer* buffer)
+std::unique_ptr<FontCustomPlatformData> createFontCustomPlatformData(SharedBuffer* buffer)
 {
     ASSERT_ARG(buffer, buffer);
 
@@ -88,9 +88,9 @@ FontCustomPlatformData* createFontCustomPlatformData(SharedBuffer* buffer)
     HANDLE fontReference = renameAndActivateFont(buffer, fontName);
 
     if (!fontReference)
-        return 0;
+        return nullptr;
 
-    return new FontCustomPlatformData(fontReference, fontName);
+    return std::make_unique<FontCustomPlatformData>(fontReference, fontName);
 }
 
 bool FontCustomPlatformData::supportsFormat(const String& format)
index e1e5afa..9c89b3c 100644 (file)
@@ -70,15 +70,15 @@ static String createUniqueFontName()
     return fontName.replace('/', '_');
 }
 
-FontCustomPlatformData* createFontCustomPlatformData(const SharedBuffer* buffer)
+std::unique_ptr<FontCustomPlatformData> createFontCustomPlatformData(const SharedBuffer* buffer)
 {
     if (g_customFontCache) {
         String fontName = createUniqueFontName();
         RefPtr<SharedBuffer> localBuffer = SharedBuffer::create(buffer->data(), buffer->size());
         if (renameFont(localBuffer.get(), fontName) && g_customFontCache->registerFont(fontName, localBuffer.get()))
-            return new FontCustomPlatformData(fontName);
+            return std::make_unique<FontCustomPlatformData>(fontName);
     }
-    return 0;
+    return nullptr;
 }
 
 bool FontCustomPlatformData::supportsFormat(const String& format)
index a3a8a29..84d5d73 100644 (file)
@@ -56,7 +56,7 @@ namespace WebCore {
         String m_name;
     };
 
-    FontCustomPlatformData* createFontCustomPlatformData(const SharedBuffer*);
+    std::unique_ptr<FontCustomPlatformData> createFontCustomPlatformData(const SharedBuffer*);
     void setCustomFontCache(CustomFontCache*);
 }
 
index ee77726..56a0a59 100644 (file)
@@ -46,7 +46,7 @@ class NetworkStorageSession {
     WTF_MAKE_NONCOPYABLE(NetworkStorageSession); WTF_MAKE_FAST_ALLOCATED;
 public:
     static NetworkStorageSession& defaultStorageSession();
-    static PassOwnPtr<NetworkStorageSession> createPrivateBrowsingSession(const String& identifierBase = String());
+    static std::unique_ptr<NetworkStorageSession> createPrivateBrowsingSession(const String& identifierBase = String());
 
     static void switchToNewTestingSession();
 
@@ -55,10 +55,12 @@ public:
 #endif
 
 #if PLATFORM(MAC) || USE(CFNETWORK)
+    NetworkStorageSession(RetainPtr<CFURLStorageSessionRef>);
     // May be null, in which case a Foundation default should be used.
     CFURLStorageSessionRef platformSession() { return m_platformSession.get(); }
     RetainPtr<CFHTTPCookieStorageRef> cookieStorage() const;
 #elif USE(SOUP)
+    NetworkStorageSession(SoupSession*);
     void setSoupSession(SoupSession* session) { m_session = session; }
     SoupSession* soupSession() const { return m_session.get(); }
 #else
@@ -69,11 +71,9 @@ public:
 
 private:
 #if PLATFORM(MAC) || USE(CFNETWORK)
-    NetworkStorageSession(RetainPtr<CFURLStorageSessionRef>);
     NetworkStorageSession();
     RetainPtr<CFURLStorageSessionRef> m_platformSession;
 #elif USE(SOUP)
-    NetworkStorageSession(SoupSession*);
     GRefPtr<SoupSession> m_session;
 #else
     RefPtr<NetworkingContext> m_context;
index ef5947d..a13f316 100644 (file)
@@ -89,18 +89,18 @@ NetworkStorageSession& NetworkStorageSession::defaultStorageSession()
     return *defaultNetworkStorageSession();
 }
 
-PassOwnPtr<NetworkStorageSession> NetworkStorageSession::createPrivateBrowsingSession(const String& identifierBase)
+std::unique_ptr<NetworkStorageSession> NetworkStorageSession::createPrivateBrowsingSession(const String& identifierBase)
 {
     RetainPtr<CFStringRef> cfIdentifier = String(identifierBase + ".PrivateBrowsing").createCFString();
 
 #if PLATFORM(MAC)
-    OwnPtr<NetworkStorageSession> session = adoptPtr(new NetworkStorageSession(adoptCF(wkCreatePrivateStorageSession(cfIdentifier.get()))));
+    auto session = std::make_unique<NetworkStorageSession>(adoptCF(wkCreatePrivateStorageSession(cfIdentifier.get())));
 #else
-    OwnPtr<NetworkStorageSession> session = adoptPtr(new NetworkStorageSession(adoptCF(wkCreatePrivateStorageSession(cfIdentifier.get(), defaultNetworkStorageSession()->platformSession()))));
+    auto session = std::make_unique<NetworkStorageSession>(adoptCF(wkCreatePrivateStorageSession(cfIdentifier.get(), defaultNetworkStorageSession()->platformSession())));
 #endif
     session->m_isPrivate = true;
 
-    return session.release();
+    return session;
 }
 
 RetainPtr<CFHTTPCookieStorageRef> NetworkStorageSession::cookieStorage() const
index 7501569..8b77525 100644 (file)
@@ -29,8 +29,7 @@
 
 #include "ResourceHandle.h"
 #include <wtf/MainThread.h>
-#include <wtf/PassOwnPtr.h>
-#include <wtf/text/StringConcatenate.h>
+#include <wtf/NeverDestroyed.h>
 
 namespace WebCore {
 
@@ -40,33 +39,30 @@ NetworkStorageSession::NetworkStorageSession(SoupSession* session)
 {
 }
 
-static OwnPtr<NetworkStorageSession>& defaultSession()
+static std::unique_ptr<NetworkStorageSession>& defaultSession()
 {
     ASSERT(isMainThread());
-    DEFINE_STATIC_LOCAL(OwnPtr<NetworkStorageSession>, session, ());
+    NeverDestroyed<std::unique_ptr<NetworkStorageSession>> session;
     return session;
 }
 
 NetworkStorageSession& NetworkStorageSession::defaultStorageSession()
 {
     if (!defaultSession())
-        defaultSession() = adoptPtr(new NetworkStorageSession(ResourceHandle::defaultSession()));
+        defaultSession() = std::make_unique<NetworkStorageSession>(ResourceHandle::defaultSession());
     return *defaultSession();
 }
 
-PassOwnPtr<NetworkStorageSession> NetworkStorageSession::createPrivateBrowsingSession(const String&)
+std::unique_ptr<NetworkStorageSession> NetworkStorageSession::createPrivateBrowsingSession(const String&)
 {
-    OwnPtr<NetworkStorageSession> session = adoptPtr(new NetworkStorageSession(ResourceHandle::createPrivateBrowsingSession()));
+    auto session = std::make_unique<NetworkStorageSession>(ResourceHandle::createPrivateBrowsingSession());
     session->m_isPrivate = true;
-
-    return session.release();
+    return session;
 }
 
 void NetworkStorageSession::switchToNewTestingSession()
 {
-    // A null session will make us fall back to the default cookie jar, which is currently
-    // the expected behavior for tests.
-    defaultSession() = adoptPtr(new NetworkStorageSession(ResourceHandle::createTestingSession()));
+    defaultSession() = std::make_unique<NetworkStorageSession>(ResourceHandle::createTestingSession());
 }
 
 }
index fa817ba..7156656 100644 (file)
@@ -1,3 +1,30 @@
+2013-10-12  Darin Adler  <darin@apple.com>
+
+        Use unique_ptr instead of delete in a few places
+        https://bugs.webkit.org/show_bug.cgi?id=122639
+
+        Reviewed by Anders Carlsson.
+
+        * History/WebHistory.mm:
+        (-[WebHistoryPrivate init]): Use make_unique.
+        (-[WebHistoryPrivate dealloc]): Don't delete.
+        (-[WebHistoryPrivate finalize]): Don't delete.
+        (-[WebHistoryPrivate data]): Use get.
+
+        * WebCoreSupport/WebFrameNetworkingContext.mm:
+        (privateSession): Use NeverDestroyed here instead of a raw pointer.
+        (WebFrameNetworkingContext::ensurePrivateBrowsingSession): Use the
+        new function instead of direct global variable access.
+        (WebFrameNetworkingContext::destroyPrivateBrowsingSession): Ditto.
+        (WebFrameNetworkingContext::storageSession): Ditto.
+
+        * WebView/WebFrame.mm:
+        (-[WebFramePrivate dealloc]): Don't delete.
+        (-[WebFramePrivate finalize]): Don't delete.
+        (-[WebFrame _attachScriptDebugger]): Use make_unique.
+        (-[WebFrame _detachScriptDebugger]): Don't delete.
+        * WebView/WebFrameInternal.h: Use unique_ptr.
+
 2013-10-11  Timothy Hatcher  <timothy@apple.com>
 
         Remove preference support for picking the old Web Inspector.
index e0378b7..6fb362e 100644 (file)
@@ -74,7 +74,7 @@ private:
 @interface WebHistoryPrivate : NSObject {
 @private
     NSMutableDictionary *_entriesByURL;
-    DateToEntriesMap* _entriesByDate;
+    std::unique_ptr<DateToEntriesMap> _entriesByDate;
     NSMutableArray *_orderedLastVisitedDays;
     BOOL itemLimitSet;
     int itemLimit;
@@ -132,7 +132,7 @@ private:
         return nil;
     
     _entriesByURL = [[NSMutableDictionary alloc] init];
-    _entriesByDate = new DateToEntriesMap;
+    _entriesByDate = std::make_unique<DateToEntriesMap>();
 
     return self;
 }
@@ -141,13 +141,11 @@ private:
 {
     [_entriesByURL release];
     [_orderedLastVisitedDays release];
-    delete _entriesByDate;
     [super dealloc];
 }
 
 - (void)finalize
 {
-    delete _entriesByDate;
     [super finalize];
 }
 
@@ -636,7 +634,7 @@ static inline WebHistoryDateKey dateKey(NSTimeInterval date)
     
     // Ignores the date and item count limits; these are respected when loading instead of when saving, so
     // that clients can learn of discarded items by listening to WebHistoryItemsDiscardedWhileLoadingNotification.
-    WebHistoryWriter writer(_entriesByDate);
+    WebHistoryWriter writer(_entriesByDate.get());
     writer.writePropertyList();
     return [[(NSData *)writer.releaseData().get() retain] autorelease];
 }
index 4ad77c6..aa95727 100644 (file)
 #include <WebCore/Page.h>
 #include <WebCore/ResourceError.h>
 #include <WebCore/Settings.h>
+#include <wtf/NeverDestroyed.h>
 
 using namespace WebCore;
 
-static NetworkStorageSession* privateSession;
+static std::unique_ptr<NetworkStorageSession>& privateSession()
+{
+    static NeverDestroyed<std::unique_ptr<NetworkStorageSession>> session;
+    return session;
+}
 
 void WebFrameNetworkingContext::ensurePrivateBrowsingSession()
 {
     ASSERT(isMainThread());
 
-    if (privateSession)
+    if (privateSession())
         return;
 
-    privateSession = NetworkStorageSession::createPrivateBrowsingSession([[NSBundle mainBundle] bundleIdentifier]).leakPtr();
+    privateSession() = NetworkStorageSession::createPrivateBrowsingSession([[NSBundle mainBundle] bundleIdentifier]);
 }
 
 void WebFrameNetworkingContext::destroyPrivateBrowsingSession()
 {
     ASSERT(isMainThread());
 
-    delete privateSession;
-    privateSession = 0;
+    privateSession() = nullptr;
 }
 
 bool WebFrameNetworkingContext::needsSiteSpecificQuirks() const
@@ -94,7 +98,7 @@ NetworkStorageSession& WebFrameNetworkingContext::storageSession() const
     ASSERT(isMainThread());
 
     if (frame() && frame()->settings().privateBrowsingEnabled())
-        return *privateSession;
+        return *privateSession();
 
     return NetworkStorageSession::defaultStorageSession();
 }
index 68f59cf..d192776 100644 (file)
@@ -164,15 +164,11 @@ NSString *NSAccessibilityEnhancedUserInterfaceAttribute = @"AXEnhancedUserInterf
 {
     [webFrameView release];
 
-    delete scriptDebugger;
-
     [super dealloc];
 }
 
 - (void)finalize
 {
-    delete scriptDebugger;
-
     [super finalize];
 }
 
@@ -322,20 +318,16 @@ WebView *getWebView(WebFrame *webFrame)
         return;
 
     if (_private->scriptDebugger) {
-        ASSERT(_private->scriptDebugger == globalObject->debugger());
+        ASSERT(_private->scriptDebugger.get() == globalObject->debugger());
         return;
     }
 
-    _private->scriptDebugger = new WebScriptDebugger(globalObject);
+    _private->scriptDebugger = std::make_unique<WebScriptDebugger>(globalObject);
 }
 
 - (void)_detachScriptDebugger
 {
-    if (!_private->scriptDebugger)
-        return;
-
-    delete _private->scriptDebugger;
-    _private->scriptDebugger = 0;
+    _private->scriptDebugger = nullptr;
 }
 
 - (id)_initWithWebFrameView:(WebFrameView *)fv webView:(WebView *)v
index ab8c5c2..fccbeaa 100644 (file)
@@ -78,7 +78,7 @@ WebView *getWebView(WebFrame *webFrame);
 @public
     WebCore::Frame* coreFrame;
     WebFrameView *webFrameView;
-    WebScriptDebugger* scriptDebugger;
+    std::unique_ptr<WebScriptDebugger> scriptDebugger;
     id internalLoadDelegate;
     BOOL shouldCreateRenderers;
     BOOL includedInWebKitStatistics;
index f10bac2..15b5a55 100644 (file)
@@ -1,3 +1,19 @@
+2013-10-12  Darin Adler  <darin@apple.com>
+
+        Use unique_ptr instead of delete in a few places
+        https://bugs.webkit.org/show_bug.cgi?id=122639
+
+        Reviewed by Anders Carlsson.
+
+        * WebCoreSupport/WebFrameNetworkingContext.cpp:
+        (privateSession):
+        (identifierBase):
+        (WebFrameNetworkingContext::setCookieAcceptPolicyForAllContexts):
+        (WebFrameNetworkingContext::setPrivateBrowsingStorageSessionIdentifierBase):
+        (WebFrameNetworkingContext::ensurePrivateBrowsingSession):
+        (WebFrameNetworkingContext::destroyPrivateBrowsingSession):
+        (WebFrameNetworkingContext::storageSession):
+
 2013-10-10  Anders Carlsson  <andersca@apple.com>
 
         Fix build.
index 5ee4706..bf59ee7 100644 (file)
 
 #include "config.h"
 #include "WebFrameNetworkingContext.h"
+
 #include "WebView.h"
-#if USE(CFNETWORK)
-#include <CFNetwork/CFHTTPCookiesPriv.h>
-#endif
 #include <WebCore/FrameLoader.h>
 #include <WebCore/FrameLoaderClient.h>
 #include <WebCore/NetworkStorageSession.h>
 #include <WebCore/Page.h>
 #include <WebCore/ResourceError.h>
 #include <WebCore/Settings.h>
+#include <wtf/NeverDestroyed.h>
+
 #if USE(CFNETWORK)
+#include <CFNetwork/CFHTTPCookiesPriv.h>
 #include <WebKitSystemInterface/WebKitSystemInterface.h>
 #endif
 
 using namespace WebCore;
 
-static NetworkStorageSession* privateSession;
-static String* identifierBase;
+static std::unique_ptr<NetworkStorageSession>& privateSession()
+{
+    static NeverDestroyed<std::unique_ptr<NetworkStorageSession>> session;
+    return session;
+}
+
+static String& identifierBase()
+{
+    static NeverDestroyed<String> base;
+    return base;
+}
 
 #if USE(CFNETWORK)
 void WebFrameNetworkingContext::setCookieAcceptPolicyForAllContexts(WebKitCookieStorageAcceptPolicy policy)
@@ -50,8 +60,8 @@ void WebFrameNetworkingContext::setCookieAcceptPolicyForAllContexts(WebKitCookie
     if (RetainPtr<CFHTTPCookieStorageRef> cookieStorage = NetworkStorageSession::defaultStorageSession().cookieStorage())
         CFHTTPCookieStorageSetCookieAcceptPolicy(cookieStorage.get(), policy);
 
-    if (privateSession)
-        CFHTTPCookieStorageSetCookieAcceptPolicy(privateSession->cookieStorage().get(), policy);
+    if (privateSession())
+        CFHTTPCookieStorageSetCookieAcceptPolicy(privateSession()->cookieStorage().get(), policy);
 }
 #endif
 
@@ -59,9 +69,7 @@ void WebFrameNetworkingContext::setPrivateBrowsingStorageSessionIdentifierBase(c
 {
     ASSERT(isMainThread());
 
-    delete identifierBase;
-
-    identifierBase = new String(base);
+    identifierBase() = base;
 }
 
 void WebFrameNetworkingContext::ensurePrivateBrowsingSession()
@@ -69,19 +77,18 @@ void WebFrameNetworkingContext::ensurePrivateBrowsingSession()
 #if USE(CFNETWORK)
     ASSERT(isMainThread());
 
-    if (privateSession)
+    if (privateSession())
         return;
 
     String base;
-    if (!identifierBase) {
+    if (identifierBase().isNull()) {
         if (CFTypeRef bundleValue = CFBundleGetValueForInfoDictionaryKey(CFBundleGetMainBundle(), kCFBundleIdentifierKey))
             if (CFGetTypeID(bundleValue) == CFStringGetTypeID())
                 base = reinterpret_cast<CFStringRef>(bundleValue);
-    }
-    else
-        base = *identifierBase;
+    } else
+        base = identifierBase();
 
-    privateSession = NetworkStorageSession::createPrivateBrowsingSession(base).leakPtr();
+    privateSession() = NetworkStorageSession::createPrivateBrowsingSession(base);
 #endif
 }
 
@@ -89,8 +96,7 @@ void WebFrameNetworkingContext::destroyPrivateBrowsingSession()
 {
     ASSERT(isMainThread());
 
-    delete privateSession;
-    privateSession = 0;
+    privateSession() = nullptr;
 }
 
 ResourceError WebFrameNetworkingContext::blockedError(const ResourceRequest& request) const
@@ -109,7 +115,7 @@ NetworkStorageSession& WebFrameNetworkingContext::storageSession() const
     ASSERT(isMainThread());
 
     if (frame() && frame()->settings().privateBrowsingEnabled())
-        return *privateSession;
+        return *privateSession();
 
     return NetworkStorageSession::defaultStorageSession();
 }
index 3d6dfaf..7b6392c 100644 (file)
@@ -1,3 +1,47 @@
+2013-10-12  Darin Adler  <darin@apple.com>
+
+        Use unique_ptr instead of delete in a few places
+        https://bugs.webkit.org/show_bug.cgi?id=122639
+
+        Reviewed by Anders Carlsson.
+
+        * NetworkProcess/mac/RemoteNetworkingContext.mm:
+        (WebKit::privateBrowsingStorageSession): Use NeverDestroyed and unique_ptr.
+        (WebKit::RemoteNetworkingContext::ensurePrivateBrowsingSession): Use std::move.
+
+        * Shared/Downloads/DownloadManager.cpp:
+        (WebKit::DownloadManager::startDownload): Use std::move. Also add instead of set.
+        (WebKit::DownloadManager::convertHandleToDownload): Ditto.
+        (WebKit::DownloadManager::downloadFinished): Don't delete.
+
+        * Shared/Downloads/DownloadManager.h: Changed m_downloads to hold unique_ptr instead
+        of raw pointers.
+
+        * Shared/SandboxExtension.h: Use std::unique_ptr for m_data.
+
+        * Shared/mac/SandboxExtensionMac.mm:
+        (WebKit::SandboxExtension::HandleArray::HandleArray): Don't initialize m_data to 0.
+        (WebKit::SandboxExtension::HandleArray::~HandleArray): Don't delete m_data.
+        (WebKit::SandboxExtension::HandleArray::allocate): Use make_unique to allocate m_data.
+
+        * WebProcess/WebCoreSupport/mac/WebFrameNetworkingContext.mm:
+        (WebKit::privateSession): Use NeverDestroyed and unique_ptr.
+        (WebKit::identifierBase): Use NeverDestroyed.
+        (WebKit::WebFrameNetworkingContext::setPrivateBrowsingStorageSessionIdentifierBase):
+        Updated to use the above.
+        (WebKit::WebFrameNetworkingContext::ensurePrivateBrowsingSession): Ditto.
+        (WebKit::WebFrameNetworkingContext::destroyPrivateBrowsingSession): Ditto.
+        (WebKit::WebFrameNetworkingContext::setCookieAcceptPolicyForAllContexts): Ditto.
+        (WebKit::WebFrameNetworkingContext::storageSession): Ditto.
+
+        * WebProcess/WebCoreSupport/soup/WebFrameNetworkingContext.cpp:
+        (WebKit::privateSession):
+        (WebKit::WebFrameNetworkingContext::ensurePrivateBrowsingSession):
+        (WebKit::WebFrameNetworkingContext::destroyPrivateBrowsingSession):
+        (WebKit::WebFrameNetworkingContext::storageSession):
+        (WebKit::WebFrameNetworkingContext::webFrameLoaderClient):
+        More of the same.
+
 2013-10-11  Timothy Hatcher  <timothy@apple.com>
 
         Remove preference support for picking the old Web Inspector.
index f1cc065..24b2898 100644 (file)
 #import <WebCore/ResourceError.h>
 #import <WebKitSystemInterface.h>
 #import <wtf/MainThread.h>
-#import <wtf/PassOwnPtr.h>
-#import <wtf/OwnPtr.h>
+#import <wtf/NeverDestroyed.h>
 
 using namespace WebCore;
 
 namespace WebKit {
 
-static OwnPtr<NetworkStorageSession>& privateBrowsingStorageSession()
+static std::unique_ptr<NetworkStorageSession>& privateBrowsingStorageSession()
 {
     ASSERT(isMainThread());
-    DEFINE_STATIC_LOCAL(OwnPtr<NetworkStorageSession>, session, ());
+    static NeverDestroyed<std::unique_ptr<NetworkStorageSession>> session;
     return session;
 }
 
@@ -112,7 +111,7 @@ void RemoteNetworkingContext::ensurePrivateBrowsingSession()
     ASSERT(!privateBrowsingStorageSessionIdentifierBase().isNull());
     RetainPtr<CFStringRef> cfIdentifier = String(privateBrowsingStorageSessionIdentifierBase() + ".PrivateBrowsing").createCFString();
 
-    privateBrowsingStorageSession() = NetworkStorageSession::createPrivateBrowsingSession(privateBrowsingStorageSessionIdentifierBase());
+    privateBrowsingStorageSession() = std::move(NetworkStorageSession::createPrivateBrowsingSession(privateBrowsingStorageSessionIdentifierBase()));
 }
 
 void RemoteNetworkingContext::destroyPrivateBrowsingSession()
index 06afeec..df353d8 100644 (file)
@@ -44,7 +44,7 @@ void DownloadManager::startDownload(uint64_t downloadID, const ResourceRequest&
     download->start();
 
     ASSERT(!m_downloads.contains(downloadID));
-    m_downloads.set(downloadID, download.release());
+    m_downloads.add(downloadID, std::move(download));
 }
 
 void DownloadManager::convertHandleToDownload(uint64_t downloadID, ResourceHandle* handle, const ResourceRequest& request, const ResourceResponse& response)
@@ -53,7 +53,7 @@ void DownloadManager::convertHandleToDownload(uint64_t downloadID, ResourceHandl
 
     download->startWithHandle(handle, response);
     ASSERT(!m_downloads.contains(downloadID));
-    m_downloads.set(downloadID, download.release());
+    m_downloads.add(downloadID, std::move(download));
 }
 
 void DownloadManager::cancelDownload(uint64_t downloadID)
@@ -69,8 +69,6 @@ void DownloadManager::downloadFinished(Download* download)
 {
     ASSERT(m_downloads.contains(download->downloadID()));
     m_downloads.remove(download->downloadID());
-
-    delete download;
 }
 
 void DownloadManager::didCreateDownload()
index ca7ee8a..e5ffffa 100644 (file)
@@ -79,7 +79,7 @@ public:
 
 private:
     Client* m_client;
-    HashMap<uint64_t, Download*> m_downloads;
+    HashMap<uint64_t, std::unique_ptr<Download>> m_downloads;
 };
 
 } // namespace WebKit
index 103bade..2d96c27 100644 (file)
@@ -82,7 +82,7 @@ public:
        
     private:
 #if ENABLE(WEB_PROCESS_SANDBOX)
-        Handle* m_data;
+        std::unique_ptr<Handle[]> m_data;
         size_t m_size;
 #else
         Handle m_emptyHandle;
index 33d4000..53d96b8 100644 (file)
@@ -87,15 +87,12 @@ bool SandboxExtension::Handle::decode(CoreIPC::ArgumentDecoder& decoder, Handle&
 }
 
 SandboxExtension::HandleArray::HandleArray()
-    : m_data(0)
-    , m_size(0)
+    : m_size(0)
 {
 }
 
 SandboxExtension::HandleArray::~HandleArray()
 {
-    if (m_data)
-        delete[] m_data;
 }
 
 void SandboxExtension::HandleArray::allocate(size_t size)
@@ -105,7 +102,7 @@ void SandboxExtension::HandleArray::allocate(size_t size)
 
     ASSERT(!m_data);
 
-    m_data = new SandboxExtension::Handle[size];
+    m_data = std::make_unique<SandboxExtension::Handle[]>(size);
     m_size = size;
 }
 
index 0cf6800..f80867c 100644 (file)
 #include <WebCore/ResourceError.h>
 #include <WebCore/Settings.h>
 #include <WebKitSystemInterface.h>
+#include <wtf/NeverDestroyed.h>
 
 using namespace WebCore;
 
 namespace WebKit {
 
-static NetworkStorageSession* privateSession;
-static String* identifierBase;
+static std::unique_ptr<NetworkStorageSession>& privateSession()
+{
+    static NeverDestroyed<std::unique_ptr<NetworkStorageSession>> session;
+    return session;
+}
+
+static String& identifierBase()
+{
+    static NeverDestroyed<String> base;
+    return base;
+}
     
 void WebFrameNetworkingContext::setPrivateBrowsingStorageSessionIdentifierBase(const String& base)
 {
     ASSERT(isMainThread());
 
-    delete identifierBase;
-
-    identifierBase = new String(base);
+    identifierBase() = base;
 }
 
 void WebFrameNetworkingContext::ensurePrivateBrowsingSession()
 {
     ASSERT(isMainThread());
 
-    if (privateSession)
+    if (privateSession())
         return;
 
     String base;
-    if (!identifierBase)
+    if (identifierBase().isNull())
         base = [[NSBundle mainBundle] bundleIdentifier];
     else
-        base = *identifierBase;
+        base = identifierBase();
 
-    privateSession = NetworkStorageSession::createPrivateBrowsingSession(base).leakPtr();
+    privateSession() = NetworkStorageSession::createPrivateBrowsingSession(base);
 }
 
 void WebFrameNetworkingContext::destroyPrivateBrowsingSession()
 {
     ASSERT(isMainThread());
 
-    delete privateSession;
-    privateSession = 0;
+    privateSession() = nullptr;
 }
 
 void WebFrameNetworkingContext::setCookieAcceptPolicyForAllContexts(HTTPCookieAcceptPolicy policy)
@@ -82,8 +89,8 @@ void WebFrameNetworkingContext::setCookieAcceptPolicyForAllContexts(HTTPCookieAc
     if (RetainPtr<CFHTTPCookieStorageRef> cookieStorage = NetworkStorageSession::defaultStorageSession().cookieStorage())
         WKSetHTTPCookieAcceptPolicy(cookieStorage.get(), policy);
 
-    if (privateSession)
-        WKSetHTTPCookieAcceptPolicy(privateSession->cookieStorage().get(), policy);
+    if (privateSession())
+        WKSetHTTPCookieAcceptPolicy(privateSession()->cookieStorage().get(), policy);
 }
     
 bool WebFrameNetworkingContext::needsSiteSpecificQuirks() const
@@ -118,7 +125,7 @@ NetworkStorageSession& WebFrameNetworkingContext::storageSession() const
     ASSERT(isMainThread());
 
     if (frame() && frame()->settings().privateBrowsingEnabled())
-        return *privateSession;
+        return *privateSession();
 
     return NetworkStorageSession::defaultStorageSession();
 }
index 3b8a038..f97434a 100644 (file)
 #include "WebFrame.h"
 #include "WebPage.h"
 #include <WebCore/Settings.h>
+#include <wtf/NeverDestroyed.h>
 
 using namespace WebCore;
 
 namespace WebKit {
 
-static NetworkStorageSession* privateSession;
+static std::unique_ptr<NetworkStorageSession>& privateSession()
+{
+    static NeverDestroyed<std::unique_ptr<NetworkStorageSession>> session;
+    return session;
+}
 
 void WebFrameNetworkingContext::ensurePrivateBrowsingSession()
 {
     ASSERT(isMainThread());
 
-    if (privateSession)
+    if (privateSession())
         return;
 
-    privateSession = NetworkStorageSession::createPrivateBrowsingSession().leakPtr();
+    privateSession() = NetworkStorageSession::createPrivateBrowsingSession();
 }
 
 void WebFrameNetworkingContext::destroyPrivateBrowsingSession()
 {
     ASSERT(isMainThread());
 
-    delete privateSession;
-    privateSession = 0;
+    privateSession() = nullptr;
 }
 
 WebFrameNetworkingContext::WebFrameNetworkingContext(WebFrame* frame)
@@ -66,7 +70,7 @@ WebFrameNetworkingContext::WebFrameNetworkingContext(WebFrame* frame)
 NetworkStorageSession& WebFrameNetworkingContext::storageSession() const
 {
     if (frame() && frame()->settings().privateBrowsingEnabled())
-        return *privateSession;
+        return *privateSession();
 
     return NetworkStorageSession::defaultStorageSession();
 }
@@ -79,10 +83,9 @@ uint64_t WebFrameNetworkingContext::initiatingPageID() const
 WebFrameLoaderClient* WebFrameNetworkingContext::webFrameLoaderClient() const
 {
     if (!frame())
-        return 0;
+        return nullptr;
 
     return toWebFrameLoaderClient(frame()->loader().client());
 }
 
 }
-