Commit a136df50 authored by Jim Chen's avatar Jim Chen
Browse files

Bug 1367077 - 2. Move PromptService startup to BrowserCLH; r=snorp

Use the BrowserCLH for PromptService startup, to consolidate startup
handling code and also to delay loading PromptService.

MozReview-Commit-ID: 25UgVH7wrrs

--HG--
extra : rebase_source : a47a50f81cbc21ba0aaee714fb1de8099d778450
parent 70aad3b8
Loading
Loading
Loading
Loading
+29 −0
Original line number Diff line number Diff line
@@ -45,11 +45,15 @@ BrowserCLH.prototype = {
      case "app-startup": {
        this.setResourceSubstitutions();

        Services.obs.addObserver(this, "chrome-document-global-created");
        Services.obs.addObserver(this, "content-document-global-created");

        GeckoViewUtils.addLazyGetter(this, "DownloadNotifications", {
          module: "resource://gre/modules/DownloadNotifications.jsm",
          observers: ["chrome-document-loaded"],
          once: true,
        });

        if (AppConstants.MOZ_WEBRTC) {
          GeckoViewUtils.addLazyGetter(this, "WebrtcUI", {
            script: "chrome://browser/content/WebrtcUI.js",
@@ -63,6 +67,31 @@ BrowserCLH.prototype = {
            ],
          });
        }

        GeckoViewUtils.addLazyGetter(this, "SelectHelper", {
          script: "chrome://browser/content/SelectHelper.js",
        });
        GeckoViewUtils.addLazyGetter(this, "InputWidgetHelper", {
          script: "chrome://browser/content/InputWidgetHelper.js",
        });
        break;
      }

      case "chrome-document-global-created":
      case "content-document-global-created": {
        let win = GeckoViewUtils.getChromeWindow(subject);
        if (win !== subject) {
          // Only attach to top-level windows.
          return;
        }

        GeckoViewUtils.addLazyEventListener(win, "click", {
          handler: _ => [this.SelectHelper, this.InputWidgetHelper],
          options: {
            capture: true,
            mozSystemGroup: true,
          },
        });
        break;
      }
    }
+0 −1
Original line number Diff line number Diff line
@@ -41,7 +41,6 @@ contract @mozilla.org/prompter;1 {9a61149b-2276-4a0a-b79c-be994ad106cf}
contract @mozilla.org/embedcomp/prompt-service;1 {9a61149b-2276-4a0a-b79c-be994ad106cf}
component {80dae1e9-e0d2-4974-915f-f97050fa8068} PromptService.js
contract @mozilla.org/network/authprompt-adapter-factory;1 {80dae1e9-e0d2-4974-915f-f97050fa8068}
category app-startup PromptService service,@mozilla.org/prompter;1

# PresentationDevicePrompt.js
component {388bd149-c919-4a43-b646-d7ec57877689} PresentationDevicePrompt.js
+1 −40
Original line number Diff line number Diff line
@@ -22,46 +22,7 @@ PromptService.prototype = {
  classID: Components.ID("{9a61149b-2276-4a0a-b79c-be994ad106cf}"),

  QueryInterface: XPCOMUtils.generateQI([
      Ci.nsIObserver, Ci.nsIPromptFactory, Ci.nsIPromptService, Ci.nsIPromptService2]),

  loadSubscript: function(aName, aScript) {
    let sandbox = {};
    Services.scriptloader.loadSubScript(aScript, sandbox);
    return sandbox[aName];
  },

  /* ----------  nsIObserver  ---------- */
  observe: function(aSubject, aTopic, aData) {
    switch (aTopic) {
      case "app-startup": {
        Services.obs.addObserver(this, "chrome-document-global-created");
        Services.obs.addObserver(this, "content-document-global-created");
        break;
      }
      case "chrome-document-global-created":
      case "content-document-global-created": {
        let win = aSubject.QueryInterface(Ci.nsIInterfaceRequestor)
                          .getInterface(Ci.nsIDocShell).QueryInterface(Ci.nsIDocShellTreeItem)
                          .rootTreeItem.QueryInterface(Ci.nsIInterfaceRequestor)
                          .getInterface(Ci.nsIDOMWindow);
        if (win !== aSubject) {
          // Only attach to top-level windows.
          return;
        }
        if (!this.selectHelper) {
          this.selectHelper = this.loadSubscript(
              "SelectHelper", "chrome://browser/content/SelectHelper.js");
        }
        if (!this.inputWidgetHelper) {
          this.inputWidgetHelper = this.loadSubscript(
              "InputWidgetHelper", "chrome://browser/content/InputWidgetHelper.js");
        }
        win.addEventListener("click", this.selectHelper, /* capture */ true);
        win.addEventListener("click", this.inputWidgetHelper, /* capture */ true);
        break;
      }
    }
  },
      Ci.nsIPromptFactory, Ci.nsIPromptService, Ci.nsIPromptService2]),

  /* ----------  nsIPromptFactory  ---------- */
  // XXX Copied from nsPrompter.js.