2 * Copyright (C) 2011 Apple Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
14 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
15 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
17 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
18 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
19 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
20 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
21 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
22 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
23 * THE POSSIBILITY OF SUCH DAMAGE.
27 #import "SecItemShimMethods.h"
29 #if !defined(BUILDING_ON_SNOW_LEOPARD)
31 #import "CoreIPCClientRunLoop.h"
32 #import "SecItemRequestData.h"
33 #import "SecItemResponseData.h"
34 #import "WebProcess.h"
35 #import "WebProcessProxyMessages.h"
36 #import "WebProcessShim.h"
37 #import <Security/SecItem.h>
42 // FIXME (https://bugs.webkit.org/show_bug.cgi?id=60975) - Once CoreIPC supports sync messaging from a secondary thread,
43 // we can remove SecItemAPIContext and these 4 main-thread methods, and we can have the shim methods call out directly
44 // from whatever thread they're on.
46 struct SecItemAPIContext {
47 CFDictionaryRef query;
48 CFDictionaryRef attributesToUpdate;
49 CFTypeRef resultObject;
53 static void webSecItemCopyMatchingMainThread(void* voidContext)
55 SecItemAPIContext* context = (SecItemAPIContext*)voidContext;
57 SecItemRequestData requestData(context->query);
58 SecItemResponseData response;
59 if (!WebProcess::shared().connection()->sendSync(Messages::WebProcessProxy::SecItemCopyMatching(requestData), Messages::WebProcessProxy::SecItemCopyMatching::Reply(response), 0)) {
60 context->resultCode = errSecInteractionNotAllowed;
65 context->resultObject = response.resultObject().leakRef();
66 context->resultCode = response.resultCode();
69 static OSStatus webSecItemCopyMatching(CFDictionaryRef query, CFTypeRef* result)
71 SecItemAPIContext context;
72 context.query = query;
74 callOnCoreIPCClientRunLoopAndWait(webSecItemCopyMatchingMainThread, &context);
77 *result = context.resultObject;
78 return context.resultCode;
81 static void webSecItemAddOnMainThread(void* voidContext)
83 SecItemAPIContext* context = (SecItemAPIContext*)voidContext;
85 SecItemRequestData requestData(context->query);
86 SecItemResponseData response;
87 if (!WebProcess::shared().connection()->sendSync(Messages::WebProcessProxy::SecItemAdd(requestData), Messages::WebProcessProxy::SecItemAdd::Reply(response), 0)) {
88 context->resultCode = errSecInteractionNotAllowed;
93 context->resultObject = response.resultObject().leakRef();
94 context->resultCode = response.resultCode();
97 static OSStatus webSecItemAdd(CFDictionaryRef query, CFTypeRef* result)
99 SecItemAPIContext context;
100 context.query = query;
102 callOnCoreIPCClientRunLoopAndWait(webSecItemAddOnMainThread, &context);
105 *result = context.resultObject;
106 return context.resultCode;
109 static void webSecItemUpdateOnMainThread(void* voidContext)
111 SecItemAPIContext* context = (SecItemAPIContext*)voidContext;
113 SecItemRequestData requestData(context->query, context->attributesToUpdate);
114 SecItemResponseData response;
115 if (!WebProcess::shared().connection()->sendSync(Messages::WebProcessProxy::SecItemUpdate(requestData), Messages::WebProcessProxy::SecItemUpdate::Reply(response), 0)) {
116 context->resultCode = errSecInteractionNotAllowed;
117 ASSERT_NOT_REACHED();
121 context->resultCode = response.resultCode();
124 static OSStatus webSecItemUpdate(CFDictionaryRef query, CFDictionaryRef attributesToUpdate)
126 SecItemAPIContext context;
127 context.query = query;
128 context.attributesToUpdate = attributesToUpdate;
130 callOnCoreIPCClientRunLoopAndWait(webSecItemUpdateOnMainThread, &context);
132 return context.resultCode;
135 static void webSecItemDeleteOnMainThread(void* voidContext)
137 SecItemAPIContext* context = (SecItemAPIContext*)voidContext;
139 SecItemRequestData requestData(context->query);
140 SecItemResponseData response;
141 if (!WebProcess::shared().connection()->sendSync(Messages::WebProcessProxy::SecItemDelete(requestData), Messages::WebProcessProxy::SecItemDelete::Reply(response), 0)) {
142 context->resultCode = errSecInteractionNotAllowed;
143 ASSERT_NOT_REACHED();
147 context->resultCode = response.resultCode();
150 static OSStatus webSecItemDelete(CFDictionaryRef query)
152 SecItemAPIContext context;
153 context.query = query;
155 callOnCoreIPCClientRunLoopAndWait(webSecItemDeleteOnMainThread, &context);
157 return context.resultCode;
160 void initializeSecItemShim()
162 const WebProcessSecItemShimCallbacks callbacks = {
163 webSecItemCopyMatching,
169 WebProcessSecItemShimInitializeFunc func = reinterpret_cast<WebProcessSecItemShimInitializeFunc>(dlsym(RTLD_DEFAULT, "WebKitWebProcessSecItemShimInitialize"));
173 } // namespace WebKit
175 #endif // !BUILDING_ON_SNOW_LEOPARD