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

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 ppapi { 18 namespace ppapi {
19 namespace proxy { 19 namespace proxy {
20 20
21 // SerializedVar::Inner -------------------------------------------------------- 21 // SerializedVar::Inner --------------------------------------------------------
22 22
23 SerializedVar::Inner::Inner() 23 SerializedVar::Inner::Inner()
24 : serialization_rules_(NULL), 24 : serialization_rules_(NULL),
25 var_(PP_MakeUndefined()), 25 var_(PP_MakeUndefined()),
26 instance_(0), 26 instance_(0),
27 cleanup_mode_(CLEANUP_NONE) { 27 cleanup_mode_(CLEANUP_NONE),
28 is_valid_var_(true) {
28 #ifndef NDEBUG 29 #ifndef NDEBUG
29 has_been_serialized_ = false; 30 has_been_serialized_ = false;
30 has_been_deserialized_ = false; 31 has_been_deserialized_ = false;
31 #endif 32 #endif
32 } 33 }
33 34
34 SerializedVar::Inner::Inner(VarSerializationRules* serialization_rules) 35 SerializedVar::Inner::Inner(VarSerializationRules* serialization_rules)
35 : serialization_rules_(serialization_rules), 36 : serialization_rules_(serialization_rules),
36 var_(PP_MakeUndefined()), 37 var_(PP_MakeUndefined()),
37 instance_(0), 38 instance_(0),
(...skipping 62 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 101 // 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 102 // output parameter, or possibly you used the wrong helper class
102 // (normally SerializedVarReturnValue). 103 // (normally SerializedVarReturnValue).
103 DCHECK(serialization_rules_.get()); 104 DCHECK(serialization_rules_.get());
104 105
105 #ifndef NDEBUG 106 #ifndef NDEBUG
106 // We should only be serializing something once. 107 // We should only be serializing something once.
107 DCHECK(!has_been_serialized_); 108 DCHECK(!has_been_serialized_);
108 has_been_serialized_ = true; 109 has_been_serialized_ = true;
109 #endif 110 #endif
110 RawVarDataGraph::Create(var_, instance_)->Write(m); 111 scoped_ptr<RawVarDataGraph> data =
112 RawVarDataGraph::Create(var_, instance_);
113 if (data) {
114 m->WriteBool(true); // Success.
115 data->Write(m);
116 } else {
117 m->WriteBool(false); // Failure.
118 }
111 } 119 }
112 120
113 bool SerializedVar::Inner::ReadFromMessage(const IPC::Message* m, 121 bool SerializedVar::Inner::ReadFromMessage(const IPC::Message* m,
114 PickleIterator* iter) { 122 PickleIterator* iter) {
115 #ifndef NDEBUG 123 #ifndef NDEBUG
116 // We should only deserialize something once or will end up with leaked 124 // We should only deserialize something once or will end up with leaked
117 // references. 125 // references.
118 // 126 //
119 // One place this has happened in the past is using 127 // One place this has happened in the past is using
120 // std::vector<SerializedVar>.resize(). If you're doing this manually instead 128 // std::vector<SerializedVar>.resize(). If you're doing this manually instead
121 // of using the helper classes for handling in/out vectors of vars, be 129 // of using the helper classes for handling in/out vectors of vars, be
122 // sure you use the same pattern as the SerializedVarVector classes. 130 // sure you use the same pattern as the SerializedVarVector classes.
123 DCHECK(!has_been_deserialized_); 131 DCHECK(!has_been_deserialized_);
124 has_been_deserialized_ = true; 132 has_been_deserialized_ = true;
125 #endif 133 #endif
126 // When reading, the dispatcher should be set when we get a Deserialize 134 // When reading, the dispatcher should be set when we get a Deserialize
127 // call (which will supply a dispatcher). 135 // call (which will supply a dispatcher).
128 raw_var_data_ = RawVarDataGraph::Read(m, iter); 136 if (!m->ReadBool(iter, &is_valid_var_))
129 return raw_var_data_.get() != NULL; 137 return false;
138 if (is_valid_var_) {
139 raw_var_data_ = RawVarDataGraph::Read(m, iter);
140 if (!raw_var_data_)
141 return false;
142 }
143
144 return true;
130 } 145 }
131 146
132 void SerializedVar::Inner::SetCleanupModeToEndSendPassRef() { 147 void SerializedVar::Inner::SetCleanupModeToEndSendPassRef() {
133 cleanup_mode_ = END_SEND_PASS_REF; 148 cleanup_mode_ = END_SEND_PASS_REF;
134 } 149 }
135 150
136 void SerializedVar::Inner::SetCleanupModeToEndReceiveCallerOwned() { 151 void SerializedVar::Inner::SetCleanupModeToEndReceiveCallerOwned() {
137 cleanup_mode_ = END_RECEIVE_CALLER_OWNED; 152 cleanup_mode_ = END_RECEIVE_CALLER_OWNED;
138 } 153 }
139 154
(...skipping 287 matching lines...) Expand 10 before | Expand all | Expand 10 after
427 const std::string& str) { 442 const std::string& str) {
428 inner_->ForceSetVarValueForTest(StringVar::StringToPPVar(str)); 443 inner_->ForceSetVarValueForTest(StringVar::StringToPPVar(str));
429 } 444 }
430 445
431 SerializedVarTestReader::SerializedVarTestReader(const SerializedVar& var) 446 SerializedVarTestReader::SerializedVarTestReader(const SerializedVar& var)
432 : SerializedVar(var) { 447 : SerializedVar(var) {
433 } 448 }
434 449
435 } // namespace proxy 450 } // namespace proxy
436 } // namespace ppapi 451 } // namespace ppapi
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698