Components.WebView: Convert to using messages for JS → client comms
This commit is contained in:
parent
89453931bf
commit
fb96676fbd
2 changed files with 53 additions and 51 deletions
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2016 Michael Gratton <mike@vee.net>
|
||||
* Copyright © 2016-2020 Michael Gratton <mike@vee.net>
|
||||
*
|
||||
* This software is licensed under the GNU Lesser General Public License
|
||||
* (version 2.1 or later). See the COPYING file in this distribution.
|
||||
|
|
@ -20,6 +20,13 @@ PageState.prototype = {
|
|||
this.hasSelection = false;
|
||||
this.lastPreferredHeight = 0;
|
||||
|
||||
this._selectionChanged = MessageSender("selection_changed");
|
||||
this._contentLoaded = MessageSender("content_loaded");
|
||||
this._remoteImageLoadBlocked = MessageSender("remote_image_load_blocked");
|
||||
this._preferredHeightChanged = MessageSender("preferred_height_changed");
|
||||
this._commandStackChanged = MessageSender("command_stack_changed");
|
||||
this._documentModified = MessageSender("document_modified");
|
||||
|
||||
let state = this;
|
||||
|
||||
// Set up an observer to keep track of modifications made to
|
||||
|
|
@ -106,7 +113,7 @@ PageState.prototype = {
|
|||
// be vaguegly correct when notifying of the HTML load
|
||||
// completing.
|
||||
this.updatePreferredHeight();
|
||||
window.webkit.messageHandlers.contentLoaded.postMessage(null);
|
||||
this._contentLoaded();
|
||||
},
|
||||
loadRemoteImages: function() {
|
||||
window._gearyAllowRemoteResourceLoads = true;
|
||||
|
|
@ -142,7 +149,7 @@ PageState.prototype = {
|
|||
this.bodyObserver.disconnect();
|
||||
},
|
||||
remoteImageLoadBlocked: function() {
|
||||
window.webkit.messageHandlers.remoteImageLoadBlocked.postMessage(null);
|
||||
this._remoteImageLoadBlocked();
|
||||
},
|
||||
/**
|
||||
* Sends "preferredHeightChanged" message if it has changed.
|
||||
|
|
@ -160,9 +167,7 @@ PageState.prototype = {
|
|||
// shrink again, leading to visual flicker.
|
||||
if (this.isLoaded && height > 0 && height != this.lastPreferredHeight) {
|
||||
this.lastPreferredHeight = height;
|
||||
window.webkit.messageHandlers.preferredHeightChanged.postMessage(
|
||||
height
|
||||
);
|
||||
this._preferredHeightChanged(height);
|
||||
}
|
||||
},
|
||||
checkCommandStack: function() {
|
||||
|
|
@ -172,19 +177,17 @@ PageState.prototype = {
|
|||
if (canUndo != this.undoEnabled || canRedo != this.redoEnabled) {
|
||||
this.undoEnabled = canUndo;
|
||||
this.redoEnabled = canRedo;
|
||||
window.webkit.messageHandlers.commandStackChanged.postMessage(
|
||||
this.undoEnabled + "," + this.redoEnabled
|
||||
);
|
||||
this._commandStackChanged(this.undoEnabled, this.redoEnabled);
|
||||
}
|
||||
},
|
||||
documentModified: function(element) {
|
||||
window.webkit.messageHandlers.documentModified.postMessage(null);
|
||||
this._documentModified();
|
||||
},
|
||||
selectionChanged: function() {
|
||||
let hasSelection = !window.getSelection().isCollapsed;
|
||||
if (this.hasSelection != hasSelection) {
|
||||
this.hasSelection = hasSelection;
|
||||
window.webkit.messageHandlers.selectionChanged.postMessage(hasSelection);
|
||||
this._selectionChanged(hasSelection);
|
||||
}
|
||||
},
|
||||
// Methods below are for unit tests.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue