| 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 13 matching lines...) Expand all Loading... |
| 24 #include "content/public/renderer/v8_value_converter.h" | 24 #include "content/public/renderer/v8_value_converter.h" |
| 25 #include "extensions/common/api/messaging/message.h" | 25 #include "extensions/common/api/messaging/message.h" |
| 26 #include "extensions/common/extension_messages.h" | 26 #include "extensions/common/extension_messages.h" |
| 27 #include "extensions/renderer/event_bindings.h" | 27 #include "extensions/renderer/event_bindings.h" |
| 28 #include "extensions/renderer/scoped_persistent.h" | 28 #include "extensions/renderer/scoped_persistent.h" |
| 29 #include "grit/renderer_resources.h" | 29 #include "grit/renderer_resources.h" |
| 30 #include "third_party/WebKit/public/web/WebScopedMicrotaskSuppression.h" | 30 #include "third_party/WebKit/public/web/WebScopedMicrotaskSuppression.h" |
| 31 #include "third_party/WebKit/public/web/WebScopedUserGesture.h" | 31 #include "third_party/WebKit/public/web/WebScopedUserGesture.h" |
| 32 #include "third_party/WebKit/public/web/WebScopedWindowFocusAllowedIndicator.h" | 32 #include "third_party/WebKit/public/web/WebScopedWindowFocusAllowedIndicator.h" |
| 33 #include "third_party/WebKit/public/web/WebUserGestureIndicator.h" | 33 #include "third_party/WebKit/public/web/WebUserGestureIndicator.h" |
| 34 #include "third_party/WebKit/public/web/WebUserGestureToken.h" |
| 34 #include "v8/include/v8.h" | 35 #include "v8/include/v8.h" |
| 35 | 36 |
| 36 // Message passing API example (in a content script): | 37 // Message passing API example (in a content script): |
| 37 // var extension = | 38 // var extension = |
| 38 // new chrome.Extension('00123456789abcdef0123456789abcdef0123456'); | 39 // new chrome.Extension('00123456789abcdef0123456789abcdef0123456'); |
| 39 // var port = runtime.connect(); | 40 // var port = runtime.connect(); |
| 40 // port.postMessage('Can you hear me now?'); | 41 // port.postMessage('Can you hear me now?'); |
| 41 // port.onmessage.addListener(function(msg, port) { | 42 // port.onmessage.addListener(function(msg, port) { |
| 42 // alert('response=' + msg); | 43 // alert('response=' + msg); |
| 43 // port.postMessage('I got your reponse'); | 44 // port.postMessage('I got your reponse'); |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 113 args[0]->IsInt32() && | 114 args[0]->IsInt32() && |
| 114 args[1]->IsString()); | 115 args[1]->IsString()); |
| 115 | 116 |
| 116 int port_id = args[0]->Int32Value(); | 117 int port_id = args[0]->Int32Value(); |
| 117 if (!HasPortData(port_id)) { | 118 if (!HasPortData(port_id)) { |
| 118 args.GetIsolate()->ThrowException(v8::Exception::Error( | 119 args.GetIsolate()->ThrowException(v8::Exception::Error( |
| 119 v8::String::NewFromUtf8(args.GetIsolate(), kPortClosedError))); | 120 v8::String::NewFromUtf8(args.GetIsolate(), kPortClosedError))); |
| 120 return; | 121 return; |
| 121 } | 122 } |
| 122 | 123 |
| 124 bool user_gesture = |
| 125 blink::WebUserGestureIndicator::isProcessingUserGesture(); |
| 126 double user_gesture_timestamp = 0.0; |
| 127 if (user_gesture) { |
| 128 user_gesture_timestamp = |
| 129 blink::WebUserGestureIndicator::currentUserGestureToken().timestamp(); |
| 130 } |
| 123 renderview->Send(new ExtensionHostMsg_PostMessage( | 131 renderview->Send(new ExtensionHostMsg_PostMessage( |
| 124 renderview->GetRoutingID(), port_id, | 132 renderview->GetRoutingID(), |
| 133 port_id, |
| 125 Message(*v8::String::Utf8Value(args[1]), | 134 Message(*v8::String::Utf8Value(args[1]), |
| 126 blink::WebUserGestureIndicator::isProcessingUserGesture()))); | 135 user_gesture, |
| 136 user_gesture_timestamp))); |
| 127 } | 137 } |
| 128 | 138 |
| 129 // Forcefully disconnects a port. | 139 // Forcefully disconnects a port. |
| 130 void CloseChannel(const v8::FunctionCallbackInfo<v8::Value>& args) { | 140 void CloseChannel(const v8::FunctionCallbackInfo<v8::Value>& args) { |
| 131 // Arguments are (int32 port_id, boolean notify_browser). | 141 // Arguments are (int32 port_id, boolean notify_browser). |
| 132 CHECK_EQ(2, args.Length()); | 142 CHECK_EQ(2, args.Length()); |
| 133 CHECK(args[0]->IsInt32()); | 143 CHECK(args[0]->IsInt32()); |
| 134 CHECK(args[1]->IsBoolean()); | 144 CHECK(args[1]->IsBoolean()); |
| 135 | 145 |
| 136 int port_id = args[0]->Int32Value(); | 146 int port_id = args[0]->Int32Value(); |
| (...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 346 | 356 |
| 347 // static | 357 // static |
| 348 void MessagingBindings::DeliverMessage( | 358 void MessagingBindings::DeliverMessage( |
| 349 const ChromeV8ContextSet::ContextSet& contexts, | 359 const ChromeV8ContextSet::ContextSet& contexts, |
| 350 int target_port_id, | 360 int target_port_id, |
| 351 const Message& message, | 361 const Message& message, |
| 352 content::RenderView* restrict_to_render_view) { | 362 content::RenderView* restrict_to_render_view) { |
| 353 scoped_ptr<blink::WebScopedUserGesture> web_user_gesture; | 363 scoped_ptr<blink::WebScopedUserGesture> web_user_gesture; |
| 354 scoped_ptr<blink::WebScopedWindowFocusAllowedIndicator> allow_window_focus; | 364 scoped_ptr<blink::WebScopedWindowFocusAllowedIndicator> allow_window_focus; |
| 355 if (message.user_gesture) { | 365 if (message.user_gesture) { |
| 356 web_user_gesture.reset(new blink::WebScopedUserGesture); | 366 web_user_gesture.reset( |
| 357 allow_window_focus.reset(new blink::WebScopedWindowFocusAllowedIndicator); | 367 new blink::WebScopedUserGesture(message.user_gesture_timestamp)); |
| 368 if (blink::WebUserGestureIndicator::isProcessingUserGesture()) { |
| 369 allow_window_focus.reset(new blink::WebScopedWindowFocusAllowedIndicator); |
| 370 } |
| 358 } | 371 } |
| 359 | 372 |
| 360 v8::Isolate* isolate = v8::Isolate::GetCurrent(); | 373 v8::Isolate* isolate = v8::Isolate::GetCurrent(); |
| 361 v8::HandleScope handle_scope(isolate); | 374 v8::HandleScope handle_scope(isolate); |
| 362 | 375 |
| 363 // TODO(kalman): pass in the full ChromeV8ContextSet; call ForEach. | 376 // TODO(kalman): pass in the full ChromeV8ContextSet; call ForEach. |
| 364 for (ChromeV8ContextSet::ContextSet::const_iterator it = contexts.begin(); | 377 for (ChromeV8ContextSet::ContextSet::const_iterator it = contexts.begin(); |
| 365 it != contexts.end(); ++it) { | 378 it != contexts.end(); ++it) { |
| 366 if (restrict_to_render_view && | 379 if (restrict_to_render_view && |
| 367 restrict_to_render_view != (*it)->GetRenderView()) { | 380 restrict_to_render_view != (*it)->GetRenderView()) { |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 426 } else { | 439 } else { |
| 427 arguments.push_back(v8::Null(isolate)); | 440 arguments.push_back(v8::Null(isolate)); |
| 428 } | 441 } |
| 429 (*it)->module_system()->CallModuleMethod("messaging", | 442 (*it)->module_system()->CallModuleMethod("messaging", |
| 430 "dispatchOnDisconnect", | 443 "dispatchOnDisconnect", |
| 431 &arguments); | 444 &arguments); |
| 432 } | 445 } |
| 433 } | 446 } |
| 434 | 447 |
| 435 } // namespace extensions | 448 } // namespace extensions |
| OLD | NEW |