Add doorhanger notifications for Java UI. r=mfinkle
authorGian-Carlo Pascutto <gpascutto@mozilla.com>
Tue, 25 Oct 2011 14:00:37 +0200
changeset 83242 3a14d798516092f2537b21ed89a26916b1e2d704
parent 83241 ca91054429b407a7d2bbda1597440b2f3eddbc57
child 83243 1de814feb2c97c324e1ba218ef19903f4297d420
push id519
push userakeybl@mozilla.com
push dateWed, 01 Feb 2012 00:38:35 +0000
treeherdermozilla-beta@788ea1ef610b [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmfinkle
milestone10.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Add doorhanger notifications for Java UI. r=mfinkle
embedding/android/DoorHanger.java
embedding/android/DoorHangerPopup.java
embedding/android/GeckoApp.java
embedding/android/Makefile.in
embedding/android/resources/layout/doorhangerpopup.xml
mobile/components/ContentPermissionPrompt.js
new file mode 100644
--- /dev/null
+++ b/embedding/android/DoorHanger.java
@@ -0,0 +1,93 @@
+/* -*- Mode: Java; c-basic-offset: 4; tab-width: 20; indent-tabs-mode: nil; -*-
+ * ***** BEGIN LICENSE BLOCK *****
+ * Version: MPL 1.1/GPL 2.0/LGPL 2.1
+ *
+ * The contents of this file are subject to the Mozilla Public License Version
+ * 1.1 (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ * http://www.mozilla.org/MPL/
+ *
+ * Software distributed under the License is distributed on an "AS IS" basis,
+ * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
+ * for the specific language governing rights and limitations under the
+ * License.
+ *
+ * The Original Code is Mozilla Android code.
+ *
+ * The Initial Developer of the Original Code is Mozilla Foundation.
+ * Portions created by the Initial Developer are Copyright (C) 2011
+ * the Initial Developer. All Rights Reserved.
+ *
+ * Contributor(s):
+ *   Gian-Carlo Pascutto <gpascutto@mozilla.com>
+ *
+ * Alternatively, the contents of this file may be used under the terms of
+ * either the GNU General Public License Version 2 or later (the "GPL"), or
+ * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
+ * in which case the provisions of the GPL or the LGPL are applicable instead
+ * of those above. If you wish to allow use of your version of this file only
+ * under the terms of either the GPL or the LGPL, and not to allow others to
+ * use your version of this file under the terms of the MPL, indicate your
+ * decision by deleting the provisions above and replace them with the notice
+ * and other provisions required by the GPL or the LGPL. If you do not delete
+ * the provisions above, a recipient may use your version of this file under
+ * the terms of any one of the MPL, the GPL or the LGPL.
+ *
+ * ***** END LICENSE BLOCK ***** */
+
+package org.mozilla.gecko;
+
+import java.util.ArrayList;
+
+import android.util.Log;
+import android.content.Context;
+import android.widget.PopupWindow;
+import android.widget.LinearLayout;
+
+public class DoorHanger {
+    private Context mContext;
+    public ArrayList<DoorHangerPopup> mPopups;
+
+    private final int POPUP_VERTICAL_SPACING = 10;
+    private final int POPUP_VERTICAL_OFFSET = 10;
+
+    public DoorHanger(Context aContext) {
+        mContext = aContext;
+        mPopups = new ArrayList<DoorHangerPopup>();
+    }
+
+    public DoorHangerPopup getPopup() {
+        final DoorHangerPopup dhp = new DoorHangerPopup(mContext);
+        mPopups.add(dhp);
+        return dhp;
+    }
+
+    public void removeForTab(int tabId) {
+        Log.i("DoorHanger", "removeForTab: " + tabId);
+        for (final DoorHangerPopup dhp : mPopups) {
+            if (dhp.mTabId == tabId) {
+                mPopups.remove(dhp);
+            }
+        }
+    }
+
+    public void updateForTab(int tabId) {
+        Log.i("DoorHanger", "updateForTab: " + tabId);
+        int yOffset = POPUP_VERTICAL_OFFSET;
+        for (final DoorHangerPopup dhp : mPopups) {
+            if (dhp.mTabId == tabId) {
+                dhp.setOnDismissListener(new PopupWindow.OnDismissListener() {
+                    @Override
+                    public void onDismiss() {
+                        mPopups.remove(dhp);
+                    }
+                });
+                dhp.showAtHeight(POPUP_VERTICAL_SPACING + yOffset);
+                yOffset += dhp.getHeight() + POPUP_VERTICAL_SPACING;
+            } else {
+                dhp.setOnDismissListener(null);
+                dhp.dismiss();
+            }
+        }
+    }
+}
new file mode 100644
--- /dev/null
+++ b/embedding/android/DoorHangerPopup.java
@@ -0,0 +1,111 @@
+/* -*- Mode: Java; c-basic-offset: 4; tab-width: 20; indent-tabs-mode: nil; -*-
+ * ***** BEGIN LICENSE BLOCK *****
+ * Version: MPL 1.1/GPL 2.0/LGPL 2.1
+ *
+ * The contents of this file are subject to the Mozilla Public License Version
+ * 1.1 (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ * http://www.mozilla.org/MPL/
+ *
+ * Software distributed under the License is distributed on an "AS IS" basis,
+ * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
+ * for the specific language governing rights and limitations under the
+ * License.
+ *
+ * The Original Code is Mozilla Android code.
+ *
+ * The Initial Developer of the Original Code is Mozilla Foundation.
+ * Portions created by the Initial Developer are Copyright (C) 2011
+ * the Initial Developer. All Rights Reserved.
+ *
+ * Contributor(s):
+ *   Gian-Carlo Pascutto <gpascutto@mozilla.com>
+ *
+ * Alternatively, the contents of this file may be used under the terms of
+ * either the GNU General Public License Version 2 or later (the "GPL"), or
+ * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
+ * in which case the provisions of the GPL or the LGPL are applicable instead
+ * of those above. If you wish to allow use of your version of this file only
+ * under the terms of either the GPL or the LGPL, and not to allow others to
+ * use your version of this file under the terms of the MPL, indicate your
+ * decision by deleting the provisions above and replace them with the notice
+ * and other provisions required by the GPL or the LGPL. If you do not delete
+ * the provisions above, a recipient may use your version of this file under
+ * the terms of any one of the MPL, the GPL or the LGPL.
+ *
+ * ***** END LICENSE BLOCK ***** */
+
+package org.mozilla.gecko;
+
+import android.content.Context;
+import android.widget.TextView;
+import android.widget.Button;
+import android.widget.PopupWindow;
+import android.view.Display;
+import android.view.View;
+import android.view.ViewGroup;
+import android.view.WindowManager;
+import android.view.LayoutInflater;
+import android.widget.LinearLayout;
+import android.widget.LinearLayout.LayoutParams;
+
+public class DoorHangerPopup extends PopupWindow {
+    private Context mContext;
+    private LinearLayout mChoicesLayout;
+    private TextView mTextView;
+    private Button mButton;
+    private LayoutParams mLayoutParams;
+    private View popupView;
+    public int mTabId;
+    private final int POPUP_VERTICAL_SIZE = 100;
+
+    public DoorHangerPopup(Context aContext) {
+        super(aContext);
+        mContext = aContext;
+
+        LayoutInflater inflater =
+                (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
+
+        popupView = (View) inflater.inflate(R.layout.doorhangerpopup, null);
+        setContentView(popupView);
+
+        mChoicesLayout = (LinearLayout) popupView.findViewById(R.id.doorhanger_choices);
+        mTextView = (TextView) popupView.findViewById(R.id.doorhanger_title);
+
+        mLayoutParams = new LayoutParams(LayoutParams.WRAP_CONTENT,
+                                         LayoutParams.WRAP_CONTENT);
+    }
+
+    public void addButton(String aText, int aCallback) {
+        final String sCallback = Integer.toString(aCallback);
+
+        Button mButton = new Button(mContext);
+        mButton.setText(aText);
+        mButton.setOnClickListener(new Button.OnClickListener() {
+            public void onClick(View v) {
+                GeckoEvent e = new GeckoEvent("Doorhanger:Reply", sCallback);
+                GeckoAppShell.sendEventToGecko(e);
+                dismiss();
+            }
+        });
+        mChoicesLayout.addView(mButton, mLayoutParams);
+    }
+
+    public void setText(String aText) {
+        mTextView.setText(aText);
+    }
+
+    public void setTab(int tabId) {
+        mTabId = tabId;
+    }
+
+    public void showAtHeight(int y) {
+        Display display = ((WindowManager) mContext.getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay();
+
+        int width = display.getWidth();
+        int height = display.getHeight();
+        showAsDropDown(popupView);
+        update(0, height - POPUP_VERTICAL_SIZE - y,
+               width, POPUP_VERTICAL_SIZE);
+    }
+}
--- a/embedding/android/GeckoApp.java
+++ b/embedding/android/GeckoApp.java
@@ -94,16 +94,17 @@ abstract public class GeckoApp
     public static boolean mFullscreen = false;
     public static File sGREDir = null;
     public Handler mMainHandler;
     private IntentFilter mConnectivityFilter;
     private BroadcastReceiver mConnectivityReceiver;
     private BrowserToolbar mBrowserToolbar;
     private PopupWindow mTabsTray;
     private TabsAdapter mTabsAdapter;
+    public DoorHanger mDoorHanger;
     private static boolean isTabsTrayShowing;
 
     enum LaunchState {Launching, WaitButton,
                       Launched, GeckoRunning, GeckoExiting};
     private static LaunchState sLaunchState = LaunchState.Launching;
     private static boolean sTryCatchAttached = false;
 
     private static final int FILE_PICKER_REQUEST = 1;
@@ -605,53 +606,94 @@ abstract public class GeckoApp
             } else if (event.equals("Tab:Closed")) {
                 Log.i("GeckoShell", "Destroyed a tab");
                 int tabId = message.getInt("tabID");
                 handleCloseTab(tabId);
             } else if (event.equals("Tab:Selected")) {
                 int tabId = message.getInt("tabID");
                 Log.i("GeckoShell", "Switched to tab: " + tabId);
                 handleSelectTab(tabId);
+            } else if (event.equals("Doorhanger:Add")) {
+                int tabId = message.getInt("tabID");
+                handleDoorHanger(message, tabId);
             }
         } catch (Exception e) { 
             Log.i("GeckoApp", "handleMessage throws " + e + " for message: " + event);
         }
     }
