From f6445669962b96719bcee5b162d791922828a00a Mon Sep 17 00:00:00 2001 From: Ryan VanderMeulen Date: Mon, 3 Jun 2013 15:04:51 -0400 Subject: [PATCH] Backed out 7 changesets (bug 872147, bug 872143, bug 877467, bug 877200, bug 870063, bug 872149) for robocop-2 failures on a CLOSED TREE. Backed out changeset 3a1e8e7ac07e (bug 870063) Backed out changeset 8904d2bf5da0 (bug 877200) Backed out changeset 80455a25276b (bug 872149) Backed out changeset c3b5567f1271 (bug 872147) Backed out changeset d3106edd4a5a (bug 872143) Backed out changeset 4fd2ae88da98 (bug 870063) Backed out changeset 1797dc46e862 (bug 877467) --- mobile/android/chrome/content/FeedHandler.js | 81 ++++++++++------ .../chrome/content/InputWidgetHelper.js | 59 ++++++------ mobile/android/chrome/content/browser.js | 95 ++++++++++++------- mobile/android/components/PaymentsUI.js | 27 ++++-- mobile/android/modules/Prompt.jsm | 31 +++--- 5 files changed, 174 insertions(+), 119 deletions(-) diff --git a/mobile/android/chrome/content/FeedHandler.js b/mobile/android/chrome/content/FeedHandler.js index bd761317c52..0cb513aaa28 100644 --- a/mobile/android/chrome/content/FeedHandler.js +++ b/mobile/android/chrome/content/FeedHandler.js @@ -72,26 +72,34 @@ var FeedHandler = { // First, let's decide on which feed to subscribe let feedIndex = -1; if (feeds.length > 1) { - let p = new Prompt({ - window: browser.contentWindow, - }).setSingleChoiceItems(feeds.map(function(feed) { - return { label: feed.title || feed.href } - })).show((function(data) { - feedIndex = data.button; - if (feedIndex == -1) - return; + // JSON for Prompt + let feedResult = { + type: "Prompt:Show", + multiple: false, + selected: [], + listitems: [] + }; - this.loadFeed(feeds[feedIndex], browser); - }).bind(this)); - return; + // Build the list of feeds + for (let i = 0; i < feeds.length; i++) { + let item = { + label: feeds[i].title || feeds[i].href, + isGroup: false, + inGroup: false, + disabled: false, + id: i + }; + feedResult.listitems.push(item); + } + feedIndex = JSON.parse(sendMessageToJava(feedResult)).button; + } else { + // Only a single feed on the page + feedIndex = 0; } - this.loadFeed(feeds[0], browser); - } - }, - - loadFeed: function fh_loadFeed(aFeed, aBrowser) { - let feedURL = aFeed.href; + if (feedIndex == -1) + return; + let feedURL = feeds[feedIndex].href; // Next, we decide on which service to send the feed let handlers = this.getContentHandlers(this.TYPE_MAYBE_FEED); @@ -99,21 +107,34 @@ var FeedHandler = { return; // JSON for Prompt - let p = new Prompt({ - window: aBrowser.contentWindow - }).setSingleChoiceItems(handlers.map(function(handler) { - return { label: handler.name }; - })).show(function(data) { - if (data.button == -1) - return; + let handlerResult = { + type: "Prompt:Show", + multiple: false, + selected: [], + listitems: [] + }; - // Merge the handler URL and the feed URL - let readerURL = handlers[data.button].uri; - readerURL = readerURL.replace(/%s/gi, encodeURIComponent(feedURL)); + // Build the list of handlers + for (let i = 0; i < handlers.length; ++i) { + let item = { + label: handlers[i].name, + isGroup: false, + inGroup: false, + disabled: false, + id: i + }; + handlerResult.listitems.push(item); + } + let handlerIndex = JSON.parse(sendMessageToJava(handlerResult)).button; + if (handlerIndex == -1) + return; - // Open the resultant URL in a new tab - BrowserApp.addTab(readerURL, { parentId: BrowserApp.selectedTab.id }); - }); + // Merge the handler URL and the feed URL + let readerURL = handlers[handlerIndex].uri; + readerURL = readerURL.replace(/%s/gi, encodeURIComponent(feedURL)); + // Open the resultant URL in a new tab + BrowserApp.addTab(readerURL, { parentId: BrowserApp.selectedTab.id }); + } } }; diff --git a/mobile/android/chrome/content/InputWidgetHelper.js b/mobile/android/chrome/content/InputWidgetHelper.js index 5f140b5e09c..77f06023c45 100644 --- a/mobile/android/chrome/content/InputWidgetHelper.js +++ b/mobile/android/chrome/content/InputWidgetHelper.js @@ -23,41 +23,44 @@ var InputWidgetHelper = { show: function(aElement) { let type = aElement.getAttribute('type'); - let p = new Prompt({ - window: aElement.ownerDocument.defaultView, + let msg = { + type: "Prompt:Show", title: Strings.browser.GetStringFromName("inputWidgetHelper." + aElement.getAttribute('type')), buttons: [ Strings.browser.GetStringFromName("inputWidgetHelper.set"), Strings.browser.GetStringFromName("inputWidgetHelper.clear"), Strings.browser.GetStringFromName("inputWidgetHelper.cancel") ], - }).addDatePicker({ - value: aElement.value, - type: type, - }).show((function(data) { - let changed = false; - if (data.button == -1) { - // This type is not supported with this android version. - return; - } - if (data.button == 1) { - // The user cleared the value. - if (aElement.value != "") { - aElement.value = ""; - changed = true; - } - } else if (data.button == 0) { - // Commit the new value. - if (aElement.value != data[type]) { - aElement.value = data[type + "0"]; - changed = true; - } - } - // Else the user canceled the input. + inputs: [ + { type: type, value: aElement.value } + ] + }; + + let data = JSON.parse(sendMessageToJava(msg)); + + let changed = false; + if (data.button == -1) { + // This type is not supported with this android version. + return; + } + if (data.button == 1) { + // The user cleared the value. + if (aElement.value != "") { + aElement.value = ""; + changed = true; + } + } else if (data.button == 0) { + // Commit the new value. + if (aElement.value != data[type]) { + aElement.value = data[type]; + changed = true; + } + } + // Else the user canceled the input. + + if (changed) + this.fireOnChange(aElement); - if (changed) - this.fireOnChange(aElement); - }).bind(this)); }, _isValidInput: function(aElement) { diff --git a/mobile/android/chrome/content/browser.js b/mobile/android/chrome/content/browser.js index 55d0afdcd0c..8e3101b0e4a 100644 --- a/mobile/android/chrome/content/browser.js +++ b/mobile/android/chrome/content/browser.js @@ -249,6 +249,7 @@ var BrowserApp = { _tabs: [], _selectedTab: null, _prefObservers: [], + _promptHandlers: {}, get isTablet() { let sysInfo = Cc["@mozilla.org/system-info;1"].getService(Ci.nsIPropertyBag2); @@ -298,6 +299,7 @@ var BrowserApp = { Services.obs.addObserver(this, "FormHistory:Init", false); Services.obs.addObserver(this, "gather-telemetry", false); Services.obs.addObserver(this, "keyword-search", false); + Services.obs.addObserver(this, "Prompt:Reply", false); Services.obs.addObserver(this, "sessionstore-state-purge-complete", false); @@ -1426,6 +1428,18 @@ var BrowserApp = { browser.contentDocument.mozCancelFullScreen(); break; + case "Prompt:Reply": + { + let data = JSON.parse(aData); + let guid = data.guid; + let handler = this._promptHandlers[guid]; + if (!handler) + break; + this._promptHandlers[guid]; + handler(data); + } + break; + case "Viewport:Change": if (this.isBrowserContentDocumentDisplayed()) this.selectedTab.setViewport(JSON.parse(aData)); @@ -1490,26 +1504,35 @@ var BrowserApp = { // selecting selIndex(if fromIndex<=selIndex<=toIndex) showHistory: function(fromIndex, toIndex, selIndex) { let browser = this.selectedBrowser; + let guid = uuidgen.generateUUID().toString(); + let result = { + type: "Prompt:Show", + multiple: false, + async: true, + guid: guid, + selected: [], + listitems: [] + }; let hist = browser.sessionHistory; - let listitems = []; for (let i = toIndex; i >= fromIndex; i--) { let entry = hist.getEntryAtIndex(i, false); let item = { label: entry.title || entry.URI.spec, - selected: (i == selIndex) + isGroup: false, + inGroup: false, + disabled: false, + id: i }; - listitems.push(item); + result.listitems.push(item); + result.selected.push(i == selIndex); } - - let p = new Prompt({ - window: browser.contentWindow - }).setSingleChoiceItems(listitems).show(function(data) { + this._promptHandlers[guid] = function (data) { let selected = data.button; if (selected == -1) return; - browser.gotoIndex(toIndex-selected); - }); + }; + sendMessageToJava(result); }, }; @@ -1889,8 +1912,10 @@ var NativeWindow = { icon: item.icon, label: item.label, id: id, + isGroup: false, + inGroup: false, disabled: item.disabled, - parent: item instanceof Ci.nsIDOMHTMLMenuElement + isParent: item instanceof Ci.nsIDOMHTMLMenuElement } } }; @@ -2015,36 +2040,36 @@ var NativeWindow = { if (itemArray.length == 0) return; - let prompt = new Prompt({ - window: aTarget.ownerDocument.defaultView, - title: title - }).setSingleChoiceItems(itemArray) - .show(function(data) { - if (data.button == -1) { - // prompt was cancelled - return; - } + let msg = { + type: "Prompt:Show", + title: title, + listitems: itemArray + }; + let data = JSON.parse(sendMessageToJava(msg)); + if (data.button == -1) { + // prompt was cancelled + return; + } - let selectedId = itemArray[data.button].id; - let selectedItem = this._getMenuItemForId(selectedId); + let selectedId = itemArray[data.button].id; + let selectedItem = this._getMenuItemForId(selectedId); - this.menuitems = null; - if (selectedItem && selectedItem.callback) { - if (selectedItem.matches) { - // for menuitems added using the native UI, pass the dom element that matched that item to the callback - while (aTarget) { - if (selectedItem.matches(aTarget, aX, aY)) { - selectedItem.callback.call(selectedItem, aTarget, aX, aY); - break; - } - aTarget = aTarget.parentNode; + this.menuitems = null; + if (selectedItem && selectedItem.callback) { + if (selectedItem.matches) { + // for menuitems added using the native UI, pass the dom element that matched that item to the callback + while (aTarget) { + if (selectedItem.matches(aTarget, aX, aY)) { + selectedItem.callback.call(selectedItem, aTarget, aX, aY); + break; } - } else { - // if this was added using the html5 context menu api, just click on the context menu item - selectedItem.callback.call(selectedItem, aTarget, aX, aY); + aTarget = aTarget.parentNode; } + } else { + // if this was added using the html5 context menu api, just click on the context menu item + selectedItem.callback.call(selectedItem, aTarget, aX, aY); } - }); + } }, handleEvent: function(aEvent) { diff --git a/mobile/android/components/PaymentsUI.js b/mobile/android/components/PaymentsUI.js index 2ee2192c899..a08baf18b20 100644 --- a/mobile/android/components/PaymentsUI.js +++ b/mobile/android/components/PaymentsUI.js @@ -82,19 +82,28 @@ PaymentUI.prototype = { requestText += " (" + request.productPrice[0].amount + " " + request.productPrice[0].currency + ")"; } - listItems.push({ label: requestText }); + listItems.push({ + label: requestText, + isGroup: false, + inGroup: false, + disabled: false, + id: i + }); } - let p = new Prompt({ - window: null, + let result = this.sendMessageToJava({ + type: "Prompt:Show", title: this.bundle.GetStringFromName("payments.providerdialog.title"), - }).setSingleChoiceItems(listItems).show(function(data) { - if (data.button > -1 && aSuccessCb) { - aSuccessCb.onresult(aRequestId, aRequests[data.button].wrappedJSObject.type); - } else { - _error(aRequestId, "USER_CANCELED"); - } + multiple: false, + selected: [], + listItems: listItems, }); + + if (result.button > -1 && aSuccessCb) { + aSuccessCb.onresult(aRequestId, aRequests[result.button].wrappedJSObject.type); + } else { + _error(aRequestId, "USER_CANCELED"); + } }, _error: function(aCallback) { diff --git a/mobile/android/modules/Prompt.jsm b/mobile/android/modules/Prompt.jsm index d28337432ec..1e9acb4b858 100644 --- a/mobile/android/modules/Prompt.jsm +++ b/mobile/android/modules/Prompt.jsm @@ -48,8 +48,6 @@ Prompt.prototype = { obj.id = aOptions.id || (aOptions.type + this[aOptions.type + "_count"]); this[aOptions.type + "_count"]++; - if (!this.msg.inputs) - this.msg.inputs = []; this.msg.inputs.push(obj); return this; }, @@ -83,13 +81,6 @@ Prompt.prototype = { }); }, - addDatePicker: function(aOptions) { - return this._addInput({ - type: aOptions.type || "date", - value: aOptions.value, - }); - }, - addMenulist: function(aOptions) { return this._addInput({ type: "menulist", @@ -121,13 +112,17 @@ Prompt.prototype = { this.callback(data); }, - _setListItems: function(aItems) { + _setListItems: function(aItems, aInGroup) { let hasSelected = false; - this.msg.listitems = []; + if (!aInGroup) + this.msg.listitems = []; aItems.forEach(function(item) { let obj = { id: item.id }; + if (aInGroup !== undefined) + obj.inGroup = aInGroup; + obj.label = item.label; if (item.disabled) @@ -141,17 +136,19 @@ Prompt.prototype = { this.msg.selected[this.msg.listitems.length] = item.selected; } - if (item.header) + if (item.children) { obj.isGroup = true; - - if (item.menu) + } else if (item.submenu) { obj.isParent = true; + } - if (item.child) - obj.inGroup = true; - + // Order matters in the java message, so make sure we add the obj + // to the list before we add its children this.msg.listitems.push(obj); + if (item.children) + this._setListItems(item.children, true); + }, this); return this; },