Commit graph

2864 commits

Author SHA1 Message Date
Michael James Gratton
772b874def Clean up JavaScriptCore VAPI, client and engine code.
* bindings/vapi/javascriptcore-4.0.vapi: Make JS objects match their JSC
  definitions: move JSValueFoo methods to JS.Value, etc. Update call
  sites.

* src/client/util/util-webkit.vala: Move WebKit-specific common methods
  from ClientWebView here. Update call sites.

* src/engine/util/util-js.vala: Move JSC-specific common methods from
  ClientWebView and ComposerPageStateTest here. Update call sites.

* src/client/web-process/web-process-extension.vala: Check for and handle
  exceptions when calling JS code.

* src/CMakeLists.txt: Add new source files, make WebKit VAPI generation
  and engine compilation depend on JSC.
2017-02-01 00:41:43 +11:00
Michael James Gratton
22de6b122e Fix JS error getting F=F text from ComposerWebView. Add JS unit tests.
* ui/composer-web-view.js (ComposerPageState::resolveNesting): Apply JS
  RegExp globally, to match default GLib RegEx behaviour.

* test/js/composer-page-state-test.vala: New tests covering generation of
  HTML and F=F text from JS ComposerPageState object.

* test/CMakeLists.txt: Add the new test.

* test/main.vala (main): Add a test suite for JS tests, add the new test
  to it.

* src/client/components/client-web-view.vala (ClientWebView): Add a
  reason to the JSError domain for when a JS exception is thrown.

* bindings/vapi/javascriptcore-4.0.vapi (JS::Context): Add JS.Type and
  some additional methods needed for the unit tests. Move most
  GlobalContext methods to Context so we can pass the lowest common
  demominator around.
2017-02-01 00:41:43 +11:00
Michael James Gratton
5dc20f4273 Make GTK & async unit tests work by running them in a GTK+ main loop.
Include GResources in the build so they can be loaded.

Bug 776421.

* test/main.vala (main): Init GTK, start a main loop and run the tests in
  that.

* test/CMakeLists.txt: Include GResources in unit test binary so they can
  be loaded by tests, and since we can't compile them into the client
  static lib.
2017-02-01 00:41:43 +11:00
Michael James Gratton
61c8e5a105 Remove global GearyApplication instance from ClientWebView.
This is also needed to make the class and its subclasses unit testable.

* src/client/components/client-web-view.vala
  (ClientWebView::ClientWebView): Replace use of
  GearyApplication.instance.config with a constructor parameter. Update
  all subclassess and call sites to ensure the parameter is passed in.
2017-02-01 00:41:43 +11:00
Michael James Gratton
a2d6381b8c Make ClientWebView and derived classes unit-testable.
* src/client/components/client-web-view.vala (ClientWebView): Don't
  require an instance of GearyApplication to be passed in to resource
  loading, use new GioUtil methods to load the resources instead. Update
  subclasses and call sites. Add a static init method for initialising
  the WebKit.WebContext move code from GearyController here.

* src/client/application/geary-application.vala (GearyApplication):
  Reimplement ::create_builder and ::read_resource using new GioUtil,
  deprecate them. Merge ::load_ui_resource_for_manager into
  ::load_ui_resource since that's its only use, deprecate it.

* src/client/util/util-gio.vala: New util methods for loading GResources,
  independent of the app.

* src/CMakeLists.txt: Add new util source.

