geary/ui/client-web-view.js

59 lines
1.7 KiB
JavaScript
Raw Normal View History

/*
* Copyright 2016 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.
*/
/**
* Application logic for ClientWebView and subclasses.
*/
var PageState = function() {
this.init.apply(this, arguments);
};
Re-implement remote image loading management for WebKit2. * src/client/components/client-web-view.vala (ClientWebView): Register for new remoteImageLoadBlocked message from JS. Add new ::remote_image_load_blocked signal to notify when a remote image load was blocked. Add ::allow_remote_image_loading and ::load_remote_images methods to allow th app to manage image loading state. * src/client/conversation-viewer/conversation-email.vala (ConversationEmail): Determine up front whether the message view should load remote images and flag that, rather than passing through the email flag and the contact store. * src/client/conversation-viewer/conversation-message.vala (ConversationMessage): Rmeove contact_store and always_load_remote_images properties and related code, just let the parent email view advise whether remote images should be initially loaded and act accordingly. Look up to ClientWebView signal and methods to handle manual remote image loading management by the user. Remove some obsolete code. * src/client/web-process/web-process-extension.vala (GearyWebExtension): Replace allow_prefix implementation for remote image management with explicit signalling to/from the application via JavaScript. * ui/client-web-view.js: Add a new PageState object, add props and method to implement remote image loading management. * ui/client-web-view-allow-remote-images.js: Monkeypatch to be used when remote images should be loaded by default. * ui/CMakeLists.txt: Include new JS file. * src/client/conversation-viewer/conversation-web-view.vala, src/client/web-process/util-conversation.vala, src/client/web-process/util-webkit.vala: Remove obsolete code.
2016-11-25 16:30:50 +11:00
PageState.prototype = {
init: function() {
this.allowRemoteImages = false;
this.loaded = false;
var state = this;
var timeoutId = window.setInterval(function() {
state.preferredHeightChanged();
if (state.loaded) {
window.clearTimeout(timeoutId);
}
}, 50);
},
Re-implement remote image loading management for WebKit2. * src/client/components/client-web-view.vala (ClientWebView): Register for new remoteImageLoadBlocked message from JS. Add new ::remote_image_load_blocked signal to notify when a remote image load was blocked. Add ::allow_remote_image_loading and ::load_remote_images methods to allow th app to manage image loading state. * src/client/conversation-viewer/conversation-email.vala (ConversationEmail): Determine up front whether the message view should load remote images and flag that, rather than passing through the email flag and the contact store. * src/client/conversation-viewer/conversation-message.vala (ConversationMessage): Rmeove contact_store and always_load_remote_images properties and related code, just let the parent email view advise whether remote images should be initially loaded and act accordingly. Look up to ClientWebView signal and methods to handle manual remote image loading management by the user. Remove some obsolete code. * src/client/web-process/web-process-extension.vala (GearyWebExtension): Replace allow_prefix implementation for remote image management with explicit signalling to/from the application via JavaScript. * ui/client-web-view.js: Add a new PageState object, add props and method to implement remote image loading management. * ui/client-web-view-allow-remote-images.js: Monkeypatch to be used when remote images should be loaded by default. * ui/CMakeLists.txt: Include new JS file. * src/client/conversation-viewer/conversation-web-view.vala, src/client/web-process/util-conversation.vala, src/client/web-process/util-webkit.vala: Remove obsolete code.
2016-11-25 16:30:50 +11:00
loadRemoteImages: function() {
this.allowRemoteImages = true;
var images = document.getElementsByTagName("IMG");
for (var i = 0; i < images.length; i++) {
var img = images.item(i);
var src = img.src;
img.src = "";
img.src = src;
}
},
remoteImageLoadBlocked: function() {
window.webkit.messageHandlers.remoteImageLoadBlocked.postMessage(null);
},
preferredHeightChanged: function() {
var height = window.document.documentElement.offsetHeight;
if (height > 0) {
window.webkit.messageHandlers.preferredHeightChanged.postMessage(
height
);
}
},
selectionChanged: function() {
var has_selection = !window.getSelection().isCollapsed;
window.webkit.messageHandlers.selectionChanged.postMessage(has_selection);
Re-implement remote image loading management for WebKit2. * src/client/components/client-web-view.vala (ClientWebView): Register for new remoteImageLoadBlocked message from JS. Add new ::remote_image_load_blocked signal to notify when a remote image load was blocked. Add ::allow_remote_image_loading and ::load_remote_images methods to allow th app to manage image loading state. * src/client/conversation-viewer/conversation-email.vala (ConversationEmail): Determine up front whether the message view should load remote images and flag that, rather than passing through the email flag and the contact store. * src/client/conversation-viewer/conversation-message.vala (ConversationMessage): Rmeove contact_store and always_load_remote_images properties and related code, just let the parent email view advise whether remote images should be initially loaded and act accordingly. Look up to ClientWebView signal and methods to handle manual remote image loading management by the user. Remove some obsolete code. * src/client/web-process/web-process-extension.vala (GearyWebExtension): Replace allow_prefix implementation for remote image management with explicit signalling to/from the application via JavaScript. * ui/client-web-view.js: Add a new PageState object, add props and method to implement remote image loading management. * ui/client-web-view-allow-remote-images.js: Monkeypatch to be used when remote images should be loaded by default. * ui/CMakeLists.txt: Include new JS file. * src/client/conversation-viewer/conversation-web-view.vala, src/client/web-process/util-conversation.vala, src/client/web-process/util-webkit.vala: Remove obsolete code.
2016-11-25 16:30:50 +11:00
}
};
var geary = new PageState();
window.onload = function() {
geary.loaded = true;
};