• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
7 #include <memory>
8 
9 #include "libcef/common/values_impl.h"
10 
11 #include "base/logging.h"
12 #include "base/memory/ptr_util.h"
13 
14 // static
Create(const CefString & name)15 CefRefPtr<CefProcessMessage> CefProcessMessage::Create(const CefString& name) {
16   return new CefProcessMessageImpl(name, CefListValue::Create());
17 }
18 
CefProcessMessageImpl(const CefString & name,CefRefPtr<CefListValue> arguments)19 CefProcessMessageImpl::CefProcessMessageImpl(const CefString& name,
20                                              CefRefPtr<CefListValue> arguments)
21     : name_(name), arguments_(arguments) {
22   DCHECK(!name_.empty());
23   DCHECK(arguments_ && arguments_->IsValid());
24 }
25 
CefProcessMessageImpl(const CefString & name,base::ListValue arguments,bool read_only)26 CefProcessMessageImpl::CefProcessMessageImpl(const CefString& name,
27                                              base::ListValue arguments,
28                                              bool read_only)
29     : name_(name) {
30   DCHECK(!name_.empty());
31 
32   auto new_obj = std::make_unique<base::ListValue>();
33   *new_obj = std::move(arguments);
34   arguments_ =
35       new CefListValueImpl(new_obj.release(), /*will_delete=*/true, read_only);
36 }
37 
38 CefProcessMessageImpl::~CefProcessMessageImpl() = default;
39 
TakeArgumentList()40 base::ListValue CefProcessMessageImpl::TakeArgumentList() {
41   DCHECK(IsValid());
42   CefListValueImpl* value_impl =
43       static_cast<CefListValueImpl*>(arguments_.get());
44   auto value = base::WrapUnique(value_impl->CopyOrDetachValue(nullptr));
45   return std::move(*value);
46 }
47 
IsValid()48 bool CefProcessMessageImpl::IsValid() {
49   return arguments_->IsValid();
50 }
51 
IsReadOnly()52 bool CefProcessMessageImpl::IsReadOnly() {
53   return arguments_->IsReadOnly();
54 }
55 
Copy()56 CefRefPtr<CefProcessMessage> CefProcessMessageImpl::Copy() {
57   if (!IsValid())
58     return nullptr;
59   return new CefProcessMessageImpl(name_, arguments_->Copy());
60 }
61 
GetName()62 CefString CefProcessMessageImpl::GetName() {
63   return name_;
64 }
65 
GetArgumentList()66 CefRefPtr<CefListValue> CefProcessMessageImpl::GetArgumentList() {
67   return arguments_;
68 }
69