aboutsummaryrefslogtreecommitdiffstats
path: root/embed/xulrunner/src/gecko-embed.cpp
blob: 6ad9a3ae4852f09e751268a98bfcbcba9b86a11a (plain) (blame)
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
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
/*
 *  Copyright © Christopher Blizzard
 *  Copyright © Ramiro Estrugo
 *  Copyright © 2006 Christian Persch
 *
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU Lesser General Public License as published by
 *  the Free Software Foundation; either version 2.1, 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 Lesser General Public License for more details.
 *
 *  You should have received a copy of the GNU Lesser General Public License
 *  along with this program; if not, write to the Free Software
 *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 *
 *  ---------------------------------------------------------------------------
 *  Derived from Mozilla.org code, which had the following attributions:
 *
 *  The Original Code is mozilla.org code.
 *
 *  The Initial Developer of the Original Code is
 *  Christopher Blizzard. Portions created by Christopher Blizzard are Copyright © Christopher Blizzard.  All Rights Reserved.
 *  Portions created by the Initial Developer are Copyright © 2001
 *  the Initial Developer. All Rights Reserved.
 *
 *  Contributor(s):
 *    Christopher Blizzard <blizzard@mozilla.org>
 *    Ramiro Estrugo <ramiro@eazel.com>
 *  ---------------------------------------------------------------------------
 *
 *  $Id$
 */

#include <xpcom-config.h>
#include "config.h"

#include "gecko-embed.h"
#include "gecko-embed-private.h"
#include "gecko-embed-signals.h"
#include "gecko-embed-marshal.h"
#include "gecko-embed-single.h"
#include "gecko-embed-types.h"

#include "gecko-dom-event.h"

#include "GeckoBrowser.h"
#include "EmbedWindow.h"

#ifdef XPCOM_GLUE
#include "nsXPCOMGlue.h"
#endif

// so we can do our get_nsIWebBrowser later...
#include <nsIWebBrowser.h>

#include <stdio.h>

#define GET_OBJECT_CLASS_TYPE(x) G_OBJECT_CLASS_TYPE(x)

class nsIDirectoryServiceProvider;

// class and instance initialization

static void gecko_embed_class_init (GeckoEmbedClass *klass);
static void gecko_embed_init       (GeckoEmbed *embed);

// GtkObject methods

static void gecko_embed_destroy(GtkObject *object);

// GtkWidget methods

static void gecko_embed_realize(GtkWidget *widget);

static void gecko_embed_unrealize(GtkWidget *widget);

static void gecko_embed_size_allocate(GtkWidget *widget, GtkAllocation *allocation);

static void gecko_embed_map(GtkWidget *widget);

static void gecko_embed_unmap(GtkWidget *widget);

#ifdef MOZ_ACCESSIBILITY_ATK
static AtkObject* gecko_embed_get_accessible (GtkWidget *widget);
#endif

static gint handle_child_focus_in(GtkWidget     *aWidget,
              GdkEventFocus *aGdkFocusEvent,
              GeckoEmbed   *aEmbed);

static gint handle_child_focus_out(GtkWidget     *aWidget,
               GdkEventFocus *aGdkFocusEvent,
               GeckoEmbed   *aEmbed);

static PRInt32 sWidgetCount;

// globals for this type of widget

static GtkBinClass *parent_class;

guint gecko_embed_signals[LAST_EMBED_SIGNAL] = { 0 };

// GtkObject + class-related functions

#define GECKO_EMBED_GET_PRIVATE(object)(G_TYPE_INSTANCE_GET_PRIVATE ((object), GECKO_TYPE_EMBED, GeckoEmbedPrivate))

struct _GeckoEmbedPrivate
{
  GeckoBrowser *browser;
};

GType
gecko_embed_get_type(void)
{
  static GType type = 0;

  if (!type)
  {
    const GTypeInfo info =
    {
      sizeof (GeckoEmbedClass),
      NULL, /* base_init */
      NULL, /* base_finalize */
      (GClassInitFunc) gecko_embed_class_init,
      NULL,
      NULL, /* class_data */
      sizeof (GeckoEmbed),
      0, /* n_preallocs */
      (GInstanceInitFunc) gecko_embed_init
    };

    type = g_type_register_static (GTK_TYPE_BIN, "GeckoEmbed",
                       &info, (GTypeFlags) 0);
  }

  return type;
}


/* GObject methods */

#define GET_BROWSER(x)  (((GeckoEmbed *) x)->priv->browser)

