Update Romanian translation
[evolution.git] / src / modules / webkit-editor / web-extension / e-editor-web-extension.c
blobd799db498ea767bdb7da5b1c015bc9093d117a6d
1 /*
2 * e-editor-web-extension.c
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) version 3.
9 * This program 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 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with the program; if not, see <http://www.gnu.org/licenses/>
19 #include "evolution-config.h"
21 #include <string.h>
23 #include <glib/gstdio.h>
24 #include <gio/gio.h>
25 #include <gtk/gtk.h>
26 #include <webkit2/webkit-web-extension.h>
27 #include <camel/camel.h>
29 #include <webkitdom/webkitdom.h>
31 #include "web-extensions/e-dom-utils.h"
33 #include "e-editor-page.h"
34 #include "e-composer-dom-functions.h"
35 #include "e-dialogs-dom-functions.h"
36 #include "e-editor-dom-functions.h"
37 #include "e-editor-undo-redo-manager.h"
39 #include "e-editor-web-extension.h"
41 #define E_EDITOR_WEB_EXTENSION_GET_PRIVATE(obj) \
42 (G_TYPE_INSTANCE_GET_PRIVATE \
43 ((obj), E_TYPE_EDITOR_WEB_EXTENSION, EEditorWebExtensionPrivate))
45 struct _EEditorWebExtensionPrivate {
46 WebKitWebExtension *wk_extension;
48 GDBusConnection *dbus_connection;
49 guint registration_id;
51 GHashTable *editor_pages; /* guint64 *webpage_id ~> EEditorPage * */
54 static CamelDataCache *emd_global_http_cache = NULL;
56 static const gchar *introspection_xml =
57 "<node>"
58 " <interface name='" E_WEBKIT_EDITOR_WEB_EXTENSION_INTERFACE "'>"
59 "<!-- ********************************************************* -->"
60 "<!-- SIGNALS -->"
61 "<!-- ********************************************************* -->"
62 " <signal name='SelectionChanged'>"
63 " <arg type='t' name='page_id' direction='out'/>"
64 " <arg type='i' name='alignment' direction='out'/>"
65 " <arg type='i' name='block_format' direction='out'/>"
66 " <arg type='b' name='indented' direction='out'/>"
67 " <arg type='i' name='style_flags' direction='out'/>"
68 " <arg type='i' name='font_size' direction='out'/>"
69 " <arg type='s' name='font_color' direction='out'/>"
70 " </signal>"
71 " <signal name='ContentChanged'>"
72 " <arg type='t' name='page_id' direction='out'/>"
73 " </signal>"
74 " <signal name='UndoRedoStateChanged'>"
75 " <arg type='t' name='page_id' direction='out'/>"
76 " <arg type='b' name='can_undo' direction='out'/>"
77 " <arg type='b' name='can_redo' direction='out'/>"
78 " </signal>"
79 " <signal name='UserChangedDefaultColors'>"
80 " <arg type='b' name='suppress_color_changes' direction='out'/>"
81 " </signal>"
82 "<!-- ********************************************************* -->"
83 "<!-- METHODS -->"
84 "<!-- ********************************************************* -->"
85 "<!-- ********************************************************* -->"
86 "<!-- FOR TESTING ONLY -->"
87 "<!-- ********************************************************* -->"
88 " <method name='TestHTMLEqual'>"
89 " <arg type='t' name='page_id' direction='in'/>"
90 " <arg type='s' name='html1' direction='in'/>"
91 " <arg type='s' name='html2' direction='in'/>"
92 " <arg type='b' name='equal' direction='out'/>"
93 " </method>"
94 "<!-- ********************************************************* -->"
95 "<!-- GENERIC -->"
96 "<!-- ********************************************************* -->"
97 " <method name='ElementHasAttribute'>"
98 " <arg type='t' name='page_id' direction='in'/>"
99 " <arg type='s' name='element_id' direction='in'/>"
100 " <arg type='s' name='attribute' direction='in'/>"
101 " <arg type='b' name='has_attribute' direction='out'/>"
102 " </method>"
103 " <method name='ElementGetAttribute'>"
104 " <arg type='t' name='page_id' direction='in'/>"
105 " <arg type='s' name='element_id' direction='in'/>"
106 " <arg type='s' name='attribute' direction='in'/>"
107 " <arg type='s' name='value' direction='out'/>"
108 " </method>"
109 " <method name='ElementGetAttributeBySelector'>"
110 " <arg type='t' name='page_id' direction='in'/>"
111 " <arg type='s' name='selector' direction='in'/>"
112 " <arg type='s' name='attribute' direction='in'/>"
113 " <arg type='s' name='value' direction='out'/>"
114 " </method>"
115 " <method name='ElementRemoveAttribute'>"
116 " <arg type='t' name='page_id' direction='in'/>"
117 " <arg type='s' name='element_id' direction='in'/>"
118 " <arg type='s' name='attribute' direction='in'/>"
119 " </method>"
120 " <method name='ElementRemoveAttributeBySelector'>"
121 " <arg type='t' name='page_id' direction='in'/>"
122 " <arg type='s' name='selector' direction='in'/>"
123 " <arg type='s' name='attribute' direction='in'/>"
124 " </method>"
125 " <method name='ElementSetAttribute'>"
126 " <arg type='t' name='page_id' direction='in'/>"
127 " <arg type='s' name='element_id' direction='in'/>"
128 " <arg type='s' name='attribute' direction='in'/>"
129 " <arg type='s' name='value' direction='in'/>"
130 " </method>"
131 " <method name='ElementSetAttributeBySelector'>"
132 " <arg type='t' name='page_id' direction='in'/>"
133 " <arg type='s' name='selector' direction='in'/>"
134 " <arg type='s' name='attribute' direction='in'/>"
135 " <arg type='s' name='value' direction='in'/>"
136 " </method>"
137 " <method name='ElementGetTagName'>"
138 " <arg type='t' name='page_id' direction='in'/>"
139 " <arg type='s' name='element_id' direction='in'/>"
140 " <arg type='s' name='tag_name' direction='out'/>"
141 " </method>"
142 "<!-- ********************************************************* -->"
143 "<!-- Functions that are specific to composer -->"
144 "<!-- ********************************************************* -->"
145 " <method name='RemoveImageAttributesFromElementBySelector'>"
146 " <arg type='t' name='page_id' direction='in'/>"
147 " <arg type='s' name='selector' direction='in'/>"
148 " </method>"
149 "<!-- ********************************************************* -->"
150 "<!-- Functions that are used in EEditorCellDialog -->"
151 "<!-- ********************************************************* -->"
152 " <method name='EEditorCellDialogMarkCurrentCellElement'>"
153 " <arg type='t' name='page_id' direction='in'/>"
154 " <arg type='s' name='element_id' direction='in'/>"
155 " </method>"
156 " <method name='EEditorCellDialogSaveHistoryOnExit'>"
157 " <arg type='t' name='page_id' direction='in'/>"
158 " </method>"
159 " <method name='EEditorCellDialogSetElementVAlign'>"
160 " <arg type='t' name='page_id' direction='in'/>"
161 " <arg type='s' name='value' direction='in'/>"
162 " <arg type='i' name='scope' direction='in'/>"
163 " </method>"
164 " <method name='EEditorCellDialogSetElementAlign'>"
165 " <arg type='t' name='page_id' direction='in'/>"
166 " <arg type='s' name='value' direction='in'/>"
167 " <arg type='i' name='scope' direction='in'/>"
168 " </method>"
169 " <method name='EEditorCellDialogSetElementNoWrap'>"
170 " <arg type='t' name='page_id' direction='in'/>"
171 " <arg type='b' name='value' direction='in'/>"
172 " <arg type='i' name='scope' direction='in'/>"
173 " </method>"
174 " <method name='EEditorCellDialogSetElementHeaderStyle'>"
175 " <arg type='t' name='page_id' direction='in'/>"
176 " <arg type='b' name='value' direction='in'/>"
177 " <arg type='i' name='scope' direction='in'/>"
178 " </method>"
179 " <method name='EEditorCellDialogSetElementWidth'>"
180 " <arg type='t' name='page_id' direction='in'/>"
181 " <arg type='s' name='value' direction='in'/>"
182 " <arg type='i' name='scope' direction='in'/>"
183 " </method>"
184 " <method name='EEditorCellDialogSetElementColSpan'>"
185 " <arg type='t' name='page_id' direction='in'/>"
186 " <arg type='i' name='value' direction='in'/>"
187 " <arg type='i' name='scope' direction='in'/>"
188 " </method>"
189 " <method name='EEditorCellDialogSetElementRowSpan'>"
190 " <arg type='t' name='page_id' direction='in'/>"
191 " <arg type='i' name='value' direction='in'/>"
192 " <arg type='i' name='scope' direction='in'/>"
193 " </method>"
194 " <method name='EEditorCellDialogSetElementBgColor'>"
195 " <arg type='t' name='page_id' direction='in'/>"
196 " <arg type='s' name='value' direction='in'/>"
197 " <arg type='i' name='scope' direction='in'/>"
198 " </method>"
199 "<!-- ********************************************************* -->"
200 "<!-- Functions that are used in EEditorHRuleDialog -->"
201 "<!-- ********************************************************* -->"
202 " <method name='EEditorHRuleDialogFindHRule'>"
203 " <arg type='t' name='page_id' direction='in'/>"
204 " <arg type='b' name='created_new_hr' direction='out'/>"
205 " </method>"
206 " <method name='EEditorHRuleDialogOnClose'>"
207 " <arg type='t' name='page_id' direction='in'/>"
208 " </method>"
209 "<!-- ********************************************************* -->"
210 "<!-- Functions that are used in EEditorImageDialog -->"
211 "<!-- ********************************************************* -->"
212 " <method name='EEditorImageDialogMarkImage'>"
213 " <arg type='t' name='page_id' direction='in'/>"
214 " </method>"
215 " <method name='EEditorImageDialogSaveHistoryOnExit'>"
216 " <arg type='t' name='page_id' direction='in'/>"
217 " </method>"
218 " <method name='EEditorImageDialogSetElementUrl'>"
219 " <arg type='t' name='page_id' direction='in'/>"
220 " <arg type='s' name='value' direction='in'/>"
221 " </method>"
222 " <method name='EEditorImageDialogGetElementUrl'>"
223 " <arg type='t' name='page_id' direction='in'/>"
224 " <arg type='s' name='value' direction='out'/>"
225 " </method>"
226 " <method name='ImageElementSetWidth'>"
227 " <arg type='t' name='page_id' direction='in'/>"
228 " <arg type='s' name='element_id' direction='in'/>"
229 " <arg type='i' name='value' direction='in'/>"
230 " </method>"
231 " <method name='ImageElementGetWidth'>"
232 " <arg type='t' name='page_id' direction='in'/>"
233 " <arg type='s' name='element_id' direction='in'/>"
234 " <arg type='i' name='value' direction='out'/>"
235 " </method>"
236 " <method name='ImageElementSetHeight'>"
237 " <arg type='t' name='page_id' direction='in'/>"
238 " <arg type='s' name='element_id' direction='in'/>"
239 " <arg type='i' name='value' direction='in'/>"
240 " </method>"
241 " <method name='ImageElementGetHeight'>"
242 " <arg type='t' name='page_id' direction='in'/>"
243 " <arg type='s' name='element_id' direction='in'/>"
244 " <arg type='i' name='value' direction='out'/>"
245 " </method>"
246 " <method name='ImageElementGetNaturalWidth'>"
247 " <arg type='t' name='page_id' direction='in'/>"
248 " <arg type='s' name='element_id' direction='in'/>"
249 " <arg type='i' name='value' direction='out'/>"
250 " </method>"
251 " <method name='ImageElementGetNaturalHeight'>"
252 " <arg type='t' name='page_id' direction='in'/>"
253 " <arg type='s' name='element_id' direction='in'/>"
254 " <arg type='i' name='value' direction='out'/>"
255 " </method>"
256 " <method name='ImageElementSetHSpace'>"
257 " <arg type='t' name='page_id' direction='in'/>"
258 " <arg type='s' name='element_id' direction='in'/>"
259 " <arg type='i' name='value' direction='in'/>"
260 " </method>"
261 " <method name='ImageElementGetHSpace'>"
262 " <arg type='t' name='page_id' direction='in'/>"
263 " <arg type='s' name='element_id' direction='in'/>"
264 " <arg type='i' name='value' direction='out'/>"
265 " </method>"
266 " <method name='ImageElementSetVSpace'>"
267 " <arg type='t' name='page_id' direction='in'/>"
268 " <arg type='s' name='element_id' direction='in'/>"
269 " <arg type='i' name='value' direction='in'/>"
270 " </method>"
271 " <method name='ImageElementGetVSpace'>"
272 " <arg type='t' name='page_id' direction='in'/>"
273 " <arg type='s' name='element_id' direction='in'/>"
274 " <arg type='i' name='value' direction='out'/>"
275 " </method>"
276 "<!-- ********************************************************* -->"
277 "<!-- Functions that are used in EEditorLinkDialog -->"
278 "<!-- ********************************************************* -->"
279 " <method name='EEditorLinkDialogOk'>"
280 " <arg type='t' name='page_id' direction='in'/>"
281 " <arg type='s' name='url' direction='in'/>"
282 " <arg type='s' name='inner_text' direction='in'/>"
283 " </method>"
284 " <method name='EEditorLinkDialogShow'>"
285 " <arg type='t' name='page_id' direction='in'/>"
286 " <arg type='s' name='url' direction='out'/>"
287 " <arg type='s' name='inner_text' direction='out'/>"
288 " </method>"
289 " <method name='EEditorLinkDialogOnOpen'>"
290 " <arg type='t' name='page_id' direction='in'/>"
291 " </method>"
292 " <method name='EEditorLinkDialogOnClose'>"
293 " <arg type='t' name='page_id' direction='in'/>"
294 " </method>"
295 " <method name='EEditorLinkDialogUnlink'>"
296 " <arg type='t' name='page_id' direction='in'/>"
297 " </method>"
298 "<!-- ********************************************************* -->"
299 "<!-- Functions that are used in EEditorPageDialog -->"
300 "<!-- ********************************************************* -->"
301 " <method name='EEditorPageDialogSaveHistory'>"
302 " <arg type='t' name='page_id' direction='in'/>"
303 " </method>"
304 " <method name='EEditorPageDialogSaveHistoryOnExit'>"
305 " <arg type='t' name='page_id' direction='in'/>"
306 " </method>"
307 "<!-- ********************************************************* -->"
308 "<!-- Functions that are used in EEditorSpellCheckDialog -->"
309 "<!-- ********************************************************* -->"
310 " <method name='EEditorSpellCheckDialogNext'>"
311 " <arg type='t' name='page_id' direction='in'/>"
312 " <arg type='s' name='word' direction='in'/>"
313 " <arg type='as' name='languages' direction='in'/>"
314 " <arg type='s' name='next_word' direction='out'/>"
315 " </method>"
316 " <method name='EEditorSpellCheckDialogPrev'>"
317 " <arg type='t' name='page_id' direction='in'/>"
318 " <arg type='s' name='word' direction='in'/>"
319 " <arg type='as' name='languages' direction='in'/>"
320 " <arg type='s' name='prev_word' direction='out'/>"
321 " </method>"
322 "<!-- ********************************************************* -->"
323 "<!-- Functions that are used in EEditorTableDialog -->"
324 "<!-- ********************************************************* -->"
325 " <method name='EEditorTableDialogSetRowCount'>"
326 " <arg type='t' name='page_id' direction='in'/>"
327 " <arg type='u' name='value' direction='in'/>"
328 " </method>"
329 " <method name='EEditorTableDialogGetRowCount'>"
330 " <arg type='t' name='page_id' direction='in'/>"
331 " <arg type='u' name='value' direction='out'/>"
332 " </method>"
333 " <method name='EEditorTableDialogSetColumnCount'>"
334 " <arg type='t' name='page_id' direction='in'/>"
335 " <arg type='u' name='value' direction='in'/>"
336 " </method>"
337 " <method name='EEditorTableDialogGetColumnCount'>"
338 " <arg type='t' name='page_id' direction='in'/>"
339 " <arg type='u' name='value' direction='out'/>"
340 " </method>"
341 " <method name='EEditorTableDialogShow'>"
342 " <arg type='t' name='page_id' direction='in'/>"
343 " <arg type='b' name='created_new_table' direction='out'/>"
344 " </method>"
345 " <method name='EEditorTableDialogSaveHistoryOnExit'>"
346 " <arg type='t' name='page_id' direction='in'/>"
347 " </method>"
348 "<!-- ********************************************************* -->"
349 "<!-- Functions that are used in EEditorActions -->"
350 "<!-- ********************************************************* -->"
351 " <method name='TableCellElementGetNoWrap'>"
352 " <arg type='t' name='page_id' direction='in'/>"
353 " <arg type='s' name='element_id' direction='in'/>"
354 " <arg type='b' name='no_wrap' direction='out'/>"
355 " </method>"
356 " <method name='TableCellElementGetRowSpan'>"
357 " <arg type='t' name='page_id' direction='in'/>"
358 " <arg type='s' name='element_id' direction='in'/>"
359 " <arg type='i' name='row_span' direction='out'/>"
360 " </method>"
361 " <method name='TableCellElementGetColSpan'>"
362 " <arg type='t' name='page_id' direction='in'/>"
363 " <arg type='s' name='element_id' direction='in'/>"
364 " <arg type='i' name='col_span' direction='out'/>"
365 " </method>"
366 " <method name='EEditorDialogDeleteCellContents'>"
367 " <arg type='t' name='page_id' direction='in'/>"
368 " </method>"
369 " <method name='EEditorDialogDeleteColumn'>"
370 " <arg type='t' name='page_id' direction='in'/>"
371 " </method>"
372 " <method name='EEditorDialogDeleteRow'>"
373 " <arg type='t' name='page_id' direction='in'/>"
374 " </method>"
375 " <method name='EEditorDialogDeleteTable'>"
376 " <arg type='t' name='page_id' direction='in'/>"
377 " </method>"
378 " <method name='EEditorDialogInsertColumnAfter'>"
379 " <arg type='t' name='page_id' direction='in'/>"
380 " </method>"
381 " <method name='EEditorDialogInsertColumnBefore'>"
382 " <arg type='t' name='page_id' direction='in'/>"
383 " </method>"
384 " <method name='EEditorDialogInsertRowAbove'>"
385 " <arg type='t' name='page_id' direction='in'/>"
386 " </method>"
387 " <method name='EEditorDialogInsertRowBelow'>"
388 " <arg type='t' name='page_id' direction='in'/>"
389 " </method>"
390 " <method name='EEditorActionsSaveHistoryForCut'>"
391 " <arg type='t' name='page_id' direction='in'/>"
392 " </method>"
393 "<!-- ********************************************************* -->"
394 "<!-- Functions that are used in EEditorView -->"
395 "<!-- ********************************************************* -->"
396 " <method name='SetPastingContentFromItself'>"
397 " <arg type='t' name='page_id' direction='in'/>"
398 " <arg type='b' name='value' direction='in'/>"
399 " </method>"
400 " <method name='SetEditorHTMLMode'>"
401 " <arg type='t' name='page_id' direction='in'/>"
402 " <arg type='b' name='html_mode' direction='in'/>"
403 " <arg type='b' name='convert' direction='in'/>"
404 " </method>"
405 " <method name='SetConvertInSitu'>"
406 " <arg type='t' name='page_id' direction='in'/>"
407 " <arg type='b' name='value' direction='in'/>"
408 " <arg type='n' name='start_at_bottom' direction='in'/>"
409 " <arg type='n' name='top_signature' direction='in'/>"
410 " </method>"
411 " <method name='DOMForceSpellCheck'>"
412 " <arg type='t' name='page_id' direction='in'/>"
413 " </method>"
414 " <method name='DOMTurnSpellCheckOff'>"
415 " <arg type='t' name='page_id' direction='in'/>"
416 " </method>"
417 " <method name='DOMScrollToCaret'>"
418 " <arg type='t' name='page_id' direction='in'/>"
419 " </method>"
420 " <method name='DOMEmbedStyleSheet'>"
421 " <arg type='t' name='page_id' direction='in'/>"
422 " <arg type='s' name='style_sheet_content' direction='in'/>"
423 " </method>"
424 " <method name='DOMRemoveEmbeddedStyleSheet'>"
425 " <arg type='t' name='page_id' direction='in'/>"
426 " </method>"
427 " <method name='DOMSaveSelection'>"
428 " <arg type='t' name='page_id' direction='in'/>"
429 " </method>"
430 " <method name='DOMRestoreSelection'>"
431 " <arg type='t' name='page_id' direction='in'/>"
432 " </method>"
433 " <method name='DOMUndo'>"
434 " <arg type='t' name='page_id' direction='in'/>"
435 " </method>"
436 " <method name='DOMRedo'>"
437 " <arg type='t' name='page_id' direction='in'/>"
438 " </method>"
439 " <method name='DOMQuoteAndInsertTextIntoSelection'>"
440 " <arg type='t' name='page_id' direction='in'/>"
441 " <arg type='s' name='text' direction='in'/>"
442 " <arg type='b' name='is_html' direction='in'/>"
443 " </method>"
444 " <method name='DOMConvertAndInsertHTMLIntoSelection'>"
445 " <arg type='t' name='page_id' direction='in'/>"
446 " <arg type='s' name='text' direction='in'/>"
447 " <arg type='b' name='is_html' direction='in'/>"
448 " </method>"
449 " <method name='DOMCheckIfConversionNeeded'>"
450 " <arg type='t' name='page_id' direction='in'/>"
451 " <arg type='b' name='conversion_needed' direction='out'/>"
452 " </method>"
453 " <method name='DOMGetContent'>"
454 " <arg type='t' name='page_id' direction='in'/>"
455 " <arg type='s' name='from_domain' direction='in'/>"
456 " <arg type='i' name='flags' direction='in'/>"
457 " <arg type='s' name='content' direction='out'/>"
458 " <arg type='v' name='inline_images' direction='out'/>"
459 " </method>"
460 " <method name='DOMInsertHTML'>"
461 " <arg type='t' name='page_id' direction='in'/>"
462 " <arg type='s' name='html' direction='in'/>"
463 " </method>"
464 " <method name='DOMConvertContent'>"
465 " <arg type='t' name='page_id' direction='in'/>"
466 " <arg type='s' name='preffered_text' direction='in'/>"
467 " <arg type='n' name='start_at_bottom' direction='in'/>"
468 " <arg type='n' name='top_signature' direction='in'/>"
469 " </method>"
470 " <method name='DOMAddNewInlineImageIntoList'>"
471 " <arg type='t' name='page_id' direction='in'/>"
472 " <arg type='s' name='filename' direction='in'/>"
473 " <arg type='s' name='cid_src' direction='in'/>"
474 " <arg type='s' name='src' direction='in'/>"
475 " </method>"
476 " <method name='DOMReplaceImageSrc'>"
477 " <arg type='t' name='page_id' direction='in'/>"
478 " <arg type='s' name='selector' direction='in'/>"
479 " <arg type='s' name='uri' direction='in'/>"
480 " </method>"
481 " <method name='DOMMoveSelectionOnPoint'>"
482 " <arg type='t' name='page_id' direction='in'/>"
483 " <arg type='i' name='x' direction='in'/>"
484 " <arg type='i' name='y' direction='in'/>"
485 " <arg type='b' name='cancel_if_not_collapsed' direction='in'/>"
486 " </method>"
487 " <method name='DOMInsertSmiley'>"
488 " <arg type='t' name='page_id' direction='in'/>"
489 " <arg type='s' name='smiley_name' direction='in'/>"
490 " </method>"
491 " <method name='DOMLastDropOperationDidCopy'>"
492 " <arg type='t' name='page_id' direction='in'/>"
493 " </method>"
494 "<!-- ********************************************************* -->"
495 "<!-- Functions that are used in EEditorSelection -->"
496 "<!-- ********************************************************* -->"
497 " <method name='DOMSelectionIndent'>"
498 " <arg type='t' name='page_id' direction='in'/>"
499 " </method>"
500 " <method name='DOMSelectionInsertImage'>"
501 " <arg type='t' name='page_id' direction='in'/>"
502 " <arg type='s' name='uri' direction='in'/>"
503 " </method>"
504 " <method name='DOMInsertReplaceAllHistoryEvent'>"
505 " <arg type='t' name='page_id' direction='in'/>"
506 " <arg type='s' name='search_text' direction='in'/>"
507 " <arg type='s' name='replacement' direction='in'/>"
508 " </method>"
509 " <method name='DOMSelectionReplace'>"
510 " <arg type='t' name='page_id' direction='in'/>"
511 " <arg type='s' name='replacement' direction='in'/>"
512 " </method>"
513 " <method name='DOMSelectionSetAlignment'>"
514 " <arg type='t' name='page_id' direction='in'/>"
515 " <arg type='i' name='alignment' direction='in'/>"
516 " </method>"
517 " <method name='DOMSelectionSetBold'>"
518 " <arg type='t' name='page_id' direction='in'/>"
519 " <arg type='b' name='bold' direction='in'/>"
520 " </method>"
521 " <method name='DOMSelectionSetBlockFormat'>"
522 " <arg type='t' name='page_id' direction='in'/>"
523 " <arg type='i' name='block_format' direction='in'/>"
524 " </method>"
525 " <method name='DOMSelectionSetFontColor'>"
526 " <arg type='t' name='page_id' direction='in'/>"
527 " <arg type='s' name='color' direction='in'/>"
528 " </method>"
529 " <method name='DOMSelectionSetFontSize'>"
530 " <arg type='t' name='page_id' direction='in'/>"
531 " <arg type='i' name='font_size' direction='in'/>"
532 " </method>"
533 " <method name='DOMSelectionSetItalic'>"
534 " <arg type='t' name='page_id' direction='in'/>"
535 " <arg type='b' name='italic' direction='in'/>"
536 " </method>"
537 " <method name='DOMSelectionSetMonospaced'>"
538 " <arg type='t' name='page_id' direction='in'/>"
539 " <arg type='b' name='monospaced' direction='in'/>"
540 " </method>"
541 " <method name='DOMSelectionSetStrikethrough'>"
542 " <arg type='t' name='page_id' direction='in'/>"
543 " <arg type='b' name='strikethrough' direction='in'/>"
544 " </method>"
545 " <method name='DOMSelectionSetSubscript'>"
546 " <arg type='t' name='page_id' direction='in'/>"
547 " <arg type='b' name='subscript' direction='in'/>"
548 " </method>"
549 " <method name='DOMSelectionSetSuperscript'>"
550 " <arg type='t' name='page_id' direction='in'/>"
551 " <arg type='b' name='superscript' direction='in'/>"
552 " </method>"
553 " <method name='DOMSelectionSetUnderline'>"
554 " <arg type='t' name='page_id' direction='in'/>"
555 " <arg type='b' name='underline' direction='in'/>"
556 " </method>"
557 " <method name='DOMSelectionUnindent'>"
558 " <arg type='t' name='page_id' direction='in'/>"
559 " </method>"
560 " <method name='DOMSelectionWrap'>"
561 " <arg type='t' name='page_id' direction='in'/>"
562 " </method>"
563 " <method name='DOMGetCaretWord'>"
564 " <arg type='t' name='page_id' direction='in'/>"
565 " <arg type='s' name='word' direction='out'/>"
566 " </method>"
567 " <method name='DOMReplaceCaretWord'>"
568 " <arg type='t' name='page_id' direction='in'/>"
569 " <arg type='s' name='replacement' direction='in'/>"
570 " </method>"
571 "<!-- ********************************************************* -->"
572 "<!-- Functions that are used in EComposerPrivate -->"
573 "<!-- ********************************************************* -->"
574 " <method name='DOMInsertSignature'>"
575 " <arg type='t' name='page_id' direction='in'/>"
576 " <arg type='s' name='content' direction='in'/>"
577 " <arg type='b' name='is_html' direction='in'/>"
578 " <arg type='s' name='signature_id' direction='in'/>"
579 " <arg type='b' name='set_signature_from_message' direction='in'/>"
580 " <arg type='b' name='check_if_signature_is_changed' direction='in'/>"
581 " <arg type='b' name='ignore_next_signature_change' direction='in'/>"
582 " <arg type='n' name='start_at_bottom' direction='in'/>"
583 " <arg type='n' name='top_signature' direction='in'/>"
584 " <arg type='s' name='new_signature_id' direction='out'/>"
585 " <arg type='b' name='out_set_signature_from_message' direction='out'/>"
586 " <arg type='b' name='out_check_if_signature_is_changed' direction='out'/>"
587 " <arg type='b' name='out_ignore_next_signature_change' direction='out'/>"
588 " </method>"
589 " <method name='DOMGetActiveSignatureUid'>"
590 " <arg type='t' name='page_id' direction='in'/>"
591 " <arg type='s' name='uid' direction='out'/>"
592 " </method>"
593 "<!-- ********************************************************* -->"
594 "<!-- Functions that are used in External Editor plugin -->"
595 "<!-- ********************************************************* -->"
596 " <method name='DOMGetCaretPosition'>"
597 " <arg type='t' name='page_id' direction='in'/>"
598 " <arg type='u' name='position' direction='out'/>"
599 " </method>"
600 " <method name='DOMGetCaretOffset'>"
601 " <arg type='t' name='page_id' direction='in'/>"
602 " <arg type='u' name='offset' direction='out'/>"
603 " </method>"
604 " <method name='DOMClearUndoRedoHistory'>"
605 " <arg type='t' name='page_id' direction='in'/>"
606 " </method>"
607 " </interface>"
608 "</node>";
610 G_DEFINE_TYPE (EEditorWebExtension, e_editor_web_extension, G_TYPE_OBJECT)
612 static EEditorPage *
613 get_editor_page (EEditorWebExtension *extension,
614 guint64 page_id)
616 g_return_val_if_fail (E_IS_EDITOR_WEB_EXTENSION (extension), NULL);
618 return g_hash_table_lookup (extension->priv->editor_pages, &page_id);
621 static EEditorPage *
622 get_editor_page_or_return_dbus_error (GDBusMethodInvocation *invocation,
623 EEditorWebExtension *extension,
624 guint64 page_id)
626 WebKitWebPage *web_page;
627 EEditorPage *editor_page;
629 g_return_val_if_fail (E_IS_EDITOR_WEB_EXTENSION (extension), NULL);
631 web_page = webkit_web_extension_get_page (extension->priv->wk_extension, page_id);
632 if (!web_page) {
633 g_dbus_method_invocation_return_error (
634 invocation, G_DBUS_ERROR, G_DBUS_ERROR_INVALID_ARGS,
635 "Invalid page ID: %" G_GUINT64_FORMAT, page_id);
637 return NULL;
640 editor_page = get_editor_page (extension, page_id);
641 if (!editor_page) {
642 g_dbus_method_invocation_return_error (
643 invocation, G_DBUS_ERROR, G_DBUS_ERROR_INVALID_ARGS,
644 "Invalid page ID: %" G_GUINT64_FORMAT, page_id);
647 return editor_page;
650 static void
651 handle_method_call (GDBusConnection *connection,
652 const char *sender,
653 const char *object_path,
654 const char *interface_name,
655 const char *method_name,
656 GVariant *parameters,
657 GDBusMethodInvocation *invocation,
658 gpointer user_data)
660 guint64 page_id;
661 EEditorWebExtension *extension = E_EDITOR_WEB_EXTENSION (user_data);
662 WebKitDOMDocument *document;
663 EEditorPage *editor_page;
665 if (g_strcmp0 (interface_name, E_WEBKIT_EDITOR_WEB_EXTENSION_INTERFACE) != 0)
666 return;
668 if (camel_debug ("webkit:editor"))
669 printf ("EEditorWebExtension - %s - %s\n", G_STRFUNC, method_name);
671 if (g_strcmp0 (method_name, "TestHTMLEqual") == 0) {
672 gboolean equal = FALSE;
673 const gchar *html1 = NULL, *html2 = NULL;
675 g_variant_get (parameters, "(t&s&s)", &page_id, &html1, &html2);
677 editor_page = get_editor_page_or_return_dbus_error (invocation, extension, page_id);
678 if (!editor_page)
679 goto error;
681 document = e_editor_page_get_document (editor_page);
682 equal = e_editor_dom_test_html_equal (document, html1, html2);
684 g_dbus_method_invocation_return_value (invocation, g_variant_new ("(b)", equal));
685 } else if (g_strcmp0 (method_name, "ElementHasAttribute") == 0) {
686 gboolean value = FALSE;
687 const gchar *element_id, *attribute;
688 WebKitDOMElement *element;
690 g_variant_get (
691 parameters, "(t&s&s)", &page_id, &element_id, &attribute);
693 editor_page = get_editor_page_or_return_dbus_error (invocation, extension, page_id);
694 if (!editor_page)
695 goto error;
697 document = e_editor_page_get_document (editor_page);
698 element = webkit_dom_document_get_element_by_id (document, element_id);
699 if (element)
700 value = webkit_dom_element_has_attribute (element, attribute);
702 g_dbus_method_invocation_return_value (
703 invocation, g_variant_new ("(b)", value));
704 } else if (g_strcmp0 (method_name, "ElementGetAttribute") == 0) {
705 const gchar *element_id, *attribute;
706 gchar *value = NULL;
707 WebKitDOMElement *element;
709 g_variant_get (
710 parameters, "(t&s&s)", &page_id, &element_id, &attribute);
712 editor_page = get_editor_page_or_return_dbus_error (invocation, extension, page_id);
713 if (!editor_page)
714 goto error;
716 document = e_editor_page_get_document (editor_page);
717 element = webkit_dom_document_get_element_by_id (document, element_id);
718 if (element)
719 value = webkit_dom_element_get_attribute (element, attribute);
721 g_dbus_method_invocation_return_value (
722 invocation,
723 g_variant_new (
724 "(@s)",
725 g_variant_new_take_string (
726 value ? value : g_strdup (""))));
727 } else if (g_strcmp0 (method_name, "ElementGetAttributeBySelector") == 0) {
728 const gchar *attribute, *selector;
729 gchar *value = NULL;
730 WebKitDOMElement *element;
732 g_variant_get (
733 parameters, "(t&s&s)", &page_id, &selector, &attribute);
735 editor_page = get_editor_page_or_return_dbus_error (invocation, extension, page_id);
736 if (!editor_page)
737 goto error;
739 document = e_editor_page_get_document (editor_page);
740 element = webkit_dom_document_query_selector (document, selector, NULL);
741 if (element)
742 value = webkit_dom_element_get_attribute (element, attribute);
744 g_dbus_method_invocation_return_value (
745 invocation,
746 g_variant_new (
747 "(@s)",
748 g_variant_new_take_string (
749 value ? value : g_strdup (""))));
750 } else if (g_strcmp0 (method_name, "ElementRemoveAttribute") == 0) {
751 const gchar *element_id, *attribute;
752 WebKitDOMElement *element;
754 g_variant_get (
755 parameters, "(t&s&s)", &page_id, &element_id, &attribute);
757 editor_page = get_editor_page_or_return_dbus_error (invocation, extension, page_id);
758 if (!editor_page)
759 goto error;
761 document = e_editor_page_get_document (editor_page);
762 element = webkit_dom_document_get_element_by_id (document, element_id);
763 if (element)
764 webkit_dom_element_remove_attribute (element, attribute);
766 g_dbus_method_invocation_return_value (invocation, NULL);
767 } else if (g_strcmp0 (method_name, "ElementRemoveAttributeBySelector") == 0) {
768 const gchar *attribute, *selector;
769 WebKitDOMElement *element;
771 g_variant_get (
772 parameters, "(t&s&s)", &page_id, &selector, &attribute);
774 editor_page = get_editor_page_or_return_dbus_error (invocation, extension, page_id);
775 if (!editor_page)
776 goto error;
778 document = e_editor_page_get_document (editor_page);
779 element = webkit_dom_document_query_selector (document, selector, NULL);
780 if (element)
781 webkit_dom_element_remove_attribute (element, attribute);
783 g_dbus_method_invocation_return_value (invocation, NULL);
784 } else if (g_strcmp0 (method_name, "ElementSetAttribute") == 0) {
785 const gchar *element_id, *attribute, *value;
786 WebKitDOMElement *element;
788 g_variant_get (
789 parameters,
790 "(t&s&s&s)",
791 &page_id, &element_id, &attribute, &value);
793 editor_page = get_editor_page_or_return_dbus_error (invocation, extension, page_id);
794 if (!editor_page)
795 goto error;
797 document = e_editor_page_get_document (editor_page);
798 element = webkit_dom_document_get_element_by_id (document, element_id);
799 if (element)
800 webkit_dom_element_set_attribute (
801 element, attribute, value, NULL);
803 g_dbus_method_invocation_return_value (invocation, NULL);
804 } else if (g_strcmp0 (method_name, "ElementSetAttributeBySelector") == 0) {
805 const gchar *attribute, *selector, *value;
806 WebKitDOMElement *element;
808 g_variant_get (
809 parameters, "(t&s&s&s)", &page_id, &selector, &attribute, &value);
811 editor_page = get_editor_page_or_return_dbus_error (invocation, extension, page_id);
812 if (!editor_page)
813 goto error;
815 document = e_editor_page_get_document (editor_page);
816 element = webkit_dom_document_query_selector (document, selector, NULL);
817 if (element) {
818 if (g_strcmp0 (selector, "body") == 0 &&
819 g_strcmp0 (attribute, "link") == 0)
820 e_editor_dom_set_link_color (editor_page, value);
821 else if (g_strcmp0 (selector, "body") == 0 &&
822 g_strcmp0 (attribute, "vlink") == 0)
823 e_editor_dom_set_visited_link_color (editor_page, value);
824 else
825 webkit_dom_element_set_attribute (
826 element, attribute, value, NULL);
829 g_dbus_method_invocation_return_value (invocation, NULL);
830 } else if (g_strcmp0 (method_name, "ElementGetTagName") == 0) {
831 const gchar *element_id;
832 gchar *value = NULL;
833 WebKitDOMElement *element;
835 g_variant_get (parameters, "(t&s)", &page_id, &element_id);
837 editor_page = get_editor_page_or_return_dbus_error (invocation, extension, page_id);
838 if (!editor_page)
839 goto error;
841 document = e_editor_page_get_document (editor_page);
842 element = webkit_dom_document_get_element_by_id (document, element_id);
843 if (element)
844 value = webkit_dom_element_get_tag_name (element);
846 g_dbus_method_invocation_return_value (
847 invocation,
848 g_variant_new (
849 "(@s)",
850 g_variant_new_take_string (
851 value ? value : g_strdup (""))));
852 } else if (g_strcmp0 (method_name, "RemoveImageAttributesFromElementBySelector") == 0) {
853 const gchar *selector;
854 WebKitDOMElement *element;
856 g_variant_get (parameters, "(t&s)", &page_id, &selector);
858 editor_page = get_editor_page_or_return_dbus_error (invocation, extension, page_id);
859 if (!editor_page)
860 goto error;
862 document = e_editor_page_get_document (editor_page);
863 element = webkit_dom_document_query_selector (document, selector, NULL);
864 if (element) {
865 webkit_dom_element_remove_attribute (element, "background");
866 webkit_dom_element_remove_attribute (element, "data-uri");
867 webkit_dom_element_remove_attribute (element, "data-inline");
868 webkit_dom_element_remove_attribute (element, "data-name");
871 g_dbus_method_invocation_return_value (invocation, NULL);
872 } else if (g_strcmp0 (method_name, "EEditorCellDialogMarkCurrentCellElement") == 0) {
873 const gchar *element_id;
875 g_variant_get (parameters, "(t&s)", &page_id, &element_id);
877 editor_page = get_editor_page_or_return_dbus_error (invocation, extension, page_id);
878 if (!editor_page)
879 goto error;
881 e_dialogs_dom_cell_mark_current_cell_element (editor_page, element_id);
883 g_dbus_method_invocation_return_value (invocation, NULL);
884 } else if (g_strcmp0 (method_name, "EEditorCellDialogSaveHistoryOnExit") == 0) {
885 g_variant_get (parameters, "(t)", &page_id);
887 editor_page = get_editor_page_or_return_dbus_error (invocation, extension, page_id);
888 if (!editor_page)
889 goto error;
891 e_dialogs_dom_cell_save_history_on_exit (editor_page);
893 g_dbus_method_invocation_return_value (invocation, NULL);
894 } else if (g_strcmp0 (method_name, "EEditorCellDialogSetElementVAlign") == 0) {
895 const gchar *value;
896 EContentEditorScope scope;
898 g_variant_get (parameters, "(t&si)", &page_id, &value, &scope);
900 editor_page = get_editor_page_or_return_dbus_error (invocation, extension, page_id);
901 if (!editor_page)
902 goto error;
904 e_dialogs_dom_cell_set_element_v_align (editor_page, value, scope);
906 g_dbus_method_invocation_return_value (invocation, NULL);
907 } else if (g_strcmp0 (method_name, "EEditorCellDialogSetElementAlign") == 0) {
908 const gchar *value;
909 EContentEditorScope scope;
911 g_variant_get (parameters, "(t&si)", &page_id, &value, &scope);
913 editor_page = get_editor_page_or_return_dbus_error (invocation, extension, page_id);
914 if (!editor_page)
915 goto error;
917 e_dialogs_dom_cell_set_element_align (editor_page, value, scope);
919 g_dbus_method_invocation_return_value (invocation, NULL);
920 } else if (g_strcmp0 (method_name, "EEditorCellDialogSetElementNoWrap") == 0) {
921 gboolean value;
922 EContentEditorScope scope;
924 g_variant_get (parameters, "(tbi)", &page_id, &value, &scope);
926 editor_page = get_editor_page_or_return_dbus_error (invocation, extension, page_id);
927 if (!editor_page)
928 goto error;
930 e_dialogs_dom_cell_set_element_no_wrap (editor_page, value, scope);
932 g_dbus_method_invocation_return_value (invocation, NULL);
933 } else if (g_strcmp0 (method_name, "EEditorCellDialogSetElementHeaderStyle") == 0) {
934 gboolean value;
935 EContentEditorScope scope;
937 g_variant_get (parameters, "(tbi)", &page_id, &value, &scope);
939 editor_page = get_editor_page_or_return_dbus_error (invocation, extension, page_id);
940 if (!editor_page)
941 goto error;
943 e_dialogs_dom_cell_set_element_header_style (editor_page, value, scope);
945 g_dbus_method_invocation_return_value (invocation, NULL);
946 } else if (g_strcmp0 (method_name, "EEditorCellDialogSetElementWidth") == 0) {
947 const gchar *value;
948 EContentEditorScope scope;
950 g_variant_get (parameters, "(t&si)", &page_id, &value, &scope);
952 editor_page = get_editor_page_or_return_dbus_error (invocation, extension, page_id);
953 if (!editor_page)
954 goto error;
956 e_dialogs_dom_cell_set_element_width (editor_page, value, scope);
958 g_dbus_method_invocation_return_value (invocation, NULL);
959 } else if (g_strcmp0 (method_name, "EEditorCellDialogSetElementColSpan") == 0) {
960 glong value;
961 EContentEditorScope scope;
963 g_variant_get (parameters, "(tii)", &page_id, &value, &scope);
965 editor_page = get_editor_page_or_return_dbus_error (invocation, extension, page_id);
966 if (!editor_page)
967 goto error;
969 e_dialogs_dom_cell_set_element_col_span (editor_page, value, scope);
971 g_dbus_method_invocation_return_value (invocation, NULL);
972 } else if (g_strcmp0 (method_name, "EEditorCellDialogSetElementRowSpan") == 0) {
973 glong value;
974 EContentEditorScope scope;
976 g_variant_get (parameters, "(tii)", &page_id, &value, &scope);
978 editor_page = get_editor_page_or_return_dbus_error (invocation, extension, page_id);
979 if (!editor_page)
980 goto error;
982 e_dialogs_dom_cell_set_element_row_span (editor_page, value, scope);
984 g_dbus_method_invocation_return_value (invocation, NULL);
985 } else if (g_strcmp0 (method_name, "EEditorCellDialogSetElementBgColor") == 0) {
986 const gchar *value;
987 EContentEditorScope scope;
989 g_variant_get (parameters, "(t&si)", &page_id, &value, &scope);
991 editor_page = get_editor_page_or_return_dbus_error (invocation, extension, page_id);
992 if (!editor_page)
993 goto error;
995 e_dialogs_dom_cell_set_element_bg_color (editor_page, value, scope);
997 g_dbus_method_invocation_return_value (invocation, NULL);
998 } else if (g_strcmp0 (method_name, "EEditorHRuleDialogFindHRule") == 0) {
999 gboolean created_new_hr = FALSE;
1000 g_variant_get (parameters, "(t)", &page_id);
1002 editor_page = get_editor_page_or_return_dbus_error (invocation, extension, page_id);
1003 if (!editor_page)
1004 goto error;
1006 created_new_hr = e_dialogs_dom_h_rule_find_hrule (editor_page);
1008 g_dbus_method_invocation_return_value (
1009 invocation, g_variant_new ("(b)", created_new_hr));
1010 } else if (g_strcmp0 (method_name, "EEditorHRuleDialogOnClose") == 0) {
1011 g_variant_get (parameters, "(t)", &page_id);
1013 editor_page = get_editor_page_or_return_dbus_error (invocation, extension, page_id);
1014 if (!editor_page)
1015 goto error;
1017 e_dialogs_dom_h_rule_dialog_on_close (editor_page);
1019 g_dbus_method_invocation_return_value (invocation, NULL);
1020 } else if (g_strcmp0 (method_name, "EEditorImageDialogMarkImage") == 0) {
1021 g_variant_get (parameters, "(t)", &page_id);
1023 editor_page = get_editor_page_or_return_dbus_error (invocation, extension, page_id);
1024 if (!editor_page)
1025 goto error;
1027 e_dialogs_dom_image_mark_image (editor_page);
1029 g_dbus_method_invocation_return_value (invocation, NULL);
1030 } else if (g_strcmp0 (method_name, "EEditorImageDialogSaveHistoryOnExit") == 0) {
1031 g_variant_get (parameters, "(t)", &page_id);
1033 editor_page = get_editor_page_or_return_dbus_error (invocation, extension, page_id);
1034 if (!editor_page)
1035 goto error;
1037 e_dialogs_dom_image_save_history_on_exit (editor_page);
1039 g_dbus_method_invocation_return_value (invocation, NULL);
1040 } else if (g_strcmp0 (method_name, "EEditorImageDialogSetElementUrl") == 0) {
1041 const gchar *value;
1043 g_variant_get (parameters, "(t&s)", &page_id, &value);
1045 editor_page = get_editor_page_or_return_dbus_error (invocation, extension, page_id);
1046 if (!editor_page)
1047 goto error;
1049 e_dialogs_dom_image_set_element_url (editor_page, value);
1051 g_dbus_method_invocation_return_value (invocation, NULL);
1052 } else if (g_strcmp0 (method_name, "EEditorImageDialogGetElementUrl") == 0) {
1053 gchar *value;
1055 g_variant_get (parameters, "(t)", &page_id);
1057 editor_page = get_editor_page_or_return_dbus_error (invocation, extension, page_id);
1058 if (!editor_page)
1059 goto error;
1061 value = e_dialogs_dom_image_get_element_url (editor_page);
1063 g_dbus_method_invocation_return_value (
1064 invocation,
1065 g_variant_new (
1066 "(@s)",
1067 g_variant_new_take_string (
1068 value ? value : g_strdup (""))));
1069 } else if (g_strcmp0 (method_name, "ImageElementSetWidth") == 0) {
1070 const gchar *element_id;
1071 gint32 value;
1072 WebKitDOMElement *element;
1074 g_variant_get (
1075 parameters, "(t&si)", &page_id, &element_id, &value);
1077 editor_page = get_editor_page_or_return_dbus_error (invocation, extension, page_id);
1078 if (!editor_page)
1079 goto error;
1081 document = e_editor_page_get_document (editor_page);
1082 element = webkit_dom_document_get_element_by_id (document, element_id);
1083 if (element)
1084 webkit_dom_html_image_element_set_width (
1085 WEBKIT_DOM_HTML_IMAGE_ELEMENT (element), value);
1087 g_dbus_method_invocation_return_value (invocation, NULL);
1088 } else if (g_strcmp0 (method_name, "ImageElementGetWidth") == 0) {
1089 const gchar *element_id;
1090 glong value = 0;
1091 WebKitDOMElement *element;
1093 g_variant_get (
1094 parameters, "(t&s)", &page_id, &element_id);
1096 editor_page = get_editor_page_or_return_dbus_error (invocation, extension, page_id);
1097 if (!editor_page)
1098 goto error;
1100 document = e_editor_page_get_document (editor_page);
1101 element = webkit_dom_document_get_element_by_id (document, element_id);
1102 if (element)
1103 value = webkit_dom_html_image_element_get_width (
1104 WEBKIT_DOM_HTML_IMAGE_ELEMENT (element));
1106 g_dbus_method_invocation_return_value (
1107 invocation, g_variant_new ("(i)", value));
1108 } else if (g_strcmp0 (method_name, "ImageElementSetHeight") == 0) {
1109 const gchar *element_id;
1110 gint32 value;
1111 WebKitDOMElement *element;
1113 g_variant_get (
1114 parameters, "(t&si)", &page_id, &element_id, &value);
1116 editor_page = get_editor_page_or_return_dbus_error (invocation, extension, page_id);
1117 if (!editor_page)
1118 goto error;
1120 document = e_editor_page_get_document (editor_page);
1121 element = webkit_dom_document_get_element_by_id (document, element_id);
1122 if (element)
1123 webkit_dom_html_image_element_set_width (
1124 WEBKIT_DOM_HTML_IMAGE_ELEMENT (element), value);
1126 g_dbus_method_invocation_return_value (invocation, NULL);
1127 } else if (g_strcmp0 (method_name, "ImageElementGetHeight") == 0) {
1128 const gchar *element_id;
1129 glong value = 0;
1130 WebKitDOMElement *element;
1132 g_variant_get (
1133 parameters, "(t&s)", &page_id, &element_id);
1135 editor_page = get_editor_page_or_return_dbus_error (invocation, extension, page_id);
1136 if (!editor_page)
1137 goto error;
1139 document = e_editor_page_get_document (editor_page);
1140 element = webkit_dom_document_get_element_by_id (document, element_id);
1141 if (element)
1142 value = webkit_dom_html_image_element_get_height (
1143 WEBKIT_DOM_HTML_IMAGE_ELEMENT (element));
1145 g_dbus_method_invocation_return_value (
1146 invocation, g_variant_new ("(i)", value));
1147 } else if (g_strcmp0 (method_name, "ImageElementGetNaturalWidth") == 0) {
1148 const gchar *element_id;
1149 glong value = 0;
1150 WebKitDOMElement *element;
1152 g_variant_get (
1153 parameters, "(t&s)", &page_id, &element_id);
1155 editor_page = get_editor_page_or_return_dbus_error (invocation, extension, page_id);
1156 if (!editor_page)
1157 goto error;
1159 document = e_editor_page_get_document (editor_page);
1160 element = webkit_dom_document_get_element_by_id (document, element_id);
1161 if (element)
1162 value = webkit_dom_html_image_element_get_natural_width (
1163 WEBKIT_DOM_HTML_IMAGE_ELEMENT (element));
1165 g_dbus_method_invocation_return_value (
1166 invocation, g_variant_new ("(i)", value));
1167 } else if (g_strcmp0 (method_name, "ImageElementGetNaturalHeight") == 0) {
1168 const gchar *element_id;
1169 glong value = 0;
1170 WebKitDOMElement *element;
1172 g_variant_get (
1173 parameters, "(t&s)", &page_id, &element_id);
1175 editor_page = get_editor_page_or_return_dbus_error (invocation, extension, page_id);
1176 if (!editor_page)
1177 goto error;
1179 document = e_editor_page_get_document (editor_page);
1180 element = webkit_dom_document_get_element_by_id (document, element_id);
1181 if (element)
1182 value = webkit_dom_html_image_element_get_natural_height (
1183 WEBKIT_DOM_HTML_IMAGE_ELEMENT (element));
1185 g_dbus_method_invocation_return_value (
1186 invocation, g_variant_new ("(i)", value));
1187 } else if (g_strcmp0 (method_name, "ImageElementSetHSpace") == 0) {
1188 const gchar *element_id;
1189 gint32 value;
1190 WebKitDOMElement *element;
1192 g_variant_get (
1193 parameters, "(t&si)", &page_id, &element_id, &value);
1195 editor_page = get_editor_page_or_return_dbus_error (invocation, extension, page_id);
1196 if (!editor_page)
1197 goto error;
1199 document = e_editor_page_get_document (editor_page);
1200 element = webkit_dom_document_get_element_by_id (document, element_id);
1201 if (element)
1202 webkit_dom_html_image_element_set_hspace (
1203 WEBKIT_DOM_HTML_IMAGE_ELEMENT (element), value);
1205 g_dbus_method_invocation_return_value (invocation, NULL);
1206 } else if (g_strcmp0 (method_name, "ImageElementGetHSpace") == 0) {
1207 const gchar *element_id;
1208 glong value = 0;
1209 WebKitDOMElement *element;
1211 g_variant_get (
1212 parameters, "(t&s)", &page_id, &element_id);
1214 editor_page = get_editor_page_or_return_dbus_error (invocation, extension, page_id);
1215 if (!editor_page)
1216 goto error;
1218 document = e_editor_page_get_document (editor_page);
1219 element = webkit_dom_document_get_element_by_id (document, element_id);
1220 if (element)
1221 value = webkit_dom_html_image_element_get_hspace (
1222 WEBKIT_DOM_HTML_IMAGE_ELEMENT (element));
1224 g_dbus_method_invocation_return_value (
1225 invocation, g_variant_new ("(i)", value));
1226 } else if (g_strcmp0 (method_name, "ImageElementSetVSpace") == 0) {
1227 const gchar *element_id;
1228 gint32 value;
1229 WebKitDOMElement *element;
1231 g_variant_get (
1232 parameters, "(t&si)", &page_id, &element_id, &value);
1234 editor_page = get_editor_page_or_return_dbus_error (invocation, extension, page_id);
1235 if (!editor_page)
1236 goto error;
1238 document = e_editor_page_get_document (editor_page);
1239 element = webkit_dom_document_get_element_by_id (document, element_id);
1240 if (element)
1241 webkit_dom_html_image_element_set_vspace (
1242 WEBKIT_DOM_HTML_IMAGE_ELEMENT (element), value);
1244 g_dbus_method_invocation_return_value (invocation, NULL);
1245 } else if (g_strcmp0 (method_name, "ImageElementGetVSpace") == 0) {
1246 const gchar *element_id;
1247 glong value = 0;
1248 WebKitDOMElement *element;
1250 g_variant_get (
1251 parameters, "(t&s)", &page_id, &element_id);
1253 editor_page = get_editor_page_or_return_dbus_error (invocation, extension, page_id);
1254 if (!editor_page)
1255 goto error;
1257 document = e_editor_page_get_document (editor_page);
1258 element = webkit_dom_document_get_element_by_id (document, element_id);
1259 if (element)
1260 value = webkit_dom_html_image_element_get_vspace (
1261 WEBKIT_DOM_HTML_IMAGE_ELEMENT (element));
1263 g_dbus_method_invocation_return_value (
1264 invocation, g_variant_new ("(i)", value));
1265 } else if (g_strcmp0 (method_name, "EEditorLinkDialogOk") == 0) {
1266 const gchar *url, *inner_text;
1268 g_variant_get (parameters, "(t&s&s)", &page_id, &url, &inner_text);
1270 editor_page = get_editor_page_or_return_dbus_error (invocation, extension, page_id);
1271 if (!editor_page)
1272 goto error;
1274 e_dialogs_dom_link_commit (editor_page, url, inner_text);
1276 g_dbus_method_invocation_return_value (invocation, NULL);
1277 } else if (g_strcmp0 (method_name, "EEditorLinkDialogShow") == 0) {
1278 g_variant_get (parameters, "(t)", &page_id);
1280 editor_page = get_editor_page_or_return_dbus_error (invocation, extension, page_id);
1281 if (!editor_page)
1282 goto error;
1284 g_dbus_method_invocation_return_value (
1285 invocation, e_dialogs_dom_link_show (editor_page));
1286 } else if (g_strcmp0 (method_name, "EEditorPageDialogSaveHistory") == 0) {
1287 g_variant_get (parameters, "(t)", &page_id);
1289 editor_page = get_editor_page_or_return_dbus_error (invocation, extension, page_id);
1290 if (!editor_page)
1291 goto error;
1293 e_dialogs_dom_page_save_history (editor_page);
1295 g_dbus_method_invocation_return_value (invocation, NULL);
1296 } else if (g_strcmp0 (method_name, "EEditorPageDialogSaveHistoryOnExit") == 0) {
1297 g_variant_get (parameters, "(t)", &page_id);
1299 editor_page = get_editor_page_or_return_dbus_error (invocation, extension, page_id);
1300 if (!editor_page)
1301 goto error;
1303 e_dialogs_dom_page_save_history_on_exit (editor_page);
1305 g_dbus_method_invocation_return_value (invocation, NULL);
1306 } else if (g_strcmp0 (method_name, "EEditorSpellCheckDialogNext") == 0) {
1307 const gchar *from_word = NULL;
1308 const gchar * const *languages = NULL;
1309 gchar *value = NULL;
1311 g_variant_get (parameters, "(t&s^as)", &page_id, &from_word, &languages);
1313 editor_page = get_editor_page_or_return_dbus_error (invocation, extension, page_id);
1314 if (!editor_page)
1315 goto error;
1317 value = e_dialogs_dom_spell_check_next (editor_page, from_word, languages);
1319 g_dbus_method_invocation_return_value (
1320 invocation,
1321 g_variant_new (
1322 "(@s)",
1323 g_variant_new_take_string (
1324 value ? value : g_strdup (""))));
1325 } else if (g_strcmp0 (method_name, "EEditorSpellCheckDialogPrev") == 0) {
1326 const gchar *from_word = NULL;
1327 const gchar * const *languages = NULL;
1328 gchar *value = NULL;
1330 g_variant_get (parameters, "(t&s^as)", &page_id, &from_word, &languages);
1332 editor_page = get_editor_page_or_return_dbus_error (invocation, extension, page_id);
1333 if (!editor_page)
1334 goto error;
1336 value = e_dialogs_dom_spell_check_prev (editor_page, from_word, languages);
1338 g_dbus_method_invocation_return_value (
1339 invocation,
1340 g_variant_new (
1341 "(@s)",
1342 g_variant_new_take_string (
1343 value ? value : g_strdup (""))));
1344 } else if (g_strcmp0 (method_name, "EEditorTableDialogSetRowCount") == 0) {
1345 guint32 value;
1347 g_variant_get (parameters, "(tu)", &page_id, &value);
1349 editor_page = get_editor_page_or_return_dbus_error (invocation, extension, page_id);
1350 if (!editor_page)
1351 goto error;
1353 e_dialogs_dom_table_set_row_count (editor_page, value);
1355 g_dbus_method_invocation_return_value (invocation, NULL);
1356 } else if (g_strcmp0 (method_name, "EEditorTableDialogGetRowCount") == 0) {
1357 gulong value;
1359 g_variant_get (parameters, "(t)", &page_id);
1361 editor_page = get_editor_page_or_return_dbus_error (invocation, extension, page_id);
1362 if (!editor_page)
1363 goto error;
1365 value = e_dialogs_dom_table_get_row_count (editor_page);
1367 g_dbus_method_invocation_return_value (
1368 invocation, g_variant_new ("(u)", value));
1369 } else if (g_strcmp0 (method_name, "EEditorTableDialogSetColumnCount") == 0) {
1370 guint32 value;
1372 g_variant_get (parameters, "(tu)", &page_id, &value);
1374 editor_page = get_editor_page_or_return_dbus_error (invocation, extension, page_id);
1375 if (!editor_page)
1376 goto error;
1378 e_dialogs_dom_table_set_column_count (editor_page, value);
1380 g_dbus_method_invocation_return_value (invocation, NULL);
1381 } else if (g_strcmp0 (method_name, "EEditorTableDialogGetColumnCount") == 0) {
1382 gulong value;
1384 g_variant_get (parameters, "(t)", &page_id);
1386 editor_page = get_editor_page_or_return_dbus_error (invocation, extension, page_id);
1387 if (!editor_page)
1388 goto error;
1390 value = e_dialogs_dom_table_get_column_count (editor_page);
1392 g_dbus_method_invocation_return_value (
1393 invocation, g_variant_new ("(u)", value));
1394 } else if (g_strcmp0 (method_name, "EEditorTableDialogShow") == 0) {
1395 gboolean created_new_table;
1397 g_variant_get (parameters, "(t)", &page_id);
1399 editor_page = get_editor_page_or_return_dbus_error (invocation, extension, page_id);
1400 if (!editor_page)
1401 goto error;
1403 created_new_table = e_dialogs_dom_table_show (editor_page);
1405 g_dbus_method_invocation_return_value (
1406 invocation, g_variant_new ("(b)", created_new_table));
1407 } else if (g_strcmp0 (method_name, "EEditorTableDialogSaveHistoryOnExit") == 0) {
1408 g_variant_get (parameters, "(t)", &page_id);
1410 editor_page = get_editor_page_or_return_dbus_error (invocation, extension, page_id);
1411 if (!editor_page)
1412 goto error;
1414 e_dialogs_dom_table_save_history_on_exit (editor_page);
1416 g_dbus_method_invocation_return_value (invocation, NULL);
1417 } else if (g_strcmp0 (method_name, "EEditorDialogDeleteCellContents") == 0) {
1418 g_variant_get (parameters, "(t)", &page_id);
1420 editor_page = get_editor_page_or_return_dbus_error (invocation, extension, page_id);
1421 if (!editor_page)
1422 goto error;
1424 e_editor_dom_delete_cell_contents (editor_page);
1426 g_dbus_method_invocation_return_value (invocation, NULL);
1427 } else if (g_strcmp0 (method_name, "EEditorDialogDeleteColumn") == 0) {
1428 g_variant_get (parameters, "(t)", &page_id);
1430 editor_page = get_editor_page_or_return_dbus_error (invocation, extension, page_id);
1431 if (!editor_page)
1432 goto error;
1434 e_editor_dom_delete_column (editor_page);
1436 g_dbus_method_invocation_return_value (invocation, NULL);
1437 } else if (g_strcmp0 (method_name, "EEditorDialogDeleteRow") == 0) {
1438 g_variant_get (parameters, "(t)", &page_id);
1440 editor_page = get_editor_page_or_return_dbus_error (invocation, extension, page_id);
1441 if (!editor_page)
1442 goto error;
1444 e_editor_dom_delete_row (editor_page);
1446 g_dbus_method_invocation_return_value (invocation, NULL);
1447 } else if (g_strcmp0 (method_name, "EEditorDialogDeleteTable") == 0) {
1448 g_variant_get (parameters, "(t)", &page_id);
1450 editor_page = get_editor_page_or_return_dbus_error (invocation, extension, page_id);
1451 if (!editor_page)
1452 goto error;
1454 e_editor_dom_delete_table (editor_page);
1456 g_dbus_method_invocation_return_value (invocation, NULL);
1457 } else if (g_strcmp0 (method_name, "EEditorDialogInsertColumnAfter") == 0) {
1458 g_variant_get (parameters, "(t)", &page_id);
1460 editor_page = get_editor_page_or_return_dbus_error (invocation, extension, page_id);
1461 if (!editor_page)
1462 goto error;
1464 e_editor_dom_insert_column_after (editor_page);
1466 g_dbus_method_invocation_return_value (invocation, NULL);
1467 } else if (g_strcmp0 (method_name, "EEditorDialogInsertColumnBefore") == 0) {
1468 g_variant_get (parameters, "(t)", &page_id);
1470 editor_page = get_editor_page_or_return_dbus_error (invocation, extension, page_id);
1471 if (!editor_page)
1472 goto error;
1474 e_editor_dom_insert_column_before (editor_page);
1476 g_dbus_method_invocation_return_value (invocation, NULL);
1477 } else if (g_strcmp0 (method_name, "EEditorDialogInsertRowAbove") == 0) {
1478 g_variant_get (parameters, "(t)", &page_id);
1480 editor_page = get_editor_page_or_return_dbus_error (invocation, extension, page_id);
1481 if (!editor_page)
1482 goto error;
1484 e_editor_dom_insert_row_above (editor_page);
1486 g_dbus_method_invocation_return_value (invocation, NULL);
1487 } else if (g_strcmp0 (method_name, "EEditorDialogInsertRowBelow") == 0) {
1488 g_variant_get (parameters, "(t)", &page_id);
1490 editor_page = get_editor_page_or_return_dbus_error (invocation, extension, page_id);
1491 if (!editor_page)
1492 goto error;
1494 e_editor_dom_insert_row_below (editor_page);
1496 g_dbus_method_invocation_return_value (invocation, NULL);
1497 } else if (g_strcmp0 (method_name, "EEditorLinkDialogOnOpen") == 0) {
1498 g_variant_get (parameters, "(t)", &page_id);
1500 editor_page = get_editor_page_or_return_dbus_error (invocation, extension, page_id);
1501 if (!editor_page)
1502 goto error;
1504 e_dialogs_dom_link_dialog_on_open (editor_page);
1506 g_dbus_method_invocation_return_value (invocation, NULL);
1507 } else if (g_strcmp0 (method_name, "EEditorLinkDialogOnClose") == 0) {
1508 g_variant_get (parameters, "(t)", &page_id);
1510 editor_page = get_editor_page_or_return_dbus_error (invocation, extension, page_id);
1511 if (!editor_page)
1512 goto error;
1514 e_dialogs_dom_link_dialog_on_close (editor_page);
1516 g_dbus_method_invocation_return_value (invocation, NULL);
1517 } else if (g_strcmp0 (method_name, "EEditorLinkDialogUnlink") == 0) {
1518 EEditorUndoRedoManager *manager;
1520 g_variant_get (parameters, "(t)", &page_id);
1522 editor_page = get_editor_page_or_return_dbus_error (invocation, extension, page_id);
1523 if (!editor_page)
1524 goto error;
1526 manager = e_editor_page_get_undo_redo_manager (editor_page);
1527 /* Remove the history event that was saved when the dialog was opened */
1528 e_editor_undo_redo_manager_remove_current_history_event (manager);
1530 e_editor_dom_selection_unlink (editor_page);
1532 g_dbus_method_invocation_return_value (invocation, NULL);
1533 } else if (g_strcmp0 (method_name, "EEditorActionsSaveHistoryForCut") == 0) {
1534 g_variant_get (parameters, "(t)", &page_id);
1536 editor_page = get_editor_page_or_return_dbus_error (invocation, extension, page_id);
1537 if (!editor_page)
1538 goto error;
1540 e_editor_dom_save_history_for_cut (editor_page);
1542 g_dbus_method_invocation_return_value (invocation, NULL);
1543 } else if (g_strcmp0 (method_name, "TableCellElementGetNoWrap") == 0) {
1544 const gchar *element_id;
1545 gboolean value = FALSE;
1546 WebKitDOMElement *element;
1548 g_variant_get (parameters, "(t&s)", &page_id, &element_id);
1550 editor_page = get_editor_page_or_return_dbus_error (invocation, extension, page_id);
1551 if (!editor_page)
1552 goto error;
1554 document = e_editor_page_get_document (editor_page);
1555 element = webkit_dom_document_get_element_by_id (document, element_id);
1556 if (element)
1557 value = webkit_dom_html_table_cell_element_get_no_wrap (
1558 WEBKIT_DOM_HTML_TABLE_CELL_ELEMENT (element));
1560 g_dbus_method_invocation_return_value (
1561 invocation, g_variant_new ("(b)", value));
1562 } else if (g_strcmp0 (method_name, "TableCellElementGetRowSpan") == 0) {
1563 const gchar *element_id;
1564 glong value = 0;
1565 WebKitDOMElement *element;
1567 g_variant_get (parameters, "(t&s)", &page_id, &element_id);
1569 editor_page = get_editor_page_or_return_dbus_error (invocation, extension, page_id);
1570 if (!editor_page)
1571 goto error;
1573 document = e_editor_page_get_document (editor_page);
1574 element = webkit_dom_document_get_element_by_id (document, element_id);
1575 if (element)
1576 value = webkit_dom_html_table_cell_element_get_row_span (
1577 WEBKIT_DOM_HTML_TABLE_CELL_ELEMENT (element));
1579 g_dbus_method_invocation_return_value (
1580 invocation, g_variant_new ("(i)", value));
1581 } else if (g_strcmp0 (method_name, "TableCellElementGetColSpan") == 0) {
1582 const gchar *element_id;
1583 glong value = 0;
1584 WebKitDOMElement *element;
1586 g_variant_get (parameters, "(t&s)", &page_id, &element_id);
1588 editor_page = get_editor_page_or_return_dbus_error (invocation, extension, page_id);
1589 if (!editor_page)
1590 goto error;
1592 document = e_editor_page_get_document (editor_page);
1593 element = webkit_dom_document_get_element_by_id (document, element_id);
1594 if (element)
1595 value = webkit_dom_html_table_cell_element_get_col_span (
1596 WEBKIT_DOM_HTML_TABLE_CELL_ELEMENT (element));
1598 g_dbus_method_invocation_return_value (
1599 invocation, g_variant_new ("(i)", value));
1600 } else if (g_strcmp0 (method_name, "DOMSaveSelection") == 0) {
1601 g_variant_get (parameters, "(t)", &page_id);
1603 editor_page = get_editor_page_or_return_dbus_error (invocation, extension, page_id);
1604 if (!editor_page)
1605 goto error;
1607 e_editor_dom_selection_save (editor_page);
1608 g_dbus_method_invocation_return_value (invocation, NULL);
1609 } else if (g_strcmp0 (method_name, "DOMRestoreSelection") == 0) {
1610 g_variant_get (parameters, "(t)", &page_id);
1612 editor_page = get_editor_page_or_return_dbus_error (invocation, extension, page_id);
1613 if (!editor_page)
1614 goto error;
1616 e_editor_dom_selection_restore (editor_page);
1617 g_dbus_method_invocation_return_value (invocation, NULL);
1618 } else if (g_strcmp0 (method_name, "DOMUndo") == 0) {
1619 EEditorUndoRedoManager *manager;
1621 g_variant_get (parameters, "(t)", &page_id);
1623 editor_page = get_editor_page_or_return_dbus_error (invocation, extension, page_id);
1624 if (!editor_page)
1625 goto error;
1627 manager = e_editor_page_get_undo_redo_manager (editor_page);
1629 e_editor_undo_redo_manager_undo (manager);
1631 g_dbus_method_invocation_return_value (invocation, NULL);
1632 } else if (g_strcmp0 (method_name, "DOMRedo") == 0) {
1633 EEditorUndoRedoManager *manager;
1635 g_variant_get (parameters, "(t)", &page_id);
1637 editor_page = get_editor_page_or_return_dbus_error (invocation, extension, page_id);
1638 if (!editor_page)
1639 goto error;
1641 manager = e_editor_page_get_undo_redo_manager (editor_page);
1643 e_editor_undo_redo_manager_redo (manager);
1645 g_dbus_method_invocation_return_value (invocation, NULL);
1646 } else if (g_strcmp0 (method_name, "DOMTurnSpellCheckOff") == 0) {
1647 g_variant_get (parameters, "(t)", &page_id);
1649 editor_page = get_editor_page_or_return_dbus_error (invocation, extension, page_id);
1650 if (!editor_page)
1651 goto error;
1653 e_editor_dom_turn_spell_check_off (editor_page);
1654 g_dbus_method_invocation_return_value (invocation, NULL);
1655 } else if (g_strcmp0 (method_name, "DOMQuoteAndInsertTextIntoSelection") == 0) {
1656 gboolean is_html = FALSE;
1657 const gchar *text;
1659 g_variant_get (parameters, "(t&sb)", &page_id, &text, &is_html);
1661 editor_page = get_editor_page_or_return_dbus_error (invocation, extension, page_id);
1662 if (!editor_page)
1663 goto error;
1665 e_editor_dom_quote_and_insert_text_into_selection (editor_page, text, is_html);
1666 g_dbus_method_invocation_return_value (invocation, NULL);
1667 } else if (g_strcmp0 (method_name, "DOMConvertAndInsertHTMLIntoSelection") == 0) {
1668 gboolean is_html;
1669 const gchar *text;
1671 g_variant_get (parameters, "(t&sb)", &page_id, &text, &is_html);
1673 editor_page = get_editor_page_or_return_dbus_error (invocation, extension, page_id);
1674 if (!editor_page)
1675 goto error;
1677 e_editor_dom_convert_and_insert_html_into_selection (editor_page, text, is_html);
1678 g_dbus_method_invocation_return_value (invocation, NULL);
1679 } else if (g_strcmp0 (method_name, "DOMEmbedStyleSheet") == 0) {
1680 const gchar *style_sheet_content;
1682 g_variant_get (parameters, "(t&s)", &page_id, &style_sheet_content);
1684 editor_page = get_editor_page_or_return_dbus_error (invocation, extension, page_id);
1685 if (!editor_page)
1686 goto error;
1688 e_editor_dom_embed_style_sheet (editor_page, style_sheet_content);
1689 g_dbus_method_invocation_return_value (invocation, NULL);
1690 } else if (g_strcmp0 (method_name, "DOMRemoveEmbeddedStyleSheet") == 0) {
1691 g_variant_get (parameters, "(t)", &page_id);
1693 editor_page = get_editor_page_or_return_dbus_error (invocation, extension, page_id);
1694 if (!editor_page)
1695 goto error;
1697 e_editor_dom_remove_embedded_style_sheet (editor_page);
1698 g_dbus_method_invocation_return_value (invocation, NULL);
1699 } else if (g_strcmp0 (method_name, "SetPastingContentFromItself") == 0) {
1700 gboolean value = FALSE;
1702 g_variant_get (parameters, "(tb)", &page_id, &value);
1704 editor_page = get_editor_page_or_return_dbus_error (invocation, extension, page_id);
1705 if (!editor_page)
1706 goto error;
1708 e_editor_page_set_pasting_content_from_itself (editor_page, value);
1710 g_dbus_method_invocation_return_value (invocation, NULL);
1711 } else if (g_strcmp0 (method_name, "SetEditorHTMLMode") == 0) {
1712 gboolean html_mode = FALSE;
1713 gboolean convert = FALSE;
1715 g_variant_get (parameters, "(tbb)", &page_id, &html_mode, &convert);
1717 editor_page = get_editor_page_or_return_dbus_error (invocation, extension, page_id);
1718 if (!editor_page)
1719 goto error;
1721 convert = convert && e_editor_page_get_html_mode (editor_page) && !html_mode;
1722 e_editor_page_set_html_mode (editor_page, html_mode);
1724 if (convert)
1725 e_editor_dom_convert_when_changing_composer_mode (editor_page);
1726 else
1727 e_editor_dom_process_content_after_mode_change (editor_page);
1729 g_dbus_method_invocation_return_value (invocation, NULL);
1730 } else if (g_strcmp0 (method_name, "SetConvertInSitu") == 0) {
1731 gboolean value = FALSE;
1732 gint16 start_at_bottom = -1, top_signature = -1;
1734 g_variant_get (parameters, "(tbnn)", &page_id, &value, &start_at_bottom, &top_signature);
1736 editor_page = get_editor_page_or_return_dbus_error (invocation, extension, page_id);
1737 if (!editor_page)
1738 goto error;
1740 e_editor_page_set_convert_in_situ (editor_page, value, start_at_bottom, top_signature);
1742 g_dbus_method_invocation_return_value (invocation, NULL);
1743 } else if (g_strcmp0 (method_name, "DOMForceSpellCheck") == 0) {
1744 g_variant_get (parameters, "(t)", &page_id);
1746 editor_page = get_editor_page_or_return_dbus_error (invocation, extension, page_id);
1747 if (!editor_page)
1748 goto error;
1750 e_editor_dom_force_spell_check (editor_page);
1751 g_dbus_method_invocation_return_value (invocation, NULL);
1752 } else if (g_strcmp0 (method_name, "DOMCheckIfConversionNeeded") == 0) {
1753 gboolean conversion_needed;
1755 g_variant_get (parameters, "(t)", &page_id);
1757 editor_page = get_editor_page_or_return_dbus_error (invocation, extension, page_id);
1758 if (!editor_page)
1759 goto error;
1761 conversion_needed = e_editor_dom_check_if_conversion_needed (editor_page);
1762 g_dbus_method_invocation_return_value (
1763 invocation, g_variant_new ("(b)", conversion_needed));
1764 } else if (g_strcmp0 (method_name, "DOMGetContent") == 0) {
1765 EContentEditorGetContentFlags flags;
1766 const gchar *from_domain;
1767 gchar *value = NULL;
1768 GVariant *inline_images = NULL;
1770 g_variant_get (parameters, "(t&si)", &page_id, &from_domain, &flags);
1772 editor_page = get_editor_page_or_return_dbus_error (invocation, extension, page_id);
1773 if (!editor_page)
1774 goto error;
1776 if ((flags & E_CONTENT_EDITOR_GET_INLINE_IMAGES) && from_domain && *from_domain)
1777 inline_images = e_editor_dom_get_inline_images_data (editor_page, from_domain);
1779 if ((flags & E_CONTENT_EDITOR_GET_TEXT_HTML) &&
1780 !(flags & E_CONTENT_EDITOR_GET_PROCESSED)) {
1781 value = e_editor_dom_process_content_for_draft (
1782 editor_page, (flags & E_CONTENT_EDITOR_GET_BODY));
1783 } else if ((flags & E_CONTENT_EDITOR_GET_TEXT_HTML) &&
1784 (flags & E_CONTENT_EDITOR_GET_PROCESSED) &&
1785 !(flags & E_CONTENT_EDITOR_GET_BODY)) {
1786 value = e_editor_dom_process_content_to_html_for_exporting (editor_page);
1787 } else if ((flags & E_CONTENT_EDITOR_GET_TEXT_PLAIN) &&
1788 (flags & E_CONTENT_EDITOR_GET_PROCESSED) &&
1789 !(flags & E_CONTENT_EDITOR_GET_BODY)) {
1790 value = e_editor_dom_process_content_to_plain_text_for_exporting (editor_page);
1791 } else if ((flags & E_CONTENT_EDITOR_GET_TEXT_PLAIN) &&
1792 (flags & E_CONTENT_EDITOR_GET_BODY) &&
1793 !(flags & E_CONTENT_EDITOR_GET_PROCESSED)) {
1794 if (flags & E_CONTENT_EDITOR_GET_EXCLUDE_SIGNATURE)
1795 value = e_composer_dom_get_raw_body_content_without_signature (editor_page);
1796 else
1797 value = e_composer_dom_get_raw_body_content (editor_page);
1798 } else {
1799 g_warning ("Unsupported flags combination (%d) in (%s)", flags, G_STRFUNC);
1802 if ((flags & E_CONTENT_EDITOR_GET_INLINE_IMAGES) && from_domain && *from_domain && inline_images)
1803 e_editor_dom_restore_images (editor_page, inline_images);
1805 /* If no inline images are requested we still have to return
1806 * something even it won't be used at all. */
1807 g_dbus_method_invocation_return_value (
1808 invocation,
1809 g_variant_new (
1810 "(sv)",
1811 value ? value : "",
1812 inline_images ? inline_images : g_variant_new_int32 (0)));
1814 g_free (value);
1815 } else if (g_strcmp0 (method_name, "DOMInsertHTML") == 0) {
1816 const gchar *html;
1818 g_variant_get (parameters, "(t&s)", &page_id, &html);
1820 editor_page = get_editor_page_or_return_dbus_error (invocation, extension, page_id);
1821 if (!editor_page)
1822 goto error;
1824 e_editor_dom_insert_html (editor_page, html);
1825 g_dbus_method_invocation_return_value (invocation, NULL);
1826 } else if (g_strcmp0 (method_name, "DOMConvertContent") == 0) {
1827 const gchar *preferred_text;
1828 gint64 start_at_bottom = -1, top_signature = -1;
1830 g_variant_get (parameters, "(t&snn)", &page_id, &preferred_text, &start_at_bottom, &top_signature);
1832 editor_page = get_editor_page_or_return_dbus_error (invocation, extension, page_id);
1833 if (!editor_page)
1834 goto error;
1836 e_editor_dom_convert_content (editor_page, preferred_text, start_at_bottom, top_signature);
1837 g_dbus_method_invocation_return_value (invocation, NULL);
1838 } else if (g_strcmp0 (method_name, "DOMAddNewInlineImageIntoList") == 0) {
1839 const gchar *cid_uri, *src, *filename;
1841 g_variant_get (parameters, "(t&s&s&s)", &page_id, &filename, &cid_uri, &src);
1843 editor_page = get_editor_page_or_return_dbus_error (invocation, extension, page_id);
1844 if (!editor_page)
1845 goto error;
1847 e_editor_page_add_new_inline_image_into_list (
1848 editor_page, cid_uri, src);
1850 g_dbus_method_invocation_return_value (invocation, NULL);
1851 } else if (g_strcmp0 (method_name, "DOMReplaceImageSrc") == 0) {
1852 const gchar *selector, *uri;
1854 g_variant_get (parameters, "(t&s&s)", &page_id, &selector, &uri);
1856 editor_page = get_editor_page_or_return_dbus_error (invocation, extension, page_id);
1857 if (!editor_page)
1858 goto error;
1860 e_editor_dom_replace_image_src (editor_page, selector, uri);
1862 g_dbus_method_invocation_return_value (invocation, NULL);
1863 } else if (g_strcmp0 (method_name, "DOMInsertSmiley") == 0) {
1864 const gchar *smiley_name;
1866 g_variant_get (parameters, "(t&s)", &page_id, &smiley_name);
1868 editor_page = get_editor_page_or_return_dbus_error (invocation, extension, page_id);
1869 if (!editor_page)
1870 goto error;
1872 e_editor_dom_insert_smiley_by_name (editor_page, smiley_name);
1873 g_dbus_method_invocation_return_value (invocation, NULL);
1874 } else if (g_strcmp0 (method_name, "DOMMoveSelectionOnPoint") == 0) {
1875 gboolean cancel_if_not_collapsed;
1876 gint x, y;
1878 g_variant_get (parameters, "(tiib)", &page_id, &x, &y, &cancel_if_not_collapsed);
1880 editor_page = get_editor_page_or_return_dbus_error (invocation, extension, page_id);
1881 if (!editor_page)
1882 goto error;
1884 if (cancel_if_not_collapsed) {
1885 if (e_editor_dom_selection_is_collapsed (editor_page))
1886 e_editor_dom_selection_set_on_point (editor_page, x, y);
1887 } else
1888 e_editor_dom_selection_set_on_point (editor_page, x, y);
1890 g_dbus_method_invocation_return_value (invocation, NULL);
1891 } else if (g_strcmp0 (method_name, "DOMSelectionIndent") == 0) {
1892 g_variant_get (parameters, "(t)", &page_id);
1894 editor_page = get_editor_page_or_return_dbus_error (invocation, extension, page_id);
1895 if (!editor_page)
1896 goto error;
1898 e_editor_dom_selection_indent (editor_page);
1899 g_dbus_method_invocation_return_value (invocation, NULL);
1900 } else if (g_strcmp0 (method_name, "DOMSelectionSave") == 0) {
1901 g_variant_get (parameters, "(t)", &page_id);
1903 editor_page = get_editor_page_or_return_dbus_error (invocation, extension, page_id);
1904 if (!editor_page)
1905 goto error;
1907 e_editor_dom_selection_save (editor_page);
1908 g_dbus_method_invocation_return_value (invocation, NULL);
1909 } else if (g_strcmp0 (method_name, "DOMSelectionRestore") == 0) {
1910 g_variant_get (parameters, "(t)", &page_id);
1912 editor_page = get_editor_page_or_return_dbus_error (invocation, extension, page_id);
1913 if (!editor_page)
1914 goto error;
1916 e_editor_dom_selection_restore (editor_page);
1917 g_dbus_method_invocation_return_value (invocation, NULL);
1918 } else if (g_strcmp0 (method_name, "DOMSelectionInsertImage") == 0) {
1919 const gchar *uri;
1921 g_variant_get (parameters, "(t&s)", &page_id, &uri);
1923 editor_page = get_editor_page_or_return_dbus_error (invocation, extension, page_id);
1924 if (!editor_page)
1925 goto error;
1927 e_editor_dom_insert_image (editor_page, uri);
1929 g_dbus_method_invocation_return_value (invocation, NULL);
1930 } else if (g_strcmp0 (method_name, "DOMInsertReplaceAllHistoryEvent") == 0) {
1931 const gchar *replacement, *search_text;
1933 g_variant_get (parameters, "(t&s&s)", &page_id, &search_text, &replacement);
1935 editor_page = get_editor_page_or_return_dbus_error (invocation, extension, page_id);
1936 if (!editor_page)
1937 goto error;
1939 e_editor_dom_insert_replace_all_history_event (editor_page, search_text, replacement);
1940 g_dbus_method_invocation_return_value (invocation, NULL);
1941 } else if (g_strcmp0 (method_name, "DOMSelectionReplace") == 0) {
1942 const gchar *replacement;
1944 g_variant_get (parameters, "(t&s)", &page_id, &replacement);
1946 editor_page = get_editor_page_or_return_dbus_error (invocation, extension, page_id);
1947 if (!editor_page)
1948 goto error;
1950 e_editor_dom_selection_replace (editor_page, replacement);
1951 g_dbus_method_invocation_return_value (invocation, NULL);
1952 } else if (g_strcmp0 (method_name, "DOMSelectionSetAlignment") == 0) {
1953 EContentEditorAlignment alignment;
1955 g_variant_get (parameters, "(ti)", &page_id, &alignment);
1957 editor_page = get_editor_page_or_return_dbus_error (invocation, extension, page_id);
1958 if (!editor_page)
1959 goto error;
1961 e_editor_dom_selection_set_alignment (editor_page, alignment);
1962 e_editor_page_set_alignment (editor_page, alignment);
1963 g_dbus_method_invocation_return_value (invocation, NULL);
1964 } else if (g_strcmp0 (method_name, "DOMSelectionSetBold") == 0) {
1965 gboolean bold;
1967 g_variant_get (parameters, "(tb)", &page_id, &bold);
1969 editor_page = get_editor_page_or_return_dbus_error (invocation, extension, page_id);
1970 if (!editor_page)
1971 goto error;
1973 e_editor_page_set_bold (editor_page, bold);
1974 g_dbus_method_invocation_return_value (invocation, NULL);
1975 } else if (g_strcmp0 (method_name, "DOMSelectionSetBlockFormat") == 0) {
1976 EContentEditorBlockFormat block_format;
1978 g_variant_get (parameters, "(ti)", &page_id, &block_format);
1980 editor_page = get_editor_page_or_return_dbus_error (invocation, extension, page_id);
1981 if (!editor_page)
1982 goto error;
1984 e_editor_dom_selection_set_block_format (editor_page, block_format);
1985 g_dbus_method_invocation_return_value (invocation, NULL);
1986 } else if (g_strcmp0 (method_name, "DOMSelectionSetFontColor") == 0) {
1987 const gchar *color;
1989 g_variant_get (parameters, "(t&s)", &page_id, &color);
1991 editor_page = get_editor_page_or_return_dbus_error (invocation, extension, page_id);
1992 if (!editor_page)
1993 goto error;
1995 e_editor_dom_selection_set_font_color (editor_page, color);
1996 g_dbus_method_invocation_return_value (invocation, NULL);
1997 } else if (g_strcmp0 (method_name, "DOMSelectionSetFontSize") == 0) {
1998 EContentEditorFontSize font_size;
2000 g_variant_get (parameters, "(ti)", &page_id, &font_size);
2002 editor_page = get_editor_page_or_return_dbus_error (invocation, extension, page_id);
2003 if (!editor_page)
2004 goto error;
2006 e_editor_dom_selection_set_font_size (editor_page, font_size);
2007 g_dbus_method_invocation_return_value (invocation, NULL);
2008 } else if (g_strcmp0 (method_name, "DOMSelectionSetItalic") == 0) {
2009 gboolean italic;
2011 g_variant_get (parameters, "(tb)", &page_id, &italic);
2013 editor_page = get_editor_page_or_return_dbus_error (invocation, extension, page_id);
2014 if (!editor_page)
2015 goto error;
2017 e_editor_page_set_italic (editor_page, italic);
2018 g_dbus_method_invocation_return_value (invocation, NULL);
2019 } else if (g_strcmp0 (method_name, "DOMSelectionSetMonospaced") == 0) {
2020 gboolean monospaced;
2022 g_variant_get (parameters, "(tb)", &page_id, &monospaced);
2024 editor_page = get_editor_page_or_return_dbus_error (invocation, extension, page_id);
2025 if (!editor_page)
2026 goto error;
2028 e_editor_page_set_monospace (editor_page, monospaced);
2029 g_dbus_method_invocation_return_value (invocation, NULL);
2030 } else if (g_strcmp0 (method_name, "DOMSelectionSetStrikethrough") == 0) {
2031 gboolean strikethrough;
2033 g_variant_get (parameters, "(tb)", &page_id, &strikethrough);
2035 editor_page = get_editor_page_or_return_dbus_error (invocation, extension, page_id);
2036 if (!editor_page)
2037 goto error;
2039 e_editor_page_set_strikethrough (editor_page, strikethrough);
2040 g_dbus_method_invocation_return_value (invocation, NULL);
2041 } else if (g_strcmp0 (method_name, "DOMSelectionSetSubscript") == 0) {
2042 gboolean subscript;
2044 g_variant_get (parameters, "(tb)", &page_id, &subscript);
2046 editor_page = get_editor_page_or_return_dbus_error (invocation, extension, page_id);
2047 if (!editor_page)
2048 goto error;
2050 e_editor_dom_selection_set_subscript (editor_page, subscript);
2051 g_dbus_method_invocation_return_value (invocation, NULL);
2052 } else if (g_strcmp0 (method_name, "DOMSelectionSetSuperscript") == 0) {
2053 gboolean superscript;
2055 g_variant_get (parameters, "(tb)", &page_id, &superscript);
2057 editor_page = get_editor_page_or_return_dbus_error (invocation, extension, page_id);
2058 if (!editor_page)
2059 goto error;
2061 e_editor_dom_selection_set_superscript (editor_page, superscript);
2062 g_dbus_method_invocation_return_value (invocation, NULL);
2063 } else if (g_strcmp0 (method_name, "DOMSelectionSetUnderline") == 0) {
2064 gboolean underline;
2066 g_variant_get (parameters, "(tb)", &page_id, &underline);
2068 editor_page = get_editor_page_or_return_dbus_error (invocation, extension, page_id);
2069 if (!editor_page)
2070 goto error;
2072 e_editor_page_set_underline (editor_page, underline);
2073 g_dbus_method_invocation_return_value (invocation, NULL);
2074 } else if (g_strcmp0 (method_name, "DOMSelectionUnindent") == 0) {
2075 g_variant_get (parameters, "(t)", &page_id);
2077 editor_page = get_editor_page_or_return_dbus_error (invocation, extension, page_id);
2078 if (!editor_page)
2079 goto error;
2081 e_editor_dom_selection_unindent (editor_page);
2082 g_dbus_method_invocation_return_value (invocation, NULL);
2083 } else if (g_strcmp0 (method_name, "DOMSelectionWrap") == 0) {
2084 g_variant_get (parameters, "(t)", &page_id);
2086 editor_page = get_editor_page_or_return_dbus_error (invocation, extension, page_id);
2087 if (!editor_page)
2088 goto error;
2090 e_editor_dom_selection_wrap (editor_page);
2091 g_dbus_method_invocation_return_value (invocation, NULL);
2092 } else if (g_strcmp0 (method_name, "DOMGetCaretWord") == 0) {
2093 gchar *word;
2095 g_variant_get (parameters, "(t)", &page_id);
2097 editor_page = get_editor_page_or_return_dbus_error (invocation, extension, page_id);
2098 if (!editor_page)
2099 goto error;
2101 word = e_editor_dom_get_caret_word (editor_page);
2103 g_dbus_method_invocation_return_value (
2104 invocation,
2105 g_variant_new (
2106 "(@s)",
2107 g_variant_new_take_string (
2108 word ? word : g_strdup (""))));
2109 } else if (g_strcmp0 (method_name, "DOMReplaceCaretWord") == 0) {
2110 const gchar *replacement = NULL;
2112 g_variant_get (parameters, "(t&s)", &page_id, &replacement);
2114 editor_page = get_editor_page_or_return_dbus_error (invocation, extension, page_id);
2115 if (!editor_page)
2116 goto error;
2118 e_editor_dom_replace_caret_word (editor_page, replacement);
2120 g_dbus_method_invocation_return_value (invocation, NULL);
2121 } else if (g_strcmp0 (method_name, "DOMInsertSignature") == 0) {
2122 gboolean is_html, set_signature_from_message;
2123 gboolean check_if_signature_is_changed, ignore_next_signature_change;
2124 gint16 start_at_bottom = -1, top_signature = -1;
2125 const gchar *content, *signature_id;
2126 gchar *new_signature_id = NULL;
2128 g_variant_get (
2129 parameters,
2130 "(t&sb&sbbbnn)",
2131 &page_id,
2132 &content,
2133 &is_html,
2134 &signature_id,
2135 &set_signature_from_message,
2136 &check_if_signature_is_changed,
2137 &ignore_next_signature_change,
2138 &start_at_bottom,
2139 &top_signature);
2141 editor_page = get_editor_page_or_return_dbus_error (invocation, extension, page_id);
2142 if (!editor_page)
2143 goto error;
2145 new_signature_id = e_composer_dom_insert_signature (
2146 editor_page,
2147 content,
2148 is_html,
2149 signature_id,
2150 &set_signature_from_message,
2151 &check_if_signature_is_changed,
2152 &ignore_next_signature_change,
2153 start_at_bottom,
2154 top_signature);
2156 g_dbus_method_invocation_return_value (
2157 invocation,
2158 g_variant_new (
2159 "(sbbb)",
2160 new_signature_id ? new_signature_id : "",
2161 set_signature_from_message,
2162 check_if_signature_is_changed,
2163 ignore_next_signature_change));
2165 g_free (new_signature_id);
2166 } else if (g_strcmp0 (method_name, "DOMGetActiveSignatureUid") == 0) {
2167 gchar *value;
2169 g_variant_get (parameters, "(t)", &page_id);
2171 editor_page = get_editor_page_or_return_dbus_error (invocation, extension, page_id);
2172 if (!editor_page)
2173 goto error;
2175 value = e_composer_dom_get_active_signature_uid (editor_page);
2177 g_dbus_method_invocation_return_value (
2178 invocation,
2179 g_variant_new (
2180 "(@s)",
2181 g_variant_new_take_string (
2182 value ? value : g_strdup (""))));
2183 } else if (g_strcmp0 (method_name, "DOMLastDropOperationDidCopy") == 0) {
2184 EEditorUndoRedoManager *manager;
2186 g_variant_get (parameters, "(t)", &page_id);
2188 editor_page = get_editor_page_or_return_dbus_error (invocation, extension, page_id);
2189 if (!editor_page)
2190 goto error;
2192 manager = e_editor_page_get_undo_redo_manager (editor_page);
2193 if (manager)
2194 e_editor_undo_redo_manager_last_drop_operation_did_copy (manager);
2196 g_dbus_method_invocation_return_value (invocation, NULL);
2197 } else if (g_strcmp0 (method_name, "DOMGetCaretPosition") == 0) {
2198 guint32 value;
2200 g_variant_get (parameters, "(t)", &page_id);
2202 editor_page = get_editor_page_or_return_dbus_error (invocation, extension, page_id);
2203 if (!editor_page)
2204 goto error;
2206 value = e_editor_dom_get_caret_position (editor_page);
2208 g_dbus_method_invocation_return_value (
2209 invocation,
2210 g_variant_new ("(u)", value));
2211 } else if (g_strcmp0 (method_name, "DOMGetCaretOffset") == 0) {
2212 guint32 value;
2214 g_variant_get (parameters, "(t)", &page_id);
2216 editor_page = get_editor_page_or_return_dbus_error (invocation, extension, page_id);
2217 if (!editor_page)
2218 goto error;
2220 value = e_editor_dom_get_caret_offset (editor_page);
2222 g_dbus_method_invocation_return_value (
2223 invocation,
2224 g_variant_new ("(u)", value));
2225 } else if (g_strcmp0 (method_name, "DOMClearUndoRedoHistory") == 0) {
2226 EEditorUndoRedoManager *manager;
2228 g_variant_get (parameters, "(t)", &page_id);
2230 editor_page = get_editor_page_or_return_dbus_error (invocation, extension, page_id);
2231 if (!editor_page)
2232 goto error;
2234 manager = e_editor_page_get_undo_redo_manager (editor_page);
2235 if (manager)
2236 e_editor_undo_redo_manager_clean_history (manager);
2238 g_dbus_method_invocation_return_value (invocation, NULL);
2239 } else {
2240 g_warning ("UNKNOWN METHOD '%s'", method_name);
2243 return;
2245 error:
2246 g_warning ("Cannot obtain WebKitWebPage for %" G_GUINT64_FORMAT, page_id);
2249 static void
2250 web_page_gone_cb (gpointer user_data,
2251 GObject *gone_web_page)
2253 EEditorWebExtension *extension = user_data;
2254 GHashTableIter iter;
2255 gpointer key, value;
2257 g_return_if_fail (E_IS_EDITOR_WEB_EXTENSION (extension));
2259 g_hash_table_iter_init (&iter, extension->priv->editor_pages);
2260 while (g_hash_table_iter_next (&iter, &key, &value)) {
2261 EEditorPage *editor_page = E_EDITOR_PAGE (value);
2262 WebKitWebPage *web_page = e_editor_page_get_web_page (editor_page);
2264 if ((gpointer) web_page == gone_web_page) {
2265 g_hash_table_remove (extension->priv->editor_pages, key);
2266 break;
2271 static const GDBusInterfaceVTable interface_vtable = {
2272 handle_method_call,
2273 NULL,
2274 NULL
2277 static void
2278 e_editor_web_extension_dispose (GObject *object)
2280 EEditorWebExtension *extension = E_EDITOR_WEB_EXTENSION (object);
2282 if (extension->priv->dbus_connection) {
2283 g_dbus_connection_unregister_object (
2284 extension->priv->dbus_connection,
2285 extension->priv->registration_id);
2286 extension->priv->registration_id = 0;
2287 extension->priv->dbus_connection = NULL;
2290 g_hash_table_remove_all (extension->priv->editor_pages);
2292 g_clear_object (&extension->priv->wk_extension);
2294 /* Chain up to parent's dispose() method. */
2295 G_OBJECT_CLASS (e_editor_web_extension_parent_class)->dispose (object);
2298 static void
2299 e_editor_web_extension_finalize (GObject *object)
2301 EEditorWebExtension *extension = E_EDITOR_WEB_EXTENSION (object);
2303 if (extension->priv->editor_pages) {
2304 g_hash_table_destroy (extension->priv->editor_pages);
2305 extension->priv->editor_pages = NULL;
2308 /* Chain up to parent's finalize() method. */
2309 G_OBJECT_CLASS (e_editor_web_extension_parent_class)->finalize (object);
2312 static void
2313 e_editor_web_extension_class_init (EEditorWebExtensionClass *class)
2315 GObjectClass *object_class = G_OBJECT_CLASS (class);
2317 object_class->dispose = e_editor_web_extension_dispose;
2318 object_class->finalize = e_editor_web_extension_finalize;
2320 g_type_class_add_private (object_class, sizeof(EEditorWebExtensionPrivate));
2323 static void
2324 e_editor_web_extension_init (EEditorWebExtension *extension)
2326 extension->priv = E_EDITOR_WEB_EXTENSION_GET_PRIVATE (extension);
2327 extension->priv->editor_pages = g_hash_table_new_full (g_int64_hash, g_int64_equal, g_free, g_object_unref);
2330 static gpointer
2331 e_editor_web_extension_create_instance (gpointer data)
2333 return g_object_new (E_TYPE_EDITOR_WEB_EXTENSION, NULL);
2336 EEditorWebExtension *
2337 e_editor_web_extension_get_default (void)
2339 static GOnce once_init = G_ONCE_INIT;
2340 return E_EDITOR_WEB_EXTENSION (g_once (&once_init, e_editor_web_extension_create_instance, NULL));
2343 static gboolean
2344 image_exists_in_cache (const gchar *image_uri)
2346 gchar *filename;
2347 gchar *hash;
2348 gboolean exists = FALSE;
2350 if (!emd_global_http_cache)
2351 return FALSE;
2353 hash = g_compute_checksum_for_string (G_CHECKSUM_MD5, image_uri, -1);
2354 filename = camel_data_cache_get_filename (
2355 emd_global_http_cache, "http", hash);
2357 if (filename != NULL) {
2358 struct stat st;
2360 exists = g_file_test (filename, G_FILE_TEST_EXISTS);
2361 if (exists && g_stat (filename, &st) == 0) {
2362 exists = st.st_size != 0;
2363 } else {
2364 exists = FALSE;
2366 g_free (filename);
2369 g_free (hash);
2371 return exists;
2374 static gboolean
2375 redirect_http_uri (EEditorWebExtension *extension,
2376 WebKitWebPage *web_page,
2377 WebKitURIRequest *request)
2379 const gchar *uri;
2380 gchar *new_uri;
2381 SoupURI *soup_uri;
2382 gboolean image_exists;
2383 EEditorPage *editor_page;
2384 EImageLoadingPolicy image_policy;
2386 editor_page = get_editor_page (extension, webkit_web_page_get_id (web_page));
2387 g_return_val_if_fail (E_IS_EDITOR_PAGE (editor_page), FALSE);
2389 uri = webkit_uri_request_get_uri (request);
2391 /* Check Evolution's cache */
2392 image_exists = image_exists_in_cache (uri);
2394 /* If the URI is not cached and we are not allowed to load it
2395 * then redirect to invalid URI, so that webkit would display
2396 * a native placeholder for it. */
2397 image_policy = e_editor_page_get_image_loading_policy (editor_page);
2398 if (!image_exists && !e_editor_page_get_force_image_load (editor_page) &&
2399 (image_policy == E_IMAGE_LOADING_POLICY_NEVER)) {
2400 return FALSE;
2403 new_uri = g_strconcat ("evo-", uri, NULL);
2404 soup_uri = soup_uri_new (new_uri);
2405 g_free (new_uri);
2407 new_uri = soup_uri_to_string (soup_uri, FALSE);
2408 webkit_uri_request_set_uri (request, new_uri);
2409 soup_uri_free (soup_uri);
2411 g_free (new_uri);
2413 return TRUE;
2416 static gboolean
2417 web_page_send_request_cb (WebKitWebPage *web_page,
2418 WebKitURIRequest *request,
2419 WebKitURIResponse *redirected_response,
2420 EEditorWebExtension *extension)
2422 const char *request_uri;
2423 const char *page_uri;
2424 gboolean uri_is_http;
2426 request_uri = webkit_uri_request_get_uri (request);
2427 page_uri = webkit_web_page_get_uri (web_page);
2429 /* Always load the main resource. */
2430 if (g_strcmp0 (request_uri, page_uri) == 0)
2431 return FALSE;
2433 uri_is_http =
2434 g_str_has_prefix (request_uri, "http:") ||
2435 g_str_has_prefix (request_uri, "https:") ||
2436 g_str_has_prefix (request_uri, "evo-http:") ||
2437 g_str_has_prefix (request_uri, "evo-https:");
2439 if (uri_is_http &&
2440 !redirect_http_uri (extension, web_page, request))
2441 return TRUE;
2443 return FALSE;
2446 static void
2447 web_page_document_loaded_cb (WebKitWebPage *web_page,
2448 gpointer user_data)
2450 WebKitDOMDocument *document;
2451 WebKitDOMRange *range = NULL;
2452 WebKitDOMDOMWindow *dom_window;
2453 WebKitDOMDOMSelection *dom_selection;
2455 g_return_if_fail (WEBKIT_IS_WEB_PAGE (web_page));
2457 document = webkit_web_page_get_dom_document (web_page);
2458 if (!document)
2459 return;
2461 dom_window = webkit_dom_document_get_default_view (document);
2462 dom_selection = webkit_dom_dom_window_get_selection (dom_window);
2464 /* Make sure there is a cursor located in the body after the document loads. */
2465 if (!webkit_dom_dom_selection_get_anchor_node (dom_selection) &&
2466 !webkit_dom_dom_selection_get_focus_node (dom_selection)) {
2467 range = webkit_dom_document_caret_range_from_point (document, 0, 0);
2468 webkit_dom_dom_selection_remove_all_ranges (dom_selection);
2469 webkit_dom_dom_selection_add_range (dom_selection, range);
2472 g_clear_object (&range);
2473 g_clear_object (&dom_selection);
2474 g_clear_object (&dom_window);
2477 static void
2478 web_page_created_cb (WebKitWebExtension *wk_extension,
2479 WebKitWebPage *web_page,
2480 EEditorWebExtension *extension)
2482 EEditorPage *editor_page;
2483 guint64 *ppage_id;
2485 g_return_if_fail (WEBKIT_IS_WEB_PAGE (web_page));
2486 g_return_if_fail (E_IS_EDITOR_WEB_EXTENSION (extension));
2488 ppage_id = g_new (guint64, 1);
2489 *ppage_id = webkit_web_page_get_id (web_page);
2491 editor_page = e_editor_page_new (web_page, extension);
2492 g_hash_table_insert (extension->priv->editor_pages, ppage_id, editor_page);
2494 g_object_weak_ref (G_OBJECT (web_page), web_page_gone_cb, extension);
2496 g_signal_connect (
2497 web_page, "send-request",
2498 G_CALLBACK (web_page_send_request_cb), extension);
2500 g_signal_connect (
2501 web_page, "document-loaded",
2502 G_CALLBACK (web_page_document_loaded_cb), NULL);
2505 void
2506 e_editor_web_extension_initialize (EEditorWebExtension *extension,
2507 WebKitWebExtension *wk_extension)
2509 g_return_if_fail (E_IS_EDITOR_WEB_EXTENSION (extension));
2511 extension->priv->wk_extension = g_object_ref (wk_extension);
2513 if (emd_global_http_cache == NULL) {
2514 emd_global_http_cache = camel_data_cache_new (
2515 e_get_user_cache_dir (), NULL);
2517 if (emd_global_http_cache) {
2518 /* cache expiry - 2 hour access, 1 day max */
2519 camel_data_cache_set_expire_age (
2520 emd_global_http_cache, 24 * 60 * 60);
2521 camel_data_cache_set_expire_access (
2522 emd_global_http_cache, 2 * 60 * 60);
2526 g_signal_connect (
2527 wk_extension, "page-created",
2528 G_CALLBACK (web_page_created_cb), extension);
2531 void
2532 e_editor_web_extension_dbus_register (EEditorWebExtension *extension,
2533 GDBusConnection *connection)
2535 GError *error = NULL;
2536 static GDBusNodeInfo *introspection_data = NULL;
2538 g_return_if_fail (E_IS_EDITOR_WEB_EXTENSION (extension));
2539 g_return_if_fail (G_IS_DBUS_CONNECTION (connection));
2541 if (!introspection_data) {
2542 introspection_data =
2543 g_dbus_node_info_new_for_xml (introspection_xml, NULL);
2545 extension->priv->registration_id =
2546 g_dbus_connection_register_object (
2547 connection,
2548 E_WEBKIT_EDITOR_WEB_EXTENSION_OBJECT_PATH,
2549 introspection_data->interfaces[0],
2550 &interface_vtable,
2551 extension,
2552 NULL,
2553 &error);
2555 if (!extension->priv->registration_id) {
2556 g_warning ("Failed to register object: %s\n", error->message);
2557 g_error_free (error);
2558 } else {
2559 extension->priv->dbus_connection = connection;
2560 g_object_add_weak_pointer (
2561 G_OBJECT (connection),
2562 (gpointer *) &extension->priv->dbus_connection);
2567 GDBusConnection *
2568 e_editor_web_extension_get_connection (EEditorWebExtension *extension)
2570 g_return_val_if_fail (E_IS_EDITOR_WEB_EXTENSION (extension), NULL);
2572 return extension->priv->dbus_connection;