OLD | NEW |
| (Empty) |
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. | |
4 | |
5 #include "content/child/npapi/npruntime_util.h" | |
6 | |
7 #include <stddef.h> | |
8 #include <stdint.h> | |
9 | |
10 #include "base/pickle.h" | |
11 #include "third_party/WebKit/public/web/WebBindings.h" | |
12 | |
13 using blink::WebBindings; | |
14 | |
15 namespace content { | |
16 | |
17 bool SerializeNPIdentifier(NPIdentifier identifier, base::Pickle* pickle) { | |
18 const NPUTF8* string; | |
19 int32_t number; | |
20 bool is_string; | |
21 WebBindings::extractIdentifierData(identifier, string, number, is_string); | |
22 | |
23 if (!pickle->WriteBool(is_string)) | |
24 return false; | |
25 if (is_string) { | |
26 // Write the null byte for efficiency on the other end. | |
27 return pickle->WriteData(string, strlen(string) + 1); | |
28 } | |
29 return pickle->WriteInt(number); | |
30 } | |
31 | |
32 bool DeserializeNPIdentifier(base::PickleIterator* pickle_iter, | |
33 NPIdentifier* identifier) { | |
34 bool is_string; | |
35 if (!pickle_iter->ReadBool(&is_string)) | |
36 return false; | |
37 | |
38 if (is_string) { | |
39 const char* data; | |
40 int data_len; | |
41 if (!pickle_iter->ReadData(&data, &data_len)) | |
42 return false; | |
43 DCHECK_EQ((static_cast<size_t>(data_len)), strlen(data) + 1); | |
44 *identifier = WebBindings::getStringIdentifier(data); | |
45 } else { | |
46 int number; | |
47 if (!pickle_iter->ReadInt(&number)) | |
48 return false; | |
49 *identifier = WebBindings::getIntIdentifier(number); | |
50 } | |
51 return true; | |
52 } | |
53 | |
54 } // namespace content | |
OLD | NEW |