1 : /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 : /* ***** BEGIN LICENSE BLOCK *****
3 : * Version: MPL 1.1/GPL 2.0/LGPL 2.1
4 : *
5 : * The contents of this file are subject to the Mozilla Public License Version
6 : * 1.1 (the "License"); you may not use this file except in compliance with
7 : * the License. You may obtain a copy of the License at
8 : * http://www.mozilla.org/MPL/
9 : *
10 : * Software distributed under the License is distributed on an "AS IS" basis,
11 : * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12 : * for the specific language governing rights and limitations under the
13 : * License.
14 : *
15 : * The Original Code is Mozilla Communicator client code.
16 : *
17 : * The Initial Developer of the Original Code is
18 : * Netscape Communications Corporation.
19 : * Portions created by the Initial Developer are Copyright (C) 1998
20 : * the Initial Developer. All Rights Reserved.
21 : *
22 : * Contributor(s):
23 : * Ryan Cassin <rcassin@supernova.org>
24 : * Daniel Glazman <glazman@netscape.com>
25 : * Charles Manske <cmanske@netscape.com>
26 : * Kathleen Brade <brade@netscape.com>
27 : *
28 : * Alternatively, the contents of this file may be used under the terms of
29 : * either of the GNU General Public License Version 2 or later (the "GPL"),
30 : * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
31 : * in which case the provisions of the GPL or the LGPL are applicable instead
32 : * of those above. If you wish to allow use of your version of this file only
33 : * under the terms of either the GPL or the LGPL, and not to allow others to
34 : * use your version of this file under the terms of the MPL, indicate your
35 : * decision by deleting the provisions above and replace them with the notice
36 : * and other provisions required by the GPL or the LGPL. If you do not delete
37 : * the provisions above, a recipient may use your version of this file under
38 : * the terms of any one of the MPL, the GPL or the LGPL.
39 : *
40 : * ***** END LICENSE BLOCK ***** */
41 :
42 :
43 : #include "nsIEditor.h"
44 : #include "nsIEditingSession.h"
45 : #include "nsIPlaintextEditor.h"
46 : #include "nsIHTMLEditor.h"
47 : #include "nsIHTMLObjectResizer.h"
48 : #include "nsIHTMLInlineTableEditor.h"
49 :
50 : #include "nsIDOMDocument.h"
51 : #include "nsIDocument.h"
52 : #include "nsISelectionController.h"
53 : #include "nsIPresShell.h"
54 : #include "nsPresContext.h"
55 : #include "nsIDocShell.h"
56 : #include "nsIURI.h"
57 :
58 : #include "nsCOMPtr.h"
59 :
60 : #include "nsComposerCommands.h"
61 : #include "nsICommandParams.h"
62 : #include "nsCRT.h"
63 :
64 : //defines
65 : #define STATE_ENABLED "state_enabled"
66 : #define STATE_ATTRIBUTE "state_attribute"
67 : #define STATE_DATA "state_data"
68 :
69 : static
70 : nsresult
71 0 : GetPresContextFromEditor(nsIEditor *aEditor, nsPresContext **aResult)
72 : {
73 0 : NS_ENSURE_ARG_POINTER(aResult);
74 0 : *aResult = nsnull;
75 0 : NS_ENSURE_ARG_POINTER(aEditor);
76 :
77 0 : nsCOMPtr<nsISelectionController> selCon;
78 0 : nsresult rv = aEditor->GetSelectionController(getter_AddRefs(selCon));
79 0 : NS_ENSURE_SUCCESS(rv, rv);
80 0 : NS_ENSURE_TRUE(selCon, NS_ERROR_FAILURE);
81 :
82 0 : nsCOMPtr<nsIPresShell> presShell = do_QueryInterface(selCon);
83 0 : NS_ENSURE_TRUE(presShell, NS_ERROR_FAILURE);
84 :
85 0 : NS_IF_ADDREF(*aResult = presShell->GetPresContext());
86 0 : return NS_OK;
87 : }
88 :
89 : NS_IMETHODIMP
90 0 : nsSetDocumentOptionsCommand::IsCommandEnabled(const char * aCommandName,
91 : nsISupports *refCon,
92 : bool *outCmdEnabled)
93 : {
94 0 : NS_ENSURE_ARG_POINTER(outCmdEnabled);
95 0 : nsCOMPtr<nsIEditor> editor = do_QueryInterface(refCon);
96 0 : if (editor)
97 0 : return editor->GetIsSelectionEditable(outCmdEnabled);
98 :
99 0 : *outCmdEnabled = false;
100 0 : return NS_OK;
101 : }
102 :
103 : NS_IMETHODIMP
104 0 : nsSetDocumentOptionsCommand::DoCommand(const char *aCommandName,
105 : nsISupports *refCon)
106 : {
107 0 : return NS_ERROR_NOT_IMPLEMENTED;
108 : }
109 :
110 : NS_IMETHODIMP
111 0 : nsSetDocumentOptionsCommand::DoCommandParams(const char *aCommandName,
112 : nsICommandParams *aParams,
113 : nsISupports *refCon)
114 : {
115 0 : NS_ENSURE_ARG_POINTER(aParams);
116 :
117 0 : nsCOMPtr<nsIEditor> editor = do_QueryInterface(refCon);
118 0 : NS_ENSURE_TRUE(editor, NS_ERROR_INVALID_ARG);
119 :
120 0 : nsRefPtr<nsPresContext> presContext;
121 0 : nsresult rv = GetPresContextFromEditor(editor, getter_AddRefs(presContext));
122 0 : NS_ENSURE_SUCCESS(rv, rv);
123 0 : NS_ENSURE_TRUE(presContext, NS_ERROR_FAILURE);
124 :
125 : PRInt32 animationMode;
126 0 : rv = aParams->GetLongValue("imageAnimation", &animationMode);
127 0 : if (NS_SUCCEEDED(rv))
128 : {
129 : // for possible values of animation mode, see:
130 : // http://lxr.mozilla.org/seamonkey/source/image/public/imgIContainer.idl
131 0 : presContext->SetImageAnimationMode(animationMode);
132 : }
133 :
134 : bool allowPlugins;
135 0 : rv = aParams->GetBooleanValue("plugins", &allowPlugins);
136 0 : if (NS_SUCCEEDED(rv))
137 : {
138 0 : nsCOMPtr<nsISupports> container = presContext->GetContainer();
139 0 : NS_ENSURE_TRUE(container, NS_ERROR_FAILURE);
140 :
141 0 : nsCOMPtr<nsIDocShell> docShell(do_QueryInterface(container, &rv));
142 0 : NS_ENSURE_SUCCESS(rv, rv);
143 0 : NS_ENSURE_TRUE(docShell, NS_ERROR_FAILURE);
144 :
145 0 : rv = docShell->SetAllowPlugins(allowPlugins);
146 0 : NS_ENSURE_SUCCESS(rv, rv);
147 : }
148 :
149 0 : return NS_OK;
150 : }
151 :
152 : NS_IMETHODIMP
153 0 : nsSetDocumentOptionsCommand::GetCommandStateParams(const char *aCommandName,
154 : nsICommandParams *aParams,
155 : nsISupports *refCon)
156 : {
157 0 : NS_ENSURE_ARG_POINTER(aParams);
158 0 : NS_ENSURE_ARG_POINTER(refCon);
159 :
160 : // The base editor owns most state info
161 0 : nsCOMPtr<nsIEditor> editor = do_QueryInterface(refCon);
162 0 : NS_ENSURE_TRUE(editor, NS_ERROR_INVALID_ARG);
163 :
164 : // Always get the enabled state
165 0 : bool outCmdEnabled = false;
166 0 : IsCommandEnabled(aCommandName, refCon, &outCmdEnabled);
167 0 : nsresult rv = aParams->SetBooleanValue(STATE_ENABLED, outCmdEnabled);
168 0 : NS_ENSURE_SUCCESS(rv, rv);
169 :
170 : // get pres context
171 0 : nsRefPtr<nsPresContext> presContext;
172 0 : rv = GetPresContextFromEditor(editor, getter_AddRefs(presContext));
173 0 : NS_ENSURE_SUCCESS(rv, rv);
174 0 : NS_ENSURE_TRUE(presContext, NS_ERROR_FAILURE);
175 :
176 : PRInt32 animationMode;
177 0 : rv = aParams->GetLongValue("imageAnimation", &animationMode);
178 0 : if (NS_SUCCEEDED(rv))
179 : {
180 : // for possible values of animation mode, see
181 : // http://lxr.mozilla.org/seamonkey/source/image/public/imgIContainer.idl
182 : rv = aParams->SetLongValue("imageAnimation",
183 0 : presContext->ImageAnimationMode());
184 0 : NS_ENSURE_SUCCESS(rv, rv);
185 : }
186 :
187 : bool allowPlugins;
188 0 : rv = aParams->GetBooleanValue("plugins", &allowPlugins);
189 0 : if (NS_SUCCEEDED(rv))
190 : {
191 0 : nsCOMPtr<nsISupports> container = presContext->GetContainer();
192 0 : NS_ENSURE_TRUE(container, NS_ERROR_FAILURE);
193 :
194 0 : nsCOMPtr<nsIDocShell> docShell(do_QueryInterface(container, &rv));
195 0 : NS_ENSURE_SUCCESS(rv, rv);
196 0 : NS_ENSURE_TRUE(docShell, NS_ERROR_FAILURE);
197 :
198 0 : rv = docShell->GetAllowPlugins(&allowPlugins);
199 0 : NS_ENSURE_SUCCESS(rv, rv);
200 :
201 0 : rv = aParams->SetBooleanValue("plugins", allowPlugins);
202 0 : NS_ENSURE_SUCCESS(rv, rv);
203 : }
204 :
205 0 : return NS_OK;
206 : }
207 :
208 :
209 : /**
210 : * Commands for document state that may be changed via doCommandParams
211 : * As of 11/11/02, this is just "cmd_setDocumentModified"
212 : * Note that you can use the same command class, nsSetDocumentStateCommand,
213 : * for more than one of this type of command
214 : * We check the input command param for different behavior
215 : */
216 :
217 : NS_IMETHODIMP
218 0 : nsSetDocumentStateCommand::IsCommandEnabled(const char * aCommandName,
219 : nsISupports *refCon,
220 : bool *outCmdEnabled)
221 : {
222 0 : NS_ENSURE_ARG_POINTER(outCmdEnabled);
223 0 : nsCOMPtr<nsIEditor> editor = do_QueryInterface(refCon);
224 0 : if (editor)
225 0 : return editor->GetIsSelectionEditable(outCmdEnabled);
226 :
227 0 : *outCmdEnabled = false;
228 0 : return NS_OK;
229 : }
230 :
231 : NS_IMETHODIMP
232 0 : nsSetDocumentStateCommand::DoCommand(const char *aCommandName,
233 : nsISupports *refCon)
234 : {
235 0 : return NS_ERROR_NOT_IMPLEMENTED;
236 : }
237 :
238 : NS_IMETHODIMP
239 0 : nsSetDocumentStateCommand::DoCommandParams(const char *aCommandName,
240 : nsICommandParams *aParams,
241 : nsISupports *refCon)
242 : {
243 0 : nsCOMPtr<nsIEditor> editor = do_QueryInterface(refCon);
244 0 : NS_ENSURE_TRUE(editor, NS_ERROR_INVALID_ARG);
245 :
246 0 : if (!nsCRT::strcmp(aCommandName, "cmd_setDocumentModified"))
247 : {
248 0 : NS_ENSURE_ARG_POINTER(aParams);
249 :
250 : bool modified;
251 0 : nsresult rv = aParams->GetBooleanValue(STATE_ATTRIBUTE, &modified);
252 :
253 : // Should we fail if this param wasn't set?
254 : // I'm not sure we should be that strict
255 0 : NS_ENSURE_SUCCESS(rv, rv);
256 :
257 0 : if (modified)
258 0 : return editor->IncrementModificationCount(1);
259 :
260 0 : return editor->ResetModificationCount();
261 : }
262 :
263 0 : if (!nsCRT::strcmp(aCommandName, "cmd_setDocumentReadOnly"))
264 : {
265 0 : NS_ENSURE_ARG_POINTER(aParams);
266 : bool isReadOnly;
267 0 : nsresult rvRO = aParams->GetBooleanValue(STATE_ATTRIBUTE, &isReadOnly);
268 0 : NS_ENSURE_SUCCESS(rvRO, rvRO);
269 :
270 : PRUint32 flags;
271 0 : editor->GetFlags(&flags);
272 0 : if (isReadOnly)
273 0 : flags |= nsIPlaintextEditor::eEditorReadonlyMask;
274 : else
275 0 : flags &= ~(nsIPlaintextEditor::eEditorReadonlyMask);
276 :
277 0 : return editor->SetFlags(flags);
278 : }
279 :
280 0 : if (!nsCRT::strcmp(aCommandName, "cmd_setDocumentUseCSS"))
281 : {
282 0 : NS_ENSURE_ARG_POINTER(aParams);
283 0 : nsCOMPtr<nsIHTMLEditor> htmleditor = do_QueryInterface(refCon);
284 0 : NS_ENSURE_TRUE(htmleditor, NS_ERROR_INVALID_ARG);
285 :
286 : bool desireCSS;
287 0 : nsresult rvCSS = aParams->GetBooleanValue(STATE_ATTRIBUTE, &desireCSS);
288 0 : NS_ENSURE_SUCCESS(rvCSS, rvCSS);
289 :
290 0 : return htmleditor->SetIsCSSEnabled(desireCSS);
291 : }
292 :
293 0 : if (!nsCRT::strcmp(aCommandName, "cmd_insertBrOnReturn"))
294 : {
295 0 : NS_ENSURE_ARG_POINTER(aParams);
296 0 : nsCOMPtr<nsIHTMLEditor> htmleditor = do_QueryInterface(refCon);
297 0 : NS_ENSURE_TRUE(htmleditor, NS_ERROR_INVALID_ARG);
298 :
299 : bool insertBrOnReturn;
300 : nsresult rvBR = aParams->GetBooleanValue(STATE_ATTRIBUTE,
301 0 : &insertBrOnReturn);
302 0 : NS_ENSURE_SUCCESS(rvBR, rvBR);
303 :
304 0 : return htmleditor->SetReturnInParagraphCreatesNewParagraph(!insertBrOnReturn);
305 : }
306 :
307 0 : if (!nsCRT::strcmp(aCommandName, "cmd_enableObjectResizing"))
308 : {
309 0 : NS_ENSURE_ARG_POINTER(aParams);
310 0 : nsCOMPtr<nsIHTMLObjectResizer> resizer = do_QueryInterface(refCon);
311 0 : NS_ENSURE_TRUE(resizer, NS_ERROR_INVALID_ARG);
312 :
313 : bool enabled;
314 0 : nsresult rvOR = aParams->GetBooleanValue(STATE_ATTRIBUTE, &enabled);
315 0 : NS_ENSURE_SUCCESS(rvOR, rvOR);
316 :
317 0 : return resizer->SetObjectResizingEnabled(enabled);
318 : }
319 :
320 0 : if (!nsCRT::strcmp(aCommandName, "cmd_enableInlineTableEditing"))
321 : {
322 0 : NS_ENSURE_ARG_POINTER(aParams);
323 0 : nsCOMPtr<nsIHTMLInlineTableEditor> editor = do_QueryInterface(refCon);
324 0 : NS_ENSURE_TRUE(editor, NS_ERROR_INVALID_ARG);
325 :
326 : bool enabled;
327 0 : nsresult rvOR = aParams->GetBooleanValue(STATE_ATTRIBUTE, &enabled);
328 0 : NS_ENSURE_SUCCESS(rvOR, rvOR);
329 :
330 0 : return editor->SetInlineTableEditingEnabled(enabled);
331 : }
332 :
333 0 : return NS_ERROR_NOT_IMPLEMENTED;
334 : }
335 :
336 : NS_IMETHODIMP
337 0 : nsSetDocumentStateCommand::GetCommandStateParams(const char *aCommandName,
338 : nsICommandParams *aParams,
339 : nsISupports *refCon)
340 : {
341 0 : NS_ENSURE_ARG_POINTER(aParams);
342 0 : NS_ENSURE_ARG_POINTER(refCon);
343 :
344 : // The base editor owns most state info
345 0 : nsCOMPtr<nsIEditor> editor = do_QueryInterface(refCon);
346 0 : NS_ENSURE_TRUE(editor, NS_ERROR_INVALID_ARG);
347 :
348 : // Always get the enabled state
349 0 : bool outCmdEnabled = false;
350 0 : IsCommandEnabled(aCommandName, refCon, &outCmdEnabled);
351 0 : nsresult rv = aParams->SetBooleanValue(STATE_ENABLED, outCmdEnabled);
352 0 : NS_ENSURE_SUCCESS(rv, rv);
353 :
354 0 : if (!nsCRT::strcmp(aCommandName, "cmd_setDocumentModified"))
355 : {
356 : bool modified;
357 0 : rv = editor->GetDocumentModified(&modified);
358 0 : NS_ENSURE_SUCCESS(rv, rv);
359 :
360 0 : return aParams->SetBooleanValue(STATE_ATTRIBUTE, modified);
361 : }
362 :
363 0 : if (!nsCRT::strcmp(aCommandName, "cmd_setDocumentReadOnly"))
364 : {
365 0 : NS_ENSURE_ARG_POINTER(aParams);
366 :
367 : PRUint32 flags;
368 0 : editor->GetFlags(&flags);
369 0 : bool isReadOnly = flags & nsIPlaintextEditor::eEditorReadonlyMask;
370 0 : return aParams->SetBooleanValue(STATE_ATTRIBUTE, isReadOnly);
371 : }
372 :
373 0 : if (!nsCRT::strcmp(aCommandName, "cmd_setDocumentUseCSS"))
374 : {
375 0 : NS_ENSURE_ARG_POINTER(aParams);
376 0 : nsCOMPtr<nsIHTMLEditor> htmleditor = do_QueryInterface(refCon);
377 0 : NS_ENSURE_TRUE(htmleditor, NS_ERROR_INVALID_ARG);
378 :
379 : bool isCSS;
380 0 : htmleditor->GetIsCSSEnabled(&isCSS);
381 0 : return aParams->SetBooleanValue(STATE_ATTRIBUTE, isCSS);
382 : }
383 :
384 0 : if (!nsCRT::strcmp(aCommandName, "cmd_insertBrOnReturn"))
385 : {
386 0 : NS_ENSURE_ARG_POINTER(aParams);
387 0 : nsCOMPtr<nsIHTMLEditor> htmleditor = do_QueryInterface(refCon);
388 0 : NS_ENSURE_TRUE(htmleditor, NS_ERROR_INVALID_ARG);
389 :
390 : bool createPOnReturn;
391 0 : htmleditor->GetReturnInParagraphCreatesNewParagraph(&createPOnReturn);
392 0 : return aParams->SetBooleanValue(STATE_ATTRIBUTE, !createPOnReturn);
393 : }
394 :
395 0 : if (!nsCRT::strcmp(aCommandName, "cmd_enableObjectResizing"))
396 : {
397 0 : NS_ENSURE_ARG_POINTER(aParams);
398 0 : nsCOMPtr<nsIHTMLObjectResizer> resizer = do_QueryInterface(refCon);
399 0 : NS_ENSURE_TRUE(resizer, NS_ERROR_INVALID_ARG);
400 :
401 : bool enabled;
402 0 : resizer->GetObjectResizingEnabled(&enabled);
403 0 : return aParams->SetBooleanValue(STATE_ATTRIBUTE, enabled);
404 : }
405 :
406 0 : if (!nsCRT::strcmp(aCommandName, "cmd_enableInlineTableEditing"))
407 : {
408 0 : NS_ENSURE_ARG_POINTER(aParams);
409 0 : nsCOMPtr<nsIHTMLInlineTableEditor> editor = do_QueryInterface(refCon);
410 0 : NS_ENSURE_TRUE(editor, NS_ERROR_INVALID_ARG);
411 :
412 : bool enabled;
413 0 : editor->GetInlineTableEditingEnabled(&enabled);
414 0 : return aParams->SetBooleanValue(STATE_ATTRIBUTE, enabled);
415 : }
416 :
417 0 : return NS_ERROR_NOT_IMPLEMENTED;
418 : }
419 :
420 : /**
421 : * Commands just for state notification
422 : * As of 11/21/02, possible commands are:
423 : * "obs_documentCreated"
424 : * "obs_documentWillBeDestroyed"
425 : * "obs_documentLocationChanged"
426 : * Note that you can use the same command class, nsDocumentStateCommand
427 : * for these or future observer commands.
428 : * We check the input command param for different behavior
429 : *
430 : * How to use:
431 : * 1. Get the nsICommandManager for the current editor
432 : * 2. Implement an nsIObserve object, e.g:
433 : *
434 : * void Observe(
435 : * in nsISupports aSubject, // The nsICommandManager calling this Observer
436 : * in string aTopic, // command name, e.g.:"obs_documentCreated"
437 : * // or "obs_documentWillBeDestroyed"
438 : in wstring aData ); // ignored (set to "command_status_changed")
439 : *
440 : * 3. Add the observer by:
441 : * commandManager.addObserver(observeobject, obs_documentCreated);
442 : * 4. In the appropriate location in editorSession, editor, or commands code,
443 : * trigger the notification of this observer by something like:
444 : *
445 : * nsCOMPtr<nsICommandManager> commandManager = do_GetInterface(mDocShell);
446 : * nsCOMPtr<nsPICommandUpdater> commandUpdater = do_QueryInterface(commandManager);
447 : * NS_ENSURE_TRUE(commandUpdater, NS_ERROR_FAILURE);
448 : * commandUpdater->CommandStatusChanged(obs_documentCreated);
449 : *
450 : * 5. Use GetCommandStateParams() to obtain state information
451 : * e.g., any creation state codes when creating an editor are
452 : * supplied for "obs_documentCreated" command in the
453 : * "state_data" param's value
454 : *
455 : */
456 :
457 : NS_IMETHODIMP
458 0 : nsDocumentStateCommand::IsCommandEnabled(const char* aCommandName,
459 : nsISupports *refCon,
460 : bool *outCmdEnabled)
461 : {
462 0 : NS_ENSURE_ARG_POINTER(outCmdEnabled);
463 : // Always return false to discourage callers from using DoCommand()
464 0 : *outCmdEnabled = false;
465 0 : return NS_OK;
466 : }
467 :
468 : NS_IMETHODIMP
469 0 : nsDocumentStateCommand::DoCommand(const char *aCommandName,
470 : nsISupports *refCon)
471 : {
472 0 : return NS_ERROR_NOT_IMPLEMENTED;
473 : }
474 :
475 : NS_IMETHODIMP
476 0 : nsDocumentStateCommand::DoCommandParams(const char *aCommandName,
477 : nsICommandParams *aParams,
478 : nsISupports *refCon)
479 : {
480 0 : return NS_ERROR_NOT_IMPLEMENTED;
481 : }
482 :
483 : NS_IMETHODIMP
484 0 : nsDocumentStateCommand::GetCommandStateParams(const char *aCommandName,
485 : nsICommandParams *aParams,
486 : nsISupports *refCon)
487 : {
488 0 : NS_ENSURE_ARG_POINTER(aParams);
489 0 : NS_ENSURE_ARG_POINTER(aCommandName);
490 : nsresult rv;
491 :
492 0 : if (!nsCRT::strcmp(aCommandName, "obs_documentCreated"))
493 : {
494 0 : PRUint32 editorStatus = nsIEditingSession::eEditorErrorUnknown;
495 :
496 0 : nsCOMPtr<nsIEditingSession> editingSession = do_QueryInterface(refCon);
497 0 : if (editingSession)
498 : {
499 : // refCon is initially set to nsIEditingSession until editor
500 : // is successfully created and source doc is loaded
501 : // Embedder gets error status if this fails
502 : // If called before startup is finished,
503 : // status = eEditorCreationInProgress
504 0 : rv = editingSession->GetEditorStatus(&editorStatus);
505 0 : NS_ENSURE_SUCCESS(rv, rv);
506 : }
507 : else
508 : {
509 : // If refCon is an editor, then everything started up OK!
510 0 : nsCOMPtr<nsIEditor> editor = do_QueryInterface(refCon);
511 0 : if (editor)
512 0 : editorStatus = nsIEditingSession::eEditorOK;
513 : }
514 :
515 : // Note that if refCon is not-null, but is neither
516 : // an nsIEditingSession or nsIEditor, we return "eEditorErrorUnknown"
517 0 : aParams->SetLongValue(STATE_DATA, editorStatus);
518 0 : return NS_OK;
519 : }
520 0 : else if (!nsCRT::strcmp(aCommandName, "obs_documentLocationChanged"))
521 : {
522 0 : nsCOMPtr<nsIEditor> editor = do_QueryInterface(refCon);
523 0 : if (editor)
524 : {
525 0 : nsCOMPtr<nsIDOMDocument> domDoc;
526 0 : editor->GetDocument(getter_AddRefs(domDoc));
527 0 : nsCOMPtr<nsIDocument> doc = do_QueryInterface(domDoc);
528 0 : NS_ENSURE_TRUE(doc, NS_ERROR_FAILURE);
529 :
530 0 : nsIURI *uri = doc->GetDocumentURI();
531 0 : NS_ENSURE_TRUE(uri, NS_ERROR_FAILURE);
532 :
533 0 : return aParams->SetISupportsValue(STATE_DATA, (nsISupports*)uri);
534 : }
535 0 : return NS_OK;
536 : }
537 :
538 0 : return NS_ERROR_NOT_IMPLEMENTED;
539 : }
|