1/*
2 * Copyright (C) 2009 Google Inc. All rights reserved.
3 * Copyright (C) 2013 Seokju Kwon (seokju.kwon@gmail.com)
4 * Copyright (C) 2013 Apple Inc. All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions are
8 * met:
9 *
10 *     * Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 *     * Redistributions in binary form must reproduce the above
13 * copyright notice, this list of conditions and the following disclaimer
14 * in the documentation and/or other materials provided with the
15 * distribution.
16 *     * Neither the name of Google Inc. nor the names of its
17 * contributors may be used to endorse or promote products derived from
18 * this software without specific prior written permission.
19 *
20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 */
32
33if (!window.InspectorFrontendHost) {
34    WebInspector.InspectorFrontendHostStub = function()
35    {
36    }
37
38    WebInspector.InspectorFrontendHostStub.prototype = {
39        // Public
40
41        initializeWebSocket: function(url)
42        {
43            var socket = new WebSocket(url);
44            socket.addEventListener("open", socketReady.bind(this));
45
46            function socketReady()
47            {
48                this._socket = socket;
49
50                this._socket.addEventListener("message", function(message) { InspectorBackend.dispatch(message.data); });
51                this._socket.addEventListener("error", function(error) { console.error(error); });
52
53                this._sendPendingMessagesToBackendIfNeeded();
54            }
55        },
56
57        bringToFront: function()
58        {
59            this._windowVisible = true;
60        },
61
62        closeWindow: function()
63        {
64            this._windowVisible = false;
65        },
66
67        requestSetDockSide: function(side)
68        {
69            InspectorFrontendAPI.setDockSide(side);
70        },
71
72        setAttachedWindowHeight: function(height)
73        {
74        },
75
76        setAttachedWindowWidth: function(width)
77        {
78        },
79
80        setToolbarHeight: function(width)
81        {
82        },
83
84        moveWindowBy: function(x, y)
85        {
86        },
87
88        loaded: function()
89        {
90        },
91
92        localizedStringsURL: function()
93        {
94            return undefined;
95        },
96
97        debuggableType: function()
98        {
99            return "web";
100        },
101
102        inspectedURLChanged: function(title)
103        {
104            document.title = title;
105        },
106
107        copyText: function(text)
108        {
109            this._textToCopy = text;
110            if (!document.execCommand("copy"))
111                console.error("Clipboard access is denied");
112        },
113
114        openInNewTab: function(url)
115        {
116            window.open(url, "_blank");
117        },
118
119        save: function(url, content, base64Encoded, forceSaveAs)
120        {
121        },
122
123        sendMessageToBackend: function(message)
124        {
125            if (!this._socket) {
126                if (!this._pendingMessages)
127                    this._pendingMessages = [];
128                this._pendingMessages.push(message);
129                return;
130            }
131
132            this._sendPendingMessagesToBackendIfNeeded();
133
134            this._socket.send(message);
135        },
136
137        platform: function()
138        {
139            return (navigator.platform.match(/mac|win|linux/i) || ["other"])[0].toLowerCase();
140        },
141
142        beep: function()
143        {
144        },
145
146        // Private
147
148        _sendPendingMessagesToBackendIfNeeded: function()
149        {
150            if (!this._pendingMessages)
151                return;
152
153            for (var i = 0; i < this._pendingMessages.length; ++i)
154                this._socket.send(this._pendingMessages[i]);
155
156            delete this._pendingMessages;
157        }
158    }
159
160    InspectorFrontendHost = new WebInspector.InspectorFrontendHostStub();
161
162    WebInspector.dontLocalizeUserInterface = true;
163}
164