Commit 069c51e4 authored by pfeldman@chromium.org's avatar pfeldman@chromium.org
Browse files

2009-12-03 Pavel Feldman <pfeldman@dhcp-172-28-174-220.spb.corp.google.com>

        Reviewed by Timothy Hatcher.

        Web Inspector: Simplify the settings support in inspector controller.

        https://bugs.webkit.org/show_bug.cgi?id=32076

        Test: inspector/settings-set-get.html

        * WebCore.Inspector.exp:
        * bindings/js/JSInspectorFrontendHostCustom.cpp:
        * bindings/v8/custom/V8InspectorFrontendHostCustom.cpp:
        * inspector/InspectorClient.h:
        * inspector/InspectorController.cpp:
        (WebCore::InspectorController::~InspectorController):
        (WebCore::InspectorController::setting):
        (WebCore::InspectorController::setSetting):
        (WebCore::InspectorController::setWindowVisible):
        (WebCore::InspectorController::attachWindow):
        (WebCore::InspectorController::setAttachedWindowHeight):
        (WebCore::InspectorController::storeLastActivePanel):
        (WebCore::InspectorController::scriptObjectReady):
        (WebCore::InspectorController::showWindow):
        (WebCore::InspectorController::enableResourceTracking):
        (WebCore::InspectorController::disableResourceTracking):
        (WebCore::InspectorController::ensureResourceTrackingSettingsLoaded):
        (WebCore::InspectorController::enableProfiler):
        (WebCore::InspectorController::disableProfiler):
        (WebCore::InspectorController::enableDebuggerFromFrontend):
        (WebCore::InspectorController::disableDebugger):
        * inspector/InspectorController.h:
        * inspector/InspectorFrontendHost.cpp:
        (WebCore::InspectorFrontendHost::setting):
        (WebCore::InspectorFrontendHost::setSetting):
        * inspector/InspectorFrontendHost.h:
        * inspector/InspectorFrontendHost.idl:
        * loader/EmptyClients.h:
        (WebCore::EmptyInspectorClient::populateSetting):
        (WebCore::EmptyInspectorClient::storeSetting):

WebKit/chromium
        * src/InspectorClientImpl.cpp:
        (WebKit::InspectorClientImpl::hiddenPanels):
        (WebKit::InspectorClientImpl::populateSetting):
        (WebKit::InspectorClientImpl::storeSetting):
        (WebKit::InspectorClientImpl::loadSettings):
        (WebKit::InspectorClientImpl::saveSettings):
        * src/InspectorClientImpl.h:

WebKit/cf
        * WebCoreSupport/WebInspectorClientCF.cpp:
        (WebInspectorClient::populateSetting):
        (WebInspectorClient::storeSetting):

WebKit/gtk
        * WebCoreSupport/InspectorClientGtk.cpp:
        (WebKit::InspectorClient::populateSetting):
        (WebKit::InspectorClient::storeSetting):
        * WebCoreSupport/InspectorClientGtk.h:

WebKit/haiku
        * WebCoreSupport/InspectorClientHaiku.cpp:
        (WebCore::InspectorClientHaiku::populateSetting):
        (WebCore::InspectorClientHaiku::storeSetting):
        * WebCoreSupport/InspectorClientHaiku.h:

WebKit/mac
        * WebCoreSupport/WebInspectorClient.h:
        * WebCoreSupport/WebInspectorClient.mm:
        (-[WebInspectorWindowController showWindow:]):
        (-[WebInspectorWindowController attach]):
        (-[WebInspectorWindowController detach]):

WebKit/qt
        * WebCoreSupport/InspectorClientQt.cpp:
        (WebCore::InspectorClientQt::populateSetting):
        (WebCore::InspectorClientQt::storeSetting):
        (WebCore::variantToSetting):
        (WebCore::settingToVariant):
        * WebCoreSupport/InspectorClientQt.h:

WebKit/win
        * WebCoreSupport/WebInspectorClient.cpp:
        (WebInspectorClient::attachWindow):
        (WebInspectorClient::detachWindow):
        (WebInspectorClient::showWindowWithoutNotifications):
        * WebCoreSupport/WebInspectorClient.h:

