Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(39)

Side by Side Diff: chrome/renderer/extensions/messaging_bindings.cc

Issue 256623008: Mark forwarded user gestures as forwarded, and don't forward already forwarded user gestures. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: test Created 6 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chrome/browser/extensions/extension_messages_apitest.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 12 matching lines...) Expand all
23 #include "extensions/common/extension_messages.h" 23 #include "extensions/common/extension_messages.h"
24 #include "extensions/renderer/event_bindings.h" 24 #include "extensions/renderer/event_bindings.h"
25 #include "extensions/renderer/object_backed_native_handler.h" 25 #include "extensions/renderer/object_backed_native_handler.h"
26 #include "extensions/renderer/scoped_persistent.h" 26 #include "extensions/renderer/scoped_persistent.h"
27 #include "extensions/renderer/script_context.h" 27 #include "extensions/renderer/script_context.h"
28 #include "extensions/renderer/script_context_set.h" 28 #include "extensions/renderer/script_context_set.h"
29 #include "third_party/WebKit/public/web/WebScopedMicrotaskSuppression.h" 29 #include "third_party/WebKit/public/web/WebScopedMicrotaskSuppression.h"
30 #include "third_party/WebKit/public/web/WebScopedUserGesture.h" 30 #include "third_party/WebKit/public/web/WebScopedUserGesture.h"
31 #include "third_party/WebKit/public/web/WebScopedWindowFocusAllowedIndicator.h" 31 #include "third_party/WebKit/public/web/WebScopedWindowFocusAllowedIndicator.h"
32 #include "third_party/WebKit/public/web/WebUserGestureIndicator.h" 32 #include "third_party/WebKit/public/web/WebUserGestureIndicator.h"
33 #include "third_party/WebKit/public/web/WebUserGestureToken.h"
33 #include "v8/include/v8.h" 34 #include "v8/include/v8.h"
34 35
35 // Message passing API example (in a content script): 36 // Message passing API example (in a content script):
36 // var extension = 37 // var extension =
37 // new chrome.Extension('00123456789abcdef0123456789abcdef0123456'); 38 // new chrome.Extension('00123456789abcdef0123456789abcdef0123456');
38 // var port = runtime.connect(); 39 // var port = runtime.connect();
39 // port.postMessage('Can you hear me now?'); 40 // port.postMessage('Can you hear me now?');
40 // port.onmessage.addListener(function(msg, port) { 41 // port.onmessage.addListener(function(msg, port) {
41 // alert('response=' + msg); 42 // alert('response=' + msg);
42 // port.postMessage('I got your reponse'); 43 // port.postMessage('I got your reponse');
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
95 } 96 }
96 97
97 virtual ~ExtensionImpl() {} 98 virtual ~ExtensionImpl() {}
98 99
99 private: 100 private:
100 void ClearPortDataAndNotifyDispatcher(int port_id) { 101 void ClearPortDataAndNotifyDispatcher(int port_id) {
101 ClearPortData(port_id); 102 ClearPortData(port_id);
102 dispatcher_->ClearPortData(port_id); 103 dispatcher_->ClearPortData(port_id);
103 } 104 }
104 105
106 bool ShouldForwardUserGesture() {
107 return blink::WebUserGestureIndicator::isProcessingUserGesture() &&
108 !blink::WebUserGestureIndicator::currentUserGestureToken()
109 .wasForwarded();
110 }
111
105 // Sends a message along the given channel. 112 // Sends a message along the given channel.
106 void PostMessage(const v8::FunctionCallbackInfo<v8::Value>& args) { 113 void PostMessage(const v8::FunctionCallbackInfo<v8::Value>& args) {
107 content::RenderView* renderview = context()->GetRenderView(); 114 content::RenderView* renderview = context()->GetRenderView();
108 if (!renderview) 115 if (!renderview)
109 return; 116 return;
110 117
111 // Arguments are (int32 port_id, string message). 118 // Arguments are (int32 port_id, string message).
112 CHECK(args.Length() == 2 && 119 CHECK(args.Length() == 2 &&
113 args[0]->IsInt32() && 120 args[0]->IsInt32() &&
114 args[1]->IsString()); 121 args[1]->IsString());
115 122
116 int port_id = args[0]->Int32Value(); 123 int port_id = args[0]->Int32Value();
117 if (!HasPortData(port_id)) { 124 if (!HasPortData(port_id)) {
118 args.GetIsolate()->ThrowException(v8::Exception::Error( 125 args.GetIsolate()->ThrowException(v8::Exception::Error(
119 v8::String::NewFromUtf8(args.GetIsolate(), kPortClosedError))); 126 v8::String::NewFromUtf8(args.GetIsolate(), kPortClosedError)));
120 return; 127 return;
121 } 128 }
122 129
123 renderview->Send(new ExtensionHostMsg_PostMessage( 130 renderview->Send(new ExtensionHostMsg_PostMessage(
124 renderview->GetRoutingID(), port_id, 131 renderview->GetRoutingID(),
125 Message(*v8::String::Utf8Value(args[1]), 132 port_id,
126 blink::WebUserGestureIndicator::isProcessingUserGesture()))); 133 Message(*v8::String::Utf8Value(args[1]), ShouldForwardUserGesture())));
127 } 134 }
128 135
129 // Forcefully disconnects a port. 136 // Forcefully disconnects a port.
130 void CloseChannel(const v8::FunctionCallbackInfo<v8::Value>& args) { 137 void CloseChannel(const v8::FunctionCallbackInfo<v8::Value>& args) {
131 // Arguments are (int32 port_id, boolean notify_browser). 138 // Arguments are (int32 port_id, boolean notify_browser).
132 CHECK_EQ(2, args.Length()); 139 CHECK_EQ(2, args.Length());
133 CHECK(args[0]->IsInt32()); 140 CHECK(args[0]->IsInt32());
134 CHECK(args[1]->IsBoolean()); 141 CHECK(args[1]->IsBoolean());
135 142
136 int port_id = args[0]->Int32Value(); 143 int port_id = args[0]->Int32Value();
(...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after
350 // static 357 // static
351 void MessagingBindings::DeliverMessage( 358 void MessagingBindings::DeliverMessage(
352 const ScriptContextSet::ContextSet& contexts, 359 const ScriptContextSet::ContextSet& contexts,
353 int target_port_id, 360 int target_port_id,
354 const Message& message, 361 const Message& message,
355 content::RenderView* restrict_to_render_view) { 362 content::RenderView* restrict_to_render_view) {
356 scoped_ptr<blink::WebScopedUserGesture> web_user_gesture; 363 scoped_ptr<blink::WebScopedUserGesture> web_user_gesture;
357 scoped_ptr<blink::WebScopedWindowFocusAllowedIndicator> allow_window_focus; 364 scoped_ptr<blink::WebScopedWindowFocusAllowedIndicator> allow_window_focus;
358 if (message.user_gesture) { 365 if (message.user_gesture) {
359 web_user_gesture.reset(new blink::WebScopedUserGesture); 366 web_user_gesture.reset(new blink::WebScopedUserGesture);
367 blink::WebUserGestureIndicator::currentUserGestureToken().setForwarded();
360 allow_window_focus.reset(new blink::WebScopedWindowFocusAllowedIndicator); 368 allow_window_focus.reset(new blink::WebScopedWindowFocusAllowedIndicator);
361 } 369 }
362 370
363 v8::Isolate* isolate = v8::Isolate::GetCurrent(); 371 v8::Isolate* isolate = v8::Isolate::GetCurrent();
364 v8::HandleScope handle_scope(isolate); 372 v8::HandleScope handle_scope(isolate);
365 373
366 // TODO(kalman): pass in the full ScriptContextSet; call ForEach. 374 // TODO(kalman): pass in the full ScriptContextSet; call ForEach.
367 for (ScriptContextSet::ContextSet::const_iterator it = contexts.begin(); 375 for (ScriptContextSet::ContextSet::const_iterator it = contexts.begin();
368 it != contexts.end(); 376 it != contexts.end();
369 ++it) { 377 ++it) {
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
431 } else { 439 } else {
432 arguments.push_back(v8::Null(isolate)); 440 arguments.push_back(v8::Null(isolate));
433 } 441 }
434 (*it)->module_system()->CallModuleMethod("messaging", 442 (*it)->module_system()->CallModuleMethod("messaging",
435 "dispatchOnDisconnect", 443 "dispatchOnDisconnect",
436 &arguments); 444 &arguments);
437 } 445 }
438 } 446 }
439 447
440 } // namespace extensions 448 } // namespace extensions
OLDNEW
« no previous file with comments | « chrome/browser/extensions/extension_messages_apitest.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698