// FIXME split in dispose and finalize
static void
gecko_embed_destroy(GtkObject *object)
{
  GeckoEmbed *embed = GECKO_EMBED (object);
  GeckoBrowser *browser = GET_BROWSER (object);

  if (browser) {

    // Destroy the widget only if it's been Init()ed.
    if(browser->mMozWindowWidget != 0) {
      browser->Destroy();
    }

    delete browser;
    embed->priv->browser = NULL;
  }

  gecko_embed_single_pop_startup();
}

// GtkWidget methods

static void
gecko_embed_realize(GtkWidget *widget)
{
  GeckoEmbed *embed = GECKO_EMBED (widget);
  GeckoEmbedPrivate *priv = embed->priv;
  GeckoBrowser *browser = GET_BROWSER (widget);
  GtkWidget *toplevel = gtk_widget_get_toplevel (widget);
  GdkWindowAttr attributes;
  int attributes_mask;

  GTK_WIDGET_SET_FLAGS(widget, GTK_REALIZED);

  attributes.window_type = GDK_WINDOW_CHILD;
  attributes.x = widget->allocation.x;
  attributes.y = widget->allocation.y;
  attributes.width = widget->allocation.width;
  attributes.height = widget->allocation.height;
  attributes.wclass = GDK_INPUT_OUTPUT;
  attributes.visual = gtk_widget_get_visual (widget);
  attributes.colormap = gtk_widget_get_colormap (widget);
  attributes.event_mask = gtk_widget_get_events (widget) | GDK_EXPOSURE_MASK;

  attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL | GDK_WA_COLORMAP;

  widget->window = gdk_window_new (gtk_widget_get_parent_window (widget),
                   &attributes, attributes_mask);
  gdk_window_set_user_data (widget->window, embed);

  widget->style = gtk_style_attach (widget->style, widget->window);
  gtk_style_set_background (widget->style, widget->window, GTK_STATE_NORMAL);

  // initialize the window
  nsresult rv;
  rv = browser->Init(embed);
  g_return_if_fail(NS_SUCCEEDED(rv));
  
  PRBool alreadyRealized = PR_FALSE;
  rv = browser->Realize(&alreadyRealized);
  g_return_if_fail(NS_SUCCEEDED(rv));

  // if we're already realized we don't need to hook up to anything below
  if (alreadyRealized)
    return;

  browser->LoadCurrentURI();

  GtkWidget *child_widget = GTK_BIN (widget)->child;
  g_signal_connect_object (child_widget, "focus_in_event",
                           G_CALLBACK (handle_child_focus_in), embed,
                           (GConnectFlags) 0);
  g_signal_connect_object (child_widget, "focus_out_event",
                           G_CALLBACK (handle_child_focus_out), embed,
                           (GConnectFlags) 0);
#if 0
  // connect to the focus out event for the child
  gtk_signal_connect_while_alive(GTK_OBJECT(child_widget),
                 "focus_out_event",
                 GTK_SIGNAL_FUNC(handle_child_focus_out),
                 embed,
                 GTK_OBJECT(child_widget));
  gtk_signal_connect_while_alive(GTK_OBJECT(child_widget),
                 "focus_in_event",
                 GTK_SIGNAL_FUNC(handle_child_focus_in),
                 embed,
                 GTK_OBJECT(child_widget));
#endif
}

static void
gecko_embed_unrealize(GtkWidget *widget)
{
  GeckoEmbed *embed = GECKO_EMBED (widget);
  GeckoEmbedPrivate *priv = embed->priv;
  GeckoBrowser *browser = GET_BROWSER (widget);
  GtkWidget *toplevel = gtk_widget_get_toplevel (widget);

  if (browser) {
    browser->Unrealize();
  }

  if (GTK_WIDGET_CLASS(parent_class)->unrealize)
    GTK_WIDGET_CLASS(parent_class)->unrealize (widget);
}

static void
gecko_embed_size_allocate (GtkWidget *widget,
                           GtkAllocation *allocation)
{
  GeckoEmbed *embed = GECKO_EMBED (widget);
  GeckoBrowser *browser = GET_BROWSER (widget);
  
  widget->allocation = *allocation;

  if (GTK_WIDGET_REALIZED(widget))
  {
    gdk_window_move_resize(widget->window,
               allocation->x, allocation->y,
               allocation->width, allocation->height);

    browser->Resize(allocation->width, allocation->height);
  }
}

static void
gecko_embed_map (GtkWidget *widget)
{
  GeckoEmbed *embed = GECKO_EMBED (widget);
  GeckoBrowser *browser = GET_BROWSER (widget);

  GTK_WIDGET_SET_FLAGS(widget, GTK_MAPPED);

  browser->Show();

  gdk_window_show(widget->window);
  
}