UNit tetsing
2017-02-01 00:41:43 +11:00
Michael James Gratton
ef48c5daec Move WebKit2GTK target version to root cmake file for consistency. 2017-02-01 00:41:43 +11:00
Michael James Gratton
12834b11b5 Remove some more now-unsed DOM code. 2017-02-01 00:41:43 +11:00
Michael James Gratton
d4a4c5b45f Initial pass at implementing Format=Flowed formatting in JS for WK2.
May not actually be working, needs testing, may eat your replies, etc.
2017-02-01 00:41:43 +11:00
Michael James Gratton
6edc097e50 Ensure basic rich text editing controls work under WK2. 2017-02-01 00:41:43 +11:00
Michael James Gratton
a023b8aa6b Re-implement select-link-on-click for WK2. 2017-02-01 00:41:43 +11:00
Michael James Gratton
6933f3b6f2 Re-enable rich/plain text editing toggke for WK2. 2017-02-01 00:41:43 +11:00
Michael James Gratton
7063907688 Fix links not being opened when link target is a new window.
* src/client/components/client-web-view.vala
  (ClientWebView::on_decide_policy): Handle new window policy as well as
  nav actions.
2017-02-01 00:41:43 +11:00
Michael James Gratton
a72d845b35 Fix some dumb bugs in ConversationPageState::getSelectionForQuoting().
* ui/conversation-web-view.js: Fix prviously brace-less if block
  indentation, minor cleanup.
2017-02-01 00:41:43 +11:00
Michael James Gratton
b1027fcbbf Implement getting HTML and plain text from ComposerWebView in WK2.
* src/client/composer/composer-web-view.vala (ComposerWebView): Implement
  both ::get_html and ::get_text as async JS calls, make the methods
  async and update cal sites to handle that.

* src/client/composer/composer-widget.vala: Make saving deafts and
  sending message async, to handle editor returning message body text
  async. Remove uneeded ::get_html and ::get_text functions, update call
  sites to call same directly on the on editor instead.

* src/client/web-process/util-composer.vala: Remove obsolete ::get_html
  and ::get_text functions.

* ui/composer-web-view.js (ComposerPageState): Initial implementation of
  getHtml and getText methods.
2017-02-01 00:41:43 +11:00
Michael James Gratton
9e5e90ceb8 Mark ClientWebView::get_string_result and call sites as nullable. 2017-02-01 00:41:43 +11:00
Michael James Gratton
a77a19c101 Remove some reduncant method calls and related code. 2017-02-01 00:41:43 +11:00
Michael James Gratton
9ae52342f5 Add some WebView and WebProcess debugging. 2017-02-01 00:41:43 +11:00
Michael James Gratton
5b8c68f5fa Implement getting message selection for quoting and selection in WK2.
* src/client/conversation-viewer/conversation-web-view.vala
  (ConversationWebView): Remove has_selection method since we are
  using the signal to specify if a selection was found or not. Update
  call sites to use that.
  (ConversationWebView::get_selection_for_find,
  ConversationWebView::get_selection_for_quoting): Implement using calls
  to web process JS methods.

* src/client/application/geary-controller.vala
  (GearyController::create_reply_forward_widget): If we have a possible
  message view to quote from, handle constructing the compser widget
  asynchronously, when we know if we have a quote or not.

* src/client/conversation-viewer/conversation-viewer.vala:
  (ConversationViewer::on_find_mode_changed): Handle getting text
  selection for finds asynchonously.

* src/client/components/client-web-view.vala
  (ClientWebView::get_string_result): New helper for getting string
  values from JS calls.

* src/client/conversation-viewer/conversation-email.vala
  (ConversationEmail::get_selection_for_quoting,
  ConversationEmail::get_selection_for_find): Handxle errors when
  obtaining selections from a message view.

* src/client/conversation-viewer/conversation-message.vala: Remove
  methods that were simply passed through to the web view anyway. Update
  call sies.

* src/client/web-process/util-conversation.vala: Port all remaining
  functions to JS, remove.

* bindings/vapi/javascriptcore-4.0.vapi: Add methods needed to get
  strings out of WebKit.JavascriptResult instances.

* ui/conversation-web-view.js: Implement selection functions in JS, minor
  cleanup.
2017-02-01 00:41:43 +11:00
Michael James Gratton
3f90f7785a Reimplement loading and cleaning message into WK2 composer web view.
* src/client/application/geary-controller.vala (GearyController::open_async):
  Load ComposerWebView resources.

* src/client/composer/composer-web-view.vala (ComposerWebView): Move
  HTML/CSS template here from ComposerWidget. Load composer-web-view.js
  on app init and add it to the web view's user content manager.
  (ComposerWebView::load_html): Overridden to require HTML body and
  signature, assemble complete HTML as appropriate before chaining up to
  the default impl.
  (ComposerWebView::load_finished_and_realised): Remove redundant method.

* src/client/composer/composer-widget.vala (ComposerWidget):
  Remove 'message' prop since it is unused and onerous. Cache current
  account's signature as a field so it can be passed through to the
  editor as needed. Port on_link_clicked to composer-web-view.js.

* src/client/web-process/util-composer.vala: Remove function ported to JS
  in composer-web-view.js

* ui/CMakeLists.txt: Include new ComposerWebView JS resource.

* ui/composer-web-view.js: Port composer HTML sanitisation methods to JS,
  add to a custom subclass of PageState. Instantiate it and hook it up to
  onload.
2017-02-01 00:41:43 +11:00
Michael James Gratton
b02059795f Remove some obsolete CSS from conversation-web-view.css. 2017-02-01 00:41:43 +11:00
Michael James Gratton
431ebcb35f Re-implement message HTML cleaning in JS in the web extension for WK2.
* ui/conversation-web-view.js: New script, port old HTML cleaning code in
  vala to Javascript as new subclass of PageState. Instantiate that on
  page load.

* src/client/conversation-viewer/conversation-web-view.vala
  (ConversationWebView): Load and add new JS script for conversations.

* src/client/web-process/util-conversation.vala (Util.Conversation):
  Remove migrated and obsolete code.

* ui/client-web-view.js (PageState): Allow on-load behaviour to be
  overridden in subclasses.

* ui/CMakeLists.txt: Include new JS script.

* ui/conversation-web-view.css: Chase CSS class name changes.
2017-02-01 00:41:43 +11:00
Michael James Gratton
7c5e5ae2cd Remove ConversationWebView ::is_height_valid property.
WK2 seems to be reporting valid hight values now, so we don't need this
any more. With an additional small tweak, this also fixes auto-marking
messages as read under WK2.

* src/client/conversation-viewer/conversation-web-view.vala
  (ConversationWebView): Remove ::is_height_valid property. Update call
  sites to use ClientWebView::is_loaded instead.

* src/client/conversation-viewer/conversation-list-box.vala
  (ConversationListBox::check_mark_read): Also check that the web view
  has been allocated a positive size before auto-marking as read.
2017-02-01 00:41:43 +11:00
Michael James Gratton
766d55e75d Reimplement selection_changed signal for WK2.
Add a "has_selection" param to avoid a second round-trip to the web
process to determine that.

* src/client/components/client-web-view.vala (ClientWebView): Add a
  selection_changed signal, register a JS message handler for the JS
  equivalent hook up firing the signal.

* src/client/web-process/web-process-extension.vala (GearyWebExtension):
  Send a JS selectionChanged message when the page's selection changes.

* src/client/composer/composer-widget.vala,
  src/client/conversation-viewer/conversation-email.vala,
  src/client/conversation-viewer/conversation-message.vala: Uncomment
  code that relied on the WK1 selection_changed signal, use signal param
  rather than DOM calls.

* ui/client-web-view.js: Implement sending the selectionChanged message.
2017-02-01 00:41:43 +11:00
Michael James Gratton
3068d1b0e5 Integrate preferred height JS code into PageState, tidy it up a bit.
* ui/client-web-view.js: Move emitPreferredHeightChanged() into PageState
  as ::preferredHeightChanged(). Add a explicit constructor, move
  instance properties into that. Add an interval timer to periodically
  update the preferred height until loaded.
