~ubuntu-branches/ubuntu/raring/qtwebkit-source/raring-proposed

« back to all changes in this revision

Viewing changes to Source/WebKit2/WebProcess/mac/WebProcessShim.mm

  • Committer: Package Import Robot
  • Author(s): Jonathan Riddell
  • Date: 2013-02-18 14:24:18 UTC
  • Revision ID: package-import@ubuntu.com-20130218142418-eon0jmjg3nj438uy
Tags: upstream-2.3
ImportĀ upstreamĀ versionĀ 2.3

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright (C) 2011 Apple Inc. All rights reserved.
 
3
 *
 
4
 * Redistribution and use in source and binary forms, with or without
 
5
 * modification, are permitted provided that the following conditions
 
6
 * are met:
 
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.
 
12
 *
 
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.
 
24
 */
 
25
#import "WebProcessShim.h"
 
26
 
 
27
#import <Security/SecItem.h>
 
28
#import <wtf/Platform.h>
 
29
 
 
30
#define DYLD_INTERPOSE(_replacement,_replacee) \
 
31
    __attribute__((used)) static struct{ const void* replacement; const void* replacee; } _interpose_##_replacee \
 
32
    __attribute__ ((section ("__DATA,__interpose"))) = { (const void*)(unsigned long)&_replacement, (const void*)(unsigned long)&_replacee };
 
33
 
 
34
namespace WebKit {
 
35
 
 
36
#if __MAC_OS_X_VERSION_MIN_REQUIRED >= 1070
 
37
 
 
38
extern "C" void WebKitWebProcessSecItemShimInitialize(const WebProcessSecItemShimCallbacks&);
 
39
 
 
40
static WebProcessSecItemShimCallbacks secItemShimCallbacks;
 
41
 
 
42
static OSStatus shimSecItemCopyMatching(CFDictionaryRef query, CFTypeRef* result)
 
43
{
 
44
    return secItemShimCallbacks.secItemCopyMatching(query, result);
 
45
}
 
46
 
 
47
static OSStatus shimSecItemAdd(CFDictionaryRef query, CFTypeRef* result)
 
48
{
 
49
    return secItemShimCallbacks.secItemAdd(query, result);
 
50
}
 
51
 
 
52
static OSStatus shimSecItemUpdate(CFDictionaryRef query, CFDictionaryRef attributesToUpdate)
 
53
{
 
54
    return secItemShimCallbacks.secItemUpdate(query, attributesToUpdate);
 
55
}
 
56
 
 
57
static OSStatus shimSecItemDelete(CFDictionaryRef query)
 
58
{
 
59
    return secItemShimCallbacks.secItemDelete(query);
 
60
}
 
61
 
 
62
DYLD_INTERPOSE(shimSecItemCopyMatching, SecItemCopyMatching)
 
63
DYLD_INTERPOSE(shimSecItemAdd, SecItemAdd)
 
64
DYLD_INTERPOSE(shimSecItemUpdate, SecItemUpdate)
 
65
DYLD_INTERPOSE(shimSecItemDelete, SecItemDelete)
 
66
 
 
67
__attribute__((visibility("default")))
 
68
void WebKitWebProcessSecItemShimInitialize(const WebProcessSecItemShimCallbacks& callbacks)
 
69
{
 
70
    secItemShimCallbacks = callbacks;
 
71
}
 
72
 
 
73
#endif // __MAC_OS_X_VERSION_MIN_REQUIRED >= 1070
 
74
 
 
75
#if __MAC_OS_X_VERSION_MIN_REQUIRED == 1060
 
76
 
 
77
extern "C" void WebKitWebProcessKeychainItemShimInitialize(const WebProcessKeychainItemShimCallbacks&);
 
78
 
 
79
static WebProcessKeychainItemShimCallbacks keychainItemShimCallbacks;
 
80
 
 
81
static OSStatus shimSecKeychainItemCopyContent(SecKeychainItemRef item, SecItemClass* itemClass, SecKeychainAttributeList* attrList, UInt32* length, void** outData)
 
82
{
 
83
    return keychainItemShimCallbacks.secKeychainItemCopyContent(item, itemClass, attrList, length, outData);
 
84
}
 
85
 
 
86
static OSStatus shimSecKeychainItemCreateFromContent(SecItemClass itemClass, SecKeychainAttributeList* attrList, UInt32 length, const void* data, 
 
87
                                                     SecKeychainRef keychainRef, SecAccessRef initialAccess, SecKeychainItemRef *itemRef)
 
88
{
 
89
    // We don't support shimming SecKeychainItemCreateFromContent with Keychain or Access arguments at this time
 
90
    if (keychainRef || initialAccess)
 
91
        return SecKeychainItemCreateFromContent(itemClass, attrList, length, data, keychainRef, initialAccess, itemRef);
 
92
    return keychainItemShimCallbacks.secKeychainItemCreateFromContent(itemClass, attrList, length, data, itemRef);
 
93
}
 
94
 
 
95
static OSStatus shimSecKeychainItemModifyContent(SecKeychainItemRef itemRef, const SecKeychainAttributeList* attrList, UInt32 length, const void* data)
 
96
{
 
97
    return keychainItemShimCallbacks.secKeychainItemModifyContent(itemRef, attrList, length, data);
 
98
}
 
99
 
 
100
static OSStatus shimSecKeychainItemFreeContent(SecKeychainAttributeList* attrList, void* data)
 
101
{    
 
102
    bool attrListHandled = !attrList || keychainItemShimCallbacks.freeAttributeListContent(attrList);
 
103
    bool keychainItemContentHandled = !data || keychainItemShimCallbacks.freeKeychainItemContentData(data);
 
104
    
 
105
    // If both items were handled by the shim handlers, return now.
 
106
    if (attrListHandled && keychainItemContentHandled)
 
107
        return errSecSuccess;
 
108
    
 
109
    // Have the native function handle whichever item wasn't already handled.
 
110
    return SecKeychainItemFreeContent(attrListHandled ? attrList : NULL, keychainItemContentHandled ? data : NULL);
 
111
}
 
112
 
 
113
DYLD_INTERPOSE(shimSecKeychainItemCopyContent, SecKeychainItemCopyContent)
 
114
DYLD_INTERPOSE(shimSecKeychainItemCreateFromContent, SecKeychainItemCreateFromContent)
 
115
DYLD_INTERPOSE(shimSecKeychainItemModifyContent, SecKeychainItemModifyContent)
 
116
DYLD_INTERPOSE(shimSecKeychainItemFreeContent, SecKeychainItemFreeContent)
 
117
 
 
118
__attribute__((visibility("default")))
 
119
void WebKitWebProcessKeychainItemShimInitialize(const WebProcessKeychainItemShimCallbacks& callbacks)
 
120
{
 
121
    keychainItemShimCallbacks = callbacks;
 
122
}
 
123
 
 
124
#endif // __MAC_OS_X_VERSION_MIN_REQUIRED == 1060
 
125
 
 
126
} // namespace WebKit