script debugger should only attach to JavaScriptCore when there are listeners
http://bugzilla.opendarwin.org/show_bug.cgi?id=9552
Attaches the debugger to all WebFrames when the first listener
is added. Detaches when the last listener is removed.
Also detach when the script debug delegate is set to nil.
* DefaultDelegates/WebScriptDebugServer.m:
(+[WebScriptDebugServer listenerCount]):
(-[WebScriptDebugServer dealloc]):
(-[WebScriptDebugServer attachScriptDebuggerToAllWebViews]):
(-[WebScriptDebugServer detachScriptDebuggerFromAllWebViews]):
(-[WebScriptDebugServer listenerConnectionDidDie:]):
(-[WebScriptDebugServer addListener:]):
(-[WebScriptDebugServer removeListener:]):
* DefaultDelegates/WebScriptDebugServerPrivate.h:
* WebCoreSupport/WebFrameBridge.m:
(-[WebFrameBridge windowObjectCleared]):
* WebView/WebFrame.m:
(-[WebFrame _attachScriptDebugger]):
(-[WebFrame _detachScriptDebugger]):
* WebView/WebFramePrivate.h:
* WebView/WebScriptDebugDelegate.m:
(-[WebScriptCallFrame parsedSource:fromURL:sourceId:]):
(-[WebScriptCallFrame enteredFrame:sourceId:line:]):
(-[WebScriptCallFrame hitStatement:sourceId:line:]):
(-[WebScriptCallFrame leavingFrame:sourceId:line:]):
* WebView/WebView.m:
(-[WebView _attachScriptDebuggerToAllFrames]):
(-[WebView _detachScriptDebuggerFromAllFrames]):
(-[WebView setScriptDebugDelegate:]):
* WebView/WebViewPrivate.h:
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@14990
268f45cc-cd09-0410-ab3c-
d52691b4dbfc
+2006-06-23 Timothy Hatcher <timothy@apple.com>
+
+ Reviewed by Geoff.
+
+ script debugger should only attach to JavaScriptCore when there are listeners
+ http://bugzilla.opendarwin.org/show_bug.cgi?id=9552
+
+ Attaches the debugger to all WebFrames when the first listener
+ is added. Detaches when the last listener is removed.
+ Also detach when the script debug delegate is set to nil.
+
+ * DefaultDelegates/WebScriptDebugServer.m:
+ (+[WebScriptDebugServer listenerCount]):
+ (-[WebScriptDebugServer dealloc]):
+ (-[WebScriptDebugServer attachScriptDebuggerToAllWebViews]):
+ (-[WebScriptDebugServer detachScriptDebuggerFromAllWebViews]):
+ (-[WebScriptDebugServer listenerConnectionDidDie:]):
+ (-[WebScriptDebugServer addListener:]):
+ (-[WebScriptDebugServer removeListener:]):
+ * DefaultDelegates/WebScriptDebugServerPrivate.h:
+ * WebCoreSupport/WebFrameBridge.m:
+ (-[WebFrameBridge windowObjectCleared]):
+ * WebView/WebFrame.m:
+ (-[WebFrame _attachScriptDebugger]):
+ (-[WebFrame _detachScriptDebugger]):
+ * WebView/WebFramePrivate.h:
+ * WebView/WebScriptDebugDelegate.m:
+ (-[WebScriptCallFrame parsedSource:fromURL:sourceId:]):
+ (-[WebScriptCallFrame enteredFrame:sourceId:line:]):
+ (-[WebScriptCallFrame hitStatement:sourceId:line:]):
+ (-[WebScriptCallFrame leavingFrame:sourceId:line:]):
+ * WebView/WebView.m:
+ (-[WebView _attachScriptDebuggerToAllFrames]):
+ (-[WebView _detachScriptDebuggerFromAllFrames]):
+ (-[WebView setScriptDebugDelegate:]):
+ * WebView/WebViewPrivate.h:
+
2006-06-22 John Sullivan <sullivan@apple.com>
Reviewed by Tim Omernick
#import "WebScriptDebugServer.h"
#import "WebScriptDebugServerPrivate.h"
+#import "WebViewInternal.h"
+
+#import <JavaScriptCore/Assertions.h>
NSString *WebScriptDebugServerProcessNameKey = @"WebScriptDebugServerProcessNameKey";
NSString *WebScriptDebugServerProcessBundleIdentifierKey = @"WebScriptDebugServerProcessBundleIdentifierKey";
@implementation WebScriptDebugServer
static WebScriptDebugServer *sharedServer = nil;
+static unsigned listenerCount = 0;
+ (WebScriptDebugServer *)sharedScriptDebugServer
{
return sharedServer;
}
++ (unsigned)listenerCount
+{
+ return listenerCount;
+}
+
- (id)init
{
self = [super init];
- (void)dealloc
{
+ ASSERT(listenerCount >= [listeners count]);
+ listenerCount -= [listeners count];
+ if (!listenerCount)
+ [self detachScriptDebuggerFromAllWebViews];
[[NSDistributedNotificationCenter defaultCenter] removeObserver:self name:WebScriptDebugServerQueryNotification object:nil];
[[NSDistributedNotificationCenter defaultCenter] postNotificationName:WebScriptDebugServerWillUnloadNotification object:serverName];
[[NSNotificationCenter defaultCenter] removeObserver:self name:NSConnectionDidDieNotification object:nil];
[super dealloc];
}
+- (void)attachScriptDebuggerToAllWebViews
+{
+ [WebView _makeAllWebViewsPerformSelector:@selector(_attachScriptDebuggerToAllFrames)];
+}
+
+- (void)detachScriptDebuggerFromAllWebViews
+{
+ [WebView _makeAllWebViewsPerformSelector:@selector(_detachScriptDebuggerFromAllFrames)];
+}
+
- (void)serverQuery:(NSNotification *)notification
{
NSProcessInfo *processInfo = [NSProcessInfo processInfo];
if ([[listener connectionForProxy] isEqualTo:connection])
[listenersToRemove addObject:listener];
+ ASSERT(listenerCount >= [listenersToRemove count]);
+ listenerCount -= [listenersToRemove count];
[listeners minusSet:listenersToRemove];
[listenersToRemove release];
+
+ if (!listenerCount)
+ [self detachScriptDebuggerFromAllWebViews];
}
- (oneway void)addListener:(id<WebScriptDebugListener>)listener
// can't use isKindOfClass: here because that will send over the wire and not check the proxy object
if ([listener class] != [NSDistantObject class] || ![listener conformsToProtocol:@protocol(WebScriptDebugListener)])
return;
+ listenerCount++;
[listeners addObject:listener];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(listenerConnectionDidDie:) name:NSConnectionDidDieNotification object:[(NSDistantObject *)listener connectionForProxy]];
+ if (listenerCount == 1)
+ [self attachScriptDebuggerToAllWebViews];
}
- (oneway void)removeListener:(id<WebScriptDebugListener>)listener
{
+ ASSERT(listenerCount >= 1);
+ listenerCount--;
[[NSNotificationCenter defaultCenter] removeObserver:self name:NSConnectionDidDieNotification object:[(NSDistantObject *)listener connectionForProxy]];
[listeners removeObject:listener];
+ if (!listenerCount)
+ [self detachScriptDebuggerFromAllWebViews];
}
- (oneway void)step
BOOL step;
}
+ (WebScriptDebugServer *)sharedScriptDebugServer;
++ (unsigned)listenerCount;
+
+- (void)attachScriptDebuggerToAllWebViews;
+- (void)detachScriptDebuggerFromAllWebViews;
- (void)webView:(WebView *)webView didParseSource:(NSString *)source
fromURL:(NSString *)url
#import "WebPluginViewFactoryPrivate.h"
#import "WebPreferencesPrivate.h"
#import "WebResourcePrivate.h"
+#import "WebScriptDebugServerPrivate.h"
#import "WebSubresourceLoader.h"
#import "WebUIDelegatePrivate.h"
#import "WebViewInternal.h"
{
WebView *wv = [self webView];
[[wv _frameLoadDelegateForwarder] webView:wv windowScriptObjectAvailable:[self windowScriptObject]];
- if ([wv scriptDebugDelegate] || [WebView _scriptDebuggerEnabled])
+ if ([wv scriptDebugDelegate] || [WebScriptDebugServer listenerCount])
[_frame _attachScriptDebugger];
}
- (void)_attachScriptDebugger
{
- if (!_private->scriptDebugger) {
+ if (!_private->scriptDebugger)
_private->scriptDebugger = [[WebScriptDebugger alloc] initWithWebFrame:self];
+}
+
+- (void)_detachScriptDebugger
+{
+ if (_private->scriptDebugger) {
+ id old = _private->scriptDebugger;
+ _private->scriptDebugger = nil;
+ [old release];
}
}
- (BOOL)_isFrameSet;
- (void)_attachScriptDebugger;
+- (void)_detachScriptDebugger;
- (void)_recursive_pauseNullEventsForAllNetscapePlugins;
- (void)_recursive_resumeNullEventsForAllNetscapePlugins;
- (void)parsedSource:(NSString *)source fromURL:(NSString *)url sourceId:(int)sid
{
[[_webView _scriptDebugDelegateForwarder] webView:_webView didParseSource:source fromURL:url sourceId:sid forWebFrame:_webFrame];
- if ([WebView _scriptDebuggerEnabled])
+ if ([WebScriptDebugServer listenerCount])
[[WebScriptDebugServer sharedScriptDebugServer] webView:_webView didParseSource:source fromURL:url sourceId:sid forWebFrame:_webFrame];
}
- (void)enteredFrame:(WebCoreScriptCallFrame *)frame sourceId:(int)sid line:(int)lineno
{
[[_webView _scriptDebugDelegateForwarder] webView:_webView didEnterCallFrame:[frame wrapper] sourceId:sid line:lineno forWebFrame:_webFrame];
- if ([WebView _scriptDebuggerEnabled])
+ if ([WebScriptDebugServer listenerCount])
[[WebScriptDebugServer sharedScriptDebugServer] webView:_webView didEnterCallFrame:[frame wrapper] sourceId:sid line:lineno forWebFrame:_webFrame];
}
- (void)hitStatement:(WebCoreScriptCallFrame *)frame sourceId:(int)sid line:(int)lineno
{
[[_webView _scriptDebugDelegateForwarder] webView:_webView willExecuteStatement:[frame wrapper] sourceId:sid line:lineno forWebFrame:_webFrame];
- if ([WebView _scriptDebuggerEnabled])
+ if ([WebScriptDebugServer listenerCount])
[[WebScriptDebugServer sharedScriptDebugServer] webView:_webView willExecuteStatement:[frame wrapper] sourceId:sid line:lineno forWebFrame:_webFrame];
}
- (void)leavingFrame:(WebCoreScriptCallFrame *)frame sourceId:(int)sid line:(int)lineno
{
[[_webView _scriptDebugDelegateForwarder] webView:_webView willLeaveCallFrame:[frame wrapper] sourceId:sid line:lineno forWebFrame:_webFrame];
- if ([WebView _scriptDebuggerEnabled])
+ if ([WebScriptDebugServer listenerCount])
[[WebScriptDebugServer sharedScriptDebugServer] webView:_webView willLeaveCallFrame:[frame wrapper] sourceId:sid line:lineno forWebFrame:_webFrame];
}
[_private->pluginDatabase refresh];
}
+- (void)_attachScriptDebuggerToAllFrames
+{
+ WebFrame *frame = [self mainFrame];
+ do {
+ [frame _attachScriptDebugger];
+ frame = [frame _nextFrameWithWrap:NO];
+ } while (frame);
+}
+
+- (void)_detachScriptDebuggerFromAllFrames
+{
+ WebFrame *frame = [self mainFrame];
+ do {
+ [frame _detachScriptDebugger];
+ frame = [frame _nextFrameWithWrap:NO];
+ } while (frame);
+}
+
@end
_private->scriptDebugDelegate = delegate;
[_private->scriptDebugDelegateForwarder release];
_private->scriptDebugDelegateForwarder = nil;
+ if (delegate)
+ [self _attachScriptDebuggerToAllFrames];
+ else
+ [self _detachScriptDebuggerFromAllFrames];
}
- scriptDebugDelegate
- (IBAction)toggleContinuousSpellChecking:(id)sender;
-- (void)toggleSmartInsertDelete:(id)sender;
+- (IBAction)toggleSmartInsertDelete:(id)sender;
- (BOOL)canMakeTextStandardSize;
- (IBAction)makeTextStandardSize:(id)sender;
@interface WebView (WebViewEditingPendingPublic)
-- (void)moveToBeginningOfSentence:(id)sender;
-- (void)moveToBeginningOfSentenceAndModifySelection:(id)sender;
-- (void)moveToEndOfSentence:(id)sender;
-- (void)moveToEndOfSentenceAndModifySelection:(id)sender;
-- (void)selectSentence:(id)sender;
+- (IBAction)moveToBeginningOfSentence:(id)sender;
+- (IBAction)moveToBeginningOfSentenceAndModifySelection:(id)sender;
+- (IBAction)moveToEndOfSentence:(id)sender;
+- (IBAction)moveToEndOfSentenceAndModifySelection:(id)sender;
+- (IBAction)selectSentence:(id)sender;
@end
*/
- (void)_setAdditionalWebPlugInPaths:(NSArray *)newPaths;
+/*!
+ @method _attachScriptDebuggerToAllFrames
+ @abstract Attaches a script debugger to all frames belonging to the receiver.
+ */
+- (void)_attachScriptDebuggerToAllFrames;
+
+/*!
+ @method _detachScriptDebuggerFromAllFrames
+ @abstract Detaches any script debuggers from all frames belonging to the receiver.
+ */
+- (void)_detachScriptDebuggerFromAllFrames;
+
@end
@interface WebView (WebViewPrintingPrivate)