2017-02-01 00:41:43 +11:00
Michael James Gratton
d002722a19 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.
2017-02-01 00:41:43 +11:00
Michael James Gratton
8d13bf1922 Enable accessing javascriptcore objects from web extensions.
* src/CMakeLists.txt: Also generate a custom Also generate a custom
  webkit2gtk-web-extension-4.0 VAPI that re-includes javascriptcore
  objects, so they can be access from the web extension.

* bindings/metadata/WebKit2WebExtension-4.0-custom.vala,
  bindings/metadata/WebKit2WebExtension-4.0.metadata: Include in-tree
  metadata for web extension VAPI, update to all access to JS obejcts.

* bindings/vapi/javascriptcore-4.0.vapi: Add a bunch of useful additional
  objects and method.
2017-02-01 00:41:43 +11:00
Michael James Gratton
3a3b5d0bff Rename some JS methods to be more vala-esque. 2017-02-01 00:41:43 +11:00
Michael James Gratton
56651ed8c4 Inject ClientWebView script at document start.
* src/client/components/client-web-view.vala
  (ClientWebView::load_app_script): Set script injection time to the
  start of the document load.

* ui/client-web-view.js: Set an onload handler to report back the
  preferred height.
2017-02-01 00:41:43 +11:00
Michael James Gratton
26fe139e97 Initial pass at getting the HTML document's height from the web process.
* bindings/vapi/javascriptcore-4.0.vapi: Add some methods to
  GlobalContext for accessing JSValues as ints.

* src/client/components/client-web-view.vala
  (ClientWebView): Hook up UserContentManager script messages handler and
  handler implementation for "preferredHeightChanged", update the new
  preferred_height prop on the class, and queue a resize. Hook those
  values up to the GTK allocation machinery.
  (ClientWebView::get_int_result): Convenience method for getting an int
  from a JavascriptResult.
  (ClientWebView::get_preferred_height): Report back values as reported
  by messages from the script handler.
  (ClientWebView::register_message_handler): Convenience method for
  registering script messages handlers.

* src/client/conversation-viewer/conversation-web-view.vala
  (ConversationWebView): Remove now-redundant GTK allocation machinery.

* ui/client-web-view.js: Post a message to preferredHeightChanged when
  the page is sorta-kinda loaded.
2017-02-01 00:41:43 +11:00
Michael James Gratton
09c9a398f7 Load a default app script into ClientWebViews at construction time.
* src/client/application/geary-controller.vala
  (GearyController::open_async): Load the app script for ClientWebView at
  startup.

* src/client/components/client-web-view.vala
  (ClientWebView::ClientWebView): Ensure we actually have a
  UserContentManager instance to work with, add the app script to the
  manager for the instance.
  (ClientWebView::load_scripts): Actually load client-web-view.js.
  (ClientWebView::load_user_stylesheet): Helper method for this class and
  subsclasses for doing the actual script load from the app.

* ui/client-web-view.js: Add boilerplaye for new file.

* ui/CMakeLists.txt: Include client-web-view.js.
2017-02-01 00:41:43 +11:00
Michael James Gratton
adf912faae Explicitly set a bunch of good-to-know default WebSettings values. 2017-02-01 00:41:43 +11:00
Michael James Gratton
f51f55cd78 Depend on javascriptcore, generate webkit2 VAPI that uses it.
This gives us a means of using JS objects returned by UserContentManager
script messages directly from Vala.

* bindings/metadata/WebKit2-4.0.metadata: Tweak standard webkit2 VAPI to
  re-include methods that return javascriptcore objects.

* bindings/vapi/javascriptcore-4.0.vapi: Copy generated VAPI file into
  the tree, customise it so that it actually works.

* src/CMakeLists.txt: Generate the custom webkit2 VAPI, depend on
  javascriptcore and include in-tree javascriptcore VAPI in the client
  build.

