Display new Autofill UI Contents in Views
[chromium-blink-merge.git] / webkit / glue / npruntime_util.cc
blob4c448aefe5caafcbaed8c2d7e91bd33a05736e04
1 // Copyright (c) 2012 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 "webkit/glue/npruntime_util.h"
7 #include "base/pickle.h"
8 #include "third_party/WebKit/Source/WebKit/chromium/public/WebBindings.h"
10 using WebKit::WebBindings;
12 namespace webkit_glue {
14 bool SerializeNPIdentifier(NPIdentifier identifier, Pickle* pickle) {
15 const NPUTF8* string;
16 int32_t number;
17 bool is_string;
18 WebBindings::extractIdentifierData(identifier, string, number, is_string);
20 if (!pickle->WriteBool(is_string))
21 return false;
22 if (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(PickleIterator* pickle_iter,
30 NPIdentifier* identifier) {
31 bool is_string;
32 if (!pickle_iter->ReadBool(&is_string))
33 return false;
35 if (is_string) {
36 const char* data;
37 int data_len;
38 if (!pickle_iter->ReadData(&data, &data_len))
39 return false;
40 DCHECK_EQ((static_cast<size_t>(data_len)), strlen(data) + 1);
41 *identifier = WebBindings::getStringIdentifier(data);
42 } else {
43 int number;
44 if (!pickle_iter->ReadInt(&number))
45 return false;
46 *identifier = WebBindings::getIntIdentifier(number);
48 return true;
51 } // namespace webkit_glue