зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1078353 - handleReaderListStatusRequest should use JS-Java callbacks. r=margaret
This commit is contained in:
Родитель
48bb703940
Коммит
6281949c07
|
@ -70,7 +70,7 @@ public final class ReadingListHelper implements GeckoEventListener, NativeEventL
|
|||
}
|
||||
|
||||
case "Reader:ListStatusRequest": {
|
||||
handleReadingListStatusRequest(message.getString("url"));
|
||||
handleReadingListStatusRequest(callback, message.getString("url"));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -155,7 +155,7 @@ public final class ReadingListHelper implements GeckoEventListener, NativeEventL
|
|||
* Gecko (ReaderMode) requests the page ReadingList status, to display
|
||||
* the proper ReaderMode banner icon (readinglist-add / readinglist-remove).
|
||||
*/
|
||||
private void handleReadingListStatusRequest(final String url) {
|
||||
private void handleReadingListStatusRequest(final EventCallback callback, final String url) {
|
||||
ThreadUtils.postToBackgroundThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
|
@ -168,11 +168,10 @@ public final class ReadingListHelper implements GeckoEventListener, NativeEventL
|
|||
json.put("inReadingList", inReadingList);
|
||||
} catch (JSONException e) {
|
||||
Log.e(LOGTAG, "JSON error - failed to return inReadingList status", e);
|
||||
return;
|
||||
}
|
||||
|
||||
GeckoAppShell.sendEventToGecko(
|
||||
GeckoEvent.createBroadcastEvent("Reader:ListStatusReturn", json.toString()));
|
||||
// Return the json object to fulfill the promise.
|
||||
callback.sendSuccess(json.toString());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
|
@ -35,7 +35,6 @@ let AboutReader = function(doc, win) {
|
|||
Services.obs.addObserver(this, "Reader:FaviconReturn", false);
|
||||
Services.obs.addObserver(this, "Reader:Added", false);
|
||||
Services.obs.addObserver(this, "Reader:Removed", false);
|
||||
Services.obs.addObserver(this, "Reader:ListStatusReturn", false);
|
||||
Services.obs.addObserver(this, "Gesture:DoubleTap", false);
|
||||
|
||||
this._article = null;
|
||||
|
@ -205,23 +204,6 @@ AboutReader.prototype = {
|
|||
break;
|
||||
}
|
||||
|
||||
case "Reader:ListStatusReturn": {
|
||||
let args = JSON.parse(aData);
|
||||
if (args.url == this._article.url) {
|
||||
if (this._isReadingListItem != args.inReadingList) {
|
||||
let isInitialStateChange = (this._isReadingListItem == -1);
|
||||
this._isReadingListItem = args.inReadingList;
|
||||
this._updateToggleButton();
|
||||
|
||||
// Display the toolbar when all its initial component states are known
|
||||
if (isInitialStateChange) {
|
||||
this._setToolbarVisibility(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case "Gesture:DoubleTap": {
|
||||
let args = JSON.parse(aData);
|
||||
let scrollBy;
|
||||
|
@ -275,7 +257,6 @@ AboutReader.prototype = {
|
|||
case "unload":
|
||||
Services.obs.removeObserver(this, "Reader:Added");
|
||||
Services.obs.removeObserver(this, "Reader:Removed");
|
||||
Services.obs.removeObserver(this, "Reader:ListStatusReturn");
|
||||
Services.obs.removeObserver(this, "Gesture:DoubleTap");
|
||||
break;
|
||||
}
|
||||
|
@ -303,9 +284,23 @@ AboutReader.prototype = {
|
|||
},
|
||||
|
||||
_requestReadingListStatus: function Reader_requestReadingListStatus() {
|
||||
Messaging.sendRequest({
|
||||
Messaging.sendRequestForResult({
|
||||
type: "Reader:ListStatusRequest",
|
||||
url: this._article.url
|
||||
}).then((data) => {
|
||||
let args = JSON.parse(data);
|
||||
if (args.url == this._article.url) {
|
||||
if (this._isReadingListItem != args.inReadingList) {
|
||||
let isInitialStateChange = (this._isReadingListItem == -1);
|
||||
this._isReadingListItem = args.inReadingList;
|
||||
this._updateToggleButton();
|
||||
|
||||
// Display the toolbar when all its initial component states are known
|
||||
if (isInitialStateChange) {
|
||||
this._setToolbarVisibility(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче