зеркало из https://github.com/mozilla/pjs.git
Bug 477620: Enable addition of search plugins []
This commit is contained in:
Родитель
d2ec37a306
Коммит
ff19c12556
|
@ -124,6 +124,15 @@ var BrowserUI = {
|
|||
if (this._favicon.src != "")
|
||||
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) {
|
||||
|
@ -492,7 +501,7 @@ var BrowserUI = {
|
|||
},
|
||||
|
||||
showAutoComplete : function(showDefault) {
|
||||
this.updateSearchEngines();
|
||||
BrowserSearch.updateSearchButtons();
|
||||
this._edit.showHistoryPopup();
|
||||
},
|
||||
|
||||
|
@ -508,30 +517,6 @@ var BrowserUI = {
|
|||
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() {
|
||||
if (PlacesUtils.getMostRecentBookmarkForURI(Browser.selectedBrowser.currentURI) != -1)
|
||||
this.starButton.setAttribute("starred", "true");
|
||||
|
|
|
@ -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
|
||||
*/
|
||||
|
@ -1711,6 +1802,9 @@ IdentityHandler.prototype = {
|
|||
this._identityPopupContentOwner.textContent = owner;
|
||||
this._identityPopupContentSupp.textContent = supplemental;
|
||||
this._identityPopupContentVerif.textContent = verifier;
|
||||
|
||||
// Update the search engines results
|
||||
BrowserSearch.updatePageSearchEngines();
|
||||
},
|
||||
|
||||
show: function ih_show() {
|
||||
|
|
|
@ -264,26 +264,32 @@
|
|||
</hbox>
|
||||
|
||||
<!-- popup for site identity information -->
|
||||
<hbox id="identity-container" hidden="true" class="panel-dark" top="0" left="0" align="top" mode="unknownIdentity">
|
||||
<image id="identity-popup-icon"/>
|
||||
<vbox id="identity-popup-content-box" flex="1">
|
||||
<hbox flex="1">
|
||||
<label id="identity-popup-connectedToLabel" value="&identity.connectedTo2;"/>
|
||||
<label id="identity-popup-connectedToLabel2" flex="1">&identity.unverifiedsite2;</label>
|
||||
<description id="identity-popup-content-host" flex="1"/>
|
||||
</hbox>
|
||||
<hbox flex="1">
|
||||
<label id="identity-popup-runByLabel" value="&identity.runBy2;"/>
|
||||
<description id="identity-popup-content-owner"/>
|
||||
<description id="identity-popup-content-supplemental"/>
|
||||
</hbox>
|
||||
<description id="identity-popup-content-verifier"/>
|
||||
</vbox>
|
||||
<vbox align="center" pack="start">
|
||||
<image id="identity-popup-encryption-icon"/>
|
||||
<description id="identity-popup-encryption-label"/>
|
||||
</vbox>
|
||||
</hbox>
|
||||
<vbox id="identity-container" hidden="true" class="panel-dark" top="0" left="0" mode="unknownIdentity">
|
||||
<hbox id="identity-popup-container" flex="1" align="top">
|
||||
<image id="identity-popup-icon"/>
|
||||
<vbox id="identity-popup-content-box" flex="1">
|
||||
<hbox flex="1">
|
||||
<label id="identity-popup-connectedToLabel" value="&identity.connectedTo2;"/>
|
||||
<label id="identity-popup-connectedToLabel2" flex="1">&identity.unverifiedsite2;</label>
|
||||
<description id="identity-popup-content-host" flex="1"/>
|
||||
</hbox>
|
||||
<hbox flex="1">
|
||||
<label id="identity-popup-runByLabel" value="&identity.runBy2;"/>
|
||||
<description id="identity-popup-content-owner"/>
|
||||
<description id="identity-popup-content-supplemental"/>
|
||||
</hbox>
|
||||
<description id="identity-popup-content-verifier"/>
|
||||
</vbox>
|
||||
<vbox align="center" pack="start">
|
||||
<image id="identity-popup-encryption-icon"/>
|
||||
<description id="identity-popup-encryption-label"/>
|
||||
</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">
|
||||
<label/>
|
||||
|
|
|
@ -83,6 +83,8 @@
|
|||
<!ENTITY noResults.label "No results">
|
||||
<!ENTITY allBookmarks.label "See all bookmarks">
|
||||
|
||||
<!ENTITY searchEngine.addSearch "Add Search:">
|
||||
|
||||
<!ENTITY bookmarkPopup.label "Page Bookmarked">
|
||||
<!ENTITY bookmarkRemove.label "Remove">
|
||||
<!ENTITY bookmarkEdit.label "Edit">
|
||||
|
|
|
@ -679,6 +679,10 @@ findbar .findbar-closebutton {
|
|||
|
||||
/* Identity popup -------------------------------------------------------- */
|
||||
#identity-container {
|
||||
border-bottom: 0.2mm solid grey;
|
||||
}
|
||||
|
||||
#identity-popup-container {
|
||||
padding: 2.2mm; /* core spacing */
|
||||
}
|
||||
|
||||
|
@ -735,6 +739,22 @@ findbar .findbar-closebutton {
|
|||
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 ---------------------------------------------------- */
|
||||
/* XXX should be a richlistitem */
|
||||
richpref {
|
||||
|
|
|
@ -105,6 +105,11 @@
|
|||
background: url("images/leftcapSSL-active-64.png");
|
||||
}
|
||||
|
||||
.search-engine-button .button-icon {
|
||||
width: 16px;
|
||||
height: 16px;
|
||||
}
|
||||
|
||||
#urlbar-throbber[loading] {
|
||||
list-style-image: url("chrome://browser/skin/images/throbber.png");
|
||||
}
|
||||
|
|
|
@ -104,6 +104,11 @@
|
|||
background: url("images/leftcapSSL-active-36.png");
|
||||
}
|
||||
|
||||
.search-engine-button .button-icon {
|
||||
width: 16px;
|
||||
height: 16px;
|
||||
}
|
||||
|
||||
#urlbar-throbber[loading] {
|
||||
list-style-image: url("chrome://browser/skin/images/throbber.png");
|
||||
}
|
||||
|
|
|
@ -455,6 +455,10 @@ findbar {
|
|||
|
||||
/* Identity popup -------------------------------------------------------- */
|
||||
#identity-container {
|
||||
border-bottom: 0.1mm solid grey;
|
||||
}
|
||||
|
||||
#identity-popup-container {
|
||||
padding: 1.1mm; /* core spacing */
|
||||
}
|
||||
|
||||
|
@ -488,6 +492,17 @@ findbar {
|
|||
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 ---------------------------------------------------- */
|
||||
/* XXX should be a richlistitem */
|
||||
richpref {
|
||||
|
|
Загрузка…
Ссылка в новой задаче