static void
gecko_embed_unmap (GtkWidget *widget)
{
  GeckoEmbed *embed = GECKO_EMBED (widget);
  GeckoBrowser *browser = GET_BROWSER (widget);

  GTK_WIDGET_UNSET_FLAGS(widget, GTK_MAPPED);

  gdk_window_hide(widget->window);

  browser->Hide();
}

#ifdef MOZ_ACCESSIBILITY_ATK
static AtkObject*
gecko_embed_get_accessible (GtkWidget *widget)
{
  GeckoEmbed *embed = GECKO_EMBED (widget);
  GeckoBrowser *browser = GET_BROWSER (widget);

  return static_cast<AtkObject *>
                    (browser->GetAtkObjectForCurrentDocument());
}
#endif /* MOZ_ACCESSIBILITY_ATK */

static gint
handle_child_focus_in (GtkWidget     *aWidget,
               GdkEventFocus *aGdkFocusEvent,
               GeckoEmbed   *aEmbed)
{
  GeckoBrowser *browser = GET_BROWSER (aEmbed);

  browser->ChildFocusIn();

  return FALSE;
}

static gint
handle_child_focus_out (GtkWidget     *aWidget,
                GdkEventFocus *aGdkFocusEvent,
                GeckoEmbed   *aEmbed)
{
  GeckoBrowser *browser = GET_BROWSER (aEmbed);

  browser->ChildFocusOut();
 
  return FALSE;
}

// Widget methods

void
gecko_embed_load_url (GeckoEmbed *embed,
                      const char *url)
{
  GeckoBrowser *browser;
  
  g_return_if_fail(embed != NULL);
  g_return_if_fail(GECKO_IS_EMBED(embed));

  browser = GET_BROWSER (embed);

  browser->SetURI(url);

  // If the widget is realized, load the URI.  If it isn't then we
  // will load it later.
  if (GTK_WIDGET_REALIZED(embed))
    browser->LoadCurrentURI();
}

void
gecko_embed_stop_load (GeckoEmbed *embed)
{
  GeckoBrowser *browser;
  
  g_return_if_fail(GECKO_IS_EMBED(embed));

  browser = GET_BROWSER (embed);

  if (browser->mNavigation)
    browser->mNavigation->Stop(nsIWebNavigation::STOP_ALL);
}

gboolean
gecko_embed_can_go_back (GeckoEmbed *embed)
{
  PRBool retval = PR_FALSE;
  GeckoBrowser *browser;

  g_return_val_if_fail (GECKO_IS_EMBED(embed), FALSE);

  browser = GET_BROWSER (embed);

  if (browser->mNavigation)
    browser->mNavigation->GetCanGoBack(&retval);
  return retval;
}

gboolean
gecko_embed_can_go_forward (GeckoEmbed *embed)
{
  PRBool retval = PR_FALSE;
  GeckoBrowser *browser;

  g_return_val_if_fail (GECKO_IS_EMBED(embed), FALSE);

  browser = GET_BROWSER (embed);

  if (browser->mNavigation)
    browser->mNavigation->GetCanGoForward(&retval);
  return retval;
}

void
gecko_embed_go_back (GeckoEmbed *embed)
{
  GeckoBrowser *browser;

  g_return_if_fail (GECKO_IS_EMBED(embed));

  browser = GET_BROWSER (embed);

  if (browser->mNavigation)
    browser->mNavigation->GoBack();
}

void
gecko_embed_go_forward (GeckoEmbed *embed)
{
  GeckoBrowser *browser;

  g_return_if_fail (GECKO_IS_EMBED(embed));

  browser = GET_BROWSER (embed);

  if (browser->mNavigation)
    browser->mNavigation->GoForward();
}

void
gecko_embed_render_data (GeckoEmbed *embed, const char *data,
             guint32 len, const char *base_uri,
             const char *mime_type)
{
  GeckoBrowser *browser;

  g_return_if_fail (GECKO_IS_EMBED(embed));

  browser = GET_BROWSER (embed);

#if 0
  browser->OpenStream(base_uri, mime_type);
  browser->AppendToStream(data, len);
  browser->CloseStream();
#endif
}

void
gecko_embed_open_stream (GeckoEmbed *embed, const char *base_uri,
             const char *mime_type)
{
  GeckoBrowser *browser;

  g_return_if_fail (GECKO_IS_EMBED(embed));
  g_return_if_fail (GTK_WIDGET_REALIZED(GTK_WIDGET(embed)));

  browser = GET_BROWSER (embed);

#if 0
  browser->OpenStream(base_uri, mime_type);
#endif
}

