From: Alan Knowles Date: Wed, 18 Mar 2015 12:16:53 +0000 (+0800) Subject: sync X-Git-Url: http://git.roojs.org/?p=app.Builder.js;a=commitdiff_plain;h=fc21b7d6e10764915823d17fdefb96a8b1c398ca;hp=081d803c5c10bb7945064239f96cdad1826a690b sync --- diff --git a/src/Application.vala b/src/Application.vala index d8a520ac2..854f50971 100644 --- a/src/Application.vala +++ b/src/Application.vala @@ -68,9 +68,7 @@ configDirectory(); this.settings = AppSettings.factory(); - - this.initResources(true); - + } @@ -103,71 +101,11 @@ return dirname; } - - public void initResources(bool force = false) - { - // files to fetch from resources. - string[] res = { - "bootstrap.builder.html", - "roo.builder.html", - "roo.builder.js", - "Gir.overides", - "RooUsage.txt", - "GtkUsage.txt" - }; - for (var i = 0; i < res.length; i++ ) { - this.fetchResource(res[i], force); - } - - this.fetchResourceFrom ( - "http://git.roojs.org/?p=roojs1;a=blob_plain;f=docs/json/roodata.json", - "roodata.json", - force - ); - - - } - public void fetchResource(string res, bool force) { - if (!force && FileUtils.test(configDirectory() + "/resources/" + res, FileTest.EXISTS)) { - return; - } - this.fetchResourceFrom( - "http://git.roojs.org/?p=app.Builder.js;a=blob_plain;f=resources/" + res, - res, - force - ); - - - } - - public void fetchResourceFrom(string src, string res, bool force) { - if (!force && FileUtils.test(configDirectory() + "/resources/" + res, FileTest.EXISTS)) { - return; - } - // fetch... - print("downloading %s \nto : %s\n", src,res); - var session = new Soup.Session (); - session.user_agent = "App Builder "; - var message = new Soup.Message ("GET", - src - ); - - // send the HTTP request and wait for response - session.send_message (message); - - // output the XML result to stdout - FileUtils.set_contents( - configDirectory() + "/resources/" + res, - (string) message.response_body.data - ); - - - } - + } - \ No newline at end of file + diff --git a/src/Palete/Javascript.vala b/src/Palete/Javascript.vala index dd3ea6ea5..13fe8f912 100644 --- a/src/Palete/Javascript.vala +++ b/src/Palete/Javascript.vala @@ -3,6 +3,12 @@ namespace Palete { + public errordomain JavascriptError { + MISSING_METHOD, + MISSING_FILE + + } + Javascript instance = null; public class Javascript { @@ -16,7 +22,7 @@ namespace Palete { { var c = new JSCore.Class (class_definition); var o = new JSCore.Object (ctx, c, null); - exception = null; + exception = null; return o; } static const JSCore.StaticFunction[] class_functions = { @@ -103,10 +109,73 @@ namespace Palete { } + /** + * extension API concept.. + * javascript file.. loaded into jscore, + * then a method is called, with a string argument (json encoded) + * + */ + public void executeFile(string fname, string call_method, string js_data) + { + string file_data; + if (!FileUtils.test (fname, FileTest.EXISTS)) { + throw new JavascriptError.MISSING_FILE("Plugin: file not found %s", fname); + } + FileUtils.get_contents(fname, out file_data); + + var jfile_data = new JSCore.String.with_utf8_c_string(file_data); + var jmethod = new JSCore.String.with_utf8_c_string(call_method); + var json_args = new JSCore.String.with_utf8_c_string(js_data); + + JSCore.Value exa; + JSCore.Value exb; + unowned JSCore.Value exc; + JSCore.Value exd; + + var goc = new JSCore.Class( class_definition ); + var ctx = new JSCore.GlobalContext(goc); + var othis = ctx.get_global_object(); + + var eval = ctx.evaluate_script ( + jfile_data, + othis, + null, + 0, + out exa + ); + + + if (!othis.has_property(ctx,jmethod)) { + throw new JavascriptError.MISSING_METHOD ("Plugin: missing method %s", call_method); + return; + } + + var val = othis.get_property (ctx, jmethod, out exb); + + if (!val.is_object(ctx)) { + throw new JavascriptError.MISSING_METHOD ("Plugin: not a property not found %s", call_method); + } + var oval = val.to_object(ctx, out exc); + + if (!oval.is_function(ctx)) { + throw new JavascriptError.MISSING_METHOD ("Plugin: not a method %s", call_method); + } + + // this will never work, as we can not create arrays of Values - due to no + // free function being available.. + //var args = new JSCore.Value[1] ; + //args[0] = new JSCore.Value.string(ctx,json_args) ; + + unowned JSCore.Value res = oval.call_as_function(ctx, othis, null, out exd); - } + + } + + + } + diff --git a/src/Resources.vala b/src/Resources.vala index 36458adaa..03907113a 100644 --- a/src/Resources.vala +++ b/src/Resources.vala @@ -20,9 +20,9 @@ public class Resources : Object public signal void updateProgress(uint cur_pos); static Resources singleton_val; - static Resources singleton() + public static Resources singleton() { - if (singleton_val != null) { + if (singleton_val == null) { singleton_val = new Resources(); } return singleton_val; diff --git a/src/vapi/javascriptcore.vapi b/src/vapi/javascriptcore.vapi index aacca04d2..3cfb399ed 100644 --- a/src/vapi/javascriptcore.vapi +++ b/src/vapi/javascriptcore.vapi @@ -278,6 +278,7 @@ namespace JSCore { [Compact] /* FIXME: free_function causes a warning */ [CCode (cname = "void", free_function = "(void)0")] + [CCode (cname = "JSValueRef", free_function = "")] public class Value { [CCode (cname = "JSValueMakeUndefined")] public Value.undefined (Context ctx); @@ -338,19 +339,21 @@ namespace JSCore { public JSCore.String to_string_copy (Context ctx, Value *exception); [CCode (cname = "JSValueToObject", instance_pos=1.1)] - public Object to_object (Context ctx, Value *exception); + public Object to_object (Context ctx, out Value *exception); [CCode (cname = "JSValueProtect", instance_pos=1.1)] public void protect (Context ctx); [CCode (cname = "JSValueUnprotect", instance_pos=1.1)] public void unprotect (Context ctx); + + } [Compact] /* FIXME: causes a warning */ - [CCode (cname = "void", free_function = "")] + [CCode (cname = "JSObjectRef", free_function = "")] public class Object: JSCore.Value { [CCode (cname = "JSObjectMake")] public Object (Context ctx, Class js_class, void *data); @@ -430,11 +433,12 @@ namespace JSCore { public bool is_function (Context ctx); [CCode (cname = "JSObjectCallAsFunction", instance_pos=1.1)] - public unowned JSCore.Value call_as_function (Context ctx, - JSCore.Object? this_object, - [CCode (array_length_pos=2.9, array_length_type="size_t")] - JSCore.Value[]? arguments, - out JSCore.Value exception); + public unowned JSCore.Value call_as_function (Context ctx, + JSCore.Object thisObject, + [CCode (array_length_pos=2.9, array_length_type="size_t")] + JSCore.Value[] arguments, + out JSCore.Value exception); + [CCode (cname = "JSObjectIsConstructor", instance_pos=1.1)] public bool is_constructor (Context ctx); diff --git a/src/vapi/webkit2gtk-4.0.vapi b/src/vapi/webkit2gtk-4.0.vapi index e4e8d796e..f9e76a348 100644 --- a/src/vapi/webkit2gtk-4.0.vapi +++ b/src/vapi/webkit2gtk-4.0.vapi @@ -41,6 +41,18 @@ namespace WebKit { public unowned string get_title (); public unowned string get_uri (); } + [CCode (cheader_filename = "webkit2/webkit2.h", type_id = "webkit_color_chooser_request_get_type ()")] + public class ColorChooserRequest : GLib.Object { + [CCode (has_construct_function = false)] + protected ColorChooserRequest (); + public void cancel (); + public void finish (); + public Gdk.Rectangle get_element_rectangle (); + public Gdk.RGBA get_rgba (); + public void set_rgba (Gdk.RGBA rgba); + public Gdk.RGBA rgba { get; set construct; } + public signal void finished (); + } [CCode (cheader_filename = "webkit2/webkit2.h", type_id = "webkit_context_menu_get_type ()")] public class ContextMenu : GLib.Object { [CCode (has_construct_function = false)] @@ -50,12 +62,14 @@ namespace WebKit { public unowned WebKit.ContextMenuItem get_item_at_position (uint position); public unowned GLib.List get_items (); public uint get_n_items (); + public unowned GLib.Variant get_user_data (); public void insert (WebKit.ContextMenuItem item, int position); public unowned WebKit.ContextMenuItem last (); public void move_item (WebKit.ContextMenuItem item, int position); public void prepend (WebKit.ContextMenuItem item); public void remove (WebKit.ContextMenuItem item); public void remove_all (); + public void set_user_data (GLib.Variant user_data); [CCode (has_construct_function = false)] public ContextMenu.with_items (GLib.List items); } @@ -107,6 +121,7 @@ namespace WebKit { [CCode (has_construct_function = false)] protected Download (); public void cancel (); + public bool get_allow_overwrite (); public unowned string get_destination (); public double get_elapsed_time (); public double get_estimated_progress (); @@ -114,7 +129,9 @@ namespace WebKit { public unowned WebKit.URIRequest get_request (); public unowned WebKit.URIResponse get_response (); public unowned WebKit.WebView get_web_view (); + public void set_allow_overwrite (bool allowed); public void set_destination (string uri); + public bool allow_overwrite { get; set; } public string destination { get; } public double estimated_progress { get; } public WebKit.URIResponse response { get; } @@ -196,6 +213,7 @@ namespace WebKit { public bool context_is_link (); public bool context_is_media (); public bool context_is_scrollbar (); + public bool context_is_selection (); public uint get_context (); public unowned string get_image_uri (); public unowned string get_link_label (); @@ -261,6 +279,24 @@ namespace WebKit { [Deprecated (since = "2.6")] public WebKit.URIRequest request { get; } } + [CCode (cheader_filename = "webkit2/webkit2.h", type_id = "webkit_notification_get_type ()")] + public class Notification : GLib.Object { + [CCode (has_construct_function = false)] + protected Notification (); + public void close (); + public unowned string get_body (); + public uint64 get_id (); + public unowned string get_title (); + public string body { get; } + public uint64 id { get; } + public string title { get; } + public signal void closed (); + } + [CCode (cheader_filename = "webkit2/webkit2.h", type_id = "webkit_notification_permission_request_get_type ()")] + public class NotificationPermissionRequest : GLib.Object, WebKit.PermissionRequest { + [CCode (has_construct_function = false)] + protected NotificationPermissionRequest (); + } [CCode (cheader_filename = "webkit2/webkit2.h", type_id = "webkit_plugin_get_type ()")] public class Plugin : GLib.Object { [CCode (has_construct_function = false)] @@ -495,11 +531,13 @@ namespace WebKit { [CCode (has_construct_function = false)] protected URIResponse (); public uint64 get_content_length (); + public unowned Soup.MessageHeaders get_http_headers (); public unowned string get_mime_type (); public uint get_status_code (); public unowned string get_suggested_filename (); public unowned string get_uri (); public uint64 content_length { get; } + public Soup.MessageHeaders http_headers { get; } public string mime_type { get; } public uint status_code { get; } public string suggested_filename { get; } @@ -522,8 +560,20 @@ namespace WebKit { public UserContentManager (); public void add_script (WebKit.UserScript script); public void add_style_sheet (WebKit.UserStyleSheet stylesheet); + public bool register_script_message_handler (string name); public void remove_all_scripts (); public void remove_all_style_sheets (); + public void unregister_script_message_handler (string name); + public signal void script_message_received (WebKit.JavascriptResult js_result); + } + [CCode (cheader_filename = "webkit2/webkit2.h", type_id = "webkit_user_media_permission_request_get_type ()")] + public class UserMediaPermissionRequest : GLib.Object, WebKit.PermissionRequest { + [CCode (has_construct_function = false)] + protected UserMediaPermissionRequest (); + [NoAccessorMethod] + public bool is_for_audio_device { get; } + [NoAccessorMethod] + public bool is_for_video_device { get; } } [CCode (cheader_filename = "webkit2/webkit2.h", ref_function = "webkit_user_script_ref", type_id = "webkit_user_script_get_type ()", unref_function = "webkit_user_script_unref")] [Compact] @@ -544,7 +594,7 @@ namespace WebKit { [CCode (cheader_filename = "webkit2/webkit2.h", type_id = "webkit_web_context_get_type ()")] public class WebContext : GLib.Object { [CCode (has_construct_function = false)] - protected WebContext (); + public WebContext (); public void allow_tls_certificate_for_host (GLib.TlsCertificate certificate, string host); public void clear_cache (); public WebKit.Download download_uri (string uri); @@ -573,8 +623,10 @@ namespace WebKit { public void set_tls_errors_policy (WebKit.TLSErrorsPolicy policy); public void set_web_extensions_directory (string directory); public void set_web_extensions_initialization_user_data (GLib.Variant user_data); - public signal void download_started (WebKit.Download download); - public signal void initialize_web_extensions (); + [NoAccessorMethod] + public string local_storage_directory { owned get; construct; } + public virtual signal void download_started (WebKit.Download download); + public virtual signal void initialize_web_extensions (); } [CCode (cheader_filename = "webkit2/webkit2.h", type_id = "webkit_web_inspector_get_type ()")] public class WebInspector : GLib.Object { @@ -582,11 +634,13 @@ namespace WebKit { protected WebInspector (); public void close (); public uint get_attached_height (); + public bool get_can_attach (); public unowned string get_inspected_uri (); public unowned WebKit.WebViewBase get_web_view (); public bool is_attached (); public void show (); public uint attached_height { get; } + public bool can_attach { get; } public string inspected_uri { get; } [HasEmitter] public signal bool attach (); @@ -606,6 +660,7 @@ namespace WebKit { public WebKit.URIResponse response { get; } public string uri { get; } public signal void failed (void* error); + public signal void failed_with_tls_errors (GLib.TlsCertificate certificate, GLib.TlsCertificateFlags errors); public signal void finished (); public signal void received_data (uint64 data_length); public signal void sent_request (WebKit.URIRequest request, WebKit.URIResponse redirected_response); @@ -621,6 +676,7 @@ namespace WebKit { public WebKit.Download download_uri (string uri); public void execute_editing_command (string command); public unowned WebKit.BackForwardList get_back_forward_list (); + public Gdk.RGBA get_background_color (); public unowned WebKit.WebContext get_context (); public unowned string get_custom_charset (); public double get_estimated_load_progress (); @@ -640,6 +696,7 @@ namespace WebKit { public void go_back (); public void go_forward (); public void go_to_back_forward_list_item (WebKit.BackForwardListItem list_item); + public bool is_editable (); public void load_alternate_html (string content, string content_uri, string? base_uri); public void load_bytes (GLib.Bytes bytes, string? mime_type, string? encoding, string? base_uri); public void load_html (string content, string? base_uri); @@ -653,7 +710,9 @@ namespace WebKit { public async WebKit.JavascriptResult run_javascript_from_gresource (string resource, GLib.Cancellable? cancellable) throws GLib.Error; public async GLib.InputStream save (WebKit.SaveMode save_mode, GLib.Cancellable? cancellable) throws GLib.Error; public async bool save_to_file (GLib.File file, WebKit.SaveMode save_mode, GLib.Cancellable? cancellable) throws GLib.Error; + public void set_background_color (Gdk.RGBA rgba); public void set_custom_charset (string? charset); + public void set_editable (bool editable); public void set_settings (WebKit.Settings settings); public void set_zoom_level (double zoom_level); public void stop_loading (); @@ -663,10 +722,14 @@ namespace WebKit { public WebView.with_settings (WebKit.Settings settings); [CCode (has_construct_function = false, type = "GtkWidget*")] public WebView.with_user_content_manager (WebKit.UserContentManager user_content_manager); + [NoAccessorMethod] + public bool editable { get; set; } public double estimated_load_progress { get; } public void* favicon { get; } [NoAccessorMethod] public bool is_loading { get; } + [NoAccessorMethod] + public bool is_playing_audio { get; } public WebKit.WebView related_view { construct; } public WebKit.Settings settings { set construct; } public string title { get; } @@ -686,15 +749,17 @@ namespace WebKit { public virtual signal bool leave_fullscreen (); public virtual signal void load_changed (WebKit.LoadEvent load_event); public virtual signal bool load_failed (WebKit.LoadEvent load_event, string failing_uri, void* error); - public virtual signal bool load_failed_with_tls_errors (GLib.TlsCertificate certificate, GLib.TlsCertificateFlags errors, string host); + public virtual signal bool load_failed_with_tls_errors (string failing_uri, GLib.TlsCertificate certificate, GLib.TlsCertificateFlags errors); public virtual signal void mouse_target_changed (WebKit.HitTestResult hit_test_result, uint modifiers); public virtual signal bool permission_request (WebKit.PermissionRequest permission_request); public virtual signal bool print (WebKit.PrintOperation print_operation); public virtual signal void ready_to_show (); public virtual signal void resource_load_started (WebKit.WebResource resource, WebKit.URIRequest request); public virtual signal void run_as_modal (); + public virtual signal bool run_color_chooser (WebKit.ColorChooserRequest request); public virtual signal bool run_file_chooser (WebKit.FileChooserRequest request); public virtual signal bool script_dialog (WebKit.ScriptDialog dialog); + public virtual signal bool show_notification (WebKit.Notification notification); public virtual signal void submit_form (WebKit.FormSubmissionRequest request); public virtual signal bool web_process_crashed (); } @@ -830,7 +895,8 @@ namespace WebKit { IMAGE, MEDIA, EDITABLE, - SCROLLBAR + SCROLLBAR, + SELECTION } [CCode (cheader_filename = "webkit2/webkit2.h", cprefix = "WEBKIT_INSECURE_CONTENT_", type_id = "webkit_insecure_content_event_get_type ()")] public enum InsecureContentEvent { @@ -883,7 +949,8 @@ namespace WebKit { [Flags] public enum SnapshotOptions { NONE, - INCLUDE_SELECTION_HIGHLIGHTING + INCLUDE_SELECTION_HIGHLIGHTING, + TRANSPARENT_BACKGROUND } [CCode (cheader_filename = "webkit2/webkit2.h", cprefix = "WEBKIT_SNAPSHOT_REGION_", type_id = "webkit_snapshot_region_get_type ()")] public enum SnapshotRegion { @@ -995,4 +1062,8 @@ namespace WebKit { public static uint get_micro_version (); [CCode (cheader_filename = "webkit2/webkit2.h")] public static uint get_minor_version (); + [CCode (cheader_filename = "webkit2/webkit2.h")] + public static bool user_media_permission_is_for_audio_device (WebKit.UserMediaPermissionRequest request); + [CCode (cheader_filename = "webkit2/webkit2.h")] + public static bool user_media_permission_is_for_video_device (WebKit.UserMediaPermissionRequest request); } diff --git a/tests/JsCoreExecTest.vala b/tests/JsCoreExecTest.vala new file mode 100644 index 000000000..a1fe6b0bb --- /dev/null +++ b/tests/JsCoreExecTest.vala @@ -0,0 +1,13 @@ + +// valac --vapidir ../src/vapi JsCoreExecTest.vala ../src/Palete/Javascript.vala --pkg javascriptcore -o /tmp/jstest + + +int main (string[] args) { + var js = Palete.Javascript.singleton(); + js.executeFile("/home/alan/gitlive/app.Builder.js/tests/hello.js", + "hello", "{}"); + + + return 0; +} + diff --git a/tests/hello.js b/tests/hello.js new file mode 100644 index 000000000..41ba3c5b9 --- /dev/null +++ b/tests/hello.js @@ -0,0 +1,5 @@ + +function hello(w) { + return w+'xx'; + +}