-    
+
+    void handleDoorHanger(JSONObject geckoObject, final int tabId) throws JSONException {
+        final String msg = geckoObject.getString("message");
+        Log.i("GeckoApp", "DoorHanger received for tab " + tabId
+              + ", msg:" + msg);
+        final JSONArray buttons = geckoObject.getJSONArray("buttons");
+
+        mMainHandler.post(new Runnable() {
+                public void run() {
+                    DoorHangerPopup dhp =
+                        mAppContext.mDoorHanger.getPopup();
+                    dhp.setTab(tabId);
+                    for (int i = 0; i < buttons.length(); i++) {
+                        JSONObject jo;
+                        String label;
+                        int callBackId;
+                        try {
+                            jo = buttons.getJSONObject(i);
+                            label = jo.getString("label");
+                            callBackId = jo.getInt("callback");
+                            Log.i("GeckoShell", "Label: " + label
+                                  + " CallbackId: " + callBackId);
+                            dhp.addButton(label, callBackId);
+                        } catch (JSONException e) {
+                            Log.i("GeckoShell", "JSON throws " + e);
+                        }
+                    }
+                    dhp.setText(msg);
+
+                    // Show doorhanger if it is on the active tab
+                    int activeTab = Tabs.getInstance().getSelectedTabId();
+                    mAppContext.mDoorHanger.updateForTab(activeTab);
+                }
+           });
+    }
+
     void handleAddTab(final int tabId, final String uri) {
         Tab tab = Tabs.getInstance().addTab(tabId, uri);
         mMainHandler.post(new Runnable() { 
             public void run() {
                 onTabsChanged();
                 mBrowserToolbar.updateTabs(Tabs.getInstance().getCount());
+                mDoorHanger.updateForTab(tabId);
             }
         });
     }
     
     void handleCloseTab(final int tabId) {
         Tabs.getInstance().removeTab(tabId);
         
         mMainHandler.post(new Runnable() { 
             public void run() {
                 onTabsChanged();
                 mBrowserToolbar.updateTabs(Tabs.getInstance().getCount());
+                mDoorHanger.removeForTab(tabId);
             }
         });
     }
     
     void handleSelectTab(final int tabId) {
         final Tab tab = Tabs.getInstance().selectTab(tabId);
         if (tab == null)
             return;
 
         mMainHandler.post(new Runnable() { 
             public void run() {
                 mBrowserToolbar.setTitle(tab.getTitle());
                 mBrowserToolbar.setFavicon(tab.getFavicon());
                 mBrowserToolbar.setProgressVisibility(tab.isLoading());
+                mDoorHanger.updateForTab(tabId);
             }
         });
     }
 
     void handleDocumentStart(final int tabId) {
         Tab tab = Tabs.getInstance().getTab(tabId);
 
         if (tab == null)
@@ -889,16 +931,17 @@ abstract public class GeckoApp
                              WindowManager.LayoutParams.FLAG_FULLSCREEN);
         
         setContentView(R.layout.gecko_app);
         mAppContext = this;
 
         // setup gecko layout
         mGeckoLayout = (RelativeLayout) findViewById(R.id.geckoLayout);
         mBrowserToolbar = (BrowserToolbar) findViewById(R.id.browserToolbar);
