Commit 99661088 authored by Mark Banner's avatar Mark Banner Committed by Richard Pospesel
Browse files

Bug 1845752. r=ckerschb

parent 1674ff16
Loading
Loading
Loading
Loading
+6 −1
Original line number Original line Diff line number Diff line
@@ -144,7 +144,12 @@ export class OpenSearchEngine extends SearchEngine {


    lazy.logConsole.debug("_install: Downloading engine from:", loadURI.spec);
    lazy.logConsole.debug("_install: Downloading engine from:", loadURI.spec);


    var chan = lazy.SearchUtils.makeChannel(loadURI);
    var chan = lazy.SearchUtils.makeChannel(
      loadURI,
      // OpenSearchEngine is loading a definition file for a search engine,
      // TYPE_DOCUMENT captures that load best
      Ci.nsIContentPolicy.TYPE_DOCUMENT
    );


    if (this._engineToUpdate && chan instanceof Ci.nsIHttpChannel) {
    if (this._engineToUpdate && chan instanceof Ci.nsIHttpChannel) {
      var lastModified = this._engineToUpdate.getAttr("updatelastmodified");
      var lastModified = this._engineToUpdate.getAttr("updatelastmodified");
+4 −1
Original line number Original line Diff line number Diff line
@@ -805,7 +805,10 @@ export class SearchEngine {
          this._hasPreferredIcon = isPreferred;
          this._hasPreferredIcon = isPreferred;
        };
        };


        let chan = lazy.SearchUtils.makeChannel(uri);
        let chan = lazy.SearchUtils.makeChannel(
          uri,
          Ci.nsIContentPolicy.TYPE_IMAGE
        );
        let listener = new lazy.SearchUtils.LoadListener(
        let listener = new lazy.SearchUtils.LoadListener(
          chan,
          chan,
          /^image\//,
          /^image\//,
+8 −3
Original line number Original line Diff line number Diff line
@@ -248,19 +248,24 @@ export var SearchUtils = {
   *
   *
   * @param {string|nsIURI} url
   * @param {string|nsIURI} url
   *   The URL string from which to create an nsIChannel.
   *   The URL string from which to create an nsIChannel.
   * @param {nsIContentPolicy} contentPolicyType
   *   The type of document being loaded.
   * @returns {nsIChannel}
   * @returns {nsIChannel}
   *   an nsIChannel object, or null if the url is invalid.
   *   an nsIChannel object, or null if the url is invalid.
   */
   */
  makeChannel(url) {
  makeChannel(url, contentPolicyType) {
    if (!contentPolicyType) {
      throw new Error("makeChannel called with invalid content policy type");
    }
    try {
    try {
      let uri = typeof url == "string" ? Services.io.newURI(url) : url;
      let uri = typeof url == "string" ? Services.io.newURI(url) : url;
      return Services.io.newChannelFromURI(
      return Services.io.newChannelFromURI(
        uri,
        uri,
        null /* loadingNode */,
        null /* loadingNode */,
        Services.scriptSecurityManager.getSystemPrincipal(),
        Services.scriptSecurityManager.createNullPrincipal({}),
        null /* triggeringPrincipal */,
        null /* triggeringPrincipal */,
        Ci.nsILoadInfo.SEC_ALLOW_CROSS_ORIGIN_SEC_CONTEXT_IS_NULL,
        Ci.nsILoadInfo.SEC_ALLOW_CROSS_ORIGIN_SEC_CONTEXT_IS_NULL,
        Ci.nsIContentPolicy.TYPE_OTHER
        contentPolicyType
      );
      );
    } catch (ex) {}
    } catch (ex) {}


+1 −1
Original line number Original line Diff line number Diff line
@@ -10,7 +10,7 @@ function handleRequest(request, response) {
  response.setStatusLine("1.1", 302, "Moved");
  response.setStatusLine("1.1", 302, "Moved");
  if (request.queryString == "type=invalid") {
  if (request.queryString == "type=invalid") {
    response.setHeader("Content-Type", "image/png", false);
    response.setHeader("Content-Type", "image/png", false);
    response.setHeader("Location", "engine.xml", false);
    response.setHeader("Location", "/head_search.js", false);
  } else {
  } else {
    response.setHeader("Content-Type", "text/html", false);
    response.setHeader("Content-Type", "text/html", false);
    response.setHeader("Location", "remoteIcon.ico", false);
    response.setHeader("Location", "remoteIcon.ico", false);
+4 −1
Original line number Original line Diff line number Diff line
@@ -12,9 +12,11 @@ add_task(async function setup() {
});
});


add_task(async function test_installedresourceicon() {
add_task(async function test_installedresourceicon() {
  // Attempts to load a resource:// url as an icon.
  let engine1 = await SearchTestUtils.promiseNewSearchEngine({
  let engine1 = await SearchTestUtils.promiseNewSearchEngine({
    url: `${gDataUrl}opensearch/resourceicon.xml`,
    url: `${gDataUrl}opensearch/resourceicon.xml`,
  });
  });
  // Attempts to load a chrome:// url as an icon.
  let engine2 = await SearchTestUtils.promiseNewSearchEngine({
  let engine2 = await SearchTestUtils.promiseNewSearchEngine({
    url: `${gDataUrl}opensearch/chromeicon.xml`,
    url: `${gDataUrl}opensearch/chromeicon.xml`,
  });
  });
@@ -32,12 +34,13 @@ add_task(async function test_installedhttpplace() {


  // The easiest way to test adding the icon is via a generated xml, otherwise
  // The easiest way to test adding the icon is via a generated xml, otherwise
  // we have to somehow insert the address of the server into it.
  // we have to somehow insert the address of the server into it.
  // Attempts to load a non-image page into an image icon.
  let engine = await SearchTestUtils.promiseNewSearchEngine({
  let engine = await SearchTestUtils.promiseNewSearchEngine({
    url:
    url:
      `${gDataUrl}data/engineMaker.sjs?` +
      `${gDataUrl}data/engineMaker.sjs?` +
      JSON.stringify({
      JSON.stringify({
        baseURL: gDataUrl,
        baseURL: gDataUrl,
        image: "opensearch/resourceicon.xml",
        image: "head_search.js",
        name: "invalidicon",
        name: "invalidicon",
        method: "GET",
        method: "GET",
      }),
      }),
Loading