morgan pushed to branch tor-browser-140.4.0esr-15.0-1 at The Tor Project / Applications / Tor Browser
Commits:
-
39767109
by Pier Angelo Vendrame at 2025-10-15T17:28:31+00:00
5 changed files:
- browser/components/urlbar/ActionsProviderContextualSearch.sys.mjs
- toolkit/components/search/OpenSearchEngine.sys.mjs
- toolkit/components/search/SearchEngine.sys.mjs
- toolkit/components/search/SearchService.sys.mjs
- toolkit/components/search/SearchUtils.sys.mjs
Changes:
| ... | ... | @@ -286,10 +286,22 @@ class ProviderContextualSearch extends ActionsProvider { |
| 286 | 286 | let { type, engine } = this.#resultEngine;
|
| 287 | 287 | |
| 288 | 288 | if (type == OPEN_SEARCH_ENGINE) {
|
| 289 | + let originAttributes;
|
|
| 290 | + try {
|
|
| 291 | + let currentURI = Services.io.newURI(queryContext.currentPage);
|
|
| 292 | + originAttributes = {
|
|
| 293 | + firstPartyDomain: Services.eTLD.getSchemelessSite(currentURI),
|
|
| 294 | + };
|
|
| 295 | + } catch {}
|
|
| 289 | 296 | let openSearchEngineData = await lazy.loadAndParseOpenSearchEngine(
|
| 290 | - Services.io.newURI(engine.uri)
|
|
| 297 | + Services.io.newURI(engine.uri),
|
|
| 298 | + null,
|
|
| 299 | + originAttributes
|
|
| 291 | 300 | );
|
| 292 | - engine = new lazy.OpenSearchEngine({ engineData: openSearchEngineData });
|
|
| 301 | + engine = new lazy.OpenSearchEngine({
|
|
| 302 | + engineData: openSearchEngineData,
|
|
| 303 | + originAttributes,
|
|
| 304 | + });
|
|
| 293 | 305 | }
|
| 294 | 306 | |
| 295 | 307 | this.#performSearch(
|
| ... | ... | @@ -56,6 +56,8 @@ export class OpenSearchEngine extends SearchEngine { |
| 56 | 56 | * @param {string} [options.faviconURL]
|
| 57 | 57 | * The website favicon, to be used if the engine data hasn't specified an
|
| 58 | 58 | * icon.
|
| 59 | + * @param {object} [options.originAttributes]
|
|
| 60 | + * The origin attributes to use to download additional resources.
|
|
| 59 | 61 | */
|
| 60 | 62 | constructor(options = {}) {
|
| 61 | 63 | super({
|
| ... | ... | @@ -68,7 +70,10 @@ export class OpenSearchEngine extends SearchEngine { |
| 68 | 70 | });
|
| 69 | 71 | |
| 70 | 72 | if (options.faviconURL) {
|
| 71 | - this._setIcon(options.faviconURL, undefined, false).catch(e =>
|
|
| 73 | + this._setIcon(options.faviconURL, {
|
|
| 74 | + override: false,
|
|
| 75 | + originAttributes: options.originAttributes,
|
|
| 76 | + }).catch(e =>
|
|
| 72 | 77 | lazy.logConsole.error(
|
| 73 | 78 | `Error while setting icon for search engine ${options.engineData.name}:`,
|
| 74 | 79 | e.message
|
| ... | ... | @@ -77,7 +82,7 @@ export class OpenSearchEngine extends SearchEngine { |
| 77 | 82 | }
|
| 78 | 83 | |
| 79 | 84 | if (options.engineData) {
|
| 80 | - this.#setEngineData(options.engineData);
|
|
| 85 | + this.#setEngineData(options.engineData, options.originAttributes);
|
|
| 81 | 86 | |
| 82 | 87 | // As this is a new engine, we must set the verification hash for the load
|
| 83 | 88 | // path set in the constructor.
|
| ... | ... | @@ -189,8 +194,10 @@ export class OpenSearchEngine extends SearchEngine { |
| 189 | 194 | *
|
| 190 | 195 | * @param {OpenSearchProperties} data
|
| 191 | 196 | * The OpenSearch data.
|
| 197 | + * @param {object} originAttributes
|
|
| 198 | + * The origin attributes for any additional downloads
|
|
| 192 | 199 | */
|
| 193 | - #setEngineData(data) {
|
|
| 200 | + #setEngineData(data, originAttributes) {
|
|
| 194 | 201 | let name = data.name.trim();
|
| 195 | 202 | if (Services.search.getEngineByName(name)) {
|
| 196 | 203 | throw Components.Exception(
|
| ... | ... | @@ -258,11 +265,12 @@ export class OpenSearchEngine extends SearchEngine { |
| 258 | 265 | }
|
| 259 | 266 | |
| 260 | 267 | for (let image of data.images) {
|
| 261 | - this._setIcon(image.url, image.size).catch(e =>
|
|
| 262 | - lazy.logConsole.error(
|
|
| 263 | - `Error while setting icon for search engine ${data.name}:`,
|
|
| 264 | - e.message
|
|
| 265 | - )
|
|
| 268 | + this._setIcon(image.url, { size: image.size, originAttributes }).catch(
|
|
| 269 | + e =>
|
|
| 270 | + lazy.logConsole.error(
|
|
| 271 | + `Error while setting icon for search engine ${data.name}:`,
|
|
| 272 | + e.message
|
|
| 273 | + )
|
|
| 266 | 274 | );
|
| 267 | 275 | }
|
| 268 | 276 | }
|
| ... | ... | @@ -585,15 +585,19 @@ export class SearchEngine { |
| 585 | 585 | * @param {string} iconURL
|
| 586 | 586 | * A URI string pointing to the engine's icon.
|
| 587 | 587 | * Must have http[s], data, or moz-extension protocol.
|
| 588 | - * @param {number} [size]
|
|
| 588 | + * @param {object} options
|
|
| 589 | + * The options object
|
|
| 590 | + * @param {number} [options.size]
|
|
| 589 | 591 | * Width and height of the icon (determined automatically if not provided).
|
| 590 | - * @param {boolean} [override]
|
|
| 592 | + * @param {boolean} [options.override]
|
|
| 591 | 593 | * Whether the new URI should override an existing one.
|
| 594 | + * @param {object} [options.originAttributes]
|
|
| 595 | + * The origin attributes to use to load the icon.
|
|
| 592 | 596 | * @returns {Promise<void>}
|
| 593 | 597 | * Resolves when the icon was set.
|
| 594 | 598 | * Rejects with an Error if there was an error.
|
| 595 | 599 | */
|
| 596 | - async _setIcon(iconURL, size, override = true) {
|
|
| 600 | + async _setIcon(iconURL, options = { override: true }) {
|
|
| 597 | 601 | lazy.logConsole.debug(
|
| 598 | 602 | "_setIcon: Setting icon url for",
|
| 599 | 603 | this.name,
|
| ... | ... | @@ -601,8 +605,12 @@ export class SearchEngine { |
| 601 | 605 | limitURILength(iconURL)
|
| 602 | 606 | );
|
| 603 | 607 | |
| 604 | - [iconURL, size] = await this._downloadAndRescaleIcon(iconURL, size);
|
|
| 605 | - this._addIconToMap(iconURL, size, override);
|
|
| 608 | + let size;
|
|
| 609 | + [iconURL, size] = await this._downloadAndRescaleIcon(iconURL, {
|
|
| 610 | + size: options.size,
|
|
| 611 | + originAttributes: options.originAttributes,
|
|
| 612 | + });
|
|
| 613 | + this._addIconToMap(iconURL, size, options.override);
|
|
| 606 | 614 | |
| 607 | 615 | if (this._engineAddedToStore) {
|
| 608 | 616 | lazy.SearchUtils.notifyAction(
|
| ... | ... | @@ -620,18 +628,24 @@ export class SearchEngine { |
| 620 | 628 | * @param {string} iconURL
|
| 621 | 629 | * A URI string pointing to the engine's icon.
|
| 622 | 630 | * Must have http[s], data, or moz-extension protocol.
|
| 623 | - * @param {number} [size]
|
|
| 631 | + * @param {object} options
|
|
| 632 | + * The options object
|
|
| 633 | + * @param {number} [options.size]
|
|
| 624 | 634 | * Width and height of the icon (determined automatically if not provided).
|
| 635 | + * @param {object} [options.originAttributes]
|
|
| 636 | + * The origin attributes to use to load the icon.
|
|
| 625 | 637 | * @returns {Promise<[string, number]>}
|
| 626 | 638 | * Resolves to [dataURL, size] if successful and rejects if there was an error.
|
| 627 | 639 | */
|
| 628 | - async _downloadAndRescaleIcon(iconURL, size) {
|
|
| 640 | + async _downloadAndRescaleIcon(iconURL, options = {}) {
|
|
| 629 | 641 | let uri = lazy.SearchUtils.makeURI(iconURL);
|
| 630 | 642 | |
| 631 | 643 | if (!uri) {
|
| 632 | 644 | throw new Error(`Invalid URI`);
|
| 633 | 645 | }
|
| 634 | 646 | |
| 647 | + let size = options.size;
|
|
| 648 | + |
|
| 635 | 649 | switch (uri.scheme) {
|
| 636 | 650 | case "moz-extension": {
|
| 637 | 651 | if (!size) {
|
| ... | ... | @@ -644,7 +658,10 @@ export class SearchEngine { |
| 644 | 658 | case "data":
|
| 645 | 659 | case "http":
|
| 646 | 660 | case "https": {
|
| 647 | - let [byteArray, contentType] = await lazy.SearchUtils.fetchIcon(uri);
|
|
| 661 | + let [byteArray, contentType] = await lazy.SearchUtils.fetchIcon(
|
|
| 662 | + uri,
|
|
| 663 | + options.originAttributes
|
|
| 664 | + );
|
|
| 648 | 665 | if (byteArray.length > lazy.SearchUtils.MAX_ICON_SIZE) {
|
| 649 | 666 | lazy.logConsole.debug(
|
| 650 | 667 | `Rescaling icon for search engine ${this.name}.`
|
| ... | ... | @@ -772,7 +772,11 @@ export class SearchService { |
| 772 | 772 | null,
|
| 773 | 773 | originAttributes
|
| 774 | 774 | );
|
| 775 | - engine = new lazy.OpenSearchEngine({ engineData, faviconURL: iconURL });
|
|
| 775 | + engine = new lazy.OpenSearchEngine({
|
|
| 776 | + engineData,
|
|
| 777 | + faviconURL: iconURL,
|
|
| 778 | + originAttributes,
|
|
| 779 | + });
|
|
| 776 | 780 | } catch (ex) {
|
| 777 | 781 | throw Components.Exception(
|
| 778 | 782 | "addEngine: Error adding engine:\n" + ex,
|
| ... | ... | @@ -511,13 +511,19 @@ export var SearchUtils = { |
| 511 | 511 | *
|
| 512 | 512 | * @param {string|nsIURI} uri
|
| 513 | 513 | * The URI to the icon.
|
| 514 | + * @param {object} [originAttributes]
|
|
| 515 | + * The origin attributes to download the icon.
|
|
| 514 | 516 | * @returns {Promise<[Uint8Array, string]>}
|
| 515 | 517 | * Resolves to an array containing the data and the mime type.
|
| 516 | 518 | * Rejects if the icon cannot be fetched.
|
| 517 | 519 | */
|
| 518 | - async fetchIcon(uri) {
|
|
| 520 | + async fetchIcon(uri, originAttributes = null) {
|
|
| 519 | 521 | return new Promise((resolve, reject) => {
|
| 520 | - let chan = SearchUtils.makeChannel(uri, Ci.nsIContentPolicy.TYPE_IMAGE);
|
|
| 522 | + let chan = SearchUtils.makeChannel(
|
|
| 523 | + uri,
|
|
| 524 | + Ci.nsIContentPolicy.TYPE_IMAGE,
|
|
| 525 | + originAttributes
|
|
| 526 | + );
|
|
| 521 | 527 | let listener = new SearchUtils.LoadListener(
|
| 522 | 528 | chan,
|
| 523 | 529 | /^image\//,
|