+        mDoorHanger = new DoorHanger(this);
 
         Tab tab = Tabs.getInstance().getSelectedTab();
         if (tab != null) {
             mBrowserToolbar.setTitle(tab.getTitle());
             mBrowserToolbar.setFavicon(tab.getFavicon());
             mBrowserToolbar.updateTabs(Tabs.getInstance().getCount()); 
         } 
 
@@ -948,17 +991,17 @@ abstract public class GeckoApp
         GeckoAppShell.registerGeckoEventListener("log", GeckoApp.mAppContext);
         GeckoAppShell.registerGeckoEventListener("onLocationChange", GeckoApp.mAppContext);
         GeckoAppShell.registerGeckoEventListener("onStateChange", GeckoApp.mAppContext);
         GeckoAppShell.registerGeckoEventListener("onProgressChange", GeckoApp.mAppContext);
         GeckoAppShell.registerGeckoEventListener("onCameraCapture", GeckoApp.mAppContext);
         GeckoAppShell.registerGeckoEventListener("Tab:Added", GeckoApp.mAppContext);
         GeckoAppShell.registerGeckoEventListener("Tab:Closed", GeckoApp.mAppContext);
         GeckoAppShell.registerGeckoEventListener("Tab:Selected", GeckoApp.mAppContext);