WebKit/wx
        * WebKitSupport/InspectorClientWx.cpp:
        (WebCore::InspectorClientWx::populateSetting):
        (WebCore::InspectorClientWx::storeSetting):
        * WebKitSupport/InspectorClientWx.h:


git-svn-id: http://svn.webkit.org/repository/webkit/trunk@51631 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent 7fa1e046
2009-12-03 Pavel Feldman <pfeldman@dhcp-172-28-174-220.spb.corp.google.com>
Reviewed by Timothy Hatcher.
Web Inspector: Simplify the settings support in inspector controller.
https://bugs.webkit.org/show_bug.cgi?id=32076
* inspector/settings-set-get-expected.txt: Added.
* inspector/settings-set-get.html: Added.
2009-12-03 Oliver Hunt <oliver@apple.com>
 
Reviewed by Maciej Stachowiak.
Tests front-end settings read/write.
Setting should have 'bar' value, was: 'bar'
Setting should have 'baz' value, was: 'baz'
<html>
<head>
<script src="inspector-test.js"></script>
<script>
function doit()
{
evaluateInWebInspector("frontend_setSetting('foo', 'bar')");
function callback(result)
{
output("Setting should have 'bar' value, was: '" + result + "'");
}
evaluateInWebInspector("frontend_setting('foo')", callback);
evaluateInWebInspector("frontend_setSetting('foo', 'baz')");
function callback2(result)
{
output("Setting should have 'baz' value, was: '" + result + "'");
notifyDone();
}
evaluateInWebInspector("frontend_setting('foo')", callback2);
}
// Frontend functions.
function frontend_setSetting(key, value)
{
InspectorFrontendHost.setSetting(key, value);
}
function frontend_setting(key)
{
return InspectorFrontendHost.setting(key);
}
</script>
</head>
<body onload="onload()">
<p id="test-topic">
Tests front-end settings read/write.
</p>
</body>
</html>
2009-12-03 Pavel Feldman <pfeldman@dhcp-172-28-174-220.spb.corp.google.com>
Reviewed by Timothy Hatcher.
Web Inspector: Simplify the settings support in inspector controller.
https://bugs.webkit.org/show_bug.cgi?id=32076
Test: inspector/settings-set-get.html
* WebCore.Inspector.exp:
* bindings/js/JSInspectorFrontendHostCustom.cpp:
* bindings/v8/custom/V8InspectorFrontendHostCustom.cpp:
* inspector/InspectorClient.h:
* inspector/InspectorController.cpp:
(WebCore::InspectorController::~InspectorController):
(WebCore::InspectorController::setting):
(WebCore::InspectorController::setSetting):
(WebCore::InspectorController::setWindowVisible):
(WebCore::InspectorController::attachWindow):
(WebCore::InspectorController::setAttachedWindowHeight):
(WebCore::InspectorController::storeLastActivePanel):
(WebCore::InspectorController::scriptObjectReady):
(WebCore::InspectorController::showWindow):
(WebCore::InspectorController::enableResourceTracking):
(WebCore::InspectorController::disableResourceTracking):
(WebCore::InspectorController::ensureResourceTrackingSettingsLoaded):
(WebCore::InspectorController::enableProfiler):
(WebCore::InspectorController::disableProfiler):
(WebCore::InspectorController::enableDebuggerFromFrontend):
(WebCore::InspectorController::disableDebugger):
* inspector/InspectorController.h:
* inspector/InspectorFrontendHost.cpp:
(WebCore::InspectorFrontendHost::setting):
(WebCore::InspectorFrontendHost::setSetting):
* inspector/InspectorFrontendHost.h:
* inspector/InspectorFrontendHost.idl:
* loader/EmptyClients.h:
(WebCore::EmptyInspectorClient::populateSetting):
(WebCore::EmptyInspectorClient::storeSetting):
2009-12-03 Ben Murdoch <benm@google.com>
 
