~noskcaj/ubuntu/wily/epiphany-browser/merge

« back to all changes in this revision

Viewing changes to embed/ephy-embed-prefs.c

  • Committer: Package Import Robot
  • Author(s): Emilio Pozuelo Monfort
  • Date: 2013-06-01 20:50:15 UTC
  • mto: (1.10.1) (120.1.3 experimental) (105.1.14 sid)
  • mto: This revision was merged to the branch mainline in revision 121.
  • Revision ID: package-import@ubuntu.com-20130601205015-v8nb09ac39f606e5
Tags: upstream-3.8.2
ImportĀ upstreamĀ versionĀ 3.8.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
48
48
#define ENABLE_SCRIPTS_SETTING "enable-javascript"
49
49
#define DEFAULT_ENCODING_SETTING "default-charset"
50
50
static WebKitSettings *webkit_settings = NULL;
 
51
static WebKitWebViewGroup *web_view_group = NULL;
51
52
#else
52
53
#define ENABLE_SCRIPTS_SETTING "enable-scripts"
53
54
#define DEFAULT_ENCODING_SETTING "default-encoding"
54
55
static WebKitWebSettings *webkit_settings = NULL;
55
56
#endif
56
57
 
 
58
#ifdef HAVE_WEBKIT2
 
59
static void
 
60
user_style_sheet_output_stream_splice_cb (GOutputStream *output_stream,
 
61
                                          GAsyncResult *result,
 
62
                                          gpointer user_data)
 
63
{
 
64
  gssize bytes;
 
65
 
 
66
  bytes = g_output_stream_splice_finish (output_stream, result, NULL);
 
67
  if (bytes > 0) {
 
68
    webkit_web_view_group_add_user_style_sheet (web_view_group,
 
69
                                                g_memory_output_stream_get_data (G_MEMORY_OUTPUT_STREAM (output_stream)),
 
70
                                                NULL, NULL, NULL, WEBKIT_INJECTED_CONTENT_FRAMES_ALL);
 
71
  }
 
72
}
 
73
 
 
74
static void
 
75
user_style_seet_read_cb (GFile *file,
 
76
                         GAsyncResult *result,
 
77
                         gpointer user_data)
 
78
{
 
79
  GFileInputStream *input_stream;
 
80
  GOutputStream *output_stream;
 
81
 
 
82
  input_stream = g_file_read_finish (file, result, NULL);
 
83
  if (!input_stream)
 
84
    return;
 
85
 
 
86
  output_stream = g_memory_output_stream_new_resizable ();
 
87
  g_output_stream_splice_async (output_stream, G_INPUT_STREAM (input_stream),
 
88
                                G_OUTPUT_STREAM_SPLICE_CLOSE_SOURCE |
 
89
                                G_OUTPUT_STREAM_SPLICE_CLOSE_TARGET,
 
90
                                G_PRIORITY_DEFAULT,
 
91
                                NULL,
 
92
                                (GAsyncReadyCallback)user_style_sheet_output_stream_splice_cb,
 
93
                                NULL);
 
94
  g_object_unref (input_stream);
 
95
  g_object_unref (output_stream);
 
96
}
 
97
#endif
 
98
 
57
99
static void
58
100
webkit_pref_callback_user_stylesheet (GSettings *settings,
59
101
                                      char *key,
60
102
                                      gpointer data)
61
103
{
62
 
  gboolean value = FALSE;
 
104
  gboolean value;
 
105
#ifndef HAVE_WEBKIT2
63
106
  char *uri = NULL;
64
 
#ifndef HAVE_WEBKIT2
65
107
  char *webkit_pref = data;
66
108
#endif
67
109
 
68
110
  value = g_settings_get_boolean (settings, key);
69
111
 
 
112
#ifndef HAVE_WEBKIT2
70
113
  if (value)
71
114
    /* We need the leading file://, so use g_strconcat instead
72
115
     * of g_build_filename */
75
118
                       G_DIR_SEPARATOR_S,
76
119
                       USER_STYLESHEET_FILENAME,
77
120
                       NULL);
78
 
#ifdef HAVE_WEBKIT2
79
 
  /* TODO: user-stylesheet-uri setting */
80
 
#else
81
121
  g_object_set (webkit_settings, webkit_pref, uri, NULL);
82
 
#endif
83
122
  g_free (uri);
 
123
#else
 
124
  if (!value)
 
125
    webkit_web_view_group_remove_all_user_style_sheets (web_view_group);
 
126
  else {
 
127
    GFile *file;
 
128
    char *filename;
 
129
 
 
130
    filename = g_build_filename (ephy_dot_dir (), USER_STYLESHEET_FILENAME, NULL);
 
131
    file = g_file_new_for_path (filename);
 
132
    g_free (filename);
 
133
 
 
134
    g_file_read_async (file, G_PRIORITY_DEFAULT, NULL,
 
135
                       (GAsyncReadyCallback)user_style_seet_read_cb, NULL);
 
136
    g_object_unref (file);
 
137
  }
 
138
#endif
84
139
}
85
140
 
86
141
static char *
665
720
      webkit_pref_callback_cookie_accept_policy },
666
721
  };
667
722
 
668
 
#ifdef HAVE_WEBKIT2
669
 
static void
670
 
ephy_embed_prefs_apply (EphyEmbed *embed, WebKitSettings *settings)
671
 
#else
 
723
#ifndef HAVE_WEBKIT2
672
724
static void
673
725
ephy_embed_prefs_apply (EphyEmbed *embed, WebKitWebSettings *settings)
674
 
#endif
675
726
{
676
727
  webkit_web_view_set_settings (EPHY_GET_WEBKIT_WEB_VIEW_FROM_EMBED (embed),
677
728
                                settings);
678
729
}
 
730
#endif
679
731
 
680
732
void
681
733
ephy_embed_prefs_init (void)
682
734
{
683
735
  int i;
684
736
#ifdef HAVE_WEBKIT2
685
 
  webkit_settings = webkit_settings_new_with_settings ("enable-developer-extras", TRUE,
686
 
                                                       "enable-fullscreen", TRUE,
687
 
                                                       "enable-site-specific-quirks", TRUE,
688
 
                                                       "enable-dns-prefetching", TRUE,
689
 
                                                       NULL);
 
737
  web_view_group = webkit_web_view_group_new ("Ephy WebView Group");
 
738
  webkit_settings = webkit_web_view_group_get_settings (web_view_group);
 
739
 
 
740
  g_object_set (webkit_settings,
 
741
                "enable-developer-extras", TRUE,
 
742
                "enable-fullscreen", TRUE,
 
743
                "enable-site-specific-quirks", TRUE,
 
744
                "enable-dns-prefetching", TRUE,
 
745
                NULL);
690
746
#else
691
747
  webkit_settings = webkit_web_settings_new ();
692
748
 
758
814
void
759
815
ephy_embed_prefs_shutdown (void)
760
816
{
 
817
#ifdef HAVE_WEBKIT2
 
818
  g_object_unref (web_view_group);
 
819
#else
761
820
  g_object_unref (webkit_settings);
 
821
#endif
762
822
}
763
823
 
 
824
#ifdef HAVE_WEBKIT2
 
825
WebKitWebViewGroup *
 
826
ephy_embed_prefs_get_web_view_group (void)
 
827
{
 
828
  return web_view_group;
 
829
}
 
830
#else
764
831
void
765
832
ephy_embed_prefs_add_embed (EphyEmbed *embed)
766
833
{
767
834
  ephy_embed_prefs_apply (embed, webkit_settings);
768
835
}
769
 
 
 
836
#endif