[Release] Webkit-EFL Ver. 2.0_beta_118996_0.6.24
[framework/web/webkit-efl.git] / Source / WebKit / mac / WebInspector / WebInspector.mm
1 /*
2  * Copyright (C) 2007 Apple 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
6  * are met:
7  *
8  * 1.  Redistributions of source code must retain the above copyright
9  *     notice, this list of conditions and the following disclaimer. 
10  * 2.  Redistributions in binary form must reproduce the above copyright
11  *     notice, this list of conditions and the following disclaimer in the
12  *     documentation and/or other materials provided with the distribution. 
13  * 3.  Neither the name of Apple Computer, Inc. ("Apple") nor the names of
14  *     its contributors may be used to endorse or promote products derived
15  *     from this software without specific prior written permission. 
16  *
17  * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
18  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20  * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
21  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
22  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
23  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
24  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27  */
28
29 #import "WebInspector.h"
30
31 #import "WebFrameInternal.h"
32 #import "WebInspectorPrivate.h"
33 #import "WebInspectorFrontend.h"
34
35 #include <WebCore/Document.h>
36 #include <WebCore/Frame.h>
37 #include <WebCore/InspectorController.h>
38 #include <WebCore/Page.h>
39
40 using namespace WebCore;
41
42 @implementation WebInspector
43 - (id)initWithWebView:(WebView *)webView
44 {
45     if (!(self = [super init]))
46         return nil;
47     _webView = webView; // not retained to prevent a cycle
48
49     return self;
50 }
51
52 - (void)dealloc
53 {
54     [_frontend release];
55     [super dealloc];
56 }
57
58 - (void)webViewClosed
59 {
60     _webView = nil;
61 }
62
63 - (void)showWindow
64 {
65     if (Page* page = core(_webView))
66         page->inspectorController()->show();
67 }
68
69 - (void)show:(id)sender
70 {
71     [self showWindow];
72 }
73
74 - (void)showConsole:(id)sender
75 {
76     [self showWindow];
77     [_frontend showConsole];
78 }
79
80 - (void)showTimeline:(id)sender
81 {
82     // Not used anymore. Remove when a release of Safari non-longer calls this.
83 }
84
85 - (BOOL)isDebuggingJavaScript
86 {
87     return _frontend && [_frontend isDebuggingEnabled];
88 }
89
90 - (void)toggleDebuggingJavaScript:(id)sender
91 {
92     [self showWindow];
93
94     if ([self isDebuggingJavaScript])
95         [_frontend setDebuggingEnabled:false];
96     else
97         [_frontend setDebuggingEnabled:true];
98 }
99
100 - (void)startDebuggingJavaScript:(id)sender
101 {
102     if (_frontend)
103         [_frontend setDebuggingEnabled:true];
104 }
105
106 - (void)stopDebuggingJavaScript:(id)sender
107 {
108     if (_frontend)
109         [_frontend setDebuggingEnabled:false];
110 }
111
112 - (BOOL)isProfilingJavaScript
113 {
114     return _frontend && [_frontend isProfilingJavaScript];
115 }
116
117 - (void)toggleProfilingJavaScript:(id)sender
118 {
119     [self showWindow];
120
121     if ([self isProfilingJavaScript])
122         [_frontend stopProfilingJavaScript];
123     else
124         [_frontend startProfilingJavaScript];
125 }
126
127 - (void)startProfilingJavaScript:(id)sender
128 {
129     if (_frontend)
130         [_frontend startProfilingJavaScript];
131 }
132
133 - (void)stopProfilingJavaScript:(id)sender
134 {
135     if (_frontend)
136         [_frontend stopProfilingJavaScript];
137 }
138
139 - (BOOL)isJavaScriptProfilingEnabled
140 {
141     if (Page* page = core(_webView))
142         return page->inspectorController()->profilerEnabled();
143     return NO;
144 }
145
146 - (void)setJavaScriptProfilingEnabled:(BOOL)enabled
147 {
148     Page* page = core(_webView);
149     if (!page)
150         return;
151
152     page->inspectorController()->setProfilerEnabled(enabled);
153 }
154
155 - (BOOL)isTimelineProfilingEnabled
156 {
157     return _frontend && [_frontend isTimelineProfilingEnabled];
158 }
159
160 - (void)setTimelineProfilingEnabled:(BOOL)enabled
161 {
162     if (_frontend)
163         [_frontend setTimelineProfilingEnabled:enabled];
164 }
165
166 - (void)close:(id)sender 
167 {
168     if (Page* page = core(_webView))
169         page->inspectorController()->close();
170 }
171
172 - (void)attach:(id)sender
173 {
174     [_frontend attach];
175 }
176
177 - (void)detach:(id)sender
178 {
179     [_frontend detach];
180 }
181
182 - (void)evaluateInFrontend:(id)sender callId:(long)callId script:(NSString *)script
183 {
184     if (Page* page = core(_webView))
185         page->inspectorController()->evaluateForTestInFrontend(callId, script);
186 }
187
188 - (void)setFrontend:(WebInspectorFrontend *)frontend
189 {
190     _frontend = [frontend retain];
191 }
192
193 - (void)releaseFrontend
194 {
195     [_frontend release];
196     _frontend = 0;
197 }
198 @end
199
200 @implementation WebInspector (Obsolete)
201 + (WebInspector *)webInspector
202 {
203     // Safari 3.0 calls this method
204     static BOOL logged = NO;
205     if (!logged) {
206         NSLog(@"+[WebInspector webInspector]: this method is obsolete.");
207         logged = YES;
208     }
209
210     return [[[WebInspector alloc] init] autorelease];
211 }
212
213 - (void)setWebFrame:(WebFrame *)frame
214 {
215     // Safari 3.0 calls this method
216     static BOOL logged = NO;
217     if (!logged) {
218         NSLog(@"-[WebInspector setWebFrame:]: this method is obsolete.");
219         logged = YES;
220     }
221
222     _webView = [frame webView];
223 }
224
225 - (NSWindow *)window
226 {
227     // Shiira calls this internal method, return nil since we can't easily return the window
228     static BOOL logged = NO;
229     if (!logged) {
230         NSLog(@"-[WebInspector window]: this method is obsolete and now returns nil.");
231         logged = YES;
232     }
233
234     return nil;
235 }
236
237 - (void)showWindow:(id)sender
238 {
239     // Safari 3.0 calls this method
240     static BOOL logged = NO;
241     if (!logged) {
242         NSLog(@"-[WebInspector showWindow:]: this method is obsolete.");
243         logged = YES;
244     }
245
246     [self showWindow];
247 }
248 @end