-
+        GeckoAppShell.registerGeckoEventListener("Doorhanger:Add", GeckoApp.mAppContext);
 
         mConnectivityFilter = new IntentFilter();
         mConnectivityFilter.addAction(ConnectivityManager.CONNECTIVITY_ACTION);
         mConnectivityReceiver = new GeckoConnectivityReceiver();
 
         final GeckoApp self = this;
  
         mMainHandler.postDelayed(new Runnable() {
@@ -1141,16 +1184,17 @@ abstract public class GeckoApp
         GeckoAppShell.unregisterGeckoEventListener("log", GeckoApp.mAppContext);
         GeckoAppShell.unregisterGeckoEventListener("onLocationChange", GeckoApp.mAppContext);
         GeckoAppShell.unregisterGeckoEventListener("onStateChange", GeckoApp.mAppContext);
         GeckoAppShell.unregisterGeckoEventListener("onProgressChange", GeckoApp.mAppContext);
         GeckoAppShell.unregisterGeckoEventListener("onCameraCapture", GeckoApp.mAppContext);
         GeckoAppShell.unregisterGeckoEventListener("Tab:Added", GeckoApp.mAppContext);
         GeckoAppShell.unregisterGeckoEventListener("Tab:Closed", GeckoApp.mAppContext);
         GeckoAppShell.unregisterGeckoEventListener("Tab:Selected", GeckoApp.mAppContext);
+        GeckoAppShell.unregisterGeckoEventListener("Doorhanger:Add", GeckoApp.mAppContext);
 
         super.onDestroy();
     }
 
     @Override
     public void onConfigurationChanged(android.content.res.Configuration newConfig)
     {
         Log.i(LOG_FILE_NAME, "configuration changed");
--- a/embedding/android/Makefile.in
+++ b/embedding/android/Makefile.in
@@ -56,16 +56,18 @@ JAVAFILES = \
   AlertNotification.java \
   AwesomeBar.java \
   GeckoBookmarks.java \
   Tab.java \
   Tabs.java \
   GeckoEventListener.java \
   PromptService.java \
   SurfaceInfo.java \
+  DoorHanger.java \
+  DoorHangerPopup.java \
   $(NULL)
 
 PROCESSEDJAVAFILES = \
   App.java \
   Restarter.java \
   NotificationHandler.java \
   LauncherShortcuts.java \
   $(NULL)
@@ -137,16 +139,17 @@ RES_LAYOUT = \
   res/layout/awesomebar_search.xml \
   res/layout/awesomebar_row.xml \
   res/layout/browser_toolbar.xml \
   res/layout/bookmarks.xml \
   res/layout/bookmark_list_row.xml \
   res/layout/tabs_tray.xml \
   res/layout/tabs_row.xml \
   res/layout/dialog_checkbox.xml \
+  res/layout/doorhangerpopup.xml \
   $(NULL)
 
 RES_VALUES = \
   res/values/colors.xml \
   res/values/styles.xml \
   res/values/themes.xml \
   $(NULL)
 
new file mode 100644
--- /dev/null
+++ b/embedding/android/resources/layout/doorhangerpopup.xml
@@ -0,0 +1,13 @@
+<?xml version="1.0" encoding="utf-8"?>
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+              android:orientation="vertical"
+              android:layout_width="wrap_content"
+              android:layout_height="wrap_content">
+  <TextView android:id="@+id/doorhanger_title"
+            android:layout_width="wrap_content"
+            android:layout_height="wrap_content"/>
+  <LinearLayout android:id="@+id/doorhanger_choices"
+                android:orientation="horizontal"
+                android:layout_width="wrap_content"
+                android:layout_height="wrap_content"/>
+</LinearLayout>
--- a/mobile/components/ContentPermissionPrompt.js
+++ b/mobile/components/ContentPermissionPrompt.js
@@ -1,17 +1,61 @@
+/* ***** BEGIN LICENSE BLOCK *****
+ * Version: MPL 1.1/GPL 2.0/LGPL 2.1
+ *
+ * The contents of this file are subject to the Mozilla Public License Version
+ * 1.1 (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ * http://www.mozilla.org/MPL/
+ *
+ * Software distributed under the License is distributed on an "AS IS" basis,
+ * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
+ * for the specific language governing rights and limitations under the
+ * License.
+ *
+ * The Original Code is mozilla.org code
+ *
+ * The Initial Developer of the Original Code is
+ * Mozilla Foundation.
+ * Portions created by the Initial Developer are Copyright (C) 2011
+ * the Initial Developer. All Rights Reserved.
+ *
+ * Contributor(s):
+ *   Gian-Carlo Pascutto <gpascutto@mozilla.com>
+ *
+ * Alternatively, the contents of this file may be used under the terms of
+ * either the GNU General Public License Version 2 or later (the "GPL"), or
+ * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
+ * in which case the provisions of the GPL or the LGPL are applicable instead
+ * of those above. If you wish to allow use of your version of this file only
+ * under the terms of either the GPL or the LGPL, and not to allow others to
+ * use your version of this file under the terms of the MPL, indicate your
+ * decision by deleting the provisions above and replace them with the notice
+ * and other provisions required by the GPL or the LGPL. If you do not delete
+ * the provisions above, a recipient may use your version of this file under
+ * the terms of any one of the MPL, the GPL or the LGPL.
+ *
+ * ***** END LICENSE BLOCK ***** */
+
 const Ci = Components.interfaces;
 const Cr = Components.results;
 const Cu = Components.utils;
+const Cc = Components.classes;
 
 Cu.import("resource://gre/modules/XPCOMUtils.jsm");
 Cu.import("resource://gre/modules/Services.jsm");
 
 const kCountBeforeWeRemember = 5;
 
+function dump(a) {
+    Cc["@mozilla.org/consoleservice;1"]
+        .getService(Ci.nsIConsoleService)
+        .logStringMessage(a);
+}
+
 function setPagePermission(type, uri, allow) {
   let pm = Services.perms;
   let contentPrefs = Services.contentPrefs;
   let contentPrefName = type + ".request.remember";
 
   if (!contentPrefs.hasPref(uri, contentPrefName))
       contentPrefs.setPref(uri, contentPrefName, 0);
 
@@ -35,91 +79,155 @@ const kEntities = { "geolocation": "geol
 
 function ContentPermissionPrompt() {}
 
 ContentPermissionPrompt.prototype = {
   classID: Components.ID("{C6E8C44D-9F39-4AF7-BCC0-76E38A8310F5}"),
 
   QueryInterface: XPCOMUtils.generateQI([Ci.nsIContentPermissionPrompt]),
 
-  getChromeWindow: function getChromeWindow(aWindow) {
-     let chromeWin = aWindow.QueryInterface(Ci.nsIInterfaceRequestor)
-                            .getInterface(Ci.nsIWebNavigation)
-                            .QueryInterface(Ci.nsIDocShellTreeItem)
-                            .rootTreeItem
-                            .QueryInterface(Ci.nsIInterfaceRequestor)
-                            .getInterface(Ci.nsIDOMWindow)
-                            .QueryInterface(Ci.nsIDOMChromeWindow);
-     return chromeWin;
-  },
-
-  getNotificationBoxForRequest: function getNotificationBoxForRequest(request) {
-    let notificationBox = null;
-    if (request.window) {
-      let requestingWindow = request.window.top;
-      let chromeWin = this.getChromeWindow(requestingWindow).wrappedJSObject;
-      let windowID = window.QueryInterface(Ci.nsIInterfaceRequestor).getInterface(Ci.nsIDOMWindowUtils).currentInnerWindowID;
-      let browser = chromeWin.Browser.getBrowserForWindowId(windowID);
-      return chromeWin.getNotificationBox(browser);
-    }
-
-    let chromeWin = request.element.ownerDocument.defaultView;
-    return chromeWin.Browser.getNotificationBox(request.element);
-  },
+  _promptId : 0,
+  _callbackId : 0,
+  _callbacks : [],
 
   handleExistingPermission: function handleExistingPermission(request) {
     let result = Services.perms.testExactPermission(request.uri, request.type);
     if (result == Ci.nsIPermissionManager.ALLOW_ACTION) {
       request.allow();
       return true;
     }
     if (result == Ci.nsIPermissionManager.DENY_ACTION) {
       request.cancel();
       return true;
     }
     return false;
   },
 
+  getChromeWindow: function getChromeWindow(aWindow) {
+     let chromeWin = aWindow.QueryInterface(Ci.nsIInterfaceRequestor)
+                            .getInterface(Ci.nsIWebNavigation)
+                            .QueryInterface(Ci.nsIDocShellTreeItem)
+                            .rootTreeItem
+                            .QueryInterface(Ci.nsIInterfaceRequestor)
+                            .getInterface(Ci.nsIDOMWindow)
+                            .QueryInterface(Ci.nsIDOMChromeWindow);
+     return chromeWin;
+  },
+
+  getTabForRequest: function getTabForRequest(request) {
+    if (request.window) {
+      let requestingWindow = request.window.top;
+      let chromeWin = this.getChromeWindow(requestingWindow).wrappedJSObject;
+      let windowID = chromeWin.QueryInterface(Ci.nsIInterfaceRequestor).getInterface(Ci.nsIDOMWindowUtils).currentInnerWindowID;
+      let browser = chromeWin.BrowserApp.getBrowserForWindow(request.window);
+      let tabID = chromeWin.BrowserApp.getTabForBrowser(browser).id;
+      return tabID;
+    }
+    let chromeWin = request.element.ownerDocument.defaultView;
+    let browser = chromeWin.Browser;
+    let tabID = chromeWin.BrowserApp.getTabForBrowser(browser).id;
+    return tabID;
+  },
+
   prompt: function(request) {
     // returns true if the request was handled
     if (this.handleExistingPermission(request))
        return;
 
     let pm = Services.perms;
-    let notificationBox = this.getNotificationBoxForRequest(request);
     let browserBundle = Services.strings.createBundle("chrome://browser/locale/browser.properties");
-    
-    let notification = notificationBox.getNotificationWithValue(request.type);
-    if (notification)
-      return;
 
     let entityName = kEntities[request.type];
 
+    let tabID = this.getTabForRequest(request);
+
+    this._promptId++;
+    this._callbackId++;
+    let allowCallback = {
+      cb : function(notification) {
+        setPagePermission(request.type, request.uri, true);
+        request.allow();
+      },
+      callbackId  : this._callbackId,
+      promptId : this._promptId
+    };
+    this._callbackId++;
+    let denyCallback = {
+      cb : function(notification) {
+        setPagePermission(request.type, request.uri, false);
+        request.cancel();
+      },
+      callbackId : this._callbackId,
+      promptId : this._promptId
+    };
+    this._callbacks.push(allowCallback);
+    this._callbacks.push(denyCallback);
+
     let buttons = [{
       label: browserBundle.GetStringFromName(entityName + ".allow"),
       accessKey: null,
-      callback: function(notification) {
-        setPagePermission(request.type, request.uri, true);
-        request.allow();
-      }
+      callback: allowCallback.callbackId
     },
     {
       label: browserBundle.GetStringFromName(entityName + ".dontAllow"),
       accessKey: null,
-      callback: function(notification) {
-        setPagePermission(request.type, request.uri, false);
-        request.cancel();
-      }
+      callback: denyCallback.callbackId
     }];
 
     let message = browserBundle.formatStringFromName(entityName + ".wantsTo",
                                                      [request.uri.host], 1);
-    let newBar = notificationBox.appendNotification(message,
-                                                    request.type,
-                                                    "", // Notifications in Fennec do not display images.
-                                                    notificationBox.PRIORITY_WARNING_MEDIUM,
-                                                    buttons);
+
+    let DoorhangerEventListener = {
+      _contentPermission: this,
+      init: function(owner) {
+        Services.obs.addObserver(this, "Doorhanger:Reply", false);
+      },
+      observe: function(aSubject, aTopic, aData) {
+        let cpo = this._contentPermission;
+        if (aTopic == "Doorhanger:Reply") {
+          let cbId = parseInt(aData);
+          let promptId = -1;
+          let keepStack = [];
+          // Find the callback to call for this id
+          for (i = 0; i < cpo._callbacks.length; i++) {
+            if (cpo._callbacks[i].callbackId == cbId) {
+              promptId = cpo._callbacks[i].promptId;
+              cpo._callbacks[i].cb();
+              break;
+            }
+          }
+          // Now find all remaining callbacks that were not
+          // in the same notification (!same promptId)
+          for (i = 0; i < cpo._callbacks.length; i++) {
+            if (cpo._callbacks[i].promptId != promptId) {
+              keepStack.push(cpo._callbacks[i]);
+            }
+          }
+          // Keep those, throw away everything else
+          cpo._callbacks = keepStack;
+          if (cpo._callbacks.length == 0) {
+            // Remove if this was the last one outstanding
+            Services.obs.removeObserver(this, "Doorhanger:Reply");
+          }
+        }
+      }
+    };
+    DoorhangerEventListener.init(this);
+
+    let json = {
+      gecko: {
+        type: "Doorhanger:Add",
+        message: message,
+        severity: "PRIORITY_WARNING_MEDIUM",
+        buttons: buttons,
+        tabID: tabID
+      }
+    };
+
+    Cc["@mozilla.org/android/bridge;1"]
+          .getService(Ci.nsIAndroidBridge)
+          .handleGeckoMessage(JSON.stringify(json));
   }
 };
 
 
 //module initialization
 const NSGetFactory = XPCOMUtils.generateNSGetFactory([ContentPermissionPrompt]);