1 : /* ***** BEGIN LICENSE BLOCK *****
2 : * Version: MPL 1.1/GPL 2.0/LGPL 2.1
3 : *
4 : * The contents of this file are subject to the Mozilla Public License Version
5 : * 1.1 (the "License"); you may not use this file except in compliance with
6 : * the License. You may obtain a copy of the License at
7 : * http://www.mozilla.org/MPL/
8 : *
9 : * Software distributed under the License is distributed on an "AS IS" basis,
10 : * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
11 : * for the specific language governing rights and limitations under the
12 : * License.
13 : *
14 : * The Original Code is mozilla.org code.
15 : *
16 : * The Initial Developer of the Original Code is
17 : * The Mozilla Foundation
18 : * Portions created by the Initial Developer are Copyright (C) 2010
19 : * the Initial Developer. All Rights Reserved.
20 : *
21 : * Contributor(s):
22 : * Michal Novotny <michal.novotny@gmail.com>
23 : *
24 : * Alternatively, the contents of this file may be used under the terms of
25 : * either the GNU General Public License Version 2 or later (the "GPL"), or
26 : * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
27 : * in which case the provisions of the GPL or the LGPL are applicable instead
28 : * of those above. If you wish to allow use of your version of this file only
29 : * under the terms of either the GPL or the LGPL, and not to allow others to
30 : * use your version of this file under the terms of the MPL, indicate your
31 : * decision by deleting the provisions above and replace them with the notice
32 : * and other provisions required by the GPL or the LGPL. If you do not delete
33 : * the provisions above, a recipient may use your version of this file under
34 : * the terms of any one of the MPL, the GPL or the LGPL.
35 : *
36 : * ***** END LICENSE BLOCK ***** */
37 :
38 : #include "nsWyciwyg.h"
39 :
40 : #include "mozilla/net/NeckoChild.h"
41 : #include "WyciwygChannelChild.h"
42 :
43 : #include "nsIParser.h"
44 : #include "nsStringStream.h"
45 : #include "nsMimeTypes.h"
46 : #include "nsNetUtil.h"
47 : #include "nsISerializable.h"
48 : #include "nsSerializationHelper.h"
49 :
50 : namespace mozilla {
51 : namespace net {
52 :
53 0 : NS_IMPL_ISUPPORTS3(WyciwygChannelChild,
54 : nsIRequest,
55 : nsIChannel,
56 : nsIWyciwygChannel);
57 :
58 :
59 0 : WyciwygChannelChild::WyciwygChannelChild()
60 : : mStatus(NS_OK)
61 : , mIsPending(false)
62 : , mCanceled(false)
63 : , mLoadFlags(LOAD_NORMAL)
64 : , mContentLength(-1)
65 : , mCharsetSource(kCharsetUninitialized)
66 : , mState(WCC_NEW)
67 : , mIPCOpen(false)
68 0 : , mEventQ(this)
69 : {
70 0 : LOG(("Creating WyciwygChannelChild @%x\n", this));
71 0 : }
72 :
73 0 : WyciwygChannelChild::~WyciwygChannelChild()
74 : {
75 0 : LOG(("Destroying WyciwygChannelChild @%x\n", this));
76 0 : }
77 :
78 : void
79 0 : WyciwygChannelChild::AddIPDLReference()
80 : {
81 0 : NS_ABORT_IF_FALSE(!mIPCOpen, "Attempt to retain more than one IPDL reference");
82 0 : mIPCOpen = true;
83 0 : AddRef();
84 0 : }
85 :
86 : void
87 0 : WyciwygChannelChild::ReleaseIPDLReference()
88 : {
89 0 : NS_ABORT_IF_FALSE(mIPCOpen, "Attempt to release nonexistent IPDL reference");
90 0 : mIPCOpen = false;
91 0 : Release();
92 0 : }
93 :
94 : nsresult
95 0 : WyciwygChannelChild::Init(nsIURI* uri)
96 : {
97 0 : NS_ENSURE_ARG_POINTER(uri);
98 :
99 0 : mState = WCC_INIT;
100 :
101 0 : mURI = uri;
102 0 : mOriginalURI = uri;
103 :
104 0 : SendInit(IPC::URI(mURI));
105 0 : return NS_OK;
106 : }
107 :
108 : //-----------------------------------------------------------------------------
109 : // WyciwygChannelChild::PWyciwygChannelChild
110 : //-----------------------------------------------------------------------------
111 :
112 : class WyciwygStartRequestEvent : public ChannelEvent
113 0 : {
114 : public:
115 0 : WyciwygStartRequestEvent(WyciwygChannelChild* child,
116 : const nsresult& statusCode,
117 : const PRInt32& contentLength,
118 : const PRInt32& source,
119 : const nsCString& charset,
120 : const nsCString& securityInfo)
121 : : mChild(child), mStatusCode(statusCode), mContentLength(contentLength),
122 0 : mSource(source), mCharset(charset), mSecurityInfo(securityInfo) {}
123 0 : void Run() { mChild->OnStartRequest(mStatusCode, mContentLength, mSource,
124 0 : mCharset, mSecurityInfo); }
125 : private:
126 : WyciwygChannelChild* mChild;
127 : nsresult mStatusCode;
128 : PRInt32 mContentLength;
129 : PRInt32 mSource;
130 : nsCString mCharset;
131 : nsCString mSecurityInfo;
132 : };
133 :
134 : bool
135 0 : WyciwygChannelChild::RecvOnStartRequest(const nsresult& statusCode,
136 : const PRInt32& contentLength,
137 : const PRInt32& source,
138 : const nsCString& charset,
139 : const nsCString& securityInfo)
140 : {
141 0 : if (mEventQ.ShouldEnqueue()) {
142 : mEventQ.Enqueue(new WyciwygStartRequestEvent(this, statusCode,
143 : contentLength, source,
144 0 : charset, securityInfo));
145 : } else {
146 0 : OnStartRequest(statusCode, contentLength, source, charset, securityInfo);
147 : }
148 0 : return true;
149 : }
150 :
151 : void
152 0 : WyciwygChannelChild::OnStartRequest(const nsresult& statusCode,
153 : const PRInt32& contentLength,
154 : const PRInt32& source,
155 : const nsCString& charset,
156 : const nsCString& securityInfo)
157 : {
158 0 : LOG(("WyciwygChannelChild::RecvOnStartRequest [this=%x]\n", this));
159 :
160 0 : mState = WCC_ONSTART;
161 :
162 0 : mStatus = statusCode;
163 0 : mContentLength = contentLength;
164 0 : mCharsetSource = source;
165 0 : mCharset = charset;
166 :
167 0 : if (!securityInfo.IsEmpty()) {
168 0 : NS_DeserializeObject(securityInfo, getter_AddRefs(mSecurityInfo));
169 : }
170 :
171 0 : AutoEventEnqueuer ensureSerialDispatch(mEventQ);
172 :
173 0 : nsresult rv = mListener->OnStartRequest(this, mListenerContext);
174 0 : if (NS_FAILED(rv))
175 0 : Cancel(rv);
176 0 : }
177 :
178 : class WyciwygDataAvailableEvent : public ChannelEvent
179 0 : {
180 : public:
181 0 : WyciwygDataAvailableEvent(WyciwygChannelChild* child,
182 : const nsCString& data,
183 : const PRUint32& offset)
184 0 : : mChild(child), mData(data), mOffset(offset) {}
185 0 : void Run() { mChild->OnDataAvailable(mData, mOffset); }
186 : private:
187 : WyciwygChannelChild* mChild;
188 : nsCString mData;
189 : PRUint32 mOffset;
190 : };
191 :
192 : bool
193 0 : WyciwygChannelChild::RecvOnDataAvailable(const nsCString& data,
194 : const PRUint32& offset)
195 : {
196 0 : if (mEventQ.ShouldEnqueue()) {
197 0 : mEventQ.Enqueue(new WyciwygDataAvailableEvent(this, data, offset));
198 : } else {
199 0 : OnDataAvailable(data, offset);
200 : }
201 0 : return true;
202 : }
203 :
204 : void
205 0 : WyciwygChannelChild::OnDataAvailable(const nsCString& data,
206 : const PRUint32& offset)
207 : {
208 0 : LOG(("WyciwygChannelChild::RecvOnDataAvailable [this=%x]\n", this));
209 :
210 0 : if (mCanceled)
211 0 : return;
212 :
213 0 : mState = WCC_ONDATA;
214 :
215 : // NOTE: the OnDataAvailable contract requires the client to read all the data
216 : // in the inputstream. This code relies on that ('data' will go away after
217 : // this function). Apparently the previous, non-e10s behavior was to actually
218 : // support only reading part of the data, allowing later calls to read the
219 : // rest.
220 0 : nsCOMPtr<nsIInputStream> stringStream;
221 0 : nsresult rv = NS_NewByteInputStream(getter_AddRefs(stringStream),
222 : data.get(),
223 0 : data.Length(),
224 0 : NS_ASSIGNMENT_DEPEND);
225 0 : if (NS_FAILED(rv)) {
226 0 : Cancel(rv);
227 : return;
228 : }
229 :
230 0 : AutoEventEnqueuer ensureSerialDispatch(mEventQ);
231 :
232 0 : rv = mListener->OnDataAvailable(this, mListenerContext,
233 0 : stringStream, offset, data.Length());
234 0 : if (NS_FAILED(rv))
235 0 : Cancel(rv);
236 :
237 0 : if (mProgressSink && NS_SUCCEEDED(rv) && !(mLoadFlags & LOAD_BACKGROUND))
238 0 : mProgressSink->OnProgress(this, nsnull, PRUint64(offset + data.Length()),
239 0 : PRUint64(mContentLength));
240 : }
241 :
242 : class WyciwygStopRequestEvent : public ChannelEvent
243 0 : {
244 : public:
245 0 : WyciwygStopRequestEvent(WyciwygChannelChild* child,
246 : const nsresult& statusCode)
247 0 : : mChild(child), mStatusCode(statusCode) {}
248 0 : void Run() { mChild->OnStopRequest(mStatusCode); }
249 : private:
250 : WyciwygChannelChild* mChild;
251 : nsresult mStatusCode;
252 : };
253 :
254 : bool
255 0 : WyciwygChannelChild::RecvOnStopRequest(const nsresult& statusCode)
256 : {
257 0 : if (mEventQ.ShouldEnqueue()) {
258 0 : mEventQ.Enqueue(new WyciwygStopRequestEvent(this, statusCode));
259 : } else {
260 0 : OnStopRequest(statusCode);
261 : }
262 0 : return true;
263 : }
264 :
265 : void
266 0 : WyciwygChannelChild::OnStopRequest(const nsresult& statusCode)
267 : {
268 0 : LOG(("WyciwygChannelChild::RecvOnStopRequest [this=%x status=%u]\n",
269 : this, statusCode));
270 :
271 : { // We need to ensure that all IPDL message dispatching occurs
272 : // before we delete the protocol below
273 0 : AutoEventEnqueuer ensureSerialDispatch(mEventQ);
274 :
275 0 : mState = WCC_ONSTOP;
276 :
277 0 : mIsPending = false;
278 :
279 0 : if (!mCanceled)
280 0 : mStatus = statusCode;
281 :
282 0 : mListener->OnStopRequest(this, mListenerContext, statusCode);
283 :
284 0 : mListener = 0;
285 0 : mListenerContext = 0;
286 :
287 0 : if (mLoadGroup)
288 0 : mLoadGroup->RemoveRequest(this, nsnull, mStatus);
289 :
290 0 : mCallbacks = 0;
291 0 : mProgressSink = 0;
292 : }
293 :
294 0 : if (mIPCOpen)
295 0 : PWyciwygChannelChild::Send__delete__(this);
296 0 : }
297 :
298 : class WyciwygCancelEvent : public ChannelEvent
299 0 : {
300 : public:
301 0 : WyciwygCancelEvent(WyciwygChannelChild* child, const nsresult& status)
302 : : mChild(child)
303 0 : , mStatus(status) {}
304 :
305 0 : void Run() { mChild->CancelEarly(mStatus); }
306 : private:
307 : WyciwygChannelChild* mChild;
308 : nsresult mStatus;
309 : };
310 :
311 : bool
312 0 : WyciwygChannelChild::RecvCancelEarly(const nsresult& statusCode)
313 : {
314 0 : if (mEventQ.ShouldEnqueue()) {
315 0 : mEventQ.Enqueue(new WyciwygCancelEvent(this, statusCode));
316 : } else {
317 0 : CancelEarly(statusCode);
318 : }
319 0 : return true;
320 : }
321 :
322 0 : void WyciwygChannelChild::CancelEarly(const nsresult& statusCode)
323 : {
324 0 : LOG(("WyciwygChannelChild::CancelEarly [this=%x]\n", this));
325 :
326 0 : if (mCanceled)
327 0 : return;
328 :
329 0 : mCanceled = true;
330 0 : mStatus = statusCode;
331 :
332 0 : mIsPending = false;
333 0 : if (mLoadGroup)
334 0 : mLoadGroup->RemoveRequest(this, nsnull, mStatus);
335 :
336 0 : if (mListener) {
337 0 : mListener->OnStartRequest(this, mListenerContext);
338 0 : mListener->OnStopRequest(this, mListenerContext, mStatus);
339 : }
340 0 : mListener = nsnull;
341 0 : mListenerContext = nsnull;
342 :
343 0 : if (mIPCOpen)
344 0 : PWyciwygChannelChild::Send__delete__(this);
345 : }
346 :
347 : //-----------------------------------------------------------------------------
348 : // nsIRequest
349 : //-----------------------------------------------------------------------------
350 :
351 : /* readonly attribute AUTF8String name; */
352 : NS_IMETHODIMP
353 0 : WyciwygChannelChild::GetName(nsACString & aName)
354 : {
355 0 : return mURI->GetSpec(aName);
356 : }
357 :
358 : /* boolean isPending (); */
359 : NS_IMETHODIMP
360 0 : WyciwygChannelChild::IsPending(bool *aIsPending)
361 : {
362 0 : *aIsPending = mIsPending;
363 0 : return NS_OK;
364 : }
365 :
366 : /* readonly attribute nsresult status; */
367 : NS_IMETHODIMP
368 0 : WyciwygChannelChild::GetStatus(nsresult *aStatus)
369 : {
370 0 : *aStatus = mStatus;
371 0 : return NS_OK;
372 : }
373 :
374 : /* void cancel (in nsresult aStatus); */
375 : NS_IMETHODIMP
376 0 : WyciwygChannelChild::Cancel(nsresult aStatus)
377 : {
378 0 : if (mCanceled)
379 0 : return NS_OK;
380 :
381 0 : mCanceled = true;
382 0 : mStatus = aStatus;
383 0 : if (mIPCOpen)
384 0 : SendCancel(aStatus);
385 0 : return NS_OK;
386 : }
387 :
388 : /* void suspend (); */
389 : NS_IMETHODIMP
390 0 : WyciwygChannelChild::Suspend()
391 : {
392 0 : return NS_ERROR_NOT_IMPLEMENTED;
393 : }
394 :
395 : /* void resume (); */
396 : NS_IMETHODIMP
397 0 : WyciwygChannelChild::Resume()
398 : {
399 0 : return NS_ERROR_NOT_IMPLEMENTED;
400 : }
401 :
402 : /* attribute nsILoadGroup loadGroup; */
403 : NS_IMETHODIMP
404 0 : WyciwygChannelChild::GetLoadGroup(nsILoadGroup * *aLoadGroup)
405 : {
406 0 : *aLoadGroup = mLoadGroup;
407 0 : NS_IF_ADDREF(*aLoadGroup);
408 0 : return NS_OK;
409 : }
410 : NS_IMETHODIMP
411 0 : WyciwygChannelChild::SetLoadGroup(nsILoadGroup * aLoadGroup)
412 : {
413 0 : mLoadGroup = aLoadGroup;
414 : NS_QueryNotificationCallbacks(mCallbacks,
415 : mLoadGroup,
416 : NS_GET_IID(nsIProgressEventSink),
417 0 : getter_AddRefs(mProgressSink));
418 0 : return NS_OK;
419 : }
420 :
421 : /* attribute nsLoadFlags loadFlags; */
422 : NS_IMETHODIMP
423 0 : WyciwygChannelChild::GetLoadFlags(nsLoadFlags *aLoadFlags)
424 : {
425 0 : *aLoadFlags = mLoadFlags;
426 0 : return NS_OK;
427 : }
428 : NS_IMETHODIMP
429 0 : WyciwygChannelChild::SetLoadFlags(nsLoadFlags aLoadFlags)
430 : {
431 0 : mLoadFlags = aLoadFlags;
432 0 : return NS_OK;
433 : }
434 :
435 :
436 : //-----------------------------------------------------------------------------
437 : // nsIChannel
438 : //-----------------------------------------------------------------------------
439 :
440 : /* attribute nsIURI originalURI; */
441 : NS_IMETHODIMP
442 0 : WyciwygChannelChild::GetOriginalURI(nsIURI * *aOriginalURI)
443 : {
444 0 : *aOriginalURI = mOriginalURI;
445 0 : NS_ADDREF(*aOriginalURI);
446 0 : return NS_OK;
447 : }
448 : NS_IMETHODIMP
449 0 : WyciwygChannelChild::SetOriginalURI(nsIURI * aOriginalURI)
450 : {
451 0 : NS_ENSURE_TRUE(mState == WCC_INIT, NS_ERROR_UNEXPECTED);
452 :
453 0 : NS_ENSURE_ARG_POINTER(aOriginalURI);
454 0 : mOriginalURI = aOriginalURI;
455 0 : return NS_OK;
456 : }
457 :
458 : /* readonly attribute nsIURI URI; */
459 : NS_IMETHODIMP
460 0 : WyciwygChannelChild::GetURI(nsIURI * *aURI)
461 : {
462 0 : *aURI = mURI;
463 0 : NS_IF_ADDREF(*aURI);
464 0 : return NS_OK;
465 : }
466 :
467 : /* attribute nsISupports owner; */
468 : NS_IMETHODIMP
469 0 : WyciwygChannelChild::GetOwner(nsISupports * *aOwner)
470 : {
471 0 : NS_PRECONDITION(mOwner, "Must have a principal!");
472 0 : NS_ENSURE_STATE(mOwner);
473 :
474 0 : NS_ADDREF(*aOwner = mOwner);
475 0 : return NS_OK;
476 : }
477 : NS_IMETHODIMP
478 0 : WyciwygChannelChild::SetOwner(nsISupports * aOwner)
479 : {
480 0 : mOwner = aOwner;
481 0 : return NS_OK;
482 : }
483 :
484 : /* attribute nsIInterfaceRequestor notificationCallbacks; */
485 : NS_IMETHODIMP
486 0 : WyciwygChannelChild::GetNotificationCallbacks(nsIInterfaceRequestor * *aCallbacks)
487 : {
488 0 : *aCallbacks = mCallbacks;
489 0 : NS_IF_ADDREF(*aCallbacks);
490 0 : return NS_OK;
491 : }
492 : NS_IMETHODIMP
493 0 : WyciwygChannelChild::SetNotificationCallbacks(nsIInterfaceRequestor * aCallbacks)
494 : {
495 0 : mCallbacks = aCallbacks;
496 : NS_QueryNotificationCallbacks(mCallbacks,
497 : mLoadGroup,
498 : NS_GET_IID(nsIProgressEventSink),
499 0 : getter_AddRefs(mProgressSink));
500 0 : return NS_OK;
501 : }
502 :
503 : /* readonly attribute nsISupports securityInfo; */
504 : NS_IMETHODIMP
505 0 : WyciwygChannelChild::GetSecurityInfo(nsISupports * *aSecurityInfo)
506 : {
507 0 : NS_IF_ADDREF(*aSecurityInfo = mSecurityInfo);
508 :
509 0 : return NS_OK;
510 : }
511 :
512 : /* attribute ACString contentType; */
513 : NS_IMETHODIMP
514 0 : WyciwygChannelChild::GetContentType(nsACString & aContentType)
515 : {
516 0 : aContentType.AssignLiteral(WYCIWYG_TYPE);
517 0 : return NS_OK;
518 : }
519 : NS_IMETHODIMP
520 0 : WyciwygChannelChild::SetContentType(const nsACString & aContentType)
521 : {
522 0 : return NS_ERROR_NOT_IMPLEMENTED;
523 : }
524 :
525 : /* attribute ACString contentCharset; */
526 : NS_IMETHODIMP
527 0 : WyciwygChannelChild::GetContentCharset(nsACString & aContentCharset)
528 : {
529 0 : aContentCharset.Assign("UTF-16");
530 0 : return NS_OK;
531 : }
532 : NS_IMETHODIMP
533 0 : WyciwygChannelChild::SetContentCharset(const nsACString & aContentCharset)
534 : {
535 0 : return NS_ERROR_NOT_IMPLEMENTED;
536 : }
537 :
538 : NS_IMETHODIMP
539 0 : WyciwygChannelChild::GetContentDisposition(PRUint32 *aContentDisposition)
540 : {
541 0 : return NS_ERROR_NOT_AVAILABLE;
542 : }
543 :
544 : NS_IMETHODIMP
545 0 : WyciwygChannelChild::GetContentDispositionFilename(nsAString &aContentDispositionFilename)
546 : {
547 0 : return NS_ERROR_NOT_AVAILABLE;
548 : }
549 :
550 : NS_IMETHODIMP
551 0 : WyciwygChannelChild::GetContentDispositionHeader(nsACString &aContentDispositionHeader)
552 : {
553 0 : return NS_ERROR_NOT_AVAILABLE;
554 : }
555 :
556 : /* attribute long contentLength; */
557 : NS_IMETHODIMP
558 0 : WyciwygChannelChild::GetContentLength(PRInt32 *aContentLength)
559 : {
560 0 : return NS_ERROR_NOT_IMPLEMENTED;
561 : }
562 : NS_IMETHODIMP
563 0 : WyciwygChannelChild::SetContentLength(PRInt32 aContentLength)
564 : {
565 0 : return NS_ERROR_NOT_IMPLEMENTED;
566 : }
567 :
568 : /* nsIInputStream open (); */
569 : NS_IMETHODIMP
570 0 : WyciwygChannelChild::Open(nsIInputStream **_retval)
571 : {
572 0 : return NS_ERROR_NOT_IMPLEMENTED;
573 : }
574 :
575 : /* void asyncOpen (in nsIStreamListener aListener, in nsISupports aContext); */
576 : NS_IMETHODIMP
577 0 : WyciwygChannelChild::AsyncOpen(nsIStreamListener *aListener, nsISupports *aContext)
578 : {
579 0 : LOG(("WyciwygChannelChild::AsyncOpen [this=%x]\n", this));
580 :
581 : // The only places creating wyciwyg: channels should be
582 : // HTMLDocument::OpenCommon and session history. Both should be setting an
583 : // owner.
584 0 : NS_PRECONDITION(mOwner, "Must have a principal");
585 0 : NS_ENSURE_STATE(mOwner);
586 :
587 0 : NS_ENSURE_ARG_POINTER(aListener);
588 0 : NS_ENSURE_TRUE(!mIsPending, NS_ERROR_IN_PROGRESS);
589 :
590 0 : mListener = aListener;
591 0 : mListenerContext = aContext;
592 0 : mIsPending = true;
593 :
594 0 : if (mLoadGroup)
595 0 : mLoadGroup->AddRequest(this, nsnull);
596 :
597 0 : SendAsyncOpen(IPC::URI(mOriginalURI), mLoadFlags);
598 :
599 0 : mState = WCC_OPENED;
600 :
601 0 : return NS_OK;
602 : }
603 :
604 :
605 : //-----------------------------------------------------------------------------
606 : // nsIWyciwygChannel
607 : //-----------------------------------------------------------------------------
608 :
609 : /* void writeToCacheEntry (in AString aData); */
610 : NS_IMETHODIMP
611 0 : WyciwygChannelChild::WriteToCacheEntry(const nsAString & aData)
612 : {
613 0 : NS_ENSURE_TRUE((mState == WCC_INIT) ||
614 : (mState == WCC_ONWRITE), NS_ERROR_UNEXPECTED);
615 :
616 0 : SendWriteToCacheEntry(PromiseFlatString(aData));
617 0 : mState = WCC_ONWRITE;
618 0 : return NS_OK;
619 : }
620 :
621 : /* void closeCacheEntry (in nsresult reason); */
622 : NS_IMETHODIMP
623 0 : WyciwygChannelChild::CloseCacheEntry(nsresult reason)
624 : {
625 0 : NS_ENSURE_TRUE(mState == WCC_ONWRITE, NS_ERROR_UNEXPECTED);
626 :
627 0 : SendCloseCacheEntry(reason);
628 0 : mState = WCC_ONCLOSED;
629 :
630 0 : if (mIPCOpen)
631 0 : PWyciwygChannelChild::Send__delete__(this);
632 :
633 0 : return NS_OK;
634 : }
635 :
636 : /* void setSecurityInfo (in nsISupports aSecurityInfo); */
637 : NS_IMETHODIMP
638 0 : WyciwygChannelChild::SetSecurityInfo(nsISupports *aSecurityInfo)
639 : {
640 0 : mSecurityInfo = aSecurityInfo;
641 :
642 0 : if (mSecurityInfo) {
643 0 : nsCOMPtr<nsISerializable> serializable = do_QueryInterface(mSecurityInfo);
644 0 : if (serializable) {
645 0 : nsCString secInfoStr;
646 0 : NS_SerializeToString(serializable, secInfoStr);
647 0 : SendSetSecurityInfo(secInfoStr);
648 : }
649 : else {
650 0 : NS_WARNING("Can't serialize security info");
651 : }
652 : }
653 :
654 0 : return NS_OK;
655 : }
656 :
657 : /* void setCharsetAndSource (in long aSource, in ACString aCharset); */
658 : NS_IMETHODIMP
659 0 : WyciwygChannelChild::SetCharsetAndSource(PRInt32 aSource, const nsACString & aCharset)
660 : {
661 : // mState == WCC_ONSTART when reading from the channel
662 : // mState == WCC_INIT when writing to the cache
663 0 : NS_ENSURE_TRUE((mState == WCC_ONSTART) ||
664 : (mState == WCC_INIT), NS_ERROR_UNEXPECTED);
665 :
666 0 : mCharsetSource = aSource;
667 0 : mCharset = aCharset;
668 :
669 : // TODO ensure that nsWyciwygChannel in the parent has still the cache entry
670 0 : SendSetCharsetAndSource(mCharsetSource, mCharset);
671 0 : return NS_OK;
672 : }
673 :
674 : /* ACString getCharsetAndSource (out long aSource); */
675 : NS_IMETHODIMP
676 0 : WyciwygChannelChild::GetCharsetAndSource(PRInt32 *aSource NS_OUTPARAM, nsACString & _retval)
677 : {
678 0 : NS_ENSURE_TRUE((mState == WCC_ONSTART) ||
679 : (mState == WCC_ONDATA) ||
680 : (mState == WCC_ONSTOP), NS_ERROR_NOT_AVAILABLE);
681 :
682 0 : if (mCharsetSource == kCharsetUninitialized)
683 0 : return NS_ERROR_NOT_AVAILABLE;
684 :
685 0 : *aSource = mCharsetSource;
686 0 : _retval = mCharset;
687 0 : return NS_OK;
688 : }
689 :
690 : //------------------------------------------------------------------------------
691 : }} // mozilla::net
|