Adopt modern C++11 loops and fix WebArchive creation functions
authorandersca@apple.com <andersca@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 18 Jun 2014 19:40:25 +0000 (19:40 +0000)
committerandersca@apple.com <andersca@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 18 Jun 2014 19:40:25 +0000 (19:40 +0000)
https://bugs.webkit.org/show_bug.cgi?id=134032

Reviewed by Andreas Kling.

Source/WebCore:
Use modern loops in a couple of places, fix DocumentLoader::subresources() to return a Vector,
and stop using Vectors of PassRefPtrs.

* WebCore.exp.in:
* dom/Document.cpp:
(WebCore::Document::textInserted):
(WebCore::Document::textRemoved):
(WebCore::Document::textNodesMerged):
* loader/DocumentLoader.cpp:
(WebCore::DocumentLoader::subresources):
(WebCore::DocumentLoader::getSubresources): Deleted.
* loader/DocumentLoader.h:
* loader/appcache/ApplicationCache.cpp:
(WebCore::ApplicationCache::dump):
* loader/appcache/ApplicationCache.h:
(WebCore::ApplicationCache::resources):
(WebCore::ApplicationCache::begin): Deleted.
(WebCore::ApplicationCache::end): Deleted.
* loader/appcache/ApplicationCacheGroup.cpp:
(WebCore::ApplicationCacheGroup::didFinishLoadingManifest):
* loader/appcache/ApplicationCacheHost.cpp:
(WebCore::ApplicationCacheHost::fillResourceList):
* loader/appcache/ApplicationCacheStorage.cpp:
(WebCore::ApplicationCacheStorage::fallbackCacheGroupForURL):
(WebCore::ApplicationCacheStorage::store):
(WebCore::ApplicationCacheStorage::empty):
(WebCore::ApplicationCacheStorage::storeCopyOfCache):
* loader/archive/cf/LegacyWebArchive.cpp:
(WebCore::LegacyWebArchive::create):
(WebCore::LegacyWebArchive::createFromSelection):
* loader/archive/cf/LegacyWebArchive.h:
* xml/XMLHttpRequestProgressEventThrottle.cpp:
(WebCore::XMLHttpRequestProgressEventThrottle::dispatchDeferredEvents):

Source/WebKit/mac:
* WebView/WebArchive.mm:
(-[WebArchive initWithMainResource:subresources:subframeArchives:]):
* WebView/WebDataSource.mm:
(-[WebDataSource subresources]):

Source/WebKit2:
* Shared/APIWebArchive.cpp:
(API::WebArchive::WebArchive):

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

18 files changed:
Source/WebCore/ChangeLog
Source/WebCore/WebCore.exp.in
Source/WebCore/dom/Document.cpp
Source/WebCore/loader/DocumentLoader.cpp
Source/WebCore/loader/DocumentLoader.h
Source/WebCore/loader/appcache/ApplicationCache.cpp
Source/WebCore/loader/appcache/ApplicationCache.h
Source/WebCore/loader/appcache/ApplicationCacheGroup.cpp
Source/WebCore/loader/appcache/ApplicationCacheHost.cpp
Source/WebCore/loader/appcache/ApplicationCacheStorage.cpp
Source/WebCore/loader/archive/cf/LegacyWebArchive.cpp
Source/WebCore/loader/archive/cf/LegacyWebArchive.h
Source/WebCore/xml/XMLHttpRequestProgressEventThrottle.cpp
Source/WebKit/mac/ChangeLog
Source/WebKit/mac/WebView/WebArchive.mm
Source/WebKit/mac/WebView/WebDataSource.mm
Source/WebKit2/ChangeLog
Source/WebKit2/Shared/APIWebArchive.cpp

