File:  [mozdev] / chimera / BookmarksService.mm
Revision 1.18: download - view: text, annotated - select for diffs - revision graph
Fri Apr 12 08:45:17 2002 UTC (17 years, 1 month ago) by hyatt
Branches: MAIN
CVS tags: HEAD
Fix a slew of activation issues.

    1: /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
    2: /* ***** BEGIN LICENSE BLOCK *****
    3:  * Version: NPL 1.1/GPL 2.0/LGPL 2.1
    4:  *
    5:  * The contents of this file are subject to the Netscape Public License
    6:  * Version 1.1 (the "License"); you may not use this file except in
    7:  * compliance with the License. You may obtain a copy of the License at
    8:  * http://www.mozilla.org/NPL/
    9:  *
   10:  * Software distributed under the License is distributed on an "AS IS" basis,
   11:  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
   12:  * for the specific language governing rights and limitations under the
   13:  * License.
   14:  *
   15:  * The Original Code is mozilla.org code.
   16:  *
   17:  * The Initial Developer of the Original Code is 
   18:  * Netscape Communications Corporation.
   19:  * Portions created by the Initial Developer are Copyright (C) 2002
   20:  * the Initial Developer. All Rights Reserved.
   21:  *
   22:  * Contributor(s):
   23:  *
   24:  * Alternatively, the contents of this file may be used under the terms of
   25:  * either the GNU General Public License Version 2 or later (the "GPL"), or 
   26:  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
   27:  * in which case the provisions of the GPL or the LGPL are applicable instead
   28:  * of those above. If you wish to allow use of your version of this file only
   29:  * under the terms of either the GPL or the LGPL, and not to allow others to
   30:  * use your version of this file under the terms of the NPL, indicate your
   31:  * decision by deleting the provisions above and replace them with the notice
   32:  * and other provisions required by the GPL or the LGPL. If you do not delete
   33:  * the provisions above, a recipient may use your version of this file under
   34:  * the terms of any one of the NPL, the GPL or the LGPL.
   35:  *
   36:  * ***** END LICENSE BLOCK ***** */
   37: 
   38: #import "NSBrowserView.h"
   39: #include "BookmarksService.h"
   40: #include "nsIDocument.h"
   41: #include "nsIContent.h"
   42: #include "nsIAtom.h"
   43: #include "nsITextContent.h"
   44: #include "nsIDOMWindow.h"
   45: #include "nsIDOMHTMLDocument.h"
   46: #include "nsIDOMElement.h"
   47: #include "nsString.h"
   48: #include "nsIFile.h"
   49: #include "nsAppDirectoryServiceDefs.h"
   50: #include "nsIXMLHttpRequest.h"
   51: #include "nsIDOMSerializer.h"
   52: #include "nsNetUtil.h"
   53: #include "nsINamespaceManager.h"
   54: #include "nsIXBLService.h"
   55: #include "nsIWebBrowser.h"
   56: 
   57: @implementation BookmarksDataSource
   58: 
   59: -(id) init
   60: {
   61:     [super init];
   62:     mBookmarks = nsnull;
   63:     return self;
   64: }
   65: 
   66: -(void) dealloc
   67: {
   68:     [super dealloc];
   69: }
   70: 
   71: -(void) windowClosing
   72: {
   73:     if (mBookmarks) {
   74:         mBookmarks->RemoveObserver();
   75:         delete mBookmarks;
   76:     }
   77: }
   78: 
   79: -(void) ensureBookmarks
   80: {
   81:     if (mBookmarks)
   82:         return;
   83:     
   84:     mBookmarks = new BookmarksService(self);
   85:     mBookmarks->AddObserver();
   86:     
   87:     [mOutlineView setTarget: self];
   88:     [mOutlineView setDoubleAction: @selector(openBookmark:)];
   89:     [mOutlineView reloadData];
   90: }
   91: 
   92: -(IBAction)addBookmark:(id)aSender
   93: {
   94:     if (!mBookmarks)
   95:         return;
   96:     
   97:     nsCOMPtr<nsIContent> content;
   98:     int index = [mOutlineView selectedRow];
   99:    
  100:     if (index >= 0) {
  101:         BookmarkItem* item = [mOutlineView itemAtRow: index];
  102:         if ([mOutlineView isExpandable: item]) 
  103:             content = [item contentNode];
  104:     }
  105:     
  106:     if (!content)
  107:         mBookmarks->GetRootContent(getter_AddRefs(content));
  108:         
  109:     nsCOMPtr<nsIDOMDocument> domDoc(do_QueryInterface(mBookmarks->gBookmarks));
  110:     nsCOMPtr<nsIDOMElement> elt;
  111:     domDoc->CreateElementNS(NS_LITERAL_STRING("http://chimera.mozdev.org/bookmarks"), 
  112:                             NS_LITERAL_STRING("bookmark"), 
  113:                             getter_AddRefs(elt));
  114:     
  115:     // Fetch the title of the current page and the URL.
  116:     nsCOMPtr<nsIWebBrowser> webBrowser = getter_AddRefs([[[mBrowserWindowController getMyBrowserView] getBrowserView] getWebBrowser]);
  117:     nsCOMPtr<nsIDOMWindow> window;
  118:     webBrowser->GetContentDOMWindow(getter_AddRefs(window));
  119:     nsCOMPtr<nsIDOMDocument> htmlDoc;
  120:     window->GetDocument(getter_AddRefs(htmlDoc));
  121:     nsCOMPtr<nsIDocument> pageDoc(do_QueryInterface(htmlDoc));
  122:     
  123:     nsAutoString href; 
  124:     if (pageDoc) {
  125:         nsCOMPtr<nsIURI> url;
  126:         pageDoc->GetDocumentURL(getter_AddRefs(url));
  127:         nsCAutoString spec;
  128:         url->GetSpec(spec);
  129:         href.AssignWithConversion(spec.get());
  130:     }
  131:     
  132:     nsAutoString title;
  133:     nsCOMPtr<nsIDOMHTMLDocument> htmlDocument(do_QueryInterface(htmlDoc));
  134:     if (htmlDocument)
  135:         htmlDocument->GetTitle(title);
  136:     if (title.IsEmpty())
  137:         title = href;
  138:         
  139:     elt->SetAttribute(NS_LITERAL_STRING("name"), title);
  140:     elt->SetAttribute(NS_LITERAL_STRING("href"), href);    
  141:     
  142:     nsCOMPtr<nsIDOMElement> parent(do_QueryInterface(content));
  143:     nsCOMPtr<nsIDOMNode> dummy;
  144:     parent->AppendChild(elt, getter_AddRefs(dummy));
  145: 
  146:     mBookmarks->NotifyObservers(content, PR_TRUE);
  147: }
  148: 
  149: -(IBAction)deleteBookmark: (id)aSender
  150: {
  151:     if (!mBookmarks)
  152:         return;
  153:     
  154:     int index = [mOutlineView selectedRow];
  155:     if (index == -1)
  156:         return;
  157:         
  158:     BookmarkItem* item = [mOutlineView itemAtRow: index];
  159:     nsCOMPtr<nsIContent> content = [item contentNode];
  160:     nsCOMPtr<nsIDOMElement> child(do_QueryInterface(content));
  161:     nsCOMPtr<nsIDOMNode> parent;
  162:     child->GetParentNode(getter_AddRefs(parent));
  163:     nsCOMPtr<nsIDOMNode> dummy;
  164:     parent->RemoveChild(child, getter_AddRefs(dummy));
  165:     nsCOMPtr<nsIContent> parentContent(do_QueryInterface(parent));
  166:     mBookmarks->NotifyObservers(parentContent, PR_TRUE);
  167:     
  168:     int total = [mOutlineView numberOfRows];
  169:     if (index == total)
  170:         index--;
  171:         
  172:     [mOutlineView selectRow: index byExtendingSelection: NO];
  173: }
  174: 
  175: -(IBAction)openBookmark: (id)aSender
  176: {
  177:     int index = [mOutlineView selectedRow];
  178:     if (index == -1)
  179:         return;
  180:     
  181:     id item = [mOutlineView itemAtRow: index];
  182:     if (!item)
  183:         return;
  184:         
  185:     if ([mOutlineView isExpandable: item]) {
  186:         if ([mOutlineView isItemExpanded: item])
  187:             [mOutlineView collapseItem: item];
  188:         else
  189:             [mOutlineView expandItem: item];
  190:     }
  191:     else {
  192:         nsIContent* content = [item contentNode];
  193:         nsAutoString href;
  194:         content->GetAttr(kNameSpaceID_None, BookmarksService::gHrefAtom, href);
  195:         if (!href.IsEmpty()) {
  196:             nsCAutoString cstr; cstr.AssignWithConversion(href);
  197:             NSString* url = [NSString stringWithCString: cstr.get()];
  198:             [[[mBrowserWindowController getMyBrowserView] getBrowserView] loadURI:[NSURL URLWithString: url] flags:NSLoadFlagsNone];
  199:             // Focus and activate our content area.
  200:             [[[mBrowserWindowController getMyBrowserView] getBrowserView] setActive: YES];
  201:         }
  202:     } 
  203: }
  204: 
  205: - (BOOL)outlineView:(NSOutlineView *)outlineView shouldEditTableColumn:(NSTableColumn *)tableColumn item:(id)item
  206: {
  207:     return NO;
  208: }
  209: 
  210: - (id)outlineView:(NSOutlineView *)outlineView child:(int)index ofItem:(id)item
  211: {
  212:     if (!mBookmarks)
  213:         return nil;
  214:        
  215:     nsCOMPtr<nsIContent> content;
  216:     if (!item)
  217:         mBookmarks->GetRootContent(getter_AddRefs(content));
  218:     else
  219:         content = [item contentNode];
  220:     
  221:     nsCOMPtr<nsIContent> child;
  222:     content->ChildAt(index, *getter_AddRefs(child));
  223:     return mBookmarks->GetWrapperFor(child);
  224: }
  225: 
  226: - (BOOL)outlineView:(NSOutlineView *)outlineView isItemExpandable:(id)item
  227: {
  228:     if (!mBookmarks)
  229:         return NO;
  230:     
  231:     if (!item)
  232:         return YES; // The root node is always open.
  233:     
  234:     nsCOMPtr<nsIAtom> tagName;
  235:     nsIContent* content = [item contentNode];
  236:     content->GetTag(*getter_AddRefs(tagName));
  237:     
  238:     return (tagName == BookmarksService::gFolderAtom);
  239: }
  240: 
  241: - (int)outlineView:(NSOutlineView *)outlineView numberOfChildrenOfItem:(id)item
  242: {
  243:     if (!mBookmarks)
  244:         return 0;
  245:   
  246:     nsCOMPtr<nsIContent> content;
  247:     if (!item)
  248:         mBookmarks->GetRootContent(getter_AddRefs(content));
  249:     else 
  250:         content = [item contentNode];
  251:     
  252:     PRInt32 childCount;
  253:     content->ChildCount(childCount);
  254:     
  255:     return childCount;
  256: }
  257: 
  258: - (id)outlineView:(NSOutlineView *)outlineView objectValueForTableColumn:(NSTableColumn *)tableColumn byItem:(id)item
  259: {
  260:     NSString 					*columnName = [tableColumn identifier];
  261:     NSMutableAttributedString 	*cellValue = [[NSMutableAttributedString alloc] init];
  262:     NSFileWrapper				*fileWrapper = [[NSFileWrapper alloc] initRegularFileWithContents:nil];
  263:     NSTextAttachment			*textAttachment = [[NSTextAttachment alloc] initWithFileWrapper:fileWrapper];
  264:     NSMutableAttributedString   *attachmentAttrString = nil;
  265:     NSCell 						*attachmentAttrStringCell;
  266: 
  267:     if ([columnName isEqualToString: @"name"]) {
  268:         nsIContent* content = [item contentNode];
  269:         nsAutoString nameAttr;
  270:         content->GetAttr(kNameSpaceID_None, BookmarksService::gNameAtom, nameAttr);
  271:         nsCAutoString cStr; cStr.AssignWithConversion(nameAttr);
  272:         
  273:         //Set cell's textual contents
  274:         [cellValue replaceCharactersInRange:NSMakeRange(0, [cellValue length])
  275:                                  withString:[NSString stringWithCString: cStr.get()]];
  276:         
  277:         //Create an attributed string to hold the empty attachment, then release the components.
  278:         attachmentAttrString = [[NSMutableAttributedString attributedStringWithAttachment:textAttachment] retain];
  279:         [textAttachment release];
  280:         [fileWrapper release];
  281: 
  282:         //Get the cell of the text attachment.
  283:         attachmentAttrStringCell = (NSCell *)[(NSTextAttachment *)[attachmentAttrString attribute:NSAttachmentAttributeName
  284:                                                                                           atIndex:0
  285:                                                                                    effectiveRange:nil] attachmentCell];
  286:         //Figure out which image to add, and set the cell's image.
  287:         if ( [self outlineView:outlineView isItemExpandable:item] ) {
  288:             [attachmentAttrStringCell setImage:[NSImage imageNamed:@"folder"]];
  289:         } else {
  290:             [attachmentAttrStringCell setImage:[NSImage imageNamed:@"smallbookmark"]];
  291:         }
  292:         //Insert the image
  293:         [cellValue replaceCharactersInRange:NSMakeRange(0, 0) withAttributedString:attachmentAttrString];
  294:         
  295:         //Tweak the baseline to vertically center the text.
  296:         [cellValue addAttribute:NSBaselineOffsetAttributeName
  297:                           value:[NSNumber numberWithFloat:-3.0]
  298:                           range:NSMakeRange(0, 1)];
  299:     }
  300:     return cellValue;
  301: }
  302: 
  303: - (void)outlineView:(NSOutlineView *)outlineView setObjectValue:(id)object forTableColumn:(NSTableColumn *)tableColumn byItem:(id)item
  304: {
  305: }
  306: 
  307: - (void)reloadDataForItem:(id)item reloadChildren: (BOOL)aReloadChildren
  308: {
  309:     printf("Reloading?\n");
  310:     if (!item)
  311:         [mOutlineView reloadData];
  312:     else if ([mOutlineView isItemExpanded: item])
  313:         [mOutlineView reloadItem: item reloadChildren: aReloadChildren];
  314: }
  315: 
  316: @end
  317: 
  318: @implementation BookmarkItem
  319: -(nsIContent*)contentNode
  320: {
  321:     return mContentNode;
  322: }
  323: 
  324: -(void)setContentNode: (nsIContent*)aContentNode
  325: {
  326:     mContentNode = aContentNode;
  327: }
  328: 
  329: - (id)copyWithZone:(NSZone *)aZone
  330: {
  331:     BookmarkItem* copy = [[[self class] allocWithZone: aZone] init];
  332:     [copy setContentNode: mContentNode];
  333:     return copy;
  334: }
  335: 
  336: @end
  337: 
  338: // Helper for stripping whitespace
  339: static void
  340: StripWhitespaceNodes(nsIContent* aElement)
  341: {
  342:     PRInt32 childCount;
  343:     aElement->ChildCount(childCount);
  344:     for (PRInt32 i = 0; i < childCount; i++) {
  345:         nsCOMPtr<nsIContent> child;
  346:         aElement->ChildAt(i, *getter_AddRefs(child));
  347:         nsCOMPtr<nsITextContent> text = do_QueryInterface(child);
  348:         if (text) {
  349:             PRBool isEmpty;
  350:             text->IsOnlyWhitespace(&isEmpty);
  351:             if (isEmpty) {
  352:                 // This node contained nothing but whitespace.
  353:                 // Remove it from the content model.
  354:                 aElement->RemoveChildAt(i, PR_TRUE);
  355:                 i--; // Decrement our count, since we just removed this child.
  356:                 childCount--; // Also decrement our total count.
  357:             }
  358:         }
  359:         else StripWhitespaceNodes(child);
  360:     }
  361: }
  362: 
  363: PRUint32 BookmarksService::gRefCnt = 0;
  364: nsIDocument* BookmarksService::gBookmarks = nsnull;
  365: NSMutableDictionary* BookmarksService::gDictionary = nil;
  366: MainController* BookmarksService::gMainController = nil;
  367: nsIAtom* BookmarksService::gFolderAtom = nsnull;
  368: nsIAtom* BookmarksService::gBookmarkAtom = nsnull;
  369: nsIAtom* BookmarksService::gHrefAtom = nsnull;
  370: nsIAtom* BookmarksService::gNameAtom = nsnull;
  371: nsVoidArray* BookmarksService::gInstances = nsnull;
  372: 
  373: BookmarksService::BookmarksService(BookmarksDataSource* aDataSource)
  374: {
  375:     mDataSource = aDataSource;
  376: }
  377: 
  378: BookmarksService::~BookmarksService()
  379: {
  380: }
  381: 
  382: void
  383: BookmarksService::GetRootContent(nsIContent** aResult)
  384: {
  385:     *aResult = nsnull;
  386:     if (gBookmarks) {
  387:         nsCOMPtr<nsIDOMElement> elt;
  388:         nsCOMPtr<nsIDOMDocument> domDoc(do_QueryInterface(gBookmarks));
  389:         domDoc->GetDocumentElement(getter_AddRefs(elt));
  390:         elt->QueryInterface(NS_GET_IID(nsIContent), (void**)aResult); // Addref happens here.
  391:     }
  392: }
  393: 
  394: BookmarkItem*
  395: BookmarksService::GetWrapperFor(nsIContent* aContent)
  396: {
  397:     if (!gDictionary)
  398:         gDictionary = [[NSMutableDictionary alloc] initWithCapacity: 30];
  399:     
  400:     PRUint32 contentID;
  401:     aContent->GetContentID(&contentID);
  402:     
  403:     BookmarkItem* item = [gDictionary objectForKey: [NSNumber numberWithInt: contentID]];
  404:     if (item)
  405:         return item;
  406:     else {
  407:         // Create an item.
  408:         item = [[[BookmarkItem alloc] init] autorelease]; // The dictionary retains us.
  409:         [item setContentNode: aContent];
  410:         [gDictionary setObject: item forKey: [NSNumber numberWithInt: contentID]];
  411:     }
  412:     return item;
  413: }
  414: 
  415: void
  416: BookmarksService::NotifyObservers(nsIContent* aContainer, PRBool aReloadChildren)
  417: {
  418:     if (!gInstances)
  419:         return;
  420:     
  421:     PRInt32 count = gInstances->Count();
  422:     for (PRInt32 i = 0; i < count; i++) {
  423:         BookmarksService* instance = (BookmarksService*)gInstances->ElementAt(i);
  424:         instance->NotifyObserver(aContainer, aReloadChildren);
  425:     }
  426:     
  427:     FlushBookmarks();
  428: }
  429: 
  430: 
  431: void
  432: BookmarksService::NotifyObserver(nsIContent* aContainer, PRBool aReloadChildren)
  433: {
  434:     if (!gDictionary)
  435:         return;
  436:    
  437:     nsCOMPtr<nsIContent> parent;
  438:     aContainer->GetParent(*getter_AddRefs(parent));
  439:     
  440:     BookmarkItem* item = nil;
  441:     if (parent)
  442:         // We're not the root.
  443:         item = GetWrapperFor(aContainer);
  444:     
  445:     [mDataSource reloadDataForItem: item reloadChildren: aReloadChildren];
  446: }
  447: 
  448: void
  449: BookmarksService::AddObserver()
  450: {
  451:     gRefCnt++;
  452:     if (gRefCnt == 1) {
  453:         gBookmarkAtom = NS_NewAtom("bookmark");
  454:         gFolderAtom = NS_NewAtom("folder");
  455:         gNameAtom = NS_NewAtom("name");
  456:         gHrefAtom = NS_NewAtom("href");
  457:         gInstances = new nsVoidArray();
  458:                 
  459:         nsCOMPtr<nsIFile> profileDir;
  460:         NS_GetSpecialDirectory(NS_APP_USER_PROFILE_50_DIR, getter_AddRefs(profileDir));
  461:         profileDir->Append("bookmarks.xml");
  462:     
  463:         nsCAutoString bookmarksFileURL;
  464:         NS_GetURLSpecFromFile(profileDir, bookmarksFileURL);
  465:         
  466:         nsCOMPtr<nsIURI> uri;
  467:         NS_NewURI(getter_AddRefs(uri), bookmarksFileURL.get());
  468:     
  469:         nsCOMPtr<nsIXBLService> xblService(do_GetService("@mozilla.org/xbl;1"));    
  470:         xblService->FetchSyncXMLDocument(uri, &gBookmarks); // The addref is here.
  471:         
  472:         nsCOMPtr<nsIContent> rootNode;
  473:         GetRootContent(getter_AddRefs(rootNode));
  474:         StripWhitespaceNodes(rootNode);
  475:     }
  476:     
  477:     gInstances->AppendElement(this);
  478: }
  479: 
  480: void
  481: BookmarksService::RemoveObserver()
  482: {
  483:     if (gRefCnt == 0)
  484:         return;
  485:  
  486:     gInstances->RemoveElement(this);
  487:      
  488:     gRefCnt--;
  489:     if (gRefCnt == 0) {
  490:         NS_IF_RELEASE(gBookmarks);
  491:         NS_RELEASE(gBookmarkAtom);
  492:         NS_RELEASE(gFolderAtom);
  493:         NS_RELEASE(gNameAtom);
  494:         NS_RELEASE(gHrefAtom);
  495:         [gDictionary release];
  496:     }
  497: }
  498: 
  499: void
  500: BookmarksService::FlushBookmarks()
  501: {
  502:     nsCOMPtr<nsIFile> bookmarksFile;
  503:     NS_GetSpecialDirectory(NS_APP_USER_PROFILE_50_DIR, getter_AddRefs(bookmarksFile));
  504:     bookmarksFile->Append("bookmarks.xml");
  505: 
  506:     nsCOMPtr<nsIOutputStream> outputStream;
  507:     NS_NewLocalFileOutputStream(getter_AddRefs(outputStream), bookmarksFile);
  508: 
  509:     nsCOMPtr<nsIDOMDocument> domDoc(do_QueryInterface(gBookmarks));
  510:     
  511:     nsCOMPtr<nsIDOMSerializer> domSerializer(do_CreateInstance(NS_XMLSERIALIZER_CONTRACTID));
  512:     domSerializer->SerializeToStream(domDoc, outputStream, nsnull);
  513: }
  514: 
  515: void
  516: BookmarksService::ConstructBookmarksMenu(NSMenu* aMenu, nsIContent* aContent)
  517: {
  518:     nsCOMPtr<nsIContent> content = aContent;
  519:     if (!content) {
  520:         GetRootContent(getter_AddRefs(content));
  521:         GetWrapperFor(content);
  522:     }
  523:     
  524:     // Now walk our children, and for folders also recur into them.
  525:     PRInt32 childCount;
  526:     content->ChildCount(childCount);
  527:     
  528:     for (PRInt32 i = 0; i < childCount; i++) {
  529:         nsCOMPtr<nsIContent> child;
  530:         content->ChildAt(i, *getter_AddRefs(child));
  531:         
  532:         // Obtain our name attribute.
  533:         nsAutoString name;
  534:         child->GetAttr(kNameSpaceID_None, gNameAtom, name);
  535:         nsCAutoString nameCStr; nameCStr.AssignWithConversion(name);
  536:         NSString* title = [NSString stringWithCString: nameCStr.get()];
  537:                 
  538:         // Create a menu or menu item for the child.
  539:         NSMenuItem* menuItem = [[[NSMenuItem alloc] initWithTitle: title action: NULL keyEquivalent: @""] autorelease];
  540:         GetWrapperFor(child);
  541:         [aMenu addItem: menuItem];
  542:         
  543:         nsCOMPtr<nsIAtom> tag;
  544:         child->GetTag(*getter_AddRefs(tag));
  545:         
  546:         if (tag == gFolderAtom) {
  547:             NSMenu* menu = [[[NSMenu alloc] initWithTitle: title] autorelease];
  548:             [aMenu setSubmenu: menu forItem: menuItem];
  549:             [menu setAutoenablesItems: NO];
  550:             ConstructBookmarksMenu(menu, child);
  551:         }
  552:         else {
  553:             [menuItem setTarget: gMainController];
  554:             [menuItem setAction: @selector(openMenuBookmark:)];
  555:         }
  556:         
  557:         PRUint32 contentID;
  558:         child->GetContentID(&contentID);
  559:         [menuItem setTag: contentID];
  560:     }
  561: }
  562: 
  563: void 
  564: BookmarksService::OpenMenuBookmark(BrowserWindowController* aController, id aMenuItem)
  565: {
  566:     // Get the corresponding bookmark item.
  567:     BookmarkItem* item = [gDictionary objectForKey: [NSNumber numberWithInt: [aMenuItem tag]]];
  568:         
  569:     // Get the content node.
  570:     nsIContent* content = [item contentNode];
  571:         
  572:     // Get the href attribute.  This is the URL we want to load.
  573:     nsAutoString href;
  574:     content->GetAttr(kNameSpaceID_None, gHrefAtom, href);
  575:     nsCAutoString cref; cref.AssignWithConversion(href);
  576:     if (cref.IsEmpty())
  577:         return;
  578:         
  579:     NSString* url = [NSString stringWithCString: cref.get()];
  580:     
  581:     // Now load the URL in the window.
  582:     [aController loadURL:[NSURL URLWithString: url]];
  583:     
  584:     // Focus and activate our content area.
  585:     [[[aController getMyBrowserView] getBrowserView] setActive: YES];
  586: }

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>