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