1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4  * License, v. 2.0. If a copy of the MPL was not distributed with this
5  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 
7 #include "mozilla/dom/DocShellMessageUtils.h"
8 #include "nsSerializationHelper.h"
9 
10 namespace mozilla {
11 namespace ipc {
12 
Write(IPC::Message * aMsg,IProtocol * aActor,nsDocShellLoadState * aParam)13 void IPDLParamTraits<nsDocShellLoadState*>::Write(IPC::Message* aMsg,
14                                                   IProtocol* aActor,
15                                                   nsDocShellLoadState* aParam) {
16   MOZ_RELEASE_ASSERT(aParam);
17   WriteIPDLParam(aMsg, aActor, aParam->Serialize());
18 }
19 
Read(const IPC::Message * aMsg,PickleIterator * aIter,IProtocol * aActor,RefPtr<nsDocShellLoadState> * aResult)20 bool IPDLParamTraits<nsDocShellLoadState*>::Read(
21     const IPC::Message* aMsg, PickleIterator* aIter, IProtocol* aActor,
22     RefPtr<nsDocShellLoadState>* aResult) {
23   DocShellLoadStateInit loadState;
24   if (!ReadIPDLParam(aMsg, aIter, aActor, &loadState)) {
25     return false;
26   }
27 
28   // Assert if we somehow don't have a URI in our IPDL type, because we can't
29   // construct anything out of it. This mimics the assertion in the constructor
30   // for nsDocShellLoadState, but makes it clearer that the
31   // DocShellLoadStateInit IPC object can't be clearly converted into a
32   // nsDocShellLoadState.
33   MOZ_ASSERT(loadState.URI());
34 
35   *aResult = new nsDocShellLoadState(loadState);
36   return true;
37 }
38 
39 }  // namespace ipc
40 }  // namespace mozilla
41