Skip to content
Permalink
Browse files
2010-10-27 Pavel Podivilov <podivilov@chromium.org>
        Reviewed by Pavel Feldman.

        Web Inspector: move frontend settings to local storage
        https://bugs.webkit.org/show_bug.cgi?id=47715

        * inspector/Inspector.idl:
        * inspector/InspectorController.cpp:
        (WebCore::InspectorController::InspectorController):
        (WebCore::InspectorController::didCommitLoad):
        * inspector/InspectorController.h:
        * inspector/InspectorState.cpp:
        (WebCore::InspectorState::InspectorState):
        * inspector/InspectorState.h:
        * inspector/front-end/ConsoleView.js:
        * inspector/front-end/EventListenersSidebarPane.js:
        * inspector/front-end/NetworkPanel.js:
        (WebInspector.NetworkPanel.prototype._createStatusbarButtons):
        * inspector/front-end/Panel.js:
        (WebInspector.Panel):
        * inspector/front-end/ResourcesPanel.js:
        (WebInspector.ResourcesPanel.prototype._createStatusbarButtons):
        * inspector/front-end/Settings.js:
        (WebInspector.Settings):
        (WebInspector.Settings.prototype.installApplicationSetting):
        (WebInspector.Settings.prototype.installProjectSetting):
        (WebInspector.Settings.prototype._get):
        (WebInspector.Settings.prototype._set):
        (WebInspector.Settings.prototype._getProjectSetting):
        (WebInspector.Settings.prototype._setProjectSetting):
        (WebInspector.Settings.prototype._formatProjectKey):
        * inspector/front-end/StylesSidebarPane.js:
        * inspector/front-end/WatchExpressionsSidebarPane.js:
        (WebInspector.WatchExpressionsSidebarPane):
        (WebInspector.WatchExpressionsSidebarPane.prototype.reset):
        * inspector/front-end/inspector.js:
        (WebInspector.reset):

Canonical link: https://commits.webkit.org/61145@main
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@70622 268f45cc-cd09-0410-ab3c-d52691b4dbfc
  • Loading branch information
Pavel Podivilov committed Oct 27, 2010
1 parent 09fdae6 commit 0cd76dc3720b647ce0f43bbd8819787468bdebcc
Showing 15 changed files with 109 additions and 157 deletions.
@@ -1,3 +1,42 @@
2010-10-27 Pavel Podivilov <podivilov@chromium.org>

Reviewed by Pavel Feldman.

Web Inspector: move frontend settings to local storage
https://bugs.webkit.org/show_bug.cgi?id=47715

* inspector/Inspector.idl:
* inspector/InspectorController.cpp:
(WebCore::InspectorController::InspectorController):
(WebCore::InspectorController::didCommitLoad):
* inspector/InspectorController.h:
* inspector/InspectorState.cpp:
(WebCore::InspectorState::InspectorState):
* inspector/InspectorState.h:
* inspector/front-end/ConsoleView.js:
* inspector/front-end/EventListenersSidebarPane.js:
* inspector/front-end/NetworkPanel.js:
(WebInspector.NetworkPanel.prototype._createStatusbarButtons):
* inspector/front-end/Panel.js:
(WebInspector.Panel):
* inspector/front-end/ResourcesPanel.js:
(WebInspector.ResourcesPanel.prototype._createStatusbarButtons):
* inspector/front-end/Settings.js:
(WebInspector.Settings):
(WebInspector.Settings.prototype.installApplicationSetting):
(WebInspector.Settings.prototype.installProjectSetting):
(WebInspector.Settings.prototype._get):
(WebInspector.Settings.prototype._set):
(WebInspector.Settings.prototype._getProjectSetting):
(WebInspector.Settings.prototype._setProjectSetting):
(WebInspector.Settings.prototype._formatProjectKey):
* inspector/front-end/StylesSidebarPane.js:
* inspector/front-end/WatchExpressionsSidebarPane.js:
(WebInspector.WatchExpressionsSidebarPane):
(WebInspector.WatchExpressionsSidebarPane.prototype.reset):
* inspector/front-end/inspector.js:
(WebInspector.reset):

2010-10-27 Andy Estes <aestes@apple.com>

Reviewed by David Hyatt.
@@ -94,13 +94,9 @@ module core {
// This method is going to be broken down into smaller parts.
[handler=Controller] void populateScriptObjects();

[handler=Controller] void getSettings(out Object settings);
[handler=Controller] void getInspectorState(out Object state);
[handler=Controller] void storeLastActivePanel(in String panelName);

[handler=Controller] void saveApplicationSettings(in String settings);
[handler=Controller] void saveSessionSettings(in String settings);

[handler=Controller] void setSearchingForNode(in boolean enabled, out boolean newState);

[handler=Controller] void setMonitoringXHREnabled(in boolean enable, out boolean newState);
@@ -144,7 +144,6 @@ InspectorController::InspectorController(Page* page, InspectorClient* client)
, m_domContentEventTime(-1.0)
, m_expiredConsoleMessageCount(0)
, m_showAfterVisible(LastActivePanel)
, m_sessionSettings(InspectorObject::create())
, m_groupLevel(0)
, m_previousMessage(0)
, m_settingsLoaded(false)
@@ -231,16 +230,6 @@ bool InspectorController::resourceTrackingEnabled() const
return m_state->getBoolean(InspectorState::resourceTrackingEnabled);
}

void InspectorController::saveApplicationSettings(const String& settings)
{
m_state->setString(InspectorState::frontendSettings, settings);
}

void InspectorController::saveSessionSettings(const String& settingsJSON)
{
m_sessionSettings = InspectorValue::parseJSON(settingsJSON);
}

