1 // Copyright (c) 2012 The Chromium Embedded Framework Authors. All rights
2 // reserved. Use of this source code is governed by a BSD-style license that
3 // can be found in the LICENSE file.
4
5 #include "libcef/common/process_message_impl.h"
6 #include "libcef/common/cef_messages.h"
7 #include "libcef/common/values_impl.h"
8
9 #include "base/logging.h"
10
11 namespace {
12
CopyValue(const Cef_Request_Params & source,Cef_Request_Params & target)13 void CopyValue(const Cef_Request_Params& source, Cef_Request_Params& target) {
14 target.name = source.name;
15 auto copy = source.arguments.CreateDeepCopy();
16 target.arguments.Swap(copy.get());
17 }
18
19 } // namespace
20
21 // static
Create(const CefString & name)22 CefRefPtr<CefProcessMessage> CefProcessMessage::Create(const CefString& name) {
23 Cef_Request_Params* params = new Cef_Request_Params();
24 params->name = name;
25 return new CefProcessMessageImpl(params, true, false);
26 }
27
CefProcessMessageImpl(Cef_Request_Params * value,bool will_delete,bool read_only)28 CefProcessMessageImpl::CefProcessMessageImpl(Cef_Request_Params* value,
29 bool will_delete,
30 bool read_only)
31 : CefValueBase<CefProcessMessage, Cef_Request_Params>(
32 value,
33 nullptr,
34 will_delete ? kOwnerWillDelete : kOwnerNoDelete,
35 read_only,
36 nullptr) {}
37
CopyTo(Cef_Request_Params & target)38 bool CefProcessMessageImpl::CopyTo(Cef_Request_Params& target) {
39 CEF_VALUE_VERIFY_RETURN(false, false);
40 CopyValue(const_value(), target);
41 return true;
42 }
43
IsValid()44 bool CefProcessMessageImpl::IsValid() {
45 return !detached();
46 }
47
IsReadOnly()48 bool CefProcessMessageImpl::IsReadOnly() {
49 return read_only();
50 }
51
Copy()52 CefRefPtr<CefProcessMessage> CefProcessMessageImpl::Copy() {
53 CEF_VALUE_VERIFY_RETURN(false, nullptr);
54 Cef_Request_Params* params = new Cef_Request_Params();
55 CopyValue(const_value(), *params);
56 return new CefProcessMessageImpl(params, true, false);
57 }
58
GetName()59 CefString CefProcessMessageImpl::GetName() {
60 CEF_VALUE_VERIFY_RETURN(false, CefString());
61 return const_value().name;
62 }
63
GetArgumentList()64 CefRefPtr<CefListValue> CefProcessMessageImpl::GetArgumentList() {
65 CEF_VALUE_VERIFY_RETURN(false, nullptr);
66 return CefListValueImpl::GetOrCreateRef(
67 const_cast<base::ListValue*>(&(const_value().arguments)),
68 const_cast<Cef_Request_Params*>(&const_value()), read_only(),
69 controller());
70 }
71