diff options
author | Philip Chimento <philip@endlessm.com> | 2015-05-18 17:37:45 -0700 |
---|---|---|
committer | Philip Chimento <philip@endlessm.com> | 2015-05-21 13:22:21 -0700 |
commit | e2729f045a9459c9a320c617ac6e599814744e56 (patch) | |
tree | 1da582aae21c2dea1896ab26f8e7102e795c450b /test/smoke-tests | |
parent | 6ff70f1a9ae70e3481411d27de7594477fa4d0d2 (diff) |
Implement web actions in WebHelper2
This allows communicating with the host program through URIs of the
form webhelper://action?param=value¶m2=value2. Actions can be
defined on the WebHelper object and given a callback in Javascript.
Unfortunately we have to use a private C library to register the URI
scheme, because of https://bugs.webkit.org/show_bug.cgi?id=116672
[endlessm/eos-sdk#291]
Diffstat (limited to 'test/smoke-tests')
-rw-r--r-- | test/smoke-tests/webhelper/webview2.js | 47 |
1 files changed, 46 insertions, 1 deletions
diff --git a/test/smoke-tests/webhelper/webview2.js b/test/smoke-tests/webhelper/webview2.js index 604819c..ec029c9 100644 --- a/test/smoke-tests/webhelper/webview2.js +++ b/test/smoke-tests/webhelper/webview2.js @@ -2,6 +2,7 @@ const Endless = imports.gi.Endless; const Gettext = imports.gettext; +const Gtk = imports.gi.Gtk; const Lang = imports.lang; const WebHelper2 = imports.webhelper2; const WebKit2 = imports.gi.WebKit2; @@ -26,6 +27,17 @@ body { \ <body> \ <h1>First page</h1> \ \ +<p><a href="webhelper://moveToPage?name=page2">Move to page 2</a></p> \ +\ +<p><a \ +href="webhelper://showMessageFromParameter?msg=This%20is%20a%20message%20from%20the%20URL%20parameter">Show \ +message from parameter in this URL</a></p> \ +\ +<form action="webhelper://showMessageFromParameter"> \ +<input name="msg" value="I am in a form!"/> \ +<input type="submit" value="Show message using a form"/> \ +</form> \ +\ <p><a href="http://wikipedia.org">Regular link to a Web site</a></p> \ \ <p>This is text that will be italicized: <span name="translatable">Hello, \ @@ -50,6 +62,10 @@ const TestApplication = new Lang.Class({ this.parent(); this._webhelper.set_gettext((s) => s.italics()); + this._webhelper.define_web_actions({ + moveToPage: this.moveToPage.bind(this), + showMessageFromParameter: this.showMessageFromParameter.bind(this), + }); this._webview = new WebKit2.WebView(); this._webview.connect('load-changed', (webview, event) => { @@ -58,7 +74,14 @@ const TestApplication = new Lang.Class({ this._webhelper.translate_html_finish(res); }); }); - this._webview.load_html(TEST_HTML, 'file://'); + this._webview.load_html(TEST_HTML, null); + + this._page2 = new Gtk.Grid(); + let back_button = new Gtk.Button({ label: 'Go back to page 1' }); + back_button.connect('clicked', () => { + this._pm.visible_child_name = 'page1'; + }); + this._page2.add(back_button); this._window = new Endless.Window({ application: this, @@ -66,7 +89,10 @@ const TestApplication = new Lang.Class({ }); this._pm = this._window.page_manager; + this._pm.set_transition_type(Gtk.StackTransitionType.CROSSFADE); this._pm.add(this._webview, { name: 'page1' }); + this._pm.add(this._page2, { name: 'page2' }); + this._pm.visible_child_name = 'page1'; this._window.show_all(); }, @@ -75,6 +101,25 @@ const TestApplication = new Lang.Class({ this.parent(connection, object_path); this._webhelper.unregister(); }, + + // WEB ACTIONS + + // dict['name'] is the name of the page to move to + moveToPage: function (dict) { + this._pm.visible_child_name = dict['name']; + }, + + // dict['msg'] is the message to display + showMessageFromParameter: function (dict) { + let dialog = new Gtk.MessageDialog({ + buttons: Gtk.ButtonsType.CLOSE, + message_type: Gtk.MessageType.INFO, + text: dict['msg'], + transient_for: this._window, + }); + dialog.run(); + dialog.destroy(); + }, }); let app = new TestApplication({ |