2012-04-03 03:34:16 +02:00
|
|
|
// Copyright (c) 2012 The Chromium Embedded Framework Authors. All rights
|
|
|
|
// reserved. Use of this source code is governed by a BSD-style license that
|
|
|
|
// can be found in the LICENSE file.
|
|
|
|
|
2017-05-17 11:29:28 +02:00
|
|
|
#include "libcef/common/process_message_impl.h"
|
2021-05-20 18:26:36 +02:00
|
|
|
|
|
|
|
#include <memory>
|
|
|
|
|
2012-04-03 03:34:16 +02:00
|
|
|
#include "libcef/common/values_impl.h"
|
|
|
|
|
|
|
|
#include "base/logging.h"
|
2021-05-14 18:58:55 +02:00
|
|
|
#include "base/memory/ptr_util.h"
|
2012-04-03 03:34:16 +02:00
|
|
|
|
2021-05-14 18:58:55 +02:00
|
|
|
// static
|
|
|
|
CefRefPtr<CefProcessMessage> CefProcessMessage::Create(const CefString& name) {
|
|
|
|
return new CefProcessMessageImpl(name, CefListValue::Create());
|
|
|
|
}
|
2012-04-03 03:34:16 +02:00
|
|
|
|
2021-05-14 18:58:55 +02:00
|
|
|
CefProcessMessageImpl::CefProcessMessageImpl(const CefString& name,
|
|
|
|
CefRefPtr<CefListValue> arguments)
|
|
|
|
: name_(name), arguments_(arguments) {
|
|
|
|
DCHECK(!name_.empty());
|
2021-05-20 18:26:36 +02:00
|
|
|
DCHECK(arguments_ && arguments_->IsValid());
|
2012-04-03 03:34:16 +02:00
|
|
|
}
|
|
|
|
|
2021-05-14 18:58:55 +02:00
|
|
|
CefProcessMessageImpl::CefProcessMessageImpl(const CefString& name,
|
2021-05-20 18:26:36 +02:00
|
|
|
base::ListValue arguments,
|
2021-05-14 18:58:55 +02:00
|
|
|
bool read_only)
|
2021-05-20 18:26:36 +02:00
|
|
|
: name_(name) {
|
2021-05-14 18:58:55 +02:00
|
|
|
DCHECK(!name_.empty());
|
2012-04-03 03:34:16 +02:00
|
|
|
|
2021-05-20 18:26:36 +02:00
|
|
|
auto new_obj = std::make_unique<base::ListValue>();
|
|
|
|
*new_obj = std::move(arguments);
|
|
|
|
arguments_ =
|
|
|
|
new CefListValueImpl(new_obj.release(), /*will_delete=*/true, read_only);
|
2012-04-03 03:34:16 +02:00
|
|
|
}
|
|
|
|
|
2021-05-20 18:26:36 +02:00
|
|
|
CefProcessMessageImpl::~CefProcessMessageImpl() = default;
|
2012-04-03 03:34:16 +02:00
|
|
|
|
2021-05-14 18:58:55 +02:00
|
|
|
base::ListValue CefProcessMessageImpl::TakeArgumentList() {
|
|
|
|
DCHECK(IsValid());
|
|
|
|
CefListValueImpl* value_impl =
|
|
|
|
static_cast<CefListValueImpl*>(arguments_.get());
|
|
|
|
auto value = base::WrapUnique(value_impl->CopyOrDetachValue(nullptr));
|
|
|
|
return std::move(*value);
|
2012-04-03 03:34:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
bool CefProcessMessageImpl::IsValid() {
|
2021-05-14 18:58:55 +02:00
|
|
|
return arguments_->IsValid();
|
2012-04-03 03:34:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
bool CefProcessMessageImpl::IsReadOnly() {
|
2021-05-14 18:58:55 +02:00
|
|
|
return arguments_->IsReadOnly();
|
2012-04-03 03:34:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
CefRefPtr<CefProcessMessage> CefProcessMessageImpl::Copy() {
|
2021-05-14 18:58:55 +02:00
|
|
|
if (!IsValid())
|
|
|
|
return nullptr;
|
|
|
|
return new CefProcessMessageImpl(name_, arguments_->Copy());
|
2012-04-03 03:34:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
CefString CefProcessMessageImpl::GetName() {
|
2021-05-14 18:58:55 +02:00
|
|
|
return name_;
|
2012-04-03 03:34:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
CefRefPtr<CefListValue> CefProcessMessageImpl::GetArgumentList() {
|
2021-05-14 18:58:55 +02:00
|
|
|
return arguments_;
|
2012-04-03 03:34:16 +02:00
|
|
|
}
|