#include "extensions/renderer/api/messaging/messaging_util.h"
#include <string>
#include "base/check.h"
#include "base/notreached.h"
#include "base/strings/stringprintf.h"
#include "components/crx_file/id_util.h"
#include "extensions/common/api/messaging/message.h"
#include "extensions/common/api/messaging/messaging_endpoint.h"
#include "extensions/common/extension.h"
#include "extensions/common/extension_features.h"
#include "extensions/common/manifest.h"
#include "extensions/common/manifest_handlers/background_info.h"
#include "extensions/common/mojom/context_type.mojom.h"
#include "extensions/common/mojom/message_port.mojom-shared.h"
#include "extensions/renderer/extension_interaction_provider.h"
#include "extensions/renderer/get_script_context.h"
#include "extensions/renderer/script_context.h"
#include "extensions/renderer/worker_thread_util.h"
#include "gin/converter.h"
#include "gin/dictionary.h"
#include "third_party/blink/public/web/web_local_frame.h"
#include "v8/include/v8-context.h"
#include "v8/include/v8-exception.h"
#include "v8/include/v8-json.h"
#include "v8/include/v8-object.h"
#include "v8/include/v8-primitive.h"
namespace extensions {
namespace messaging_util {
namespace {
constexpr char kExtensionIdRequiredErrorTemplate[] = …;
constexpr char kErrorCouldNotSerialize[] = …;
constexpr char kErrorMalformedJSONMessage[] = …;
std::unique_ptr<Message> MessageFromJSONString(v8::Isolate* isolate,
v8::Local<v8::Context> context,
v8::Local<v8::String> json,
std::string* error_out,
blink::WebLocalFrame* web_frame,
bool privileged_context) { … }
}
const char kSendMessageChannel[] = …;
const char kSendRequestChannel[] = …;
const char kOnMessageEvent[] = …;
const char kOnUserScriptMessageEvent[] = …;
const char kOnMessageExternalEvent[] = …;
const char kOnRequestEvent[] = …;
const char kOnRequestExternalEvent[] = …;
const char kOnConnectEvent[] = …;
const char kOnUserScriptConnectEvent[] = …;
const char kOnConnectExternalEvent[] = …;
const char kOnConnectNativeEvent[] = …;
const int kNoFrameId = …;
std::unique_ptr<Message> MessageFromV8(v8::Local<v8::Context> context,
v8::Local<v8::Value> value,
mojom::SerializationFormat format,
std::string* error_out) { … }
v8::Local<v8::Value> MessageToV8(v8::Local<v8::Context> context,
const Message& message,
bool is_parsing_fail_safe,
std::string* error) { … }
int ExtractIntegerId(v8::Local<v8::Value> value) { … }
mojom::SerializationFormat GetSerializationFormat(
const ScriptContext& script_context) { … }
MessageOptions ParseMessageOptions(v8::Local<v8::Context> context,
v8::Local<v8::Object> v8_options,
int flags) { … }
bool GetTargetExtensionId(ScriptContext* script_context,
v8::Local<v8::Value> v8_target_id,
const char* method_name,
std::string* target_out,
std::string* error_out) { … }
void MassageSendMessageArguments(v8::Isolate* isolate,
bool allow_options_argument,
v8::LocalVector<v8::Value>* arguments_out) { … }
bool IsSendRequestDisabled(ScriptContext* script_context) { … }
std::string GetEventForChannel(const MessagingEndpoint& source_endpoint,
const ExtensionId& target_extension_id,
mojom::ChannelType channel_type) { … }
}
}