OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "extensions/renderer/messaging_bindings.h" | 5 #include "extensions/renderer/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" |
11 #include "base/bind.h" | 11 #include "base/bind.h" |
12 #include "base/bind_helpers.h" | 12 #include "base/bind_helpers.h" |
13 #include "base/lazy_instance.h" | 13 #include "base/lazy_instance.h" |
14 #include "base/message_loop/message_loop.h" | 14 #include "base/message_loop/message_loop.h" |
15 #include "base/values.h" | 15 #include "base/values.h" |
16 #include "content/public/renderer/render_thread.h" | 16 #include "content/public/renderer/render_thread.h" |
17 #include "content/public/renderer/render_view.h" | 17 #include "content/public/renderer/render_view.h" |
18 #include "content/public/renderer/v8_value_converter.h" | 18 #include "content/public/renderer/v8_value_converter.h" |
19 #include "extensions/common/api/messaging/message.h" | 19 #include "extensions/common/api/messaging/message.h" |
20 #include "extensions/common/extension_messages.h" | 20 #include "extensions/common/extension_messages.h" |
21 #include "extensions/common/manifest_handlers/externally_connectable.h" | |
22 #include "extensions/renderer/dispatcher.h" | 21 #include "extensions/renderer/dispatcher.h" |
23 #include "extensions/renderer/event_bindings.h" | 22 #include "extensions/renderer/event_bindings.h" |
24 #include "extensions/renderer/object_backed_native_handler.h" | 23 #include "extensions/renderer/object_backed_native_handler.h" |
25 #include "extensions/renderer/scoped_persistent.h" | 24 #include "extensions/renderer/scoped_persistent.h" |
26 #include "extensions/renderer/script_context.h" | 25 #include "extensions/renderer/script_context.h" |
27 #include "extensions/renderer/script_context_set.h" | 26 #include "extensions/renderer/script_context_set.h" |
28 #include "third_party/WebKit/public/web/WebScopedMicrotaskSuppression.h" | 27 #include "third_party/WebKit/public/web/WebScopedMicrotaskSuppression.h" |
29 #include "third_party/WebKit/public/web/WebScopedUserGesture.h" | 28 #include "third_party/WebKit/public/web/WebScopedUserGesture.h" |
30 #include "third_party/WebKit/public/web/WebScopedWindowFocusAllowedIndicator.h" | 29 #include "third_party/WebKit/public/web/WebScopedWindowFocusAllowedIndicator.h" |
31 #include "third_party/WebKit/public/web/WebUserGestureIndicator.h" | 30 #include "third_party/WebKit/public/web/WebUserGestureIndicator.h" |
32 #include "v8/include/v8.h" | 31 #include "v8/include/v8.h" |
33 | 32 |
| 33 // TODO(thestig): Remove #ifdef from this file when extensions are no longer |
| 34 // used on mobile. |
| 35 #if defined(ENABLE_EXTENSIONS) |
| 36 #include "extensions/common/manifest_handlers/externally_connectable.h" |
| 37 #endif |
| 38 |
34 // Message passing API example (in a content script): | 39 // Message passing API example (in a content script): |
35 // var extension = | 40 // var extension = |
36 // new chrome.Extension('00123456789abcdef0123456789abcdef0123456'); | 41 // new chrome.Extension('00123456789abcdef0123456789abcdef0123456'); |
37 // var port = runtime.connect(); | 42 // var port = runtime.connect(); |
38 // port.postMessage('Can you hear me now?'); | 43 // port.postMessage('Can you hear me now?'); |
39 // port.onmessage.addListener(function(msg, port) { | 44 // port.onmessage.addListener(function(msg, port) { |
40 // alert('response=' + msg); | 45 // alert('response=' + msg); |
41 // port.postMessage('I got your reponse'); | 46 // port.postMessage('I got your reponse'); |
42 // }); | 47 // }); |
43 | 48 |
(...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
254 std::string target_extension_id = script_context->GetExtensionID(); | 259 std::string target_extension_id = script_context->GetExtensionID(); |
255 const Extension* extension = script_context->extension(); | 260 const Extension* extension = script_context->extension(); |
256 | 261 |
257 v8::Handle<v8::Value> tab = v8::Null(isolate); | 262 v8::Handle<v8::Value> tab = v8::Null(isolate); |
258 v8::Handle<v8::Value> tls_channel_id_value = v8::Undefined(isolate); | 263 v8::Handle<v8::Value> tls_channel_id_value = v8::Undefined(isolate); |
259 | 264 |
260 if (extension) { | 265 if (extension) { |
261 if (!source_tab->empty() && !extension->is_platform_app()) | 266 if (!source_tab->empty() && !extension->is_platform_app()) |
262 tab = converter->ToV8Value(source_tab, script_context->v8_context()); | 267 tab = converter->ToV8Value(source_tab, script_context->v8_context()); |
263 | 268 |
| 269 #if defined(ENABLE_EXTENSIONS) |
264 ExternallyConnectableInfo* externally_connectable = | 270 ExternallyConnectableInfo* externally_connectable = |
265 ExternallyConnectableInfo::Get(extension); | 271 ExternallyConnectableInfo::Get(extension); |
266 if (externally_connectable && | 272 if (externally_connectable && |
267 externally_connectable->accepts_tls_channel_id) { | 273 externally_connectable->accepts_tls_channel_id) { |
268 tls_channel_id_value = v8::String::NewFromUtf8(isolate, | 274 tls_channel_id_value = v8::String::NewFromUtf8(isolate, |
269 tls_channel_id.c_str(), | 275 tls_channel_id.c_str(), |
270 v8::String::kNormalString, | 276 v8::String::kNormalString, |
271 tls_channel_id.size()); | 277 tls_channel_id.size()); |
272 } | 278 } |
| 279 #endif |
273 } | 280 } |
274 | 281 |
275 v8::Handle<v8::Value> arguments[] = { | 282 v8::Handle<v8::Value> arguments[] = { |
276 // portId | 283 // portId |
277 v8::Integer::New(isolate, target_port_id), | 284 v8::Integer::New(isolate, target_port_id), |
278 // channelName | 285 // channelName |
279 v8::String::NewFromUtf8(isolate, | 286 v8::String::NewFromUtf8(isolate, |
280 channel_name.c_str(), | 287 channel_name.c_str(), |
281 v8::String::kNormalString, | 288 v8::String::kNormalString, |
282 channel_name.size()), | 289 channel_name.size()), |
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
418 const ScriptContextSet& context_set, | 425 const ScriptContextSet& context_set, |
419 int port_id, | 426 int port_id, |
420 const std::string& error_message, | 427 const std::string& error_message, |
421 content::RenderView* restrict_to_render_view) { | 428 content::RenderView* restrict_to_render_view) { |
422 context_set.ForEach( | 429 context_set.ForEach( |
423 restrict_to_render_view, | 430 restrict_to_render_view, |
424 base::Bind(&DispatchOnDisconnectToScriptContext, port_id, error_message)); | 431 base::Bind(&DispatchOnDisconnectToScriptContext, port_id, error_message)); |
425 } | 432 } |
426 | 433 |
427 } // namespace extensions | 434 } // namespace extensions |
OLD | NEW |