Commit 59e56558 authored by andersca@apple.com's avatar andersca@apple.com

Add ImmutableArray::createStringArray

https://bugs.webkit.org/show_bug.cgi?id=124210

Reviewed by Andreas Kling.

Creating an ImmutableArray of WebStrings is a common operation, so add a
helper function to ImmutableArray that does this from a Vector of Strings.

* Shared/ImmutableArray.cpp:
(WebKit::ImmutableArray::createStringArray):
* Shared/ImmutableArray.h:
* Shared/ImmutableDictionary.cpp:
(WebKit::ImmutableDictionary::keys):
* Shared/WebOpenPanelParameters.cpp:
(WebKit::WebOpenPanelParameters::acceptMIMETypes):
(WebKit::WebOpenPanelParameters::selectedFileNames):
* UIProcess/Plugins/WebPluginSiteDataManager.cpp:
(WebKit::WebPluginSiteDataManager::didGetSitesWithData):
* UIProcess/WebCookieManagerProxy.cpp:
(WebKit::WebCookieManagerProxy::didGetHostnamesWithCookies):
* UIProcess/WebMediaCacheManagerProxy.cpp:
(WebKit::WebMediaCacheManagerProxy::didGetHostnamesWithMediaCache):
* WebProcess/InjectedBundle/InjectedBundlePageLoaderClient.cpp:
(WebKit::InjectedBundlePageLoaderClient::featuresUsedInPage):

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@159123 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent 0e4d08bf
2013-11-12 Anders Carlsson <andersca@apple.com>
Add ImmutableArray::createStringArray
https://bugs.webkit.org/show_bug.cgi?id=124210
Reviewed by Andreas Kling.
Creating an ImmutableArray of WebStrings is a common operation, so add a
helper function to ImmutableArray that does this from a Vector of Strings.
* Shared/ImmutableArray.cpp:
(WebKit::ImmutableArray::createStringArray):
* Shared/ImmutableArray.h:
* Shared/ImmutableDictionary.cpp:
(WebKit::ImmutableDictionary::keys):
* Shared/WebOpenPanelParameters.cpp:
(WebKit::WebOpenPanelParameters::acceptMIMETypes):
(WebKit::WebOpenPanelParameters::selectedFileNames):
* UIProcess/Plugins/WebPluginSiteDataManager.cpp:
(WebKit::WebPluginSiteDataManager::didGetSitesWithData):
* UIProcess/WebCookieManagerProxy.cpp:
(WebKit::WebCookieManagerProxy::didGetHostnamesWithCookies):
* UIProcess/WebMediaCacheManagerProxy.cpp:
(WebKit::WebMediaCacheManagerProxy::didGetHostnamesWithMediaCache):
* WebProcess/InjectedBundle/InjectedBundlePageLoaderClient.cpp:
(WebKit::InjectedBundlePageLoaderClient::featuresUsedInPage):
2013-11-12 Csaba Osztrogonác <ossy@webkit.org>
One more URTBF after r159108.
......
......@@ -26,8 +26,21 @@
#include "config.h"
#include "ImmutableArray.h"
#include "WebString.h"
namespace WebKit {
PassRefPtr<ImmutableArray> ImmutableArray::createStringArray(const Vector<String>& strings)
{
Vector<RefPtr<APIObject>> elements;
elements.reserveInitialCapacity(strings.size());
for (const auto& string : strings)
elements.uncheckedAppend(WebString::create(string));
return adopt(elements);
}
ImmutableArray::ImmutableArray()
{
}
......
......@@ -27,6 +27,7 @@
#define ImmutableArray_h
#include "APIObject.h"
#include <wtf/Forward.h>
#include <wtf/PassRefPtr.h>
#include <wtf/Vector.h>
......@@ -55,6 +56,8 @@ public:
return adoptRef(new ImmutableArray(entries));
}
static PassRefPtr<ImmutableArray> createStringArray(const Vector<String>&);
virtual ~ImmutableArray();
template<typename T>
......
......@@ -49,15 +49,13 @@ PassRefPtr<ImmutableArray> ImmutableDictionary::keys() const
if (m_map.isEmpty())
return ImmutableArray::create();
Vector<RefPtr<APIObject>> vector;
vector.reserveInitialCapacity(m_map.size());
Vector<RefPtr<APIObject>> keys;
keys.reserveInitialCapacity(m_map.size());
MapType::const_iterator::Keys it = m_map.begin().keys();
MapType::const_iterator::Keys end = m_map.end().keys();
for (; it != end; ++it)
vector.uncheckedAppend(WebString::create(*it));
for (const auto& key : m_map.keys())
keys.uncheckedAppend(WebString::create(key));
return ImmutableArray::adopt(vector);
return ImmutableArray::adopt(keys);
}
} // namespace WebKit
......@@ -51,13 +51,7 @@ WebOpenPanelParameters::~WebOpenPanelParameters()
PassRefPtr<ImmutableArray> WebOpenPanelParameters::acceptMIMETypes() const
{
Vector<RefPtr<APIObject>> vector;
vector.reserveInitialCapacity(m_settings.acceptMIMETypes.size());
for (const auto& mimeType : m_settings.acceptMIMETypes)
vector.uncheckedAppend(WebString::create(mimeType));
return ImmutableArray::adopt(vector);
return ImmutableArray::createStringArray(m_settings.acceptMIMETypes);
}
#if ENABLE(MEDIA_CAPTURE)
......@@ -68,14 +62,8 @@ String WebOpenPanelParameters::capture() const
#endif
PassRefPtr<ImmutableArray> WebOpenPanelParameters::selectedFileNames() const
{
Vector<RefPtr<APIObject>> vector;
vector.reserveInitialCapacity(m_settings.selectedFiles.size());
for (const auto& selectedFile : m_settings.selectedFiles)
vector.uncheckedAppend(WebString::create(selectedFile));
return ImmutableArray::adopt(vector);
{
return ImmutableArray::createStringArray(m_settings.selectedFiles);
}
} // namespace WebCore
......@@ -165,13 +165,7 @@ void WebPluginSiteDataManager::didGetSitesWithData(const Vector<String>& sites,
return;
}
Vector<RefPtr<APIObject>> sitesArray;
sitesArray.reserveInitialCapacity(sites.size());
for (const auto& site : sites)
sitesArray.uncheckedAppend(WebString::create(site));
callback->performCallbackWithReturnValue(ImmutableArray::adopt(sitesArray).get());
callback->performCallbackWithReturnValue(ImmutableArray::createStringArray(sites).get());
}
void WebPluginSiteDataManager::clearSiteData(ImmutableArray* sites, uint64_t flags, uint64_t maxAgeInSeconds, PassRefPtr<VoidCallback> prpCallback)
......
......@@ -115,13 +115,7 @@ void WebCookieManagerProxy::didGetHostnamesWithCookies(const Vector<String>& hos
return;
}
Vector<RefPtr<APIObject>> hostnameStrings;
hostnameStrings.reserveInitialCapacity(hostnames.size());
for (const auto& hostname : hostnames)
hostnameStrings.uncheckedAppend(WebString::create(hostname));
callback->performCallbackWithReturnValue(ImmutableArray::adopt(hostnameStrings).get());
callback->performCallbackWithReturnValue(ImmutableArray::createStringArray(hostnames).get());
}
void WebCookieManagerProxy::deleteCookiesForHostname(const String& hostname)
......
......@@ -98,13 +98,7 @@ void WebMediaCacheManagerProxy::didGetHostnamesWithMediaCache(const Vector<Strin
return;
}
Vector<RefPtr<APIObject>> hostnamesArray;
hostnamesArray.reserveInitialCapacity(hostnames.size());
for (const auto& hostname : hostnames)
hostnamesArray.uncheckedAppend(WebString::create(hostname));
callback->performCallbackWithReturnValue(ImmutableArray::adopt(hostnamesArray).get());
callback->performCallbackWithReturnValue(ImmutableArray::createStringArray(hostnames).get());
}
void WebMediaCacheManagerProxy::clearCacheForHostname(const String& hostname)
......
......@@ -341,13 +341,7 @@ void InjectedBundlePageLoaderClient::featuresUsedInPage(WebPage* page, const Vec
if (!m_client.featuresUsedInPage)
return;
Vector<RefPtr<APIObject>> featureStrings;
featureStrings.reserveInitialCapacity(features.size());
for (const auto& feature : features)
featureStrings.uncheckedAppend(WebString::create(feature));
return m_client.featuresUsedInPage(toAPI(page), toAPI(ImmutableArray::adopt(featureStrings).get()), m_client.clientInfo);
return m_client.featuresUsedInPage(toAPI(page), toAPI(ImmutableArray::createStringArray(features).get()), m_client.clientInfo);
}
void InjectedBundlePageLoaderClient::willDestroyFrame(WebPage* page, WebFrame* frame)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment