Changeset 70622 in webkit


Ignore:
Timestamp:
Oct 27, 2010 1:52:13 AM (14 years ago)
Author:
podivilov@chromium.org
Message:

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):
Location:
trunk/WebCore
Files:
15 edited

Legend:

Unmodified
Added
Removed
  • trunk/WebCore/ChangeLog

    r70619 r70622  
     12010-10-27  Pavel Podivilov  <podivilov@chromium.org>
     2
     3        Reviewed by Pavel Feldman.
     4
     5        Web Inspector: move frontend settings to local storage
     6        https://bugs.webkit.org/show_bug.cgi?id=47715
     7
     8        * inspector/Inspector.idl:
     9        * inspector/InspectorController.cpp:
     10        (WebCore::InspectorController::InspectorController):
     11        (WebCore::InspectorController::didCommitLoad):
     12        * inspector/InspectorController.h:
     13        * inspector/InspectorState.cpp:
     14        (WebCore::InspectorState::InspectorState):
     15        * inspector/InspectorState.h:
     16        * inspector/front-end/ConsoleView.js:
     17        * inspector/front-end/EventListenersSidebarPane.js:
     18        * inspector/front-end/NetworkPanel.js:
     19        (WebInspector.NetworkPanel.prototype._createStatusbarButtons):
     20        * inspector/front-end/Panel.js:
     21        (WebInspector.Panel):
     22        * inspector/front-end/ResourcesPanel.js:
     23        (WebInspector.ResourcesPanel.prototype._createStatusbarButtons):
     24        * inspector/front-end/Settings.js:
     25        (WebInspector.Settings):
     26        (WebInspector.Settings.prototype.installApplicationSetting):
     27        (WebInspector.Settings.prototype.installProjectSetting):
     28        (WebInspector.Settings.prototype._get):
     29        (WebInspector.Settings.prototype._set):
     30        (WebInspector.Settings.prototype._getProjectSetting):
     31        (WebInspector.Settings.prototype._setProjectSetting):
     32        (WebInspector.Settings.prototype._formatProjectKey):
     33        * inspector/front-end/StylesSidebarPane.js:
     34        * inspector/front-end/WatchExpressionsSidebarPane.js:
     35        (WebInspector.WatchExpressionsSidebarPane):
     36        (WebInspector.WatchExpressionsSidebarPane.prototype.reset):
     37        * inspector/front-end/inspector.js:
     38        (WebInspector.reset):
     39
    1402010-10-27  Andy Estes  <aestes@apple.com>
    241
  • trunk/WebCore/inspector/Inspector.idl

    r70519 r70622  
    9595        [handler=Controller] void populateScriptObjects();
    9696
    97         [handler=Controller] void getSettings(out Object settings);
    9897        [handler=Controller] void getInspectorState(out Object state);
    9998        [handler=Controller] void storeLastActivePanel(in String panelName);
    100 
    101         [handler=Controller] void saveApplicationSettings(in String settings);
    102         [handler=Controller] void saveSessionSettings(in String settings);
    10399
    104100        [handler=Controller] void setSearchingForNode(in boolean enabled, out boolean newState);
  • trunk/WebCore/inspector/InspectorController.cpp

    r70566 r70622  
    145145    , m_expiredConsoleMessageCount(0)
    146146    , m_showAfterVisible(LastActivePanel)
    147     , m_sessionSettings(InspectorObject::create())
    148147    , m_groupLevel(0)
    149148    , m_previousMessage(0)
     
    232231}
    233232
    234 void InspectorController::saveApplicationSettings(const String& settings)
    235 {
    236     m_state->setString(InspectorState::frontendSettings, settings);
    237 }
    238 
    239 void InspectorController::saveSessionSettings(const String& settingsJSON)
    240 {
    241     m_sessionSettings = InspectorValue::parseJSON(settingsJSON);
    242 }
    243 
    244233void InspectorController::getInspectorState(RefPtr<InspectorObject>* state)
    245234{
     
    256245    if (m_state->getBoolean(InspectorState::timelineProfilerEnabled))
    257246        startTimelineProfiler();
    258 }
    259 
    260 void InspectorController::getSettings(RefPtr<InspectorObject>* settings)
    261 {
    262     *settings = InspectorObject::create();
    263     (*settings)->setString("application", m_state->getString(InspectorState::frontendSettings));
    264     (*settings)->setString("session", m_sessionSettings->toJSONString());
    265247}
    266248
     
    786768
    787769        m_cssStore->reset();
    788         m_sessionSettings = InspectorObject::create();
    789770        if (m_frontend) {
    790771            m_frontend->reset();
  • trunk/WebCore/inspector/InspectorController.h

    r70300 r70622  
    125125    void reloadPage();
    126126
    127     void saveApplicationSettings(const String& settings);
    128     void saveSessionSettings(const String&);
    129     void getSettings(RefPtr<InspectorObject>*);
    130 
    131127    void restoreInspectorStateFromCookie(const String& inspectorCookie);
    132128
     
    375371    String m_showAfterVisible;
    376372    RefPtr<Node> m_highlightedNode;
    377 #if ENABLE(INSPECTOR)
    378     RefPtr<InspectorValue> m_sessionSettings;
    379 #endif
    380373    unsigned m_groupLevel;
    381374    ConsoleMessage* m_previousMessage;
  • trunk/WebCore/inspector/InspectorState.cpp

    r69956 r70622  
    4646    registerBoolean(searchingForNode, false, "searchingForNodeEnabled", (const char*)0);
    4747    registerBoolean(profilerAlwaysEnabled, false, (const char*)0, "profilerEnabled");
    48     registerString(frontendSettings, "", (const char*)0, "frontendSettings");
    4948    registerBoolean(debuggerAlwaysEnabled, false, (const char*)0, "debuggerEnabled");
    5049    registerString(lastActivePanel, InspectorController::LastActivePanel, (const char*)0, "lastActivePanel");
  • trunk/WebCore/inspector/InspectorState.h

    r69916 r70622  
    5151        searchingForNode,
    5252        profilerAlwaysEnabled,
    53         frontendSettings,
    5453        debuggerAlwaysEnabled,
    5554        lastActivePanel,
  • trunk/WebCore/inspector/front-end/ConsoleView.js

    r70532 r70622  
    4949    this.promptElement.addEventListener("keydown", this._promptKeyDown.bind(this), true);
    5050    this.prompt = new WebInspector.TextPrompt(this.promptElement, this.completions.bind(this), ExpressionStopCharacters + ".");
    51     WebInspector.applicationSettings.addEventListener("loaded", this._settingsLoaded, this);
     51    this.prompt.history = WebInspector.applicationSettings.consoleHistory;
    5252
    5353    this.topGroup = new WebInspector.ConsoleGroup(null, 0);
     
    103103
    104104WebInspector.ConsoleView.prototype = {
    105     _settingsLoaded: function()
    106     {
    107         this.prompt.history = WebInspector.applicationSettings.consoleHistory;
    108     },
    109    
    110105    _updateFilter: function(e)
    111106    {
  • trunk/WebCore/inspector/front-end/EventListenersSidebarPane.js

    r69203 r70622  
    4747    this.settingsSelectElement.appendChild(option);
    4848
    49     WebInspector.applicationSettings.addEventListener("loaded", this._settingsLoaded, this);
     49    var filter = WebInspector.applicationSettings.eventListenersFilter;
     50    if (filter === "all")
     51        this.settingsSelectElement[0].selected = true;
     52    else if (filter === "selected")
     53        this.settingsSelectElement[1].selected = true;
    5054    this.settingsSelectElement.addEventListener("click", function(event) { event.stopPropagation() }, false);
    5155    this.settingsSelectElement.addEventListener("change", this._changeSetting.bind(this), false);
     
    5559
    5660WebInspector.EventListenersSidebarPane.prototype = {
    57     _settingsLoaded: function()
    58     {
    59         var filter = WebInspector.applicationSettings.eventListenersFilter;
    60         if (filter === "all")
    61             this.settingsSelectElement[0].selected = true;
    62         if (filter === "selected")
    63             this.settingsSelectElement[1].selected = true;
    64     },
    65 
    6661    update: function(node)
    6762    {
  • trunk/WebCore/inspector/front-end/NetworkPanel.js

    r70532 r70622  
    612612
    613613        this._largerResourcesButton = new WebInspector.StatusBarButton(WebInspector.UIString("Use small resource rows."), "network-larger-resources-status-bar-item");
    614         WebInspector.applicationSettings.addEventListener("loaded", this._settingsLoaded, this);
    615         this._largerResourcesButton.addEventListener("click", this._toggleLargerResources.bind(this), false);
    616     },
    617 
    618     _settingsLoaded: function()
    619     {
    620614        this._largerResourcesButton.toggled = WebInspector.applicationSettings.resourcesLargeRows;
    621615        if (!WebInspector.applicationSettings.resourcesLargeRows)
    622616            this._setLargerResources(WebInspector.applicationSettings.resourcesLargeRows);
     617        this._largerResourcesButton.addEventListener("click", this._toggleLargerResources.bind(this), false);
    623618    },
    624619
  • trunk/WebCore/inspector/front-end/Panel.js

    r66601 r70622  
    3535    this._panelName = name;
    3636
    37     WebInspector.applicationSettings.installSetting(this._sidebarWidthSettingName(), this._panelName + "-sidebar-width", undefined);
     37    WebInspector.applicationSettings.installApplicationSetting(this._sidebarWidthSettingName(), undefined);
    3838}
    3939
  • trunk/WebCore/inspector/front-end/ResourcesPanel.js

    r70532 r70622  
    447447        this.largerResourcesButton = new WebInspector.StatusBarButton(WebInspector.UIString("Use small resource rows."), "resources-larger-resources-status-bar-item");
    448448
    449         WebInspector.applicationSettings.addEventListener("loaded", this._settingsLoaded, this);
     449        this.largerResourcesButton.toggled = WebInspector.applicationSettings.resourcesLargeRows;
     450        if (!WebInspector.applicationSettings.resourcesLargeRows)
     451            this._setLargerResources(WebInspector.applicationSettings.resourcesLargeRows);
     452        this._loadSortOptions();
     453
    450454        this.largerResourcesButton.addEventListener("click", this._toggleLargerResources.bind(this), false);
    451455        this.sortingSelectElement = document.createElement("select");
    452456        this.sortingSelectElement.className = "status-bar-item";
    453457        this.sortingSelectElement.addEventListener("change", this._changeSortingFunction.bind(this), false);
    454     },
    455 
    456     _settingsLoaded: function()
    457     {
    458         this.largerResourcesButton.toggled = WebInspector.applicationSettings.resourcesLargeRows;
    459         if (!WebInspector.applicationSettings.resourcesLargeRows)
    460             this._setLargerResources(WebInspector.applicationSettings.resourcesLargeRows);
    461         this._loadSortOptions();
    462458    },
    463459
  • trunk/WebCore/inspector/front-end/Settings.js

    r70519 r70622  
    5050}
    5151
    52 WebInspector.Settings = function(sessionScope)
     52WebInspector.Settings = function()
    5353{
    54     this._sessionScope = sessionScope;
    55     this._store = {};
    56 }
     54    this.installApplicationSetting("colorFormat", "hex");
     55    this.installApplicationSetting("consoleHistory", []);
     56    this.installApplicationSetting("eventListenersFilter", "all");
     57    this.installApplicationSetting("lastViewedScriptFile", "application");
     58    this.installApplicationSetting("resourcesLargeRows", true);
     59    this.installApplicationSetting("resourcesSortOptions", {timeOption: "responseTime", sizeOption: "transferSize"});
     60    this.installApplicationSetting("resourceViewTab", "content");
     61    this.installApplicationSetting("showInheritedComputedStyleProperties", false);
     62    this.installApplicationSetting("showUserAgentStyles", true);
     63    this.installApplicationSetting("watchExpressions", []);
    5764
    58 WebInspector.Settings.initialize = function()
    59 {
    60     WebInspector.applicationSettings = new WebInspector.Settings(false);
    61     WebInspector.sessionSettings = new WebInspector.Settings(true);
    62 
    63     function populateApplicationSettings(settingsString)
    64     {
    65         WebInspector.applicationSettings._load(settingsString);
    66         WebInspector.applicationSettings.installSetting("eventListenersFilter", "event-listeners-filter", "all");
    67         WebInspector.applicationSettings.installSetting("colorFormat", "color-format", "hex");
    68         WebInspector.applicationSettings.installSetting("resourcesLargeRows", "resources-large-rows", true);
    69         WebInspector.applicationSettings.installSetting("watchExpressions", "watch-expressions", []);
    70         WebInspector.applicationSettings.installSetting("lastViewedScriptFile", "last-viewed-script-file");
    71         WebInspector.applicationSettings.installSetting("showInheritedComputedStyleProperties", "show-inherited-computed-style-properties", false);
    72         WebInspector.applicationSettings.installSetting("showUserAgentStyles", "show-user-agent-styles", true);
    73         WebInspector.applicationSettings.installSetting("resourceViewTab", "resource-view-tab", "content");
    74         WebInspector.applicationSettings.installSetting("consoleHistory", "console-history", []);
    75         WebInspector.applicationSettings.installSetting("resourcesSortOptions", "resources-sort-options", {timeOption: "responseTime", sizeOption: "transferSize"});
    76 
    77         WebInspector.applicationSettings.dispatchEventToListeners("loaded");
    78     }
    79 
    80     function populateSessionSettings(settingsString)
    81     {
    82         WebInspector.sessionSettings._load(settingsString);
    83         WebInspector.sessionSettings.dispatchEventToListeners("loaded");
    84     }
    85 
    86     InspectorBackend.getSettings(function(settings) {
    87         populateApplicationSettings(settings.application);
    88         populateSessionSettings(settings.session);
    89     });
     65    this.installProjectSetting("breakpoints", {});
    9066}
    9167
    9268WebInspector.Settings.prototype = {
    93     reset: function()
     69    installApplicationSetting: function(key, defaultValue)
    9470    {
    95         this._store = {};
    96         // FIXME: restore default values (bug 42820)
    97         this.dispatchEventToListeners("loaded");
     71        this.__defineGetter__(key, this._get.bind(this, key, defaultValue));
     72        this.__defineSetter__(key, this._set.bind(this, key));
    9873    },
    9974
    100     _load: function(settingsString)
     75    installProjectSetting: function(key, defaultValue)
    10176    {
    102         try {
    103             var loadedStore = JSON.parse(settingsString);
    104         } catch (e) {
    105             // May fail;
    106             loadedStore = {};
    107         }
    108         if (!loadedStore)
    109             return;
    110         for (var propertyName in loadedStore)
    111             this._store[propertyName] = loadedStore[propertyName];
     77        this.__defineGetter__(key, this._getProjectSetting.bind(this, key, defaultValue));
     78        this.__defineSetter__(key, this._setProjectSetting.bind(this, key));
    11279    },
    11380
    114     installSetting: function(name, propertyName, defaultValue)
     81    _get: function(key, defaultValue)
    11582    {
    116         this.__defineGetter__(name, this._get.bind(this, propertyName));
    117         this.__defineSetter__(name, this._set.bind(this, propertyName));
    118         if (!(propertyName in this._store))
    119             this._store[propertyName] = defaultValue;
     83        if (key in window.localStorage) {
     84            try {
     85                return JSON.parse(window.localStorage[key]);
     86            } catch(e) {
     87                window.localStorage.removeItem(key);
     88            }
     89        }
     90        return defaultValue;
    12091    },
    12192
    122     _get: function(propertyName)
     93    _set: function(key, value)
    12394    {
    124         return this._store[propertyName];
     95        window.localStorage[key] = JSON.stringify(value);
    12596    },
    12697
    127     _set: function(propertyName, newValue)
     98    _getProjectSetting: function(key, defaultValue)
    12899    {
    129         this._store[propertyName] = newValue;
    130         try {
    131             var store = JSON.stringify(this._store);
    132             if (this._sessionScope)
    133                 InspectorBackend.saveSessionSettings(store);
    134             else
    135                 InspectorBackend.saveApplicationSettings(store);
    136         } catch (e) {
    137             // May fail;
    138         }
     100        return this._get(this._formatProjectKey(key), defaultValue);
     101    },
     102
     103    _setProjectSetting: function(key, value)
     104    {
     105        return this._set(this._formatProjectKey(key), value);
     106    },
     107
     108    _formatProjectKey: function(key)
     109    {
     110        var url = this._mainResourceURL;
     111        var fragmentIndex = url.indexOf("#");
     112        if (fragmentIndex !== -1)
     113            url = url.substring(0, fragmentIndex);
     114        return key + "." + url;
    139115    }
    140116}
  • trunk/WebCore/inspector/front-end/StylesSidebarPane.js

    r70532 r70622  
    6161    this.settingsSelectElement.addEventListener("click", function(event) { event.stopPropagation() }, false);
    6262    this.settingsSelectElement.addEventListener("change", this._changeSetting.bind(this), false);
    63     WebInspector.applicationSettings.addEventListener("loaded", this._settingsLoaded, this);
     63    var format = WebInspector.applicationSettings.colorFormat;
     64    if (format === "hex")
     65        this.settingsSelectElement[0].selected = true;
     66    else if (format === "rgb")
     67        this.settingsSelectElement[1].selected = true;
     68    else if (format === "hsl")
     69        this.settingsSelectElement[2].selected = true;
    6470
    6571    this.titleElement.appendChild(this.settingsSelectElement);
     
    96102
    97103WebInspector.StylesSidebarPane.prototype = {
    98     _settingsLoaded: function()
    99     {
    100         var format = WebInspector.applicationSettings.colorFormat;
    101         if (format === "hex")
    102             this.settingsSelectElement[0].selected = true;
    103         if (format === "rgb")
    104             this.settingsSelectElement[1].selected = true;
    105         if (format === "hsl")
    106             this.settingsSelectElement[2].selected = true;
    107     },
    108 
    109104    _contextMenuEventFired: function(event)
    110105    {
     
    591586    this.titleElement.appendChild(showInheritedCheckbox.element);
    592587
    593     function settingsLoaded()
    594     {
    595         if (WebInspector.applicationSettings.showInheritedComputedStyleProperties) {
    596             this.bodyElement.addStyleClass("show-inherited");
    597             showInheritedCheckbox.checked = true;
    598         }
     588    if (WebInspector.applicationSettings.showInheritedComputedStyleProperties) {
     589        this.bodyElement.addStyleClass("show-inherited");
     590        showInheritedCheckbox.checked = true;
    599591    }
    600 
    601     WebInspector.applicationSettings.addEventListener("loaded", settingsLoaded.bind(this));
    602592
    603593    function showInheritedToggleFunction(event)
  • trunk/WebCore/inspector/front-end/WatchExpressionsSidebarPane.js

    r65248 r70622  
    3232{
    3333    WebInspector.SidebarPane.call(this, WebInspector.UIString("Watch Expressions"));
    34     WebInspector.applicationSettings.addEventListener("loaded", this._settingsLoaded, this);
     34    this.reset();
    3535}
    3636
    3737WebInspector.WatchExpressionsSidebarPane.prototype = {
    38     _settingsLoaded: function()
     38    reset: function()
    3939    {
    4040        this.bodyElement.removeChildren();
  • trunk/WebCore/inspector/front-end/inspector.js

    r70532 r70622  
    531531
    532532    InspectorFrontendHost.loaded();
    533     WebInspector.Settings.initialize();
    534    
     533    WebInspector.applicationSettings = new WebInspector.Settings();
     534
    535535    this._registerShortcuts();
    536536
     
    15051505            panel.reset();
    15061506    }
    1507 
    1508     this.sessionSettings.reset();
    15091507
    15101508    this.resources = {};
Note: See TracChangeset for help on using the changeset viewer.