Bug 1450344 - 1. Use frame script to handle input prompts; r?esawin draft
authorJim Chen <nchen@mozilla.com>
Thu, 05 Apr 2018 18:50:12 -0400
changeset 778196 65a96ffcc858b6cc34aed5febfd18c2652fbbae7
parent 778194 34bbbfc918b1911cf195b2e55e02839a3cb79228
child 778197 5da6ff4a6e6cf5edcba0f0bcc80fa8d68cf201b0
push id105423
push userbmo:nchen@mozilla.com
push dateThu, 05 Apr 2018 22:54:08 +0000
reviewersesawin
bugs1450344
milestone61.0a1
Bug 1450344 - 1. Use frame script to handle input prompts; r?esawin Use a frame script to handle <select> and <input type="date/time"> prompts, in order to support e10s iframes. MozReview-Commit-ID: AE0KGu8QwUf
mobile/android/chrome/geckoview/GeckoViewPromptContent.js
mobile/android/chrome/geckoview/jar.mn
mobile/android/components/geckoview/GeckoViewStartup.js
new file mode 100644
--- /dev/null
+++ b/mobile/android/chrome/geckoview/GeckoViewPromptContent.js
@@ -0,0 +1,15 @@
+/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+ChromeUtils.import("resource://gre/modules/GeckoViewUtils.jsm");
+
+GeckoViewUtils.addLazyEventListener(this, ["click", "contextmenu"], {
+  handler: _ =>
+    Cc["@mozilla.org/prompter;1"].getService(Ci.nsIDOMEventListener),
+  options: {
+    capture: false,
+    mozSystemGroup: true,
+  },
+});
--- a/mobile/android/chrome/geckoview/jar.mn
+++ b/mobile/android/chrome/geckoview/jar.mn
@@ -6,10 +6,11 @@ geckoview.jar:
 % content geckoview %content/
 
   content/ErrorPageEventHandler.js
   content/geckoview.xul
   content/geckoview.js
   content/GeckoViewContent.js
   content/GeckoViewContentSettings.js
   content/GeckoViewNavigationContent.js
+  content/GeckoViewPromptContent.js
   content/GeckoViewScrollContent.js
   content/GeckoViewSelectionActionContent.js
--- a/mobile/android/components/geckoview/GeckoViewStartup.js
+++ b/mobile/android/components/geckoview/GeckoViewStartup.js
@@ -33,37 +33,31 @@ GeckoViewStartup.prototype = {
     protocolHandler.setSubstitution("android", Services.io.newURI(url));
   },
 
   /* ----------  nsIObserver  ---------- */
   observe: function(aSubject, aTopic, aData) {
     switch (aTopic) {
       case "app-startup": {
         // Parent and content process.
-        Services.obs.addObserver(this, "chrome-document-global-created");
-        Services.obs.addObserver(this, "content-document-global-created");
-
         GeckoViewUtils.addLazyGetter(this, "GeckoViewPermission", {
           service: "@mozilla.org/content-permission/prompt;1",
           observers: [
             "getUserMedia:ask-device-permission",
             "getUserMedia:request",
             "PeerConnection:request",
           ],
         });
 
         if (Services.appinfo.processType == Services.appinfo.PROCESS_TYPE_DEFAULT) {
           // Parent process only.
           this.setResourceSubstitutions();
 
-        } else {
-          // Content process only.
-          GeckoViewUtils.addLazyGetter(this, "GeckoViewPrompt", {
-            service: "@mozilla.org/prompter;1",
-          });
+          Services.mm.loadFrameScript(
+              "chrome://geckoview/content/GeckoViewPromptContent.js", true);
         }
         break;
       }
 
       case "profile-after-change": {
         // Parent process only.
         // ContentPrefServiceParent is needed for e10s file picker.
         GeckoViewUtils.addLazyGetter(this, "ContentPrefServiceParent", {
@@ -79,31 +73,13 @@ GeckoViewStartup.prototype = {
         GeckoViewUtils.addLazyGetter(this, "GeckoViewPrompt", {
           service: "@mozilla.org/prompter;1",
           mm: [
             "GeckoView:Prompt",
           ],
         });
         break;
       }
-
-      case "chrome-document-global-created":
-      case "content-document-global-created": {
-        let win = GeckoViewUtils.getChromeWindow(aSubject);
-        if (win !== aSubject) {
-          // Only attach to top-level windows.
-          return;
-        }
-
-        GeckoViewUtils.addLazyEventListener(win, ["click", "contextmenu"], {
-          handler: _ => this.GeckoViewPrompt,
-          options: {
-            capture: false,
-            mozSystemGroup: true,
-          },
-        });
-        break;
-      }
     }
   },
 };
 
 this.NSGetFactory = XPCOMUtils.generateNSGetFactory([GeckoViewStartup]);