Web Inspector: convert workers inspection into capability
[WebKit-https.git] / Source / WebCore / inspector / front-end / InspectorFrontendHostStub.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 if (!window.InspectorFrontendHost) {
32
33 /**
34  * @constructor
35  * @implements {InspectorFrontendHostAPI}
36  */
37 WebInspector.InspectorFrontendHostStub = function()
38 {
39     this._attachedWindowHeight = 0;
40     this.isStub = true;
41     this._fileBuffers = {};
42     WebInspector.documentCopyEventFired = this.documentCopy.bind(this);
43 }
44
45 WebInspector.InspectorFrontendHostStub.prototype = {
46     platform: function()
47     {
48         var match = navigator.userAgent.match(/Windows NT/);
49         if (match)
50             return "windows";
51         match = navigator.userAgent.match(/Mac OS X/);
52         if (match)
53             return "mac";
54         return "linux";
55     },
56
57     port: function()
58     {
59         return "unknown";
60     },
61
62     bringToFront: function()
63     {
64         this._windowVisible = true;
65     },
66
67     closeWindow: function()
68     {
69         this._windowVisible = false;
70     },
71
72     requestSetDockSide: function(side)
73     {
74         InspectorFrontendAPI.setDockSide(side);
75     },
76
77     setAttachedWindowHeight: function(height)
78     {
79     },
80
81     moveWindowBy: function(x, y)
82     {
83     },
84
85     setInjectedScriptForOrigin: function(origin, script)
86     {
87     },
88
89     loaded: function()
90     {
91     },
92
93     localizedStringsURL: function()
94     {
95         return undefined;
96     },
97
98     hiddenPanels: function()
99     {
100         return WebInspector.queryParamsObject["hiddenPanels"] || "";
101     },
102
103     inspectedURLChanged: function(url)
104     {
105         document.title = WebInspector.UIString(Preferences.applicationTitle, url);
106     },
107
108     documentCopy: function(event)
109     {
110         if (!this._textToCopy)
111             return;
112         event.clipboardData.setData("text", this._textToCopy);
113         event.preventDefault();
114         delete this._textToCopy;
115     },
116
117     copyText: function(text)
118     {
119         this._textToCopy = text;
120         if (!document.execCommand("copy")) {
121             var screen = new WebInspector.ClipboardAccessDeniedScreen();
122             screen.showModal();
123         }
124     },
125
126     openInNewTab: function(url)
127     {
128         window.open(url, "_blank");
129     },
130
131     canSave: function()
132     {
133         return true;
134     },
135
136     save: function(url, content, forceSaveAs)
137     {
138         if (this._fileBuffers[url])
139             throw new Error("Concurrent file modification denied.");
140
141         this._fileBuffers[url] = [content];
142         setTimeout(WebInspector.fileManager.savedURL.bind(WebInspector.fileManager, url), 0);
143     },
144
145     append: function(url, content)
146     {
147         var buffer = this._fileBuffers[url];
148         if (!buffer)
149             throw new Error("File is not open for write yet.");
150
151         buffer.push(content);
152         setTimeout(WebInspector.fileManager.appendedToURL.bind(WebInspector.fileManager, url), 0);
153     },
154
155     close: function(url)
156     {
157         var content = this._fileBuffers[url];
158         delete this._fileBuffers[url];
159
160         if (!content)
161             return;
162
163         var lastSlashIndex = url.lastIndexOf("/");
164         var fileNameSuffix = (lastSlashIndex === -1) ? url : url.substring(lastSlashIndex + 1);
165
166         var blob = new Blob(content, { type: "application/octet-stream" });
167         var objectUrl = window.URL.createObjectURL(blob);
168         window.location = objectUrl + "#" + fileNameSuffix;
169
170         function cleanup()
171         {
172             window.URL.revokeObjectURL(objectUrl);
173         }
174         setTimeout(cleanup, 0);
175     },
176
177     sendMessageToBackend: function(message)
178     {
179     },
180
181     recordActionTaken: function(actionCode)
182     {
183     },
184
185     recordPanelShown: function(panelCode)
186     {
187     },
188
189     recordSettingChanged: function(settingCode)
190     {
191     },
192
193     loadResourceSynchronously: function(url)
194     {
195         return loadXHR(url);
196     },
197
198     supportsFileSystems: function()
199     {
200         return false;
201     },
202
203     requestFileSystems: function()
204     {
205     },
206
207     addFileSystem: function()
208     {
209     },
210
211     removeFileSystem: function(fileSystemPath)
212     {
213     },
214
215     isolatedFileSystem: function(fileSystemId, registeredName)
216     {
217         return null;
218     },
219
220     setZoomFactor: function(zoom)
221     {
222     },
223
224     isUnderTest: function()
225     {
226         return false;
227     }
228 }
229
230 InspectorFrontendHost = new WebInspector.InspectorFrontendHostStub();
231 Preferences.localizeUI = false;
232
233 // Default implementation; platforms will override.
234 WebInspector.clipboardAccessDeniedMessage = function()
235 {
236     return "";
237 }
238
239 /**
240  * @constructor
241  * @extends {WebInspector.HelpScreen}
242  */
243 WebInspector.ClipboardAccessDeniedScreen = function()
244 {
245     WebInspector.HelpScreen.call(this, WebInspector.UIString("Clipboard access is denied"));
246     var platformMessage = WebInspector.clipboardAccessDeniedMessage();
247     if (platformMessage) {
248         var p = this.contentElement.createChild("p");
249         p.addStyleClass("help-section");
250         p.textContent = platformMessage;
251     }
252 }
253
254 WebInspector.ClipboardAccessDeniedScreen.prototype = {
255     __proto__: WebInspector.HelpScreen.prototype
256 }
257
258 }
259
260 /**
261  * @constructor
262  * @extends {WebInspector.HelpScreen}
263  */
264 WebInspector.RemoteDebuggingTerminatedScreen = function(reason)
265 {
266     WebInspector.HelpScreen.call(this, WebInspector.UIString("Detached from the target"));
267     var p = this.contentElement.createChild("p");
268     p.addStyleClass("help-section");
269     p.createChild("span").textContent = "Remote debugging has been terminated with reason: ";
270     p.createChild("span", "error-message").textContent = reason;
271     p.createChild("br");
272     p.createChild("span").textContent = "Please re-attach to the new target.";
273 }
274
275 WebInspector.RemoteDebuggingTerminatedScreen.prototype = {
276     __proto__: WebInspector.HelpScreen.prototype
277 }