Bug 479279: Fennec should have a system for browser-level notifications, r=gavin
authorMark Finkle <mfinkle@mozilla.com>
Thu, 09 Apr 2009 01:13:16 -0400
changeset 65160 fa11593b9870150966f030c0790b8a228c74976c
parent 65159 92bf78725729ed4a5cb93f297d998bfd07715734
child 65161 a67b9731650de728d8a66907f4d8e1566b65fa97
push id1
push userroot
push dateMon, 20 Oct 2014 17:29:22 +0000
reviewersgavin
bugs479279
Bug 479279: Fennec should have a system for browser-level notifications, r=gavin
mobile/chrome/content/browser.js
mobile/chrome/content/browser.xul
mobile/components/Makefile.in
mobile/components/alertsService.js
mobile/themes/hildon/browser.css
mobile/themes/wince/browser.css
--- a/mobile/chrome/content/browser.js
+++ b/mobile/chrome/content/browser.js
@@ -1009,16 +1009,64 @@ const gXPInstallObserver = {
     }
   }
 };
 
 function getNotificationBox(aWindow) {
   return Browser.getNotificationBox();
 }
 
+var AlertsHelper = {
+  _timeoutID: -1,
+  _listener: null,
+  _cookie: "",
+  _clickable: false,
+
+  showAlertNotification: function ah_show(aImageURL, aTitle, aText, aTextClickable, aCookie, aListener) {
+    this._clickable = aTextClickable || false;
+    this._listener = aListener || null;
+    this._cookie = aCookie || "";
+
+    document.getElementById("alerts-image").setAttribute("src", aImageURL);
+    document.getElementById("alerts-title").value = aTitle;
+    document.getElementById("alerts-text").textContent = aText;
+
+    let container = document.getElementById("alerts-container");
+    container.hidden = false;
+
+    let rect = container.getBoundingClientRect();
+    container.top = window.innerHeight - (rect.height + 20);
+    container.left = window.innerWidth - (rect.width + 20);
+
+    let timeout = gPrefService.getIntPref("alerts.totalOpenTime");
+    let self = this;
+    this._timeoutID = setTimeout(function() { self._timeoutAlert(); }, timeout);
+  },
+
+  _timeoutAlert: function ah__timeoutAlert() {
+    this._timeoutID = -1;
+    let container = document.getElementById("alerts-container");
+    container.hidden = true;
+
+    if (this._listener)
+      this._listener.observe(null, "alertfinished", this._cookie);
+
+    // TODO: add slide to UI
+  },
+
+  click: function ah_click(aEvent) {
+    if (this._clickable && this._listener)
+      this._listener.observe(null, "alertclickcallback", this._cookie);
+
+    if (this._timeoutID != -1) {
+      clearTimeout(this._timeoutID);
+      this._timeoutAlert();
+    }
+  }
+}
 
 function ProgressController(tab) {
   this._tab = tab;
 }
 
 ProgressController.prototype = {
   get browser() {
     return this._tab.browser;
--- a/mobile/chrome/content/browser.xul
+++ b/mobile/chrome/content/browser.xul
@@ -362,16 +362,24 @@
       <hbox id="folder-header" style="height: 60px">
         <description flex="1">&foldersHeader.label;</description>
         <toolbarbutton id="tool-folders-close" class="urlbar-button"
                        oncommand="FolderPicker.close()"/>
       </hbox>
       <placetree id="folder-items" type="bookmarks" mode="folders" flex="1" onselect="FolderPicker.moveItem();"/>
     </vbox>
 
+    <hbox id="alerts-container" hidden="true" style="-moz-stack-sizing: ignore;" align="start" top="0" left="0" width="200"
+          onclick="AlertsHelper.click(event);">
+      <image id="alerts-image"/>
+      <vbox>
+        <label id="alerts-title" value=""/>
+        <description id="alerts-text"/>
+      </vbox>
+    </hbox>
   </stack>
 
   </box>
 
   <vbox id="findpanel-placeholder" sizetopopup="always">
     <panel id="findpanel" onpopupshown="Browser.doFind()">
       <findbar id="findbar"/>
    </panel>
--- a/mobile/components/Makefile.in
+++ b/mobile/components/Makefile.in
@@ -47,18 +47,19 @@ MODULE = browsercomps
 XPIDL_MODULE = browsercompsbase
 
 #XPIDLSRCS = \
 #	$(NULL)
 
 EXTRA_COMPONENTS = \
 	aboutFirstrun.js \
 	geolocationPrompt.js \
+	alertsService.js \
 	$(NULL)
 
 DIRS = protocols \
 	$(NULL)
-	
+
 ifdef WINCE
 DIRS += phone
-endif       	
+endif
 
 include $(topsrcdir)/config/rules.mk
new file mode 100644
--- /dev/null
+++ b/mobile/components/alertsService.js
@@ -0,0 +1,63 @@
+/* ***** 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 Alerts Service.
+ *
+ * The Initial Developer of the Original Code is Mozilla Foundation.
+ * Portions created by the Initial Developer are Copyright (C) 2009
+ * the Initial Developer. All Rights Reserved.
+ *
+ * Contributor(s):
+ *   Mark Finkle <mfinkle@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 Cc = Components.classes;
+const Ci = Components.interfaces;
+
+Components.utils.import("resource://gre/modules/XPCOMUtils.jsm");
+
+// -----------------------------------------------------------------------
+// Alerts Service
+// -----------------------------------------------------------------------
+
+function AlertsService() { }
+
+AlertsService.prototype = {
+  classDescription: "Alerts Service",
+  contractID: "@mozilla.org/alerts-service;1",
+  classID: Components.ID("{fe33c107-82a4-41d6-8c64-5353267e04c9}"),
+  QueryInterface: XPCOMUtils.generateQI([Ci.nsIAlertsService]),
+
+  showAlertNotification: function(aImageUrl, aTitle, aText, aTextClickable, aCookie, aAlertListener, aName) {
+    let wm = Cc["@mozilla.org/appshell/window-mediator;1"].getService(Ci.nsIWindowMediator);
+    let browser = wm.getMostRecentWindow("navigator:browser");
+    browser.AlertsHelper.showAlertNotification(aImageUrl, aTitle, aText, aTextClickable, aCookie, aAlertListener);
+  }
+};
+
+function NSGetModule(aCompMgr, aFileSpec) {
+  return XPCOMUtils.generateModule([AlertsService]);
+}
--- a/mobile/themes/hildon/browser.css
+++ b/mobile/themes/hildon/browser.css
@@ -718,8 +718,23 @@ richpref > button {
   font-size: 1em ! important;
 }
 
 /* Shortcut editor   ------------------------------------------------------- */
 #shortcuts {
   border: 0;
   padding: .2em;
 }
+
+/* alerts popup ----------------------------------------------------------- */
+#alerts-container {
+  color: #000;
+  background-color: #fff;
+  border: 4px solid gray;
+  -moz-border-radius: 8px;
+  padding: 8px;
+  -moz-box-shadow: black 4px 4px 10px;
+}
+
+#alerts-text {
+  font-size: 85% !important;
+  white-space: pre-wrap;
+}
--- a/mobile/themes/wince/browser.css
+++ b/mobile/themes/wince/browser.css
@@ -711,8 +711,23 @@ richpref > button {
   font-size: 1em ! important;
 }
 
 /* Shortcut editor   ------------------------------------------------------- */
 #shortcuts {
   border: 0;
   padding: .2em;
 }
+
+/* alerts popup ----------------------------------------------------------- */
+#alerts-container {
+  color: #000;
+  background-color: #fff;
+  border: 4px solid gray;
+  -moz-border-radius: 8px;
+  padding: 8px;
+  -moz-box-shadow: black 4px 4px 10px;
+}
+
+#alerts-text {
+  font-size: 85% !important;
+  white-space: pre-wrap;
+}