From 3b8c96c58f1d33dfcd0d623c491042cc6ec72a7f Mon Sep 17 00:00:00 2001 From: "stuart.morgan%alumni.case.edu" Date: Thu, 19 Apr 2007 14:40:01 +0000 Subject: [PATCH] Camino only - Bug 374503: Clear status bar after loading all secondary resources. r=mento sr=pink --- camino/src/browser/BrowserWrapper.h | 9 ++-- camino/src/browser/BrowserWrapper.mm | 58 +++++++++++++++++------ camino/src/embedding/CHBrowserListener.mm | 15 +++--- camino/src/embedding/CHBrowserView.h | 4 ++ camino/src/formfill/KeychainService.mm | 8 ++++ 5 files changed, 71 insertions(+), 23 deletions(-) diff --git a/camino/src/browser/BrowserWrapper.h b/camino/src/browser/BrowserWrapper.h index 140e72c7533..c66a9202ed7 100644 --- a/camino/src/browser/BrowserWrapper.h +++ b/camino/src/browser/BrowserWrapper.h @@ -143,11 +143,12 @@ class nsIArray; // array of popupevents that have been blocked. We can use them to reconstruct the popups // later. If nil, no sites are blocked. Cleared after each new page. nsIMutableArray* mBlockedPopups; - NSMutableArray* mFeedList; // list of feeds found on page + NSMutableArray* mFeedList; // list of feeds found on page - CHBrowserView* mBrowserView; // retained + CHBrowserView* mBrowserView; // retained ToolTip* mToolTip; - NSMutableArray* mStatusStrings; // current status bar messages, STRONG + NSMutableArray* mStatusStrings; // current status bar messages, STRONG + NSMutableSet* mLoadingResources; // page resources currently loading, STRONG IBOutlet NSView* mBlockedPopupView; // loaded on demand, can be nil, STRONG IBOutlet RolloverImageButton* mBlockedPopupCloseButton; @@ -230,6 +231,8 @@ class nsIArray; // CHBrowserListener messages - (void)onLoadingStarted; - (void)onLoadingCompleted:(BOOL)succeeded; +- (void)onResourceLoadingStarted:(NSNumber*)resourceIdentifier; +- (void)onResourceLoadingCompleted:(NSNumber*)resourceIdentifier; - (void)onProgressChange64:(long long)currentBytes outOf:(long long)maxBytes; - (void)onProgressChange:(long)currentBytes outOf:(long)maxBytes; - (void)onLocationChange:(NSString*)urlSpec isNewPage:(BOOL)newPage requestSucceeded:(BOOL)requestOK; diff --git a/camino/src/browser/BrowserWrapper.mm b/camino/src/browser/BrowserWrapper.mm index 808280dbd6e..7175c966db9 100644 --- a/camino/src/browser/BrowserWrapper.mm +++ b/camino/src/browser/BrowserWrapper.mm @@ -89,7 +89,7 @@ class nsIDOMPopupBlockedEvent; static NSString* const kEnablePluginsChangedNotificationName = @"EnablePluginsChanged"; // types of status bar messages, in order of priority for showing to the user -enum { +enum StatusPriority { eStatusLinkTarget = 0, // link mouseover info eStatusProgress = 1, // loading progress eStatusScript = 2, // javascript window.status @@ -110,6 +110,8 @@ enum { - (void)updateSiteIconImage:(NSImage*)inSiteIcon withURI:(NSString *)inSiteIconURI loadError:(BOOL)inLoadError; +- (void)updateStatusString:(NSString*)statusString withPriority:(StatusPriority)priority; + - (void)setPendingURI:(NSString*)inURI; - (NSString*)displayTitleForPageURL:(NSString*)inURL title:(NSString*)inTitle; @@ -177,6 +179,8 @@ enum { mDisplayTitle = [[NSString alloc] init]; + mLoadingResources = [[NSMutableSet alloc] init]; + [self registerNotificationListener]; } return self; @@ -193,6 +197,7 @@ enum { [mSiteIconImage release]; [mSiteIconURI release]; [mStatusStrings release]; + [mLoadingResources release]; [mToolTip release]; [mDisplayTitle release]; @@ -490,9 +495,10 @@ enum { [mDelegate loadingStarted]; [mDelegate setLoadingActive:YES]; [mDelegate setLoadingProgress:mProgress]; - - [mStatusStrings replaceObjectAtIndex:eStatusProgress withObject:NSLocalizedString(@"TabLoading", @"")]; - [mDelegate updateStatus:[self statusString]]; + + [mLoadingResources removeAllObjects]; + + [self updateStatusString:NSLocalizedString(@"TabLoading", @"") withPriority:eStatusProgress]; [(BrowserTabViewItem*)mTabItem startLoadAnimation]; @@ -510,9 +516,8 @@ enum { [self setPendingURI:nil]; [mDelegate setLoadingActive:NO]; - - [mStatusStrings replaceObjectAtIndex:eStatusProgress withObject:[NSNull null]]; - [mDelegate updateStatus:[self statusString]]; + + [self updateStatusString:nil withPriority:eStatusProgress]; [(BrowserTabViewItem*)mTabItem stopLoadAnimation]; @@ -537,6 +542,24 @@ enum { } } +- (void)onResourceLoadingStarted:(NSNumber*)resourceIdentifier +{ + [mLoadingResources addObject:resourceIdentifier]; +} + +- (void)onResourceLoadingCompleted:(NSNumber*)resourceIdentifier +{ + if ([mLoadingResources containsObject:resourceIdentifier]) + { + [mLoadingResources removeObject:resourceIdentifier]; + // When the last sub-resource finishes loading (which may be after + // onLoadingCompleted: is called), clear the status string, since otherwise + // it will stay stuck on the last loading message. + if ([mLoadingResources count] == 0) + [self updateStatusString:nil withPriority:eStatusProgress]; + } +} + - (void)onProgressChange64:(long long)currentBytes outOf:(long long)maxBytes { if (maxBytes > 0) @@ -623,8 +646,7 @@ enum { - (void)onStatusChange:(NSString*)aStatusString { - [mStatusStrings replaceObjectAtIndex:eStatusProgress withObject:aStatusString]; - [mDelegate updateStatus:[self statusString]]; + [self updateStatusString:aStatusString withPriority:eStatusProgress]; } // @@ -642,16 +664,24 @@ enum { - (void)setStatus:(NSString *)statusString ofType:(NSStatusType)type { - int index; + StatusPriority priority; if (type == NSStatusTypeScriptDefault) - index = eStatusScriptDefault; + priority = eStatusScriptDefault; else if (type == NSStatusTypeScript) - index = eStatusScript; + priority = eStatusScript; else - index = eStatusLinkTarget; + priority = eStatusLinkTarget; - [mStatusStrings replaceObjectAtIndex:index withObject:(statusString ? (id)statusString : (id)[NSNull null])]; + [self updateStatusString:statusString withPriority:priority]; +} + +// Private method to consolidate all status string changes, as status strings +// can come from Gecko through several callbacks. +- (void)updateStatusString:(NSString*)statusString withPriority:(StatusPriority)priority +{ + [mStatusStrings replaceObjectAtIndex:priority withObject:(statusString ? (id)statusString + : (id)[NSNull null])]; [mDelegate updateStatus:[self statusString]]; } diff --git a/camino/src/embedding/CHBrowserListener.mm b/camino/src/embedding/CHBrowserListener.mm index aa166fcb1f5..9822575451f 100644 --- a/camino/src/embedding/CHBrowserListener.mm +++ b/camino/src/embedding/CHBrowserListener.mm @@ -680,18 +680,21 @@ CHBrowserListener::OnStateChange(nsIWebProgress *aWebProgress, nsIRequest *aRequ { NSEnumerator* enumerator = [mListeners objectEnumerator]; id obj; - if (aStateFlags & nsIWebProgressListener::STATE_IS_NETWORK) - { - if (aStateFlags & nsIWebProgressListener::STATE_START) - { + if (aStateFlags & nsIWebProgressListener::STATE_START) { + if (aStateFlags & nsIWebProgressListener::STATE_IS_NETWORK) { while ((obj = [enumerator nextObject])) [obj onLoadingStarted]; } - else if (aStateFlags & nsIWebProgressListener::STATE_STOP) - { + while ((obj = [enumerator nextObject])) + [obj onResourceLoadingStarted:[NSNumber numberWithUnsignedLongLong:(unsigned long long)aRequest]]; + } + else if (aStateFlags & nsIWebProgressListener::STATE_STOP) { + if (aStateFlags & nsIWebProgressListener::STATE_IS_NETWORK) { while ((obj = [enumerator nextObject])) [obj onLoadingCompleted:(NS_SUCCEEDED(aStatus))]; } + while ((obj = [enumerator nextObject])) + [obj onResourceLoadingCompleted:[NSNumber numberWithUnsignedLongLong:(unsigned long long)aRequest]]; } return NS_OK; diff --git a/camino/src/embedding/CHBrowserView.h b/camino/src/embedding/CHBrowserView.h index e0e74112e62..dc21587724b 100644 --- a/camino/src/embedding/CHBrowserView.h +++ b/camino/src/embedding/CHBrowserView.h @@ -68,6 +68,10 @@ class nsISecureBrowserUI; - (void)onLoadingStarted; - (void)onLoadingCompleted:(BOOL)succeeded; +// Called when each resource on a page (the main HTML plus any subsidiary +// resources such as images and style sheets) starts ond finishes. +- (void)onResourceLoadingStarted:(NSNumber*)resourceIdentifier; +- (void)onResourceLoadingCompleted:(NSNumber*)resourceIdentifier; // Invoked regularly as data associated with a page streams // in. If the total number of bytes expected is unknown, // maxBytes is -1. diff --git a/camino/src/formfill/KeychainService.mm b/camino/src/formfill/KeychainService.mm index fd0667bc6cd..92107151c3b 100644 --- a/camino/src/formfill/KeychainService.mm +++ b/camino/src/formfill/KeychainService.mm @@ -1122,6 +1122,14 @@ KeychainFormSubmitObserver::Notify(nsIDOMHTMLFormElement* formNode, nsIDOMWindow { } +- (void)onResourceLoadingStarted:(NSNumber*)resourceIdentifier +{ +} + +- (void)onResourceLoadingCompleted:(NSNumber*)resourceIdentifier +{ +} + - (void)onProgressChange:(long)currentBytes outOf:(long)maxBytes { }