2 "build_module" : "webkitpdf",
6 "Gtk.WindowType type" : "Gtk.WindowType.TOPLEVEL",
12 "\tthis.el.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC);",
17 "id" : "scrolled_window",
20 "# bool print_started" : false,
22 "# string cookie_file" : "",
28 "\t\tthis.load_try = 0;",
34 "\t\t this.el.load_changed.connect( (ev ) => {",
35 " \t\tif (ev != WebKit.LoadEvent.FINISHED) {",
36 "\t\t \t\treturn;\t ",
44 "\t\t\tthis.el.resource_load_started.connect( (resource, request) => {",
45 "\t\t\t//\tprint(\"Adding referrer header %s\\n\" , request.get_uri());",
47 "\t\t\t\tif (request.get_http_headers() != null) {",
48 "\t \t\t\t\trequest.get_http_headers().remove(\"Referer\");\t\t",
49 "\t \t\t\t\trequest.get_http_headers().append(\"Referer\", request.get_uri());",
52 " var settings = this.el.get_settings();",
53 "\t\t\tsettings.set_user_agent( \"Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.84 Safari/537.36\" );",
54 "\t\t\tsettings.hardware_acceleration_policy = WebKit.HardwareAccelerationPolicy.NEVER;",
55 "\t\t\tsettings.enable_accelerated_2d_canvas = false;",
56 "\t\t\tif (webkitpdf.opt_disable_javascript) { ",
57 "\t \t\t\tsettings.enable_javascript = false;",
60 "\t\t\tWebKit.WebContext.get_default().set_tls_errors_policy(\tWebKit.TLSErrorsPolicy.IGNORE );",
64 " // this.el.resource_request_starting.connect( (p0, webres, netreq ) => {",
65 " // print(\"resource req. started %s\\n\", netreq.uri);",
69 " this.el.load_finished.connect( ( ) => {",
74 " WebKit.get_default_session().request_started.connect((message, socket) => {",
75 " \t Soup.URI uri = message.get_uri();",
77 "\t\t\t\tvar host = uri.get_host ();",
78 "\t\t\t\tif (host.contains(\"google-analytics\") || host.contains(\"googlesyndication\") || host.contains(\"facebook\") ) {",
79 "\t\t\t\t\tprint(\"DISCONNECTING: %s\\n\", host);",
80 "\t\t\t\t\tsocket.disconnect();",
84 "\t\t\t\tprint(\"Adding header: %s\\n\", uri.to_string(false));",
85 "\t\t\t\tmessage.request_headers.remove(\"Referer\");\t\t\t\t",
86 "\t\t\t\tmessage.request_headers.append(\"Referer\", \"http://\"+host+\"/\");",
90 " var sess = WebKit.get_default_session();",
91 "\t\t\tsess.user_agent= \"Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.84 Safari/537.36\";",
92 "\t\t\tsess.ssl_strict = false;",
94 " var settings = this.el.get_settings();",
96 "\t\t\tsettings.enable_webgl = false;",
97 "\t\t\tsettings.enable_plugins = false;",
98 "\t\t\tsettings.enable_java_applet = false;",
99 "\t\t\tif (webkitpdf.opt_disable_javascript) { ",
100 "\t \t\t\tsettings.enable_scripts = false;",
104 "\t\t\tthis.el.console_message.connect((msg, line, sid) => {",
105 "\t\t\t\tprint(\"CONSOLE: %s:%d %s\\n\", sid, line, msg);",
106 "\t\t\t\treturn false;",
108 "\t\t\tthis.el.create_web_view.connect((frame) => {",
109 "\t\t\t\tprint(\"WEBFRAME:%s\\n\", frame.uri);",
110 " \t\t\t\treturn new WebKit.WebView();",
115 "\t \tthis.cookie_file = \"\";",
116 "\t\tif (webkitpdf.opt_cookies != null) {",
117 "\t\t\tprint(\"setting cookie %s\\n\",webkitpdf.opt_cookies);",
119 "\t\t\tvar uri = GLib.Uri.parse (webkitpdf.opt_url, GLib.UriFlags.NONE);",
121 "\t\t\tstring[] cookies = webkitpdf.opt_cookies.split (\"=\", 2);",
123 "\t\t\tif(cookies.length > 1 ) {",
126 "\t\t\t\tvar context = WebKit.WebContext.get_default();\t ",
127 "\t\t\t\tvar cookie_manager = context.get_cookie_manager();",
128 "\t\t\t\tcookie_manager.set_accept_policy(WebKit.CookieAcceptPolicy.NEVER);",
129 "\t\t\t\tstring scheme = uri.get_scheme ();",
132 "\t\t\t\t FileIOStream iostream;\t\t ",
133 "\t\t\t\t File file = File.new_tmp (\"cookie-XXXXXX.txt\", out iostream);",
134 "\t\t\t\t this.cookie_file = file.get_path (); ",
135 "\t\t\t\t print(\"cookie tmp file name: %s\\n\", file.get_path ());",
137 "\t\t\t\t OutputStream ostream = iostream.output_stream;",
138 "\t\t\t\t DataOutputStream dostream = new DataOutputStream (ostream);\t\t\t\t\t ",
139 "\t\t\t\t dostream.put_string (\"%s\\tTRUE\\t/\\t%s\\t2147483647\\t%s\\t%s\".printf(uri.get_host(),scheme == \"http\" ? \"FALSE\" : \"TRUE\",cookies[0],cookies[1]));\t\t ",
140 "\t\t\t\t cookie_manager.set_persistent_storage(file.get_path(), WebKit.CookiePersistentStorage.TEXT);\t\t ",
141 "\t\t\t\t} catch (Error e) {",
142 "\t\t\t\t stdout.printf (\"Error: %s\\n\", e.message);",
145 "\t\t\t\tvar cookie_jar = new Soup.CookieJar();\t\t",
146 "\t\t\t\tvar cookie = new Soup.Cookie (cookies[0], cookies[1], uri.get_host(), \"/\", -1);",
147 "\t\t\t\tif(uri.get_scheme() ==\"https\") {",
148 "\t\t\t\t cookie.set_secure(true); ",
150 "\t\t\t\tcookie_jar.set_accept_policy(Soup.CookieJarAcceptPolicy.NEVER);\t\t\t\t ",
151 "\t\t\t\tcookie_jar.add_cookie(cookie);\t\t\t ",
152 "\t\t\t\tWebKit.get_default_session().add_feature(cookie_jar);",
154 "\t\t\t\t\t \t\t\t \t\t\t ",
163 "| bool printpdf" : [
168 "\t\tvar list = Gtk.PaperSize.get_paper_sizes(false);",
169 "\t var psetup = new Gtk.PageSetup();",
170 "\t for(var i = 0; i < list.length(); i++ ) {",
171 "\t var entry = list.nth_data(i).copy();",
172 "\t if (entry.get_name() == \"iso_a2\") {",
173 "\t psetup.set_paper_size(entry);",
180 "\t\tvar pe = new WebKit.PrintOperation(this.el);",
181 "\t\tpe.set_page_setup(psetup);",
182 "\t\tpe.finished.connect( () => {",
183 "\t\t\tprint(\"print completed\\n\");",
184 " this.delete_cookiefile(); ",
185 "\t\t\t Gtk.main_quit();",
189 "\t\tvar ps = new Gtk.PrintSettings();",
190 "\t ps.set_printer(\"Print to File\");",
191 "\t ps.set(\"output-file-format\", \"pdf\");",
192 "\t ps.set(\"output-uri\", \"file://\" + webkitpdf.opt_target_pdf);",
195 "\t\tpe.set_print_settings(ps);",
202 "\t\tvar pe = new Gtk.PrintOperation();",
203 "\t\tpe.export_filename = webkitpdf.opt_target_pdf;",
204 "\t\tprint(\"got callback for print\\n\");",
206 "\t\t/*pe.failed.connect(() => {",
207 "\t\t\tprint(\"print failed\\n\");",
208 "\t\t\t Gtk.main_quit();",
212 "\t\t pe.done.connect(() => {",
213 "\t\t\tprint(\"print completed\\n\");",
214 " this.delete_cookiefile(); ",
215 "\t\t\t Gtk.main_quit();",
219 "\t\t//pe.run_dialog(_this.el);",
225 "\t pe.set_default_page_setup(psetup);",
226 "\t print(\"Calling Print?\\n\");",
227 "\t //pe.run_dialog(_this.el);",
234 "\t\t this.el.get_main_frame().print_full(pe,Gtk.PrintOperationAction.EXPORT);",
235 "\t } catch (Error e) {",
236 "\t\t\t// print failed...",
245 "| void delete_cookiefile" : [
247 " \tif(this.cookie_file.length < 1 ){",
250 " print(\"deleting tmp file %s\\n\",this.cookie_file);",
251 " File file = File.new_for_path (this.cookie_file);",
253 " if (file.query_exists () == true) {",
254 " file.delete ();\t ",
256 " } catch (Error e) {",
257 " stdout.printf (\"Error: %s\\n\", e.message);",
265 " print(\"load_finsihed\\n\");",
267 " if (this.print_started) {",
268 " print(\"load_finsihed - already printing..%d %s\\n\", this.load_try, this.el.uri);",
277 " this.print_started = true; // flag to stop double call.",
280 "\t// inject any javascript if needed..",
281 "\tif (webkitpdf.opt_inject_js != null) {",
283 "\t\tprint(\"injecting javascript files \\n\");",
284 "\t\tforeach(var inject_js in webkitpdf.opt_inject_js) {",
285 "\t\tprint(\"inject? %s\\n\", inject_js);",
288 "\t\t\t\tFileUtils.get_contents( inject_js, out str);",
289 "\t\t\t} catch(FileError e) {",
290 "\t\t\t\tprint(\"Failed to inject %s\\n\", inject_js);",
294 "\t\t\tGLib.MainLoop mainloop = new GLib.MainLoop();",
295 "\t\t\tthis.el.run_javascript.begin(str, null, (obj,res) => {",
296 "\t\t\t\tmainloop.quit();",
298 "\t\t\tmainloop.run();",
301 "\t\t\tthis.el.execute_script(str);",
306 "\tprint(\"calling print in %d seconds\\n\", (int)webkitpdf.opt_delay);",
307 "\tif (webkitpdf.opt_target_pdf != null) {",
308 "\t\tGLib.Timeout.add_seconds(webkitpdf.opt_delay, () => { ",
309 "\t\t\tprint(\"delay done URL: %s\\n\", this.el.uri);",
312 "\t\t\tthis.printpdf();",
313 "\t\t\t return false;",
314 "\t\t}, GLib.Priority.DEFAULT);",
320 "\tGLib.Timeout.add_seconds(webkitpdf.opt_delay, () => { ",
321 "\t\t\tprint(\"delay done URL: %s\\n\", this.el.uri);",
322 "\t\t\tthis.printpng();\t",
323 "\t\t\treturn false;",
324 "\t\t}, GLib.Priority.DEFAULT);",
328 " GLib.Timeout.add_seconds(webkitpdf.opt_delay, () => { ",
331 "\t\t// ----------------- JPEG ",
332 "\t\t// resize the window...",
333 "\t\t// window.document.documentElement.scrollHeight",
334 "\t\tvar scroll_height = (int) _this.view.el.get_dom_document().document_element.scroll_height;",
335 "\t\tprint(\"Scroll height %d\\n\", scroll_height);",
336 "\t\tif (scroll_height> 1024 || webkitpdf.opt_width > 0 || webkitpdf.opt_height > 0 ) {",
337 "\t\t\tvar w = webkitpdf.opt_width > 0 ? webkitpdf.opt_width : 1200;",
338 "\t\t\tvar h = int.min(scroll_height, 6000);",
339 "\t\t\t_this.scrolled_window.el.set_size_request( w, h); ",
340 "\t\t\t_this.el.resize (w+50, h+50);",
341 "\t\t\tprint(\"Resize to %d, %d\\n\", w,h);",
342 "\t\t GLib.Timeout.add_seconds(webkitpdf.opt_delay > 0 ? webkitpdf.opt_delay : 1 , () => { ",
343 "\t\t\t\tthis.printpng();",
344 "\t\t\t\treturn false;",
345 "\t\t\t }, GLib.Priority.DEFAULT);",
346 " \t\t return false;",
348 "\t\tthis.printpng();\t\t",
350 "\t }, GLib.Priority.DEFAULT);",
358 "| void printpng" : [
360 " //var filename = \"/tmp/test.pdf\";",
361 " //print(\"load_changed %d ?= %d\\n\", le, LoadEvent.FINISHED);",
363 " //if (le != LoadEvent.FINISHED) {",
367 "// what size is the documet.",
369 " print(\"making screenshot\\n\");",
371 "GLib.MainLoop mainloop = new GLib.MainLoop();",
372 " _this.view.el.get_snapshot.begin(WebKit.SnapshotRegion.FULL_DOCUMENT, WebKit.SnapshotOptions.NONE, null, (obj, res) => {",
373 " \t\t var sf = _this.view.el.get_snapshot.end(res);",
374 " \t\t sf.write_to_png(webkitpdf.opt_target_png);",
375 " \tprint(\"Saved to %s\\n\", webkitpdf.opt_target_png);",
376 " \t\t mainloop.quit();",
383 " // fix vapi - get_snapshot add '?' to all null.",
384 " var pixmap = _this.view.el.get_snapshot( null );",
390 " // add out to gdkpixmap.get_size",
391 "\tpixmap.get_size( out w , out h);",
392 "\tvar pixbuf = Gdk.pixbuf_get_from_drawable(null, pixmap, null , 0, 0, 0, 0, w, h);",
393 "\tprint(\"pixbuf size: %d x %d\\n \", w,h);",
397 " pixbuf.save(webkitpdf.opt_target_png, \"png\");",
398 " print(\"Saved to %s\\n\", webkitpdf.opt_target_png);",
399 " //view.get_snapshot.begin(WebKit.SnapshotRegion.FULL_DOCUMENT, WebKit.SnapshotOptions.NONE, null, (obj, res) => {",
400 " // var sf = view.get_snapshot.end(res);",
402 " // sf.write_to_png(Browser.opt_target_png);",
405 " this.delete_cookiefile(); ",
418 "xtype" : "ScrolledWindow"
430 "\tprint(\"resizing window\\n\");",
431 "\tvar w = webkitpdf.opt_width > 0 ? webkitpdf.opt_width : 1200;",
432 "\tvar h = webkitpdf.opt_height > 0 ? webkitpdf.opt_height : 500;",
435 "\tthis.el.resize(w,h);",
437 "\t// we have to do silly stuff with blogspot!!?!?",
438 "\tvar blog = webkitpdf.opt_url;",
441 " /* Do not redirect if the domain is .com already */",
442 " if (/\\.blogspot\\.com/.match(blog)) {",
443 "\t\tvar r = new Regex (\"\\\\.blogspot\\\\..*?/\");",
444 "\t\tblog = r.replace(blog, blog.length, 0, \".blogspot.com/ncr/\");",
447 "\tprint(\"loading url %s\\n\",blog);\t",
448 "\tthis.view.el.load_uri(blog);",
450 "\t// if we have not finished in 25 seconds",
451 "\t// call printit...",
452 "\tvar cd = webkitpdf.opt_delay > 25 ? webkitpdf.opt_delay : 25;",
453 "\t GLib.Timeout.add_seconds(1, () => { ",
455 "\t\tprint(\"timeout %d seconds :%d\", (int)( webkitpdf.opt_delay > 25 ? webkitpdf.opt_delay : 25), (int)cd);",
457 "\t\t\tprint(\"calling printit - timed out\");",
458 "\t\t\t_this.view.printit();",
459 "\t\t\treturn false;\t\t\t",
473 "name" : "BrowserWindow",
475 "path" : "/home/alan/gitlive/app.webkitpdf/BrowserWindow.bjs",