Commit bb2ed332 authored by andersca@apple.com's avatar andersca@apple.com

Stop using WKArrayCreate internally

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

Reviewed by Andreas Kling.

* UIProcess/API/mac/WKBrowsingContextGroup.mm:
(createWKArray):
(-[WKBrowsingContextGroup addUserStyleSheet:baseURL:whitelistedURLPatterns:blacklistedURLPatterns:mainFrameOnly:]):
(-[WKBrowsingContextGroup addUserScript:baseURL:whitelistedURLPatterns:blacklistedURLPatterns:injectionTime:mainFrameOnly:]):
* WebProcess/InjectedBundle/API/c/WKBundlePage.cpp:
(WKBundlePageCopyContextMenuItems):

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@159133 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent ba4495bf
2013-11-12 Anders Carlsson <andersca@apple.com>
Stop using WKArrayCreate internally
https://bugs.webkit.org/show_bug.cgi?id=124217
Reviewed by Andreas Kling.
* UIProcess/API/mac/WKBrowsingContextGroup.mm:
(createWKArray):
(-[WKBrowsingContextGroup addUserStyleSheet:baseURL:whitelistedURLPatterns:blacklistedURLPatterns:mainFrameOnly:]):
(-[WKBrowsingContextGroup addUserScript:baseURL:whitelistedURLPatterns:blacklistedURLPatterns:injectionTime:mainFrameOnly:]):
* WebProcess/InjectedBundle/API/c/WKBundlePage.cpp:
(WKBundlePageCopyContextMenuItems):
2013-11-12 Csaba Osztrogonác <ossy@webkit.org>
URTBF after r159129, use create() instead of adopt() everywhere.
......
......@@ -27,15 +27,20 @@
#import "WKBrowsingContextGroup.h"
#import "WKBrowsingContextGroupPrivate.h"
#import "ImmutableArray.h"
#import "WKArray.h"
#import "WKPageGroup.h"
#import "WKPreferences.h"
#import "WKRetainPtr.h"
#import "WKSharedAPICast.h"
#import "WKStringCF.h"
#import "WKURL.h"
#import "WKURLCF.h"
#import "WebString.h"
#import <wtf/Vector.h>
using namespace WebKit;
@interface WKBrowsingContextGroupData : NSObject {
@public
WKRetainPtr<WKPageGroupRef> _pageGroupRef;
......@@ -101,22 +106,22 @@
WKPreferencesSetPluginsEnabled(WKPageGroupGetPreferences(self._pageGroupRef), allowsPlugIns);
}
static WKArrayRef createWKArray(NSArray *array)
static WKRetainPtr<WKArrayRef> createWKArray(NSArray *array)
{
NSUInteger count = [array count];
if (count == 0)
return WKArrayRef();
Vector<WKTypeRef> stringVector;
stringVector.reserveInitialCapacity(count);
for (NSUInteger i = 0; i < count; ++i) {
id entry = [array objectAtIndex:i];
if (!count)
return nullptr;
Vector<RefPtr<APIObject>> strings;
strings.reserveInitialCapacity(count);
for (id entry in array) {
if ([entry isKindOfClass:[NSString class]])
stringVector.uncheckedAppend(WKStringCreateWithCFString((CFStringRef)entry));
strings.uncheckedAppend(adoptRef(toImpl(WKStringCreateWithCFString((CFStringRef)entry))));
}
return WKArrayCreateAdoptingValues(stringVector.data(), stringVector.size());
return toAPI(ImmutableArray::create(std::move(strings)).leakRef());
}
-(void)addUserStyleSheet:(NSString *)source baseURL:(NSURL *)baseURL whitelistedURLPatterns:(NSArray *)whitelist blacklistedURLPatterns:(NSArray *)blacklist mainFrameOnly:(BOOL)mainFrameOnly
......@@ -126,8 +131,8 @@ static WKArrayRef createWKArray(NSArray *array)
WKRetainPtr<WKStringRef> wkSource = adoptWK(WKStringCreateWithCFString((CFStringRef)source));
WKRetainPtr<WKURLRef> wkBaseURL = adoptWK(WKURLCreateWithCFURL((CFURLRef)baseURL));
WKRetainPtr<WKArrayRef> wkWhitelist = adoptWK(createWKArray(whitelist));
WKRetainPtr<WKArrayRef> wkBlacklist = adoptWK(createWKArray(blacklist));
auto wkWhitelist = createWKArray(whitelist);
auto wkBlacklist = createWKArray(blacklist);
WKUserContentInjectedFrames injectedFrames = mainFrameOnly ? kWKInjectInTopFrameOnly : kWKInjectInAllFrames;
WKPageGroupAddUserStyleSheet(self._pageGroupRef, wkSource.get(), wkBaseURL.get(), wkWhitelist.get(), wkBlacklist.get(), injectedFrames);
......@@ -145,8 +150,8 @@ static WKArrayRef createWKArray(NSArray *array)
WKRetainPtr<WKStringRef> wkSource = adoptWK(WKStringCreateWithCFString((CFStringRef)source));
WKRetainPtr<WKURLRef> wkBaseURL = adoptWK(WKURLCreateWithCFURL((CFURLRef)baseURL));
WKRetainPtr<WKArrayRef> wkWhitelist = adoptWK(createWKArray(whitelist));
WKRetainPtr<WKArrayRef> wkBlacklist = adoptWK(createWKArray(blacklist));
auto wkWhitelist = createWKArray(whitelist);
auto wkBlacklist = createWKArray(blacklist);
WKUserContentInjectedFrames injectedFrames = mainFrameOnly ? kWKInjectInTopFrameOnly : kWKInjectInAllFrames;
WKPageGroupAddUserScript(self._pageGroupRef, wkSource.get(), wkBaseURL.get(), wkWhitelist.get(), wkBlacklist.get(), injectedFrames, injectionTime);
......
......@@ -169,16 +169,18 @@ WKArrayRef WKBundlePageCopyContextMenuItems(WKBundlePageRef pageRef)
{
#if ENABLE(CONTEXT_MENUS)
WebContextMenu* contextMenu = toImpl(pageRef)->contextMenu();
const Vector<WebContextMenuItemData>& items = contextMenu->items();
size_t arrayLength = items.size();
auto wkItems = std::make_unique<WKTypeRef[]>(arrayLength);
for (size_t i = 0; i < arrayLength; ++i)
wkItems[i] = toAPI(WebContextMenuItem::create(items[i]).leakRef());
auto items = contextMenu->items();
Vector<RefPtr<APIObject>> menuItems;
menuItems.reserveInitialCapacity(items.size());
return WKArrayCreate(wkItems.get(), arrayLength);
for (const auto& item : items)
menuItems.uncheckedAppend(WebContextMenuItem::create(item));
return toAPI(ImmutableArray::create(std::move(menuItems)).leakRef());
#else
return 0;
return nullptr;
#endif
}
......
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