index e521aaf..7226298 100644 (file)
@@ -1,3 +1,44 @@
+2014-06-18  Anders Carlsson  <andersca@apple.com>
+
+        Adopt modern C++11 loops and fix WebArchive creation functions
+        https://bugs.webkit.org/show_bug.cgi?id=134032
+
+        Reviewed by Andreas Kling.
+
+        Use modern loops in a couple of places, fix DocumentLoader::subresources() to return a Vector,
+        and stop using Vectors of PassRefPtrs.
+
+        * WebCore.exp.in:
+        * dom/Document.cpp:
+        (WebCore::Document::textInserted):
+        (WebCore::Document::textRemoved):
+        (WebCore::Document::textNodesMerged):
+        * loader/DocumentLoader.cpp:
+        (WebCore::DocumentLoader::subresources):
+        (WebCore::DocumentLoader::getSubresources): Deleted.
+        * loader/DocumentLoader.h:
+        * loader/appcache/ApplicationCache.cpp:
+        (WebCore::ApplicationCache::dump):
+        * loader/appcache/ApplicationCache.h:
+        (WebCore::ApplicationCache::resources):
+        (WebCore::ApplicationCache::begin): Deleted.
+        (WebCore::ApplicationCache::end): Deleted.
+        * loader/appcache/ApplicationCacheGroup.cpp:
+        (WebCore::ApplicationCacheGroup::didFinishLoadingManifest):
+        * loader/appcache/ApplicationCacheHost.cpp:
+        (WebCore::ApplicationCacheHost::fillResourceList):
+        * loader/appcache/ApplicationCacheStorage.cpp:
+        (WebCore::ApplicationCacheStorage::fallbackCacheGroupForURL):
+        (WebCore::ApplicationCacheStorage::store):
+        (WebCore::ApplicationCacheStorage::empty):
+        (WebCore::ApplicationCacheStorage::storeCopyOfCache):
+        * loader/archive/cf/LegacyWebArchive.cpp:
+        (WebCore::LegacyWebArchive::create):
+        (WebCore::LegacyWebArchive::createFromSelection):
+        * loader/archive/cf/LegacyWebArchive.h:
+        * xml/XMLHttpRequestProgressEventThrottle.cpp:
+        (WebCore::XMLHttpRequestProgressEventThrottle::dispatchDeferredEvents):
+
 2014-06-18  Alex Christensen  <achristensen@webkit.org>
 
         Remove duplicate code using sdiv.
index fc2aec6..22a84b7 100644 (file)
@@ -682,7 +682,7 @@ __ZN7WebCore16IconDatabaseBase28synchronousIconURLForPageURLERKN3WTF6StringE
 __ZN7WebCore16IconDatabaseBase4openERKN3WTF6StringES4_
 __ZN7WebCore16LegacyWebArchive19createFromSelectionEPNS_5FrameE
 __ZN7WebCore16LegacyWebArchive21rawDataRepresentationEv
-__ZN7WebCore16LegacyWebArchive6createEN3WTF10PassRefPtrINS_15ArchiveResourceEEERNS1_6VectorIS4_Lm0ENS1_15CrashOnOverflowEEERNS5_INS2_IS0_EELm0ES6_EE
+__ZN7WebCore16LegacyWebArchive6createEN3WTF10PassRefPtrINS_15ArchiveResourceEEENS1_6VectorINS1_6RefPtrIS3_EELm0ENS1_15CrashOnOverflowEEENS5_INS6_IS0_EELm0ES8_EE
 __ZN7WebCore16LegacyWebArchive6createEPNS_12SharedBufferE
 __ZN7WebCore16LegacyWebArchive6createEPNS_4NodeENSt3__18functionIFbRNS_5FrameEEEE
 __ZN7WebCore16LegacyWebArchive6createEPNS_5FrameE
@@ -1640,9 +1640,9 @@ __ZNK7WebCore14DocumentLoader11frameLoaderEv
 __ZNK7WebCore14DocumentLoader11responseURLEv
 __ZNK7WebCore14DocumentLoader11subresourceERKNS_3URLE
 __ZNK7WebCore14DocumentLoader12mainResourceEv
+__ZNK7WebCore14DocumentLoader12subresourcesEv
 __ZNK7WebCore14DocumentLoader13urlForHistoryEv
 __ZNK7WebCore14DocumentLoader14unreachableURLEv
-__ZNK7WebCore14DocumentLoader15getSubresourcesERN3WTF6VectorINS1_10PassRefPtrINS_15ArchiveResourceEEELm0ENS1_15CrashOnOverflowEEE
 __ZNK7WebCore14DocumentLoader15originalRequestEv
 __ZNK7WebCore14DocumentLoader16mainResourceDataEv
 __ZNK7WebCore14DocumentLoader17parsedArchiveDataEv
