webkit2-gtk 3.3.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,24 @@
1
+ # Ruby/WebKit2GTK
2
+
3
+ Ruby/WebKit2GTK is a Ruby binding of WebKit2GTK+.
4
+
5
+ ## Requirements
6
+
7
+ * Ruby/GObjectIntrospection and Ruby/GTK3 in
8
+ [Ruby-GNOME2](https://ruby-gnome2.osdn.jp/)
9
+ * [WebKit2GTK+](http://webkitgtk.org/)
10
+
11
+ ## Install
12
+
13
+ gem install webkit2-gtk
14
+
15
+ ## License
16
+
17
+ Copyright (c) 2015 Ruby-GNOME2 Project Team
18
+
19
+ This program is free software. You can distribute/modify this program
20
+ under the terms of the GNU LESSER GENERAL PUBLIC LICENSE Version 2.1.
21
+
22
+ ## Project Website
23
+
24
+ https://ruby-gnome2.osdn.jp/
@@ -0,0 +1,26 @@
1
+ # -*- ruby -*-
2
+ #
3
+ # Copyright (C) 2015-2018 Ruby-GNOME2 Project Team
4
+ #
5
+ # This library is free software; you can redistribute it and/or
6
+ # modify it under the terms of the GNU Lesser General Public
7
+ # License as published by the Free Software Foundation; either
8
+ # version 2.1 of the License, or (at your option) any later version.
9
+ #
10
+ # This library is distributed in the hope that it will be useful,
11
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13
+ # Lesser General Public License for more details.
14
+ #
15
+ # You should have received a copy of the GNU Lesser General Public
16
+ # License along with this library; if not, write to the Free Software
17
+ # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18
+
19
+ $LOAD_PATH.unshift("./../glib2/lib")
20
+ require "gnome2/rake/package-task"
21
+
22
+ package_name = File.basename(__dir__)
23
+ spec = Gem::Specification.load("#{package_name}.gemspec")
24
+
25
+ GNOME2::Rake::PackageTask.define(spec, __dir__) do |package|
26
+ end
@@ -0,0 +1,40 @@
1
+ # Copyright (C) 2017 Ruby-GNOME2 Project Team
2
+ #
3
+ # This library is free software; you can redistribute it and/or
4
+ # modify it under the terms of the GNU Lesser General Public
5
+ # License as published by the Free Software Foundation; either
6
+ # version 2.1 of the License, or (at your option) any later version.
7
+ #
8
+ # This library is distributed in the hope that it will be useful,
9
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
10
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11
+ # Lesser General Public License for more details.
12
+ #
13
+ # You should have received a copy of the GNU Lesser General Public
14
+ # License along with this library; if not, write to the Free Software
15
+ # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16
+
17
+ require "pkg-config"
18
+ require "native-package-installer"
19
+
20
+ if File.exist?(File.join(__dir__, "..", "vendor"))
21
+ task :default => "nothing"
22
+ else
23
+ task :default => "dependency:check"
24
+ end
25
+
26
+ task :nothing do
27
+ end
28
+
29
+ namespace :dependency do
30
+ desc "Check dependency"
31
+ task :check do
32
+ unless PKGConfig.check_version?("webkit2gtk-4.0")
33
+ unless NativePackageInstaller.install(:debian => "libwebkit2gtk-4.0-dev",
34
+ :redhat => "pkgconfig(webkit2gtk-4.0)",
35
+ :homebrew => "webkitgtk")
36
+ exit(false)
37
+ end
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,48 @@
1
+ # Copyright (C) 2015-2017 Ruby-GNOME2 Project Team
2
+ #
3
+ # This library is free software; you can redistribute it and/or
4
+ # modify it under the terms of the GNU Lesser General Public
5
+ # License as published by the Free Software Foundation; either
6
+ # version 2.1 of the License, or (at your option) any later version.
7
+ #
8
+ # This library is distributed in the hope that it will be useful,
9
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
10
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11
+ # Lesser General Public License for more details.
12
+ #
13
+ # You should have received a copy of the GNU Lesser General Public
14
+ # License along with this library; if not, write to the Free Software
15
+ # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16
+
17
+ require "gobject-introspection"
18
+ require "gtk3"
19
+
20
+ base_dir = Pathname.new(__FILE__).dirname.dirname.expand_path
21
+ vendor_dir = base_dir + "vendor" + "local"
22
+ vendor_bin_dir = vendor_dir + "bin"
23
+ GLib.prepend_dll_path(vendor_bin_dir)
24
+
25
+ require "webkit2-gtk/loader"
26
+
27
+ module WebKit2Gtk
28
+ class << self
29
+ def const_missing(name)
30
+ init
31
+ if const_defined?(name)
32
+ const_get(name)
33
+ else
34
+ super
35
+ end
36
+ end
37
+
38
+ def init
39
+ class << self
40
+ remove_method(:init)
41
+ remove_method(:const_missing)
42
+ end
43
+ Gtk.init if Gtk.respond_to?(:init)
44
+ loader = Loader.new(self)
45
+ loader.load
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,55 @@
1
+ # Copyright (C) 2015-2017 Ruby-GNOME2 Project Team
2
+ #
3
+ # This library is free software; you can redistribute it and/or
4
+ # modify it under the terms of the GNU Lesser General Public
5
+ # License as published by the Free Software Foundation; either
6
+ # version 2.1 of the License, or (at your option) any later version.
7
+ #
8
+ # This library is distributed in the hope that it will be useful,
9
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
10
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11
+ # Lesser General Public License for more details.
12
+ #
13
+ # You should have received a copy of the GNU Lesser General Public
14
+ # License along with this library; if not, write to the Free Software
15
+ # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16
+
17
+ module WebKit2Gtk
18
+ class Loader < GObjectIntrospection::Loader
19
+ NAMESPACE = "WebKit2"
20
+
21
+ def load
22
+ super(NAMESPACE)
23
+ end
24
+
25
+ private
26
+ def pre_load(repository, namespace)
27
+ define_version_module
28
+ end
29
+
30
+ def post_load(repository, namespace)
31
+ require_libraries
32
+ end
33
+
34
+ def define_version_module
35
+ @version_module = Module.new
36
+ @base_module.const_set("Version", @version_module)
37
+ end
38
+
39
+ def require_libraries
40
+ require "webkit2-gtk/version" if @version_module.const_defined?(:MAJOR)
41
+
42
+ require "webkit2-gtk/web-context"
43
+ require "webkit2-gtk/web-view"
44
+ end
45
+
46
+ def load_constant_info(info)
47
+ case info.name
48
+ when /_VERSION\z/
49
+ @version_module.const_set($PREMATCH, info.value)
50
+ else
51
+ super
52
+ end
53
+ end
54
+ end
55
+ end
@@ -0,0 +1,33 @@
1
+ # Copyright (C) 2015 Ruby-GNOME2 Project Team
2
+ #
3
+ # This library is free software; you can redistribute it and/or
4
+ # modify it under the terms of the GNU Lesser General Public
5
+ # License as published by the Free Software Foundation; either
6
+ # version 2.1 of the License, or (at your option) any later version.
7
+ #
8
+ # This library is distributed in the hope that it will be useful,
9
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
10
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11
+ # Lesser General Public License for more details.
12
+ #
13
+ # You should have received a copy of the GNU Lesser General Public
14
+ # License along with this library; if not, write to the Free Software
15
+ # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16
+
17
+ module WebKit2Gtk
18
+ module Version
19
+ STRING = [MAJOR, MINOR, MICRO].join(".")
20
+
21
+ class << self
22
+ def or_later?(major, minor, micro=nil)
23
+ micro ||= 0
24
+ version = [
25
+ MAJOR,
26
+ MINOR,
27
+ MICRO,
28
+ ]
29
+ (version <=> [major, minor, micro]) >= 0
30
+ end
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,34 @@
1
+ # Copyright (C) 2017 Ruby-GNOME2 Project Team
2
+ #
3
+ # This library is free software; you can redistribute it and/or
4
+ # modify it under the terms of the GNU Lesser General Public
5
+ # License as published by the Free Software Foundation; either
6
+ # version 2.1 of the License, or (at your option) any later version.
7
+ #
8
+ # This library is distributed in the hope that it will be useful,
9
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
10
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11
+ # Lesser General Public License for more details.
12
+ #
13
+ # You should have received a copy of the GNU Lesser General Public
14
+ # License along with this library; if not, write to the Free Software
15
+ # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16
+
17
+ module WebKit2Gtk
18
+ class WebContext
19
+ alias_method :initialize_raw, :initialize
20
+ def initialize(*args)
21
+ if args.size == 1 and args[0].is_a?(Hash)
22
+ options = args[0]
23
+ ephemeral = options[:ephemeral]
24
+ if ephemeral
25
+ initialize_new_ephemeral
26
+ else
27
+ initialize_raw
28
+ end
29
+ else
30
+ initialize_raw(*args)
31
+ end
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,74 @@
1
+ # Copyright (C) 2017 Ruby-GNOME2 Project Team
2
+ #
3
+ # This library is free software; you can redistribute it and/or
4
+ # modify it under the terms of the GNU Lesser General Public
5
+ # License as published by the Free Software Foundation; either
6
+ # version 2.1 of the License, or (at your option) any later version.
7
+ #
8
+ # This library is distributed in the hope that it will be useful,
9
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
10
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11
+ # Lesser General Public License for more details.
12
+ #
13
+ # You should have received a copy of the GNU Lesser General Public
14
+ # License along with this library; if not, write to the Free Software
15
+ # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16
+
17
+ module WebKit2Gtk
18
+ class WebView
19
+ unless private_method_defined?(:initialize_new_with_related_view)
20
+ class << self
21
+ def new(*args)
22
+ return super unless args.size == 1
23
+ return super unless args[0].is_a?(Hash)
24
+
25
+ related_view = args[0][:related_view]
26
+ return super unless related_view
27
+ related_view.new_with_related_view
28
+ end
29
+ end
30
+ end
31
+
32
+ alias_method :initialize_raw, :initialize
33
+ def initialize(*args)
34
+ case args.size
35
+ when 1
36
+ case args[0]
37
+ when Hash
38
+ initialize_with_hash(args[0])
39
+ when WebContext
40
+ message = "#{caller[0]}: #{self.class}.new(context) is deprecated. "
41
+ message << "Use #{self.class}.new(:context => context) instead."
42
+ warn(message)
43
+ initialize_raw(args[0])
44
+ else
45
+ raise ArgumentError, "must be options: #{args[0].inspect}"
46
+ end
47
+ else
48
+ initialize_raw(*args)
49
+ end
50
+ end
51
+
52
+ def initialize_with_hash(options)
53
+ context = options[:context]
54
+ settings = options[:settings]
55
+ user_content_manager = options[:user_content_manager]
56
+ related_view = options[:related_view]
57
+
58
+ if context
59
+ initialize_new_with_context(context)
60
+ elsif settings
61
+ initialize_new_with_settings(settings)
62
+ elsif user_content_manager
63
+ initialize_new_with_user_content_manager(user_content_manager)
64
+ elsif related_view
65
+ initialize_new_with_related_view(related_view)
66
+ else
67
+ message =
68
+ "must specify :context, :settings, :user_content_manager or :related_view"
69
+ raise ArgumentError, message
70
+ end
71
+ end
72
+ private :initialize_with_hash
73
+ end
74
+ end
@@ -0,0 +1,70 @@
1
+ # Copyright (C) 2015 Ruby-GNOME2 Project Team
2
+ #
3
+ # This library is free software; you can redistribute it and/or
4
+ # modify it under the terms of the GNU Lesser General Public
5
+ # License as published by the Free Software Foundation; either
6
+ # version 2.1 of the License, or (at your option) any later version.
7
+ #
8
+ # This library is distributed in the hope that it will be useful,
9
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
10
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11
+ # Lesser General Public License for more details.
12
+ #
13
+ # You should have received a copy of the GNU Lesser General Public
14
+ # License along with this library; if not, write to the Free Software
15
+ # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16
+
17
+ require "uri"
18
+ require "webkit2-gtk"
19
+
20
+ uri = URI.parse(ARGV.shift || "https://webkitgtk.org/")
21
+
22
+ app = Gtk::Application.new("com.github.ruby-gnome2.webkit2-gtk.sample.browser",
23
+ :flags_none)
24
+ app.signal_connect(:activate) do
25
+ window = Gtk::ApplicationWindow.new(app)
26
+ window.set_default_size(800, 600)
27
+
28
+ view = nil
29
+
30
+ box = Gtk::Box.new(:vertical)
31
+ window.add(box)
32
+
33
+ entry = Gtk::Entry.new
34
+ entry.signal_connect("activate") do
35
+ view.load_uri(entry.text)
36
+ end
37
+
38
+ box.pack_start(entry)
39
+
40
+ # For supporting http_proxy and https_proxy.
41
+ # view_context = WebKit2Gtk::WebContext.new
42
+ # proxy_settings = WebKit2Gtk::NetworkProxySettings.new
43
+ # proxy_settings.add_proxy_for_scheme("http", ENV["http_proxy"])
44
+ # proxy_settings.add_proxy_for_scheme("https", ENV["https_proxy"])
45
+ # view_context.set_network_proxy_settings(:custom, proxy_settings)
46
+ # view = WebKit2Gtk::WebView.new(context: view_context)
47
+ view = WebKit2Gtk::WebView.new
48
+ view.signal_connect("load-changed") do |_, load_event|
49
+ p [:load_changed, view.uri, load_event]
50
+ entry.text = view.uri
51
+ end
52
+ view.signal_connect("load-failed") do |_, _, failed_uri, error|
53
+ message = "failed to load URI: #{failed_uri}: "
54
+ message << "#{error.class}(#{error.code}): #{error.message}"
55
+ puts(message)
56
+ true
57
+ end
58
+
59
+ if uri.class == URI::Generic
60
+ view.load_html(File.read(uri.path), uri.to_s)
61
+ else
62
+ view.load_uri(uri.to_s)
63
+ end
64
+
65
+ box.pack_start(view, expand: true, fill: true)
66
+
67
+ window.show_all
68
+ end
69
+
70
+ app.run
@@ -0,0 +1,67 @@
1
+ # Copyright (C) 2017 Ruby-GNOME2 Project Team
2
+ #
3
+ # This library is free software; you can redistribute it and/or
4
+ # modify it under the terms of the GNU Lesser General Public
5
+ # License as published by the Free Software Foundation; either
6
+ # version 2.1 of the License, or (at your option) any later version.
7
+ #
8
+ # This library is distributed in the hope that it will be useful,
9
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
10
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11
+ # Lesser General Public License for more details.
12
+ #
13
+ # You should have received a copy of the GNU Lesser General Public
14
+ # License along with this library; if not, write to the Free Software
15
+ # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16
+
17
+ require "cgi/util"
18
+ require "webkit2-gtk"
19
+
20
+ if ARGV.empty?
21
+ puts("Usage: #{$0} URL...")
22
+ puts(" e.g.: #{$0} https://webkitgtk.org/ https://www.gtk.org/")
23
+ exit(false)
24
+ end
25
+
26
+ main_loop = GLib::MainLoop.new
27
+
28
+ view_context = WebKit2Gtk::WebContext.new(ephemeral: true)
29
+ view = WebKit2Gtk::WebView.new(context: view_context)
30
+ window = Gtk::OffscreenWindow.new
31
+ window.add(view)
32
+ window.set_default_size(800, 600)
33
+ window.show_all
34
+ ARGV.each do |uri|
35
+ view.load_uri(uri)
36
+ view.signal_connect("load-changed") do |_, load_event|
37
+ case load_event
38
+ when WebKit2Gtk::LoadEvent::FINISHED
39
+ view.get_snapshot(:full_document, :none) do |_, result|
40
+ main_loop.quit
41
+ snapshot_surface = view.get_snapshot_finish(result)
42
+ base_path = CGI.escape(uri)
43
+ snapshot_surface.write_to_png("#{base_path}.png")
44
+
45
+ width = 200
46
+ height = 200
47
+ thumbnail_surface = Cairo::ImageSurface.new(:argb32, width, height)
48
+ context = Cairo::Context.new(thumbnail_surface)
49
+ context.set_source_color(:white)
50
+ context.paint
51
+ ratio = width.to_f / snapshot_surface.width
52
+ context.scale(ratio, ratio)
53
+ context.set_source(snapshot_surface)
54
+ context.paint
55
+ thumbnail_surface.write_to_png("#{base_path}.thumbnail.png")
56
+ end
57
+ end
58
+ end
59
+ view.signal_connect("load-failed") do |_, _, failed_uri, error|
60
+ main_loop.quit
61
+ message = "failed to load URI: #{failed_uri}: "
62
+ message << "#{error.class}(#{error.code}): #{error.message}"
63
+ puts(message)
64
+ true
65
+ end
66
+ main_loop.run
67
+ end