void gecko_embed_append_data (GeckoEmbed *embed, const char *data,
                  guint32 len)
{
  GeckoBrowser *browser;

  g_return_if_fail (GECKO_IS_EMBED(embed));
  g_return_if_fail (GTK_WIDGET_REALIZED(GTK_WIDGET(embed)));

  browser = GET_BROWSER (embed);
#if 0
  browser->AppendToStream(data, len);
#endif
}

void
gecko_embed_close_stream (GeckoEmbed *embed)
{
  GeckoBrowser *browser;

  g_return_if_fail (GECKO_IS_EMBED(embed));
  g_return_if_fail (GTK_WIDGET_REALIZED(GTK_WIDGET(embed)));

  browser = GET_BROWSER (embed);
#if 0
  browser->CloseStream();
#endif
}

char *
gecko_embed_get_link_message (GeckoEmbed *embed)
{
  char *retval = nsnull;
  GeckoBrowser *browser;
  nsEmbedCString tmpCString;

  g_return_val_if_fail (GECKO_IS_EMBED(embed), (char *)NULL);

  browser = GET_BROWSER (embed);

  if (browser->mWindow) {
    NS_UTF16ToCString(browser->mWindow->mLinkMessage,
                      NS_CSTRING_ENCODING_UTF8, tmpCString);
    retval = g_strdup(tmpCString.get());
  }

  return retval;
}

char *
gecko_embed_get_js_status (GeckoEmbed *embed)
{
  char *retval = nsnull;
  GeckoBrowser *browser;
  nsEmbedCString tmpCString;

  g_return_val_if_fail (GECKO_IS_EMBED(embed), (char *)NULL);

  browser = GET_BROWSER (embed);

  if (browser->mWindow) {
    NS_UTF16ToCString(browser->mWindow->mJSStatus,
                      NS_CSTRING_ENCODING_UTF8, tmpCString);
    retval = g_strdup(tmpCString.get());
  }

  return retval;
}

char *
gecko_embed_get_title (GeckoEmbed *embed)
{
  char *retval = nsnull;
  GeckoBrowser *browser;
  nsEmbedCString tmpCString;

  g_return_val_if_fail (GECKO_IS_EMBED(embed), (char *)NULL);

  browser = GET_BROWSER (embed);

  if (browser->mWindow) {
    NS_UTF16ToCString(browser->mWindow->mTitle,
                      NS_CSTRING_ENCODING_UTF8, tmpCString);
    retval = g_strdup(tmpCString.get());
  }

  return retval;
}

char *
gecko_embed_get_location (GeckoEmbed *embed)
{
  char *retval = nsnull;
  GeckoBrowser *browser;

  g_return_val_if_fail (GECKO_IS_EMBED(embed), (char *)NULL);

  browser = GET_BROWSER (embed);
  
  if (browser->mURI.Length()) {
    retval = g_strdup(browser->mURI.get());
  }

  return retval;
}

void
gecko_embed_reload (GeckoEmbed *embed,
                    gint32 flags)
{
  GeckoBrowser *browser;

  g_return_if_fail (GECKO_IS_EMBED(embed));

  browser = GET_BROWSER (embed);

  PRUint32 reloadFlags = 0;
  
  // map the external API to the internal web navigation API.
  switch (flags) {
  case GECKO_EMBED_FLAG_RELOADNORMAL:
    reloadFlags = 0;
    break;
  case GECKO_EMBED_FLAG_RELOADBYPASSCACHE:
    reloadFlags = nsIWebNavigation::LOAD_FLAGS_BYPASS_CACHE;
    break;
  case GECKO_EMBED_FLAG_RELOADBYPASSPROXY:
    reloadFlags = nsIWebNavigation::LOAD_FLAGS_BYPASS_PROXY;
    break;
  case GECKO_EMBED_FLAG_RELOADBYPASSPROXYANDCACHE:
    reloadFlags = (nsIWebNavigation::LOAD_FLAGS_BYPASS_PROXY |
           nsIWebNavigation::LOAD_FLAGS_BYPASS_CACHE);
    break;
  case GECKO_EMBED_FLAG_RELOADCHARSETCHANGE:
    reloadFlags = nsIWebNavigation::LOAD_FLAGS_CHARSET_CHANGE;
    break;
  default:
    reloadFlags = 0;
    break;
  }

  browser->Reload(reloadFlags);
}

void
gecko_embed_set_chrome_mask (GeckoEmbed *embed,
                             guint32 flags)
{
  GeckoBrowser *browser;

  g_return_if_fail (GECKO_IS_EMBED(embed));

  browser = GET_BROWSER (embed);

  browser->SetChromeMask(flags);
}

