Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(351)

Side by Side Diff: ppapi/proxy/serialized_var.cc

Issue 16140011: Don't send PP_Vars/V8 values with cycles across PostMessage (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 7 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "ppapi/proxy/serialized_var.h" 5 #include "ppapi/proxy/serialized_var.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "ipc/ipc_message_utils.h" 8 #include "ipc/ipc_message_utils.h"
9 #include "ppapi/c/pp_instance.h" 9 #include "ppapi/c/pp_instance.h"
10 #include "ppapi/proxy/dispatcher.h" 10 #include "ppapi/proxy/dispatcher.h"
11 #include "ppapi/proxy/interface_proxy.h" 11 #include "ppapi/proxy/interface_proxy.h"
12 #include "ppapi/proxy/ppapi_param_traits.h" 12 #include "ppapi/proxy/ppapi_param_traits.h"
13 #include "ppapi/proxy/ppb_buffer_proxy.h" 13 #include "ppapi/proxy/ppb_buffer_proxy.h"
14 #include "ppapi/shared_impl/ppapi_globals.h" 14 #include "ppapi/shared_impl/ppapi_globals.h"
15 #include "ppapi/shared_impl/var.h" 15 #include "ppapi/shared_impl/var.h"
16 #include "ppapi/thunk/enter.h" 16 #include "ppapi/thunk/enter.h"
17 17
18 namespace {
19 const char kSerializationError[] = "Failed to serialize a PP_Var. It may have "
20 "cycles or be of an unsupported type: ";
21 } // namespace
22
18 namespace ppapi { 23 namespace ppapi {
19 namespace proxy { 24 namespace proxy {
20 25
21 // SerializedVar::Inner -------------------------------------------------------- 26 // SerializedVar::Inner --------------------------------------------------------
22 27
23 SerializedVar::Inner::Inner() 28 SerializedVar::Inner::Inner()
24 : serialization_rules_(NULL), 29 : serialization_rules_(NULL),
25 var_(PP_MakeUndefined()), 30 var_(PP_MakeUndefined()),
26 instance_(0), 31 instance_(0),
27 cleanup_mode_(CLEANUP_NONE) { 32 cleanup_mode_(CLEANUP_NONE) {
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
100 // that returns a var. This means the message handler didn't write to the 105 // that returns a var. This means the message handler didn't write to the
101 // output parameter, or possibly you used the wrong helper class 106 // output parameter, or possibly you used the wrong helper class
102 // (normally SerializedVarReturnValue). 107 // (normally SerializedVarReturnValue).
103 DCHECK(serialization_rules_.get()); 108 DCHECK(serialization_rules_.get());
104 109
105 #ifndef NDEBUG 110 #ifndef NDEBUG
106 // We should only be serializing something once. 111 // We should only be serializing something once.
107 DCHECK(!has_been_serialized_); 112 DCHECK(!has_been_serialized_);
108 has_been_serialized_ = true; 113 has_been_serialized_ = true;
109 #endif 114 #endif
110 RawVarDataGraph::Create(var_, instance_)->Write(m); 115 scoped_ptr<RawVarDataGraph> data =
116 RawVarDataGraph::Create(var_, instance_, false);
117 if (data) {
118 data->Write(m);
119 } else {
120 // TODO(raymes): It's not ideal to log here. We should probably propagate
121 // the error all the way through to the location at which the var is used.
122 // However, SerializedVar isn't set up to propagate errors well. This case
123 // should only occur if the the PP_Var passed in is somehow corrupt or a var
124 // with reference cycles is passed in.
125 PpapiGlobals::Get()->LogWithSource(
126 instance_, PP_LOGLEVEL_ERROR, std::string(),
127 kSerializationError + ppapi::Var::PPVarToLogString(var_));
dmichael (off chromium) 2013/06/04 16:59:10 Yeah... this is going to result in sending a mess
raymes 2013/06/04 19:36:06 I actually went down this road first and then back
128 RawVarDataGraph::Create(PP_MakeUndefined(), instance_, false)->Write(m);
129 }
111 } 130 }
112 131
113 bool SerializedVar::Inner::ReadFromMessage(const IPC::Message* m, 132 bool SerializedVar::Inner::ReadFromMessage(const IPC::Message* m,
114 PickleIterator* iter) { 133 PickleIterator* iter) {
115 #ifndef NDEBUG 134 #ifndef NDEBUG
116 // We should only deserialize something once or will end up with leaked 135 // We should only deserialize something once or will end up with leaked
117 // references. 136 // references.
118 // 137 //
119 // One place this has happened in the past is using 138 // One place this has happened in the past is using
120 // std::vector<SerializedVar>.resize(). If you're doing this manually instead 139 // std::vector<SerializedVar>.resize(). If you're doing this manually instead
(...skipping 306 matching lines...) Expand 10 before | Expand all | Expand 10 after
427 const std::string& str) { 446 const std::string& str) {
428 inner_->ForceSetVarValueForTest(StringVar::StringToPPVar(str)); 447 inner_->ForceSetVarValueForTest(StringVar::StringToPPVar(str));
429 } 448 }
430 449
431 SerializedVarTestReader::SerializedVarTestReader(const SerializedVar& var) 450 SerializedVarTestReader::SerializedVarTestReader(const SerializedVar& var)
432 : SerializedVar(var) { 451 : SerializedVar(var) {
433 } 452 }
434 453
435 } // namespace proxy 454 } // namespace proxy
436 } // namespace ppapi 455 } // namespace ppapi
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698