index 770d170..5abeeac 100644 (file)
@@ -3611,9 +3611,8 @@ void Document::nodeWillBeRemoved(Node* n)
 void Document::textInserted(Node* text, unsigned offset, unsigned length)
 {
     if (!m_ranges.isEmpty()) {
-        HashSet<Range*>::const_iterator end = m_ranges.end();
-        for (HashSet<Range*>::const_iterator it = m_ranges.begin(); it != end; ++it)
-            (*it)->textInserted(text, offset, length);
+        for (auto& range : m_ranges)
+            range->textInserted(text, offset, length);
     }
 
     // Update the markers for spelling and grammar checking.
@@ -3623,9 +3622,8 @@ void Document::textInserted(Node* text, unsigned offset, unsigned length)
 void Document::textRemoved(Node* text, unsigned offset, unsigned length)
 {
     if (!m_ranges.isEmpty()) {
-        HashSet<Range*>::const_iterator end = m_ranges.end();
-        for (HashSet<Range*>::const_iterator it = m_ranges.begin(); it != end; ++it)
-            (*it)->textRemoved(text, offset, length);
+        for (auto& range : m_ranges)
+            range->textRemoved(text, offset, length);
     }
 
     // Update the markers for spelling and grammar checking.
@@ -3637,9 +3635,8 @@ void Document::textNodesMerged(Text* oldNode, unsigned offset)
 {
     if (!m_ranges.isEmpty()) {
         NodeWithIndex oldNodeWithIndex(oldNode);
-        HashSet<Range*>::const_iterator end = m_ranges.end();
-        for (HashSet<Range*>::const_iterator it = m_ranges.begin(); it != end; ++it)
-            (*it)->textNodesMerged(oldNodeWithIndex, offset);
+        for (auto& range : m_ranges)
+            range->textNodesMerged(oldNodeWithIndex, offset);
     }
 
     // FIXME: This should update markers for spelling and grammar checking.
index 88f31f6..62cca75 100644 (file)
@@ -1105,20 +1105,19 @@ PassRefPtr<ArchiveResource> DocumentLoader::subresource(const URL& url) const
     return ArchiveResource::create(data->sharedBuffer(), url, resource->response());
 }
 
-void DocumentLoader::getSubresources(Vector<PassRefPtr<ArchiveResource>>& subresources) const
+Vector<RefPtr<ArchiveResource>> DocumentLoader::subresources() const
 {
     if (!isCommitted())
-        return;
+        return { };
+
+    Vector<RefPtr<ArchiveResource>> subresources;
 
-    const CachedResourceLoader::DocumentResourceMap& allResources = m_cachedResourceLoader->allCachedResources();
-    CachedResourceLoader::DocumentResourceMap::const_iterator end = allResources.end();
-    for (CachedResourceLoader::DocumentResourceMap::const_iterator it = allResources.begin(); it != end; ++it) {
-        RefPtr<ArchiveResource> subresource = this->subresource(URL(ParsedURLString, it->value->url()));
-        if (subresource)
-            subresources.append(subresource.release());
+    for (auto& cachedResourceHandle : m_cachedResourceLoader->allCachedResources().values()) {
+        if (RefPtr<ArchiveResource> subresource = this->subresource(URL(ParsedURLString, cachedResourceHandle->url())))
+            subresources.append(std::move(subresource));
     }
 
-    return;
+    return subresources;
 }
 
 void DocumentLoader::deliverSubstituteResourcesAfterDelay()
index 9a10e5d..41fd6f9 100644 (file)
@@ -162,8 +162,7 @@ namespace WebCore {
         // Return an ArchiveResource for the URL, either creating from live data or
         // pulling from the ArchiveResourceCollection
         PassRefPtr<ArchiveResource> subresource(const URL&) const;
-        void getSubresources(Vector<PassRefPtr<ArchiveResource>>&) const;
-
+        Vector<RefPtr<ArchiveResource>> subresources() const;
 
 #ifndef NDEBUG
         bool isSubstituteLoadPending(ResourceLoader*) const;
index 983becc..35f3e95 100644 (file)
@@ -222,11 +222,9 @@ int64_t ApplicationCache::diskUsageForOrigin(SecurityOrigin* origin)
 #ifndef NDEBUG
 void ApplicationCache::dump()
 {
-    HashMap<String, RefPtr<ApplicationCacheResource>>::const_iterator end = m_resources.end();
-    
-    for (HashMap<String, RefPtr<ApplicationCacheResource>>::const_iterator it = m_resources.begin(); it != end; ++it) {
-        printf("%s ", it->key.ascii().data());
-        ApplicationCacheResource::dumpType(it->value->type());
+    for (const auto& urlAndResource : m_resources) {
+        printf("%s ", urlAndResource.key.utf8().data());
+        ApplicationCacheResource::dumpType(urlAndResource.value->type());
     }
 }
 #endif
index 680635d..e541e83 100644 (file)
@@ -81,8 +81,7 @@ public:
 #endif
 
     typedef HashMap<String, RefPtr<ApplicationCacheResource>> ResourceMap;
-    ResourceMap::const_iterator begin() const { return m_resources.begin(); }
-    ResourceMap::const_iterator end() const { return m_resources.end(); }
+    const ResourceMap& resources() const { return m_resources; }
     
     void setStorageID(unsigned storageID) { m_storageID = storageID; }
     unsigned storageID() const { return m_storageID; }
index 4d7fc09..c6a23f2 100644 (file)
@@ -765,7 +765,7 @@ void ApplicationCacheGroup::didFinishLoadingManifest()
     ASSERT(m_pendingEntries.isEmpty());
 
     if (isUpgradeAttempt) {
-        for (const auto& urlAndResource : *m_newestCache) {
+        for (const auto& urlAndResource : m_newestCache->resources()) {
             unsigned type = urlAndResource.value->type();
             if (type & ApplicationCacheResource::Master)
                 addEntry(urlAndResource.key, type);
index 9910679..fec923d 100644 (file)
@@ -286,15 +286,17 @@ void ApplicationCacheHost::fillResourceList(ResourceInfoList* resources)
     ApplicationCache* cache = applicationCache();
     if (!cache || !cache->isComplete())
         return;
-    
-    for (const auto& urlAndResource : *cache) {
-        RefPtr<ApplicationCacheResource> resource = urlAndResource.value;
+
+    for (const auto& urlAndResource : cache->resources()) {
+        ApplicationCacheResource* resource = urlAndResource.value.get();
+
         unsigned type = resource->type();
-        bool isMaster   = type & ApplicationCacheResource::Master;
+        bool isMaster = type & ApplicationCacheResource::Master;
         bool isManifest = type & ApplicationCacheResource::Manifest;
         bool isExplicit = type & ApplicationCacheResource::Explicit;
-        bool isForeign  = type & ApplicationCacheResource::Foreign;
+        bool isForeign = type & ApplicationCacheResource::Foreign;
         bool isFallback = type & ApplicationCacheResource::Fallback;
+
         resources->append(ResourceInfo(resource->url(), isMaster, isManifest, isFallback, isForeign, isExplicit, resource->estimatedSizeInStorage()));
     }
 }
index 982a342..4e71c2e 100644 (file)
@@ -275,10 +275,7 @@ ApplicationCacheGroup* ApplicationCacheStorage::fallbackCacheGroupForURL(const U
     ASSERT(!url.hasFragmentIdentifier());
 
     // Check if an appropriate cache already exists in memory.
-    CacheGroupMap::const_iterator end = m_cachesInMemory.end();
-    for (CacheGroupMap::const_iterator it = m_cachesInMemory.begin(); it != end; ++it) {
-        ApplicationCacheGroup* group = it->value;
-        
+    for (auto group : m_cachesInMemory.values()) {
         ASSERT(!group->isObsolete());
 
         if (ApplicationCache* cache = group->newestCache()) {
@@ -741,17 +738,14 @@ bool ApplicationCacheStorage::store(ApplicationCache* cache, ResourceStorageIDJo
     unsigned cacheStorageID = static_cast<unsigned>(m_database.lastInsertRowID());
 
     // Store all resources
-    {
-        ApplicationCache::ResourceMap::const_iterator end = cache->end();
-        for (ApplicationCache::ResourceMap::const_iterator it = cache->begin(); it != end; ++it) {
-            unsigned oldStorageID = it->value->storageID();
-            if (!store(it->value.get(), cacheStorageID))
-                return false;
+    for (auto& resource : cache->resources().values()) {
+        unsigned oldStorageID = resource->storageID();
+        if (!store(resource.get(), cacheStorageID))
+            return false;
 
-            // Storing the resource succeeded. Log its old storageID in case
-            // it needs to be restored later.
-            storageIDJournal->add(it->value.get(), oldStorageID);
-        }
+        // Storing the resource succeeded. Log its old storageID in case
+        // it needs to be restored later.
+        storageIDJournal->add(resource.get(), oldStorageID);
     }
     
     // Store the online whitelist
@@ -1293,10 +1287,9 @@ void ApplicationCacheStorage::empty()
     // Clear the storage IDs for the caches in memory.
     // The caches will still work, but cached resources will not be saved to disk 
     // until a cache update process has been initiated.
-    CacheGroupMap::const_iterator end = m_cachesInMemory.end();
-    for (CacheGroupMap::const_iterator it = m_cachesInMemory.begin(); it != end; ++it)
-        it->value->clearStorageID();
-    
+    for (auto group : m_cachesInMemory.values())
+        group->clearStorageID();
+
     checkForDeletedResources();
 }
     
@@ -1357,10 +1350,7 @@ bool ApplicationCacheStorage::storeCopyOfCache(const String& cacheDirectory, App
     cacheCopy->setFallbackURLs(cache->fallbackURLs());
 
     // Traverse the cache and add copies of all resources.
-    ApplicationCache::ResourceMap::const_iterator end = cache->end();
-    for (ApplicationCache::ResourceMap::const_iterator it = cache->begin(); it != end; ++it) {
-        ApplicationCacheResource* resource = it->value.get();
-        
+    for (auto& resource : cache->resources().values()) {
         RefPtr<ApplicationCacheResource> resourceCopy = ApplicationCacheResource::create(resource->url(), resource->response(), resource->type(), resource->data(), resource->path());
         
         cacheCopy->addResource(resourceCopy.release());
index d37f1b8..64d2b08 100644 (file)
@@ -237,7 +237,7 @@ PassRefPtr<LegacyWebArchive> LegacyWebArchive::create()
     return adoptRef(new LegacyWebArchive);
 }
 
-PassRefPtr<LegacyWebArchive> LegacyWebArchive::create(PassRefPtr<ArchiveResource> mainResource, Vector<PassRefPtr<ArchiveResource>>& subresources, Vector<PassRefPtr<LegacyWebArchive>>& subframeArchives)
+PassRefPtr<LegacyWebArchive> LegacyWebArchive::create(PassRefPtr<ArchiveResource> mainResource, Vector<RefPtr<ArchiveResource>> subresources, Vector<RefPtr<LegacyWebArchive>> subframeArchives)
 {
     ASSERT(mainResource);
     if (!mainResource)
@@ -247,10 +247,10 @@ PassRefPtr<LegacyWebArchive> LegacyWebArchive::create(PassRefPtr<ArchiveResource
     archive->setMainResource(mainResource);
     
     for (unsigned i = 0; i < subresources.size(); ++i)
-        archive->addSubresource(subresources[i]);
+        archive->addSubresource(std::move(subresources[i]));
     
     for (unsigned i = 0; i < subframeArchives.size(); ++i)
-        archive->addSubframeArchive(subframeArchives[i]);  
+        archive->addSubframeArchive(std::move(subframeArchives[i]));
         
     return archive.release();
 }
@@ -461,19 +461,15 @@ PassRefPtr<LegacyWebArchive> LegacyWebArchive::create(Frame* frame)
     if (!documentLoader)
         return 0;
         
-    Vector<PassRefPtr<LegacyWebArchive>> subframeArchives;
+    Vector<RefPtr<LegacyWebArchive>> subframeArchives;
     
-    unsigned children = frame->tree().childCount();
-    for (unsigned i = 0; i < children; ++i) {
-        RefPtr<LegacyWebArchive> childFrameArchive = create(frame->tree().child(i));
-        if (childFrameArchive)
-            subframeArchives.append(childFrameArchive.release());
+    for (unsigned i = 0; i < frame->tree().childCount(); ++i) {
+        if (RefPtr<LegacyWebArchive> childFrameArchive = create(frame->tree().child(i)))
+            subframeArchives.append(std::move(childFrameArchive));
     }
 
-    Vector<PassRefPtr<ArchiveResource>> subresources;
-    documentLoader->getSubresources(subresources);
-
-    return create(documentLoader->mainResource(), subresources, subframeArchives);
+    auto subresources = documentLoader->subresources();
+    return create(documentLoader->mainResource(), std::move(subresources), std::move(subframeArchives));
 }
 
 PassRefPtr<LegacyWebArchive> LegacyWebArchive::create(Range* range)
@@ -512,8 +508,8 @@ PassRefPtr<LegacyWebArchive> LegacyWebArchive::create(const String& markupString
         
     RefPtr<ArchiveResource> mainResource = ArchiveResource::create(utf8Buffer(markupString), responseURL, response.mimeType(), "UTF-8", frame->tree().uniqueName());
 
-    Vector<PassRefPtr<LegacyWebArchive>> subframeArchives;
-    Vector<PassRefPtr<ArchiveResource>> subresources;
+    Vector<RefPtr<LegacyWebArchive>> subframeArchives;
+    Vector<RefPtr<ArchiveResource>> subresources;
     HashSet<URL> uniqueSubresources;
 
     size_t nodesSize = nodes.size();    
@@ -525,28 +521,25 @@ PassRefPtr<LegacyWebArchive> LegacyWebArchive::create(const String& markupString
             if (frameFilter && !frameFilter(*childFrame))
                 continue;
                 
-            RefPtr<LegacyWebArchive> subframeArchive = create(childFrame->document(), frameFilter);
-            
-            if (subframeArchive)
-                subframeArchives.append(subframeArchive);
+            if (RefPtr<LegacyWebArchive> subframeArchive = create(childFrame->document(), frameFilter))
+                subframeArchives.append(std::move(subframeArchive));
             else
                 LOG_ERROR("Unabled to archive subframe %s", childFrame->tree().uniqueName().string().utf8().data());
+
         } else {
             ListHashSet<URL> subresourceURLs;
             node.getSubresourceURLs(subresourceURLs);
             
             DocumentLoader* documentLoader = frame->loader().documentLoader();
-            ListHashSet<URL>::iterator iterEnd = subresourceURLs.end();
-            for (ListHashSet<URL>::iterator iter = subresourceURLs.begin(); iter != iterEnd; ++iter) {
-                const URL& subresourceURL = *iter;
+
+            for (const auto& subresourceURL : subresourceURLs) {
                 if (uniqueSubresources.contains(subresourceURL))
                     continue;
 
                 uniqueSubresources.add(subresourceURL);
 
-                RefPtr<ArchiveResource> resource = documentLoader->subresource(subresourceURL);
-                if (resource) {
-                    subresources.append(resource.release());
+                if (RefPtr<ArchiveResource> resource = documentLoader->subresource(subresourceURL)) {
+                    subresources.append(std::move(resource));
                     continue;
                 }
 
@@ -557,9 +550,9 @@ PassRefPtr<LegacyWebArchive> LegacyWebArchive::create(const String& markupString
                 CachedResource* cachedResource = memoryCache()->resourceForRequest(request, frame->page()->sessionID());
                 if (cachedResource) {
                     ResourceBuffer* data = cachedResource->resourceBuffer();
-                    resource = ArchiveResource::create(data ? data->sharedBuffer() : 0, subresourceURL, cachedResource->response());
-                    if (resource) {
-                        subresources.append(resource.release());
+
+                    if (RefPtr<ArchiveResource> resource = ArchiveResource::create(data ? data->sharedBuffer() : 0, subresourceURL, cachedResource->response())) {
+                        subresources.append(std::move(resource));
                         continue;
                     }
                 }
@@ -581,7 +574,7 @@ PassRefPtr<LegacyWebArchive> LegacyWebArchive::create(const String& markupString
         }
     }
 
-    return create(mainResource.release(), subresources, subframeArchives);
+    return create(mainResource.release(), subresources, std::move(subframeArchives));
 }
 
 PassRefPtr<LegacyWebArchive> LegacyWebArchive::createFromSelection(Frame* frame)
@@ -612,14 +605,7 @@ PassRefPtr<LegacyWebArchive> LegacyWebArchive::createFromSelection(Frame* frame)
     String iframeMarkup = "<iframe frameborder=\"no\" marginwidth=\"0\" marginheight=\"0\" width=\"98%%\" height=\"98%%\" src=\"" + frame->loader().documentLoader()->response().url().string() + "\"></iframe>";
     RefPtr<ArchiveResource> iframeResource = ArchiveResource::create(utf8Buffer(iframeMarkup), blankURL(), "text/html", "UTF-8", String());
 
-    Vector<PassRefPtr<ArchiveResource>> subresources;
-
-    Vector<PassRefPtr<LegacyWebArchive>> subframeArchives;
-    subframeArchives.append(archive);
-    
-    archive = create(iframeResource.release(), subresources, subframeArchives);
-    
-    return archive.release();
+    return create(iframeResource.release(), Vector<RefPtr<ArchiveResource>> { }, Vector<RefPtr<LegacyWebArchive>> { archive });
 }
 
 }
index 40cdf31..f47c4f9 100644 (file)
@@ -43,7 +43,7 @@ public:
     static PassRefPtr<LegacyWebArchive> create();
     static PassRefPtr<LegacyWebArchive> create(SharedBuffer*);
     static PassRefPtr<LegacyWebArchive> create(const URL&, SharedBuffer*);
-    static PassRefPtr<LegacyWebArchive> create(PassRefPtr<ArchiveResource> mainResource, Vector<PassRefPtr<ArchiveResource>>& subresources, Vector<PassRefPtr<LegacyWebArchive>>& subframeArchives);
+    static PassRefPtr<LegacyWebArchive> create(PassRefPtr<ArchiveResource> mainResource, Vector<RefPtr<ArchiveResource>> subresources, Vector<RefPtr<LegacyWebArchive>> subframeArchives);
     static PassRefPtr<LegacyWebArchive> create(Node*, std::function<bool (Frame&)> frameFilter = nullptr);
     static PassRefPtr<LegacyWebArchive> create(Frame*);
     static PassRefPtr<LegacyWebArchive> createFromSelection(Frame*);
index 615e515..4a4ef05 100644 (file)
@@ -140,16 +140,13 @@ void XMLHttpRequestProgressEventThrottle::dispatchDeferredEvents(Timer<XMLHttpRe
     m_deferEvents = false;
 
     // Take over the deferred events before dispatching them which can potentially add more.
-    Vector<RefPtr<Event>> deferredEvents;
-    m_deferredEvents.swap(deferredEvents);
+    auto deferredEvents = std::move(m_deferredEvents);
 
     RefPtr<Event> deferredProgressEvent = m_deferredProgressEvent;
-    m_deferredProgressEvent = 0;
+    m_deferredProgressEvent = nullptr;
 
-    Vector<RefPtr<Event>>::const_iterator it = deferredEvents.begin();
-    const Vector<RefPtr<Event>>::const_iterator end = deferredEvents.end();
-    for (; it != end; ++it)
-        dispatchEvent(*it);
+    for (auto& deferredEvent : deferredEvents)
+        dispatchEvent(deferredEvent.release());
 
     // The progress event will be in the m_deferredEvents vector if the load was finished while suspended.
     // If not, just send the most up-to-date progress on resume.
index b57a159..1880109 100644 (file)
@@ -1,3 +1,15 @@
+2014-06-18  Anders Carlsson  <andersca@apple.com>
+
+        Adopt modern C++11 loops and fix WebArchive creation functions
+        https://bugs.webkit.org/show_bug.cgi?id=134032
+
+        Reviewed by Andreas Kling.
+
+        * WebView/WebArchive.mm:
+        (-[WebArchive initWithMainResource:subresources:subframeArchives:]):
+        * WebView/WebDataSource.mm:
+        (-[WebDataSource subresources]):
+
 2014-06-15  Anders Carlsson  <andersca@apple.com>
 
         Add an autorelease() member function to RetainPtr
index 77ea2c7..2ff0880 100644 (file)
@@ -178,24 +178,22 @@ static BOOL isArrayOfClass(id object, Class elementClass)
     
     RefPtr<ArchiveResource> coreMainResource = mainResource ? [mainResource _coreResource] : 0;
 
-    Vector<PassRefPtr<ArchiveResource>> coreResources;
-    NSEnumerator *enumerator = [subresources objectEnumerator];
-    WebResource *subresource;
-    while ((subresource = [enumerator nextObject]) != nil)
+    Vector<RefPtr<ArchiveResource>> coreResources;
+    for (WebResource *subresource in subresources)
         coreResources.append([subresource _coreResource]);
 
-    Vector<PassRefPtr<LegacyWebArchive>> coreArchives;
-    enumerator = [subframeArchives objectEnumerator];
-    WebArchive *subframeArchive;
-    while ((subframeArchive = [enumerator nextObject]) != nil)
+    Vector<RefPtr<LegacyWebArchive>> coreArchives;
+    for (WebArchive *subframeArchive in subframeArchives)
         coreArchives.append([subframeArchive->_private coreArchive]);
 
-    [_private setCoreArchive:LegacyWebArchive::create(coreMainResource.release(), coreResources, coreArchives)];
-    if (![_private coreArchive]) {
+    RefPtr<LegacyWebArchive> coreArchive = LegacyWebArchive::create(coreMainResource.release(), std::move(coreResources), std::move(coreArchives));
+    if (!coreArchive) {
         [self release];
         return nil;
     }
 
+    [_private setCoreArchive:coreArchive.release()];
+
     return self;
 }
 
index 391d3b5..2d6b367 100644 (file)
@@ -606,19 +606,15 @@ static inline void addTypesFromClass(NSMutableDictionary *allTypes, Class objCCl
 
 - (NSArray *)subresources
 {
-    Vector<PassRefPtr<ArchiveResource>> coreSubresources;
-    toPrivate(_private)->loader->getSubresources(coreSubresources);
-
-    NSMutableArray *subresources = [[NSMutableArray alloc] initWithCapacity:coreSubresources.size()];
-    for (unsigned i = 0; i < coreSubresources.size(); ++i) {
-        WebResource *resource = [[WebResource alloc] _initWithCoreResource:coreSubresources[i]];
-        if (resource) {
-            [subresources addObject:resource];
-            [resource release];
-        }
+    auto coreSubresources = toPrivate(_private)->loader->subresources();
+
+    auto subresources = adoptNS([[NSMutableArray alloc] initWithCapacity:coreSubresources.size()]);
+    for (const auto& coreSubresource : coreSubresources) {
+        if (auto resource = adoptNS([[WebResource alloc] _initWithCoreResource:coreSubresource]))
+            [subresources addObject:resource.get()];
     }
 
-    return [subresources autorelease];
+    return subresources.autorelease();
 }
 
 - (WebResource *)subresourceForURL:(NSURL *)URL
index 65db160..a568e51 100644 (file)
@@ -1,5 +1,15 @@
 2014-06-18  Anders Carlsson  <andersca@apple.com>
 
+        Adopt modern C++11 loops and fix WebArchive creation functions
+        https://bugs.webkit.org/show_bug.cgi?id=134032
+
+        Reviewed by Andreas Kling.
+
+        * Shared/APIWebArchive.cpp:
+        (API::WebArchive::WebArchive):
+
+2014-06-18  Anders Carlsson  <andersca@apple.com>
+
         Give WKWebView on iOS a mobile user agent
         https://bugs.webkit.org/show_bug.cgi?id=134034
         <rdar://problem/17346489>
index dc79fa5..8674746 100644 (file)
@@ -65,21 +65,24 @@ WebArchive::WebArchive(WebArchiveResource* mainResource, PassRefPtr<API::Array>
 {
     RefPtr<ArchiveResource> coreMainResource = m_cachedMainResource->coreArchiveResource();
 
-    Vector<PassRefPtr<ArchiveResource>> coreArchiveResources;
+    Vector<RefPtr<ArchiveResource>> coreArchiveResources;
+    coreArchiveResources.reserveInitialCapacity(m_cachedSubresources->size());
     for (size_t i = 0; i < m_cachedSubresources->size(); ++i) {
         RefPtr<WebArchiveResource> resource = m_cachedSubresources->at<WebArchiveResource>(i);
         ASSERT(resource);
-        coreArchiveResources.append(resource->coreArchiveResource());
+        coreArchiveResources.uncheckedAppend(resource->coreArchiveResource());
     }
 
-    Vector<PassRefPtr<LegacyWebArchive>> coreSubframeLegacyWebArchives;
+    Vector<RefPtr<LegacyWebArchive>> coreSubframeLegacyWebArchives;
+    coreSubframeLegacyWebArchives.reserveInitialCapacity(m_cachedSubframeArchives->size());
+
     for (size_t i = 0; i < m_cachedSubframeArchives->size(); ++i) {
         RefPtr<WebArchive> subframeWebArchive = m_cachedSubframeArchives->at<WebArchive>(i);
         ASSERT(subframeWebArchive);
-        coreSubframeLegacyWebArchives.append(subframeWebArchive->coreLegacyWebArchive());
+        coreSubframeLegacyWebArchives.uncheckedAppend(subframeWebArchive->coreLegacyWebArchive());
     }
 
-    m_legacyWebArchive = LegacyWebArchive::create(coreMainResource.release(), coreArchiveResources, coreSubframeLegacyWebArchives);
+    m_legacyWebArchive = LegacyWebArchive::create(coreMainResource.release(), std::move(coreArchiveResources), std::move(coreSubframeLegacyWebArchives));
 }
 
 WebArchive::WebArchive(API::Data* data)