initial import
[vuplus_webkit] / 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     useDataURLForResourceImageIcons: true,
48     showTimingTab: false,
49     showCookiesTab: false,
50     debugMode: false,
51     heapProfilerPresent: false,
52     detailedHeapProfiles: false,
53     saveAsAvailable: false,
54     useLowerCaseMenuTitlesOnWindows: false,
55     canInspectWorkers: false,
56     canClearCacheAndCookies: false,
57     canDisableCache: false,
58     showNetworkPanelInitiatorColumn: false
59 }
60
61 /**
62  * @constructor
63  */
64 WebInspector.Settings = function()
65 {
66     this._eventSupport = new WebInspector.Object();
67
68     this.colorFormat = this.createSetting("colorFormat", "hex");
69     this.consoleHistory = this.createSetting("consoleHistory", []);
70     this.debuggerEnabled = this.createSetting("debuggerEnabled", false);
71     this.domWordWrap = this.createSetting("domWordWrap", true);
72     this.profilerEnabled = this.createSetting("profilerEnabled", false);
73     this.eventListenersFilter = this.createSetting("eventListenersFilter", "all");
74     this.lastActivePanel = this.createSetting("lastActivePanel", "elements");
75     this.lastViewedScriptFile = this.createSetting("lastViewedScriptFile", "application");
76     this.monitoringXHREnabled = this.createSetting("monitoringXHREnabled", false);
77     this.preserveConsoleLog = this.createSetting("preserveConsoleLog", false);
78     this.resourcesLargeRows = this.createSetting("resourcesLargeRows", true);
79     this.resourcesSortOptions = this.createSetting("resourcesSortOptions", {timeOption: "responseTime", sizeOption: "transferSize"});
80     this.resourceViewTab = this.createSetting("resourceViewTab", "preview");
81     this.showInheritedComputedStyleProperties = this.createSetting("showInheritedComputedStyleProperties", false);
82     this.showUserAgentStyles = this.createSetting("showUserAgentStyles", true);
83     this.watchExpressions = this.createSetting("watchExpressions", []);
84     this.breakpoints = this.createSetting("breakpoints", []);
85     this.eventListenerBreakpoints = this.createSetting("eventListenerBreakpoints", []);
86     this.domBreakpoints = this.createSetting("domBreakpoints", []);
87     this.xhrBreakpoints = this.createSetting("xhrBreakpoints", []);
88     this.workerInspectionEnabled = this.createSetting("workerInspectionEnabled", []);
89     this.cacheDisabled = this.createSetting("cacheDisabled", false);
90     this.showScriptFolders = this.createSetting("showScriptFolders", true);
91
92     // If there are too many breakpoints in a storage, it is likely due to a recent bug that caused
93     // periodical breakpoints duplication leading to inspector slowness.
94     if (window.localStorage.breakpoints && window.localStorage.breakpoints.length > 500000)
95         delete window.localStorage.breakpoints;
96 }
97
98 WebInspector.Settings.prototype = {
99     /**
100      * @return {WebInspector.Setting}
101      */
102     createSetting: function(key, defaultValue)
103     {
104         return new WebInspector.Setting(key, defaultValue, this._eventSupport);
105     }
106 }
107
108 /**
109  * @constructor
110  */
111 WebInspector.Setting = function(name, defaultValue, eventSupport)
112 {
113     this._name = name;
114     this._defaultValue = defaultValue;
115     this._eventSupport = eventSupport;
116 }
117
118 WebInspector.Setting.prototype = {
119     addChangeListener: function(listener, thisObject)
120     {
121         this._eventSupport.addEventListener(this._name, listener, thisObject);
122     },
123
124     removeChangeListener: function(listener, thisObject)
125     {
126         this._eventSupport.removeEventListener(this._name, listener, thisObject);
127     },
128
129     get name()
130     {
131         return this._name;
132     },
133
134     get: function()
135     {
136         var value = this._defaultValue;
137         if (window.localStorage != null && this._name in window.localStorage) {
138             try {
139                 value = JSON.parse(window.localStorage[this._name]);
140             } catch(e) {
141                 window.localStorage.removeItem(this._name);
142             }
143         }
144         return value;
145     },
146
147     set: function(value)
148     {
149         if (window.localStorage != null) {
150             try {
151                 window.localStorage[this._name] = JSON.stringify(value);
152             } catch(e) {
153                 console.error("Error saving setting with name:" + this._name);
154             }
155         }
156         this._eventSupport.dispatchEventToListeners(this._name, value);
157     }
158 }
159
160 WebInspector.settings = new WebInspector.Settings();