1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
|
/* -*- Mode: C; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/*
* Copyright © 2000-2003 Marco Pesenti Gritti
* Copyright © 2011 Igalia S.L.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
*/
#include <config.h>
#include "ephy-embed-shell.h"
#include "ephy-about-handler.h"
#include "ephy-debug.h"
#include "ephy-embed-prefs.h"
#include "ephy-embed-private.h"
#include "ephy-embed-type-builtins.h"
#include "ephy-embed-utils.h"
#include "ephy-encodings.h"
#include "ephy-file-helpers.h"
#include "ephy-history-service.h"
#include "ephy-profile-utils.h"
#include "ephy-settings.h"
#include "ephy-snapshot-service.h"
#include "ephy-web-extension-proxy.h"
#include "ephy-web-extension-names.h"
#include <glib/gi18n.h>
#include <gtk/gtk.h>
#include <stdlib.h>
#define PAGE_SETUP_FILENAME "page-setup-gtk.ini"
#define PRINT_SETTINGS_FILENAME "print-settings.ini"
#define OVERVIEW_RELOAD_DELAY 500
#define EPHY_EMBED_SHELL_GET_PRIVATE(object)(G_TYPE_INSTANCE_GET_PRIVATE ((object), EPHY_TYPE_EMBED_SHELL, EphyEmbedShellPrivate))
struct _EphyEmbedShellPrivate
{
EphyHistoryService *global_history_service;
EphyEncodings *encodings;
GtkPageSetup *page_setup;
GtkPrintSettings *print_settings;
EphyEmbedShellMode mode;
EphyAboutHandler *about_handler;
guint update_overview_timeout_id;
guint hiding_overview_item;
GDBusConnection *bus;
GList *web_extensions;
guint web_extensions_page_created_signal_id;
guint web_extensions_form_auth_save_signal_id;
guint web_extensions_remove_from_overview_signal_id;
};
enum
{
PREPARE_CLOSE,
RESTORED_WINDOW,
WEB_VIEW_CREATED,
PAGE_CREATED,
LAST_SIGNAL
};
static guint signals[LAST_SIGNAL];
enum
{
PROP_0,
PROP_MODE,
N_PROPERTIES
};
static GParamSpec *object_properties[N_PROPERTIES] = { NULL, };
EphyEmbedShell *embed_shell = NULL;
G_DEFINE_TYPE (EphyEmbedShell, ephy_embed_shell, GTK_TYPE_APPLICATION)
static void
ephy_embed_shell_dispose (GObject *object)
{
EphyEmbedShellPrivate *priv = EPHY_EMBED_SHELL (object)->priv;
if (priv->update_overview_timeout_id > 0) {
g_source_remove (priv->update_overview_timeout_id);
priv->update_overview_timeout_id = 0;
}
g_clear_object (&priv->encodings);
g_clear_object (&priv->page_setup);
g_clear_object (&priv->print_settings);
g_clear_object (&priv->global_history_service);
g_clear_object (&priv->about_handler);
G_OBJECT_CLASS (ephy_embed_shell_parent_class)->dispose (object);
}
static gint
web_extension_compare (EphyWebExtensionProxy *proxy,
const char *name_owner)
{
return g_strcmp0 (ephy_web_extension_proxy_get_name_owner (proxy), name_owner);
}
static EphyWebExtensionProxy *
ephy_embed_shell_find_web_extension (EphyEmbedShell *shell,
const char *name_owner)
{
GList *l;
l = g_list_find_custom (shell->priv->web_extensions, name_owner, (GCompareFunc)web_extension_compare);
if (!l)
g_warning ("Could not find extension with name owner `%s´.", name_owner);
return l ? EPHY_WEB_EXTENSION_PROXY (l->data) : NULL;
}
static void
web_extension_form_auth_save_requested (GDBusConnection *connection,
const char *sender_name,
const char *object_path,
const char *interface_name,
const char *signal_name,
GVariant *parameters,
EphyEmbedShell *shell)
{
EphyWebExtensionProxy *web_extension;
guint request_id;
guint64 page_id;
const char *hostname;
const char *username;
g_variant_get (parameters, "(ut&s&s)", &request_id, &page_id, &hostname, &username);
web_extension = ephy_embed_shell_find_web_extension (shell, sender_name);
if (!web_extension)
return;
ephy_web_extension_proxy_form_auth_save_requested (web_extension, request_id, page_id, hostname, username);
}
static void
web_extension_page_created (GDBusConnection *connection,
const char *sender_name,
const char *object_path,
const char *interface_name,
const char *signal_name,
GVariant *parameters,
EphyEmbedShell *shell)
{
EphyWebExtensionProxy *web_extension;
guint64 page_id;
g_variant_get (parameters, "(t)", &page_id);
web_extension = ephy_embed_shell_find_web_extension (shell, sender_name);
if (!web_extension)
return;
g_signal_emit (shell, signals[PAGE_CREATED], 0, page_id, web_extension);
}
static void
history_service_query_urls_cb (EphyHistoryService *service,
gboolean success,
GList *urls,
EphyEmbedShell *shell)
{
GList *l;
if (!success)
return;
for (l = shell->priv->web_extensions; l; l = g_list_next (l)) {
EphyWebExtensionProxy *web_extension = (EphyWebExtensionProxy *)l->data;
ephy_web_extension_proxy_history_set_urls (web_extension, urls);
}
}
static void
ephy_embed_shell_update_overview_urls (EphyEmbedShell *shell)
{
EphyHistoryQuery *query;
query = ephy_history_query_new ();
query->sort_type = EPHY_HISTORY_SORT_MOST_VISITED;
query->limit = EPHY_ABOUT_OVERVIEW_MAX_ITEMS;
query->ignore_hidden = TRUE;
ephy_history_service_query_urls (shell->priv->global_history_service, query, NULL,
(EphyHistoryJobCallback) history_service_query_urls_cb,
shell);
ephy_history_query_free (query);
}
static void
history_service_urls_visited_cb (EphyHistoryService *history,
EphyEmbedShell *shell)
{
ephy_embed_shell_update_overview_urls (shell);
}
static gboolean
ephy_embed_shell_update_overview_timeout_cb (EphyEmbedShell *shell)
{
shell->priv->update_overview_timeout_id = 0;
if (shell->priv->hiding_overview_item > 0)
return FALSE;
ephy_embed_shell_update_overview_urls (shell);
return FALSE;
}
static void
history_set_url_hidden_cb (EphyHistoryService *service,
gboolean success,
gpointer result_data,
EphyEmbedShell *shell)
{
shell->priv->hiding_overview_item--;
if (!success)
return;
if (shell->priv->update_overview_timeout_id > 0)
return;
ephy_embed_shell_update_overview_urls (shell);
}
static void
web_extension_remove_from_overview (GDBusConnection *connection,
const char *sender_name,
const char *object_path,
const char *interface_name,
const char *signal_name,
GVariant *parameters,
EphyEmbedShell *shell)
{
const char *url_to_remove;
g_variant_get (parameters, "(&s)", &url_to_remove);
shell->priv->hiding_overview_item++;
ephy_history_service_set_url_hidden (shell->priv->global_history_service,
url_to_remove, TRUE, NULL,
(EphyHistoryJobCallback) history_set_url_hidden_cb,
shell);
if (shell->priv->update_overview_timeout_id > 0)
g_source_remove (shell->priv->update_overview_timeout_id);
/* Wait for the CSS animations to finish before refreshing */
shell->priv->update_overview_timeout_id =
g_timeout_add (OVERVIEW_RELOAD_DELAY, (GSourceFunc) ephy_embed_shell_update_overview_timeout_cb, shell);
}
static void
web_extension_destroyed (EphyEmbedShell *shell,
GObject *web_extension)
{
shell->priv->web_extensions = g_list_remove (shell->priv->web_extensions, web_extension);
}
static void
ephy_embed_shell_watch_web_extension (EphyEmbedShell *shell,
const char *web_extension_id)
{
EphyWebExtensionProxy *web_extension;
char *service_name;
if (!shell->priv->bus)
return;
service_name = g_strdup_printf ("%s-%s", EPHY_WEB_EXTENSION_SERVICE_NAME, web_extension_id);
web_extension = ephy_web_extension_proxy_new (shell->priv->bus, service_name);
shell->priv->web_extensions = g_list_prepend (shell->priv->web_extensions, web_extension);
g_object_weak_ref (G_OBJECT (web_extension), (GWeakNotify)web_extension_destroyed, shell);
g_free (service_name);
}
static void
ephy_embed_shell_unwatch_web_extension (EphyWebExtensionProxy *web_extension,
EphyEmbedShell *shell)
{
g_object_weak_unref (G_OBJECT (web_extension), (GWeakNotify)web_extension_destroyed, shell);
}
static void
history_service_url_title_changed_cb (EphyHistoryService *service,
const char *url,
const char *title,
EphyEmbedShell *shell)
{
GList *l;
for (l = shell->priv->web_extensions; l; l = g_list_next (l)) {
EphyWebExtensionProxy *web_extension = (EphyWebExtensionProxy *)l->data;
ephy_web_extension_proxy_history_set_url_title (web_extension, url, title);
}
}
static void
history_service_url_deleted_cb (EphyHistoryService *service,
const char *url,
EphyEmbedShell *shell)
{
GList *l;
for (l = shell->priv->web_extensions; l; l = g_list_next (l)) {
EphyWebExtensionProxy *web_extension = (EphyWebExtensionProxy *)l->data;
ephy_web_extension_proxy_history_delete_url (web_extension, url);
}
}
static void
history_service_host_deleted_cb (EphyHistoryService *service,
const char *deleted_url,
EphyEmbedShell *shell)
{
GList *l;
SoupURI *deleted_uri;
deleted_uri = soup_uri_new (deleted_url);
for (l = shell->priv->web_extensions; l; l = g_list_next (l)) {
EphyWebExtensionProxy *web_extension = (EphyWebExtensionProxy *)l->data;
ephy_web_extension_proxy_history_delete_host (web_extension, soup_uri_get_host (deleted_uri));
}
soup_uri_free (deleted_uri);
}
static void
history_service_cleared_cb (EphyHistoryService *service,
EphyEmbedShell *shell)
{
GList *l;
for (l = shell->priv->web_extensions; l; l = g_list_next (l)) {
EphyWebExtensionProxy *web_extension = (EphyWebExtensionProxy *)l->data;
ephy_web_extension_proxy_history_clear (web_extension);
}
}
void
ephy_embed_shell_set_thumbanil_path (EphyEmbedShell *shell,
const char *url,
time_t mtime,
const char *path)
{
GList *l;
ephy_history_service_set_url_thumbnail_time (shell->priv->global_history_service,
url, mtime,
NULL, NULL, NULL);
for (l = shell->priv->web_extensions; l; l = g_list_next (l)) {
EphyWebExtensionProxy *web_extension = (EphyWebExtensionProxy *)l->data;
ephy_web_extension_proxy_history_set_url_thumbnail (web_extension, url, path);
}
}
/**
* ephy_embed_shell_get_global_history_service:
* @shell: the #EphyEmbedShell
*
* Return value: (transfer none): the global #EphyHistoryService
**/
GObject *
ephy_embed_shell_get_global_history_service (EphyEmbedShell *shell)
{
g_return_val_if_fail (EPHY_IS_EMBED_SHELL (shell), NULL);
if (shell->priv->global_history_service == NULL) {
char *filename;
filename = g_build_filename (ephy_dot_dir (), EPHY_HISTORY_FILE, NULL);
shell->priv->global_history_service = ephy_history_service_new (filename, FALSE);
g_free (filename);
g_return_val_if_fail (shell->priv->global_history_service, NULL);
g_signal_connect (shell->priv->global_history_service, "urls-visited",
G_CALLBACK (history_service_urls_visited_cb),
shell);
g_signal_connect (shell->priv->global_history_service, "url-title-changed",
G_CALLBACK (history_service_url_title_changed_cb),
shell);
g_signal_connect (shell->priv->global_history_service, "url-deleted",
G_CALLBACK (history_service_url_deleted_cb),
shell);
g_signal_connect (shell->priv->global_history_service, "host-deleted",
G_CALLBACK (history_service_host_deleted_cb),
shell);
g_signal_connect (shell->priv->global_history_service, "cleared",
G_CALLBACK (history_service_cleared_cb),
shell);
}
return G_OBJECT (shell->priv->global_history_service);
}
/**
* ephy_embed_shell_get_encodings:
* @shell: the #EphyEmbedShell
*
* Return value: (transfer none):
**/
GObject *
ephy_embed_shell_get_encodings (EphyEmbedShell *shell)
{
g_return_val_if_fail (EPHY_IS_EMBED_SHELL (shell), NULL);
if (shell->priv->encodings == NULL)
shell->priv->encodings = ephy_encodings_new ();
return G_OBJECT (shell->priv->encodings);
}
void
ephy_embed_shell_prepare_close (EphyEmbedShell *shell)
{
g_signal_emit (shell, signals[PREPARE_CLOSE], 0);
}
void
ephy_embed_shell_restored_window (EphyEmbedShell *shell)
{
g_signal_emit (shell, signals[RESTORED_WINDOW], 0);
}
static void
about_request_cb (WebKitURISchemeRequest *request,
EphyEmbedShell *shell)
{
ephy_about_handler_handle_request (shell->priv->about_handler, request);
}
static void
ephy_resource_request_cb (WebKitURISchemeRequest *request)
{
const char *path;
GInputStream *stream;
gsize size;
GError *error = NULL;
path = webkit_uri_scheme_request_get_path (request);
if (!g_resources_get_info (path, 0, &size, NULL, &error)) {
webkit_uri_scheme_request_finish_error (request, error);
g_error_free (error);
return;
}
stream = g_resources_open_stream (path, 0, &error);
if (stream) {
webkit_uri_scheme_request_finish (request, stream, size, NULL);
g_object_unref (stream);
} else {
webkit_uri_scheme_request_finish_error (request, error);
g_error_free (error);
}
}
static void
initialize_web_extensions (WebKitWebContext* web_context,
EphyEmbedShell *shell)
{
GVariant *user_data;
gboolean private_profile;
char *web_extension_id;
static guint web_extension_count = 0;
webkit_web_context_set_web_extensions_directory (web_context, EPHY_WEB_EXTENSIONS_DIR);
web_extension_id = g_strdup_printf ("%u-%u", getpid (), ++web_extension_count);
ephy_embed_shell_watch_web_extension (shell, web_extension_id);
private_profile = EPHY_EMBED_SHELL_MODE_HAS_PRIVATE_PROFILE (shell->priv->mode);
user_data = g_variant_new ("(ssb)", web_extension_id, ephy_dot_dir (), private_profile);
webkit_web_context_set_web_extensions_initialization_user_data (web_context, user_data);
}
static void
ephy_embed_shell_setup_web_extensions_connection (EphyEmbedShell *shell)
{
GError *error = NULL;
shell->priv->bus = g_application_get_dbus_connection (G_APPLICATION (shell));
if (!shell->priv->bus) {
g_warning ("Application not connected to session bus: %s\n", error->message);
g_error_free (error);
return;
}
shell->priv->web_extensions_page_created_signal_id =
g_dbus_connection_signal_subscribe (shell->priv->bus,
NULL,
EPHY_WEB_EXTENSION_INTERFACE,
"PageCreated",
EPHY_WEB_EXTENSION_OBJECT_PATH,
NULL,
G_DBUS_SIGNAL_FLAGS_NONE,
(GDBusSignalCallback)web_extension_page_created,
shell,
NULL);
shell->priv->web_extensions_form_auth_save_signal_id =
g_dbus_connection_signal_subscribe (shell->priv->bus,
NULL,
EPHY_WEB_EXTENSION_INTERFACE,
"FormAuthDataSaveConfirmationRequired",
EPHY_WEB_EXTENSION_OBJECT_PATH,
NULL,
G_DBUS_SIGNAL_FLAGS_NONE,
(GDBusSignalCallback)web_extension_form_auth_save_requested,
shell,
NULL);
shell->priv->web_extensions_remove_from_overview_signal_id =
g_dbus_connection_signal_subscribe (shell->priv->bus,
NULL,
EPHY_WEB_EXTENSION_INTERFACE,
"RemoveItemFromOverview",
EPHY_WEB_EXTENSION_OBJECT_PATH,
NULL,
G_DBUS_SIGNAL_FLAGS_NONE,
(GDBusSignalCallback)web_extension_remove_from_overview,
shell,
NULL);
}
static void
ephy_embed_shell_setup_process_model (EphyEmbedShell *shell,
WebKitWebContext *web_context)
{
EphyPrefsProcessModel process_model;
process_model = g_settings_get_enum (EPHY_SETTINGS_MAIN, EPHY_PREFS_PROCESS_MODEL);
switch (process_model) {
case EPHY_PREFS_PROCESS_MODEL_SHARED_SECONDARY_PROCESS:
webkit_web_context_set_process_model (web_context, WEBKIT_PROCESS_MODEL_SHARED_SECONDARY_PROCESS);
break;
case EPHY_PREFS_PROCESS_MODEL_ONE_SECONDARY_PROCESS_PER_WEB_VIEW:
webkit_web_context_set_process_model (web_context, WEBKIT_PROCESS_MODEL_MULTIPLE_SECONDARY_PROCESSES);
break;
}
}
static void
ephy_embed_shell_startup (GApplication* application)
{
EphyEmbedShell *shell = EPHY_EMBED_SHELL (application);
EphyEmbedShellMode mode;
char *disk_cache_dir;
WebKitWebContext *web_context;
WebKitCookieManager *cookie_manager;
char *filename;
char *cookie_policy;
G_APPLICATION_CLASS (ephy_embed_shell_parent_class)->startup (application);
/* We're not remoting, setup the Web Context. */
mode = shell->priv->mode;
ephy_embed_shell_setup_web_extensions_connection (shell);
web_context = webkit_web_context_get_default ();
ephy_embed_shell_setup_process_model (shell, web_context);
g_signal_connect (web_context, "initialize-web-extensions",
G_CALLBACK (initialize_web_extensions),
shell);
/* Disk Cache */
disk_cache_dir = g_build_filename (EPHY_EMBED_SHELL_MODE_HAS_PRIVATE_PROFILE (mode) ?
ephy_dot_dir () : g_get_user_cache_dir (),
g_get_prgname (), NULL);
webkit_web_context_set_disk_cache_directory (web_context, disk_cache_dir);
g_free (disk_cache_dir);
/* about: URIs handler */
shell->priv->about_handler = ephy_about_handler_new ();
webkit_web_context_register_uri_scheme (web_context,
EPHY_ABOUT_SCHEME,
(WebKitURISchemeRequestCallback)about_request_cb,
shell, NULL);
/* Register about scheme as local so that it can contain file resources */
webkit_security_manager_register_uri_scheme_as_local (webkit_web_context_get_security_manager (web_context),
EPHY_ABOUT_SCHEME);
/* ephy-resource handler */
webkit_web_context_register_uri_scheme (web_context, "ephy-resource",
(WebKitURISchemeRequestCallback)ephy_resource_request_cb,
NULL, NULL);
/* Store cookies in moz-compatible SQLite format */
cookie_manager = webkit_web_context_get_cookie_manager (web_context);
filename = g_build_filename (ephy_dot_dir (), "cookies.sqlite", NULL);
webkit_cookie_manager_set_persistent_storage (cookie_manager, filename,
WEBKIT_COOKIE_PERSISTENT_STORAGE_SQLITE);
g_free (filename);
cookie_policy = g_settings_get_string (EPHY_SETTINGS_WEB,
EPHY_PREFS_WEB_COOKIES_POLICY);
ephy_embed_prefs_set_cookie_accept_policy (cookie_manager, cookie_policy);
g_free (cookie_policy);
}
static void
ephy_embed_shell_shutdown (GApplication* application)
{
EphyEmbedShellPrivate *priv = EPHY_EMBED_SHELL (application)->priv;
G_APPLICATION_CLASS (ephy_embed_shell_parent_class)->shutdown (application);
if (priv->web_extensions_page_created_signal_id > 0) {
g_dbus_connection_signal_unsubscribe (priv->bus, priv->web_extensions_page_created_signal_id);
priv->web_extensions_page_created_signal_id = 0;
}
if (priv->web_extensions_form_auth_save_signal_id > 0) {
g_dbus_connection_signal_unsubscribe (priv->bus, priv->web_extensions_form_auth_save_signal_id);
priv->web_extensions_form_auth_save_signal_id = 0;
}
if (priv->web_extensions_remove_from_overview_signal_id > 0) {
g_dbus_connection_signal_unsubscribe (priv->bus, priv->web_extensions_remove_from_overview_signal_id);
priv->web_extensions_remove_from_overview_signal_id = 0;
}
g_list_foreach (priv->web_extensions, (GFunc)ephy_embed_shell_unwatch_web_extension, application);
g_object_unref (ephy_embed_prefs_get_web_view_group ());
ephy_embed_utils_shutdown ();
}
static void
ephy_embed_shell_set_property (GObject *object,
guint prop_id,
const GValue *value,
GParamSpec *pspec)
{
EphyEmbedShell *embed_shell = EPHY_EMBED_SHELL (object);
switch (prop_id) {
case PROP_MODE:
embed_shell->priv->mode = g_value_get_enum (value);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
}
}
static void
ephy_embed_shell_get_property (GObject *object,
guint prop_id,
GValue *value,
GParamSpec *pspec)
{
EphyEmbedShell *embed_shell = EPHY_EMBED_SHELL (object);
switch (prop_id) {
case PROP_MODE:
g_value_set_enum (value, embed_shell->priv->mode);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
}
}
static void
ephy_embed_shell_init (EphyEmbedShell *shell)
{
shell->priv = EPHY_EMBED_SHELL_GET_PRIVATE (shell);
/* globally accessible singleton */
g_assert (embed_shell == NULL);
embed_shell = shell;
}
static void
ephy_embed_shell_class_init (EphyEmbedShellClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
GApplicationClass *application_class = G_APPLICATION_CLASS (klass);
object_class->dispose = ephy_embed_shell_dispose;
object_class->set_property = ephy_embed_shell_set_property;
object_class->get_property = ephy_embed_shell_get_property;
application_class->startup = ephy_embed_shell_startup;
application_class->shutdown = ephy_embed_shell_shutdown;
object_properties[PROP_MODE] =
g_param_spec_enum ("mode",
"Mode",
"The global mode for this instance.",
EPHY_TYPE_EMBED_SHELL_MODE,
EPHY_EMBED_SHELL_MODE_BROWSER,
G_PARAM_READWRITE | G_PARAM_STATIC_NAME | G_PARAM_STATIC_NICK |
G_PARAM_STATIC_BLURB | G_PARAM_CONSTRUCT_ONLY);
g_object_class_install_properties (object_class,
N_PROPERTIES,
object_properties);
/**
* EphyEmbed::prepare-close:
* @shell: the #EphyEmbedShell
*
* The ::prepare-close signal is emitted when epiphany is preparing to
* quit on command from the session manager. You can use it when you need
* to do something special (shut down a service, for example).
**/
signals[PREPARE_CLOSE] =
g_signal_new ("prepare-close",
EPHY_TYPE_EMBED_SHELL,
G_SIGNAL_RUN_FIRST | G_SIGNAL_RUN_LAST,
G_STRUCT_OFFSET (EphyEmbedShellClass, prepare_close),
NULL, NULL,
g_cclosure_marshal_VOID__VOID,
G_TYPE_NONE, 0);
/**
* EphyEmbedShell::finished-restoring-window:
* @shell: the #EphyEmbedShell
*
* The ::finished-restoring-window signal is emitted when the
* session finishes restoring a window.
**/
signals[RESTORED_WINDOW] =
g_signal_new ("window-restored",
EPHY_TYPE_EMBED_SHELL,
G_SIGNAL_RUN_FIRST,
G_STRUCT_OFFSET (EphyEmbedShellClass, restored_window),
NULL, NULL,
g_cclosure_marshal_VOID__VOID,
G_TYPE_NONE,
0);
/**
* EphyEmbedShell::web-view-created:
* @shell: the #EphyEmbedShell
* @view: the newly created #EphyWebView
*
* The ::web-view-created signal will be emitted every time a new
* #EphyWebView is created.
*
**/
signals[WEB_VIEW_CREATED] =
g_signal_new ("web-view-created",
EPHY_TYPE_EMBED_SHELL,
G_SIGNAL_RUN_LAST,
0, NULL, NULL,
g_cclosure_marshal_VOID__OBJECT,
G_TYPE_NONE, 1,
EPHY_TYPE_WEB_VIEW);
/**
* EphyEmbedShell::page-created:
* @shell: the #EphyEmbedShell
* @page_id: the identifier of the web page created
* @web_extension: the #EphyWebExtensionProxy
*
* Emitted when a web page is created in the web process.
*/
signals[PAGE_CREATED] =
g_signal_new ("page-created",
EPHY_TYPE_EMBED_SHELL,
G_SIGNAL_RUN_FIRST,
0, NULL, NULL,
g_cclosure_marshal_generic,
G_TYPE_NONE, 2,
G_TYPE_UINT64,
EPHY_TYPE_WEB_EXTENSION_PROXY);
g_type_class_add_private (object_class, sizeof (EphyEmbedShellPrivate));
}
/**
* ephy_embed_shell_get_default:
*
* Retrieves the default #EphyEmbedShell object
*
* Return value: (transfer none): the default #EphyEmbedShell
**/
EphyEmbedShell *
ephy_embed_shell_get_default (void)
{
return embed_shell;
}
void
ephy_embed_shell_set_page_setup (EphyEmbedShell *shell,
GtkPageSetup *page_setup)
{
EphyEmbedShellPrivate *priv;
char *path;
g_return_if_fail (EPHY_IS_EMBED_SHELL (shell));
priv = shell->priv;
if (page_setup != NULL)
g_object_ref (page_setup);
else
page_setup = gtk_page_setup_new ();
if (priv->page_setup != NULL)
g_object_unref (priv->page_setup);
priv->page_setup = page_setup;
path = g_build_filename (ephy_dot_dir (), PAGE_SETUP_FILENAME, NULL);
gtk_page_setup_to_file (page_setup, path, NULL);
g_free (path);
}
/**
* ephy_embed_shell_get_page_setup:
*
* Return value: (transfer none):
**/
GtkPageSetup *
ephy_embed_shell_get_page_setup (EphyEmbedShell *shell)
{
EphyEmbedShellPrivate *priv;
g_return_val_if_fail (EPHY_IS_EMBED_SHELL (shell), NULL);
priv = shell->priv;
if (priv->page_setup == NULL) {
GError *error = NULL;
char *path;
path = g_build_filename (ephy_dot_dir (), PAGE_SETUP_FILENAME, NULL);
priv->page_setup = gtk_page_setup_new_from_file (path, &error);
g_free (path);
if (error)
g_error_free (error);
/* If that still didn't work, create a new, empty one */
if (priv->page_setup == NULL)
priv->page_setup = gtk_page_setup_new ();
}
return priv->page_setup;
}
/**
* ephy_embed_shell_set_print_settings:
* @shell: the #EphyEmbedShell
* @settings: the new #GtkPrintSettings object
*
* Sets the global #GtkPrintSettings object.
*
**/
void
ephy_embed_shell_set_print_settings (EphyEmbedShell *shell,
GtkPrintSettings *settings)
{
EphyEmbedShellPrivate *priv;
char *path;
g_return_if_fail (EPHY_IS_EMBED_SHELL (shell));
priv = shell->priv;
if (settings != NULL)
g_object_ref (settings);
if (priv->print_settings != NULL)
g_object_unref (priv->print_settings);
priv->print_settings = settings ? settings : gtk_print_settings_new ();
path = g_build_filename (ephy_dot_dir (), PRINT_SETTINGS_FILENAME, NULL);
gtk_print_settings_to_file (settings, path, NULL);
g_free (path);
}
/**
* ephy_embed_shell_get_print_settings:
* @shell: the #EphyEmbedShell
*
* Gets the global #GtkPrintSettings object.
*
* Returns: (transfer none): a #GtkPrintSettings object
**/
GtkPrintSettings *
ephy_embed_shell_get_print_settings (EphyEmbedShell *shell)
{
EphyEmbedShellPrivate *priv;
g_return_val_if_fail (EPHY_IS_EMBED_SHELL (shell), NULL);
priv = shell->priv;
if (priv->print_settings == NULL) {
GError *error = NULL;
char *path;
path = g_build_filename (ephy_dot_dir (), PRINT_SETTINGS_FILENAME, NULL);
priv->print_settings = gtk_print_settings_new_from_file (path, &error);
g_free (path);
/* Note: the gtk print settings file format is the same as our
* legacy one, so no need to migrate here.
*/
if (priv->print_settings == NULL)
priv->print_settings = gtk_print_settings_new ();
}
return priv->print_settings;
}
/**
* ephy_embed_shell_get_mode:
* @shell: an #EphyEmbedShell
*
* Returns: the global mode of the @shell
**/
EphyEmbedShellMode
ephy_embed_shell_get_mode (EphyEmbedShell *shell)
{
g_return_val_if_fail (EPHY_IS_EMBED_SHELL (shell), EPHY_EMBED_SHELL_MODE_BROWSER);
return shell->priv->mode;
}
/**
* ephy_embed_shell_launch_handler:
* @shell: an #EphyEmbedShell
* @file: a #GFile to open
* @mime_type: the mime type of @file or %NULL
* @user_time: user time to prevent focus stealing
*
* Tries to open @file with the right application, making sure we will
* not call ourselves in the process. This is needed to avoid
* potential infinite loops when opening unknown file types.
*
* Returns: %TRUE on success
**/
gboolean
ephy_embed_shell_launch_handler (EphyEmbedShell *shell,
GFile *file,
const char *mime_type,
guint32 user_time)
{
GAppInfo *app;
GList *list = NULL;
gboolean ret = FALSE;
g_return_val_if_fail (EPHY_IS_EMBED_SHELL (shell), FALSE);
g_return_val_if_fail (file || mime_type, FALSE);
app = ephy_file_launcher_get_app_info_for_file (file, mime_type);
/* Do not allow recursive calls into the browser, they can lead to
* infinite loops and they should never happen anyway. */
/* FIXME: eventually there should be a nice and safe way of getting
* the app ID from the GApplication itself, but for now let's
* hardcode the .desktop file name and use it here. */
if (!app || g_strcmp0 (g_app_info_get_id (app), "epiphany.desktop") == 0)
return ret;
list = g_list_append (list, file);
ret = ephy_file_launch_application (app, list, user_time, NULL);
g_list_free (list);
return ret;
}
/**
* ephy_embed_shell_clear_cache:
* @shell: an #EphyEmbedShell
*
* Clears the HTTP cache (temporarily saved web pages).
**/
void
ephy_embed_shell_clear_cache (EphyEmbedShell *shell)
{
webkit_web_context_clear_cache (webkit_web_context_get_default ());
}
|