Bug 477620: Enable addition of search plugins []

This commit is contained in:
Vivien Nicolas 2009-08-26 15:29:46 -04:00
parent d2ec37a306
commit ff19c12556
8 changed files with 177 additions and 45 deletions

View File

@ -124,6 +124,15 @@ var BrowserUI = {
if (this._favicon.src != "") if (this._favicon.src != "")
this._setIcon(this._faviconLink); this._setIcon(this._faviconLink);
} }
else if (/\bsearch\b/i(link.rel)) {
var type = link.type && link.type.toLowerCase();
type = type.replace(/^\s+|\s*(?:;.*)?$/g, "");
if (type == "application/opensearchdescription+xml" && link.title && /^(?:https?|ftp):/i.test(link.href)) {
var engine = { title: link.title, href: link.href };
BrowserSearch.addPageSearchEngine(engine, link.ownerDocument);
}
}
}, },
_updateButtons : function(aBrowser) { _updateButtons : function(aBrowser) {
@ -492,7 +501,7 @@ var BrowserUI = {
}, },
showAutoComplete : function(showDefault) { showAutoComplete : function(showDefault) {
this.updateSearchEngines(); BrowserSearch.updateSearchButtons();
this._edit.showHistoryPopup(); this._edit.showHistoryPopup();
}, },
@ -508,30 +517,6 @@ var BrowserUI = {
getBrowser().loadURI(submission.uri.spec, null, submission.postData, false); getBrowser().loadURI(submission.uri.spec, null, submission.postData, false);
}, },
engines : null,
updateSearchEngines : function() {
if (this.engines)
return;
var searchService = Cc["@mozilla.org/browser/search-service;1"].getService(Ci.nsIBrowserSearchService);
var engines = searchService.getVisibleEngines({ });
this.engines = engines;
const kXULNS = "http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul";
var container = document.getElementById("search-buttons");
for (var e = 0; e < engines.length; e++) {
var button = document.createElementNS(kXULNS, "radio");
var engine = engines[e];
button.id = engine.name;
button.setAttribute("label", engine.name);
button.className = "searchengine";
if (engine.iconURI)
button.setAttribute("src", engine.iconURI.spec);
container.appendChild(button);
button.engine = engine;
}
},
updateStar : function() { updateStar : function() {
if (PlacesUtils.getMostRecentBookmarkForURI(Browser.selectedBrowser.currentURI) != -1) if (PlacesUtils.getMostRecentBookmarkForURI(Browser.selectedBrowser.currentURI) != -1)
this.starButton.setAttribute("starred", "true"); this.starButton.setAttribute("starred", "true");

View File

@ -1478,6 +1478,97 @@ nsBrowserAccess.prototype = {
} }
}; };
const BrowserSearch = {
engines: null,
_allEngines: [],
get _currentEngines() {
let doc = getBrowser().contentDocument;
return this._allEngines.filter(function(element) element.doc === doc, this);
},
addPageSearchEngine: function (aEngine, aDocument) {
// Clean the engine referenced for document that didn't exist anymore
let browsers = Browser.browsers;
this._allEngines = this._allEngines.filter(function(element) {
return browsers.some(function (browser) browser.contentDocument == element.doc);
}, this);
// Prevent duplicate
if (!this._allEngines.some(function (e) {
return (e.engine.title == aEngine.title) && (e.doc == aDocument);
})) this._allEngines.push( {engine:aEngine, doc:aDocument});
},
updatePageSearchEngines: function() {
// Check to see whether we've already added an engine with this title in
// the search list
let newEngines = this._currentEngines.filter(function(element) {
return !this.engines.some(function (e) e.name == element.engine.title);
}, this);
let container = document.getElementById('search-container');
let buttons = container.getElementsByAttribute("class", "search-engine-button button-dark");
for (let i=0; i<buttons.length; i++)
container.removeChild(buttons[i]);
if (newEngines.length == 0) {
container.hidden = true;
return;
}
// XXX limit to the first search engine for now
for (let i = 0; i<1; i++) {
let button = document.createElement("button");
button.className = "search-engine-button button-dark";
button.setAttribute("oncommand", "BrowserSearch.addPermanentSearchEngine(this.engine);this.parentNode.hidden=true;");
let engine = newEngines[i];
button.engine = engine.engine;
button.setAttribute("label", engine.engine.title);
button.setAttribute("image", BrowserUI._favicon.src);
container.appendChild(button);
}
container.hidden = false;
},
addPermanentSearchEngine: function (aEngine) {
var searchService = Cc["@mozilla.org/browser/search-service;1"].getService(Ci.nsIBrowserSearchService);
let iconURL = BrowserUI._favicon.src;
searchService.addEngine(aEngine.href, Ci.nsISearchEngine.DATA_XML, iconURL, false);
this.engines = null;
},
updateSearchButtons: function() {
if (this.engines)
return;
var searchService = Cc["@mozilla.org/browser/search-service;1"].getService(Ci.nsIBrowserSearchService);
var engines = searchService.getVisibleEngines({ });
this.engines = engines;
// Clean the previous search engines button
var container = document.getElementById("search-buttons");
while (container.hasChildNodes())
container.removeChild(container.lastChild);
for (var e = 0; e < engines.length; e++) {
var button = document.createElement("radio");
var engine = engines[e];
button.id = engine.name;
button.setAttribute("label", engine.name);
button.className = "searchengine";
if (engine.iconURI)
button.setAttribute("src", engine.iconURI.spec);
container.appendChild(button);
button.engine = engine;
}
}
}
/** /**
* Utility class to handle manipulations of the identity indicators in the UI * Utility class to handle manipulations of the identity indicators in the UI
*/ */
@ -1711,6 +1802,9 @@ IdentityHandler.prototype = {
this._identityPopupContentOwner.textContent = owner; this._identityPopupContentOwner.textContent = owner;
this._identityPopupContentSupp.textContent = supplemental; this._identityPopupContentSupp.textContent = supplemental;
this._identityPopupContentVerif.textContent = verifier; this._identityPopupContentVerif.textContent = verifier;
// Update the search engines results
BrowserSearch.updatePageSearchEngines();
}, },
show: function ih_show() { show: function ih_show() {

View File

@ -264,26 +264,32 @@
</hbox> </hbox>
<!-- popup for site identity information --> <!-- popup for site identity information -->
<hbox id="identity-container" hidden="true" class="panel-dark" top="0" left="0" align="top" mode="unknownIdentity"> <vbox id="identity-container" hidden="true" class="panel-dark" top="0" left="0" mode="unknownIdentity">
<image id="identity-popup-icon"/> <hbox id="identity-popup-container" flex="1" align="top">
<vbox id="identity-popup-content-box" flex="1"> <image id="identity-popup-icon"/>
<hbox flex="1"> <vbox id="identity-popup-content-box" flex="1">
<label id="identity-popup-connectedToLabel" value="&identity.connectedTo2;"/> <hbox flex="1">
<label id="identity-popup-connectedToLabel2" flex="1">&identity.unverifiedsite2;</label> <label id="identity-popup-connectedToLabel" value="&identity.connectedTo2;"/>
<description id="identity-popup-content-host" flex="1"/> <label id="identity-popup-connectedToLabel2" flex="1">&identity.unverifiedsite2;</label>
</hbox> <description id="identity-popup-content-host" flex="1"/>
<hbox flex="1"> </hbox>
<label id="identity-popup-runByLabel" value="&identity.runBy2;"/> <hbox flex="1">
<description id="identity-popup-content-owner"/> <label id="identity-popup-runByLabel" value="&identity.runBy2;"/>
<description id="identity-popup-content-supplemental"/> <description id="identity-popup-content-owner"/>
</hbox> <description id="identity-popup-content-supplemental"/>
<description id="identity-popup-content-verifier"/> </hbox>
</vbox> <description id="identity-popup-content-verifier"/>
<vbox align="center" pack="start"> </vbox>
<image id="identity-popup-encryption-icon"/> <vbox align="center" pack="start">
<description id="identity-popup-encryption-label"/> <image id="identity-popup-encryption-icon"/>
</vbox> <description id="identity-popup-encryption-label"/>
</hbox> </vbox>
</hbox>
<hbox id="search-container" align="center" flex="1">
<label id="search-engine-label-add" value="&searchEngine.addSearch;"/>
</hbox>
</vbox>
<vbox id="newtab-popup" hidden="true" class="panel-dark" onclick="NewTabPopup.selectTab()" align="center" left="21"> <vbox id="newtab-popup" hidden="true" class="panel-dark" onclick="NewTabPopup.selectTab()" align="center" left="21">
<label/> <label/>

View File

@ -83,6 +83,8 @@
<!ENTITY noResults.label "No results"> <!ENTITY noResults.label "No results">
<!ENTITY allBookmarks.label "See all bookmarks"> <!ENTITY allBookmarks.label "See all bookmarks">
<!ENTITY searchEngine.addSearch "Add Search:">
<!ENTITY bookmarkPopup.label "Page Bookmarked"> <!ENTITY bookmarkPopup.label "Page Bookmarked">
<!ENTITY bookmarkRemove.label "Remove"> <!ENTITY bookmarkRemove.label "Remove">
<!ENTITY bookmarkEdit.label "Edit"> <!ENTITY bookmarkEdit.label "Edit">

View File

@ -679,6 +679,10 @@ findbar .findbar-closebutton {
/* Identity popup -------------------------------------------------------- */ /* Identity popup -------------------------------------------------------- */
#identity-container { #identity-container {
border-bottom: 0.2mm solid grey;
}
#identity-popup-container {
padding: 2.2mm; /* core spacing */ padding: 2.2mm; /* core spacing */
} }
@ -735,6 +739,22 @@ findbar .findbar-closebutton {
list-style-image: url("chrome://browser/skin/images/lock-40.png"); list-style-image: url("chrome://browser/skin/images/lock-40.png");
} }
/* search popup ---------------------------------------------------------- */
#search-container {
border-top: 0.1mm solid rgb(207,207,207);
padding: 2.2mm; /* core spacing */
margin-top: 2mm;
}
#search-engine-label-add {
font-size: 80%;
}
.search-engine-button .button-icon {
width: 16px;
height: 16px;
}
/* Preferences window ---------------------------------------------------- */ /* Preferences window ---------------------------------------------------- */
/* XXX should be a richlistitem */ /* XXX should be a richlistitem */
richpref { richpref {

View File

@ -105,6 +105,11 @@
background: url("images/leftcapSSL-active-64.png"); background: url("images/leftcapSSL-active-64.png");
} }
.search-engine-button .button-icon {
width: 16px;
height: 16px;
}
#urlbar-throbber[loading] { #urlbar-throbber[loading] {
list-style-image: url("chrome://browser/skin/images/throbber.png"); list-style-image: url("chrome://browser/skin/images/throbber.png");
} }

