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_USE_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_USE_CF, WTF_USE_JSC, and
31 // WTF_USE_CFNETWORK manually, but we need a better long-term solution.
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/InspectorFrontendClientLocal.h>
61 #include <WebCore/Page.h>
62 #include <WebCore/PlatformString.h>
64 #include <wtf/PassOwnPtr.h>
65 #include <wtf/RetainPtr.h>
66 #include <wtf/Vector.h>
68 using namespace WebCore;
70 static const char* inspectorStartsAttachedSetting = "inspectorStartsAttached";
72 static inline CFStringRef createKeyForPreferences(const String& key)
74 RetainPtr<CFStringRef> keyCFString(AdoptCF, key.createCFString());
75 return CFStringCreateWithFormat(0, 0, CFSTR("WebKit Web Inspector Setting - %@"), keyCFString.get());
78 static void populateSetting(const String& key, String* setting)
80 RetainPtr<CFStringRef> preferencesKey(AdoptCF, createKeyForPreferences(key));
81 RetainPtr<CFPropertyListRef> value(AdoptCF, CFPreferencesCopyAppValue(preferencesKey.get(), kCFPreferencesCurrentApplication));
86 CFTypeID type = CFGetTypeID(value.get());
87 if (type == CFStringGetTypeID())
88 *setting = static_cast<String>(static_cast<CFStringRef>(value.get()));
89 else if (type == CFBooleanGetTypeID())
90 *setting = static_cast<bool>(CFBooleanGetValue(static_cast<CFBooleanRef>(value.get()))) ? "true" : "false";
95 static void storeSetting(const String& key, const String& setting)
97 RetainPtr<CFPropertyListRef> objectToStore;
98 objectToStore.adoptCF(setting.createCFString());
99 ASSERT(objectToStore);
101 RetainPtr<CFStringRef> preferencesKey(AdoptCF, createKeyForPreferences(key));
102 CFPreferencesSetAppValue(preferencesKey.get(), objectToStore.get(), kCFPreferencesCurrentApplication);
105 bool WebInspectorClient::sendMessageToFrontend(const String& message)
107 return doDispatchMessageOnFrontendPage(m_frontendPage, message);
110 bool WebInspectorClient::inspectorStartsAttached()
113 populateSetting(inspectorStartsAttachedSetting, &value);
116 return value == "true";
119 void WebInspectorClient::setInspectorStartsAttached(bool attached)
121 storeSetting(inspectorStartsAttachedSetting, attached ? "true" : "false");
124 void WebInspectorClient::releaseFrontendPage()
129 WTF::PassOwnPtr<WebCore::InspectorFrontendClientLocal::Settings> WebInspectorClient::createFrontendSettings()
131 class InspectorFrontendSettingsCF : public WebCore::InspectorFrontendClientLocal::Settings {
133 virtual ~InspectorFrontendSettingsCF() { }
134 virtual String getProperty(const String& name)
137 populateSetting(name, &value);
141 virtual void setProperty(const String& name, const String& value)
143 storeSetting(name, value);
146 return adoptPtr<WebCore::InspectorFrontendClientLocal::Settings>(new InspectorFrontendSettingsCF());