2 * Copyright (C) 2007 Apple Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
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.
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.
29 #import "WebInspector.h"
31 #import "WebFrameInternal.h"
32 #import "WebInspectorPrivate.h"
33 #import "WebInspectorFrontend.h"
35 #include <WebCore/Document.h>
36 #include <WebCore/Frame.h>
37 #include <WebCore/InspectorController.h>
38 #include <WebCore/Page.h>
40 using namespace WebCore;
42 @implementation WebInspector
43 - (id)initWithWebView:(WebView *)webView
45 if (!(self = [super init]))
47 _webView = webView; // not retained to prevent a cycle
65 if (Page* page = core(_webView))
66 page->inspectorController()->show();
69 - (void)show:(id)sender
74 - (void)showConsole:(id)sender
77 [_frontend showConsole];
80 - (void)showTimeline:(id)sender
82 // Not used anymore. Remove when a release of Safari non-longer calls this.
85 - (BOOL)isDebuggingJavaScript
87 return _frontend && [_frontend isDebuggingEnabled];
90 - (void)toggleDebuggingJavaScript:(id)sender
94 if ([self isDebuggingJavaScript])
95 [_frontend setDebuggingEnabled:false];
97 [_frontend setDebuggingEnabled:true];
100 - (void)startDebuggingJavaScript:(id)sender
103 [_frontend setDebuggingEnabled:true];
106 - (void)stopDebuggingJavaScript:(id)sender
109 [_frontend setDebuggingEnabled:false];
112 - (BOOL)isProfilingJavaScript
114 return _frontend && [_frontend isProfilingJavaScript];
117 - (void)toggleProfilingJavaScript:(id)sender
121 if ([self isProfilingJavaScript])
122 [_frontend stopProfilingJavaScript];
124 [_frontend startProfilingJavaScript];
127 - (void)startProfilingJavaScript:(id)sender
130 [_frontend startProfilingJavaScript];
133 - (void)stopProfilingJavaScript:(id)sender
136 [_frontend stopProfilingJavaScript];
139 - (BOOL)isJavaScriptProfilingEnabled
141 if (Page* page = core(_webView))
142 return page->inspectorController()->profilerEnabled();
146 - (void)setJavaScriptProfilingEnabled:(BOOL)enabled
148 Page* page = core(_webView);
152 page->inspectorController()->setProfilerEnabled(enabled);
155 - (BOOL)isTimelineProfilingEnabled
157 return _frontend && [_frontend isTimelineProfilingEnabled];
160 - (void)setTimelineProfilingEnabled:(BOOL)enabled
163 [_frontend setTimelineProfilingEnabled:enabled];
166 - (void)close:(id)sender
168 if (Page* page = core(_webView))
169 page->inspectorController()->close();
172 - (void)attach:(id)sender
177 - (void)detach:(id)sender
182 - (void)evaluateInFrontend:(id)sender callId:(long)callId script:(NSString *)script
184 if (Page* page = core(_webView))
185 page->inspectorController()->evaluateForTestInFrontend(callId, script);
188 - (void)setFrontend:(WebInspectorFrontend *)frontend
190 _frontend = [frontend retain];
193 - (void)releaseFrontend
200 @implementation WebInspector (Obsolete)
201 + (WebInspector *)webInspector
203 // Safari 3.0 calls this method
204 static BOOL logged = NO;
206 NSLog(@"+[WebInspector webInspector]: this method is obsolete.");
210 return [[[WebInspector alloc] init] autorelease];
213 - (void)setWebFrame:(WebFrame *)frame
215 // Safari 3.0 calls this method
216 static BOOL logged = NO;
218 NSLog(@"-[WebInspector setWebFrame:]: this method is obsolete.");
222 _webView = [frame webView];
227 // Shiira calls this internal method, return nil since we can't easily return the window
228 static BOOL logged = NO;
230 NSLog(@"-[WebInspector window]: this method is obsolete and now returns nil.");
237 - (void)showWindow:(id)sender
239 // Safari 3.0 calls this method
240 static BOOL logged = NO;
242 NSLog(@"-[WebInspector showWindow:]: this method is obsolete.");