From 1656ccbcf9f06a9cfc60d508968cabc90606003a Mon Sep 17 00:00:00 2001 From: "hyatt%netscape.com" Date: Mon, 29 Apr 2002 01:28:30 +0000 Subject: [PATCH] More work on importing of bookmarks. --- camino/BookmarksService.h | 4 +++ camino/BookmarksService.mm | 6 ++++ camino/BrowserWindowController.h | 1 + camino/BrowserWindowController.mm | 13 ++++++++ camino/CHBrowserWrapper.h | 4 ++- camino/CHBrowserWrapper.mm | 30 ++++++++++++++++--- camino/MainController.mm | 12 ++++++-- camino/src/application/MainController.mm | 12 ++++++-- camino/src/bookmarks/BookmarksService.h | 4 +++ camino/src/bookmarks/BookmarksService.mm | 6 ++++ camino/src/browser/BrowserWindowController.h | 1 + camino/src/browser/BrowserWindowController.mm | 13 ++++++++ camino/src/browser/BrowserWrapper.h | 4 ++- camino/src/browser/BrowserWrapper.mm | 30 ++++++++++++++++--- chimera/BookmarksService.h | 4 +++ chimera/BookmarksService.mm | 6 ++++ chimera/BrowserWindowController.h | 1 + chimera/BrowserWindowController.mm | 13 ++++++++ chimera/CHBrowserWrapper.h | 4 ++- chimera/CHBrowserWrapper.mm | 30 ++++++++++++++++--- chimera/MainController.mm | 12 ++++++-- chimera/src/application/MainController.mm | 12 ++++++-- chimera/src/bookmarks/BookmarksService.h | 4 +++ chimera/src/bookmarks/BookmarksService.mm | 6 ++++ chimera/src/browser/BrowserWindowController.h | 1 + .../src/browser/BrowserWindowController.mm | 13 ++++++++ chimera/src/browser/BrowserWrapper.h | 4 ++- chimera/src/browser/BrowserWrapper.mm | 30 ++++++++++++++++--- 28 files changed, 252 insertions(+), 28 deletions(-) diff --git a/camino/BookmarksService.h b/camino/BookmarksService.h index 75789ae329e..3733173b196 100644 --- a/camino/BookmarksService.h +++ b/camino/BookmarksService.h @@ -97,6 +97,8 @@ class nsIAtom; - (id)copyWithZone:(NSZone *)aZone; @end +class nsIDOMHTMLDocument; + class BookmarksService { public: @@ -125,6 +127,8 @@ public: static void EnsureToolbarRoot(); + static void ImportBookmarks(nsIDOMHTMLDocument* aHTMLDoc); + static void GetTitleAndHrefForBrowserView(id aBrowserView, nsString& aTitle, nsString& aHref); static void OpenBookmarkGroup(id aTabView, nsIDOMElement* aFolder); diff --git a/camino/BookmarksService.mm b/camino/BookmarksService.mm index 754ba4a86c2..229c3d045d9 100644 --- a/camino/BookmarksService.mm +++ b/camino/BookmarksService.mm @@ -979,6 +979,12 @@ BookmarksService::OpenMenuBookmark(BrowserWindowController* aController, id aMen [[[aController getBrowserWrapper] getBrowserView] setActive: YES]; } +void +BookmarksService::ImportBookmarks(nsIDOMHTMLDocument* aHTMLDoc) +{ + +} + void BookmarksService::OpenBookmarkGroup(id aTabView, nsIDOMElement* aFolder) { diff --git a/camino/BrowserWindowController.h b/camino/BrowserWindowController.h index d34f0f5dac9..351d7940625 100644 --- a/camino/BrowserWindowController.h +++ b/camino/BrowserWindowController.h @@ -138,6 +138,7 @@ class nsIDOMNode; - (void)addBookmarkExtended: (BOOL)aIsFromMenu isFolder:(BOOL)aIsFolder; - (IBAction)manageBookmarks: (id)aSender; +- (void)importBookmarks: (NSURL*)aURL; - (IBAction)toggleSidebar:(id)aSender; - (void)newTab; diff --git a/camino/BrowserWindowController.mm b/camino/BrowserWindowController.mm index 2e0cd25bd57..33d61eb485d 100644 --- a/camino/BrowserWindowController.mm +++ b/camino/BrowserWindowController.mm @@ -472,6 +472,19 @@ static NSString *PrintToolbarItemIdentifier = @"Print Toolbar Item"; [mSidebarTabView selectFirstTabViewItem:self]; } +- (void)importBookmarks: (NSURL*)aURL +{ + // Open the bookmarks sidebar. + [self manageBookmarks: self]; + + // Now do the importing. + CHBrowserWrapper* newView = [[[CHBrowserWrapper alloc] initWithTab: nil andWindow: [self window]] autorelease]; + [newView setFrame: NSZeroRect]; + [newView setIsBookmarksImport: YES]; + [[[self window] contentView] addSubview: newView]; + [[newView getBrowserView] loadURI:aURL flags:NSLoadFlagsNone]; +} + - (IBAction)goToLocationFromToolbarURLField:(id)sender { [self loadURL:[NSURL URLWithString:[sender stringValue]]]; diff --git a/camino/CHBrowserWrapper.h b/camino/CHBrowserWrapper.h index 7d315a291fc..b45d6c81cea 100644 --- a/camino/CHBrowserWrapper.h +++ b/camino/CHBrowserWrapper.h @@ -57,6 +57,8 @@ BOOL mOffline; BOOL mListenersAttached; // We hook up our click and context menu listeners lazily. // If we never become the primary view, we don't bother creating the listeners. + BOOL mIsBookmarksImport; // This view was created for the purpose of importing bookmarks. Upon + // completion, we need to do the import and then destroy ourselves. } - (IBAction)load:(id)sender; @@ -74,8 +76,8 @@ -(void)setTab: (NSTabViewItem*)tab; -(NSWindow*)getNativeWindow; - -(NSMenu*)getContextMenu; +-(void)setIsBookmarksImport:(BOOL)aIsImport; -(id)initWithTab:(id)aTab andWindow:(NSWindow*)aWindow; diff --git a/camino/CHBrowserWrapper.mm b/camino/CHBrowserWrapper.mm index d459866799c..3d0a10059a6 100644 --- a/camino/CHBrowserWrapper.mm +++ b/camino/CHBrowserWrapper.mm @@ -37,12 +37,16 @@ #import "CHBrowserWrapper.h" #import "BrowserWindowController.h" +#import "BookmarksService.h" #include "nsCOMPtr.h" #include "nsIServiceManager.h" #include "nsIIOService.h" #include "ContentClickListener.h" #include "nsIDOMWindow.h" +#include "nsIWebBrowser.h" +#include "nsIDOMDocument.h" +#include "nsIDOMHTMLDocument.h" #include "nsIChromeEventHandler.h" #include "nsPIDOMWindow.h" #include "nsIDOMEventReceiver.h" @@ -98,6 +102,7 @@ static const char* ioServiceContractID = "@mozilla.org/network/io-service;1"; { mTab = aTab; mWindow = aWindow; + mIsBookmarksImport = NO; return [self initWithFrame: NSZeroRect]; } @@ -219,9 +224,6 @@ static const char* ioServiceContractID = "@mozilla.org/network/io-service;1"; if (mWindowController) [mWindowController updateToolbarItems]; - else { - printf("background load.\n"); - } } - (void)onLoadingCompleted:(BOOL)succeeded @@ -239,7 +241,22 @@ static const char* ioServiceContractID = "@mozilla.org/network/io-service;1"; } mIsBusy = NO; - + + if (mIsBookmarksImport) { + nsCOMPtr domWindow; + nsCOMPtr webBrowser = getter_AddRefs([mBrowserView getWebBrowser]); + webBrowser->GetContentDOMWindow(getter_AddRefs(domWindow)); + if (domWindow) { + nsCOMPtr domDocument; + domWindow->GetDocument(getter_AddRefs(domDocument)); + nsCOMPtr htmlDoc(do_QueryInterface(domDocument)); + if (htmlDoc) + BookmarksService::ImportBookmarks(htmlDoc); + } + [self windowClosed]; + [self removeFromSuperview]; + } + if (mWindowController) [mWindowController updateToolbarItems]; } @@ -346,6 +363,11 @@ static const char* ioServiceContractID = "@mozilla.org/network/io-service;1"; return nil; } +-(void)setIsBookmarksImport:(BOOL)aIsImport +{ + mIsBookmarksImport = aIsImport; +} + - (void)offlineModeChanged: (NSNotification*)aNotification { nsCOMPtr ioService(do_GetService(ioServiceContractID)); diff --git a/camino/MainController.mm b/camino/MainController.mm index a724ff5a780..008b2fbe8b2 100644 --- a/camino/MainController.mm +++ b/camino/MainController.mm @@ -130,7 +130,7 @@ static const char* ioServiceContractID = "@mozilla.org/network/io-service;1"; -(IBAction) openFile:(id)aSender { - NSOpenPanel* openPanel = [[NSOpenPanel alloc] init]; + NSOpenPanel* openPanel = [[[NSOpenPanel alloc] init] autorelease]; [openPanel setCanChooseFiles: YES]; [openPanel setCanChooseDirectories: NO]; [openPanel setAllowsMultipleSelection: NO]; @@ -293,7 +293,7 @@ static const char* ioServiceContractID = "@mozilla.org/network/io-service;1"; // IE favorites: ~/Library/Preferences/Explorer/Favorites.html // Omniweb favorites: ~/Library/Application Support/Omniweb/Bookmarks.html // For now, open the panel to IE's favorites. - NSOpenPanel* openPanel = [[NSOpenPanel alloc] init]; + NSOpenPanel* openPanel = [[[NSOpenPanel alloc] init] autorelease]; [openPanel setCanChooseFiles: YES]; [openPanel setCanChooseDirectories: NO]; [openPanel setAllowsMultipleSelection: NO]; @@ -306,6 +306,14 @@ static const char* ioServiceContractID = "@mozilla.org/network/io-service;1"; if ([urlArray count] == 0) return; NSURL* url = [urlArray objectAtIndex: 0]; + + NSWindow* window = [mApplication mainWindow]; + if (!window) { + [self newWindow: self]; + window = [mApplication mainWindow]; + } + + [[window windowController] importBookmarks: url]; } } diff --git a/camino/src/application/MainController.mm b/camino/src/application/MainController.mm index a724ff5a780..008b2fbe8b2 100644 --- a/camino/src/application/MainController.mm +++ b/camino/src/application/MainController.mm @@ -130,7 +130,7 @@ static const char* ioServiceContractID = "@mozilla.org/network/io-service;1"; -(IBAction) openFile:(id)aSender { - NSOpenPanel* openPanel = [[NSOpenPanel alloc] init]; + NSOpenPanel* openPanel = [[[NSOpenPanel alloc] init] autorelease]; [openPanel setCanChooseFiles: YES]; [openPanel setCanChooseDirectories: NO]; [openPanel setAllowsMultipleSelection: NO]; @@ -293,7 +293,7 @@ static const char* ioServiceContractID = "@mozilla.org/network/io-service;1"; // IE favorites: ~/Library/Preferences/Explorer/Favorites.html // Omniweb favorites: ~/Library/Application Support/Omniweb/Bookmarks.html // For now, open the panel to IE's favorites. - NSOpenPanel* openPanel = [[NSOpenPanel alloc] init]; + NSOpenPanel* openPanel = [[[NSOpenPanel alloc] init] autorelease]; [openPanel setCanChooseFiles: YES]; [openPanel setCanChooseDirectories: NO]; [openPanel setAllowsMultipleSelection: NO]; @@ -306,6 +306,14 @@ static const char* ioServiceContractID = "@mozilla.org/network/io-service;1"; if ([urlArray count] == 0) return; NSURL* url = [urlArray objectAtIndex: 0]; + + NSWindow* window = [mApplication mainWindow]; + if (!window) { + [self newWindow: self]; + window = [mApplication mainWindow]; + } + + [[window windowController] importBookmarks: url]; } } diff --git a/camino/src/bookmarks/BookmarksService.h b/camino/src/bookmarks/BookmarksService.h index 75789ae329e..3733173b196 100644 --- a/camino/src/bookmarks/BookmarksService.h +++ b/camino/src/bookmarks/BookmarksService.h @@ -97,6 +97,8 @@ class nsIAtom; - (id)copyWithZone:(NSZone *)aZone; @end +class nsIDOMHTMLDocument; + class BookmarksService { public: @@ -125,6 +127,8 @@ public: static void EnsureToolbarRoot(); + static void ImportBookmarks(nsIDOMHTMLDocument* aHTMLDoc); + static void GetTitleAndHrefForBrowserView(id aBrowserView, nsString& aTitle, nsString& aHref); static void OpenBookmarkGroup(id aTabView, nsIDOMElement* aFolder); diff --git a/camino/src/bookmarks/BookmarksService.mm b/camino/src/bookmarks/BookmarksService.mm index 754ba4a86c2..229c3d045d9 100644 --- a/camino/src/bookmarks/BookmarksService.mm +++ b/camino/src/bookmarks/BookmarksService.mm @@ -979,6 +979,12 @@ BookmarksService::OpenMenuBookmark(BrowserWindowController* aController, id aMen [[[aController getBrowserWrapper] getBrowserView] setActive: YES]; } +void +BookmarksService::ImportBookmarks(nsIDOMHTMLDocument* aHTMLDoc) +{ + +} + void BookmarksService::OpenBookmarkGroup(id aTabView, nsIDOMElement* aFolder) { diff --git a/camino/src/browser/BrowserWindowController.h b/camino/src/browser/BrowserWindowController.h index d34f0f5dac9..351d7940625 100644 --- a/camino/src/browser/BrowserWindowController.h +++ b/camino/src/browser/BrowserWindowController.h @@ -138,6 +138,7 @@ class nsIDOMNode; - (void)addBookmarkExtended: (BOOL)aIsFromMenu isFolder:(BOOL)aIsFolder; - (IBAction)manageBookmarks: (id)aSender; +- (void)importBookmarks: (NSURL*)aURL; - (IBAction)toggleSidebar:(id)aSender; - (void)newTab; diff --git a/camino/src/browser/BrowserWindowController.mm b/camino/src/browser/BrowserWindowController.mm index 2e0cd25bd57..33d61eb485d 100644 --- a/camino/src/browser/BrowserWindowController.mm +++ b/camino/src/browser/BrowserWindowController.mm @@ -472,6 +472,19 @@ static NSString *PrintToolbarItemIdentifier = @"Print Toolbar Item"; [mSidebarTabView selectFirstTabViewItem:self]; } +- (void)importBookmarks: (NSURL*)aURL +{ + // Open the bookmarks sidebar. + [self manageBookmarks: self]; + + // Now do the importing. + CHBrowserWrapper* newView = [[[CHBrowserWrapper alloc] initWithTab: nil andWindow: [self window]] autorelease]; + [newView setFrame: NSZeroRect]; + [newView setIsBookmarksImport: YES]; + [[[self window] contentView] addSubview: newView]; + [[newView getBrowserView] loadURI:aURL flags:NSLoadFlagsNone]; +} + - (IBAction)goToLocationFromToolbarURLField:(id)sender { [self loadURL:[NSURL URLWithString:[sender stringValue]]]; diff --git a/camino/src/browser/BrowserWrapper.h b/camino/src/browser/BrowserWrapper.h index 7d315a291fc..b45d6c81cea 100644 --- a/camino/src/browser/BrowserWrapper.h +++ b/camino/src/browser/BrowserWrapper.h @@ -57,6 +57,8 @@ BOOL mOffline; BOOL mListenersAttached; // We hook up our click and context menu listeners lazily. // If we never become the primary view, we don't bother creating the listeners. + BOOL mIsBookmarksImport; // This view was created for the purpose of importing bookmarks. Upon + // completion, we need to do the import and then destroy ourselves. } - (IBAction)load:(id)sender; @@ -74,8 +76,8 @@ -(void)setTab: (NSTabViewItem*)tab; -(NSWindow*)getNativeWindow; - -(NSMenu*)getContextMenu; +-(void)setIsBookmarksImport:(BOOL)aIsImport; -(id)initWithTab:(id)aTab andWindow:(NSWindow*)aWindow; diff --git a/camino/src/browser/BrowserWrapper.mm b/camino/src/browser/BrowserWrapper.mm index d459866799c..3d0a10059a6 100644 --- a/camino/src/browser/BrowserWrapper.mm +++ b/camino/src/browser/BrowserWrapper.mm @@ -37,12 +37,16 @@ #import "CHBrowserWrapper.h" #import "BrowserWindowController.h" +#import "BookmarksService.h" #include "nsCOMPtr.h" #include "nsIServiceManager.h" #include "nsIIOService.h" #include "ContentClickListener.h" #include "nsIDOMWindow.h" +#include "nsIWebBrowser.h" +#include "nsIDOMDocument.h" +#include "nsIDOMHTMLDocument.h" #include "nsIChromeEventHandler.h" #include "nsPIDOMWindow.h" #include "nsIDOMEventReceiver.h" @@ -98,6 +102,7 @@ static const char* ioServiceContractID = "@mozilla.org/network/io-service;1"; { mTab = aTab; mWindow = aWindow; + mIsBookmarksImport = NO; return [self initWithFrame: NSZeroRect]; } @@ -219,9 +224,6 @@ static const char* ioServiceContractID = "@mozilla.org/network/io-service;1"; if (mWindowController) [mWindowController updateToolbarItems]; - else { - printf("background load.\n"); - } } - (void)onLoadingCompleted:(BOOL)succeeded @@ -239,7 +241,22 @@ static const char* ioServiceContractID = "@mozilla.org/network/io-service;1"; } mIsBusy = NO; - + + if (mIsBookmarksImport) { + nsCOMPtr domWindow; + nsCOMPtr webBrowser = getter_AddRefs([mBrowserView getWebBrowser]); + webBrowser->GetContentDOMWindow(getter_AddRefs(domWindow)); + if (domWindow) { + nsCOMPtr domDocument; + domWindow->GetDocument(getter_AddRefs(domDocument)); + nsCOMPtr htmlDoc(do_QueryInterface(domDocument)); + if (htmlDoc) + BookmarksService::ImportBookmarks(htmlDoc); + } + [self windowClosed]; + [self removeFromSuperview]; + } + if (mWindowController) [mWindowController updateToolbarItems]; } @@ -346,6 +363,11 @@ static const char* ioServiceContractID = "@mozilla.org/network/io-service;1"; return nil; } +-(void)setIsBookmarksImport:(BOOL)aIsImport +{ + mIsBookmarksImport = aIsImport; +} + - (void)offlineModeChanged: (NSNotification*)aNotification { nsCOMPtr ioService(do_GetService(ioServiceContractID)); diff --git a/chimera/BookmarksService.h b/chimera/BookmarksService.h index 75789ae329e..3733173b196 100644 --- a/chimera/BookmarksService.h +++ b/chimera/BookmarksService.h @@ -97,6 +97,8 @@ class nsIAtom; - (id)copyWithZone:(NSZone *)aZone; @end +class nsIDOMHTMLDocument; + class BookmarksService { public: @@ -125,6 +127,8 @@ public: static void EnsureToolbarRoot(); + static void ImportBookmarks(nsIDOMHTMLDocument* aHTMLDoc); + static void GetTitleAndHrefForBrowserView(id aBrowserView, nsString& aTitle, nsString& aHref); static void OpenBookmarkGroup(id aTabView, nsIDOMElement* aFolder); diff --git a/chimera/BookmarksService.mm b/chimera/BookmarksService.mm index 754ba4a86c2..229c3d045d9 100644 --- a/chimera/BookmarksService.mm +++ b/chimera/BookmarksService.mm @@ -979,6 +979,12 @@ BookmarksService::OpenMenuBookmark(BrowserWindowController* aController, id aMen [[[aController getBrowserWrapper] getBrowserView] setActive: YES]; } +void +BookmarksService::ImportBookmarks(nsIDOMHTMLDocument* aHTMLDoc) +{ + +} + void BookmarksService::OpenBookmarkGroup(id aTabView, nsIDOMElement* aFolder) { diff --git a/chimera/BrowserWindowController.h b/chimera/BrowserWindowController.h index d34f0f5dac9..351d7940625 100644 --- a/chimera/BrowserWindowController.h +++ b/chimera/BrowserWindowController.h @@ -138,6 +138,7 @@ class nsIDOMNode; - (void)addBookmarkExtended: (BOOL)aIsFromMenu isFolder:(BOOL)aIsFolder; - (IBAction)manageBookmarks: (id)aSender; +- (void)importBookmarks: (NSURL*)aURL; - (IBAction)toggleSidebar:(id)aSender; - (void)newTab; diff --git a/chimera/BrowserWindowController.mm b/chimera/BrowserWindowController.mm index 2e0cd25bd57..33d61eb485d 100644 --- a/chimera/BrowserWindowController.mm +++ b/chimera/BrowserWindowController.mm @@ -472,6 +472,19 @@ static NSString *PrintToolbarItemIdentifier = @"Print Toolbar Item"; [mSidebarTabView selectFirstTabViewItem:self]; } +- (void)importBookmarks: (NSURL*)aURL +{ + // Open the bookmarks sidebar. + [self manageBookmarks: self]; + + // Now do the importing. + CHBrowserWrapper* newView = [[[CHBrowserWrapper alloc] initWithTab: nil andWindow: [self window]] autorelease]; + [newView setFrame: NSZeroRect]; + [newView setIsBookmarksImport: YES]; + [[[self window] contentView] addSubview: newView]; + [[newView getBrowserView] loadURI:aURL flags:NSLoadFlagsNone]; +} + - (IBAction)goToLocationFromToolbarURLField:(id)sender { [self loadURL:[NSURL URLWithString:[sender stringValue]]]; diff --git a/chimera/CHBrowserWrapper.h b/chimera/CHBrowserWrapper.h index 7d315a291fc..b45d6c81cea 100644 --- a/chimera/CHBrowserWrapper.h +++ b/chimera/CHBrowserWrapper.h @@ -57,6 +57,8 @@ BOOL mOffline; BOOL mListenersAttached; // We hook up our click and context menu listeners lazily. // If we never become the primary view, we don't bother creating the listeners. + BOOL mIsBookmarksImport; // This view was created for the purpose of importing bookmarks. Upon + // completion, we need to do the import and then destroy ourselves. } - (IBAction)load:(id)sender; @@ -74,8 +76,8 @@ -(void)setTab: (NSTabViewItem*)tab; -(NSWindow*)getNativeWindow; - -(NSMenu*)getContextMenu; +-(void)setIsBookmarksImport:(BOOL)aIsImport; -(id)initWithTab:(id)aTab andWindow:(NSWindow*)aWindow; diff --git a/chimera/CHBrowserWrapper.mm b/chimera/CHBrowserWrapper.mm index d459866799c..3d0a10059a6 100644 --- a/chimera/CHBrowserWrapper.mm +++ b/chimera/CHBrowserWrapper.mm @@ -37,12 +37,16 @@ #import "CHBrowserWrapper.h" #import "BrowserWindowController.h" +#import "BookmarksService.h" #include "nsCOMPtr.h" #include "nsIServiceManager.h" #include "nsIIOService.h" #include "ContentClickListener.h" #include "nsIDOMWindow.h" +#include "nsIWebBrowser.h" +#include "nsIDOMDocument.h" +#include "nsIDOMHTMLDocument.h" #include "nsIChromeEventHandler.h" #include "nsPIDOMWindow.h" #include "nsIDOMEventReceiver.h" @@ -98,6 +102,7 @@ static const char* ioServiceContractID = "@mozilla.org/network/io-service;1"; { mTab = aTab; mWindow = aWindow; + mIsBookmarksImport = NO; return [self initWithFrame: NSZeroRect]; } @@ -219,9 +224,6 @@ static const char* ioServiceContractID = "@mozilla.org/network/io-service;1"; if (mWindowController) [mWindowController updateToolbarItems]; - else { - printf("background load.\n"); - } } - (void)onLoadingCompleted:(BOOL)succeeded @@ -239,7 +241,22 @@ static const char* ioServiceContractID = "@mozilla.org/network/io-service;1"; } mIsBusy = NO; - + + if (mIsBookmarksImport) { + nsCOMPtr domWindow; + nsCOMPtr webBrowser = getter_AddRefs([mBrowserView getWebBrowser]); + webBrowser->GetContentDOMWindow(getter_AddRefs(domWindow)); + if (domWindow) { + nsCOMPtr domDocument; + domWindow->GetDocument(getter_AddRefs(domDocument)); + nsCOMPtr htmlDoc(do_QueryInterface(domDocument)); + if (htmlDoc) + BookmarksService::ImportBookmarks(htmlDoc); + } + [self windowClosed]; + [self removeFromSuperview]; + } + if (mWindowController) [mWindowController updateToolbarItems]; } @@ -346,6 +363,11 @@ static const char* ioServiceContractID = "@mozilla.org/network/io-service;1"; return nil; } +-(void)setIsBookmarksImport:(BOOL)aIsImport +{ + mIsBookmarksImport = aIsImport; +} + - (void)offlineModeChanged: (NSNotification*)aNotification { nsCOMPtr ioService(do_GetService(ioServiceContractID)); diff --git a/chimera/MainController.mm b/chimera/MainController.mm index a724ff5a780..008b2fbe8b2 100644 --- a/chimera/MainController.mm +++ b/chimera/MainController.mm @@ -130,7 +130,7 @@ static const char* ioServiceContractID = "@mozilla.org/network/io-service;1"; -(IBAction) openFile:(id)aSender { - NSOpenPanel* openPanel = [[NSOpenPanel alloc] init]; + NSOpenPanel* openPanel = [[[NSOpenPanel alloc] init] autorelease]; [openPanel setCanChooseFiles: YES]; [openPanel setCanChooseDirectories: NO]; [openPanel setAllowsMultipleSelection: NO]; @@ -293,7 +293,7 @@ static const char* ioServiceContractID = "@mozilla.org/network/io-service;1"; // IE favorites: ~/Library/Preferences/Explorer/Favorites.html // Omniweb favorites: ~/Library/Application Support/Omniweb/Bookmarks.html // For now, open the panel to IE's favorites. - NSOpenPanel* openPanel = [[NSOpenPanel alloc] init]; + NSOpenPanel* openPanel = [[[NSOpenPanel alloc] init] autorelease]; [openPanel setCanChooseFiles: YES]; [openPanel setCanChooseDirectories: NO]; [openPanel setAllowsMultipleSelection: NO]; @@ -306,6 +306,14 @@ static const char* ioServiceContractID = "@mozilla.org/network/io-service;1"; if ([urlArray count] == 0) return; NSURL* url = [urlArray objectAtIndex: 0]; + + NSWindow* window = [mApplication mainWindow]; + if (!window) { + [self newWindow: self]; + window = [mApplication mainWindow]; + } + + [[window windowController] importBookmarks: url]; } } diff --git a/chimera/src/application/MainController.mm b/chimera/src/application/MainController.mm index a724ff5a780..008b2fbe8b2 100644 --- a/chimera/src/application/MainController.mm +++ b/chimera/src/application/MainController.mm @@ -130,7 +130,7 @@ static const char* ioServiceContractID = "@mozilla.org/network/io-service;1"; -(IBAction) openFile:(id)aSender { - NSOpenPanel* openPanel = [[NSOpenPanel alloc] init]; + NSOpenPanel* openPanel = [[[NSOpenPanel alloc] init] autorelease]; [openPanel setCanChooseFiles: YES]; [openPanel setCanChooseDirectories: NO]; [openPanel setAllowsMultipleSelection: NO]; @@ -293,7 +293,7 @@ static const char* ioServiceContractID = "@mozilla.org/network/io-service;1"; // IE favorites: ~/Library/Preferences/Explorer/Favorites.html // Omniweb favorites: ~/Library/Application Support/Omniweb/Bookmarks.html // For now, open the panel to IE's favorites. - NSOpenPanel* openPanel = [[NSOpenPanel alloc] init]; + NSOpenPanel* openPanel = [[[NSOpenPanel alloc] init] autorelease]; [openPanel setCanChooseFiles: YES]; [openPanel setCanChooseDirectories: NO]; [openPanel setAllowsMultipleSelection: NO]; @@ -306,6 +306,14 @@ static const char* ioServiceContractID = "@mozilla.org/network/io-service;1"; if ([urlArray count] == 0) return; NSURL* url = [urlArray objectAtIndex: 0]; + + NSWindow* window = [mApplication mainWindow]; + if (!window) { + [self newWindow: self]; + window = [mApplication mainWindow]; + } + + [[window windowController] importBookmarks: url]; } } diff --git a/chimera/src/bookmarks/BookmarksService.h b/chimera/src/bookmarks/BookmarksService.h index 75789ae329e..3733173b196 100644 --- a/chimera/src/bookmarks/BookmarksService.h +++ b/chimera/src/bookmarks/BookmarksService.h @@ -97,6 +97,8 @@ class nsIAtom; - (id)copyWithZone:(NSZone *)aZone; @end +class nsIDOMHTMLDocument; + class BookmarksService { public: @@ -125,6 +127,8 @@ public: static void EnsureToolbarRoot(); + static void ImportBookmarks(nsIDOMHTMLDocument* aHTMLDoc); + static void GetTitleAndHrefForBrowserView(id aBrowserView, nsString& aTitle, nsString& aHref); static void OpenBookmarkGroup(id aTabView, nsIDOMElement* aFolder); diff --git a/chimera/src/bookmarks/BookmarksService.mm b/chimera/src/bookmarks/BookmarksService.mm index 754ba4a86c2..229c3d045d9 100644 --- a/chimera/src/bookmarks/BookmarksService.mm +++ b/chimera/src/bookmarks/BookmarksService.mm @@ -979,6 +979,12 @@ BookmarksService::OpenMenuBookmark(BrowserWindowController* aController, id aMen [[[aController getBrowserWrapper] getBrowserView] setActive: YES]; } +void +BookmarksService::ImportBookmarks(nsIDOMHTMLDocument* aHTMLDoc) +{ + +} + void BookmarksService::OpenBookmarkGroup(id aTabView, nsIDOMElement* aFolder) { diff --git a/chimera/src/browser/BrowserWindowController.h b/chimera/src/browser/BrowserWindowController.h index d34f0f5dac9..351d7940625 100644 --- a/chimera/src/browser/BrowserWindowController.h +++ b/chimera/src/browser/BrowserWindowController.h @@ -138,6 +138,7 @@ class nsIDOMNode; - (void)addBookmarkExtended: (BOOL)aIsFromMenu isFolder:(BOOL)aIsFolder; - (IBAction)manageBookmarks: (id)aSender; +- (void)importBookmarks: (NSURL*)aURL; - (IBAction)toggleSidebar:(id)aSender; - (void)newTab; diff --git a/chimera/src/browser/BrowserWindowController.mm b/chimera/src/browser/BrowserWindowController.mm index 2e0cd25bd57..33d61eb485d 100644 --- a/chimera/src/browser/BrowserWindowController.mm +++ b/chimera/src/browser/BrowserWindowController.mm @@ -472,6 +472,19 @@ static NSString *PrintToolbarItemIdentifier = @"Print Toolbar Item"; [mSidebarTabView selectFirstTabViewItem:self]; } +- (void)importBookmarks: (NSURL*)aURL +{ + // Open the bookmarks sidebar. + [self manageBookmarks: self]; + + // Now do the importing. + CHBrowserWrapper* newView = [[[CHBrowserWrapper alloc] initWithTab: nil andWindow: [self window]] autorelease]; + [newView setFrame: NSZeroRect]; + [newView setIsBookmarksImport: YES]; + [[[self window] contentView] addSubview: newView]; + [[newView getBrowserView] loadURI:aURL flags:NSLoadFlagsNone]; +} + - (IBAction)goToLocationFromToolbarURLField:(id)sender { [self loadURL:[NSURL URLWithString:[sender stringValue]]]; diff --git a/chimera/src/browser/BrowserWrapper.h b/chimera/src/browser/BrowserWrapper.h index 7d315a291fc..b45d6c81cea 100644 --- a/chimera/src/browser/BrowserWrapper.h +++ b/chimera/src/browser/BrowserWrapper.h @@ -57,6 +57,8 @@ BOOL mOffline; BOOL mListenersAttached; // We hook up our click and context menu listeners lazily. // If we never become the primary view, we don't bother creating the listeners. + BOOL mIsBookmarksImport; // This view was created for the purpose of importing bookmarks. Upon + // completion, we need to do the import and then destroy ourselves. } - (IBAction)load:(id)sender; @@ -74,8 +76,8 @@ -(void)setTab: (NSTabViewItem*)tab; -(NSWindow*)getNativeWindow; - -(NSMenu*)getContextMenu; +-(void)setIsBookmarksImport:(BOOL)aIsImport; -(id)initWithTab:(id)aTab andWindow:(NSWindow*)aWindow; diff --git a/chimera/src/browser/BrowserWrapper.mm b/chimera/src/browser/BrowserWrapper.mm index d459866799c..3d0a10059a6 100644 --- a/chimera/src/browser/BrowserWrapper.mm +++ b/chimera/src/browser/BrowserWrapper.mm @@ -37,12 +37,16 @@ #import "CHBrowserWrapper.h" #import "BrowserWindowController.h" +#import "BookmarksService.h" #include "nsCOMPtr.h" #include "nsIServiceManager.h" #include "nsIIOService.h" #include "ContentClickListener.h" #include "nsIDOMWindow.h" +#include "nsIWebBrowser.h" +#include "nsIDOMDocument.h" +#include "nsIDOMHTMLDocument.h" #include "nsIChromeEventHandler.h" #include "nsPIDOMWindow.h" #include "nsIDOMEventReceiver.h" @@ -98,6 +102,7 @@ static const char* ioServiceContractID = "@mozilla.org/network/io-service;1"; { mTab = aTab; mWindow = aWindow; + mIsBookmarksImport = NO; return [self initWithFrame: NSZeroRect]; } @@ -219,9 +224,6 @@ static const char* ioServiceContractID = "@mozilla.org/network/io-service;1"; if (mWindowController) [mWindowController updateToolbarItems]; - else { - printf("background load.\n"); - } } - (void)onLoadingCompleted:(BOOL)succeeded @@ -239,7 +241,22 @@ static const char* ioServiceContractID = "@mozilla.org/network/io-service;1"; } mIsBusy = NO; - + + if (mIsBookmarksImport) { + nsCOMPtr domWindow; + nsCOMPtr webBrowser = getter_AddRefs([mBrowserView getWebBrowser]); + webBrowser->GetContentDOMWindow(getter_AddRefs(domWindow)); + if (domWindow) { + nsCOMPtr domDocument; + domWindow->GetDocument(getter_AddRefs(domDocument)); + nsCOMPtr htmlDoc(do_QueryInterface(domDocument)); + if (htmlDoc) + BookmarksService::ImportBookmarks(htmlDoc); + } + [self windowClosed]; + [self removeFromSuperview]; + } + if (mWindowController) [mWindowController updateToolbarItems]; } @@ -346,6 +363,11 @@ static const char* ioServiceContractID = "@mozilla.org/network/io-service;1"; return nil; } +-(void)setIsBookmarksImport:(BOOL)aIsImport +{ + mIsBookmarksImport = aIsImport; +} + - (void)offlineModeChanged: (NSNotification*)aNotification { nsCOMPtr ioService(do_GetService(ioServiceContractID));