DocShellMessageUtils.cpp (1592B)
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 9 #include "mozilla/dom/DOMTypes.h" 10 #include "nsSerializationHelper.h" 11 12 namespace IPC { 13 14 void ParamTraits<nsDocShellLoadState*>::Write(IPC::MessageWriter* aWriter, 15 nsDocShellLoadState* aParam) { 16 MOZ_RELEASE_ASSERT(aParam); 17 WriteParam(aWriter, aParam->Serialize(aWriter->GetActor())); 18 } 19 20 bool ParamTraits<nsDocShellLoadState*>::Read( 21 IPC::MessageReader* aReader, RefPtr<nsDocShellLoadState>* aResult) { 22 mozilla::dom::DocShellLoadStateInit loadState; 23 if (!ReadParam(aReader, &loadState)) { 24 return false; 25 } 26 27 // Assert if we somehow don't have a URI in our IPDL type, because we can't 28 // construct anything out of it. This mimics the assertion in the constructor 29 // for nsDocShellLoadState, but makes it clearer that the 30 // DocShellLoadStateInit IPC object can't be clearly converted into a 31 // nsDocShellLoadState. 32 if (!loadState.URI()) { 33 MOZ_ASSERT_UNREACHABLE("no URI in load state from IPC"); 34 return false; 35 } 36 37 bool readSuccess = false; 38 RefPtr result = 39 new nsDocShellLoadState(loadState, aReader->GetActor(), &readSuccess); 40 if (readSuccess) { 41 *aResult = result.forget(); 42 } 43 return readSuccess; 44 } 45 46 } // namespace IPC