2 * Copyright (C) 2008 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. ``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.
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, WTF_USE_JSC, and
31 // WTF_USE_CFNETWORK manually, but we need a better long-term solution.
32 #ifndef WTF_PLATFORM_CF
33 #define WTF_PLATFORM_CF 1
40 #if defined(WIN32) || defined(_WIN32)
41 #ifndef WTF_USE_CFNETWORK
42 #define WTF_USE_CFNETWORK 1
44 #if defined(BUILDING_JavaScriptCore) || defined(BUILDING_WTF)
45 #define JS_EXPORTDATA __declspec(dllexport)
47 #define JS_EXPORTDATA __declspec(dllimport)
49 #define JS_EXPORTCLASS JS_EXPORTDATA
52 #define JS_EXPORTCLASS
55 #include "WebInspectorClient.h"
57 #include <CoreFoundation/CoreFoundation.h>
59 #include <WebCore/Frame.h>
60 #include <WebCore/Page.h>
61 #include <WebCore/PlatformString.h>
63 #include <wtf/RetainPtr.h>
64 #include <wtf/Vector.h>
66 using namespace WebCore;
68 static const char* inspectorStartsAttachedSetting = "inspectorStartsAttached";
70 static inline CFStringRef createKeyForPreferences(const String& key)
72 RetainPtr<CFStringRef> keyCFString(AdoptCF, key.createCFString());
73 return CFStringCreateWithFormat(0, 0, CFSTR("WebKit Web Inspector Setting - %@"), keyCFString.get());
76 void WebInspectorClient::populateSetting(const String& key, String* setting)
78 RetainPtr<CFStringRef> preferencesKey(AdoptCF, createKeyForPreferences(key));
79 RetainPtr<CFPropertyListRef> value(AdoptCF, CFPreferencesCopyAppValue(preferencesKey.get(), kCFPreferencesCurrentApplication));
84 CFTypeID type = CFGetTypeID(value.get());
85 if (type == CFStringGetTypeID())
86 *setting = static_cast<String>(static_cast<CFStringRef>(value.get()));
87 else if (type == CFBooleanGetTypeID())
88 *setting = static_cast<bool>(CFBooleanGetValue(static_cast<CFBooleanRef>(value.get()))) ? "true" : "false";
93 void WebInspectorClient::storeSetting(const String& key, const String& setting)
95 RetainPtr<CFPropertyListRef> objectToStore;
96 objectToStore.adoptCF(setting.createCFString());
97 ASSERT(objectToStore);
99 RetainPtr<CFStringRef> preferencesKey(AdoptCF, createKeyForPreferences(key));
100 CFPreferencesSetAppValue(preferencesKey.get(), objectToStore.get(), kCFPreferencesCurrentApplication);
103 bool WebInspectorClient::sendMessageToFrontend(const String& message)
105 return doDispatchMessageOnFrontendPage(m_frontendPage, message);
108 bool WebInspectorClient::inspectorStartsAttached()
111 populateSetting(inspectorStartsAttachedSetting, &value);
114 return value == "true";
117 void WebInspectorClient::setInspectorStartsAttached(bool attached)
119 storeSetting(inspectorStartsAttachedSetting, attached ? "true" : "false");
122 void WebInspectorClient::releaseFrontendPage()