* bindings/metadata/JSCore-3.0.metadata: Remove obsolete file.
2017-02-01 00:41:43 +11:00
Michael James Gratton
330dc10f71 Impromptu minor cell renderer cleanup (long story). 2017-02-01 00:41:43 +11:00
Michael James Gratton
8a0aad1a2b Disable WebKit2 accelerated compositing. 2017-02-01 00:41:43 +11:00
Michael James Gratton
45a050271e Bump minimum WebKitGTK+ version to 2.10.
We already need to 2.10 for the EditorState::typing-attributes property,
and we're probably going to want 2.8 anyway for
WebKit.UserContentManager::register_script_message_handler.

This means geary 0.12 won't compile under Debian stable unless backports
(bpo) are enabled, but that is how most users will get it 0.12
anyway. Further, the fact that stable is still shipping WK 2.6 is pretty
heinous from a security POV.

* src/CMakeLists.txt: Yoiks and away.
2017-02-01 00:41:43 +11:00
Michael James Gratton
b8bd5095a4 Remove workaround for WK1 Settings zoom-level being floats, not doubles. 2017-02-01 00:41:43 +11:00
Michael James Gratton
b45152facd Set desktop font pref sizes on ClientWebView as pixels, per WK2's expectation. 2017-02-01 00:41:43 +11:00
Michael James Gratton
392c517f3c Load ConversationWebView HTML CSS using a WK2 UserContentManager.
* src/client/application/geary-controller.vala (GearyController): Load
  the ConversationWebView's stylesheets at startup.

* src/client/components/client-web-view.vala (ClientWebView): Add
  ::load_app_stylesheet and ::load_user_stylesheet static methods for use
  by derived classes.

* src/client/conversation-viewer/conversation-web-view.vala
  (ConversationWebView): Add static ::load_stylehseets method to load app
  and user CSS. Remove old WK1 user style loading code.

* src/client/web-process/util-conversation.vala (Util.Conversation):
  Remove old WK1 app style loading code.
2017-02-01 00:41:43 +11:00
Michael James Gratton
2b7ffd8a98 Minor code cleanup. 2017-02-01 00:41:43 +11:00
Michael James Gratton
d9cca42169 Update how inline email attachments are loaded for viewing.
* src/client/components/client-web-view.vala
  (ClientWebView::add_inline_resource): Renamed fro add_cid_resource, to
  make it more obvious what it is useful for and updated call sites.
  (ClientWebView::add_inline_resources): New method for adding a complete
  set of inline resources.

* src/client/conversation-viewer/conversation-email.vala
  (ConversationEmail::ConversationEmail): Construct a map of inline
  resources, add them to both the primary and attached messages.
  (ConversationEmail::start_loading): Only load attachments once all web
  views have been loaded, so any inline parts that were not displayed
  inline can be displayed as attachments.
2017-02-01 00:41:43 +11:00
Michael James Gratton
10ab9c6115 Reenable notifiying of inline parts being loaded by the web view.
* src/client/components/client-web-view.vala
  (ClientWebView::inline_resource_loaded): New signal to notify of when
  an inline part has been loaded by the web view.
  (ClientWebView::handle_cid_request): Fire new signal when a part is
  loaded.

* src/client/conversation-viewer/conversation-email.vala
  (ConversationEmail::connect_message_view_signals): Hook up new signal.

* src/client/conversation-viewer/conversation-message.vala
  (ConversationMessage): Remove now-unesed attachment_displayed_inline signal.
2017-02-01 00:41:43 +11:00
Michael James Gratton
1d1229b623 Use CID resources to display images for multipart/mixed messages.
* src/client/conversation-viewer/conversation-message.vala
  (ConversationMessage): Remove ReplacedImage and related code.
  (ConversationMessage::inline_image_replacer): Don't bother loading,
  scaling, rotating and serialising the images, just add them as CID
  resources.

* src/client/components/client-web-view.vala (ClientWebView): Modify the
  cid_resources map contain memory buffers, not files, and update call
  sites.