guint32
gecko_embed_get_chrome_mask (GeckoEmbed *embed)
{
  GeckoBrowser *browser;

  g_return_val_if_fail (GECKO_IS_EMBED(embed), 0);

  browser = GET_BROWSER (embed);

  return browser->mChromeMask;
}

void
gecko_embed_get_nsIWebBrowser (GeckoEmbed *embed,
                               nsIWebBrowser **retval)
{
  GeckoBrowser *browser;
  *retval = nsnull;

  g_return_if_fail (GECKO_IS_EMBED (embed));

  browser = GET_BROWSER (embed);
  
  if (browser->mWindow)
    browser->mWindow->GetWebBrowser(retval);
}

GeckoBrowser *
gecko_embed_get_GeckoBrowser (GeckoEmbed *embed)
{
  g_return_val_if_fail (GECKO_IS_EMBED (embed), nsnull);

  return GET_BROWSER (embed);
}

static void
gecko_embed_init (GeckoEmbed *embed)
{
  embed->priv = GECKO_EMBED_GET_PRIVATE (embed);

  embed->priv->browser = new GeckoBrowser();
  g_return_if_fail (embed->priv->browser);

  gtk_widget_set_name (GTK_WIDGET (embed), "gecko_embed");

  GTK_WIDGET_UNSET_FLAGS(GTK_WIDGET(embed), GTK_NO_WINDOW);
}

