├── .gitignore ├── LICENSE.txt ├── README.md ├── Rakefile ├── examples └── simple_window.rb ├── ext └── webkit │ ├── extconf.rb │ ├── javascript-type-convert.h │ ├── javascript.h │ ├── webkit.c │ ├── webkit.cr │ └── webkit.rd ├── lib ├── webkit.rb └── webkit │ └── version.rb └── test ├── constant_test.rb └── js_test.rb /.gitignore: -------------------------------------------------------------------------------- 1 | .*.swp 2 | pkg/* 3 | tmp/* 4 | *.log 5 | Makefile 6 | *.so 7 | -------------------------------------------------------------------------------- /LICENSE.txt: -------------------------------------------------------------------------------- 1 | GNU LESSER GENERAL PUBLIC LICENSE 2 | Version 2.1, February 1999 3 | 4 | Copyright (C) 1991, 1999 Free Software Foundation, Inc. 5 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 6 | Everyone is permitted to copy and distribute verbatim copies 7 | of this license document, but changing it is not allowed. 8 | 9 | [This is the first released version of the Lesser GPL. It also counts 10 | as the successor of the GNU Library Public License, version 2, hence 11 | the version number 2.1.] 12 | 13 | Preamble 14 | 15 | The licenses for most software are designed to take away your 16 | freedom to share and change it. By contrast, the GNU General Public 17 | Licenses are intended to guarantee your freedom to share and change 18 | free software--to make sure the software is free for all its users. 19 | 20 | This license, the Lesser General Public License, applies to some 21 | specially designated software packages--typically libraries--of the 22 | Free Software Foundation and other authors who decide to use it. You 23 | can use it too, but we suggest you first think carefully about whether 24 | this license or the ordinary General Public License is the better 25 | strategy to use in any particular case, based on the explanations below. 26 | 27 | When we speak of free software, we are referring to freedom of use, 28 | not price. Our General Public Licenses are designed to make sure that 29 | you have the freedom to distribute copies of free software (and charge 30 | for this service if you wish); that you receive source code or can get 31 | it if you want it; that you can change the software and use pieces of 32 | it in new free programs; and that you are informed that you can do 33 | these things. 34 | 35 | To protect your rights, we need to make restrictions that forbid 36 | distributors to deny you these rights or to ask you to surrender these 37 | rights. These restrictions translate to certain responsibilities for 38 | you if you distribute copies of the library or if you modify it. 39 | 40 | For example, if you distribute copies of the library, whether gratis 41 | or for a fee, you must give the recipients all the rights that we gave 42 | you. You must make sure that they, too, receive or can get the source 43 | code. If you link other code with the library, you must provide 44 | complete object files to the recipients, so that they can relink them 45 | with the library after making changes to the library and recompiling 46 | it. And you must show them these terms so they know their rights. 47 | 48 | We protect your rights with a two-step method: (1) we copyright the 49 | library, and (2) we offer you this license, which gives you legal 50 | permission to copy, distribute and/or modify the library. 51 | 52 | To protect each distributor, we want to make it very clear that 53 | there is no warranty for the free library. Also, if the library is 54 | modified by someone else and passed on, the recipients should know 55 | that what they have is not the original version, so that the original 56 | author's reputation will not be affected by problems that might be 57 | introduced by others. 58 | 59 | Finally, software patents pose a constant threat to the existence of 60 | any free program. We wish to make sure that a company cannot 61 | effectively restrict the users of a free program by obtaining a 62 | restrictive license from a patent holder. Therefore, we insist that 63 | any patent license obtained for a version of the library must be 64 | consistent with the full freedom of use specified in this license. 65 | 66 | Most GNU software, including some libraries, is covered by the 67 | ordinary GNU General Public License. This license, the GNU Lesser 68 | General Public License, applies to certain designated libraries, and 69 | is quite different from the ordinary General Public License. We use 70 | this license for certain libraries in order to permit linking those 71 | libraries into non-free programs. 72 | 73 | When a program is linked with a library, whether statically or using 74 | a shared library, the combination of the two is legally speaking a 75 | combined work, a derivative of the original library. The ordinary 76 | General Public License therefore permits such linking only if the 77 | entire combination fits its criteria of freedom. The Lesser General 78 | Public License permits more lax criteria for linking other code with 79 | the library. 80 | 81 | We call this license the "Lesser" General Public License because it 82 | does Less to protect the user's freedom than the ordinary General 83 | Public License. It also provides other free software developers Less 84 | of an advantage over competing non-free programs. These disadvantages 85 | are the reason we use the ordinary General Public License for many 86 | libraries. However, the Lesser license provides advantages in certain 87 | special circumstances. 88 | 89 | For example, on rare occasions, there may be a special need to 90 | encourage the widest possible use of a certain library, so that it becomes 91 | a de-facto standard. To achieve this, non-free programs must be 92 | allowed to use the library. A more frequent case is that a free 93 | library does the same job as widely used non-free libraries. In this 94 | case, there is little to gain by limiting the free library to free 95 | software only, so we use the Lesser General Public License. 96 | 97 | In other cases, permission to use a particular library in non-free 98 | programs enables a greater number of people to use a large body of 99 | free software. For example, permission to use the GNU C Library in 100 | non-free programs enables many more people to use the whole GNU 101 | operating system, as well as its variant, the GNU/Linux operating 102 | system. 103 | 104 | Although the Lesser General Public License is Less protective of the 105 | users' freedom, it does ensure that the user of a program that is 106 | linked with the Library has the freedom and the wherewithal to run 107 | that program using a modified version of the Library. 108 | 109 | The precise terms and conditions for copying, distribution and 110 | modification follow. Pay close attention to the difference between a 111 | "work based on the library" and a "work that uses the library". The 112 | former contains code derived from the library, whereas the latter must 113 | be combined with the library in order to run. 114 | 115 | GNU LESSER GENERAL PUBLIC LICENSE 116 | TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 117 | 118 | 0. This License Agreement applies to any software library or other 119 | program which contains a notice placed by the copyright holder or 120 | other authorized party saying it may be distributed under the terms of 121 | this Lesser General Public License (also called "this License"). 122 | Each licensee is addressed as "you". 123 | 124 | A "library" means a collection of software functions and/or data 125 | prepared so as to be conveniently linked with application programs 126 | (which use some of those functions and data) to form executables. 127 | 128 | The "Library", below, refers to any such software library or work 129 | which has been distributed under these terms. A "work based on the 130 | Library" means either the Library or any derivative work under 131 | copyright law: that is to say, a work containing the Library or a 132 | portion of it, either verbatim or with modifications and/or translated 133 | straightforwardly into another language. (Hereinafter, translation is 134 | included without limitation in the term "modification".) 135 | 136 | "Source code" for a work means the preferred form of the work for 137 | making modifications to it. For a library, complete source code means 138 | all the source code for all modules it contains, plus any associated 139 | interface definition files, plus the scripts used to control compilation 140 | and installation of the library. 141 | 142 | Activities other than copying, distribution and modification are not 143 | covered by this License; they are outside its scope. The act of 144 | running a program using the Library is not restricted, and output from 145 | such a program is covered only if its contents constitute a work based 146 | on the Library (independent of the use of the Library in a tool for 147 | writing it). Whether that is true depends on what the Library does 148 | and what the program that uses the Library does. 149 | 150 | 1. You may copy and distribute verbatim copies of the Library's 151 | complete source code as you receive it, in any medium, provided that 152 | you conspicuously and appropriately publish on each copy an 153 | appropriate copyright notice and disclaimer of warranty; keep intact 154 | all the notices that refer to this License and to the absence of any 155 | warranty; and distribute a copy of this License along with the 156 | Library. 157 | 158 | You may charge a fee for the physical act of transferring a copy, 159 | and you may at your option offer warranty protection in exchange for a 160 | fee. 161 | 162 | 2. You may modify your copy or copies of the Library or any portion 163 | of it, thus forming a work based on the Library, and copy and 164 | distribute such modifications or work under the terms of Section 1 165 | above, provided that you also meet all of these conditions: 166 | 167 | a) The modified work must itself be a software library. 168 | 169 | b) You must cause the files modified to carry prominent notices 170 | stating that you changed the files and the date of any change. 171 | 172 | c) You must cause the whole of the work to be licensed at no 173 | charge to all third parties under the terms of this License. 174 | 175 | d) If a facility in the modified Library refers to a function or a 176 | table of data to be supplied by an application program that uses 177 | the facility, other than as an argument passed when the facility 178 | is invoked, then you must make a good faith effort to ensure that, 179 | in the event an application does not supply such function or 180 | table, the facility still operates, and performs whatever part of 181 | its purpose remains meaningful. 182 | 183 | (For example, a function in a library to compute square roots has 184 | a purpose that is entirely well-defined independent of the 185 | application. Therefore, Subsection 2d requires that any 186 | application-supplied function or table used by this function must 187 | be optional: if the application does not supply it, the square 188 | root function must still compute square roots.) 189 | 190 | These requirements apply to the modified work as a whole. If 191 | identifiable sections of that work are not derived from the Library, 192 | and can be reasonably considered independent and separate works in 193 | themselves, then this License, and its terms, do not apply to those 194 | sections when you distribute them as separate works. But when you 195 | distribute the same sections as part of a whole which is a work based 196 | on the Library, the distribution of the whole must be on the terms of 197 | this License, whose permissions for other licensees extend to the 198 | entire whole, and thus to each and every part regardless of who wrote 199 | it. 200 | 201 | Thus, it is not the intent of this section to claim rights or contest 202 | your rights to work written entirely by you; rather, the intent is to 203 | exercise the right to control the distribution of derivative or 204 | collective works based on the Library. 205 | 206 | In addition, mere aggregation of another work not based on the Library 207 | with the Library (or with a work based on the Library) on a volume of 208 | a storage or distribution medium does not bring the other work under 209 | the scope of this License. 210 | 211 | 3. You may opt to apply the terms of the ordinary GNU General Public 212 | License instead of this License to a given copy of the Library. To do 213 | this, you must alter all the notices that refer to this License, so 214 | that they refer to the ordinary GNU General Public License, version 2, 215 | instead of to this License. (If a newer version than version 2 of the 216 | ordinary GNU General Public License has appeared, then you can specify 217 | that version instead if you wish.) Do not make any other change in 218 | these notices. 219 | 220 | Once this change is made in a given copy, it is irreversible for 221 | that copy, so the ordinary GNU General Public License applies to all 222 | subsequent copies and derivative works made from that copy. 223 | 224 | This option is useful when you wish to copy part of the code of 225 | the Library into a program that is not a library. 226 | 227 | 4. You may copy and distribute the Library (or a portion or 228 | derivative of it, under Section 2) in object code or executable form 229 | under the terms of Sections 1 and 2 above provided that you accompany 230 | it with the complete corresponding machine-readable source code, which 231 | must be distributed under the terms of Sections 1 and 2 above on a 232 | medium customarily used for software interchange. 233 | 234 | If distribution of object code is made by offering access to copy 235 | from a designated place, then offering equivalent access to copy the 236 | source code from the same place satisfies the requirement to 237 | distribute the source code, even though third parties are not 238 | compelled to copy the source along with the object code. 239 | 240 | 5. A program that contains no derivative of any portion of the 241 | Library, but is designed to work with the Library by being compiled or 242 | linked with it, is called a "work that uses the Library". Such a 243 | work, in isolation, is not a derivative work of the Library, and 244 | therefore falls outside the scope of this License. 245 | 246 | However, linking a "work that uses the Library" with the Library 247 | creates an executable that is a derivative of the Library (because it 248 | contains portions of the Library), rather than a "work that uses the 249 | library". The executable is therefore covered by this License. 250 | Section 6 states terms for distribution of such executables. 251 | 252 | When a "work that uses the Library" uses material from a header file 253 | that is part of the Library, the object code for the work may be a 254 | derivative work of the Library even though the source code is not. 255 | Whether this is true is especially significant if the work can be 256 | linked without the Library, or if the work is itself a library. The 257 | threshold for this to be true is not precisely defined by law. 258 | 259 | If such an object file uses only numerical parameters, data 260 | structure layouts and accessors, and small macros and small inline 261 | functions (ten lines or less in length), then the use of the object 262 | file is unrestricted, regardless of whether it is legally a derivative 263 | work. (Executables containing this object code plus portions of the 264 | Library will still fall under Section 6.) 265 | 266 | Otherwise, if the work is a derivative of the Library, you may 267 | distribute the object code for the work under the terms of Section 6. 268 | Any executables containing that work also fall under Section 6, 269 | whether or not they are linked directly with the Library itself. 270 | 271 | 6. As an exception to the Sections above, you may also combine or 272 | link a "work that uses the Library" with the Library to produce a 273 | work containing portions of the Library, and distribute that work 274 | under terms of your choice, provided that the terms permit 275 | modification of the work for the customer's own use and reverse 276 | engineering for debugging such modifications. 277 | 278 | You must give prominent notice with each copy of the work that the 279 | Library is used in it and that the Library and its use are covered by 280 | this License. You must supply a copy of this License. If the work 281 | during execution displays copyright notices, you must include the 282 | copyright notice for the Library among them, as well as a reference 283 | directing the user to the copy of this License. Also, you must do one 284 | of these things: 285 | 286 | a) Accompany the work with the complete corresponding 287 | machine-readable source code for the Library including whatever 288 | changes were used in the work (which must be distributed under 289 | Sections 1 and 2 above); and, if the work is an executable linked 290 | with the Library, with the complete machine-readable "work that 291 | uses the Library", as object code and/or source code, so that the 292 | user can modify the Library and then relink to produce a modified 293 | executable containing the modified Library. (It is understood 294 | that the user who changes the contents of definitions files in the 295 | Library will not necessarily be able to recompile the application 296 | to use the modified definitions.) 297 | 298 | b) Use a suitable shared library mechanism for linking with the 299 | Library. A suitable mechanism is one that (1) uses at run time a 300 | copy of the library already present on the user's computer system, 301 | rather than copying library functions into the executable, and (2) 302 | will operate properly with a modified version of the library, if 303 | the user installs one, as long as the modified version is 304 | interface-compatible with the version that the work was made with. 305 | 306 | c) Accompany the work with a written offer, valid for at 307 | least three years, to give the same user the materials 308 | specified in Subsection 6a, above, for a charge no more 309 | than the cost of performing this distribution. 310 | 311 | d) If distribution of the work is made by offering access to copy 312 | from a designated place, offer equivalent access to copy the above 313 | specified materials from the same place. 314 | 315 | e) Verify that the user has already received a copy of these 316 | materials or that you have already sent this user a copy. 317 | 318 | For an executable, the required form of the "work that uses the 319 | Library" must include any data and utility programs needed for 320 | reproducing the executable from it. However, as a special exception, 321 | the materials to be distributed need not include anything that is 322 | normally distributed (in either source or binary form) with the major 323 | components (compiler, kernel, and so on) of the operating system on 324 | which the executable runs, unless that component itself accompanies 325 | the executable. 326 | 327 | It may happen that this requirement contradicts the license 328 | restrictions of other proprietary libraries that do not normally 329 | accompany the operating system. Such a contradiction means you cannot 330 | use both them and the Library together in an executable that you 331 | distribute. 332 | 333 | 7. You may place library facilities that are a work based on the 334 | Library side-by-side in a single library together with other library 335 | facilities not covered by this License, and distribute such a combined 336 | library, provided that the separate distribution of the work based on 337 | the Library and of the other library facilities is otherwise 338 | permitted, and provided that you do these two things: 339 | 340 | a) Accompany the combined library with a copy of the same work 341 | based on the Library, uncombined with any other library 342 | facilities. This must be distributed under the terms of the 343 | Sections above. 344 | 345 | b) Give prominent notice with the combined library of the fact 346 | that part of it is a work based on the Library, and explaining 347 | where to find the accompanying uncombined form of the same work. 348 | 349 | 8. You may not copy, modify, sublicense, link with, or distribute 350 | the Library except as expressly provided under this License. Any 351 | attempt otherwise to copy, modify, sublicense, link with, or 352 | distribute the Library is void, and will automatically terminate your 353 | rights under this License. However, parties who have received copies, 354 | or rights, from you under this License will not have their licenses 355 | terminated so long as such parties remain in full compliance. 356 | 357 | 9. You are not required to accept this License, since you have not 358 | signed it. However, nothing else grants you permission to modify or 359 | distribute the Library or its derivative works. These actions are 360 | prohibited by law if you do not accept this License. Therefore, by 361 | modifying or distributing the Library (or any work based on the 362 | Library), you indicate your acceptance of this License to do so, and 363 | all its terms and conditions for copying, distributing or modifying 364 | the Library or works based on it. 365 | 366 | 10. Each time you redistribute the Library (or any work based on the 367 | Library), the recipient automatically receives a license from the 368 | original licensor to copy, distribute, link with or modify the Library 369 | subject to these terms and conditions. You may not impose any further 370 | restrictions on the recipients' exercise of the rights granted herein. 371 | You are not responsible for enforcing compliance by third parties with 372 | this License. 373 | 374 | 11. If, as a consequence of a court judgment or allegation of patent 375 | infringement or for any other reason (not limited to patent issues), 376 | conditions are imposed on you (whether by court order, agreement or 377 | otherwise) that contradict the conditions of this License, they do not 378 | excuse you from the conditions of this License. If you cannot 379 | distribute so as to satisfy simultaneously your obligations under this 380 | License and any other pertinent obligations, then as a consequence you 381 | may not distribute the Library at all. For example, if a patent 382 | license would not permit royalty-free redistribution of the Library by 383 | all those who receive copies directly or indirectly through you, then 384 | the only way you could satisfy both it and this License would be to 385 | refrain entirely from distribution of the Library. 386 | 387 | If any portion of this section is held invalid or unenforceable under any 388 | particular circumstance, the balance of the section is intended to apply, 389 | and the section as a whole is intended to apply in other circumstances. 390 | 391 | It is not the purpose of this section to induce you to infringe any 392 | patents or other property right claims or to contest validity of any 393 | such claims; this section has the sole purpose of protecting the 394 | integrity of the free software distribution system which is 395 | implemented by public license practices. Many people have made 396 | generous contributions to the wide range of software distributed 397 | through that system in reliance on consistent application of that 398 | system; it is up to the author/donor to decide if he or she is willing 399 | to distribute software through any other system and a licensee cannot 400 | impose that choice. 401 | 402 | This section is intended to make thoroughly clear what is believed to 403 | be a consequence of the rest of this License. 404 | 405 | 12. If the distribution and/or use of the Library is restricted in 406 | certain countries either by patents or by copyrighted interfaces, the 407 | original copyright holder who places the Library under this License may add 408 | an explicit geographical distribution limitation excluding those countries, 409 | so that distribution is permitted only in or among countries not thus 410 | excluded. In such case, this License incorporates the limitation as if 411 | written in the body of this License. 412 | 413 | 13. The Free Software Foundation may publish revised and/or new 414 | versions of the Lesser General Public License from time to time. 415 | Such new versions will be similar in spirit to the present version, 416 | but may differ in detail to address new problems or concerns. 417 | 418 | Each version is given a distinguishing version number. If the Library 419 | specifies a version number of this License which applies to it and 420 | "any later version", you have the option of following the terms and 421 | conditions either of that version or of any later version published by 422 | the Free Software Foundation. If the Library does not specify a 423 | license version number, you may choose any version ever published by 424 | the Free Software Foundation. 425 | 426 | 14. If you wish to incorporate parts of the Library into other free 427 | programs whose distribution conditions are incompatible with these, 428 | write to the author to ask for permission. For software which is 429 | copyrighted by the Free Software Foundation, write to the Free 430 | Software Foundation; we sometimes make exceptions for this. Our 431 | decision will be guided by the two goals of preserving the free status 432 | of all derivatives of our free software and of promoting the sharing 433 | and reuse of software generally. 434 | 435 | NO WARRANTY 436 | 437 | 15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO 438 | WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW. 439 | EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR 440 | OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY 441 | KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE 442 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 443 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE 444 | LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME 445 | THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 446 | 447 | 16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN 448 | WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY 449 | AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU 450 | FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR 451 | CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE 452 | LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING 453 | RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A 454 | FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF 455 | SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH 456 | DAMAGES. 457 | 458 | END OF TERMS AND CONDITIONS 459 | 460 | How to Apply These Terms to Your New Libraries 461 | 462 | If you develop a new library, and you want it to be of the greatest 463 | possible use to the public, we recommend making it free software that 464 | everyone can redistribute and change. You can do so by permitting 465 | redistribution under these terms (or, alternatively, under the terms of the 466 | ordinary General Public License). 467 | 468 | To apply these terms, attach the following notices to the library. It is 469 | safest to attach them to the start of each source file to most effectively 470 | convey the exclusion of warranty; and each file should have at least the 471 | "copyright" line and a pointer to where the full notice is found. 472 | 473 | 474 | Copyright (C) 475 | 476 | This library is free software; you can redistribute it and/or 477 | modify it under the terms of the GNU Lesser General Public 478 | License as published by the Free Software Foundation; either 479 | version 2.1 of the License, or (at your option) any later version. 480 | 481 | This library is distributed in the hope that it will be useful, 482 | but WITHOUT ANY WARRANTY; without even the implied warranty of 483 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 484 | Lesser General Public License for more details. 485 | 486 | You should have received a copy of the GNU Lesser General Public 487 | License along with this library; if not, write to the Free Software 488 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 489 | 490 | Also add information on how to contact you by electronic and paper mail. 491 | 492 | You should also get your employer (if you work as a programmer) or your 493 | school, if any, to sign a "copyright disclaimer" for the library, if 494 | necessary. Here is a sample; alter the names: 495 | 496 | Yoyodyne, Inc., hereby disclaims all copyright interest in the 497 | library `Frob' (a library for tweaking knobs) written by James Random Hacker. 498 | 499 | , 1 April 1990 500 | Ty Coon, President of Vice 501 | 502 | That's all there is to it! 503 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | Gtk Webkit Ruby 2 | =============== 3 | 4 | Requires 5 | -------- 6 | * rubber-generate >= 0.0.17 7 | * rake-compiler, rake to build 8 | * ruby-gnome2 (including development files) 9 | * webkit (including development files) 10 | 11 | Changes 12 | ------- 13 | * 0.0.4 - 16 Nov 2012 14 | * Use rubygems to find Ruby-GNOME2 installation (fixes #2, missing rbglib.h header file) 15 | * Wrap stored JS ref pointer with Data_Wrap_Struct (fixes GC bug) 16 | 17 | Description 18 | ----------- 19 | Gtk Webkit bindings for ruby. Partial coverage sufficient to embed a webview in a ruby-gnome2 application. 20 | 21 | Also experimental support for allowing ruby code to be called by javascript & executing javascript from ruby. 22 | 23 | e.g 24 | 25 | ````ruby 26 | require 'gtk2' 27 | require 'webkit' 28 | require 'digest/md5' 29 | 30 | v = WebKit::WebView.new 31 | v.main_frame.setup_ruby 32 | 33 | v.main_frame.add_js_api('md5') do |what| 34 | Digest::MD5.hexdigest(what) 35 | end 36 | 37 | puts v.main_frame.exec_js("ruby_eval('RUBY_DESCRIPTION')") 38 | puts v.main_frame.exec_js("md5('foo')") 39 | puts Digest::MD5.hexdigest('foo') 40 | ```` 41 | 42 | License 43 | ------- 44 | Copyright (c) 2011-2012 Geoff Youngs 45 | 46 | This program is free software. 47 | You can distribute/modify this program under the terms of 48 | the GNU LESSER GENERAL PUBLIC LICENSE Version 2.1. 49 | 50 | -------------------------------------------------------------------------------- /Rakefile: -------------------------------------------------------------------------------- 1 | require 'rubygems' 2 | gem 'rake-compiler' 3 | require 'rake/extensiontask' 4 | BASE_DIR = Dir.pwd 5 | require 'rubygems/package_task' 6 | require 'rake/testtask' 7 | 8 | $: << './lib' 9 | 10 | require 'webkit/version' 11 | exts = [] 12 | 13 | namespace :prepare do 14 | FileList["ext/*/*.cr"].each do |cr| 15 | dir = File.dirname(cr) 16 | name = File.basename(dir) 17 | desc "Generate source for #{name}" 18 | task(name.intern) do 19 | sh 'rubber-generate', '--build-dir', dir, cr 20 | end 21 | end 22 | end 23 | 24 | spec = Gem::Specification.new do |s| 25 | s.name = "gtk-webkit-ruby" 26 | s.author = "Geoff Youngs" 27 | s.email = "git@intersect-uk.co.uk" 28 | s.version = WebKit::BINDINGS_VERSION 29 | s.homepage = "http://github.com/geoffyoungs/gtk-webkit-ruby" 30 | s.summary = "Webkit bindings using rubber-generate" 31 | s.add_dependency("glib2", ">= 2.0.0") 32 | s.add_dependency("gtk2", ">= 2.0.0") 33 | s.add_development_dependency("rubber-generate", ">= 0.0.20") 34 | s.platform = Gem::Platform::RUBY 35 | s.extensions = FileList["ext/*/extconf.rb"] 36 | s.files = FileList['ext/*/*.{c,h,cr,rd}'] + ['Rakefile', 'README.md'] + FileList['lib/**/*.rb'] 37 | s.description = <<-EOF 38 | Gtk Webkit bindings for ruby. Partial coverage sufficient to embed a webview in a Ruby-GNOME2 application. 39 | 40 | Also initial/experimental support for allowing ruby code to be called by javascript & executing javascript 41 | from ruby. 42 | 43 | e.g 44 | require 'gtk2' 45 | require 'webkit' 46 | 47 | v = WebKit::WebView.new 48 | v.main_frame.setup_ruby 49 | puts v.main_frame.exec_js("ruby_eval('RUBY_DESCRIPTION')") 50 | puts v.main_frame.exec_js("document.root.innerHTML") 51 | EOF 52 | end 53 | Gem::PackageTask.new(spec) do |pkg| 54 | pkg.need_tar = true 55 | end 56 | Rake::ExtensionTask.new("webkit", spec) 57 | 58 | Rake::TestTask.new do |t| 59 | t.test_files = FileList['test/*_test.rb'] 60 | end 61 | 62 | task :default, :compile 63 | 64 | -------------------------------------------------------------------------------- /examples/simple_window.rb: -------------------------------------------------------------------------------- 1 | require 'gtk2' 2 | require 'webkit' 3 | 4 | webkit = WebKit::WebView.new 5 | webkit.open 'http://google.com' 6 | 7 | window = Gtk::Window.new 8 | window.title = 'Ruby Webkit' 9 | 10 | # Center the window and resize 11 | window.resize 800, 600 12 | window.window_position = Gtk::Window::POS_CENTER 13 | 14 | # Exit when closing the window 15 | window.signal_connect('destroy') { Gtk.main_quit } 16 | 17 | # Add the webview to the window 18 | window.add webkit 19 | window.show_all 20 | 21 | Gtk.main 22 | -------------------------------------------------------------------------------- /ext/webkit/extconf.rb: -------------------------------------------------------------------------------- 1 | require 'mkmf' 2 | use_gems = false 3 | begin 4 | require 'mkmf-gnome2' 5 | rescue LoadError 6 | use_gems = true 7 | end 8 | 9 | if use_gems or Object.const_defined?('Gem') 10 | require 'rubygems' 11 | gem 'glib2' 12 | require 'mkmf-gnome2' 13 | %w[rbglib.h rbgtk.h rbpango.h rbatk.h].each do |header| 14 | Gem.find_files(header).each do |f| 15 | $CFLAGS += " '-I#{File.dirname(f)}'" 16 | end 17 | end 18 | end 19 | # Look for headers in {gem_root}/ext/{package} 20 | if use_gems 21 | %w[ 22 | glib2 gdk_pixbuf2 atk gtk2].each do |package| 23 | require package 24 | if Gem.loaded_specs[package] 25 | $CFLAGS += " -I" + Gem.loaded_specs[package].full_gem_path + "/ext/" + package 26 | else 27 | if fn = $".find { |n| n.sub(/[.](so|rb)$/,'') == package } 28 | dr = $:.find { |d| File.exist?(File.join(d, fn)) } 29 | pt = File.join(dr,fn) if dr && fn 30 | else 31 | pt = "??" 32 | end 33 | STDERR.puts "require '" + package + "' loaded '"+pt+"' instead of the gem - trying to continue, but build may fail" 34 | end 35 | end 36 | end 37 | if RbConfig::CONFIG.has_key?('rubyhdrdir') 38 | $CFLAGS += " -I" + RbConfig::CONFIG['rubyhdrdir']+'/ruby' 39 | end 40 | 41 | $CFLAGS += " -I." 42 | have_func("rb_errinfo") 43 | PKGConfig.have_package("gtk+-2.0") or exit(-1) 44 | PKGConfig.have_package("webkit-1.0") or exit(-1) 45 | have_header("dlfcn.h") or exit(-1) 46 | have_header("errno.h") or exit(-1) 47 | have_header("ffi.h") or exit(-1) 48 | have_header("rbgobject.h") or exit(-1) 49 | have_header("sys/mman.h") or exit(-1) 50 | have_header("intern.h") or exit(-1) 51 | have_header("webkit/webkit.h") or exit(-1) 52 | have_header("webkit/webkitenumtypes.h") or exit(-1) 53 | have_header("JavaScriptCore/JavaScript.h") or exit(-1) 54 | have_library("dl") or exit(-1) 55 | $LIBS += " -ldl" 56 | have_library("ffi") or exit(-1) 57 | $LIBS += " -lffi" 58 | 59 | STDOUT.print("checking for new allocation framework... ") # for ruby-1.7 60 | if Object.respond_to? :allocate 61 | STDOUT.print "yes 62 | " 63 | $defs << "-DHAVE_OBJECT_ALLOCATE" 64 | else 65 | STDOUT.print "no 66 | " 67 | end 68 | 69 | top = File.expand_path(File.dirname(__FILE__) + '/..') # XXX 70 | $CFLAGS += " " + ['glib/src'].map{|d| 71 | "-I" + File.join(top, d) 72 | }.join(" ") 73 | 74 | have_func("rb_define_alloc_func") # for ruby-1.8 75 | 76 | #set_output_lib('libruby-webkit.a') 77 | if /cygwin|mingw/ =~ RUBY_PLATFORM 78 | top = "../.." 79 | [ 80 | ["glib/src", "ruby-glib2"], 81 | ].each{|d,l| 82 | $LDFLAGS << sprintf(" -L%s/%s", top, d) 83 | $libs << sprintf(" -l%s", l) 84 | } 85 | end 86 | begin 87 | srcdir = File.expand_path(File.dirname($0)) 88 | 89 | begin 90 | 91 | obj_ext = "."+$OBJEXT 92 | 93 | $libs = $libs.split(/ /).uniq.join(' ') 94 | $source_files = Dir.glob(sprintf("%s/*.c", srcdir)).map{|fname| 95 | fname[0, srcdir.length+1] = '' 96 | fname 97 | } 98 | $objs = $source_files.collect do |item| 99 | item.gsub(/.c$/, obj_ext) 100 | end 101 | 102 | # 103 | # create Makefile 104 | # 105 | $defs << "-DRUBY_WEBKIT_COMPILATION" 106 | # $CFLAGS << $defs.join(' ') 107 | create_makefile("webkit", srcdir) 108 | raise Interrupt if not FileTest.exist? "Makefile" 109 | 110 | File.open("Makefile", "a") do |mfile| 111 | $source_files.each do |e| 112 | mfile.print sprintf("%s: %s 113 | ", e.gsub(/.c$/, obj_ext), e) 114 | end 115 | end 116 | ensure 117 | #Dir.chdir ".." 118 | end 119 | 120 | #create_top_makefile() 121 | rescue Interrupt 122 | print " [error] " + $!.to_s + " 123 | " 124 | end 125 | 126 | -------------------------------------------------------------------------------- /ext/webkit/javascript-type-convert.h: -------------------------------------------------------------------------------- 1 | static JSValueRef 2 | convert_string_to_jsval(JSContextRef ctx, char *str) { 3 | JSStringRef js_s_ref; 4 | JSValueRef js_val_ref; 5 | 6 | js_s_ref = JSStringCreateWithUTF8CString(str); 7 | js_val_ref = JSValueMakeString(ctx, js_s_ref); 8 | JSStringRelease(js_s_ref); 9 | 10 | return js_val_ref; 11 | } 12 | 13 | static char *jsstrref_to_charp(JSStringRef str, size_t *out_len) 14 | { 15 | size_t max = 0, len; 16 | char *buf; 17 | 18 | max = JSStringGetMaximumUTF8CStringSize(str); 19 | buf = malloc(max); 20 | len = JSStringGetUTF8CString(str, buf, max); 21 | 22 | if (out_len) { 23 | *out_len = len; 24 | } 25 | 26 | return buf; 27 | } 28 | 29 | static char * 30 | convert_javascript_to_utf8_string(JSContextRef ctx, JSValueRef val, size_t* out_len) 31 | { 32 | JSStringRef str = JSValueToStringCopy(ctx, val, NULL); 33 | char *buf; 34 | 35 | buf = jsstrref_to_charp(str, out_len); 36 | 37 | JSStringRelease(str); 38 | 39 | return buf; 40 | } 41 | 42 | static ID 43 | convert_javascript_to_intern(JSStringRef str) 44 | { 45 | ID id; 46 | size_t max = 0, len; 47 | char *buf; 48 | 49 | max = JSStringGetMaximumUTF8CStringSize(str); 50 | buf = malloc(max); 51 | len = JSStringGetUTF8CString(str, buf, max); 52 | buf[len-1] = 0; 53 | id = rb_intern(buf); 54 | 55 | free(buf); 56 | 57 | return id; 58 | } 59 | 60 | static inline VALUE conv_jsstrref_to_value(JSStringRef str) 61 | { 62 | VALUE output = Qnil; 63 | size_t len = 0, max = 0; 64 | char *buf; 65 | 66 | max = JSStringGetMaximumUTF8CStringSize(str); 67 | buf = malloc(max); 68 | len = JSStringGetUTF8CString(str, buf, max); 69 | 70 | output = rb_str_new(buf, len-1); // Ignore terminator 71 | 72 | free(buf); 73 | 74 | return output; 75 | 76 | } 77 | 78 | static inline VALUE 79 | convert_javascript_string_to_ruby(JSContextRef ctx, JSValueRef val) 80 | { 81 | VALUE output = Qnil; 82 | JSStringRef str; 83 | 84 | str = JSValueToStringCopy(ctx, val, NULL); 85 | 86 | output = conv_jsstrref_to_value(str); 87 | 88 | JSStringRelease(str); 89 | 90 | return output; 91 | } 92 | 93 | static VALUE 94 | convert_javascript_to_ruby(JSContextRef ctx, JSValueRef val) 95 | { 96 | VALUE output = Qnil; 97 | JSValueRef *_exception = NULL; 98 | 99 | switch (JSValueGetType(ctx, val)) { 100 | case kJSTypeUndefined: 101 | case kJSTypeNull: 102 | output = Qnil; 103 | break; 104 | case kJSTypeBoolean: 105 | output = JSValueToBoolean(ctx, val) ? Qtrue : Qfalse; 106 | break; 107 | case kJSTypeNumber: 108 | output = rb_float_new(JSValueToNumber(ctx, val, _exception)); 109 | break; 110 | case kJSTypeString: 111 | output = convert_javascript_string_to_ruby(ctx, val); 112 | break; 113 | case kJSTypeObject: 114 | output = convert_javascript_string_to_ruby(ctx, val); 115 | break; 116 | default: 117 | break; 118 | } 119 | 120 | return output; 121 | } 122 | 123 | 124 | static JSValueRef 125 | convert_ruby_to_javascript(JSContextRef ctx, VALUE value) 126 | { 127 | JSStringRef str; 128 | JSValueRef jsval; 129 | 130 | switch (TYPE(value)) { 131 | case T_FIXNUM: 132 | return JSValueMakeNumber(ctx, (double) FIX2LONG(value)); 133 | case T_FLOAT: 134 | return JSValueMakeNumber(ctx, (double) NUM2DBL(value)); 135 | case T_BIGNUM: 136 | return JSValueMakeNumber(ctx, (double) rb_big2long(value)); 137 | case T_TRUE: 138 | case T_FALSE: 139 | return JSValueMakeBoolean(ctx, RTEST(value)); 140 | case T_UNDEF: 141 | return JSValueMakeUndefined(ctx); 142 | case T_NIL: 143 | return JSValueMakeNull(ctx); 144 | default: 145 | if (TYPE(value) != T_STRING) { 146 | value = rb_funcall(value, rb_intern("to_s"), 0); 147 | } 148 | str = JSStringCreateWithUTF8CString(RSTRING_PTR(value)); 149 | jsval = JSValueMakeString(ctx, str); 150 | JSStringRelease(str); 151 | return jsval; 152 | } 153 | } 154 | 155 | -------------------------------------------------------------------------------- /ext/webkit/javascript.h: -------------------------------------------------------------------------------- 1 | #include 2 | #include "javascript-type-convert.h" 3 | 4 | #ifndef STRINGIZE 5 | #define STRINGIZE(s) #s 6 | #endif 7 | 8 | #define JS_fn(f) _JS_fn(ctx, STRINGIZE(f), f) 9 | #ifdef __GNUC__ 10 | #pragma GCC diagnostic ignored "-Wunused-parameter" 11 | #pragma GCC diagnostic ignored "-Wunused-variable" 12 | #endif 13 | 14 | typedef struct { 15 | JSClassDefinition definition; 16 | JSClassRef class_ref; 17 | VALUE rbObject; 18 | JSContextRef ctx; 19 | } ruby_js_class_def; 20 | static ruby_js_class_def *jsrb_newClass(VALUE robject); 21 | 22 | JSObjectRef _JS_fn(JSContextRef ctx, const char *name, JSObjectCallAsFunctionCallback f) 23 | { 24 | JSStringRef nameStr = JSStringCreateWithUTF8CString(name); 25 | JSObjectRef value = JSObjectMakeFunctionWithCallback(ctx, nameStr, f); 26 | JSStringRelease(nameStr); 27 | return value; 28 | } 29 | 30 | static inline bool 31 | js_obj_set_value(JSContextRef ctx, JSObjectRef object, char *name, JSObjectRef value) 32 | { 33 | JSValueRef *_exception = NULL; 34 | JSStringRef nameStr = JSStringCreateWithUTF8CString(name); 35 | 36 | JSObjectSetProperty(ctx, object, nameStr, value, kJSPropertyAttributeNone, _exception); 37 | 38 | JSStringRelease(nameStr); 39 | 40 | if (*_exception) { return false; } 41 | 42 | return true; 43 | } 44 | 45 | 46 | static JSValueRef 47 | js_call_ruby_eval (JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, 48 | size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception) 49 | { 50 | JSValueRef value = NULL; 51 | 52 | if (argumentCount == 1) { 53 | char *script; 54 | VALUE val; 55 | 56 | script = convert_javascript_to_utf8_string(ctx, arguments[0], NULL); 57 | val = rb_eval_string(script); 58 | 59 | value = convert_ruby_to_javascript(ctx, val); 60 | 61 | free(script); 62 | } else { 63 | *exception = convert_string_to_jsval(ctx, "Wrong number of arguments"); 64 | } 65 | 66 | return value; 67 | } 68 | 69 | static GHashTable *ruby_fns = NULL; 70 | 71 | static JSValueRef 72 | js_ruby_fn(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, 73 | size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception) 74 | { 75 | size_t i; 76 | VALUE *args = ALLOC_N(VALUE, argumentCount); 77 | VALUE ruby_fn = (VALUE) JSObjectGetPrivate(function); 78 | JSValueRef retval; 79 | 80 | if ((!ruby_fn) && ruby_fns) { 81 | ruby_fn = (VALUE)g_hash_table_lookup(ruby_fns, (gpointer)function); 82 | } 83 | 84 | for (i = 0; i < argumentCount; i++) { 85 | args[i] = convert_javascript_to_ruby(ctx, arguments[i]); 86 | } 87 | 88 | retval = convert_ruby_to_javascript(ctx, 89 | rb_funcall2(ruby_fn, rb_intern("call"), argumentCount, args)); 90 | 91 | xfree(args); 92 | 93 | return retval; 94 | } 95 | 96 | static void jsrb_class_init(JSContextRef ctx, JSObjectRef object) 97 | { 98 | // Do something here? 99 | } 100 | 101 | static void jsrb_class_final(JSObjectRef object) { 102 | // Clean up? 103 | VALUE robject = (VALUE)JSObjectGetPrivate(object); 104 | if (RTEST(robject)) { 105 | ruby_js_class_def *def = (ruby_js_class_def*)DATA_PTR(rb_iv_get(robject, "_js_ref")); 106 | rb_iv_set(robject, "_js_ref", Qnil); 107 | free(def); 108 | RUBYFUNC_DEL(object); 109 | } 110 | } 111 | 112 | /** 113 | * Heuristic: 114 | * - return true if obj.respond_to?(property) # i.e. method 115 | * - return true if obj.respond_to?("#{property}=") # ie. setter 116 | * - return true if obj.instance_variables.includj?("@#{property}") # ? maybe ? 117 | */ 118 | 119 | static bool jsrb_has_prop(JSContextRef ctx, JSObjectRef object, JSStringRef propertyName) 120 | { 121 | VALUE robject = (VALUE)JSObjectGetPrivate(object); 122 | 123 | if (RTEST(robject)) { 124 | ID prop = convert_javascript_to_intern(propertyName); 125 | if (rb_respond_to(robject, prop)) { 126 | return true; 127 | } 128 | } 129 | 130 | return false; 131 | } 132 | 133 | 134 | /** 135 | * Heuristic: 136 | * - return method(property) if obj.method(property).arity > 0 137 | * - return send(property) if obj.respond_to?("#{property}=") # ie. setter - implemented as property 138 | * - return send(property) if obj.instance_variables.includj?("@#{property}") # ? maybe ? 139 | * - return send(property) if obj.respond_to?(property) # i.e. method 140 | */ 141 | 142 | static JSObjectRef jsrb_get_prop(JSContextRef ctx, JSObjectRef object, JSStringRef propertyName, JSValueRef* exception) 143 | { 144 | VALUE robject = JSObjectGetPrivate(object); 145 | 146 | if (RTEST(robject)) { 147 | ID prop = convert_javascript_to_intern(propertyName); 148 | if (rb_respond_to(robject, prop)) { 149 | VALUE rbo = rb_funcall(robject, rb_intern("method"), 1, conv_jsstrref_to_value(propertyName)); 150 | ruby_js_class_def *def = jsrb_newClass(rbo); 151 | def->ctx = ctx; 152 | return JSObjectMake(def->ctx, def->class_ref, (void*)rbo); 153 | } 154 | } 155 | 156 | return false; 157 | } 158 | 159 | static bool jsrb_set_prop(JSContextRef ctx, JSObjectRef object, JSStringRef propertyName, JSValueRef value, JSValueRef* exception) 160 | { 161 | return false; 162 | } 163 | 164 | static bool jsrb_del_prop(JSContextRef ctx, JSObjectRef object, JSStringRef propertyName, JSValueRef* exception) 165 | { 166 | return false; 167 | } 168 | 169 | static void jsrb_get_prop_names(JSContextRef ctx, JSObjectRef object, JSPropertyNameAccumulatorRef propertyNames) 170 | { 171 | } 172 | 173 | static JSValueRef jsrb_call_fn(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception) 174 | { 175 | // 176 | VALUE robject = (VALUE)JSObjectGetPrivate(function); 177 | VALUE self = (VALUE)JSObjectGetPrivate(thisObject); 178 | if (RTEST(robject)) { 179 | VALUE rbo = rb_funcall2(robject, rb_intern("call"), 0, NULL); 180 | JSValueRef retval = convert_ruby_to_javascript(ctx, rbo); 181 | return retval; 182 | } 183 | return JSValueMakeUndefined(ctx); 184 | } 185 | 186 | typedef struct { 187 | JSContextRef ctx; 188 | JSObjectRef constructor; 189 | size_t argumentCount; 190 | JSValueRef *arguments; 191 | JSValueRef* exception; 192 | } construct_args; 193 | 194 | static JSObjectRef wrapRubyObject(JSContextRef ctx, VALUE value) 195 | { 196 | ruby_js_class_def *def; 197 | JSObjectRef object; 198 | 199 | def = jsrb_newClass(value); 200 | def->ctx = ctx; 201 | rb_iv_set(value, "_js_ref", Data_Wrap_Struct(cJsPtr, NULL, NULL, def)); 202 | object = JSObjectMake(ctx, def->class_ref, (void*)value); 203 | return object; 204 | } 205 | 206 | static void jsrb_class_construct_ffi(ffi_cif* cif, 207 | void** resp, 208 | void** vargs, 209 | void* userdata) { 210 | 211 | ruby_js_class_def *def = (ruby_js_class_def*)userdata; 212 | construct_args *args = (construct_args*)vargs; 213 | 214 | { 215 | int no_args = 0; 216 | VALUE *arg_list = NULL; 217 | JSObjectRef object; 218 | VALUE value = Qnil; 219 | 220 | 221 | if (is_ruby_native_thread()) { 222 | value = rb_class_new_instance(no_args, arg_list, def->rbObject); 223 | // Convert JS values... 224 | 225 | RUBYFUNC_ADD(value); 226 | } 227 | 228 | 229 | object = JSObjectMake(def->ctx, def->class_ref, (void*)value); 230 | 231 | 232 | *resp = (void*)object; 233 | } 234 | } 235 | 236 | 237 | static JSObjectRef jsrb_call_create(JSContextRef ctx, JSObjectRef constructor, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception) 238 | { 239 | int no_args = 0, i; 240 | volatile VALUE *arg_list = NULL; 241 | JSObjectRef object; 242 | VALUE value = Qnil; 243 | 244 | VALUE robject = JSObjectGetPrivate(constructor); 245 | 246 | if (RTEST(robject)) { 247 | arg_list = ALLOC_N(VALUE, argumentCount); 248 | 249 | for(i = 0; i < argumentCount; i++) { 250 | no_args += 1; 251 | arg_list[i] = convert_javascript_to_ruby(ctx, arguments[i]); 252 | } 253 | 254 | value = rb_class_new_instance(no_args, arg_list, robject); 255 | RUBYFUNC_ADD(value); 256 | 257 | xfree(arg_list); 258 | 259 | return wrapRubyObject(ctx, value); 260 | } 261 | 262 | return NULL; 263 | } 264 | 265 | static bool jsrb_has_instance(JSContextRef ctx, JSObjectRef constructor, JSValueRef possibleInstance, JSValueRef* exception) 266 | { 267 | return false; 268 | } 269 | 270 | static JSValueRef jsrb_convert(JSContextRef ctx, JSObjectRef object, JSType type, JSValueRef* exception) 271 | { 272 | return false; 273 | } 274 | 275 | static ruby_js_class_def *jsrb_newClass(VALUE robject) { 276 | JSClassDefinition *jclass; 277 | ruby_js_class_def *def; 278 | 279 | def = ALLOC_N(ruby_js_class_def,1); 280 | def->definition = kJSClassDefinitionEmpty; 281 | jclass = &(def->definition); 282 | 283 | jclass->version = 0; 284 | jclass->attributes = kJSClassAttributeNoAutomaticPrototype; 285 | 286 | // Check this? It should probably be a valid JS name... 287 | 288 | // ignore 289 | // staticValues 290 | // staticFunctions 291 | 292 | /* Basics */ 293 | jclass->initialize = jsrb_class_init; 294 | 295 | jclass->finalize = jsrb_class_final; 296 | 297 | /* Property accessors... */ 298 | jclass->hasProperty = jsrb_has_prop; 299 | jclass->getProperty = jsrb_get_prop; 300 | jclass->setProperty = jsrb_set_prop; 301 | jclass->deleteProperty = jsrb_del_prop; 302 | jclass->getPropertyNames = jsrb_get_prop_names; 303 | 304 | /* Function */ 305 | //rb_p(robject); 306 | if (rb_respond_to(robject, rb_intern("call"))) { 307 | jclass->callAsFunction = jsrb_call_fn; 308 | } else { 309 | 310 | jclass->callAsFunction = NULL; 311 | } 312 | 313 | if (rb_obj_is_instance_of(robject, rb_cClass)) { 314 | jclass->className = rb_class2name(robject); 315 | jclass->callAsConstructor = jsrb_call_create; 316 | /*ffi_cif *cif; 317 | ffi_closure *closure; 318 | void *code; 319 | ffi_type **types; 320 | int args_len = 5; 321 | 322 | cif = ALLOC_N(ffi_cif, 1); 323 | closure = ffi_closure_alloc(sizeof(ffi_closure), &code); 324 | types = ALLOC_N(ffi_type*, args_len); 325 | 326 | types[0] = &ffi_type_pointer; 327 | types[1] = &ffi_type_pointer; 328 | types[2] = &ffi_type_uint32; 329 | types[3] = &ffi_type_pointer; 330 | types[4] = &ffi_type_pointer; 331 | 332 | if (ffi_prep_cif(cif, FFI_DEFAULT_ABI, args_len, &ffi_type_pointer, types) == FFI_OK) { 333 | if (ffi_prep_closure_loc(closure, cif, jsrb_class_construct_ffi, (void*)def, code) == FFI_OK) { 334 | jclass->callAsConstructor = closure; 335 | } 336 | }*/ 337 | } else { 338 | jclass->className = rb_class2name(rb_obj_class(robject)); 339 | jclass->callAsConstructor = NULL; 340 | } 341 | 342 | //jclass->callAsConstructor = jsrb_call_create; 343 | jclass->hasInstance = jsrb_has_instance; 344 | jclass->convertToType = jsrb_convert; 345 | 346 | def->rbObject = robject; 347 | def->class_ref = JSClassCreate(jclass); 348 | 349 | return def; 350 | } 351 | 352 | /*static void jsrb_create_class(VALUE robject) { 353 | //JSClassDefinition *def = jsrb_newClass(robject); 354 | }*/ 355 | 356 | 357 | 358 | 359 | /** 360 | * Javascript functions called directly from binding 361 | **/ 362 | static void javascript_add_class(JSGlobalContextRef ctx, char *name, VALUE robject) 363 | { 364 | JSObjectRef global = JSContextGetGlobalObject(ctx), object; 365 | 366 | // Should we store this on the class? 367 | /* VALUE v = Qfalse; 368 | ruby_js_class_def *def; 369 | 370 | if (0 && RTEST(v = rb_iv_get(robject, "_js_ref"))) { 371 | def = (ruby_js_class_def*)v; 372 | } else { 373 | def = jsrb_newClass(robject); 374 | def->ctx = ctx; 375 | rb_iv_set(robject, "_js_ref", (VALUE)def); 376 | }*/ 377 | 378 | /* object = JSObjectMake(ctx, def->class_ref, NULL);*/ 379 | 380 | js_obj_set_value(ctx, global, name, wrapRubyObject(ctx, robject)); // Check failure? 381 | } 382 | static void * 383 | javascript_add_ruby_fn(JSGlobalContextRef ctx, char *name, VALUE ruby_fn) 384 | { 385 | JSObjectRef fn = NULL; 386 | 387 | if (!ruby_fns) { 388 | ruby_fns = g_hash_table_new(NULL, NULL); 389 | } 390 | 391 | JSObjectRef global = JSContextGetGlobalObject(ctx); 392 | 393 | fn = JS_fn(js_ruby_fn); 394 | 395 | if (!JSObjectSetPrivate(fn, (void*)ruby_fn)) { 396 | gpointer old_value = g_hash_table_lookup(ruby_fns, (gpointer)fn); 397 | if (old_value != NULL) 398 | RUBYFUNC_DEL((VALUE)old_value); 399 | RUBYFUNC_ADD(ruby_fn); 400 | g_hash_table_insert(ruby_fns, (gpointer)fn, (gpointer)ruby_fn); 401 | } 402 | 403 | js_obj_set_value(ctx, global, name, fn); // Check failure? 404 | 405 | return NULL; 406 | } 407 | 408 | static void * 409 | javascript_add_ruby_eval(JSGlobalContextRef ctx) 410 | { 411 | JSObjectRef global = JSContextGetGlobalObject(ctx); 412 | 413 | js_obj_set_value(ctx, global, (char*)"ruby_eval", JS_fn(js_call_ruby_eval)); 414 | 415 | return NULL; 416 | } 417 | 418 | static VALUE 419 | javascript_exec(JSGlobalContextRef ctx, char *script) 420 | { 421 | VALUE output = Qnil; 422 | 423 | JSStringRef js_script = JSStringCreateWithUTF8CString(script); 424 | JSStringRef url = JSStringCreateWithUTF8CString("x-ruby://string"); 425 | 426 | JSValueRef err = JSValueMakeUndefined(ctx); 427 | JSValueRef retval = NULL; 428 | 429 | 430 | retval = JSEvaluateScript(ctx, js_script, NULL, url, 0, &err); 431 | 432 | JSStringRelease(url); 433 | JSStringRelease(js_script); 434 | 435 | /* Convert output to ruby */ 436 | if (retval) { 437 | output = convert_javascript_to_ruby(ctx, retval); 438 | } else { 439 | JSStringRef str = JSValueToStringCopy(ctx, err, NULL); 440 | size_t len = 0, max = 0; 441 | char *buf; 442 | 443 | max = JSStringGetMaximumUTF8CStringSize(str); 444 | buf = alloca(max); 445 | len = JSStringGetUTF8CString(str, buf, max); 446 | 447 | JSStringRelease(str); 448 | rb_raise(cJavascriptError, "%s", buf); 449 | //free(buf); // Will this ever be called? 450 | } 451 | 452 | return output; 453 | } 454 | 455 | 456 | -------------------------------------------------------------------------------- /ext/webkit/webkit.c: -------------------------------------------------------------------------------- 1 | #pragma GCC diagnostic ignored "-Wunused-but-set-variable" 2 | /* Includes */ 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include "dlfcn.h" 8 | #include "errno.h" 9 | #include "ffi.h" 10 | #include "rbgobject.h" 11 | #include "sys/mman.h" 12 | #include "intern.h" 13 | #include "webkit/webkit.h" 14 | #include "webkit/webkitenumtypes.h" 15 | #include "JavaScriptCore/JavaScript.h" 16 | 17 | /* Setup types */ 18 | /* Try not to clash with other definitions of bool... */ 19 | typedef int rubber_bool; 20 | #define bool rubber_bool 21 | 22 | /* Prototypes */ 23 | #include "rbglib.h" 24 | 25 | #include "rbgtk.h" 26 | 27 | #if defined(G_PLATFORM_WIN32) && !defined(RUBY_GTK2_STATIC_COMPILATION) 28 | # ifdef RUBY_GTK2_COMPILATION 29 | # define RUBY_GTK2_VAR __declspec(dllexport) 30 | # else 31 | # define RUBY_GTK2_VAR extern __declspec(dllimport) 32 | # endif 33 | #else 34 | # define RUBY_GTK2_VAR extern 35 | #endif 36 | 37 | RUBY_GTK2_VAR VALUE mGtk; 38 | RUBY_GTK2_VAR VALUE mGdk; 39 | 40 | #define RBGTK_INITIALIZE(obj,gtkobj) (rbgtk_initialize_gtkobject(obj, GTK_OBJECT(gtkobj))) 41 | static VALUE mWebKit; 42 | static VALUE 43 | WebKit_CLASS_set_web_database_path(VALUE self, VALUE __v_path); 44 | static VALUE 45 | WebKit_CLASS_remove_all_web_databases(VALUE self); 46 | static VALUE 47 | WebKit_CLASS_set_default_web_database_quota(VALUE self, VALUE __v_quota); 48 | static VALUE cJsPtr; 49 | static VALUE cJavascriptError; 50 | static VALUE cWebSettings; 51 | static VALUE 52 | WebSettings_initialize(VALUE self); 53 | static VALUE cWebPolicyDecision; 54 | static VALUE 55 | WebPolicyDecision_download(VALUE self); 56 | static VALUE 57 | WebPolicyDecision_use(VALUE self); 58 | static VALUE 59 | WebPolicyDecision_ignore(VALUE self); 60 | static VALUE cWebFrame; 61 | static VALUE 62 | WebFrame_exec_js(VALUE self, VALUE __v_js); 63 | static VALUE 64 | WebFrame_add_ruby_class(VALUE self, VALUE __v_name, VALUE klass); 65 | static VALUE 66 | WebFrame_add_ruby_eval(VALUE self); 67 | static VALUE 68 | WebFrame_add_js_api(VALUE self, VALUE __v_name); 69 | static VALUE 70 | WebFrame_load_string(VALUE self, VALUE __v_content, VALUE __v_mime_type, VALUE __v_encoding, VALUE __v_base_uri); 71 | static VALUE cWebView; 72 | static VALUE 73 | WebView_initialize(VALUE self); 74 | static VALUE 75 | WebView_open(VALUE self, VALUE __v_uri); 76 | static VALUE 77 | WebView_execute_script(VALUE self, VALUE __v_script); 78 | static VALUE 79 | WebView_set_settings(VALUE self, VALUE __v_settings); 80 | static VALUE 81 | WebView_load_string(VALUE self, VALUE __v_content, VALUE __v_mime_type, VALUE __v_encoding, VALUE __v_base_uri); 82 | static VALUE 83 | WebView_load_uri(VALUE self, VALUE __v_uri); 84 | static VALUE 85 | WebView_main_frame(VALUE self); 86 | static VALUE 87 | WebView_focused_frame(VALUE self); 88 | static VALUE 89 | WebView_progress(VALUE self); 90 | static VALUE 91 | WebView_title(VALUE self); 92 | static VALUE 93 | WebView_uri(VALUE self); 94 | static VALUE 95 | WebView_reload(VALUE self); 96 | static VALUE 97 | WebView_reload_bypass_cache(VALUE self); 98 | static VALUE 99 | WebView_set_custom_encoding(VALUE self, VALUE __v_encoding); 100 | static VALUE 101 | WebView_stop_loading(VALUE self); 102 | static VALUE 103 | WebView_has_selection_query(VALUE self); 104 | static VALUE 105 | WebView_inspector(VALUE self); 106 | static VALUE cWebInspector; 107 | static VALUE 108 | WebInspector_inspect_coordinates(VALUE self, VALUE __v_x, VALUE __v_y); 109 | static VALUE 110 | WebInspector_uri(VALUE self); 111 | static VALUE 112 | WebInspector_show(VALUE self); 113 | static VALUE 114 | WebInspector_close(VALUE self); 115 | static VALUE 116 | WebInspector_view(VALUE self); 117 | static VALUE cWebResource; 118 | static VALUE 119 | WebResource_encoding(VALUE self); 120 | static VALUE 121 | WebResource_frame_name(VALUE self); 122 | static VALUE 123 | WebResource_mime_type(VALUE self); 124 | static VALUE 125 | WebResource_uri(VALUE self); 126 | static VALUE 127 | WebResource_data(VALUE self); 128 | static VALUE 129 | WebResource_data_equals(VALUE self, VALUE data); 130 | static VALUE cWebNetworkRequest; 131 | static VALUE 132 | WebNetworkRequest_uri(VALUE self); 133 | static VALUE 134 | WebNetworkRequest_uri_equals(VALUE self, VALUE __v_uri); 135 | static VALUE 136 | WebNetworkRequest_message(VALUE self); 137 | static VALUE cWebNetworkResponse; 138 | static VALUE 139 | WebNetworkResponse_uri(VALUE self); 140 | static VALUE 141 | WebNetworkResponse_uri_equals(VALUE self, VALUE __v_uri); 142 | static VALUE 143 | WebNetworkResponse_message(VALUE self); 144 | static VALUE cDownload; 145 | static VALUE 146 | Download_initialize(VALUE self, VALUE __v_request); 147 | static VALUE 148 | Download_start(VALUE self); 149 | static VALUE 150 | Download_cancel(VALUE self); 151 | static VALUE 152 | Download_progress(VALUE self); 153 | static VALUE 154 | Download_current_size(VALUE self); 155 | static VALUE 156 | Download_total_size(VALUE self); 157 | static VALUE 158 | Download_uri(VALUE self); 159 | static VALUE 160 | Download_suggested_filename(VALUE self); 161 | VALUE genumTargetInfo = Qnil; 162 | VALUE genumDownloadStatus = Qnil; 163 | VALUE genumDownloadError = Qnil; 164 | VALUE genumNetworkError = Qnil; 165 | VALUE genumPolicyError = Qnil; 166 | VALUE genumPluginError = Qnil; 167 | VALUE genumCacheModel = Qnil; 168 | VALUE genumLoadStatus = Qnil; 169 | VALUE genumNavigationReason = Qnil; 170 | VALUE genumHitTestResultContext = Qnil; 171 | VALUE genumEditingBehavior = Qnil; 172 | VALUE genumNavigationResponse = Qnil; 173 | static VALUE _gcpool_RubyFunc = Qnil; 174 | static void __gcpool_RubyFunc_add(VALUE val); 175 | static void __gcpool_RubyFunc_del(VALUE val); 176 | #define RUBYFUNC_ADD(val) __gcpool_RubyFunc_add(val) 177 | #define RUBYFUNC_DEL(val) __gcpool_RubyFunc_del(val) 178 | 179 | /* Inline C code */ 180 | 181 | #include 182 | #include 183 | #include "javascript.h" 184 | 185 | static inline VALUE strOrNil(const char *str) { 186 | if (str) { 187 | return rb_str_new2(str); 188 | } else { 189 | return Qnil; 190 | } 191 | } 192 | 193 | 194 | /* Code */ 195 | static VALUE 196 | WebKit_CLASS_set_web_database_path(VALUE self, VALUE __v_path) 197 | { 198 | char * path; char * __orig_path; 199 | __orig_path = path = ( NIL_P(__v_path) ? NULL : StringValuePtr(__v_path) ); 200 | 201 | #line 46 "/home/geoff/Projects/gtk-webkit-ruby/ext/webkit/webkit.cr" 202 | webkit_set_web_database_directory_path(path); 203 | 204 | return self; 205 | } 206 | 207 | static VALUE 208 | WebKit_CLASS_remove_all_web_databases(VALUE self) 209 | { 210 | 211 | #line 49 "/home/geoff/Projects/gtk-webkit-ruby/ext/webkit/webkit.cr" 212 | webkit_remove_all_web_databases(); 213 | 214 | return Qnil; 215 | } 216 | 217 | static VALUE 218 | WebKit_CLASS_set_default_web_database_quota(VALUE self, VALUE __v_quota) 219 | { 220 | guint64 quota; guint64 __orig_quota; 221 | __orig_quota = quota = rb_num2ull(__v_quota); 222 | 223 | #line 52 "/home/geoff/Projects/gtk-webkit-ruby/ext/webkit/webkit.cr" 224 | webkit_set_default_web_database_quota(quota); 225 | 226 | return self; 227 | } 228 | 229 | static VALUE 230 | WebSettings_initialize(VALUE self) 231 | { 232 | 233 | #line 58 "/home/geoff/Projects/gtk-webkit-ruby/ext/webkit/webkit.cr" 234 | G_INITIALIZE(self, webkit_web_settings_new()); 235 | 236 | return Qnil; 237 | } 238 | 239 | static VALUE 240 | WebPolicyDecision_download(VALUE self) 241 | { 242 | WebKitWebPolicyDecision *_self = ((WebKitWebPolicyDecision*)RVAL2GOBJ(self)); 243 | 244 | #line 65 "/home/geoff/Projects/gtk-webkit-ruby/ext/webkit/webkit.cr" 245 | webkit_web_policy_decision_download(_self); 246 | 247 | return Qnil; 248 | } 249 | 250 | static VALUE 251 | WebPolicyDecision_use(VALUE self) 252 | { 253 | WebKitWebPolicyDecision *_self = ((WebKitWebPolicyDecision*)RVAL2GOBJ(self)); 254 | 255 | #line 68 "/home/geoff/Projects/gtk-webkit-ruby/ext/webkit/webkit.cr" 256 | webkit_web_policy_decision_use(_self); 257 | 258 | return Qnil; 259 | } 260 | 261 | static VALUE 262 | WebPolicyDecision_ignore(VALUE self) 263 | { 264 | WebKitWebPolicyDecision *_self = ((WebKitWebPolicyDecision*)RVAL2GOBJ(self)); 265 | 266 | #line 71 "/home/geoff/Projects/gtk-webkit-ruby/ext/webkit/webkit.cr" 267 | webkit_web_policy_decision_ignore(_self); 268 | 269 | return Qnil; 270 | } 271 | 272 | static VALUE 273 | WebFrame_exec_js(VALUE self, VALUE __v_js) 274 | { 275 | VALUE __p_retval = Qnil; 276 | char * js; char * __orig_js; 277 | WebKitWebFrame *_self = ((WebKitWebFrame*)RVAL2GOBJ(self)); 278 | __orig_js = js = ( NIL_P(__v_js) ? NULL : StringValuePtr(__v_js) ); 279 | 280 | #line 78 "/home/geoff/Projects/gtk-webkit-ruby/ext/webkit/webkit.cr" 281 | do { __p_retval = javascript_exec(webkit_web_frame_get_global_context(_self), js); goto out; } while(0); 282 | out: 283 | return __p_retval; 284 | } 285 | 286 | static VALUE 287 | WebFrame_add_ruby_class(VALUE self, VALUE __v_name, VALUE klass) 288 | { 289 | char * name; char * __orig_name; 290 | WebKitWebFrame *_self = ((WebKitWebFrame*)RVAL2GOBJ(self)); 291 | __orig_name = name = ( NIL_P(__v_name) ? NULL : StringValuePtr(__v_name) ); 292 | if (! ((TYPE(klass) == T_CLASS) || (TYPE(klass) == T_MODULE)) ) 293 | rb_raise(rb_eArgError, "klass argument must be one of Class, Module"); 294 | 295 | #line 81 "/home/geoff/Projects/gtk-webkit-ruby/ext/webkit/webkit.cr" 296 | javascript_add_class(webkit_web_frame_get_global_context(_self), name, klass); 297 | 298 | return Qnil; 299 | } 300 | 301 | static VALUE 302 | WebFrame_add_ruby_eval(VALUE self) 303 | { 304 | WebKitWebFrame *_self = ((WebKitWebFrame*)RVAL2GOBJ(self)); 305 | 306 | #line 84 "/home/geoff/Projects/gtk-webkit-ruby/ext/webkit/webkit.cr" 307 | javascript_add_ruby_eval(webkit_web_frame_get_global_context(_self)); 308 | 309 | return Qnil; 310 | } 311 | 312 | static VALUE 313 | WebFrame_add_js_api(VALUE self, VALUE __v_name) 314 | { 315 | char * name; char * __orig_name; 316 | WebKitWebFrame *_self = ((WebKitWebFrame*)RVAL2GOBJ(self)); 317 | __orig_name = name = ( NIL_P(__v_name) ? NULL : StringValuePtr(__v_name) ); 318 | VALUE block = rb_block_proc(); 319 | 320 | #line 87 "/home/geoff/Projects/gtk-webkit-ruby/ext/webkit/webkit.cr" 321 | javascript_add_ruby_fn(webkit_web_frame_get_global_context(_self), name, block); 322 | 323 | return Qnil; 324 | } 325 | 326 | static VALUE 327 | WebFrame_load_string(VALUE self, VALUE __v_content, VALUE __v_mime_type, VALUE __v_encoding, VALUE __v_base_uri) 328 | { 329 | char * content; char * __orig_content; 330 | char * mime_type; char * __orig_mime_type; 331 | char * encoding; char * __orig_encoding; 332 | char * base_uri; char * __orig_base_uri; 333 | WebKitWebFrame *_self = ((WebKitWebFrame*)RVAL2GOBJ(self)); 334 | __orig_content = content = ( NIL_P(__v_content) ? NULL : StringValuePtr(__v_content) ); 335 | __orig_mime_type = mime_type = ( NIL_P(__v_mime_type) ? NULL : StringValuePtr(__v_mime_type) ); 336 | __orig_encoding = encoding = ( NIL_P(__v_encoding) ? NULL : StringValuePtr(__v_encoding) ); 337 | __orig_base_uri = base_uri = ( NIL_P(__v_base_uri) ? NULL : StringValuePtr(__v_base_uri) ); 338 | 339 | #line 90 "/home/geoff/Projects/gtk-webkit-ruby/ext/webkit/webkit.cr" 340 | webkit_web_frame_load_string(_self, content, mime_type, encoding, base_uri); 341 | 342 | return Qnil; 343 | } 344 | 345 | static VALUE 346 | WebView_initialize(VALUE self) 347 | { 348 | 349 | #line 97 "/home/geoff/Projects/gtk-webkit-ruby/ext/webkit/webkit.cr" 350 | RBGTK_INITIALIZE(self, webkit_web_view_new()); 351 | 352 | return Qnil; 353 | } 354 | 355 | static VALUE 356 | WebView_open(VALUE self, VALUE __v_uri) 357 | { 358 | char * uri; char * __orig_uri; 359 | WebKitWebView *_self = ((WebKitWebView*)RVAL2GOBJ(self)); 360 | __orig_uri = uri = ( NIL_P(__v_uri) ? NULL : StringValuePtr(__v_uri) ); 361 | 362 | #line 100 "/home/geoff/Projects/gtk-webkit-ruby/ext/webkit/webkit.cr" 363 | webkit_web_view_open(_self, uri); 364 | 365 | return Qnil; 366 | } 367 | 368 | static VALUE 369 | WebView_execute_script(VALUE self, VALUE __v_script) 370 | { 371 | char * script; char * __orig_script; 372 | WebKitWebView *_self = ((WebKitWebView*)RVAL2GOBJ(self)); 373 | __orig_script = script = ( NIL_P(__v_script) ? NULL : StringValuePtr(__v_script) ); 374 | 375 | #line 103 "/home/geoff/Projects/gtk-webkit-ruby/ext/webkit/webkit.cr" 376 | webkit_web_view_execute_script(_self, script); 377 | 378 | return Qnil; 379 | } 380 | 381 | static VALUE 382 | WebView_set_settings(VALUE self, VALUE __v_settings) 383 | { 384 | WebKitWebSettings * settings; WebKitWebSettings * __orig_settings; 385 | WebKitWebView *_self = ((WebKitWebView*)RVAL2GOBJ(self)); 386 | __orig_settings = settings = RVAL2GOBJ(__v_settings); 387 | 388 | #line 106 "/home/geoff/Projects/gtk-webkit-ruby/ext/webkit/webkit.cr" 389 | webkit_web_view_set_settings(_self, settings); 390 | 391 | return self; 392 | } 393 | 394 | static VALUE 395 | WebView_load_string(VALUE self, VALUE __v_content, VALUE __v_mime_type, VALUE __v_encoding, VALUE __v_base_uri) 396 | { 397 | char * content; char * __orig_content; 398 | char * mime_type; char * __orig_mime_type; 399 | char * encoding; char * __orig_encoding; 400 | char * base_uri; char * __orig_base_uri; 401 | WebKitWebView *_self = ((WebKitWebView*)RVAL2GOBJ(self)); 402 | __orig_content = content = ( NIL_P(__v_content) ? NULL : StringValuePtr(__v_content) ); 403 | __orig_mime_type = mime_type = ( NIL_P(__v_mime_type) ? NULL : StringValuePtr(__v_mime_type) ); 404 | __orig_encoding = encoding = ( NIL_P(__v_encoding) ? NULL : StringValuePtr(__v_encoding) ); 405 | __orig_base_uri = base_uri = ( NIL_P(__v_base_uri) ? NULL : StringValuePtr(__v_base_uri) ); 406 | 407 | #line 109 "/home/geoff/Projects/gtk-webkit-ruby/ext/webkit/webkit.cr" 408 | webkit_web_view_load_string(_self, content, mime_type, encoding, base_uri); 409 | 410 | return Qnil; 411 | } 412 | 413 | static VALUE 414 | WebView_load_uri(VALUE self, VALUE __v_uri) 415 | { 416 | char * uri; char * __orig_uri; 417 | WebKitWebView *_self = ((WebKitWebView*)RVAL2GOBJ(self)); 418 | __orig_uri = uri = ( NIL_P(__v_uri) ? NULL : StringValuePtr(__v_uri) ); 419 | 420 | #line 112 "/home/geoff/Projects/gtk-webkit-ruby/ext/webkit/webkit.cr" 421 | webkit_web_view_load_uri(_self, uri); 422 | 423 | return Qnil; 424 | } 425 | 426 | static VALUE 427 | WebView_main_frame(VALUE self) 428 | { 429 | VALUE __p_retval = Qnil; 430 | WebKitWebView *_self = ((WebKitWebView*)RVAL2GOBJ(self)); 431 | 432 | #line 115 "/home/geoff/Projects/gtk-webkit-ruby/ext/webkit/webkit.cr" 433 | do { __p_retval = GOBJ2RVAL(webkit_web_view_get_main_frame(_self)); goto out; } while(0); 434 | out: 435 | return __p_retval; 436 | } 437 | 438 | static VALUE 439 | WebView_focused_frame(VALUE self) 440 | { 441 | VALUE __p_retval = Qnil; 442 | WebKitWebView *_self = ((WebKitWebView*)RVAL2GOBJ(self)); 443 | 444 | #line 118 "/home/geoff/Projects/gtk-webkit-ruby/ext/webkit/webkit.cr" 445 | do { __p_retval = GOBJ2RVAL(webkit_web_view_get_focused_frame(_self)); goto out; } while(0); 446 | out: 447 | return __p_retval; 448 | } 449 | 450 | static VALUE 451 | WebView_progress(VALUE self) 452 | { 453 | VALUE __p_retval = Qnil; 454 | WebKitWebView *_self = ((WebKitWebView*)RVAL2GOBJ(self)); 455 | 456 | #line 121 "/home/geoff/Projects/gtk-webkit-ruby/ext/webkit/webkit.cr" 457 | do { __p_retval = rb_float_new(webkit_web_view_get_progress(_self)); goto out; } while(0); 458 | out: 459 | return __p_retval; 460 | } 461 | 462 | static VALUE 463 | WebView_title(VALUE self) 464 | { 465 | VALUE __p_retval = Qnil; 466 | WebKitWebView *_self = ((WebKitWebView*)RVAL2GOBJ(self)); 467 | 468 | #line 124 "/home/geoff/Projects/gtk-webkit-ruby/ext/webkit/webkit.cr" 469 | do { __p_retval = strOrNil(webkit_web_view_get_title(_self)); goto out; } while(0); 470 | out: 471 | return __p_retval; 472 | } 473 | 474 | static VALUE 475 | WebView_uri(VALUE self) 476 | { 477 | VALUE __p_retval = Qnil; 478 | WebKitWebView *_self = ((WebKitWebView*)RVAL2GOBJ(self)); 479 | 480 | #line 127 "/home/geoff/Projects/gtk-webkit-ruby/ext/webkit/webkit.cr" 481 | do { __p_retval = strOrNil(webkit_web_view_get_uri(_self)); goto out; } while(0); 482 | out: 483 | return __p_retval; 484 | } 485 | 486 | static VALUE 487 | WebView_reload(VALUE self) 488 | { 489 | WebKitWebView *_self = ((WebKitWebView*)RVAL2GOBJ(self)); 490 | 491 | #line 130 "/home/geoff/Projects/gtk-webkit-ruby/ext/webkit/webkit.cr" 492 | webkit_web_view_reload(_self); 493 | 494 | return Qnil; 495 | } 496 | 497 | static VALUE 498 | WebView_reload_bypass_cache(VALUE self) 499 | { 500 | WebKitWebView *_self = ((WebKitWebView*)RVAL2GOBJ(self)); 501 | 502 | #line 133 "/home/geoff/Projects/gtk-webkit-ruby/ext/webkit/webkit.cr" 503 | webkit_web_view_reload_bypass_cache(_self); 504 | 505 | return Qnil; 506 | } 507 | 508 | static VALUE 509 | WebView_set_custom_encoding(VALUE self, VALUE __v_encoding) 510 | { 511 | char * encoding; char * __orig_encoding; 512 | WebKitWebView *_self = ((WebKitWebView*)RVAL2GOBJ(self)); 513 | __orig_encoding = encoding = ( NIL_P(__v_encoding) ? NULL : StringValuePtr(__v_encoding) ); 514 | 515 | #line 136 "/home/geoff/Projects/gtk-webkit-ruby/ext/webkit/webkit.cr" 516 | webkit_web_view_set_custom_encoding(_self, encoding); 517 | 518 | return self; 519 | } 520 | 521 | static VALUE 522 | WebView_stop_loading(VALUE self) 523 | { 524 | WebKitWebView *_self = ((WebKitWebView*)RVAL2GOBJ(self)); 525 | 526 | #line 139 "/home/geoff/Projects/gtk-webkit-ruby/ext/webkit/webkit.cr" 527 | webkit_web_view_stop_loading(_self); 528 | 529 | return Qnil; 530 | } 531 | 532 | static VALUE 533 | WebView_has_selection_query(VALUE self) 534 | { 535 | VALUE __p_retval = Qnil; 536 | WebKitWebView *_self = ((WebKitWebView*)RVAL2GOBJ(self)); 537 | 538 | #line 142 "/home/geoff/Projects/gtk-webkit-ruby/ext/webkit/webkit.cr" 539 | do { __p_retval = ((webkit_web_view_has_selection(_self)) ? Qtrue : Qfalse); goto out; } while(0); 540 | out: 541 | return __p_retval; 542 | } 543 | 544 | static VALUE 545 | WebView_inspector(VALUE self) 546 | { 547 | VALUE __p_retval = Qnil; 548 | WebKitWebView *_self = ((WebKitWebView*)RVAL2GOBJ(self)); 549 | 550 | #line 145 "/home/geoff/Projects/gtk-webkit-ruby/ext/webkit/webkit.cr" 551 | do { __p_retval = GOBJ2RVAL(webkit_web_view_get_inspector(_self)); goto out; } while(0); 552 | out: 553 | return __p_retval; 554 | } 555 | 556 | static VALUE 557 | WebInspector_inspect_coordinates(VALUE self, VALUE __v_x, VALUE __v_y) 558 | { 559 | double x; double __orig_x; 560 | double y; double __orig_y; 561 | WebKitWebInspector *_self = ((WebKitWebInspector*)RVAL2GOBJ(self)); 562 | __orig_x = x = NUM2DBL(__v_x); 563 | __orig_y = y = NUM2DBL(__v_y); 564 | 565 | #line 152 "/home/geoff/Projects/gtk-webkit-ruby/ext/webkit/webkit.cr" 566 | webkit_web_inspector_inspect_coordinates(_self, x, y); 567 | 568 | return Qnil; 569 | } 570 | 571 | static VALUE 572 | WebInspector_uri(VALUE self) 573 | { 574 | VALUE __p_retval = Qnil; 575 | WebKitWebInspector *_self = ((WebKitWebInspector*)RVAL2GOBJ(self)); 576 | 577 | #line 155 "/home/geoff/Projects/gtk-webkit-ruby/ext/webkit/webkit.cr" 578 | do { __p_retval = strOrNil(webkit_web_inspector_get_inspected_uri(_self)); goto out; } while(0); 579 | out: 580 | return __p_retval; 581 | } 582 | 583 | static VALUE 584 | WebInspector_show(VALUE self) 585 | { 586 | WebKitWebInspector *_self = ((WebKitWebInspector*)RVAL2GOBJ(self)); 587 | 588 | #line 158 "/home/geoff/Projects/gtk-webkit-ruby/ext/webkit/webkit.cr" 589 | webkit_web_inspector_show(_self); 590 | 591 | return Qnil; 592 | } 593 | 594 | static VALUE 595 | WebInspector_close(VALUE self) 596 | { 597 | WebKitWebInspector *_self = ((WebKitWebInspector*)RVAL2GOBJ(self)); 598 | 599 | #line 161 "/home/geoff/Projects/gtk-webkit-ruby/ext/webkit/webkit.cr" 600 | webkit_web_inspector_close(_self); 601 | 602 | return Qnil; 603 | } 604 | 605 | static VALUE 606 | WebInspector_view(VALUE self) 607 | { 608 | VALUE __p_retval = Qnil; 609 | WebKitWebInspector *_self = ((WebKitWebInspector*)RVAL2GOBJ(self)); 610 | 611 | #line 164 "/home/geoff/Projects/gtk-webkit-ruby/ext/webkit/webkit.cr" 612 | do { __p_retval = GOBJ2RVAL(webkit_web_inspector_get_web_view(_self)); goto out; } while(0); 613 | out: 614 | return __p_retval; 615 | } 616 | 617 | static VALUE 618 | WebResource_encoding(VALUE self) 619 | { 620 | VALUE __p_retval = Qnil; 621 | WebKitWebResource *_self = ((WebKitWebResource*)RVAL2GOBJ(self)); 622 | 623 | #line 171 "/home/geoff/Projects/gtk-webkit-ruby/ext/webkit/webkit.cr" 624 | do { __p_retval = strOrNil(webkit_web_resource_get_encoding(_self)); goto out; } while(0); 625 | out: 626 | return __p_retval; 627 | } 628 | 629 | static VALUE 630 | WebResource_frame_name(VALUE self) 631 | { 632 | VALUE __p_retval = Qnil; 633 | WebKitWebResource *_self = ((WebKitWebResource*)RVAL2GOBJ(self)); 634 | 635 | #line 174 "/home/geoff/Projects/gtk-webkit-ruby/ext/webkit/webkit.cr" 636 | do { __p_retval = strOrNil(webkit_web_resource_get_frame_name(_self)); goto out; } while(0); 637 | out: 638 | return __p_retval; 639 | } 640 | 641 | static VALUE 642 | WebResource_mime_type(VALUE self) 643 | { 644 | VALUE __p_retval = Qnil; 645 | WebKitWebResource *_self = ((WebKitWebResource*)RVAL2GOBJ(self)); 646 | 647 | #line 177 "/home/geoff/Projects/gtk-webkit-ruby/ext/webkit/webkit.cr" 648 | do { __p_retval = strOrNil(webkit_web_resource_get_mime_type(_self)); goto out; } while(0); 649 | out: 650 | return __p_retval; 651 | } 652 | 653 | static VALUE 654 | WebResource_uri(VALUE self) 655 | { 656 | VALUE __p_retval = Qnil; 657 | WebKitWebResource *_self = ((WebKitWebResource*)RVAL2GOBJ(self)); 658 | 659 | #line 180 "/home/geoff/Projects/gtk-webkit-ruby/ext/webkit/webkit.cr" 660 | do { __p_retval = strOrNil(webkit_web_resource_get_uri(_self)); goto out; } while(0); 661 | out: 662 | return __p_retval; 663 | } 664 | 665 | static VALUE 666 | WebResource_data(VALUE self) 667 | { 668 | VALUE __p_retval = Qnil; 669 | WebKitWebResource *_self = ((WebKitWebResource*)RVAL2GOBJ(self)); 670 | 671 | #line 183 "/home/geoff/Projects/gtk-webkit-ruby/ext/webkit/webkit.cr" 672 | 673 | do { 674 | GString * data = 675 | webkit_web_resource_get_data(_self); 676 | do { __p_retval = rb_str_new(data->str, data->len); goto out; } while(0); 677 | 678 | } while(0); 679 | 680 | out: 681 | return __p_retval; 682 | } 683 | 684 | static VALUE 685 | WebResource_data_equals(VALUE self, VALUE data) 686 | { 687 | VALUE __p_retval = data; 688 | WebKitWebResource *_self = ((WebKitWebResource*)RVAL2GOBJ(self)); 689 | Check_Type(data, T_STRING); 690 | 691 | #line 187 "/home/geoff/Projects/gtk-webkit-ruby/ext/webkit/webkit.cr" 692 | 693 | do { 694 | GString * odata = 695 | webkit_web_resource_get_data(_self); 696 | g_free(odata->str); 697 | odata->str = g_malloc(RSTRING_LEN(data)+1); 698 | odata->len = odata->allocated_len = RSTRING_LEN(data); 699 | memcpy(RSTRING_PTR(data), odata->str, RSTRING_LEN(data)); 700 | do { __p_retval = data; goto out; } while(0); 701 | 702 | } while(0); 703 | 704 | out: 705 | return __p_retval; 706 | } 707 | 708 | static VALUE 709 | WebNetworkRequest_uri(VALUE self) 710 | { 711 | VALUE __p_retval = Qnil; 712 | WebKitNetworkRequest *_self = ((WebKitNetworkRequest*)RVAL2GOBJ(self)); 713 | 714 | #line 199 "/home/geoff/Projects/gtk-webkit-ruby/ext/webkit/webkit.cr" 715 | do { __p_retval = strOrNil(webkit_network_request_get_uri(_self)); goto out; } while(0); 716 | out: 717 | return __p_retval; 718 | } 719 | 720 | static VALUE 721 | WebNetworkRequest_uri_equals(VALUE self, VALUE __v_uri) 722 | { 723 | char * uri; char * __orig_uri; 724 | WebKitNetworkRequest *_self = ((WebKitNetworkRequest*)RVAL2GOBJ(self)); 725 | __orig_uri = uri = ( NIL_P(__v_uri) ? NULL : StringValuePtr(__v_uri) ); 726 | 727 | #line 202 "/home/geoff/Projects/gtk-webkit-ruby/ext/webkit/webkit.cr" 728 | webkit_network_request_set_uri(_self, uri); 729 | 730 | return __v_uri; 731 | } 732 | 733 | static VALUE 734 | WebNetworkRequest_message(VALUE self) 735 | { 736 | VALUE __p_retval = Qnil; 737 | WebKitNetworkRequest *_self = ((WebKitNetworkRequest*)RVAL2GOBJ(self)); 738 | 739 | #line 205 "/home/geoff/Projects/gtk-webkit-ruby/ext/webkit/webkit.cr" 740 | do { __p_retval = GOBJ2RVAL(SOUP_MESSAGE(webkit_network_request_get_message(_self))); goto out; } while(0); 741 | out: 742 | return __p_retval; 743 | } 744 | 745 | static VALUE 746 | WebNetworkResponse_uri(VALUE self) 747 | { 748 | VALUE __p_retval = Qnil; 749 | WebKitNetworkResponse *_self = ((WebKitNetworkResponse*)RVAL2GOBJ(self)); 750 | 751 | #line 212 "/home/geoff/Projects/gtk-webkit-ruby/ext/webkit/webkit.cr" 752 | do { __p_retval = strOrNil(webkit_network_response_get_uri(_self)); goto out; } while(0); 753 | out: 754 | return __p_retval; 755 | } 756 | 757 | static VALUE 758 | WebNetworkResponse_uri_equals(VALUE self, VALUE __v_uri) 759 | { 760 | char * uri; char * __orig_uri; 761 | WebKitNetworkResponse *_self = ((WebKitNetworkResponse*)RVAL2GOBJ(self)); 762 | __orig_uri = uri = ( NIL_P(__v_uri) ? NULL : StringValuePtr(__v_uri) ); 763 | 764 | #line 215 "/home/geoff/Projects/gtk-webkit-ruby/ext/webkit/webkit.cr" 765 | webkit_network_response_set_uri(_self, uri); 766 | 767 | return __v_uri; 768 | } 769 | 770 | static VALUE 771 | WebNetworkResponse_message(VALUE self) 772 | { 773 | VALUE __p_retval = Qnil; 774 | WebKitNetworkResponse *_self = ((WebKitNetworkResponse*)RVAL2GOBJ(self)); 775 | 776 | #line 218 "/home/geoff/Projects/gtk-webkit-ruby/ext/webkit/webkit.cr" 777 | do { __p_retval = GOBJ2RVAL(SOUP_MESSAGE(webkit_network_response_get_message(_self))); goto out; } while(0); 778 | out: 779 | return __p_retval; 780 | } 781 | 782 | static VALUE 783 | Download_initialize(VALUE self, VALUE __v_request) 784 | { 785 | WebKitNetworkRequest * request; WebKitNetworkRequest * __orig_request; 786 | __orig_request = request = RVAL2GOBJ(__v_request); 787 | 788 | #line 225 "/home/geoff/Projects/gtk-webkit-ruby/ext/webkit/webkit.cr" 789 | RBGTK_INITIALIZE(self, webkit_download_new(request)); 790 | 791 | return Qnil; 792 | } 793 | 794 | static VALUE 795 | Download_start(VALUE self) 796 | { 797 | WebKitDownload *_self = ((WebKitDownload*)RVAL2GOBJ(self)); 798 | 799 | #line 228 "/home/geoff/Projects/gtk-webkit-ruby/ext/webkit/webkit.cr" 800 | webkit_download_start(_self); 801 | 802 | return Qnil; 803 | } 804 | 805 | static VALUE 806 | Download_cancel(VALUE self) 807 | { 808 | WebKitDownload *_self = ((WebKitDownload*)RVAL2GOBJ(self)); 809 | 810 | #line 231 "/home/geoff/Projects/gtk-webkit-ruby/ext/webkit/webkit.cr" 811 | webkit_download_cancel(_self); 812 | 813 | return Qnil; 814 | } 815 | 816 | static VALUE 817 | Download_progress(VALUE self) 818 | { 819 | VALUE __p_retval = Qnil; 820 | WebKitDownload *_self = ((WebKitDownload*)RVAL2GOBJ(self)); 821 | 822 | #line 234 "/home/geoff/Projects/gtk-webkit-ruby/ext/webkit/webkit.cr" 823 | do { __p_retval = rb_float_new(webkit_download_get_progress(_self)); goto out; } while(0); 824 | out: 825 | return __p_retval; 826 | } 827 | 828 | static VALUE 829 | Download_current_size(VALUE self) 830 | { 831 | VALUE __p_retval = Qnil; 832 | WebKitDownload *_self = ((WebKitDownload*)RVAL2GOBJ(self)); 833 | 834 | #line 237 "/home/geoff/Projects/gtk-webkit-ruby/ext/webkit/webkit.cr" 835 | do { __p_retval = rb_ull2inum(webkit_download_get_current_size(_self)); goto out; } while(0); 836 | out: 837 | return __p_retval; 838 | } 839 | 840 | static VALUE 841 | Download_total_size(VALUE self) 842 | { 843 | VALUE __p_retval = Qnil; 844 | WebKitDownload *_self = ((WebKitDownload*)RVAL2GOBJ(self)); 845 | 846 | #line 240 "/home/geoff/Projects/gtk-webkit-ruby/ext/webkit/webkit.cr" 847 | do { __p_retval = rb_ull2inum(webkit_download_get_total_size(_self)); goto out; } while(0); 848 | out: 849 | return __p_retval; 850 | } 851 | 852 | static VALUE 853 | Download_uri(VALUE self) 854 | { 855 | VALUE __p_retval = Qnil; 856 | WebKitDownload *_self = ((WebKitDownload*)RVAL2GOBJ(self)); 857 | 858 | #line 243 "/home/geoff/Projects/gtk-webkit-ruby/ext/webkit/webkit.cr" 859 | do { __p_retval = rb_str_new2(webkit_download_get_uri(_self)); goto out; } while(0); 860 | out: 861 | return __p_retval; 862 | } 863 | 864 | static VALUE 865 | Download_suggested_filename(VALUE self) 866 | { 867 | VALUE __p_retval = Qnil; 868 | WebKitDownload *_self = ((WebKitDownload*)RVAL2GOBJ(self)); 869 | 870 | #line 246 "/home/geoff/Projects/gtk-webkit-ruby/ext/webkit/webkit.cr" 871 | do { __p_retval = rb_str_new2(webkit_download_get_suggested_filename(_self)); goto out; } while(0); 872 | out: 873 | return __p_retval; 874 | } 875 | 876 | static void __gcpool_RubyFunc_add(VALUE val) 877 | { 878 | if (_gcpool_RubyFunc == Qnil) 879 | { 880 | _gcpool_RubyFunc = rb_ary_new3(1, val); 881 | } 882 | else 883 | { 884 | rb_ary_push(_gcpool_RubyFunc, val); 885 | } 886 | } 887 | 888 | static void __gcpool_RubyFunc_del(VALUE val) 889 | { 890 | if (_gcpool_RubyFunc == Qnil) 891 | { 892 | rb_warn("Trying to remove object from empty GC queue RubyFunc"); 893 | return; 894 | } 895 | rb_ary_delete(_gcpool_RubyFunc, val); 896 | // If nothing is referenced, don't keep an empty array in the pool... 897 | if (RARRAY_LEN(_gcpool_RubyFunc) == 0) 898 | _gcpool_RubyFunc = Qnil; 899 | } 900 | 901 | /* Init */ 902 | void 903 | Init_webkit(void) 904 | { 905 | mWebKit = rb_define_module("WebKit"); 906 | rb_define_singleton_method(mWebKit, "set_web_database_path", WebKit_CLASS_set_web_database_path, 1); 907 | rb_define_singleton_method(mWebKit, "remove_all_web_databases", WebKit_CLASS_remove_all_web_databases, 0); 908 | rb_define_singleton_method(mWebKit, "set_default_web_database_quota", WebKit_CLASS_set_default_web_database_quota, 1); 909 | cJsPtr = rb_define_class_under(mWebKit, "JsPtr", rb_cObject); 910 | cJavascriptError = rb_define_class_under(mWebKit, "JavascriptError", rb_eStandardError); 911 | cWebSettings = G_DEF_CLASS(WEBKIT_TYPE_WEB_SETTINGS, "WebSettings", mWebKit); 912 | rb_define_method(cWebSettings, "initialize", WebSettings_initialize, 0); 913 | cWebPolicyDecision = G_DEF_CLASS(WEBKIT_TYPE_WEB_POLICY_DECISION, "WebPolicyDecision", mWebKit); 914 | rb_define_method(cWebPolicyDecision, "download", WebPolicyDecision_download, 0); 915 | rb_define_method(cWebPolicyDecision, "use", WebPolicyDecision_use, 0); 916 | rb_define_method(cWebPolicyDecision, "ignore", WebPolicyDecision_ignore, 0); 917 | cWebFrame = G_DEF_CLASS(WEBKIT_TYPE_WEB_FRAME, "WebFrame", mWebKit); 918 | rb_define_method(cWebFrame, "exec_js", WebFrame_exec_js, 1); 919 | rb_define_method(cWebFrame, "add_ruby_class", WebFrame_add_ruby_class, 2); 920 | rb_define_method(cWebFrame, "add_ruby_eval", WebFrame_add_ruby_eval, 0); 921 | rb_define_method(cWebFrame, "add_js_api", WebFrame_add_js_api, 1); 922 | rb_define_method(cWebFrame, "load_string", WebFrame_load_string, 4); 923 | cWebView = G_DEF_CLASS(WEBKIT_TYPE_WEB_VIEW, "WebView", mWebKit); 924 | rb_define_method(cWebView, "initialize", WebView_initialize, 0); 925 | rb_define_method(cWebView, "open", WebView_open, 1); 926 | rb_define_method(cWebView, "execute_script", WebView_execute_script, 1); 927 | rb_define_method(cWebView, "set_settings", WebView_set_settings, 1); 928 | rb_define_method(cWebView, "load_string", WebView_load_string, 4); 929 | rb_define_method(cWebView, "load_uri", WebView_load_uri, 1); 930 | rb_define_method(cWebView, "main_frame", WebView_main_frame, 0); 931 | rb_define_method(cWebView, "focused_frame", WebView_focused_frame, 0); 932 | rb_define_method(cWebView, "progress", WebView_progress, 0); 933 | rb_define_method(cWebView, "title", WebView_title, 0); 934 | rb_define_method(cWebView, "uri", WebView_uri, 0); 935 | rb_define_method(cWebView, "reload", WebView_reload, 0); 936 | rb_define_method(cWebView, "reload_bypass_cache", WebView_reload_bypass_cache, 0); 937 | rb_define_method(cWebView, "set_custom_encoding", WebView_set_custom_encoding, 1); 938 | rb_define_method(cWebView, "stop_loading", WebView_stop_loading, 0); 939 | rb_define_method(cWebView, "has_selection?", WebView_has_selection_query, 0); 940 | rb_define_method(cWebView, "inspector", WebView_inspector, 0); 941 | cWebInspector = G_DEF_CLASS(WEBKIT_TYPE_WEB_INSPECTOR, "WebInspector", mWebKit); 942 | rb_define_method(cWebInspector, "inspect_coordinates", WebInspector_inspect_coordinates, 2); 943 | rb_define_method(cWebInspector, "uri", WebInspector_uri, 0); 944 | rb_define_method(cWebInspector, "show", WebInspector_show, 0); 945 | rb_define_method(cWebInspector, "close", WebInspector_close, 0); 946 | rb_define_method(cWebInspector, "view", WebInspector_view, 0); 947 | cWebResource = G_DEF_CLASS(WEBKIT_TYPE_WEB_RESOURCE, "WebResource", mWebKit); 948 | rb_define_method(cWebResource, "encoding", WebResource_encoding, 0); 949 | rb_define_method(cWebResource, "frame_name", WebResource_frame_name, 0); 950 | rb_define_method(cWebResource, "mime_type", WebResource_mime_type, 0); 951 | rb_define_method(cWebResource, "uri", WebResource_uri, 0); 952 | rb_define_method(cWebResource, "data", WebResource_data, 0); 953 | rb_define_method(cWebResource, "data=", WebResource_data_equals, 1); 954 | cWebNetworkRequest = G_DEF_CLASS(WEBKIT_TYPE_NETWORK_REQUEST, "WebNetworkRequest", mWebKit); 955 | rb_define_method(cWebNetworkRequest, "uri", WebNetworkRequest_uri, 0); 956 | rb_define_method(cWebNetworkRequest, "uri=", WebNetworkRequest_uri_equals, 1); 957 | rb_define_method(cWebNetworkRequest, "message", WebNetworkRequest_message, 0); 958 | cWebNetworkResponse = G_DEF_CLASS(WEBKIT_TYPE_NETWORK_RESPONSE, "WebNetworkResponse", mWebKit); 959 | rb_define_method(cWebNetworkResponse, "uri", WebNetworkResponse_uri, 0); 960 | rb_define_method(cWebNetworkResponse, "uri=", WebNetworkResponse_uri_equals, 1); 961 | rb_define_method(cWebNetworkResponse, "message", WebNetworkResponse_message, 0); 962 | cDownload = G_DEF_CLASS(WEBKIT_TYPE_DOWNLOAD, "Download", mWebKit); 963 | rb_define_method(cDownload, "initialize", Download_initialize, 1); 964 | rb_define_method(cDownload, "start", Download_start, 0); 965 | rb_define_method(cDownload, "cancel", Download_cancel, 0); 966 | rb_define_method(cDownload, "progress", Download_progress, 0); 967 | rb_define_method(cDownload, "current_size", Download_current_size, 0); 968 | rb_define_method(cDownload, "total_size", Download_total_size, 0); 969 | rb_define_method(cDownload, "uri", Download_uri, 0); 970 | rb_define_method(cDownload, "suggested_filename", Download_suggested_filename, 0); 971 | genumTargetInfo = G_DEF_CLASS(WEBKIT_TYPE_WEB_VIEW_TARGET_INFO, "TargetInfo", mWebKit); 972 | G_DEF_CONSTANTS(mWebKit, WEBKIT_TYPE_WEB_VIEW_TARGET_INFO, "WEBKIT_"); 973 | genumDownloadStatus = G_DEF_CLASS(WEBKIT_TYPE_DOWNLOAD_STATUS, "DownloadStatus", mWebKit); 974 | G_DEF_CONSTANTS(mWebKit, WEBKIT_TYPE_DOWNLOAD_STATUS, "WEBKIT_"); 975 | genumDownloadError = G_DEF_CLASS(WEBKIT_TYPE_DOWNLOAD_ERROR, "DownloadError", mWebKit); 976 | G_DEF_CONSTANTS(mWebKit, WEBKIT_TYPE_DOWNLOAD_ERROR, "WEBKIT_"); 977 | genumNetworkError = G_DEF_CLASS(WEBKIT_TYPE_NETWORK_ERROR, "NetworkError", mWebKit); 978 | G_DEF_CONSTANTS(mWebKit, WEBKIT_TYPE_NETWORK_ERROR, "WEBKIT_"); 979 | genumPolicyError = G_DEF_CLASS(WEBKIT_TYPE_POLICY_ERROR, "PolicyError", mWebKit); 980 | G_DEF_CONSTANTS(mWebKit, WEBKIT_TYPE_POLICY_ERROR, "WEBKIT_"); 981 | genumPluginError = G_DEF_CLASS(WEBKIT_TYPE_PLUGIN_ERROR, "PluginError", mWebKit); 982 | G_DEF_CONSTANTS(mWebKit, WEBKIT_TYPE_PLUGIN_ERROR, "WEBKIT_"); 983 | genumCacheModel = G_DEF_CLASS(WEBKIT_TYPE_CACHE_MODEL, "CacheModel", mWebKit); 984 | G_DEF_CONSTANTS(mWebKit, WEBKIT_TYPE_CACHE_MODEL, "WEBKIT_"); 985 | genumLoadStatus = G_DEF_CLASS(WEBKIT_TYPE_LOAD_STATUS, "LoadStatus", mWebKit); 986 | G_DEF_CONSTANTS(mWebKit, WEBKIT_TYPE_LOAD_STATUS, "WEBKIT_"); 987 | genumNavigationReason = G_DEF_CLASS(WEBKIT_TYPE_WEB_NAVIGATION_REASON, "NavigationReason", mWebKit); 988 | G_DEF_CONSTANTS(mWebKit, WEBKIT_TYPE_WEB_NAVIGATION_REASON, "WEBKIT_"); 989 | genumHitTestResultContext = G_DEF_CLASS(WEBKIT_TYPE_HIT_TEST_RESULT_CONTEXT, "HitTestResultContext", mWebKit); 990 | G_DEF_CONSTANTS(mWebKit, WEBKIT_TYPE_HIT_TEST_RESULT_CONTEXT, "WEBKIT_"); 991 | genumEditingBehavior = G_DEF_CLASS(WEBKIT_TYPE_EDITING_BEHAVIOR, "EditingBehavior", mWebKit); 992 | G_DEF_CONSTANTS(mWebKit, WEBKIT_TYPE_EDITING_BEHAVIOR, "WEBKIT_"); 993 | genumNavigationResponse = G_DEF_CLASS(WEBKIT_TYPE_NAVIGATION_RESPONSE, "NavigationResponse", mWebKit); 994 | G_DEF_CONSTANTS(mWebKit, WEBKIT_TYPE_NAVIGATION_RESPONSE, "WEBKIT_"); 995 | rb_gc_register_address(&_gcpool_RubyFunc); 996 | } 997 | -------------------------------------------------------------------------------- /ext/webkit/webkit.cr: -------------------------------------------------------------------------------- 1 | %pkg-config gtk+-2.0 2 | %pkg-config webkit-1.0 3 | %name webkit 4 | 5 | %lib dl 6 | %lib ffi 7 | %include dlfcn.h 8 | %include errno.h 9 | %include ffi.h 10 | %include rbgobject.h 11 | %include sys/mman.h 12 | %include intern.h 13 | 14 | %{ 15 | #include 16 | #include 17 | #include "javascript.h" 18 | 19 | static inline VALUE strOrNil(const char *str) { 20 | if (str) { 21 | return rb_str_new2(str); 22 | } else { 23 | return Qnil; 24 | } 25 | } 26 | 27 | %} 28 | 29 | %include webkit/webkit.h 30 | %include webkit/webkitenumtypes.h 31 | %include JavaScriptCore/JavaScript.h 32 | 33 | %map strOrNil > VALUE : strOrNil(%%) 34 | 35 | %map SoupMessage* > VALUE : GOBJ2RVAL(SOUP_MESSAGE(%%)) 36 | 37 | module WebKit 38 | gcpool RubyFunc 39 | 40 | class JsPtr 41 | end 42 | 43 | class JavascriptError < StandardError 44 | end 45 | 46 | def self.set_web_database_path(char *path) 47 | webkit_set_web_database_directory_path(path); 48 | end 49 | def self.remove_all_web_databases() 50 | webkit_remove_all_web_databases(); 51 | end 52 | def self.set_default_web_database_quota(guint64 quota) 53 | webkit_set_default_web_database_quota(quota); 54 | end 55 | 56 | gobject WebSettings < WEBKIT_TYPE_WEB_SETTINGS 57 | @type WebKitWebSettings 58 | def initialize() 59 | G_INITIALIZE(self, webkit_web_settings_new()); 60 | end 61 | end 62 | 63 | gobject WebPolicyDecision < WEBKIT_TYPE_WEB_POLICY_DECISION 64 | @type WebKitWebPolicyDecision 65 | def download 66 | webkit_web_policy_decision_download(_self); 67 | end 68 | def use 69 | webkit_web_policy_decision_use(_self); 70 | end 71 | def ignore 72 | webkit_web_policy_decision_ignore(_self); 73 | end 74 | end 75 | 76 | gobject WebFrame < WEBKIT_TYPE_WEB_FRAME 77 | @type WebKitWebFrame 78 | def exec_js(char *js) 79 | return javascript_exec(webkit_web_frame_get_global_context(_self), js); 80 | end 81 | def add_ruby_class(char *name, T_CLASS|T_MODULE klass) 82 | javascript_add_class(webkit_web_frame_get_global_context(_self), name, klass); 83 | end 84 | def add_ruby_eval() 85 | javascript_add_ruby_eval(webkit_web_frame_get_global_context(_self)); 86 | end 87 | def add_js_api(char *name, &block) 88 | javascript_add_ruby_fn(webkit_web_frame_get_global_context(_self), name, block); 89 | end 90 | def load_string(char *content, char *mime_type, char *encoding, char *base_uri) 91 | webkit_web_frame_load_string(_self, content, mime_type, encoding, base_uri); 92 | end 93 | end 94 | gobject WebView < WEBKIT_TYPE_WEB_VIEW 95 | @type WebKitWebView 96 | 97 | def initialize() 98 | RBGTK_INITIALIZE(self, webkit_web_view_new()); 99 | end 100 | def open(char *uri) 101 | webkit_web_view_open(_self, uri); 102 | end 103 | def execute_script(char *script) 104 | webkit_web_view_execute_script(_self, script); 105 | end 106 | def set_settings(WebKitWebSettings *settings) 107 | webkit_web_view_set_settings(_self, settings); 108 | end 109 | def load_string(char *content, char *mime_type, char *encoding, char *base_uri) 110 | webkit_web_view_load_string(_self, content, mime_type, encoding, base_uri); 111 | end 112 | def load_uri(char *uri) 113 | webkit_web_view_load_uri(_self, uri); 114 | end 115 | def WebKitWebFrame*:main_frame 116 | return webkit_web_view_get_main_frame(_self); 117 | end 118 | def WebKitWebFrame*:focused_frame 119 | return webkit_web_view_get_focused_frame(_self); 120 | end 121 | def double:progress 122 | return webkit_web_view_get_progress(_self); 123 | end 124 | def strOrNil:title 125 | return webkit_web_view_get_title(_self); 126 | end 127 | def strOrNil:uri 128 | return webkit_web_view_get_uri(_self); 129 | end 130 | def reload 131 | webkit_web_view_reload(_self); 132 | end 133 | def reload_bypass_cache 134 | webkit_web_view_reload_bypass_cache(_self); 135 | end 136 | def set_custom_encoding(char *encoding) 137 | webkit_web_view_set_custom_encoding(_self, encoding); 138 | end 139 | def stop_loading 140 | webkit_web_view_stop_loading(_self); 141 | end 142 | def bool:has_selection? 143 | return webkit_web_view_has_selection(_self); 144 | end 145 | def WebKitWebInspector*:inspector 146 | return webkit_web_view_get_inspector(_self); 147 | end 148 | end 149 | 150 | gobject WebInspector < WEBKIT_TYPE_WEB_INSPECTOR 151 | @type WebKitWebInspector 152 | def inspect_coordinates(double x, double y) 153 | webkit_web_inspector_inspect_coordinates(_self, x, y); 154 | end 155 | def strOrNil:uri 156 | return webkit_web_inspector_get_inspected_uri(_self); 157 | end 158 | def show 159 | webkit_web_inspector_show(_self); 160 | end 161 | def close 162 | webkit_web_inspector_close(_self); 163 | end 164 | def WebKitWebView*:view 165 | return webkit_web_inspector_get_web_view(_self); 166 | end 167 | end 168 | 169 | gobject WebResource < WEBKIT_TYPE_WEB_RESOURCE 170 | @type WebKitWebResource 171 | def strOrNil:encoding 172 | return webkit_web_resource_get_encoding(_self); 173 | end 174 | def strOrNil:frame_name 175 | return webkit_web_resource_get_frame_name(_self); 176 | end 177 | def strOrNil:mime_type 178 | return webkit_web_resource_get_mime_type(_self); 179 | end 180 | def strOrNil:uri 181 | return webkit_web_resource_get_uri(_self); 182 | end 183 | def data 184 | GString *data = webkit_web_resource_get_data(_self); 185 | return rb_str_new(data->str, data->len); 186 | end 187 | def data=(T_STRING data) 188 | GString *odata = webkit_web_resource_get_data(_self); 189 | g_free(odata->str); 190 | odata->str = g_malloc(RSTRING_LEN(data)+1); 191 | odata->len = odata->allocated_len = RSTRING_LEN(data); 192 | memcpy(RSTRING_PTR(data), odata->str, RSTRING_LEN(data)); 193 | return data; 194 | end 195 | end 196 | 197 | gobject WebNetworkRequest < WEBKIT_TYPE_NETWORK_REQUEST 198 | @type WebKitNetworkRequest 199 | def strOrNil:uri 200 | return webkit_network_request_get_uri(_self); 201 | end 202 | def uri=(char *uri) 203 | webkit_network_request_set_uri(_self, uri); 204 | end 205 | def SoupMessage*:message 206 | return webkit_network_request_get_message(_self); 207 | end 208 | end 209 | 210 | gobject WebNetworkResponse < WEBKIT_TYPE_NETWORK_RESPONSE 211 | @type WebKitNetworkResponse 212 | def strOrNil:uri 213 | return webkit_network_response_get_uri(_self); 214 | end 215 | def uri=(char *uri) 216 | webkit_network_response_set_uri(_self, uri); 217 | end 218 | def SoupMessage*:message 219 | return webkit_network_response_get_message(_self); 220 | end 221 | end 222 | 223 | gobject Download < WEBKIT_TYPE_DOWNLOAD 224 | @type WebKitDownload 225 | def initialize(WebKitNetworkRequest *request) 226 | RBGTK_INITIALIZE(self, webkit_download_new(request)); 227 | end 228 | def start 229 | webkit_download_start(_self); 230 | end 231 | def cancel 232 | webkit_download_cancel(_self); 233 | end 234 | def double:progress 235 | return webkit_download_get_progress(_self); 236 | end 237 | def guint64:current_size 238 | return webkit_download_get_current_size(_self); 239 | end 240 | def guint64:total_size 241 | return webkit_download_get_total_size(_self); 242 | end 243 | def char*:uri 244 | return webkit_download_get_uri(_self); 245 | end 246 | def char*:suggested_filename 247 | return webkit_download_get_suggested_filename(_self); 248 | end 249 | end 250 | 251 | genum TargetInfo WEBKIT_TYPE_WEB_VIEW_TARGET_INFO WEBKIT_; 252 | 253 | genum DownloadStatus WEBKIT_TYPE_DOWNLOAD_STATUS WEBKIT_; 254 | genum DownloadError WEBKIT_TYPE_DOWNLOAD_ERROR WEBKIT_; 255 | genum NetworkError WEBKIT_TYPE_NETWORK_ERROR WEBKIT_; 256 | genum PolicyError WEBKIT_TYPE_POLICY_ERROR WEBKIT_; 257 | genum PluginError WEBKIT_TYPE_PLUGIN_ERROR WEBKIT_; 258 | 259 | genum CacheModel WEBKIT_TYPE_CACHE_MODEL WEBKIT_; 260 | genum LoadStatus WEBKIT_TYPE_LOAD_STATUS WEBKIT_; 261 | 262 | genum NavigationReason WEBKIT_TYPE_WEB_NAVIGATION_REASON WEBKIT_; 263 | genum HitTestResultContext WEBKIT_TYPE_HIT_TEST_RESULT_CONTEXT WEBKIT_; 264 | genum EditingBehavior WEBKIT_TYPE_EDITING_BEHAVIOR WEBKIT_; 265 | genum NavigationResponse WEBKIT_TYPE_NAVIGATION_RESPONSE WEBKIT_; 266 | 267 | # genum ViewMode WEBKIT_TYPE_WEB_VIEW_VIEW_MODE WEBKIT_; 268 | # genum SelectionAffinity WEBKIT_TYPE_SELECTION_AFFINITY WEBKIT_; 269 | # genum InsertAction WEBKIT_TYPE_INSERT_ACTION WEBKIT_; 270 | end 271 | 272 | -------------------------------------------------------------------------------- /ext/webkit/webkit.rd: -------------------------------------------------------------------------------- 1 | = module WebKit 2 | --- WebKit.set_web_database_path(String path) 3 | 4 | 5 | --- WebKit.remove_all_web_databases() 6 | 7 | 8 | --- WebKit.set_default_web_database_quota(guint64 quota) 9 | 10 | 11 | == class WebKit::JsPtr 12 | == class WebKit::JavascriptError < StandardError 13 | == class WebKit::WebSettings 14 | --- WebKit::WebSettings.new 15 | 16 | == class WebKit::WebPolicyDecision 17 | --- WebKit::WebPolicyDecision#download 18 | 19 | --- WebKit::WebPolicyDecision#use 20 | 21 | --- WebKit::WebPolicyDecision#ignore 22 | 23 | == class WebKit::WebFrame 24 | --- WebKit::WebFrame#exec_js(String js) 25 | 26 | 27 | --- WebKit::WebFrame#add_ruby_class(String name, Class or Module klass) 28 | 29 | 30 | --- WebKit::WebFrame#add_ruby_eval 31 | 32 | --- WebKit::WebFrame#add_js_api(String name, block) 33 | 34 | 35 | --- WebKit::WebFrame#load_string(String content, String mime_type, String encoding, String base_uri) 36 | 37 | 38 | == class WebKit::WebView 39 | --- WebKit::WebView.new 40 | 41 | --- WebKit::WebView#open(String uri) 42 | 43 | 44 | --- WebKit::WebView#execute_script(String script) 45 | 46 | 47 | --- WebKit::WebView#set_settings(WebKitWebSettings* settings) 48 | 49 | 50 | --- WebKit::WebView#load_string(String content, String mime_type, String encoding, String base_uri) 51 | 52 | 53 | --- WebKit::WebView#load_uri(String uri) 54 | 55 | 56 | --- WebKit::WebView#main_frame 57 | 58 | --- WebKit::WebView#focused_frame 59 | 60 | --- WebKit::WebView#progress 61 | 62 | --- WebKit::WebView#title 63 | 64 | --- WebKit::WebView#uri 65 | 66 | --- WebKit::WebView#reload 67 | 68 | --- WebKit::WebView#reload_bypass_cache 69 | 70 | --- WebKit::WebView#set_custom_encoding(String encoding) 71 | 72 | 73 | --- WebKit::WebView#stop_loading 74 | 75 | --- WebKit::WebView#has_selection? 76 | 77 | --- WebKit::WebView#inspector 78 | 79 | == class WebKit::WebInspector 80 | --- WebKit::WebInspector#inspect_coordinates(double x, double y) 81 | 82 | 83 | --- WebKit::WebInspector#uri 84 | 85 | --- WebKit::WebInspector#show 86 | 87 | --- WebKit::WebInspector#close 88 | 89 | --- WebKit::WebInspector#view 90 | 91 | == class WebKit::WebResource 92 | --- WebKit::WebResource#encoding 93 | 94 | --- WebKit::WebResource#frame_name 95 | 96 | --- WebKit::WebResource#mime_type 97 | 98 | --- WebKit::WebResource#uri 99 | 100 | --- WebKit::WebResource#data 101 | 102 | --- WebKit::WebResource#data=(String data) 103 | 104 | 105 | == class WebKit::WebNetworkRequest 106 | --- WebKit::WebNetworkRequest#uri 107 | 108 | --- WebKit::WebNetworkRequest#uri=(String uri) 109 | 110 | 111 | --- WebKit::WebNetworkRequest#message 112 | 113 | == class WebKit::WebNetworkResponse 114 | --- WebKit::WebNetworkResponse#uri 115 | 116 | --- WebKit::WebNetworkResponse#uri=(String uri) 117 | 118 | 119 | --- WebKit::WebNetworkResponse#message 120 | 121 | == class WebKit::Download 122 | --- WebKit::Download.new(WebKitNetworkRequest* request) 123 | 124 | 125 | --- WebKit::Download#start 126 | 127 | --- WebKit::Download#cancel 128 | 129 | --- WebKit::Download#progress 130 | 131 | --- WebKit::Download#current_size 132 | 133 | --- WebKit::Download#total_size 134 | 135 | --- WebKit::Download#uri 136 | 137 | --- WebKit::Download#suggested_filename 138 | 139 | == enum WebKit::TargetInfo 140 | == enum WebKit::DownloadStatus 141 | == enum WebKit::DownloadError 142 | == enum WebKit::NetworkError 143 | == enum WebKit::PolicyError 144 | == enum WebKit::PluginError 145 | == enum WebKit::CacheModel 146 | == enum WebKit::LoadStatus 147 | == enum WebKit::NavigationReason 148 | == enum WebKit::HitTestResultContext 149 | == enum WebKit::EditingBehavior 150 | == enum WebKit::NavigationResponse 151 | -------------------------------------------------------------------------------- /lib/webkit.rb: -------------------------------------------------------------------------------- 1 | require 'webkit.so' 2 | require 'webkit/version' 3 | 4 | -------------------------------------------------------------------------------- /lib/webkit/version.rb: -------------------------------------------------------------------------------- 1 | module WebKit 2 | BINDINGS_VERSION = "0.0.8" 3 | end 4 | -------------------------------------------------------------------------------- /test/constant_test.rb: -------------------------------------------------------------------------------- 1 | require 'test/unit' 2 | require 'gtk2' 3 | $:.unshift 'ext/webkit' 4 | $:.unshift 'lib' 5 | $:.unshift 'x86_64-linux' 6 | require 'webkit' 7 | 8 | class ConstantTest < Test::Unit::TestCase 9 | def setup 10 | end 11 | 12 | def test_constants 13 | assert_equal WebKit::DOWNLOAD_STATUS_ERROR, WebKit::DownloadStatus::ERROR 14 | assert_equal WebKit::WEB_VIEW_TARGET_INFO_IMAGE, WebKit::TargetInfo::IMAGE 15 | end 16 | end 17 | 18 | -------------------------------------------------------------------------------- /test/js_test.rb: -------------------------------------------------------------------------------- 1 | require 'test/unit' 2 | require 'gtk2' 3 | $:.unshift 'ext/webkit' 4 | $:.unshift 'lib' 5 | $:.unshift 'x86_64-linux' 6 | require 'webkit' 7 | 8 | class JsTest < Test::Unit::TestCase 9 | def setup 10 | @webview = WebKit::WebView.new 11 | @webview.load_string("Foo", 12 | "text/html", "UTF-8", "file://home") 13 | end 14 | 15 | def test_exec_js 16 | assert_equal 6, @webview.main_frame.exec_js("3 + 3") 17 | assert_equal 'foobar', @webview.main_frame.exec_js("'foo' + 'bar'") 18 | assert_equal false, @webview.main_frame.exec_js("3 == 2") 19 | end 20 | 21 | def test_api 22 | @webview.main_frame.add_js_api('test_add') { |a,b| a + b } 23 | 24 | assert_equal 250, @webview.main_frame.exec_js("test_add(100, 150)") 25 | assert_equal 'foobarr', @webview.main_frame.exec_js("test_add('foo','barr')") 26 | 27 | @webview.main_frame.add_js_api('test_nil') { nil } 28 | @webview.main_frame.add_js_api('test_true') { true } 29 | @webview.main_frame.add_js_api('test_false') { false } 30 | 31 | assert_equal nil, @webview.main_frame.exec_js("test_nil()") 32 | assert_equal true, @webview.main_frame.exec_js("test_true()") 33 | assert_equal false, @webview.main_frame.exec_js("test_false()") 34 | end 35 | 36 | 37 | class Foo 38 | class << self 39 | attr_reader :objects 40 | end 41 | @objects = [] 42 | 43 | def initialize() 44 | @init = true 45 | puts "Making a new object..." 46 | Foo.objects << self 47 | end 48 | 49 | def do_something 50 | puts "Do something!" 51 | end 52 | 53 | def toString 54 | "#{self.class.name}:#{object_id}" 55 | end 56 | end 57 | 58 | class Iter 59 | def initialize() 60 | @num = 0 61 | end 62 | def id 63 | object_id 64 | end 65 | def nextNumber 66 | @num += 1 67 | end 68 | def value 69 | @num 70 | end 71 | end 72 | 73 | 74 | def test_class 75 | @webview.main_frame.add_ruby_class('Foo', Foo) 76 | @webview.main_frame.exec_js <<-EOF 77 | var s = new Foo(); 78 | //console.log(s); 79 | //console.log(s.do_something); 80 | s.do_something(); 81 | EOF 82 | assert_equal 1, Foo.objects.size 83 | @webview.main_frame.add_ruby_class('Iter', Iter) 84 | @webview.main_frame.add_ruby_class('File', ::File) 85 | 86 | js_id = false 87 | @webview.main_frame.add_js_api('id_is') { |a| js_id = a } 88 | 89 | assert @webview.main_frame.exec_js(<<-EOF) 90 | var i = new Iter(); 91 | var j = new Iter(); 92 | 93 | var fp = new File("Rakefile", "r"); 94 | var data = fp.read(); 95 | fp.close(); 96 | 97 | i.nextNumber() 98 | i.nextNumber() 99 | j.nextNumber() 100 | 101 | id_is(i.id()) 102 | 103 | if (j.value() < i.value()) { 104 | true; 105 | } else { 106 | false; 107 | } 108 | EOF 109 | 110 | ids = [] 111 | ObjectSpace.each_object(Iter) { |iter| ids << iter.id } 112 | assert ids.include?(js_id) 113 | 114 | GC.enable 115 | GC.start 116 | # Check GC doesn't crash out 117 | assert true 118 | 119 | @mainview = nil 120 | 121 | GC.start 122 | ObjectSpace.each_object(Iter) { |iter| p [:found, iter, iter.id] } 123 | end 124 | end 125 | 126 | --------------------------------------------------------------------------------