diff --git a/mozilla/browser/base/content/browser.js b/mozilla/browser/base/content/browser.js index a7b9d7897e6..f4f9895d08b 100644 --- a/mozilla/browser/base/content/browser.js +++ b/mozilla/browser/base/content/browser.js @@ -1456,17 +1456,18 @@ function addBookmarkForTabBrowser(aTabBrowser, aSelect) var doc = webNav.document; name = doc.title || url; charSet = doc.characterSet; + description = BookmarksUtils.getDescriptionFromDocument(doc); } catch (e) { name = url; } - tabsInfo[i] = { name: name, url: url, charset: charSet }; + tabsInfo[i] = { name: name, url: url, charset: charSet, description: description, bAddGroup: true }; if (browsers[i] == activeBrowser) currentTabInfo = tabsInfo[i]; } + var dialogArgs = currentTabInfo; + dialogArgs.objGroup = tabsInfo; openDialog("chrome://browser/content/bookmarks/addBookmark2.xul", "", - "centerscreen,chrome,dialog,resizable,dependent", - currentTabInfo.name, currentTabInfo.url, null, - currentTabInfo.charset, "addGroup" + (aSelect ? ",group" : ""), tabsInfo); + "centerscreen,chrome,dialog,resizable,dependent", dialogArgs); } function addBookmarkForBrowser(aDocShell, aIsWebPanel) @@ -1481,11 +1482,12 @@ function addBookmarkForBrowser(aDocShell, aIsWebPanel) try { title = aDocShell.document.title || url; charSet = aDocShell.document.characterSet; + description = BookmarksUtils.getDescriptionFromDocument(aDocShell.document); } catch (e) { title = url; } - BookmarksUtils.addBookmark(url, title, charSet, aIsWebPanel); + BookmarksUtils.addBookmark(url, title, charSet, aIsWebPanel, description); } function openLocation() @@ -2352,9 +2354,12 @@ var bookmarksButtonObserver = { var split = aXferData.data.split("\n"); var url = split[0]; if (url != aXferData.data) { //do nothing if it's not a valid URL - var name = split[1]; + var dialogArgs = { + name: split[1], + url: url + } openDialog("chrome://browser/content/bookmarks/addBookmark2.xul", "", - "centerscreen,chrome,dialog,resizable,dependent", name, url); + "centerscreen,chrome,dialog,resizable,dependent", dialogArgs); } }, @@ -4217,15 +4222,17 @@ nsContextMenu.prototype = { var docshell = document.getElementById( "content" ).webNavigation; BookmarksUtils.addBookmark( docshell.currentURI.spec, docshell.document.title, - docshell.document.charset); + docshell.document.charset, + BookmarksUtils.getDescriptionFromDocument(docshell.document)); }, addBookmarkForFrame : function() { var doc = this.target.ownerDocument; var uri = doc.location.href; var title = doc.title; + var description = BookmarksUtils.getDescriptionFromDocument(doc); if ( !title ) title = uri; - BookmarksUtils.addBookmark(uri, title, doc.charset); + BookmarksUtils.addBookmark(uri, title, doc.charset, description); }, // Open Metadata window for node showMetadata : function () { @@ -4574,10 +4581,13 @@ function asyncOpenWebPanel(event) // This is the Opera convention for a special link that - when clicked - allows // you to add a sidebar panel. We support the Opera convention here. The link's // title attribute contains the title that should be used for the sidebar panel. + var dialogArgs = { + name: wrapper.getAttribute("title"), + url: wrapper.href, + bWebPanel: true + } openDialog("chrome://browser/content/bookmarks/addBookmark2.xul", "", - "centerscreen,chrome,dialog,resizable,dependent", - wrapper.getAttribute("title"), - wrapper.href, null, null, null, null, true); + "centerscreen,chrome,dialog,resizable,dependent", dialogArgs); event.preventDefault(); return false; } @@ -5427,10 +5437,17 @@ function AddKeywordForSearchField() spec += "&" + escape(e.name) + "=" + escape(e.value); } } - openDialog("chrome://browser/content/bookmarks/addBookmark2.xul", "", - "centerscreen,chrome,dialog,resizable,dependent", - "", spec, null, node.ownerDocument.characterSet, null, null, - false, "", true, postData); + var dialogArgs = { + name: "", + url: spec, + charset: node.ownerDocument.characterSet, + bWebPanel: false, + keyword: "", + bNeedKeyword: true, + postData: postData, + description: BookmarksUtils.getDescriptionFromDocument(node.ownerDocument) + } + openDialog("chrome://browser/content/bookmarks/addBookmark2.xul", dialogArgs); } /////////////// livemark handling @@ -5557,7 +5574,8 @@ function livemarkFillPopup(menuPopup) function livemarkAddMark(wincontent, data) { var title = wincontent.document.title; - BookmarksUtils.addLivemark(wincontent.document.baseURI, data, title); + var description = BookmarksUtils.getDescriptionFromDocument(wincontent.document); + BookmarksUtils.addLivemark(wincontent.document.baseURI, data, title, description); } function updatePageFavIcon(aBrowser, aListener) { diff --git a/mozilla/browser/components/bookmarks/content/addBookmark2.js b/mozilla/browser/components/bookmarks/content/addBookmark2.js index 9f97122278b..2fb68668056 100644 --- a/mozilla/browser/components/bookmarks/content/addBookmark2.js +++ b/mozilla/browser/components/bookmarks/content/addBookmark2.js @@ -50,39 +50,38 @@ * * Parameters: * Apart from the standard openDialog parameters, this dialog can - * be passed additional information, which gets mapped to the - * window.arguments array: + * be passed additional information, which is contained in the + * wArg object: * - * XXXben - it would be cleaner just to take this dialog take an - * object so items don't need to be passed in a particular - * order. - * - * window.arguments[0]: Bookmark Name. The value to be prefilled + * wArg.name : Bookmark Name. The value to be prefilled * into the "Name: " field (if visible). - * window.arguments[1]: Bookmark URL: The location of the bookmark. + * wArg.description : Bookmark description. The value to be added + * : to the boomarks description field. + * wArg.url : Bookmark URL: The location of the bookmark. * The value to be filled in the "Location: " * field (if visible). - * window.arguments[2]: Bookmark Folder. The RDF Resource URI of the + * wArg.folderURI : Bookmark Folder. The RDF Resource URI of the * folder that this bookmark should be created in. - * window.arguments[3]: Bookmark Charset. The charset that should be + * wArg.charset : Bookmark Charset. The charset that should be * used when adding a bookmark to the specified * URL. (Usually the charset of the current - * document when launching this window). - * window.arguments[4]: The mode of operation. See notes for details. - * window.arguments[5]: If the mode is "addGroup", this is an array - * of objects with name, URL and charset + * document when launching this window). + * wArg.bAddGroup : True if adding a group of tabs, false + * otherwise. + * wArg.objGroup[] : If adding a group of tabs, this is an array + * of wArg objects with name, URL and charset * properties, one for each group member. - * window.arguments[6]: If the bookmark should become a web panel. - * window.arguments[7]: A suggested keyword for the bookmark. If this + * wArg.bWebPanel : If the bookmark should become a web panel. + * wArg.keyword : A suggested keyword for the bookmark. If this * argument is supplied, the keyword row is made * visible. - * window.arguments[8]: Whether or not a keyword is required to add + * wArg.bNeedKeyword : Whether or not a keyword is required to add * the bookmark. - * window.arguments[9]: PostData to be saved with this bookmark, + * wArg.postData : PostData to be saved with this bookmark, * in the format a string of name=value pairs * separated by CRLFs. - * window.arguments[10]: feed URL for Livemarks (turns bookmark - * into Livemark) + * wArg.feedURL : feed URL for Livemarks (turns bookmark + * into Livemark) */ var gSelectedFolder; @@ -97,6 +96,7 @@ var gKeywordRequired; var gSuggestedKeyword; var gRequiredFields = []; var gPostData; +var gArg = window.arguments[0]; # on windows, sizeToContent is buggy (see bug 227951), we''ll use resizeTo # instead and cache the bookmarks tree view size. @@ -114,11 +114,11 @@ function Startup() gExpander = document.getElementById("expander"); gMenulist = document.getElementById("select-menu"); gBookmarksTree = document.getElementById("folder-tree"); - gName.value = window.arguments[0]; + gName.value = gArg.name; gName.select(); gName.focus(); - gSuggestedKeyword = window.arguments[7]; - gKeywordRequired = window.arguments[8]; + gSuggestedKeyword = gArg.keyword; + gKeywordRequired = gArg.bNeedKeyword; if (!gSuggestedKeyword && !gKeywordRequired) { gKeywordRow.hidden = true; } else { @@ -127,11 +127,13 @@ function Startup() if (gKeywordRequired) gRequiredFields.push(gKeyword); } + if (!gArg.bAddGroup) + gGroup.setAttribute("hidden", "true"); sizeToContent(); onFieldInput(); gSelectedFolder = RDF.GetResource(gMenulist.selectedItem.id); gExpander.setAttribute("tooltiptext", gExpander.getAttribute("tooltiptextdown")); - gPostData = window.arguments[9]; + gPostData = gArg.postData; # read the persisted attribute. If it is not present, set a default height. WSucks = parseInt(gBookmarksTree.getAttribute("height")); @@ -170,28 +172,28 @@ function onOK() RDFC.Init(BMDS, gSelectedFolder); var url, rSource; - var livemarkFeed = window.arguments[10]; + var livemarkFeed = gArg.feedURL; if (gGroup && gGroup.checked) { rSource = BMDS.createFolder(gName.value); - const groups = window.arguments[5]; + const groups = gArg.objGroup; for (var i = 0; i < groups.length; ++i) { url = getNormalizedURL(groups[i].url); - BMDS.createBookmarkInContainer(groups[i].name, url, gKeyword.value, null, + BMDS.createBookmarkInContainer(groups[i].name, url, gKeyword.value, groups[i].description, groups[i].charset, gPostData, rSource, -1); } } else if (livemarkFeed != null) { - url = getNormalizedURL(window.arguments[1]); + url = getNormalizedURL(gArg.url); rSource = BMDS.createLivemark(gName.value, url, livemarkFeed, null); } else { - url = getNormalizedURL(window.arguments[1]); - rSource = BMDS.createBookmark(gName.value, url, gKeyword.value, null, window.arguments[3], gPostData); + url = getNormalizedURL(gArg.url); + rSource = BMDS.createBookmark(gName.value, url, gKeyword.value, gArg.description, gArg.charset, gPostData); } var selection = BookmarksUtils.getSelectionFromResource(rSource); var target = BookmarksUtils.getTargetFromFolder(gSelectedFolder); BookmarksUtils.insertAndCheckSelection("newbookmark", selection, target); - if (window.arguments[6] && rSource) { + if (gArg.bWebPanel && rSource) { // Assert that we're a web panel. BMDS.Assert(rSource, RDF.GetResource(NC_NS+"WebPanel"), RDF.GetLiteral("true"), true); diff --git a/mozilla/browser/components/bookmarks/content/addBookmark2.xul b/mozilla/browser/components/bookmarks/content/addBookmark2.xul index d0addf393c6..3b141609f34 100644 --- a/mozilla/browser/components/bookmarks/content/addBookmark2.xul +++ b/mozilla/browser/components/bookmarks/content/addBookmark2.xul @@ -121,10 +121,4 @@ - - - diff --git a/mozilla/browser/components/bookmarks/content/bookmarks.js b/mozilla/browser/components/bookmarks/content/bookmarks.js index a44bc30a517..e11d0b375ab 100644 --- a/mozilla/browser/components/bookmarks/content/bookmarks.js +++ b/mozilla/browser/components/bookmarks/content/bookmarks.js @@ -1623,18 +1623,39 @@ var BookmarksUtils = { }, // should update the caller, aShowDialog is no more necessary - addBookmark: function (aURL, aTitle, aCharset, aIsWebPanel) + addBookmark: function (aURL, aTitle, aCharset, aIsWebPanel, aDescription) { + var dArgs = { + name: aTitle, + url: aURL, + charset: aCharset, + bWebPanel: aIsWebPanel, + description: aDescription + } openDialog("chrome://browser/content/bookmarks/addBookmark2.xul", "", - "centerscreen,chrome,dialog,resizable,dependent", aTitle, aURL, null, aCharset, - null, null, aIsWebPanel); + "centerscreen,chrome,dialog,resizable,dependent", dArgs); }, - addLivemark: function (aURL, aFeedURL, aTitle) + addLivemark: function (aURL, aFeedURL, aTitle, aDescription) { + var dArgs = { + name: aTitle, + url: aURL, + bWebPanel: false, + feedURL: aFeedURL, + description: aDescription + } openDialog("chrome://browser/content/bookmarks/addBookmark2.xul", "", - "centerscreen,chrome,dialog,resizable,dependent", aTitle, aURL, null, null, - null, null, false, null, null, null, aFeedURL); + "centerscreen,chrome,dialog,resizable,dependent", dArgs); + }, + + getDescriptionFromDocument: function (aDocument) { + var metaElements = aDocument.getElementsByTagName('META'); + for (var m = 0; m < metaElements.length; m++) { + if (metaElements[m].name.toLowerCase() == 'description' || metaElements[m].httpEquiv.toLowerCase() == 'description') + return metaElements[m].content; + } + return ''; }, loadFavIcon: function (aURL, aFavIconURL) {