#ifdef UNSAFE_BUFFERS_BUILD
#pragma allow_unsafe_buffers
#endif
#include "chrome/browser/extensions/api/messaging/native_message_process_host.h"
#include <stddef.h>
#include <stdint.h>
#include <memory>
#include <utility>
#include "base/files/file_path.h"
#include "base/functional/bind.h"
#include "base/logging.h"
#include "base/process/kill.h"
#include "base/task/single_thread_task_runner.h"
#include "base/task/thread_pool.h"
#include "build/build_config.h"
#include "chrome/browser/extensions/api/messaging/native_messaging_host_manifest.h"
#include "chrome/browser/extensions/api/messaging/native_messaging_launch_from_native.h"
#include "chrome/browser/extensions/api/messaging/native_process_launcher.h"
#include "chrome/browser/profiles/profile.h"
#include "content/public/browser/browser_context.h"
#include "content/public/browser/browser_task_traits.h"
#include "content/public/browser/browser_thread.h"
#include "extensions/common/constants.h"
#include "extensions/common/extension_id.h"
#include "extensions/common/features/feature.h"
#include "net/base/file_stream.h"
#include "net/base/io_buffer.h"
#include "net/base/net_errors.h"
#include "url/gurl.h"
namespace {
const size_t kMaximumNativeMessageSize = …;
const size_t kMessageHeaderSize = …;
const size_t kReadBufferSize = …;
base::FilePath GetProfilePathIfEnabled(
Profile* profile,
const extensions::ExtensionId& extension_id,
const std::string& host_id) { … }
}
namespace extensions {
NativeMessageProcessHost::NativeMessageProcessHost(
const ExtensionId& source_extension_id,
const std::string& native_host_name,
std::unique_ptr<NativeProcessLauncher> launcher)
: … { … }
NativeMessageProcessHost::~NativeMessageProcessHost() { … }
std::unique_ptr<NativeMessageHost> NativeMessageHost::Create(
content::BrowserContext* browser_context,
gfx::NativeView native_view,
const ExtensionId& source_extension_id,
const std::string& native_host_name,
bool allow_user_level,
std::string* error_message) { … }
std::unique_ptr<NativeMessageHost> NativeMessageProcessHost::CreateWithLauncher(
const ExtensionId& source_extension_id,
const std::string& native_host_name,
std::unique_ptr<NativeProcessLauncher> launcher) { … }
void NativeMessageProcessHost::LaunchHostProcess() { … }
void NativeMessageProcessHost::OnHostProcessLaunched(
NativeProcessLauncher::LaunchResult result,
base::Process process,
base::PlatformFile read_file,
std::unique_ptr<net::FileStream> read_stream,
std::unique_ptr<net::FileStream> write_stream) { … }
void NativeMessageProcessHost::OnMessage(const std::string& json) { … }
void NativeMessageProcessHost::Start(Client* client) { … }
scoped_refptr<base::SingleThreadTaskRunner>
NativeMessageProcessHost::task_runner() const { … }
void NativeMessageProcessHost::WaitRead() { … }
void NativeMessageProcessHost::DoRead() { … }
void NativeMessageProcessHost::OnRead(int result) { … }
void NativeMessageProcessHost::HandleReadResult(int result) { … }
void NativeMessageProcessHost::ProcessIncomingData(
const char* data, int data_size) { … }
void NativeMessageProcessHost::DoWrite() { … }
void NativeMessageProcessHost::HandleWriteResult(int result) { … }
void NativeMessageProcessHost::OnWritten(int result) { … }
void NativeMessageProcessHost::Close(const std::string& error_message) { … }
}