void InspectorController::getInspectorState(RefPtr<InspectorObject>* state)
{
#if ENABLE(JAVASCRIPT_DEBUGGER)
@@ -257,13 +246,6 @@ void InspectorController::restoreInspectorStateFromCookie(const String& inspecto
startTimelineProfiler();
}

void InspectorController::getSettings(RefPtr<InspectorObject>* settings)
{
*settings = InspectorObject::create();
(*settings)->setString("application", m_state->getString(InspectorState::frontendSettings));
(*settings)->setString("session", m_sessionSettings->toJSONString());
}

void InspectorController::inspect(Node* node)
{
if (!enabled())
@@ -785,7 +767,6 @@ void InspectorController::didCommitLoad(DocumentLoader* loader)
unbindAllResources();

m_cssStore->reset();
m_sessionSettings = InspectorObject::create();
if (m_frontend) {
m_frontend->reset();
m_domAgent->reset();
@@ -124,10 +124,6 @@ class InspectorController : public Noncopyable {
Page* inspectedPage() const { return m_inspectedPage; }
void reloadPage();

void saveApplicationSettings(const String& settings);
void saveSessionSettings(const String&);
void getSettings(RefPtr<InspectorObject>*);

void restoreInspectorStateFromCookie(const String& inspectorCookie);

void inspect(Node*);
@@ -374,9 +370,6 @@ class InspectorController : public Noncopyable {
#endif
String m_showAfterVisible;
RefPtr<Node> m_highlightedNode;
#if ENABLE(INSPECTOR)
RefPtr<InspectorValue> m_sessionSettings;
#endif
unsigned m_groupLevel;
ConsoleMessage* m_previousMessage;
bool m_settingsLoaded;
@@ -45,7 +45,6 @@ InspectorState::InspectorState(InspectorClient* client)
registerBoolean(timelineProfilerEnabled, false, "timelineProfilerEnabled", (const char*)0);
registerBoolean(searchingForNode, false, "searchingForNodeEnabled", (const char*)0);
registerBoolean(profilerAlwaysEnabled, false, (const char*)0, "profilerEnabled");
registerString(frontendSettings, "", (const char*)0, "frontendSettings");
registerBoolean(debuggerAlwaysEnabled, false, (const char*)0, "debuggerEnabled");
registerString(lastActivePanel, InspectorController::LastActivePanel, (const char*)0, "lastActivePanel");
registerBoolean(inspectorStartsAttached, true, (const char*)0, "InspectorStartsAttached");
@@ -50,7 +50,6 @@ class InspectorState {
timelineProfilerEnabled,
searchingForNode,
profilerAlwaysEnabled,
frontendSettings,
debuggerAlwaysEnabled,
lastActivePanel,
inspectorStartsAttached,
@@ -48,7 +48,7 @@ WebInspector.ConsoleView = function(drawer)
this.promptElement.className = "source-code";
this.promptElement.addEventListener("keydown", this._promptKeyDown.bind(this), true);
this.prompt = new WebInspector.TextPrompt(this.promptElement, this.completions.bind(this), ExpressionStopCharacters + ".");
WebInspector.applicationSettings.addEventListener("loaded", this._settingsLoaded, this);
this.prompt.history = WebInspector.applicationSettings.consoleHistory;

this.topGroup = new WebInspector.ConsoleGroup(null, 0);
this.messagesElement.insertBefore(this.topGroup.element, this.promptElement);
@@ -102,11 +102,6 @@ WebInspector.ConsoleView = function(drawer)
}

WebInspector.ConsoleView.prototype = {
_settingsLoaded: function()
{
this.prompt.history = WebInspector.applicationSettings.consoleHistory;
},

_updateFilter: function(e)
{
var isMac = WebInspector.isMac();
@@ -46,23 +46,18 @@ WebInspector.EventListenersSidebarPane = function()
option.label = WebInspector.UIString("Selected Node Only");
this.settingsSelectElement.appendChild(option);

WebInspector.applicationSettings.addEventListener("loaded", this._settingsLoaded, this);
var filter = WebInspector.applicationSettings.eventListenersFilter;
if (filter === "all")
this.settingsSelectElement[0].selected = true;
else if (filter === "selected")
this.settingsSelectElement[1].selected = true;
this.settingsSelectElement.addEventListener("click", function(event) { event.stopPropagation() }, false);
this.settingsSelectElement.addEventListener("change", this._changeSetting.bind(this), false);

this.titleElement.appendChild(this.settingsSelectElement);
}

WebInspector.EventListenersSidebarPane.prototype = {
_settingsLoaded: function()
{
var filter = WebInspector.applicationSettings.eventListenersFilter;
if (filter === "all")
this.settingsSelectElement[0].selected = true;
if (filter === "selected")
this.settingsSelectElement[1].selected = true;
},

update: function(node)
{
var body = this.bodyElement;
@@ -611,15 +611,10 @@ WebInspector.NetworkPanel.prototype = {
this._clearButton.addEventListener("click", this._reset.bind(this), false);

this._largerResourcesButton = new WebInspector.StatusBarButton(WebInspector.UIString("Use small resource rows."), "network-larger-resources-status-bar-item");
WebInspector.applicationSettings.addEventListener("loaded", this._settingsLoaded, this);
this._largerResourcesButton.addEventListener("click", this._toggleLargerResources.bind(this), false);
},

_settingsLoaded: function()
{
this._largerResourcesButton.toggled = WebInspector.applicationSettings.resourcesLargeRows;
if (!WebInspector.applicationSettings.resourcesLargeRows)
this._setLargerResources(WebInspector.applicationSettings.resourcesLargeRows);
this._largerResourcesButton.addEventListener("click", this._toggleLargerResources.bind(this), false);
},

set mainResourceLoadTime(x)
@@ -34,7 +34,7 @@ WebInspector.Panel = function(name)
this.element.addStyleClass(name);
this._panelName = name;

WebInspector.applicationSettings.installSetting(this._sidebarWidthSettingName(), this._panelName + "-sidebar-width", undefined);
WebInspector.applicationSettings.installApplicationSetting(this._sidebarWidthSettingName(), undefined);
}

// Should by in sync with style declarations.
@@ -446,19 +446,15 @@ WebInspector.ResourcesPanel.prototype = {
{
this.largerResourcesButton = new WebInspector.StatusBarButton(WebInspector.UIString("Use small resource rows."), "resources-larger-resources-status-bar-item");

WebInspector.applicationSettings.addEventListener("loaded", this._settingsLoaded, this);
this.largerResourcesButton.addEventListener("click", this._toggleLargerResources.bind(this), false);
this.sortingSelectElement = document.createElement("select");
this.sortingSelectElement.className = "status-bar-item";
this.sortingSelectElement.addEventListener("change", this._changeSortingFunction.bind(this), false);
},

_settingsLoaded: function()
{
this.largerResourcesButton.toggled = WebInspector.applicationSettings.resourcesLargeRows;
if (!WebInspector.applicationSettings.resourcesLargeRows)
this._setLargerResources(WebInspector.applicationSettings.resourcesLargeRows);
this._loadSortOptions();

this.largerResourcesButton.addEventListener("click", this._toggleLargerResources.bind(this), false);
this.sortingSelectElement = document.createElement("select");
this.sortingSelectElement.className = "status-bar-item";
this.sortingSelectElement.addEventListener("change", this._changeSortingFunction.bind(this), false);
},

_loadSortOptions: function()
@@ -49,93 +49,69 @@ var Preferences = {
useDataURLForResourceImageIcons: true
}

WebInspector.Settings = function(sessionScope)
WebInspector.Settings = function()
{
this._sessionScope = sessionScope;
this._store = {};
}
this.installApplicationSetting("colorFormat", "hex");
this.installApplicationSetting("consoleHistory", []);
this.installApplicationSetting("eventListenersFilter", "all");
this.installApplicationSetting("lastViewedScriptFile", "application");
this.installApplicationSetting("resourcesLargeRows", true);
this.installApplicationSetting("resourcesSortOptions", {timeOption: "responseTime", sizeOption: "transferSize"});
this.installApplicationSetting("resourceViewTab", "content");
this.installApplicationSetting("showInheritedComputedStyleProperties", false);
this.installApplicationSetting("showUserAgentStyles", true);
this.installApplicationSetting("watchExpressions", []);

WebInspector.Settings.initialize = function()
{
WebInspector.applicationSettings = new WebInspector.Settings(false);
WebInspector.sessionSettings = new WebInspector.Settings(true);
this.installProjectSetting("breakpoints", {});
}

function populateApplicationSettings(settingsString)
WebInspector.Settings.prototype = {
installApplicationSetting: function(key, defaultValue)
{
WebInspector.applicationSettings._load(settingsString);
WebInspector.applicationSettings.installSetting("eventListenersFilter", "event-listeners-filter", "all");
WebInspector.applicationSettings.installSetting("colorFormat", "color-format", "hex");
WebInspector.applicationSettings.installSetting("resourcesLargeRows", "resources-large-rows", true);
WebInspector.applicationSettings.installSetting("watchExpressions", "watch-expressions", []);
WebInspector.applicationSettings.installSetting("lastViewedScriptFile", "last-viewed-script-file");
WebInspector.applicationSettings.installSetting("showInheritedComputedStyleProperties", "show-inherited-computed-style-properties", false);
WebInspector.applicationSettings.installSetting("showUserAgentStyles", "show-user-agent-styles", true);
WebInspector.applicationSettings.installSetting("resourceViewTab", "resource-view-tab", "content");
WebInspector.applicationSettings.installSetting("consoleHistory", "console-history", []);
WebInspector.applicationSettings.installSetting("resourcesSortOptions", "resources-sort-options", {timeOption: "responseTime", sizeOption: "transferSize"});

WebInspector.applicationSettings.dispatchEventToListeners("loaded");
}
this.__defineGetter__(key, this._get.bind(this, key, defaultValue));
this.__defineSetter__(key, this._set.bind(this, key));
},

function populateSessionSettings(settingsString)
installProjectSetting: function(key, defaultValue)
{
WebInspector.sessionSettings._load(settingsString);
WebInspector.sessionSettings.dispatchEventToListeners("loaded");
}

InspectorBackend.getSettings(function(settings) {
populateApplicationSettings(settings.application);
populateSessionSettings(settings.session);
});
}
this.__defineGetter__(key, this._getProjectSetting.bind(this, key, defaultValue));
this.__defineSetter__(key, this._setProjectSetting.bind(this, key));
},

WebInspector.Settings.prototype = {
reset: function()
_get: function(key, defaultValue)
{
this._store = {};
// FIXME: restore default values (bug 42820)
this.dispatchEventToListeners("loaded");
if (key in window.localStorage) {
try {
return JSON.parse(window.localStorage[key]);
} catch(e) {
window.localStorage.removeItem(key);
}
}
return defaultValue;
},

_load: function(settingsString)
_set: function(key, value)
{
try {
var loadedStore = JSON.parse(settingsString);
} catch (e) {
// May fail;
loadedStore = {};
}
if (!loadedStore)
return;
for (var propertyName in loadedStore)
this._store[propertyName] = loadedStore[propertyName];
window.localStorage[key] = JSON.stringify(value);
},

installSetting: function(name, propertyName, defaultValue)
_getProjectSetting: function(key, defaultValue)
{
this.__defineGetter__(name, this._get.bind(this, propertyName));
this.__defineSetter__(name, this._set.bind(this, propertyName));
if (!(propertyName in this._store))
this._store[propertyName] = defaultValue;
return this._get(this._formatProjectKey(key), defaultValue);
},

_get: function(propertyName)
_setProjectSetting: function(key, value)
{
return this._store[propertyName];
return this._set(this._formatProjectKey(key), value);
},

_set: function(propertyName, newValue)
_formatProjectKey: function(key)
{
this._store[propertyName] = newValue;
try {
var store = JSON.stringify(this._store);
if (this._sessionScope)
InspectorBackend.saveSessionSettings(store);
else
InspectorBackend.saveApplicationSettings(store);
} catch (e) {
// May fail;
}
var url = this._mainResourceURL;
var fragmentIndex = url.indexOf("#");
if (fragmentIndex !== -1)
url = url.substring(0, fragmentIndex);
return key + "." + url;
}
}

0 comments on commit 0cd76dc

Please sign in to comment.