1 // Copyright (c) 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "content/child/npapi/npruntime_util.h"
7 #include "base/pickle.h"
8 #include "third_party/WebKit/public/web/WebBindings.h"
10 using blink::WebBindings
;
14 bool SerializeNPIdentifier(NPIdentifier identifier
, base::Pickle
* pickle
) {
18 WebBindings::extractIdentifierData(identifier
, string
, number
, is_string
);
20 if (!pickle
->WriteBool(is_string
))
23 // Write the null byte for efficiency on the other end.
24 return pickle
->WriteData(string
, strlen(string
) + 1);
26 return pickle
->WriteInt(number
);
29 bool DeserializeNPIdentifier(base::PickleIterator
* pickle_iter
,
30 NPIdentifier
* identifier
) {
32 if (!pickle_iter
->ReadBool(&is_string
))
38 if (!pickle_iter
->ReadData(&data
, &data_len
))
40 DCHECK_EQ((static_cast<size_t>(data_len
)), strlen(data
) + 1);
41 *identifier
= WebBindings::getStringIdentifier(data
);
44 if (!pickle_iter
->ReadInt(&number
))
46 *identifier
= WebBindings::getIntIdentifier(number
);
51 } // namespace content