| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/renderer/extensions/messaging_bindings.h" | 5 #include "chrome/renderer/extensions/messaging_bindings.h" |
| 6 | 6 |
| 7 #include <map> | 7 #include <map> |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 111 if (!HasPortData(port_id)) { | 111 if (!HasPortData(port_id)) { |
| 112 v8::ThrowException(v8::Exception::Error( | 112 v8::ThrowException(v8::Exception::Error( |
| 113 v8::String::New(kPortClosedError))); | 113 v8::String::New(kPortClosedError))); |
| 114 return; | 114 return; |
| 115 } | 115 } |
| 116 | 116 |
| 117 renderview->Send(new ExtensionHostMsg_PostMessage( | 117 renderview->Send(new ExtensionHostMsg_PostMessage( |
| 118 renderview->GetRoutingID(), port_id, | 118 renderview->GetRoutingID(), port_id, |
| 119 extensions::Message( | 119 extensions::Message( |
| 120 *v8::String::AsciiValue(args[1]), | 120 *v8::String::AsciiValue(args[1]), |
| 121 WebKit::WebUserGestureIndicator::isProcessingUserGesture()))); | 121 blink::WebUserGestureIndicator::isProcessingUserGesture()))); |
| 122 } | 122 } |
| 123 | 123 |
| 124 // Forcefully disconnects a port. | 124 // Forcefully disconnects a port. |
| 125 void CloseChannel(const v8::FunctionCallbackInfo<v8::Value>& args) { | 125 void CloseChannel(const v8::FunctionCallbackInfo<v8::Value>& args) { |
| 126 // Arguments are (int32 port_id, boolean notify_browser). | 126 // Arguments are (int32 port_id, boolean notify_browser). |
| 127 CHECK_EQ(2, args.Length()); | 127 CHECK_EQ(2, args.Length()); |
| 128 CHECK(args[0]->IsInt32()); | 128 CHECK(args[0]->IsInt32()); |
| 129 CHECK(args[1]->IsBoolean()); | 129 CHECK(args[1]->IsBoolean()); |
| 130 | 130 |
| 131 int port_id = args[0]->Int32Value(); | 131 int port_id = args[0]->Int32Value(); |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 197 v8::Isolate* isolate) | 197 v8::Isolate* isolate) |
| 198 : object_(object), callback_(callback), isolate_(isolate) {} | 198 : object_(object), callback_(callback), isolate_(isolate) {} |
| 199 | 199 |
| 200 void RunCallback() { | 200 void RunCallback() { |
| 201 v8::HandleScope handle_scope(isolate_); | 201 v8::HandleScope handle_scope(isolate_); |
| 202 v8::Handle<v8::Function> callback = callback_.NewHandle(isolate_); | 202 v8::Handle<v8::Function> callback = callback_.NewHandle(isolate_); |
| 203 v8::Handle<v8::Context> context = callback->CreationContext(); | 203 v8::Handle<v8::Context> context = callback->CreationContext(); |
| 204 if (context.IsEmpty()) | 204 if (context.IsEmpty()) |
| 205 return; | 205 return; |
| 206 v8::Context::Scope context_scope(context); | 206 v8::Context::Scope context_scope(context); |
| 207 WebKit::WebScopedMicrotaskSuppression suppression; | 207 blink::WebScopedMicrotaskSuppression suppression; |
| 208 callback->Call(context->Global(), 0, NULL); | 208 callback->Call(context->Global(), 0, NULL); |
| 209 } | 209 } |
| 210 | 210 |
| 211 extensions::ScopedPersistent<v8::Object> object_; | 211 extensions::ScopedPersistent<v8::Object> object_; |
| 212 extensions::ScopedPersistent<v8::Function> callback_; | 212 extensions::ScopedPersistent<v8::Function> callback_; |
| 213 v8::Isolate* isolate_; | 213 v8::Isolate* isolate_; |
| 214 | 214 |
| 215 DISALLOW_COPY_AND_ASSIGN(GCCallback); | 215 DISALLOW_COPY_AND_ASSIGN(GCCallback); |
| 216 }; | 216 }; |
| 217 | 217 |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 315 target_port_id, kReceivingEndDoesntExistError)); | 315 target_port_id, kReceivingEndDoesntExistError)); |
| 316 } | 316 } |
| 317 } | 317 } |
| 318 | 318 |
| 319 // static | 319 // static |
| 320 void MessagingBindings::DeliverMessage( | 320 void MessagingBindings::DeliverMessage( |
| 321 const ChromeV8ContextSet::ContextSet& contexts, | 321 const ChromeV8ContextSet::ContextSet& contexts, |
| 322 int target_port_id, | 322 int target_port_id, |
| 323 const Message& message, | 323 const Message& message, |
| 324 content::RenderView* restrict_to_render_view) { | 324 content::RenderView* restrict_to_render_view) { |
| 325 scoped_ptr<WebKit::WebScopedUserGesture> web_user_gesture; | 325 scoped_ptr<blink::WebScopedUserGesture> web_user_gesture; |
| 326 if (message.user_gesture) | 326 if (message.user_gesture) |
| 327 web_user_gesture.reset(new WebKit::WebScopedUserGesture); | 327 web_user_gesture.reset(new blink::WebScopedUserGesture); |
| 328 | 328 |
| 329 v8::HandleScope handle_scope(v8::Isolate::GetCurrent()); | 329 v8::HandleScope handle_scope(v8::Isolate::GetCurrent()); |
| 330 | 330 |
| 331 // TODO(kalman): pass in the full ChromeV8ContextSet; call ForEach. | 331 // TODO(kalman): pass in the full ChromeV8ContextSet; call ForEach. |
| 332 for (ChromeV8ContextSet::ContextSet::const_iterator it = contexts.begin(); | 332 for (ChromeV8ContextSet::ContextSet::const_iterator it = contexts.begin(); |
| 333 it != contexts.end(); ++it) { | 333 it != contexts.end(); ++it) { |
| 334 if (restrict_to_render_view && | 334 if (restrict_to_render_view && |
| 335 restrict_to_render_view != (*it)->GetRenderView()) { | 335 restrict_to_render_view != (*it)->GetRenderView()) { |
| 336 continue; | 336 continue; |
| 337 } | 337 } |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 389 } else { | 389 } else { |
| 390 arguments.push_back(v8::Null()); | 390 arguments.push_back(v8::Null()); |
| 391 } | 391 } |
| 392 (*it)->module_system()->CallModuleMethod("messaging", | 392 (*it)->module_system()->CallModuleMethod("messaging", |
| 393 "dispatchOnDisconnect", | 393 "dispatchOnDisconnect", |
| 394 &arguments); | 394 &arguments); |
| 395 } | 395 } |
| 396 } | 396 } |
| 397 | 397 |
| 398 } // namespace extensions | 398 } // namespace extensions |
| OLD | NEW |