2017-02-01 00:41:43 +11:00
Michael James Gratton
6515db2a18 Reimplement saving inline images using WebResources.
* src/client/conversation-viewer/conversation-message.vala
  (ConversationMessage): Add a map to keep track of loaded resources,
  update it using the WebView.resource-load-started signal, clear it
  when the widget is destroyed.
  (ConversationMessage::on_context_menu): Use the hit test to get the
  image's URI, update the menu's action using that.
  (ConversationMessage::on_save_image): Implement getting and saving
  image data from the web resource object.
2017-02-01 00:41:43 +11:00
Michael James Gratton
0dbf925a86 Implement loading cid: scheme resources in ClientWebView.
* src/client/application/geary-controller.vala
  (GearyController::open_async): Register a handler for the 'cid' scheme.

* src/client/components/client-web-view.vala
  (ClientWebView::handle_cid_request): Hook up requests for cid URIs
  using attachment files.
2017-02-01 00:41:43 +11:00
Michael James Gratton
d2fac49e18 Remove now-empty util-random.vala file. 2017-02-01 00:41:43 +11:00
Michael James Gratton
2117c23734 Implement web view resource loading policy for CID, data, & remote URLs.
* src/client/web-process/web-process-extension.vala
  (GearyWebExtension::GearyWebExtension): Set the allow_prefix here,
  since this is where we need to make the decision. Hook up to the
  page-created and subsequently the send-request signals.
  (GearyWebExtension::on_send_request): Always allow data and cid
  requests through, only allow remote requests through if they have the
  allow prefix.
  (random_string): Moved here from util-random so we can call it.

* src/client/components/client-web-view.vala
  (ClientWebView::allow_prefix): Keep this here for now, but its value
  still needs to be fetched from the extension.
  (ClientWebView::on_resource_load_started): Removed, the policy needs to
  be set in the extension to actually work.
2017-02-01 00:41:43 +11:00
Michael James Gratton
6d18b247c0 Properly build and load the web extension for ClientWebView.
* src/CMakeLists.txt: Pass the build dir through to the application so it
  can work out where to find the extension when running from the source
  tree. Build geary-static as reloacatable so we can link it with the
  extension. Actually link geary-static into the extension and install it.

* src/client/application/geary-application.vala
  (GearyApplication::get_web_extensions_dir): New method that determines
  where the web extension lib is to be found.

* src/client/application/geary-controller.vala
  (GearyController::open_async): Set the extension dir on the WebContext,
  and pass through logging config to the extension.

* src/client/web-process/web-process-extension.vala: Add a
  GearyWebExtension extension object, create it on init and init logging.
2017-02-01 00:41:43 +11:00
Michael James Gratton
1eb56bb34e Allow HTML string page loads to occur, so email bodies actually show up.
* src/client/components/client-web-view.vala
  (ClientWebView::on_decide_policy): HTML string page loads are treaded
  as other navigation policy decisions, so allow them rather than
  ignoring them.
2017-02-01 00:41:43 +11:00
Michael James Gratton
b183f9d91c Fix massive graphics corruptiom when WebViews are displayed.
* src/client/application/geary-controller.vala
  (GearyController::open_async): Initialise WebKit default context here,
  rather than in GearyApplication::startup so it happens after GTK+ has
  been initialised.
2017-02-01 00:41:43 +11:00
Michael James Gratton
d542dda48e Begin the WebKit2 port in earnest.
Replace StylishWebView with ClientWebView, to act as a common base class
for the composer, conversation and other uses of web views.

Introduce a ComposerWebView that replaces WebviewEditFixer and extends
ClientWebView, and adds (dummy for now) methods for ComposerWidget to
call. Simiarly, make ConversationWebView extend ClientWebView, add dummy
calls to support the conversation viewer classes. Move common code from
both into ClientWebView.

Add a web-process library, unused other than for compile-time checking,
and move all client functions and methods involving DOM objects into util
classes there.

Bug 728002
2017-02-01 00:41:43 +11:00