Skip to content

Commit

Permalink
fixed broken incremental loading of large responses
Browse files Browse the repository at this point in the history
  • Loading branch information
liyanage committed Feb 23, 2009
1 parent 4f2dc9c commit a8cb6b0
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 19 deletions.
4 changes: 2 additions & 2 deletions Sources/XMLWebKitPluginView.h
Expand Up @@ -16,7 +16,7 @@
IBOutlet NSTextView *textView;
IBOutlet NSWindow *aboutPanel;
IBOutlet NSTextField *aboutPanelVersionLabel;
NSData *documentData;
NSMutableData *documentData;
NSURL *documentURL;
NSSavePanel *savePanel;
NSXMLDocument *xmlDocument;
Expand All @@ -37,7 +37,7 @@
@property(retain) IBOutlet NSWindow *aboutPanel;
@property(retain) IBOutlet NSTextField *aboutPanelVersionLabel;
@property(retain) NSURL *documentURL;
@property(retain) NSData *documentData;
@property(retain) NSMutableData *documentData;
@property(retain) WebFrame *parentFrame;
@property(retain) DOMHTMLElement *domElement;

Expand Down
62 changes: 47 additions & 15 deletions Sources/XMLWebKitPluginView.m
Expand Up @@ -40,7 +40,7 @@ + (NSView *)plugInViewWithArguments:(NSDictionary *)newArguments {
- (id)initWithArguments:(NSDictionary *)newArguments {

#ifdef CONFIGURATION_DEBUG
NSLog(@"arguments: %@", newArguments);
NSLog(@"XML View Plugin: arguments: %@", newArguments);
#endif

if (!(self = [super initWithFrame:NSZeroRect])) return nil;
Expand Down Expand Up @@ -175,7 +175,7 @@ - (IBAction)updateDataDisplay:(id)sender {
[clone setAttribute:@"type" value:@"text/html"];
[clone setAttribute:@"src" value:@"http://localhost/test2.xml"];
NSLog(@"redirecting");
NSLog(@"XML View Plugin: redirecting");
[[self retain] autorelease];
Expand All @@ -196,7 +196,7 @@ - (IBAction)updateDataDisplay:(id)sender {
// return;
}
NSLog(@"not redirecting");
NSLog(@"XML View Plugin: not redirecting");
*/

if (!documentData) return;
Expand Down Expand Up @@ -243,7 +243,7 @@ - (void)setupTextViewFont:(NSTextView *)tv {
// This one doesn't work, somehow we never see this on the responder chain
/*
- (IBAction)takeFindStringFromSelection:(id)sender {
NSLog(@"find string action");
NSLog(@"XML View Plugin: find string action");
tag = NSFindPanelActionSetFindString;
[textView performFindPanelAction:self];
}
Expand Down Expand Up @@ -283,7 +283,7 @@ - (NSInteger)tag {

/*
- (BOOL)respondsToSelector:(SEL)aSelector {
NSLog(@"selector: %@", NSStringFromSelector(aSelector));
NSLog(@"XML View Plugin: selector: %@", NSStringFromSelector(aSelector));
return [super respondsToSelector:aSelector];
}
*/
Expand Down Expand Up @@ -318,30 +318,32 @@ - (void)loadDataWithArguments:(NSDictionary *)arguments {
// if the key is present and tells us not to load the data, this
// method should not continue. Instead, the webPlugInMainResourceDidReceiveData:
// method gets the data already loaded.
// NSLog(@"plugin should not load data");
// NSLog(@"XML View Plugin: plugin should not load data");
return;
}

#ifdef CONFIGURATION_DEBUG
NSLog(@"XML View Plugin: WebPlugInShouldLoadMainResourceKey is YES");
#endif

if (!documentURL) {
self.notificationMessage = @"Unable to load XML data, no URL";
NSLog(notificationMessage);
NSLog(@"XML View Plugin: %@", notificationMessage);
return;
}

self.documentData = [NSData dataWithContentsOfURL:documentURL];
if (!documentData) {
self.notificationMessage = [NSString stringWithFormat:@"Unable to load XML data from %@", documentURL];
NSLog(notificationMessage);
NSLog(@"XML View Plugin: %@", notificationMessage);
return;
}

/*
NSURL *baseUrl = [arguments valueForKey:@"WebPlugInBaseURLKey"];
NSLog(@"baseurl: %@", baseUrl);
NSLog(@"XML View Plugin: baseurl: %@", baseUrl);
self.parentFrame = [[arguments valueForKey:@"WebPlugInContainerKey"] webFrame];
NSLog(@"parentframe: %@, %@", parentFrame, [parentFrame name]);
NSLog(@"XML View Plugin: parentframe: %@, %@", parentFrame, [parentFrame name]);
*/

// [parentFrame loadData:[@"test" dataUsingEncoding:NSUTF8StringEncoding] MIMEType:@"text/plain" textEncodingName:@"utf-8" baseURL:baseUrl];
Expand Down Expand Up @@ -376,7 +378,7 @@ - (void)savePanelDidEnd:(NSWindow *)sheet returnCode:(int)returnCode contextInfo

/*
- (BOOL)respondsToSelector:(SEL)sel {
NSLog(@"selector query: %@", NSStringFromSelector(sel));
NSLog(@"XML View Plugin: selector query: %@", NSStringFromSelector(sel));
return [super respondsToSelector:sel];
}
*/
Expand All @@ -387,11 +389,41 @@ - (BOOL)respondsToSelector:(SEL)sel {
- (void)webPlugInMainResourceDidReceiveData:(NSData *)data {
// self.documentData = data;
// self.documentData = [[data copy] autorelease];
self.documentData = [NSData dataWithData:data]; // if we don't create a copy but instead just retain, the data suddenly changes to garbage when we look at it again at a later time.

if (self.documentData) {
#ifdef CONFIGURATION_DEBUG
NSLog(@"XML View Plugin: additional data arrived, appending to existing data");
#endif
[self.documentData appendData:data];
} else {
#ifdef CONFIGURATION_DEBUG
NSLog(@"XML View Plugin: initial data arrived");
#endif
self.documentData = [NSMutableData dataWithData:data]; // if we don't create a copy but instead just retain, the data suddenly changes to garbage when we look at it again at a later time.
}
}


/* It appears that this method from the protocol *must* be implemented, otherwise webPlugInMainResourceDidFailWithError is
* called with a "WebKitErrorDomain error 204" and webPlugInMainResourceDidReceiveData: is only called once for
* large responses, when it should be called several times (see the append logic there).
*/
- (void)webPlugInMainResourceDidReceiveResponse:(NSURLResponse *)response {
}


- (void)webPlugInMainResourceDidFinishLoading {
#ifdef CONFIGURATION_DEBUG
NSLog(@"XML View Plugin: finish loading, data length %u", [self.documentData length]);
#endif
[self updateDataDisplay:self];
}


- (void)webPlugInMainResourceDidFailWithError:(NSError *)error {
NSLog(@"XML View Plugin: Error: %@", error);
}

/*
- (void)webPlugInInitialize
{
Expand All @@ -404,22 +436,22 @@ - (void)webPlugInStart
{
// The plug-in usually begins drawing, playing sounds and/or animation in this method.
// You are not required to implement this method. It may safely be removed.
// NSLog(@"webPlugInStart: %@", NSStringFromRect([self frame]));
// NSLog(@"XML View Plugin: webPlugInStart: %@", NSStringFromRect([self frame]));
}
- (void)webPlugInStop
{
// The plug-in normally stop animations/sounds in this method.
// You are not required to implement this method. It may safely be removed.
NSLog(@"webPlugInStop");
NSLog(@"XML View Plugin: webPlugInStop");
}
- (void)webPlugInDestroy
{
// Perform cleanup and prepare to be deallocated.
// You are not required to implement this method. It may safely be removed.
NSLog(@"webPlugInDestroy");
NSLog(@"XML View Plugin: webPlugInDestroy");
}
- (void)webPlugInSetIsSelected:(BOOL)isSelected
Expand Down
4 changes: 2 additions & 2 deletions XMLWebKitPlugin.xcodeproj/project.pbxproj
Expand Up @@ -678,7 +678,7 @@
PRODUCT_NAME = "XML View Plugin";
PRODUCT_SHORTNAME = xmlviewplugin;
PRODUCT_VERSION = "$(PRODUCT_VERSION_BASE)-dev";
PRODUCT_VERSION_BASE = 1.3;
PRODUCT_VERSION_BASE = 1.4;
SDKROOT = macosx10.5;
WARNING_CFLAGS = "-Wall";
WRAPPER_EXTENSION = webplugin;
Expand All @@ -701,7 +701,7 @@
PRODUCT_NAME = "XML View Plugin";
PRODUCT_SHORTNAME = xmlviewplugin;
PRODUCT_VERSION = "$(PRODUCT_VERSION_BASE)";
PRODUCT_VERSION_BASE = 1.3;
PRODUCT_VERSION_BASE = 1.4;
SDKROOT = macosx10.5;
WARNING_CFLAGS = "-Wall";
WRAPPER_EXTENSION = webplugin;
Expand Down
4 changes: 4 additions & 0 deletions notes.txt
@@ -1,4 +1,8 @@

setup git-svn configuration, cleanup svn sandbox, setup separate git sandbox,
- fix large data load issue SF example
- branch experimental webview / xslt

Known Issues:

- "Use Selection For Find" doesn't work. The takeFindStringFromSelection method never reaches the main view on the responder chain. The text view seems to handle it, but in a way that doesn't actually set the find clipboard.
Expand Down

0 comments on commit a8cb6b0

Please sign in to comment.