1 /* 2 * Copyright (C) 2008 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. ``AS IS'' AND ANY 14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR 17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY 21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 */ 25 26 // FIXME: On Windows, we require all WebKit source files to include config.h 27 // before including any other files. Failing to include config.h will leave 28 // WTF_PLATFORM_CF and WTF_USE_JSC undefined, causing build failures in this 29 // file. But Mac doesn't have a config.h for WebKit, so we can't include the 30 // Windows one here. For now we can just define WTF_PLATFORM_CF and WTF_USE_JSC 31 // manually, but we need a better long-term solution. 32 #ifndef WTF_PLATFORM_CF 33 #define WTF_PLATFORM_CF 1 34 #endif 35 36 #ifndef WTF_USE_JSC 37 #define WTF_USE_JSC 1 38 #endif 39 40 #if defined(WIN32) || defined(_WIN32) 41 #if defined(BUILDING_JavaScriptCore) || defined(BUILDING_WTF) 42 #define JS_EXPORTDATA __declspec(dllexport) 43 #else 44 #define JS_EXPORTDATA __declspec(dllimport) 45 #endif 46 #define JS_EXPORTCLASS JS_EXPORTDATA 47 #else 48 #define JS_EXPORTDATA 49 #define JS_EXPORTCLASS 50 #endif 51 52 #include "WebInspectorClient.h" 53 54 #include <CoreFoundation/CoreFoundation.h> 55 56 #include <WebCore/PlatformString.h> 57 58 #include <wtf/RetainPtr.h> 59 #include <wtf/Vector.h> 60 61 using namespace WebCore; 62 63 static inline CFStringRef createKeyForPreferences(const String& key) 64 { 65 RetainPtr<CFStringRef> keyCFString(AdoptCF, key.createCFString()); 66 return CFStringCreateWithFormat(0, 0, CFSTR("WebKit Web Inspector Setting - %@"), keyCFString.get()); 67 } 68 69 void WebInspectorClient::populateSetting(const String& key, String* setting) 70 { 71 RetainPtr<CFStringRef> preferencesKey(AdoptCF, createKeyForPreferences(key)); 72 RetainPtr<CFPropertyListRef> value(AdoptCF, CFPreferencesCopyAppValue(preferencesKey.get(), kCFPreferencesCurrentApplication)); 73 74 if (!value) 75 return; 76 77 CFTypeID type = CFGetTypeID(value.get()); 78 if (type == CFStringGetTypeID()) 79 *setting = static_cast<String>(static_cast<CFStringRef>(value.get())); 80 else if (type == CFBooleanGetTypeID()) 81 *setting = static_cast<bool>(CFBooleanGetValue(static_cast<CFBooleanRef>(value.get()))) ? "true" : "false"; 82 else 83 *setting = ""; 84 } 85 86 void WebInspectorClient::storeSetting(const String& key, const String& setting) 87 { 88 RetainPtr<CFPropertyListRef> objectToStore; 89 objectToStore.adoptCF(setting.createCFString()); 90 ASSERT(objectToStore); 91 92 RetainPtr<CFStringRef> preferencesKey(AdoptCF, createKeyForPreferences(key)); 93 CFPreferencesSetAppValue(preferencesKey.get(), objectToStore.get(), kCFPreferencesCurrentApplication); 94 } 95