View File

@ -104,6 +104,11 @@
background: url("images/leftcapSSL-active-36.png"); background: url("images/leftcapSSL-active-36.png");
} }
.search-engine-button .button-icon {
width: 16px;
height: 16px;
}
#urlbar-throbber[loading] { #urlbar-throbber[loading] {
list-style-image: url("chrome://browser/skin/images/throbber.png"); list-style-image: url("chrome://browser/skin/images/throbber.png");
} }

View File

@ -455,6 +455,10 @@ findbar {
/* Identity popup -------------------------------------------------------- */ /* Identity popup -------------------------------------------------------- */
#identity-container { #identity-container {
border-bottom: 0.1mm solid grey;
}
#identity-popup-container {
padding: 1.1mm; /* core spacing */ padding: 1.1mm; /* core spacing */
} }
@ -488,6 +492,17 @@ findbar {
font-weight: bold; font-weight: bold;
} }
/* search popup ---------------------------------------------------------- */
#search-container {
border-top: 0.1mm solid rgb(207,207,207);
padding: 1.1mm; /* core spacing */
margin-top: 1mm;
}
#search-engine-label-add {
font-size: 80%;
}
/* Preferences window ---------------------------------------------------- */ /* Preferences window ---------------------------------------------------- */
/* XXX should be a richlistitem */ /* XXX should be a richlistitem */
richpref { richpref {