Reviewed by Brady Eidson.
__ZN7WebCore19InspectorController10setSettingERKNS_6StringERKNS0_7SettingE
__ZN7WebCore19InspectorController10setSettingERKNS_6StringES3_
__ZN7WebCore19InspectorController12attachWindowEv
__ZN7WebCore19InspectorController12detachWindowEv
__ZN7WebCore19InspectorController14enableDebuggerEv
......
......@@ -89,88 +89,6 @@ JSValue JSInspectorFrontendHost::search(ExecState* exec, const ArgList& args)
return constructArray(exec, result);
}
JSValue JSInspectorFrontendHost::setting(ExecState* exec, const ArgList& args)
{
if (args.size() < 1)
return jsUndefined();
String key = args.at(0).toString(exec);
if (exec->hadException())
return jsUndefined();
InspectorController* ic = impl()->inspectorController();
if (!ic)
return jsUndefined();
const InspectorController::Setting& setting = ic->setting(key);
switch (setting.type()) {
default:
case InspectorController::Setting::NoType:
return jsUndefined();
case InspectorController::Setting::StringType:
return jsString(exec, setting.string());
case InspectorController::Setting::DoubleType:
return jsNumber(exec, setting.doubleValue());
case InspectorController::Setting::IntegerType:
return jsNumber(exec, setting.integerValue());
case InspectorController::Setting::BooleanType:
return jsBoolean(setting.booleanValue());
case InspectorController::Setting::StringVectorType: {
MarkedArgumentBuffer stringsArray;
const Vector<String>& strings = setting.stringVector();
const unsigned length = strings.size();
for (unsigned i = 0; i < length; ++i)
stringsArray.append(jsString(exec, strings[i]));
return constructArray(exec, stringsArray);
}
}
}
JSValue JSInspectorFrontendHost::setSetting(ExecState* exec, const ArgList& args)
{
if (args.size() < 2)
return jsUndefined();
String key = args.at(0).toString(exec);
if (exec->hadException())
return jsUndefined();
InspectorController::Setting setting;
JSValue value = args.at(1);
if (value.isUndefined() || value.isNull()) {
// Do nothing. The setting is already NoType.
ASSERT(setting.type() == InspectorController::Setting::NoType);
} else if (value.isString())
setting.set(value.toString(exec));
else if (value.isNumber())
setting.set(value.toNumber(exec));
else if (value.isBoolean())
setting.set(value.toBoolean(exec));
else {
JSArray* jsArray = asArray(value);
if (!jsArray)
return jsUndefined();
Vector<String> strings;
for (unsigned i = 0; i < jsArray->length(); ++i) {
String item = jsArray->get(exec, i).toString(exec);
if (exec->hadException())
return jsUndefined();
strings.append(item);
}
setting.set(strings);
}
if (exec->hadException())
return jsUndefined();
InspectorController* ic = impl()->inspectorController();
if (ic)
ic->setSetting(key, setting);
return jsUndefined();
}
} // namespace WebCore
#endif // ENABLE(INSPECTOR)
......@@ -84,87 +84,4 @@ CALLBACK_FUNC_DECL(InspectorFrontendHostSearch)
return result;
}
CALLBACK_FUNC_DECL(InspectorFrontendHostSetting)
{
INC_STATS("InspectorFrontendHost.setting()");
if (args.Length() < 1)
return v8::Undefined();
String key = toWebCoreStringWithNullCheck(args[0]);
if (key.isEmpty())
return v8::Undefined();
InspectorFrontendHost* inspectorHost = V8DOMWrapper::convertToNativeObject<InspectorFrontendHost>(V8ClassIndex::INSPECTORFRONTENDHOST, args.Holder());
InspectorController* ic = inspectorHost->inspectorController();
if (!ic)
return v8::Undefined();
const InspectorController::Setting& setting = ic->setting(key);
switch (setting.type()) {
default:
case InspectorController::Setting::NoType:
return v8::Undefined();
case InspectorController::Setting::StringType:
return v8String(setting.string());
case InspectorController::Setting::DoubleType:
return v8::Number::New(setting.doubleValue());
case InspectorController::Setting::IntegerType:
return v8::Number::New(setting.integerValue());
case InspectorController::Setting::BooleanType:
return v8Boolean(setting.booleanValue());
case InspectorController::Setting::StringVectorType: {
const Vector<String>& strings = setting.stringVector();
v8::Local<v8::Array> stringsArray = v8::Array::New(strings.size());
const unsigned length = strings.size();
for (unsigned i = 0; i < length; ++i)
stringsArray->Set(v8::Number::New(i), v8String(strings[i]));
return stringsArray;
}
}
}
CALLBACK_FUNC_DECL(InspectorFrontendHostSetSetting)
{
INC_STATS("InspectorFrontendHost.setSetting()");
if (args.Length() < 2)
return v8::Undefined();
String key = toWebCoreStringWithNullCheck(args[0]);
if (key.isEmpty())
return v8::Undefined();
InspectorController::Setting setting;
v8::Local<v8::Value> value = args[1];
if (value->IsUndefined() || value->IsNull()) {
// Do nothing. The setting is already NoType.
ASSERT(setting.type() == InspectorController::Setting::NoType);
} else if (value->IsString())
setting.set(toWebCoreStringWithNullCheck(value));
else if (value->IsNumber())
setting.set(value->NumberValue());
else if (value->IsBoolean())
setting.set(value->BooleanValue());
else if (value->IsArray()) {
v8::Local<v8::Array> v8Array = v8::Local<v8::Array>::Cast(value);
Vector<String> strings;
for (unsigned i = 0; i < v8Array->Length(); ++i) {
String item = toWebCoreString(v8Array->Get(v8::Integer::New(i)));
if (item.isEmpty())
return v8::Undefined();
strings.append(item);
}
setting.set(strings);
} else
return v8::Undefined();
InspectorFrontendHost* inspectorHost = V8DOMWrapper::convertToNativeObject<InspectorFrontendHost>(V8ClassIndex::INSPECTORFRONTENDHOST, args.Holder());
InspectorController* ic = inspectorHost->inspectorController();
if (ic)
inspectorHost->inspectorController()->setSetting(key, setting);
return v8::Undefined();
}
} // namespace WebCore
......@@ -59,9 +59,8 @@ public:
virtual void inspectedURLChanged(const String& newURL) = 0;
virtual void populateSetting(const String& key, InspectorController::Setting&) = 0;
virtual void storeSetting(const String& key, const InspectorController::Setting&) = 0;
virtual void removeSetting(const String& key) = 0;
virtual void populateSetting(const String& key, String* value) = 0;
virtual void storeSetting(const String& key, const String& value) = 0;
virtual void inspectorWindowObjectCleared() = 0;
};
......
......@@ -121,7 +121,6 @@ static const float minimumAttachedHeight = 250.0f;
static const float maximumAttachedHeightRatio = 0.75f;
static unsigned s_inspectorControllerCount;
static HashMap<String, InspectorController::Setting*>* s_settingCache;
InspectorController::InspectorController(Page* page, InspectorClient* client)
: m_inspectedPage(page)
......@@ -168,12 +167,6 @@ InspectorController::~InspectorController()
ASSERT(s_inspectorControllerCount);
--s_inspectorControllerCount;
if (!s_inspectorControllerCount && s_settingCache) {
deleteAllValues(*s_settingCache);
delete s_settingCache;
s_settingCache = 0;
}
releaseDOMAgent();
m_inspectorBackend->disconnectController();
......@@ -204,46 +197,22 @@ bool InspectorController::enabled() const
return m_inspectedPage->settings()->developerExtrasEnabled();
}
const InspectorController::Setting& InspectorController::setting(const String& key) const
String InspectorController::setting(const String& key) const
{
if (!s_settingCache)
s_settingCache = new HashMap<String, Setting*>;
if (Setting* cachedSetting = s_settingCache->get(key))
return *cachedSetting;
Setting* newSetting = new Setting;
s_settingCache->set(key, newSetting);
m_client->populateSetting(key, *newSetting);
Settings::iterator it = m_settings.find(key);
if (it != m_settings.end())
return it->second;
return *newSetting;
String value;
m_client->populateSetting(key, &value);
m_settings.set(key, value);
return value;
}
void InspectorController::setSetting(const String& key, const Setting& setting)
void InspectorController::setSetting(const String& key, const String& value)
{
if (setting.type() == Setting::NoType) {
if (s_settingCache) {
Setting* cachedSetting = s_settingCache->get(key);
if (cachedSetting) {
s_settingCache->remove(key);
delete cachedSetting;
}
}
m_client->removeSetting(key);
return;
}
if (!s_settingCache)
s_settingCache = new HashMap<String, Setting*>;
if (Setting* cachedSetting = s_settingCache->get(key))
*cachedSetting = setting;
else
s_settingCache->set(key, new Setting(setting));
m_client->storeSetting(key, setting);
m_settings.set(key, value);
m_client->storeSetting(key, value);
}
// Trying to inspect something in a frame with JavaScript disabled would later lead to
......@@ -323,11 +292,8 @@ void InspectorController::setWindowVisible(bool visible, bool attached)
populateScriptObjects();
if (m_showAfterVisible == CurrentPanel) {
Setting lastActivePanelSetting = setting(lastActivePanelSettingName);
if (lastActivePanelSetting.type() == Setting::StringType)
m_showAfterVisible = specialPanelForJSName(lastActivePanelSetting.string());
else
m_showAfterVisible = ElementsPanel;
String lastActivePanelSetting = setting(lastActivePanelSettingName);
m_showAfterVisible = specialPanelForJSName(lastActivePanelSetting);
}
if (m_nodeToFocus)
......@@ -439,8 +405,10 @@ void InspectorController::attachWindow()
m_client->attachWindow();
Setting attachedHeight = setting(inspectorAttachedHeightName);
unsigned preferredHeight = attachedHeight.type() == Setting::IntegerType ? attachedHeight.integerValue() : defaultAttachedHeight;
String attachedHeight = setting(inspectorAttachedHeightName);
bool success = true;
int height = attachedHeight.toInt(&success);
unsigned preferredHeight = success ? height : defaultAttachedHeight;
// We need to constrain the window height here in case the user has resized the inspected page's window so that
// the user's preferred height would be too big to display.
......@@ -470,14 +438,14 @@ void InspectorController::setAttachedWindowHeight(unsigned height)
unsigned totalHeight = m_page->mainFrame()->view()->visibleHeight() + m_inspectedPage->mainFrame()->view()->visibleHeight();
unsigned attachedHeight = constrainedAttachedWindowHeight(height, totalHeight);
setSetting(inspectorAttachedHeightName, Setting(attachedHeight));
setSetting(inspectorAttachedHeightName, String::number(attachedHeight));
m_client->setAttachedWindowHeight(attachedHeight);
}
void InspectorController::storeLastActivePanel(const String& panelName)
{
setSetting(lastActivePanelSettingName, Setting(panelName));
setSetting(lastActivePanelSettingName, panelName);
}
void InspectorController::toggleSearchForNodeInPage()
......@@ -549,11 +517,11 @@ void InspectorController::scriptObjectReady()
setFrontendProxyObject(m_scriptState, webInspectorObj, injectedScriptObj);
#if ENABLE(JAVASCRIPT_DEBUGGER)
Setting debuggerEnabled = setting(debuggerEnabledSettingName);
if (debuggerEnabled.type() == Setting::BooleanType && debuggerEnabled.booleanValue())
String debuggerEnabled = setting(debuggerEnabledSettingName);
if (debuggerEnabled == "true")
enableDebugger();
Setting profilerEnabled = setting(profilerEnabledSettingName);
if (profilerEnabled.type() == Setting::BooleanType && profilerEnabled.booleanValue())
String profilerEnabled = setting(profilerEnabledSettingName);
if (profilerEnabled == "true")
enableProfiler();
#endif
......@@ -645,8 +613,10 @@ void InspectorController::showWindow()
m_client->showWindow();
Setting attachedHeight = setting(inspectorAttachedHeightName);
unsigned preferredHeight = attachedHeight.type() == Setting::IntegerType ? attachedHeight.integerValue() : defaultAttachedHeight;
String attachedHeight = setting(inspectorAttachedHeightName);
bool success = true;
int height = attachedHeight.toInt(&success);
unsigned preferredHeight = success ? height : defaultAttachedHeight;
// This call might not go through (if the window starts out detached), but if the window is initially created attached,
// InspectorController::attachWindow is never called, so we need to make sure to set the attachedWindowHeight.
......@@ -1077,7 +1047,7 @@ void InspectorController::enableResourceTracking(bool always, bool reload)
return;
if (always)
setSetting(resourceTrackingEnabledSettingName, Setting(true));
setSetting(resourceTrackingEnabledSettingName, "true");
if (m_resourceTrackingEnabled)
return;
......@@ -1097,7 +1067,7 @@ void InspectorController::disableResourceTracking(bool always)
return;
if (always)
setSetting(resourceTrackingEnabledSettingName, Setting(false));
setSetting(resourceTrackingEnabledSettingName, "false");
ASSERT(m_inspectedPage);
m_resourceTrackingEnabled = false;
......@@ -1111,8 +1081,8 @@ void InspectorController::ensureResourceTrackingSettingsLoaded()
return;
m_resourceTrackingSettingsLoaded = true;
Setting resourceTracking = setting(resourceTrackingEnabledSettingName);
if (resourceTracking.type() == Setting::BooleanType && resourceTracking.booleanValue())
String resourceTracking = setting(resourceTrackingEnabledSettingName);
if (resourceTracking == "true")
m_resourceTrackingEnabled = true;
}
......@@ -1500,7 +1470,7 @@ void InspectorController::toggleRecordButton(bool isProfiling)
void InspectorController::enableProfiler(bool always, bool skipRecompile)
{
if (always)
setSetting(profilerEnabledSettingName, Setting(true));
setSetting(profilerEnabledSettingName, "true");
if (m_profilerEnabled)
return;
......@@ -1517,7 +1487,7 @@ void InspectorController::enableProfiler(bool always, bool skipRecompile)
void InspectorController::disableProfiler(bool always)
{
if (always)
setSetting(profilerEnabledSettingName, Setting(false));
setSetting(profilerEnabledSettingName, "false");
if (!m_profilerEnabled)
return;
......@@ -1533,7 +1503,7 @@ void InspectorController::disableProfiler(bool always)
void InspectorController::enableDebuggerFromFrontend(bool always)
{
if (always)
setSetting(debuggerEnabledSettingName, Setting(true));
setSetting(debuggerEnabledSettingName, "true");
ASSERT(m_inspectedPage);
......@@ -1566,7 +1536,7 @@ void InspectorController::disableDebugger(bool always)
return;
if (always)
setSetting(debuggerEnabledSettingName, Setting(false));
setSetting(debuggerEnabledSettingName, "false");
ASSERT(m_inspectedPage);
......
......@@ -110,60 +110,6 @@ public:
StoragePanel
} SpecialPanels;
struct Setting {
enum Type {
NoType, StringType, StringVectorType, DoubleType, IntegerType, BooleanType
};
Setting()
: m_type(NoType)
{
}
explicit Setting(bool value)
: m_type(BooleanType)
{
m_simpleContent.m_boolean = value;
}
explicit Setting(unsigned value)
: m_type(IntegerType)
{
m_simpleContent.m_integer = value;
}
explicit Setting(const String& value)
: m_type(StringType)
{
m_string = value;
}
Type type() const { return m_type; }
String string() const { ASSERT(m_type == StringType); return m_string; }
const Vector<String>& stringVector() const { ASSERT(m_type == StringVectorType); return m_stringVector; }
double doubleValue() const { ASSERT(m_type == DoubleType); return m_simpleContent.m_double; }
long integerValue() const { ASSERT(m_type == IntegerType); return m_simpleContent.m_integer; }
bool booleanValue() const { ASSERT(m_type == BooleanType); return m_simpleContent.m_boolean; }
void set(const String& value) { m_type = StringType; m_string = value; }
void set(const Vector<String>& value) { m_type = StringVectorType; m_stringVector = value; }
void set(double value) { m_type = DoubleType; m_simpleContent.m_double = value; }
void set(long value) { m_type = IntegerType; m_simpleContent.m_integer = value; }
void set(bool value) { m_type = BooleanType; m_simpleContent.m_boolean = value; }
private:
Type m_type;
String m_string;
Vector<String> m_stringVector;
union {
double m_double;
long m_integer;
bool m_boolean;
} m_simpleContent;
};
InspectorController(Page*, InspectorClient*);
~InspectorController();
......@@ -178,8 +124,8 @@ public:
Page* inspectedPage() const { return m_inspectedPage; }
const Setting& setting(const String& key) const;
void setSetting(const String& key, const Setting&);
String setting(const String& key) const;
void setSetting(const String& key, const String& value