Index: extensions/renderer/messaging_bindings.cc |
diff --git a/extensions/renderer/messaging_bindings.cc b/extensions/renderer/messaging_bindings.cc |
index 595bee1b600e7229871c148feab9b0d8c90d1aaa..3aaa5ba8610c0c6df1e6993da4184ab885bc06f4 100644 |
--- a/extensions/renderer/messaging_bindings.cc |
+++ b/extensions/renderer/messaging_bindings.cc |
@@ -28,6 +28,7 @@ |
#include "extensions/renderer/object_backed_native_handler.h" |
#include "extensions/renderer/script_context.h" |
#include "extensions/renderer/script_context_set.h" |
+#include "extensions/renderer/v8_maybe_helpers.h" |
#include "third_party/WebKit/public/web/WebDocument.h" |
#include "third_party/WebKit/public/web/WebLocalFrame.h" |
#include "third_party/WebKit/public/web/WebScopedMicrotaskSuppression.h" |
@@ -186,10 +187,11 @@ class ExtensionImpl : public ObjectBackedNativeHandler { |
// Arguments are (int32 port_id, string message). |
CHECK(args.Length() == 2 && args[0]->IsInt32() && args[1]->IsString()); |
- int port_id = args[0]->Int32Value(); |
+ int port_id = args[0].As<v8::Int32>()->Value(); |
if (!HasPortData(port_id)) { |
- args.GetIsolate()->ThrowException(v8::Exception::Error( |
- v8::String::NewFromUtf8(args.GetIsolate(), kPortClosedError))); |
+ v8::Local<v8::String> error_message = |
+ ToV8String(args.GetIsolate(), kPortClosedError); |
+ args.GetIsolate()->ThrowException(v8::Exception::Error(error_message)); |
return; |
} |
@@ -206,12 +208,12 @@ class ExtensionImpl : public ObjectBackedNativeHandler { |
CHECK(args[0]->IsInt32()); |
CHECK(args[1]->IsBoolean()); |
- int port_id = args[0]->Int32Value(); |
+ int port_id = args[0].As<v8::Int32>()->Value(); |
if (!HasPortData(port_id)) |
return; |
// Send via the RenderThread because the RenderFrame might be closing. |
- bool notify_browser = args[1]->BooleanValue(); |
+ bool notify_browser = args[1].As<v8::Boolean>()->Value(); |
if (notify_browser) { |
content::RenderThread::Get()->Send( |
new ExtensionHostMsg_CloseChannel(port_id, std::string())); |
@@ -227,7 +229,7 @@ class ExtensionImpl : public ObjectBackedNativeHandler { |
CHECK_EQ(1, args.Length()); |
CHECK(args[0]->IsInt32()); |
- int port_id = args[0]->Int32Value(); |
+ int port_id = args[0].As<v8::Int32>()->Value(); |
++GetPortData(port_id).ref_count; |
} |
@@ -237,7 +239,7 @@ class ExtensionImpl : public ObjectBackedNativeHandler { |
void PortRelease(const v8::FunctionCallbackInfo<v8::Value>& args) { |
// Arguments are (int32 port_id). |
CHECK(args.Length() == 1 && args[0]->IsInt32()); |
- ReleasePort(args[0]->Int32Value()); |
+ ReleasePort(args[0].As<v8::Int32>()->Value()); |
} |
// Implementation of both the PortRelease native handler call, and callback |
@@ -263,7 +265,7 @@ class ExtensionImpl : public ObjectBackedNativeHandler { |
void BindToGC(const v8::FunctionCallbackInfo<v8::Value>& args) { |
CHECK(args.Length() == 3 && args[0]->IsObject() && args[1]->IsFunction() && |
args[2]->IsInt32()); |
- int port_id = args[2]->Int32Value(); |
+ int port_id = args[2].As<v8::Int32>()->Value(); |
base::Closure fallback = base::Bind(&base::DoNothing); |
if (port_id >= 0) { |
fallback = base::Bind(&ExtensionImpl::ReleasePort, |
@@ -316,23 +318,29 @@ void DispatchOnConnectToScriptContext( |
ExternallyConnectableInfo* externally_connectable = |
ExternallyConnectableInfo::Get(extension); |
if (externally_connectable && |
- externally_connectable->accepts_tls_channel_id) { |
- tls_channel_id_value = v8::String::NewFromUtf8(isolate, |
- tls_channel_id.c_str(), |
- v8::String::kNormalString, |
- tls_channel_id.size()); |
+ externally_connectable->accepts_tls_channel_id && |
+ tls_channel_id.size() < v8::String::kMaxLength) { |
+ tls_channel_id_value = |
+ ToV8String(isolate, tls_channel_id.c_str()); |
} |
if (info.guest_process_id != content::ChildProcessHost::kInvalidUniqueID) |
guest_process_id = v8::Integer::New(isolate, info.guest_process_id); |
} |
+ if (channel_name.size() >= v8::String::kMaxLength || |
+ info.source_id.size() >= v8::String::kMaxLength || |
+ target_extension_id.size() >= v8::String::kMaxLength || |
+ source_url_spec.size() >= v8::String::kMaxLength) { |
+ LOG(ERROR) << "Failed to execute dispatchOnConnect."; |
+ return; |
+ } |
+ |
v8::Local<v8::Value> arguments[] = { |
// portId |
v8::Integer::New(isolate, target_port_id), |
// channelName |
- v8::String::NewFromUtf8(isolate, channel_name.c_str(), |
- v8::String::kNormalString, channel_name.size()), |
+ ToV8String(isolate, channel_name.c_str()), |
// sourceTab |
tab, |
// source_frame_id |
@@ -340,16 +348,11 @@ void DispatchOnConnectToScriptContext( |
// guestProcessId |
guest_process_id, |
// sourceExtensionId |
- v8::String::NewFromUtf8(isolate, info.source_id.c_str(), |
- v8::String::kNormalString, info.source_id.size()), |
+ ToV8String(isolate, info.source_id.c_str()), |
// targetExtensionId |
- v8::String::NewFromUtf8(isolate, target_extension_id.c_str(), |
- v8::String::kNormalString, |
- target_extension_id.size()), |
+ ToV8String(isolate, target_extension_id.c_str()), |
// sourceUrl |
- v8::String::NewFromUtf8(isolate, source_url_spec.c_str(), |
- v8::String::kNormalString, |
- source_url_spec.size()), |
+ ToV8String(isolate, source_url_spec.c_str()), |
// tlsChannelId |
tls_channel_id_value, |
}; |
@@ -360,7 +363,7 @@ void DispatchOnConnectToScriptContext( |
if (!retval.IsEmpty()) { |
CHECK(retval->IsBoolean()); |
- *port_created |= retval->BooleanValue(); |
+ *port_created |= retval.As<v8::Boolean>()->Value(); |
} else { |
LOG(ERROR) << "Empty return value from dispatchOnConnect."; |
} |
@@ -381,14 +384,13 @@ void DeliverMessageToScriptContext(const Message& message, |
1, &port_id_handle); |
CHECK(!has_port.IsEmpty()); |
- if (!has_port->BooleanValue()) |
+ if (!has_port->IsBoolean() || !has_port.As<v8::Boolean>()->Value()) |
return; |
+ if (message.data.size() >= v8::String::kMaxLength) |
+ return; |
std::vector<v8::Local<v8::Value>> arguments; |
- arguments.push_back(v8::String::NewFromUtf8(isolate, |
- message.data.c_str(), |
- v8::String::kNormalString, |
- message.data.size())); |
+ arguments.push_back(ToV8String(isolate, message.data.c_str())); |
arguments.push_back(port_id_handle); |
scoped_ptr<blink::WebScopedUserGesture> web_user_gesture; |
@@ -417,7 +419,7 @@ void DispatchOnDisconnectToScriptContext(int port_id, |
arguments.push_back(v8::Integer::New(isolate, port_id)); |
if (!error_message.empty()) { |
arguments.push_back( |
- v8::String::NewFromUtf8(isolate, error_message.c_str())); |
+ ToV8String(isolate, error_message.c_str())); |
} else { |
arguments.push_back(v8::Null(isolate)); |
} |