static void
gecko_embed_class_init (GeckoEmbedClass *klass)
{
  GtkObjectClass *object_class = GTK_OBJECT_CLASS (klass); // FIXME GObject
  GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
  GtkContainerClass *container_class = GTK_CONTAINER_CLASS (klass);

  parent_class = (GtkBinClass *) g_type_class_peek_parent (klass);

  object_class->destroy = gecko_embed_destroy;
  
  widget_class->realize = gecko_embed_realize;
  widget_class->unrealize = gecko_embed_unrealize;
  widget_class->size_allocate = gecko_embed_size_allocate;
  widget_class->map = gecko_embed_map;
  widget_class->unmap = gecko_embed_unmap;

#ifdef MOZ_ACCESSIBILITY_ATK
  widget_class->get_accessible = gecko_embed_get_accessible;
#endif

  GType dom_param_types[1] = { GECKO_TYPE_DOM_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE };

  gecko_embed_signals[DOM_KEY_DOWN] =
    g_signal_newv ("dom-key-down",
                   GECKO_TYPE_EMBED,
                   (GSignalFlags) (G_SIGNAL_RUN_FIRST | G_SIGNAL_RUN_LAST),
                   NULL,
                   g_signal_accumulator_true_handled, NULL,
                   gecko_embed_marshal_BOOLEAN__BOXED,
                   G_TYPE_BOOLEAN,
                   G_N_ELEMENTS (dom_param_types),
           dom_param_types);

  gecko_embed_signals[DOM_KEY_PRESS] =
    g_signal_newv ("dom-key-press",
                   GECKO_TYPE_EMBED,
                   (GSignalFlags) (G_SIGNAL_RUN_FIRST | G_SIGNAL_RUN_LAST),
                   NULL,
                   g_signal_accumulator_true_handled, NULL,
                   gecko_embed_marshal_BOOLEAN__BOXED,
                   G_TYPE_BOOLEAN,
                   G_N_ELEMENTS (dom_param_types),
           dom_param_types);

  gecko_embed_signals[DOM_KEY_UP] =
    g_signal_newv ("dom-key-up",
                   GECKO_TYPE_EMBED,
                   (GSignalFlags) (G_SIGNAL_RUN_FIRST | G_SIGNAL_RUN_LAST),
                   NULL,
                   g_signal_accumulator_true_handled, NULL,
                   gecko_embed_marshal_BOOLEAN__BOXED,
                   G_TYPE_BOOLEAN,
                   G_N_ELEMENTS (dom_param_types),
           dom_param_types);

  gecko_embed_signals[DOM_MOUSE_DOWN] =
    g_signal_newv ("dom-mouse-down",
                   GECKO_TYPE_EMBED,
                   (GSignalFlags) (G_SIGNAL_RUN_FIRST | G_SIGNAL_RUN_LAST),
                   NULL,
                   g_signal_accumulator_true_handled, NULL,
                   gecko_embed_marshal_BOOLEAN__BOXED,
                   G_TYPE_BOOLEAN,
                   G_N_ELEMENTS (dom_param_types),
           dom_param_types);

  gecko_embed_signals[DOM_MOUSE_UP] =
    g_signal_newv ("dom-mouse-up",
                   GECKO_TYPE_EMBED,
                   (GSignalFlags) (G_SIGNAL_RUN_FIRST | G_SIGNAL_RUN_LAST),
                   NULL,
                   g_signal_accumulator_true_handled, NULL,
                   gecko_embed_marshal_BOOLEAN__BOXED,
                   G_TYPE_BOOLEAN,
                   G_N_ELEMENTS (dom_param_types),
           dom_param_types);

  gecko_embed_signals[DOM_MOUSE_CLICK] =
    g_signal_newv ("dom-mouse-click",
                   GECKO_TYPE_EMBED,
                   (GSignalFlags) (G_SIGNAL_RUN_FIRST | G_SIGNAL_RUN_LAST),
                   NULL,
                   g_signal_accumulator_true_handled, NULL,
                   gecko_embed_marshal_BOOLEAN__BOXED,
                   G_TYPE_BOOLEAN,
                   G_N_ELEMENTS (dom_param_types),
           dom_param_types);

  gecko_embed_signals[DOM_MOUSE_DOUBLE_CLICK] =
    g_signal_newv ("dom-mouse-dbl-click",
                   GECKO_TYPE_EMBED,
                   (GSignalFlags) (G_SIGNAL_RUN_FIRST | G_SIGNAL_RUN_LAST),
                   NULL,
                   g_signal_accumulator_true_handled, NULL,
                   gecko_embed_marshal_BOOLEAN__BOXED,
                   G_TYPE_BOOLEAN,
                   G_N_ELEMENTS (dom_param_types),
           dom_param_types);

  gecko_embed_signals[DOM_MOUSE_OVER] =
    g_signal_newv ("dom-mouse-over",
                   GECKO_TYPE_EMBED,
                   (GSignalFlags) (G_SIGNAL_RUN_FIRST | G_SIGNAL_RUN_LAST),
                   NULL,
                   g_signal_accumulator_true_handled, NULL,
                   gecko_embed_marshal_BOOLEAN__BOXED,
                   G_TYPE_BOOLEAN,
                   G_N_ELEMENTS (dom_param_types),
           dom_param_types);

  gecko_embed_signals[DOM_MOUSE_OUT] =
    g_signal_newv ("dom-mouse-out",
                   GECKO_TYPE_EMBED,
                   (GSignalFlags) (G_SIGNAL_RUN_FIRST | G_SIGNAL_RUN_LAST),
                   NULL,
                   g_signal_accumulator_true_handled, NULL,
                   gecko_embed_marshal_BOOLEAN__BOXED,
                   G_TYPE_BOOLEAN,
                   G_N_ELEMENTS (dom_param_types),
           dom_param_types);

  gecko_embed_signals[DOM_MOUSE_OUT] =
    g_signal_newv ("dom-focus-in",
                   GECKO_TYPE_EMBED,
                   (GSignalFlags) (G_SIGNAL_RUN_FIRST | G_SIGNAL_RUN_LAST),
                   NULL,
                   g_signal_accumulator_true_handled, NULL,
                   gecko_embed_marshal_BOOLEAN__BOXED,
                   G_TYPE_BOOLEAN,
                   G_N_ELEMENTS (dom_param_types),
           dom_param_types);

  gecko_embed_signals[DOM_MOUSE_OUT] =
    g_signal_newv ("dom-focus-out",
                   GECKO_TYPE_EMBED,
                   (GSignalFlags) (G_SIGNAL_RUN_FIRST | G_SIGNAL_RUN_LAST),
                   NULL,
                   g_signal_accumulator_true_handled, NULL,
                   gecko_embed_marshal_BOOLEAN__BOXED,
                   G_TYPE_BOOLEAN,
                   G_N_ELEMENTS (dom_param_types),
           dom_param_types);

  gecko_embed_signals[DOM_MOUSE_OUT] =
    g_signal_newv ("dom-activate",
                   GECKO_TYPE_EMBED,
                   (GSignalFlags) (G_SIGNAL_RUN_FIRST | G_SIGNAL_RUN_LAST),
                   NULL,
                   g_signal_accumulator_true_handled, NULL,
                   gecko_embed_marshal_BOOLEAN__BOXED,
                   G_TYPE_BOOLEAN,
                   G_N_ELEMENTS (dom_param_types),
           dom_param_types);

  gecko_embed_signals[DOM_CONTEXT_MENU] =
    g_signal_newv ("dom-context-menu",
                   GECKO_TYPE_EMBED,
                   (GSignalFlags) (G_SIGNAL_RUN_FIRST | G_SIGNAL_RUN_LAST),
                   NULL,
                   g_signal_accumulator_true_handled, NULL,
                   gecko_embed_marshal_BOOLEAN__BOXED,
                   G_TYPE_BOOLEAN,
                   G_N_ELEMENTS (dom_param_types),
           dom_param_types);

  gecko_embed_signals[OPEN_URI] =
    g_signal_new ("open_uri",
                  GECKO_TYPE_EMBED,
                  (GSignalFlags) (G_SIGNAL_RUN_FIRST | G_SIGNAL_RUN_LAST),
                  G_STRUCT_OFFSET (GeckoEmbedClass, open_uri),
                  g_signal_accumulator_true_handled, NULL,
                  gecko_embed_marshal_BOOLEAN__STRING,
                  G_TYPE_BOOLEAN,
                  1,
                  G_TYPE_STRING);

  gecko_embed_signals[NET_START] =
    g_signal_new ("net_start",
                  GECKO_TYPE_EMBED,
                  (GSignalFlags) (G_SIGNAL_RUN_FIRST | G_SIGNAL_RUN_LAST),
                  G_STRUCT_OFFSET (GeckoEmbedClass, net_start),
                  NULL, NULL,
                  g_cclosure_marshal_VOID__VOID,
                  G_TYPE_NONE,
                  0);

  gecko_embed_signals[NET_STOP] =
    g_signal_new ("net_stop",
                  GECKO_TYPE_EMBED,
                  (GSignalFlags) (G_SIGNAL_RUN_FIRST | G_SIGNAL_RUN_LAST),
                  G_STRUCT_OFFSET (GeckoEmbedClass, net_stop),
                  NULL, NULL,
                  g_cclosure_marshal_VOID__VOID,
                  G_TYPE_NONE,
                  0);

  gecko_embed_signals[NET_STATE] =
    g_signal_new ("net_state",
                  GECKO_TYPE_EMBED,
                  (GSignalFlags) (G_SIGNAL_RUN_FIRST | G_SIGNAL_RUN_LAST),
                  G_STRUCT_OFFSET (GeckoEmbedClass, net_state),
                  NULL, NULL,
                  gecko_embed_marshal_VOID__INT_UINT,
                  G_TYPE_NONE,
                  2,
                  G_TYPE_INT,
                  G_TYPE_UINT);

  gecko_embed_signals[NET_STATE_ALL] =
    g_signal_new ("net_state_all",
                  GECKO_TYPE_EMBED,
                  (GSignalFlags) (G_SIGNAL_RUN_FIRST | G_SIGNAL_RUN_LAST),
                  G_STRUCT_OFFSET (GeckoEmbedClass, net_state_all),
                  NULL, NULL,
                  gecko_embed_marshal_VOID__STRING_INT_UINT,
                  G_TYPE_NONE,
                  3,
                  G_TYPE_STRING,
                  G_TYPE_INT,
                  G_TYPE_UINT); // static scope? to avoid string copy? or G_TYPE_POINTER as 1st?

  gecko_embed_signals[PROGRESS] =
    g_signal_new ("progress",
                  GECKO_TYPE_EMBED,
                  (GSignalFlags) (G_SIGNAL_RUN_FIRST | G_SIGNAL_RUN_LAST),
                  G_STRUCT_OFFSET (GeckoEmbedClass, progress),
                  NULL, NULL,
                  gecko_embed_marshal_VOID__INT_INT,
                  G_TYPE_NONE,
                  2,
                  G_TYPE_INT,
                  G_TYPE_INT);

  gecko_embed_signals[PROGRESS_ALL] =
    g_signal_new ("progress_all",
                  GECKO_TYPE_EMBED,
                  (GSignalFlags) (G_SIGNAL_RUN_FIRST | G_SIGNAL_RUN_LAST),
                  G_STRUCT_OFFSET (GeckoEmbedClass, progress_all),
                  NULL, NULL,
                  gecko_embed_marshal_VOID__STRING_INT_INT,
                  G_TYPE_NONE,
                  3,
                  G_TYPE_STRING,
                  G_TYPE_INT,
                  G_TYPE_INT); // static scope?

  gecko_embed_signals[SECURITY_CHANGE] =
    g_signal_new ("security_change",
                  GECKO_TYPE_EMBED,
                  (GSignalFlags) (G_SIGNAL_RUN_FIRST | G_SIGNAL_RUN_LAST),
                  G_STRUCT_OFFSET (GeckoEmbedClass, security_change),
                  NULL, NULL,
                  gecko_embed_marshal_VOID__POINTER_UINT,
                  G_TYPE_NONE,
                  2,
                  G_TYPE_POINTER,
                  G_TYPE_UINT);

  gecko_embed_signals[STATUS_CHANGE] =
    g_signal_new ("status_change",
                  GECKO_TYPE_EMBED,
                  (GSignalFlags) (G_SIGNAL_RUN_FIRST | G_SIGNAL_RUN_LAST),
                  G_STRUCT_OFFSET (GeckoEmbedClass, status_change),
                  NULL, NULL,
                  gecko_embed_marshal_VOID__POINTER_INT_POINTER,
                  G_TYPE_NONE,
                  3,
                  G_TYPE_POINTER,
                  G_TYPE_INT,
                  G_TYPE_POINTER);

  gecko_embed_signals[LINK_MESSAGE] =
    g_signal_new ("link_message",
                  GECKO_TYPE_EMBED,
                  (GSignalFlags) (G_SIGNAL_RUN_FIRST | G_SIGNAL_RUN_LAST),
                  G_STRUCT_OFFSET (GeckoEmbedClass, link_message),
                  NULL, NULL,
                  g_cclosure_marshal_VOID__VOID,
                  G_TYPE_NONE,
                  0);

  gecko_embed_signals[JS_STATUS] =
    g_signal_new ("js_status",
                  GECKO_TYPE_EMBED,
                  (GSignalFlags) (G_SIGNAL_RUN_FIRST | G_SIGNAL_RUN_LAST),
                  G_STRUCT_OFFSET (GeckoEmbedClass, js_status_message),
                  NULL, NULL,
                  g_cclosure_marshal_VOID__VOID,
                  G_TYPE_NONE,
                  0);

  gecko_embed_signals[LOCATION] =
    g_signal_new ("location",
                  GECKO_TYPE_EMBED,
                  (GSignalFlags) (G_SIGNAL_RUN_FIRST | G_SIGNAL_RUN_LAST),
                  G_STRUCT_OFFSET (GeckoEmbedClass, location),
                  NULL, NULL,
                  g_cclosure_marshal_VOID__VOID,
                  G_TYPE_NONE,
                  0);

  gecko_embed_signals[TITLE] =
    g_signal_new ("title",
                  GECKO_TYPE_EMBED,
                  (GSignalFlags) (G_SIGNAL_RUN_FIRST | G_SIGNAL_RUN_LAST),
                  G_STRUCT_OFFSET (GeckoEmbedClass, title),
                  NULL, NULL,
                  g_cclosure_marshal_VOID__VOID,
                  G_TYPE_NONE,
                  0);

  gecko_embed_signals[VISIBILITY] =
    g_signal_new ("visibility",
                  GECKO_TYPE_EMBED,
                  (GSignalFlags) (G_SIGNAL_RUN_FIRST | G_SIGNAL_RUN_LAST),
                  G_STRUCT_OFFSET (GeckoEmbedClass, visibility),
                  NULL, NULL,
                  g_cclosure_marshal_VOID__BOOLEAN,
                  G_TYPE_NONE,
                  1,
                  G_TYPE_BOOLEAN);

  gecko_embed_signals[DESTROY_BROWSER] =
    g_signal_new ("destroy_browser",
                  GECKO_TYPE_EMBED,
                  (GSignalFlags) (G_SIGNAL_RUN_FIRST | G_SIGNAL_RUN_LAST),
                  G_STRUCT_OFFSET (GeckoEmbedClass, destroy_browser),
                  NULL, NULL,
                  g_cclosure_marshal_VOID__VOID,
                  G_TYPE_NONE,
                  0);

  gecko_embed_signals[SIZE_TO] =
    g_signal_new ("size_to",
                  GECKO_TYPE_EMBED,
                  (GSignalFlags) (G_SIGNAL_RUN_FIRST | G_SIGNAL_RUN_LAST),
                  G_STRUCT_OFFSET (GeckoEmbedClass, size_to),
                  NULL, NULL,
                  gecko_embed_marshal_VOID__INT_INT,
                  G_TYPE_NONE,
                  2,
                  G_TYPE_INT,
                  G_TYPE_INT);

  gecko_embed_signals[NEW_WINDOW] =
    g_signal_new ("new_window",
                  GECKO_TYPE_EMBED,
                  (GSignalFlags) (G_SIGNAL_RUN_FIRST | G_SIGNAL_RUN_LAST),
                  G_STRUCT_OFFSET (GeckoEmbedClass, new_window),
                  NULL, NULL,
                  gecko_embed_marshal_VOID__OBJECT_UINT,
                  G_TYPE_NONE,
                  2,
                  G_TYPE_OBJECT,
                  G_TYPE_UINT);

  g_type_class_add_private (object_class, sizeof (GeckoEmbedPrivate));
}

GtkWidget *
gecko_embed_new (void)
{
  return GTK_WIDGET (g_object_new (GECKO_TYPE_EMBED, NULL));
}