| Differences between
and this patch
- a/Source/WebKit2/PlatformGTK.cmake +7 lines
Lines 207-212 list(APPEND WebKit2_SOURCES a/Source/WebKit2/PlatformGTK.cmake_sec1
207
    UIProcess/API/gtk/WebKitURISchemeRequest.cpp
207
    UIProcess/API/gtk/WebKitURISchemeRequest.cpp
208
    UIProcess/API/gtk/WebKitURISchemeRequest.h
208
    UIProcess/API/gtk/WebKitURISchemeRequest.h
209
    UIProcess/API/gtk/WebKitURISchemeRequestPrivate.h
209
    UIProcess/API/gtk/WebKitURISchemeRequestPrivate.h
210
    UIProcess/API/gtk/WebKitUserContent.h
211
    UIProcess/API/gtk/WebKitUserContent.cpp
212
    UIProcess/API/gtk/WebKitUserContentPrivate.h
213
    UIProcess/API/gtk/WebKitUserContentManager.h
214
    UIProcess/API/gtk/WebKitUserContentManager.cpp
210
    UIProcess/API/gtk/WebKitVersion.cpp
215
    UIProcess/API/gtk/WebKitVersion.cpp
211
    UIProcess/API/gtk/WebKitVersion.h.in
216
    UIProcess/API/gtk/WebKitVersion.h.in
212
    UIProcess/API/gtk/WebKitWebContext.cpp
217
    UIProcess/API/gtk/WebKitWebContext.cpp
Lines 349-354 set(WebKit2GTK_INSTALLED_HEADERS a/Source/WebKit2/PlatformGTK.cmake_sec2
349
    ${WEBKIT2_DIR}/UIProcess/API/gtk/WebKitURIRequest.h
354
    ${WEBKIT2_DIR}/UIProcess/API/gtk/WebKitURIRequest.h
350
    ${WEBKIT2_DIR}/UIProcess/API/gtk/WebKitURIResponse.h
355
    ${WEBKIT2_DIR}/UIProcess/API/gtk/WebKitURIResponse.h
351
    ${WEBKIT2_DIR}/UIProcess/API/gtk/WebKitURISchemeRequest.h
356
    ${WEBKIT2_DIR}/UIProcess/API/gtk/WebKitURISchemeRequest.h
357
    ${WEBKIT2_DIR}/UIProcess/API/gtk/WebKitUserContent.h
358
    ${WEBKIT2_DIR}/UIProcess/API/gtk/WebKitUserContentManager.h
352
    ${WEBKIT2_DIR}/UIProcess/API/gtk/WebKitWebContext.h
359
    ${WEBKIT2_DIR}/UIProcess/API/gtk/WebKitWebContext.h
353
    ${WEBKIT2_DIR}/UIProcess/API/gtk/WebKitWebInspector.h
360
    ${WEBKIT2_DIR}/UIProcess/API/gtk/WebKitWebInspector.h
354
    ${WEBKIT2_DIR}/UIProcess/API/gtk/WebKitWebResource.h
361
    ${WEBKIT2_DIR}/UIProcess/API/gtk/WebKitWebResource.h
- a/Source/WebKit2/UIProcess/API/gtk/WebKitUserContent.cpp +312 lines
Line 0 a/Source/WebKit2/UIProcess/API/gtk/WebKitUserContent.cpp_sec1
1
/*
2
 * Copyright (C) 2014 Igalia S.L.
3
 *
4
 * This library is free software; you can redistribute it and/or
5
 * modify it under the terms of the GNU Library General Public
6
 * License as published by the Free Software Foundation; either
7
 * version 2 of the License, or (at your option) any later version.
8
 *
9
 * This library is distributed in the hope that it will be useful,
10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12
 * Library General Public License for more details.
13
 *
14
 * You should have received a copy of the GNU Library General Public License
15
 * along with this library; see the file COPYING.LIB.  If not, write to
16
 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17
 * Boston, MA 02110-1301, USA.
18
 */
19
20
#include "config.h"
21
#include "WebKitUserContent.h"
22
23
#include "WebKitPrivate.h"
24
#include "WebKitUserContentPrivate.h"
25
26
#include <WebCore/page/UserScript.h>
27
#include <WebCore/page/UserStyleSheet.h>
28
#include <wtf/text/CString.h>
29
#include <wtf/text/StringBuilder.h>
30
31
using namespace WebCore;
32
33
34
static inline UserContentInjectedFrames toUserContentInjectedFrames(WebKitUserContentInjectedFrames injectedFrames)
35
{
36
    switch (injectedFrames) {
37
    case WEBKIT_USER_CONTENT_INJECT_TOP_FRAME:
38
        return InjectInTopFrameOnly;
39
    case WEBKIT_USER_CONTENT_INJECT_ALL_FRAMES:
40
        return InjectInAllFrames;
41
    default:
42
        ASSERT_NOT_REACHED();
43
        return InjectInAllFrames;
44
    }
45
}
46
47
48
static inline UserScriptInjectionTime toUserScriptInjectionTime(WebKitUserScriptInjectionTime injectionTime)
49
{
50
    switch (injectionTime) {
51
    case WEBKIT_USER_SCRIPT_INJECT_AT_DOCUMENT_START:
52
        return InjectAtDocumentStart;
53
    case WEBKIT_USER_SCRIPT_INJECT_AT_DOCUMENT_END:
54
        return InjectAtDocumentEnd;
55
    default:
56
        ASSERT_NOT_REACHED();
57
        return InjectAtDocumentStart;
58
    }
59
}
60
61
62
static inline UserStyleLevel toUserStyleLevel(WebKitUserStyleLevel styleLevel)
63
{
64
    switch (styleLevel) {
65
    case WEBKIT_USER_STYLE_LEVEL_USER:
66
        return UserStyleUserLevel;
67
    case WEBKIT_USER_STYLE_LEVEL_AUTHOR:
68
        return UserStyleAuthorLevel;
69
    default:
70
        ASSERT_NOT_REACHED();
71
        return UserStyleAuthorLevel;
72
    }
73
}
74
75
76
struct _WebKitUserContentPrivate {
77
    _WebKitUserContentPrivate()
78
        : injectedFrames(WEBKIT_USER_CONTENT_INJECT_ALL_FRAMES) { }
79
80
    CString source;
81
    Vector<String> whitelist;
82
    Vector<String> blacklist;
83
    WebKitUserContentInjectedFrames injectedFrames;
84
};
85
86
WEBKIT_DEFINE_TYPE(WebKitUserContent, webkit_user_content, G_TYPE_OBJECT)
87
88
89
static void webkit_user_content_class_init(WebKitUserContentClass*)
90
{
91
    // Empty
92
}
93
94
/**
95
 * webkit_user_content_set_source:
96
 */
97
void webkit_user_content_set_source(WebKitUserContent* user_content, const gchar* source)
98
{
99
    g_return_if_fail(WEBKIT_IS_USER_CONTENT(user_content));
100
    if (!g_strcmp0(user_content->priv->source.data(), source))
101
        return;
102
    user_content->priv->source = source;
103
}
104
105
/**
106
 * webkit_user_content_get_source:
107
 */
108
const gchar* webkit_user_content_get_source(WebKitUserContent* user_content)
109
{
110
    g_return_val_if_fail(WEBKIT_IS_USER_CONTENT(user_content), nullptr);
111
    return user_content->priv->source.data();
112
}
113
114
/**
115
 * webkit_user_content_set_injected_frames:
116
 */
117
void webkit_user_content_set_injected_frames(WebKitUserContent* user_content, WebKitUserContentInjectedFrames injected_frames)
118
{
119
    g_return_if_fail(WEBKIT_IS_USER_CONTENT(user_content));
120
    user_content->priv->injectedFrames = injected_frames;
121
}
122
123
/**
124
 * webkit_user_content_get_injected_frames:
125
 */
126
WebKitUserContentInjectedFrames webkit_user_content_get_injected_frames(WebKitUserContent* user_content)
127
{
128
    g_return_val_if_fail(WEBKIT_IS_USER_CONTENT(user_content), WEBKIT_USER_CONTENT_INJECT_ALL_FRAMES);
129
    return user_content->priv->injectedFrames;
130
}
131
132
/**
133
 * webkit_user_content_set_whitelist:
134
 */
135
void webkit_user_content_set_whitelist(WebKitUserContent* user_content, GList* whitelist)
136
{
137
    g_return_if_fail(WEBKIT_IS_USER_CONTENT(user_content));
138
139
    user_content->priv->whitelist.clear();
140
    for (GList *l = whitelist; l != nullptr; l = l->next)
141
        user_content->priv->whitelist.append(String::fromUTF8(reinterpret_cast<const gchar*>(l->data)));
142
}
143
144
/**
145
 * webkit_user_content_get_whitelist:
146
 */
147
GList* webkit_user_content_get_whitelist(WebKitUserContent* user_content)
148
{
149
    g_return_val_if_fail(WEBKIT_IS_USER_CONTENT(user_content), nullptr);
150
151
    GList* result = nullptr;
152
    for (auto i = user_content->priv->whitelist.rend(); i != user_content->priv->whitelist.rbegin(); --i)
153
        result = g_list_prepend(result, g_strdup(i->utf8().data()));
154
155
    return result;
156
}
157
158
/**
159
 * webkit_user_content_set_blacklist:
160
 */
161
void webkit_user_content_set_blacklist(WebKitUserContent* user_content, GList* blacklist)
162
{
163
    g_return_if_fail(WEBKIT_IS_USER_CONTENT(user_content));
164
165
    user_content->priv->blacklist.clear();
166
    for (GList *l = blacklist; l != nullptr; l = l->next)
167
        user_content->priv->blacklist.append(String::fromUTF8(reinterpret_cast<const gchar*>(l->data)));
168
}
169
170
/**
171
 * webkit_user_content_get_blacklist:
172
 */
173
GList* webkit_user_content_get_blacklist(WebKitUserContent* user_content)
174
{
175
    g_return_val_if_fail(WEBKIT_IS_USER_CONTENT(user_content), nullptr);
176
177
    GList* result = nullptr;
178
    for (auto i = user_content->priv->blacklist.rend(); i != user_content->priv->blacklist.rbegin(); --i)
179
        result = g_list_prepend(result, g_strdup(i->utf8().data()));
180
181
    return result;
182
}
183
184
185
struct _WebKitUserScriptPrivate {
186
    _WebKitUserScriptPrivate()
187
        : injectionTime(WEBKIT_USER_SCRIPT_INJECT_AT_DOCUMENT_START) { }
188
189
    WebKitUserScriptInjectionTime injectionTime;
190
};
191
192
WEBKIT_DEFINE_TYPE(WebKitUserScript, webkit_user_script, WEBKIT_TYPE_USER_CONTENT)
193
194
195
static void webkit_user_script_class_init(WebKitUserScriptClass*)
196
{
197
    // Empty
198
}
199
200
/**
201
 * webkit_user_script_new:
202
 * @source: (transfer none): Source code of the user script.
203
 *
204
 * Returns: (transfer full): A new #WebKitUserScript.
205
 */
206
WebKitUserContent* webkit_user_script_new(const gchar* source)
207
{
208
    WebKitUserContent* userContent = WEBKIT_USER_CONTENT(g_object_new(WEBKIT_TYPE_USER_SCRIPT, nullptr));
209
    userContent->priv->source = source;
210
    return userContent;
211
}
212
213
/**
214
 * webkit_user_script_set_injection_time:
215
 */
216
void webkit_user_script_set_injection_time(WebKitUserScript* userScript, WebKitUserScriptInjectionTime injectionTime)
217
{
218
    g_return_if_fail(WEBKIT_IS_USER_SCRIPT(userScript));
219
    userScript->priv->injectionTime = injectionTime;
220
}
221
222
/**
223
 * webkit_user_script_get_injection_time:
224
 */
225
WebKitUserScriptInjectionTime webkit_user_script_get_injection_time(WebKitUserScript* userScript)
226
{
227
    g_return_val_if_fail(WEBKIT_IS_USER_SCRIPT(userScript), WEBKIT_USER_SCRIPT_INJECT_AT_DOCUMENT_END);
228
    return userScript->priv->injectionTime;
229
}
230
231
UserScript webkitWebKitUserScriptToUserScript(WebKitUserScript* script, guint64 scriptId)
232
{
233
    g_assert(WEBKIT_IS_USER_SCRIPT(script));
234
235
    StringBuilder urlStringBuilder;
236
    urlStringBuilder.append("user-script:");
237
    urlStringBuilder.appendNumber(scriptId);
238
239
    return UserScript {
240
        String::fromUTF8(script->parent.priv->source.data(), script->parent.priv->source.length()),
241
        URL { URL { }, urlStringBuilder.toString() },
242
        script->parent.priv->whitelist,
243
        script->parent.priv->blacklist,
244
        toUserScriptInjectionTime(script->priv->injectionTime),
245
        toUserContentInjectedFrames(script->parent.priv->injectedFrames)
246
    };
247
}
248
249
250
struct _WebKitUserStyleSheetPrivate {
251
    _WebKitUserStyleSheetPrivate()
252
        : level(WEBKIT_USER_STYLE_LEVEL_USER) { }
253
254
    WebKitUserStyleLevel level;
255
};
256
257
WEBKIT_DEFINE_TYPE(WebKitUserStyleSheet, webkit_user_style_sheet, WEBKIT_TYPE_USER_CONTENT)
258
259
260
static void webkit_user_style_sheet_class_init(WebKitUserStyleSheetClass*)
261
{
262
    // Empty
263
}
264
265
/**
266
 * webkit_user_style_sheet_new:
267
 * @source: (transfer none): Source code of the user style sheet.
268
 *
269
 * Returns: (transfer full): A new #WebKitUserStyleSheet object.
270
 */
271
WebKitUserContent* webkit_user_style_sheet_new(const gchar* source)
272
{
273
    WebKitUserContent* userContent = WEBKIT_USER_CONTENT(g_object_new(WEBKIT_TYPE_USER_STYLE_SHEET, nullptr));
274
    userContent->priv->source = g_strdup(source);
275
    return userContent;
276
}
277
278
/**
279
 * webkit_user_style_sheet_set_level:
280
 */
281
void webkit_user_style_sheet_set_level(WebKitUserStyleSheet* userStyleSheet, WebKitUserStyleLevel level)
282
{
283
    g_return_if_fail(WEBKIT_IS_USER_STYLE_SHEET(userStyleSheet));
284
    userStyleSheet->priv->level = level;
285
}
286
287
/**
288
 * webkit_user_style_sheet_get_level:
289
 */
290
WebKitUserStyleLevel webkit_user_style_sheet_get_level(WebKitUserStyleSheet* userStyleSheet)
291
{
292
    g_return_val_if_fail(WEBKIT_IS_USER_STYLE_SHEET(userStyleSheet), WEBKIT_USER_STYLE_LEVEL_USER);
293
    return userStyleSheet->priv->level;
294
}
295
296
UserStyleSheet webkitWebKitUserStyleSheetToUserStyleSheet(WebKitUserStyleSheet* styleSheet, guint64 styleSheetId)
297
{
298
    g_assert(WEBKIT_IS_USER_STYLE_SHEET(styleSheet));
299
300
    StringBuilder urlStringBuilder;
301
    urlStringBuilder.append("user-style-sheet:");
302
    urlStringBuilder.appendNumber(styleSheetId);
303
304
    return UserStyleSheet {
305
        String::fromUTF8(styleSheet->parent.priv->source.data(), styleSheet->parent.priv->source.length()),
306
        URL { URL { }, urlStringBuilder.toString() },
307
        styleSheet->parent.priv->whitelist,
308
        styleSheet->parent.priv->blacklist,
309
        toUserContentInjectedFrames(styleSheet->parent.priv->injectedFrames),
310
        toUserStyleLevel(styleSheet->priv->level)
311
    };
312
}
- a/Source/WebKit2/UIProcess/API/gtk/WebKitUserContent.h +209 lines
Line 0 a/Source/WebKit2/UIProcess/API/gtk/WebKitUserContent.h_sec1
1
/*
2
 * Copyright (C) 2014 Igalia S.L.
3
 *
4
 * This library is free software; you can redistribute it and/or
5
 * modify it under the terms of the GNU Library General Public
6
 * License as published by the Free Software Foundation; either
7
 * version 2 of the License, or (at your option) any later version.
8
 *
9
 * This library is distributed in the hope that it will be useful,
10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12
 * Library General Public License for more details.
13
 *
14
 * You should have received a copy of the GNU Library General Public License
15
 * along with this library; see the file COPYING.LIB.  If not, write to
16
 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17
 * Boston, MA 02110-1301, USA.
18
 */
19
20
#if !defined(__WEBKIT2_H_INSIDE__) && !defined(WEBKIT2_COMPILATION)
21
#error "Only <webkit2/webkit2.h> can be included directly."
22
#endif
23
24
#ifndef WebKitUserContent_h
25
#define WebKitUserContent_h
26
27
#include <glib-object.h>
28
#include <webkit2/WebKitDefines.h>
29
30
G_BEGIN_DECLS
31
32
/**
33
 * WebKitUserContentInjectedFrames: Specifies in which frames user
34
 *   scripts and user style sheets are to be inserted in.
35
 *
36
 * @WEBKIT_USER_CONTENT_INJECT_ALL_FRAMES: Insert the user content
37
 *   (a script or style sheet) in all the frames loaded by the web
38
 *   view, including nested frames. This is the default.
39
 * @WEBKIT_USER_CONTENT_INJECT_TOP_FRAME: Insert the user content
40
 *   (a script or style sheet) *only* in the top-level frame loaded
41
 *   by the web view, and *not* in the nested frames.
42
 */
43
typedef enum {
44
    WEBKIT_USER_CONTENT_INJECT_ALL_FRAMES,
45
    WEBKIT_USER_CONTENT_INJECT_TOP_FRAME,
46
} WebKitUserContentInjectedFrames;
47
48
#define WEBKIT_TYPE_USER_CONTENT            (webkit_user_content_get_type())
49
#define WEBKIT_USER_CONTENT(obj)            (G_TYPE_CHECK_INSTANCE_CAST((obj), WEBKIT_TYPE_USER_CONTENT, WebKitUserContent))
50
#define WEBKIT_IS_USER_CONTENT(obj)         (G_TYPE_CHECK_INSTANCE_TYPE((obj), WEBKIT_TYPE_USER_CONTENT))
51
#define WEBKIT_USER_CONTENT_CLASS(klass)    (G_TYPE_CHECK_CLASS_CAST((klass),  WEBKIT_TYPE_USER_CONTENT, WebKitUserContentClass))
52
#define WEBKIT_IS_USER_CONTENT_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass),  WEBKIT_TYPE_USER_CONTENT))
53
#define WEBKIT_USER_CONTENT_GET_CLASS(obj)  (G_TYPE_INSTANCE_GET_CLASS((obj),  WEBKIT_TYPE_USER_CONTENT, WebKitUserContentClass))
54
55
typedef struct _WebKitUserContent        WebKitUserContent;
56
typedef struct _WebKitUserContentClass   WebKitUserContentClass;
57
typedef struct _WebKitUserContentPrivate WebKitUserContentPrivate;
58
59
60
struct _WebKitUserContent {
61
    GObject parent;
62
63
    /*< private >*/
64
    WebKitUserContentPrivate *priv;
65
};
66
67
struct _WebKitUserContentClass {
68
    GObjectClass parent_class;
69
};
70
71
72
WEBKIT_API GType
73
webkit_user_content_get_type            (void);
74
75
WEBKIT_API void
76
webkit_user_content_set_source          (WebKitUserContent              *user_content,
77
                                         const gchar                    *source);
78
79
WEBKIT_API const gchar *
80
webkit_user_content_get_source          (WebKitUserContent              *user_content);
81
82
WEBKIT_API void
83
webkit_user_content_set_injected_frames (WebKitUserContent              *user_content,
84
                                         WebKitUserContentInjectedFrames injected_frames);
85
86
WEBKIT_API WebKitUserContentInjectedFrames
87
webkit_user_content_get_injected_frames (WebKitUserContent              *user_content);
88
89
WEBKIT_API void
90
webkit_user_content_set_whitelist       (WebKitUserContent              *user_content,
91
                                         GList                          *whitelist);
92
93
WEBKIT_API GList *
94
webkit_user_content_get_whitelist       (WebKitUserContent              *user_content);
95
96
WEBKIT_API void
97
webkit_user_content_set_blacklist       (WebKitUserContent              *user_content,
98
                                         GList                          *blacklist);
99
100
WEBKIT_API GList *
101
webkit_user_content_get_blacklist       (WebKitUserContent              *user_content);
102
103
104
/**
105
 * WebKitUserScriptInjectionTime: Specifies at which place user scripts
106
 *   are inserted.
107
 *
108
 * @WEBKIT_USER_SCRIPT_INJECT_AT_DOCUMENT_START: Insert the code of the user
109
 *   script at the beginning of the loaded documents. This is the default.
110
 * @WEBKIT_USER_SCRIPT_INJECT_AT_DOCUMENT_END: Insert the code of the user
111
 *   script at the end of the loaded documents.
112
 */
113
typedef enum {
114
    WEBKIT_USER_SCRIPT_INJECT_AT_DOCUMENT_START,
115
    WEBKIT_USER_SCRIPT_INJECT_AT_DOCUMENT_END,
116
} WebKitUserScriptInjectionTime;
117
118
#define WEBKIT_TYPE_USER_SCRIPT            (webkit_user_content_get_type())
119
#define WEBKIT_USER_SCRIPT(obj)            (G_TYPE_CHECK_INSTANCE_CAST((obj), WEBKIT_TYPE_USER_SCRIPT, WebKitUserScript))
120
#define WEBKIT_IS_USER_SCRIPT(obj)         (G_TYPE_CHECK_INSTANCE_TYPE((obj), WEBKIT_TYPE_USER_SCRIPT))
121
#define WEBKIT_USER_SCRIPT_CLASS(klass)    (G_TYPE_CHECK_CLASS_CAST((klass),  WEBKIT_TYPE_USER_SCRIPT, WebKitUserScriptClass))
122
#define WEBKIT_IS_USER_SCRIPT_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass),  WEBKIT_TYPE_USER_SCRIPT))
123
#define WEBKIT_USER_SCRIPT_GET_CLASS(obj)  (G_TYPE_INSTANCE_GET_CLASS((obj),  WEBKIT_TYPE_USER_SCRIPT, WebKitUserScriptClass))
124
125
typedef struct _WebKitUserScript        WebKitUserScript;
126
typedef struct _WebKitUserScriptClass   WebKitUserScriptClass;
127
typedef struct _WebKitUserScriptPrivate WebKitUserScriptPrivate;
128
129
130
struct _WebKitUserScript {
131
    WebKitUserContent parent;
132
133
    /*< private >*/
134
    WebKitUserScriptPrivate *priv;
135
};
136
137
struct _WebKitUserScriptClass {
138
    WebKitUserContentClass parent_class;
139
};
140
141
142
WEBKIT_API GType
143
webkit_user_script_get_type           (void);
144
145
WEBKIT_API WebKitUserContent *
146
webkit_user_script_new                (const gchar                  *source);
147
148
WEBKIT_API void
149
webkit_user_script_set_injection_time (WebKitUserScript             *user_script,
150
                                       WebKitUserScriptInjectionTime injection_time);
151
152
WEBKIT_API WebKitUserScriptInjectionTime
153
webkit_user_script_get_injection_time (WebKitUserScript             *user_script);
154
155
156
/**
157
 * WebKitUserStyleLevel: Specifies how to treat an user style sheet.
158
 *
159
 * @WEBKIT_USER_STYLE_LEVEL_USER: The style sheet is an user style sheet,
160
 *   its contents always override other style sheets. This is the default.
161
 * @WEBKIT_USER_STYLE_LEVEL_AUTHOR: The style sheet will be treated as if
162
 *   it was provided by the loaded documents. That means other user style
163
 *   sheets may still override it.
164
 */
165
typedef enum {
166
    WEBKIT_USER_STYLE_LEVEL_USER,
167
    WEBKIT_USER_STYLE_LEVEL_AUTHOR,
168
} WebKitUserStyleLevel;
169
170
#define WEBKIT_TYPE_USER_STYLE_SHEET            (webkit_user_content_get_type())
171
#define WEBKIT_USER_STYLE_SHEET(obj)            (G_TYPE_CHECK_INSTANCE_CAST((obj), WEBKIT_TYPE_USER_STYLE_SHEET, WebKitUserStyleSheet))
172
#define WEBKIT_IS_USER_STYLE_SHEET(obj)         (G_TYPE_CHECK_INSTANCE_TYPE((obj), WEBKIT_TYPE_USER_STYLE_SHEET))
173
#define WEBKIT_USER_STYLE_SHEET_CLASS(klass)    (G_TYPE_CHECK_CLASS_CAST((klass),  WEBKIT_TYPE_USER_STYLE_SHEET, WebKitUserStyleSheetClass))
174
#define WEBKIT_IS_USER_STYLE_SHEET_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass),  WEBKIT_TYPE_USER_STYLE_SHEET))
175
#define WEBKIT_USER_STYLE_SHEET_GET_CLASS(obj)  (G_TYPE_INSTANCE_GET_CLASS((obj),  WEBKIT_TYPE_USER_STYLE_SHEET, WebKitUserStyleSheetClass))
176
177
typedef struct _WebKitUserStyleSheet        WebKitUserStyleSheet;
178
typedef struct _WebKitUserStyleSheetClass   WebKitUserStyleSheetClass;
179
typedef struct _WebKitUserStyleSheetPrivate WebKitUserStyleSheetPrivate;
180
181
182
struct _WebKitUserStyleSheet {
183
    WebKitUserContent parent;
184
185
    /*< private >*/
186
    WebKitUserStyleSheetPrivate *priv;
187
};
188
189
struct _WebKitUserStyleSheetClass {
190
    WebKitUserContentClass parent_class;
191
};
192
193
194
WEBKIT_API GType
195
webkit_user_style_sheet_get_type  (void);
196
197
WEBKIT_API WebKitUserContent *
198
webkit_user_style_sheet_new       (const gchar          *source);
199
200
WEBKIT_API void
201
webkit_user_style_sheet_set_level (WebKitUserStyleSheet *user_style_sheet,
202
                                   WebKitUserStyleLevel  level);
203
204
WEBKIT_API WebKitUserStyleLevel
205
webkit_user_style_sheet_get_level (WebKitUserStyleSheet *user_style_sheet);
206
207
G_END_DECLS
208
209
#endif
- a/Source/WebKit2/UIProcess/API/gtk/WebKitUserContentManager.cpp +229 lines
Line 0 a/Source/WebKit2/UIProcess/API/gtk/WebKitUserContentManager.cpp_sec1
1
/*
2
 * Copyright (C) 2014 Igalia S.L.
3
 *
4
 * This library is free software; you can redistribute it and/or
5
 * modify it under the terms of the GNU Library General Public
6
 * License as published by the Free Software Foundation; either
7
 * version 2 of the License, or (at your option) any later version.
8
 *
9
 * This library is distributed in the hope that it will be useful,
10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12
 * Library General Public License for more details.
13
 *
14
 * You should have received a copy of the GNU Library General Public License
15
 * along with this library; see the file COPYING.LIB.  If not, write to
16
 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17
 * Boston, MA 02110-1301, USA.
18
 */
19
20
#include "config.h"
21
#include "WebKitUserContentManager.h"
22
23
#include "UserScript.h"
24
#include "UserStyleSheet.h"
25
#include "WebKitJavascriptResult.h"
26
#include "WebKitPrivate.h"
27
#include "WebKitUserContentPrivate.h"
28
#include "WebScriptMessageHandler.h"
29
#include "WebUserContentControllerProxy.h"
30
#include <wtf/gobject/GRefPtr.h>
31
32
using namespace WebCore;
33
using namespace WebKit;
34
35
36
class ScriptMessageClientGtk : public WebScriptMessageHandler::Client {
37
public:
38
    ScriptMessageClientGtk(const GRefPtr<WebKitUserContentManager>& manager,
39
        const String& handlerName): m_handlerName(handlerName), m_manager(manager) { }
40
41
    virtual void didPostMessage(WebPageProxy&, WebFrameProxy&, WebCore::SerializedScriptValue&)
42
    {
43
        // TODO: Implement
44
    }
45
46
    virtual ~ScriptMessageClientGtk() { }
47
48
private:
49
    String m_handlerName;
50
    GRefPtr<WebKitUserContentManager> m_manager;
51
};
52
53
54
struct _WebKitUserContentManagerPrivate {
55
    _WebKitUserContentManagerPrivate()
56
        : userContentController(WebUserContentControllerProxy::create()) { }
57
58
    RefPtr<WebUserContentControllerProxy> userContentController;
59
    guint64 numUserStyleSheets;
60
    guint64 numUserScripts;
61
};
62
63
/**
64
 * SECTION:WebKitUserContentManager
65
 * @short_description: TODO
66
 * @title: WebKitUserContentManager
67
 *
68
 * Since: 2.6
69
 */
70
71
WEBKIT_DEFINE_TYPE(WebKitUserContentManager, webkit_user_content_manager, G_TYPE_OBJECT)
72
73
74
enum {
75
    SCRIPT_MESSAGE_RECEIVED,
76
77
    LAST_SIGNAL
78
};
79
80
static guint signals[LAST_SIGNAL] = { 0, };
81
82
83
static void webkit_user_content_manager_class_init(WebKitUserContentManagerClass *klass)
84
{
85
    GObjectClass* gObjectClass = G_OBJECT_CLASS(klass);
86
87
    /**
88
     * WebKitUserContentManager::script-message-received:
89
     * @manager: the #WebKitUserContentManager
90
     * @js_result: the #WebKitJavascriptResult holding the value received
91
     *     from the JavaScript world.
92
     *
93
     * This signal is emitted when JavaScript in a web view calls
94
     * <code>window.webkit.&lt;name&gt;.postMessage()</code>, after registering
95
     * <code>&lt;name&gt;</code> using
96
     * webkit_user_content_manager_register_script_message_name()
97
     */
98
    signals[SCRIPT_MESSAGE_RECEIVED] =
99
        g_signal_new(
100
            "script-message-received",
101
            G_TYPE_FROM_CLASS(gObjectClass),
102
            static_cast<GSignalFlags>(G_SIGNAL_RUN_LAST | G_SIGNAL_DETAILED),
103
            0, nullptr, nullptr,
104
            g_cclosure_marshal_VOID__BOXED,
105
            G_TYPE_NONE, 1,
106
            WEBKIT_TYPE_JAVASCRIPT_RESULT);
107
}
108
109
110
static gpointer createDefaultUserContextManager(gpointer)
111
{
112
    static GRefPtr<WebKitUserContentManager> manager = adoptGRef(WEBKIT_USER_CONTENT_MANAGER(g_object_new(WEBKIT_TYPE_USER_CONTENT_MANAGER, nullptr)));
113
    return manager.get();
114
}
115
116
/**
117
 * webkit_user_content_manager_get_default:
118
 *
119
 * Obtains the default user content manager.
120
 *
121
 * Returns: (transfer none): a #WebKitUserContentManager
122
 */
123
WebKitUserContentManager* webkit_user_content_manager_get_default(void)
124
{
125
    static GOnce onceInit = G_ONCE_INIT;
126
    return WEBKIT_USER_CONTENT_MANAGER(g_once(&onceInit, createDefaultUserContextManager, nullptr));
127
}
128
129
/**
130
 * webkit_user_content_manager_add_script:
131
 * @manager: A #WebKitUserContentManager.
132
 */
133
void
134
webkit_user_content_manager_add_script(WebKitUserContentManager* manager, WebKitUserScript* script)
135
{
136
    g_return_if_fail(WEBKIT_IS_USER_CONTENT_MANAGER(manager));
137
    g_return_if_fail(WEBKIT_IS_USER_SCRIPT(script));
138
    manager->priv->userContentController->addUserScript(
139
        webkitWebKitUserScriptToUserScript(script, manager->priv->numUserScripts++));
140
}
141
142
/**
143
 * webkit_user_content_manager_remove_all_scripts:
144
 * @manager: A #WebKitUserContentManager.
145
 */
146
void
147
webkit_user_content_manager_remove_all_scripts(WebKitUserContentManager* manager)
148
{
149
    g_return_if_fail(WEBKIT_IS_USER_CONTENT_MANAGER(manager));
150
    manager->priv->userContentController->removeAllUserScripts();
151
    manager->priv->numUserScripts = 0;
152
}
153
154
/**
155
 * webkit_user_content_manager_add_style_sheet:
156
 * @manager: A #WebKitUserContentManager.
157
 */
158
void
159
webkit_user_content_manager_add_style_sheet(WebKitUserContentManager* manager, WebKitUserStyleSheet* stylesheet)
160
{
161
    g_return_if_fail(WEBKIT_IS_USER_CONTENT_MANAGER(manager));
162
    g_return_if_fail(WEBKIT_IS_USER_STYLE_SHEET(stylesheet));
163
    manager->priv->userContentController->addUserStyleSheet(
164
        webkitWebKitUserStyleSheetToUserStyleSheet(stylesheet, manager->priv->numUserStyleSheets++));
165
}
166
167
/**
168
 * webkit_user_content_manager_remove_all_style_sheets:
169
 * @manager: A #WebKitUserContentManager.
170
 */
171
void
172
webkit_user_content_manager_remove_all_style_sheets(WebKitUserContentManager* manager)
173
{
174
    g_return_if_fail(WEBKIT_IS_USER_CONTENT_MANAGER(manager));
175
    manager->priv->userContentController->removeAllUserStyleSheets();
176
    manager->priv->numUserStyleSheets = 0;
177
}
178
179
180
/**
181
 * webkit_user_content_manager_register_script_message_handler_name:
182
 * @manager: A #WebKitUserContentManager.
183
 * @name: (transfer none): Name of the script message channel.
184
 *
185
 * Registers a new user script message handler name. After it is
186
 * registered, scripts can use `window.webkit.<name>.postMessage(value)`
187
 * to send messages. Those messages are received by connecting handlers
188
 * to the WebKitUserContentManager::script-message-received signal. The
189
 * handler name is used as the detail of the signal. To avoid race
190
 * conditions between registering the handler name, and starting to
191
 * receive the signals, it is recommended to connect to the signal
192
 * *before* registering the handler name:
193
 *
194
 * <informalexample><programlisting>
195
 * WebKitWebView *view = webkit_web_view_new ();
196
 * WebKitUserContentManager *manager = webkit_web_view_get_user_content_manager ();
197
 * g_signal_connect (manager, "script-message-received::foobar",
198
 *                   G_CALLBACK (handle_script_message), NULL);
199
 * webkit_user_content_manager_register_script_message_handler (manager, "foobar");
200
 * </programlisting></informalexample>
201
 *
202
 * Returns: Whether the message channel was registered successfully.
203
 */
204
gboolean webkit_user_content_manager_register_script_message_handler_name(WebKitUserContentManager* manager, const gchar* name)
205
{
206
    g_return_val_if_fail(WEBKIT_IS_USER_CONTENT_MANAGER(manager), FALSE);
207
208
    const auto handler_name = String::fromUTF8(name);
209
    auto handler = WebScriptMessageHandler::create(std::make_unique<ScriptMessageClientGtk>(manager, handler_name), handler_name);
210
    return manager->priv->userContentController->addUserScriptMessageHandler(handler.get());
211
}
212
213
/**
214
 * webkit_user_content_manager_unregister_script_message_handler_name:
215
 * @manager: A #WebKitUserContentManager.
216
 * @name: (transfer none): Name of the script message channel.
217
 *
218
 * Unregisters a previously registered message handler name.
219
 *
220
 * Note that this does *not* disconnect handlers for the
221
 * WebKitUserContentManager::script-message-received signal.
222
 *
223
 * See: webkit_user_content_manager_register_script_message_handler_name
224
 */
225
void webkit_user_content_manager_unregister_script_message_handler_name(WebKitUserContentManager* manager, const gchar* name)
226
{
227
    g_return_if_fail(WEBKIT_IS_USER_CONTENT_MANAGER(manager));
228
    manager->priv->userContentController->removeUserMessageHandlerForName(String::fromUTF8(name));
229
}
- a/Source/WebKit2/UIProcess/API/gtk/WebKitUserContentManager.h +94 lines
Line 0 a/Source/WebKit2/UIProcess/API/gtk/WebKitUserContentManager.h_sec1
1
/*
2
 * Copyright (C) 2014 Igalia S.L.
3
 *
4
 * This library is free software; you can redistribute it and/or
5
 * modify it under the terms of the GNU Library General Public
6
 * License as published by the Free Software Foundation; either
7
 * version 2 of the License, or (at your option) any later version.
8
 *
9
 * This library is distributed in the hope that it will be useful,
10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12
 * Library General Public License for more details.
13
 *
14
 * You should have received a copy of the GNU Library General Public License
15
 * along with this library; see the file COPYING.LIB.  If not, write to
16
 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17
 * Boston, MA 02110-1301, USA.
18
 */
19
20
#if !defined(__WEBKIT2_H_INSIDE__) && !defined(WEBKIT2_COMPILATION)
21
#error "Only <webkit2/webkit2.h> can be included directly."
22
#endif
23
24
#ifndef WebKitUserContentManager_h
25
#define WebKitUserContentManager_h
26
27
#include <glib-object.h>
28
#include <webkit2/WebKitDefines.h>
29
#include <webkit2/WebKitUserContent.h>
30
31
G_BEGIN_DECLS
32
33
#define WEBKIT_TYPE_USER_CONTENT_MANAGER            (webkit_user_content_manager_get_type())
34
#define WEBKIT_USER_CONTENT_MANAGER(obj)            (G_TYPE_CHECK_INSTANCE_CAST((obj), WEBKIT_TYPE_USER_CONTENT_MANAGER, WebKitUserContentManager))
35
#define WEBKIT_IS_USER_CONTENT_MANAGER(obj)         (G_TYPE_CHECK_INSTANCE_TYPE((obj), WEBKIT_TYPE_USER_CONTENT_MANAGER))
36
#define WEBKIT_USER_CONTENT_MANAGER_CLASS(klass)    (G_TYPE_CHECK_CLASS_CAST((klass),  WEBKIT_TYPE_USER_CONTENT_MANAGER, WebKitUserContentManagerClass))
37
#define WEBKIT_IS_USER_CONTENT_MANAGER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass),  WEBKIT_TYPE_USER_CONTENT_MANAGER))
38
#define WEBKIT_USER_CONTENT_MANAGER_GET_CLASS(obj)  (G_TYPE_INSTANCE_GET_CLASS((obj),  WEBKIT_TYPE_USER_CONTENT_MANAGER, WebKitUserContentManagerClass))
39
40
typedef struct _WebKitUserContentManager        WebKitUserContentManager;
41
typedef struct _WebKitUserContentManagerClass   WebKitUserContentManagerClass;
42
typedef struct _WebKitUserContentManagerPrivate WebKitUserContentManagerPrivate;
43
44
45
struct _WebKitUserContentManager {
46
    GObject parent;
47
48
    /*< private >*/
49
    WebKitUserContentManagerPrivate *priv;
50
};
51
52
struct _WebKitUserContentManagerClass {
53
    GObjectClass parent_class;
54
55
    void (*_webkit_reserved0) (void);
56
    void (*_webkit_reserved1) (void);
57
    void (*_webkit_reserved2) (void);
58
    void (*_webkit_reserved3) (void);
59
    void (*_webkit_reserved4) (void);
60
    void (*_webkit_reserved5) (void);
61
    void (*_webkit_reserved6) (void);
62
    void (*_webkit_reserved7) (void);
63
};
64
65
66
WEBKIT_API GType
67
webkit_user_content_manager_get_type                                (void);
68
69
WEBKIT_API WebKitUserContentManager *
70
webkit_user_content_manager_get_default                             (void);
71
72
WEBKIT_API void
73
webkit_user_content_manager_add_script                              (WebKitUserContentManager *manager,
74
                                                                     WebKitUserScript         *script);
75
WEBKIT_API void
76
webkit_user_content_manager_remove_all_scripts                      (WebKitUserContentManager *manager);
77
78
WEBKIT_API void
79
webkit_user_content_manager_add_style_sheet                         (WebKitUserContentManager *manager,
80
                                                                     WebKitUserStyleSheet     *stylesheet);
81
WEBKIT_API void
82
webkit_user_content_manager_remove_all_style_sheets                 (WebKitUserContentManager *manager);
83
84
WEBKIT_API gboolean
85
webkit_user_content_manager_register_script_message_handler_name    (WebKitUserContentManager *manager,
86
                                                                     const gchar              *name);
87
88
WEBKIT_API void
89
webkit_user_content_manager_unregister_script_message_handler_name (WebKitUserContentManager *manager,
90
                                                                    const gchar              *name);
91
92
G_END_DECLS
93
94
#endif
- a/Source/WebKit2/UIProcess/API/gtk/WebKitUserContentPrivate.h +33 lines
Line 0 a/Source/WebKit2/UIProcess/API/gtk/WebKitUserContentPrivate.h_sec1
1
/*
2
 * Copyright (C) 2014 Igalia S.L.
3
 *
4
 * This library is free software; you can redistribute it and/or
5
 * modify it under the terms of the GNU Library General Public
6
 * License as published by the Free Software Foundation; either
7
 * version 2 of the License, or (at your option) any later version.
8
 *
9
 * This library is distributed in the hope that it will be useful,
10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12
 * Library General Public License for more details.
13
 *
14
 * You should have received a copy of the GNU Library General Public License
15
 * along with this library; see the file COPYING.LIB.  If not, write to
16
 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17
 * Boston, MA 02110-1301, USA.
18
 */
19
20
#ifndef WebKitUserContentPrivate_h
21
#define WebKitUserContentPrivate_h
22
23
#include "WebKitUserContent.h"
24
25
namespace WebCore {
26
class UserScript;
27
class UserStyleSheet;
28
};
29
30
WebCore::UserScript webkitWebKitUserScriptToUserScript(WebKitUserScript*, guint64);
31
WebCore::UserStyleSheet webkitWebKitUserStyleSheetToUserStyleSheet(WebKitUserStyleSheet*, guint64);
32
33
#endif // WebKitUserContentPrivate_h
- a/Source/WebKit2/UIProcess/API/gtk/docs/webkit2gtk-sections.txt +83 lines
Lines 73-78 webkit_web_context_get_type a/Source/WebKit2/UIProcess/API/gtk/docs/webkit2gtk-sections.txt_sec1
73
</SECTION>
73
</SECTION>
74
74
75
<SECTION>
75
<SECTION>
76
<FILE>WebKitUserContent</FILE>
77
<TITLE>WebKitUserContent</TITLE>
78
WebKitUserContent
79
WebKitUserScript
80
WebKitUserStyleSheet
81
WebKitUserContentInjectedFrames
82
WebKitUserScriptInjectionTime
83
WebKitUserStyleLevel
84
webkit_user_content_get_injected_frames
85
webkit_user_content_set_injected_frames
86
webkit_user_content_get_source
87
webkit_user_content_set_source
88
webkit_user_content_get_blacklist
89
webkit_user_content_set_blacklist
90
webkit_user_content_get_whitelist
91
webkit_user_content_set_whitelist
92
webkit_user_script_new
93
webkit_user_script_get_injection_time
94
webkit_user_script_set_injection_time
95
webkit_user_style_sheet_new
96
webkit_user_style_sheet_get_level
97
webkit_user_style_sheet_set_level
98
99
<SUBSECTION Standard>
100
WebKitUserContentClass
101
WEBKIT_USER_CONTENT
102
WEBKIT_IS_USER_CONTENT
103
WEBKIT_TYPE_USER_CONTENT
104
WEBKIT_USER_CONTENT_CLASS
105
WEBKIT_IS_USER_CONTENT_CLASS
106
WEBKIT_USER_CONTENT_GET_CLASS
107
WebKitUserScriptClass
108
WEBKIT_USER_SCRIPT
109
WEBKIT_IS_USER_SCRIPT
110
WEBKIT_TYPE_USER_SCRIPT
111
WEBKIT_USER_SCRIPT_CLASS
112
WEBKIT_IS_USER_SCRIPT_CLASS
113
WEBKIT_USER_SCRIPT_GET_CLASS
114
WebKitUserStyleSheetClass
115
WEBKIT_USER_STYLE_SHEET
116
WEBKIT_IS_USER_STYLE_SHEET
117
WEBKIT_TYPE_USER_STYLE_SHEET
118
WEBKIT_USER_STYLE_SHEET_CLASS
119
WEBKIT_IS_USER_STYLE_SHEET_CLASS
120
WEBKIT_USER_STYLE_SHEET_GET_CLASS
121
122
<SUBSECTION Private>
123
WebKitUserContentPrivate
124
WebKitUserScriptPrivate
125
WebKitUserStyleSheetPrivate
126
webkit_user_content_get_type
127
webkit_user_script_get_type
128
webkit_user_style_sheet_get_type
129
</SECTION>
130
131
<SECTION>
132
<FILE>WebKitUserContentManager</FILE>
133
<TITLE>WebKitUserContentManager</TITLE>
134
WebKitUserContentManager
135
webkit_user_content_manager_get_default
136
webkit_user_content_manager_add_script
137
webkit_user_content_manager_remove_all_scripts
138
webkit_user_content_manager_add_style_sheet
139
webkit_user_content_manager_remove_all_style_sheets
140
webkit_user_content_manager_register_script_message_handler_name
141
webkit_user_content_manager_unregister_script_message_handler_name
142
143
<SUBSECTION Standard>
144
WEBKIT_IS_USER_CONTENT_MANAGER
145
WEBKIT_IS_USER_CONTENT_MANAGER_CLASS
146
WEBKIT_TYPE_USER_CONTENT_MANAGER
147
WEBKIT_USER_CONTENT_MANAGER
148
WEBKIT_USER_CONTENT_MANAGER_CLASS
149
WEBKIT_USER_CONTENT_MANAGER_GET_CLASS
150
WebKitUserContentManagerClass
151
152
<SUBSECTION Private>
153
WebKitUserContentManagerPrivate
154
webkit_user_content_manager_get_type
155
156
</SECTION>
157
158
<SECTION>
76
<FILE>WebKitWebView</FILE>
159
<FILE>WebKitWebView</FILE>
77
<TITLE>WebKitWebView</TITLE>
160
<TITLE>WebKitWebView</TITLE>
78
WebKitWebView
161
WebKitWebView
- a/Source/WebKit2/UIProcess/API/gtk/webkit2.h +2 lines
Lines 60-65 a/Source/WebKit2/UIProcess/API/gtk/webkit2.h_sec1
60
#include <webkit2/WebKitURIRequest.h>
60
#include <webkit2/WebKitURIRequest.h>
61
#include <webkit2/WebKitURIResponse.h>
61
#include <webkit2/WebKitURIResponse.h>
62
#include <webkit2/WebKitURISchemeRequest.h>
62
#include <webkit2/WebKitURISchemeRequest.h>
63
#include <webkit2/WebKitUserContent.h>
64
#include <webkit2/WebKitUserContentManager.h>
63
#include <webkit2/WebKitVersion.h>
65
#include <webkit2/WebKitVersion.h>
64
#include <webkit2/WebKitWebContext.h>
66
#include <webkit2/WebKitWebContext.h>
65
#include <webkit2/WebKitWebInspector.h>
67
#include <webkit2/WebKitWebInspector.h>
- a/Source/WebKit2/UIProcess/UserContent/WebUserContentControllerProxy.cpp +16 lines
Lines 97-102 void WebUserContentControllerProxy::removeAllUserScripts() a/Source/WebKit2/UIProcess/UserContent/WebUserContentControllerProxy.cpp_sec1
97
        processAndCount.key->connection()->send(Messages::WebUserContentController::RemoveAllUserScripts(), m_identifier);
97
        processAndCount.key->connection()->send(Messages::WebUserContentController::RemoveAllUserScripts(), m_identifier);
98
}
98
}
99
99
100
void WebUserContentControllerProxy::addUserStyleSheet(WebCore::UserStyleSheet userStyleSheet)
101
{
102
    m_userStyleSheets.append(std::move(userStyleSheet));
103
104
    for (auto& processAndCount : m_processes)
105
        processAndCount.key->connection()->send(Messages::WebUserContentController::AddUserStyleSheets({ m_userStyleSheets.last() }), m_identifier);
106
}
107
108
void WebUserContentControllerProxy::removeAllUserStyleSheets()
109
{
110
    m_userStyleSheets.clear();
111
112
    for (auto& processAndCount : m_processes)
113
        processAndCount.key->connection()->send(Messages::WebUserContentController::RemoveAllUserStyleSheets(), m_identifier);
114
}
115
100
bool WebUserContentControllerProxy::addUserScriptMessageHandler(WebScriptMessageHandler* handler)
116
bool WebUserContentControllerProxy::addUserScriptMessageHandler(WebScriptMessageHandler* handler)
101
{
117
{
102
    for (auto& existingHandler : m_scriptMessageHandlers.values()) {
118
    for (auto& existingHandler : m_scriptMessageHandlers.values()) {
- a/Source/WebKit2/UIProcess/UserContent/WebUserContentControllerProxy.h +5 lines
Lines 39-44 class DataReference; a/Source/WebKit2/UIProcess/UserContent/WebUserContentControllerProxy.h_sec1
39
39
40
namespace WebCore {
40
namespace WebCore {
41
class UserScript;
41
class UserScript;
42
class UserStyleSheet;
42
}
43
}
43
44
44
namespace WebKit {
45
namespace WebKit {
Lines 59-64 public: a/Source/WebKit2/UIProcess/UserContent/WebUserContentControllerProxy.h_sec2
59
    void addUserScript(WebCore::UserScript);
60
    void addUserScript(WebCore::UserScript);
60
    void removeAllUserScripts();
61
    void removeAllUserScripts();
61
62
63
    void addUserStyleSheet(WebCore::UserStyleSheet);
64
    void removeAllUserStyleSheets();
65
62
    // Returns false if there was a name conflict.
66
    // Returns false if there was a name conflict.
63
    bool addUserScriptMessageHandler(WebScriptMessageHandler*);
67
    bool addUserScriptMessageHandler(WebScriptMessageHandler*);
64
    void removeUserMessageHandlerForName(const String&);
68
    void removeUserMessageHandlerForName(const String&);
Lines 75-80 private: a/Source/WebKit2/UIProcess/UserContent/WebUserContentControllerProxy.h_sec3
75
    HashCountedSet<WebProcessProxy*> m_processes;
79
    HashCountedSet<WebProcessProxy*> m_processes;
76
80
77
    Vector<WebCore::UserScript> m_userScripts;
81
    Vector<WebCore::UserScript> m_userScripts;
82
    Vector<WebCore::UserStyleSheet> m_userStyleSheets;
78
    HashMap<uint64_t, RefPtr<WebScriptMessageHandler>> m_scriptMessageHandlers;
83
    HashMap<uint64_t, RefPtr<WebScriptMessageHandler>> m_scriptMessageHandlers;
79
};
84
};
80
85
- a/Source/WebKit2/WebProcess/UserContent/WebUserContentController.cpp +14 lines
Lines 35-40 a/Source/WebKit2/WebProcess/UserContent/WebUserContentController.cpp_sec1
35
#include <WebCore/DOMWrapperWorld.h>
35
#include <WebCore/DOMWrapperWorld.h>
36
#include <WebCore/ScriptController.h>
36
#include <WebCore/ScriptController.h>
37
#include <WebCore/SerializedScriptValue.h>
37
#include <WebCore/SerializedScriptValue.h>
38
#include <WebCore/UserStyleSheet.h>
38
#include <wtf/NeverDestroyed.h>
39
#include <wtf/NeverDestroyed.h>
39
40
40
#if ENABLE(USER_MESSAGE_HANDLERS)
41
#if ENABLE(USER_MESSAGE_HANDLERS)
Lines 92-97 void WebUserContentController::removeAllUserScripts() a/Source/WebKit2/WebProcess/UserContent/WebUserContentController.cpp_sec2
92
    m_userContentController->removeUserScripts(mainThreadNormalWorld());
93
    m_userContentController->removeUserScripts(mainThreadNormalWorld());
93
}
94
}
94
95
96
void WebUserContentController::addUserStyleSheets(const Vector<WebCore::UserStyleSheet>& userStyleSheets)
97
{
98
    for (const auto& userStyleSheet : userStyleSheets) {
99
        m_userContentController->addUserStyleSheet(mainThreadNormalWorld(),
100
            std::make_unique<WebCore::UserStyleSheet>(userStyleSheet), InjectInExistingDocuments);
101
    }
102
}
103
104
void WebUserContentController::removeAllUserStyleSheets()
105
{
106
    m_userContentController->removeUserStyleSheets(mainThreadNormalWorld());
107
}
108
95
#if ENABLE(USER_MESSAGE_HANDLERS)
109
#if ENABLE(USER_MESSAGE_HANDLERS)
96
class WebUserMessageHandlerDescriptorProxy : public RefCounted<WebUserMessageHandlerDescriptorProxy>, public WebCore::UserMessageHandlerDescriptor::Client {
110
class WebUserMessageHandlerDescriptorProxy : public RefCounted<WebUserMessageHandlerDescriptorProxy>, public WebCore::UserMessageHandlerDescriptor::Client {
97
public:
111
public:
- a/Source/WebKit2/WebProcess/UserContent/WebUserContentController.h +3 lines
Lines 54-59 private: a/Source/WebKit2/WebProcess/UserContent/WebUserContentController.h_sec1
54
    void addUserScripts(const Vector<WebCore::UserScript>& userScripts);
54
    void addUserScripts(const Vector<WebCore::UserScript>& userScripts);
55
    void removeAllUserScripts();
55
    void removeAllUserScripts();
56
56
57
    void addUserStyleSheets(const Vector<WebCore::UserStyleSheet>& userStyleSheets);
58
    void removeAllUserStyleSheets();
59
57
    void addUserScriptMessageHandlers(const Vector<WebScriptMessageHandlerHandle>& scriptMessageHandlers);
60
    void addUserScriptMessageHandlers(const Vector<WebScriptMessageHandlerHandle>& scriptMessageHandlers);
58
    void removeUserScriptMessageHandler(uint64_t);
61
    void removeUserScriptMessageHandler(uint64_t);
59
62
- a/Source/WebKit2/WebProcess/UserContent/WebUserContentController.messages.in +3 lines
Lines 27-32 messages -> WebUserContentController { a/Source/WebKit2/WebProcess/UserContent/WebUserContentController.messages.in_sec1
27
    AddUserScripts(Vector<WebCore::UserScript> userScripts);
27
    AddUserScripts(Vector<WebCore::UserScript> userScripts);
28
    RemoveAllUserScripts()
28
    RemoveAllUserScripts()
29
29
30
    AddUserStyleSheets(Vector<WebCore::UserStyleSheet> userStyleShhets);
31
    RemoveAllUserStyleSheets()
32
30
    AddUserScriptMessageHandlers(Vector<WebKit::WebScriptMessageHandlerHandle> scriptMessageHandlers);
33
    AddUserScriptMessageHandlers(Vector<WebKit::WebScriptMessageHandlerHandle> scriptMessageHandlers);
31
    RemoveUserScriptMessageHandler(uint64_t identifier)
34
    RemoveUserScriptMessageHandler(uint64_t identifier)
32
}
35
}

Return to Bug 133730