d8484b11929f7810e2eb7f63a89e38c7b9f6009a
[WebKit-https.git] / Source / WebCore / inspector / front-end / Settings.js
1 /*
2  * Copyright (C) 2009 Google Inc. All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions are
6  * met:
7  *
8  *     * Redistributions of source code must retain the above copyright
9  * notice, this list of conditions and the following disclaimer.
10  *     * Redistributions in binary form must reproduce the above
11  * copyright notice, this list of conditions and the following disclaimer
12  * in the documentation and/or other materials provided with the
13  * distribution.
14  *     * Neither the name of Google Inc. nor the names of its
15  * contributors may be used to endorse or promote products derived from
16  * this software without specific prior written permission.
17  *
18  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29  */
30
31
32 var Preferences = {
33     canEditScriptSource: false,
34     maxInlineTextChildLength: 80,
35     minConsoleHeight: 75,
36     minSidebarWidth: 100,
37     minElementsSidebarWidth: 200,
38     minScriptsSidebarWidth: 200,
39     styleRulesExpandedState: {},
40     showMissingLocalizedStrings: false,
41     samplingCPUProfiler: false,
42     showColorNicknames: true,
43     debuggerAlwaysEnabled: false,
44     profilerAlwaysEnabled: false,
45     onlineDetectionEnabled: true,
46     nativeInstrumentationEnabled: false,
47     resourceExportEnabled: false,
48     useDataURLForResourceImageIcons: true,
49     showTimingTab: false,
50     showCookiesTab: false,
51     debugMode: false,
52     heapProfilerPresent: false,
53     detailedHeapProfiles: false
54 }
55
56 WebInspector.Settings = function()
57 {
58     this.installApplicationSetting("colorFormat", "hex");
59     this.installApplicationSetting("consoleHistory", []);
60     this.installApplicationSetting("debuggerEnabled", false);
61     this.installApplicationSetting("domWordWrap", true);
62     this.installApplicationSetting("profilerEnabled", false);
63     this.installApplicationSetting("eventListenersFilter", "all");
64     this.installApplicationSetting("lastActivePanel", "elements");
65     this.installApplicationSetting("lastViewedScriptFile", "application");
66     this.installApplicationSetting("monitoringXHREnabled", false);
67     this.installApplicationSetting("pauseOnExceptionState", WebInspector.ScriptsPanel.PauseOnExceptionsState.DontPauseOnExceptions);
68     this.installApplicationSetting("resourcesLargeRows", true);
69     this.installApplicationSetting("resourcesSortOptions", {timeOption: "responseTime", sizeOption: "transferSize"});
70     this.installApplicationSetting("resourceViewTab", "content");
71     this.installApplicationSetting("showInheritedComputedStyleProperties", false);
72     this.installApplicationSetting("showUserAgentStyles", true);
73     this.installApplicationSetting("watchExpressions", []);
74     this.installApplicationSetting("breakpoints", []);
75
76     this.installProjectSetting("nativeBreakpoints", []);
77 }
78
79 WebInspector.Settings.Events = {
80     ProjectChanged: "project-changed"
81 }
82
83 WebInspector.Settings.prototype = {
84     installApplicationSetting: function(key, defaultValue)
85     {
86         if (key in this)
87             return;
88
89         this.__defineGetter__(key, this._get.bind(this, key, defaultValue));
90         this.__defineSetter__(key, this._set.bind(this, key));
91     },
92
93     installProjectSetting: function(key, defaultValue)
94     {
95         this.__defineGetter__(key, this._getProjectSetting.bind(this, key, defaultValue));
96         this.__defineSetter__(key, this._setProjectSetting.bind(this, key));
97     },
98
99     inspectedURLChanged: function(url)
100     {
101         var fragmentIndex = url.indexOf("#");
102         if (fragmentIndex !== -1)
103             url = url.substring(0, fragmentIndex);
104         this._projectId = url;
105         this.dispatchEventToListeners(WebInspector.Settings.Events.ProjectChanged);
106     },
107
108     get projectId()
109     {
110         return this._projectId;
111     },
112
113     findSettingForAllProjects: function(key)
114     {
115         var result = {};
116         var regexp = "^" + key + ":(.*)";
117         for (var i = 0; i < window.localStorage.length; ++i) {
118             var fullKey =  window.localStorage.key(i);
119             var match = fullKey.match(regexp);
120             if (!match)
121                 continue;
122             try {
123                 result[match[1]] = JSON.parse(window.localStorage[fullKey]);
124             } catch(e) {
125                 window.localStorage.removeItem(fullKey);
126             }
127         }
128         return result;
129     },
130
131     _get: function(key, defaultValue)
132     {
133         if (key in window.localStorage) {
134             try {
135                 return JSON.parse(window.localStorage[key]);
136             } catch(e) {
137                 window.localStorage.removeItem(key);
138             }
139         }
140         return defaultValue;
141     },
142
143     _set: function(key, value)
144     {
145         window.localStorage[key] = JSON.stringify(value);
146     },
147
148     _getProjectSetting: function(key, defaultValue)
149     {
150         return this._get(this._formatProjectKey(key), defaultValue);
151     },
152
153     _setProjectSetting: function(key, value)
154     {
155         return this._set(this._formatProjectKey(key), value);
156     },
157
158     _formatProjectKey: function(key)
159     {
160         return key + ":" + this._projectId;
161     }
162 }
163
164 WebInspector.Settings.prototype.__proto__ = WebInspector.Object.prototype;