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

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

Issue 709933002: Add frameId to MessageSender (extension messaging API) (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Generate frameId in browser Created 6 years, 1 month 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
OLDNEW
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"
(...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after
233 args.GetIsolate()); 233 args.GetIsolate());
234 } 234 }
235 235
236 // Dispatcher handle. Not owned. 236 // Dispatcher handle. Not owned.
237 Dispatcher* dispatcher_; 237 Dispatcher* dispatcher_;
238 }; 238 };
239 239
240 void DispatchOnConnectToScriptContext( 240 void DispatchOnConnectToScriptContext(
241 int target_port_id, 241 int target_port_id,
242 const std::string& channel_name, 242 const std::string& channel_name,
243 const base::DictionaryValue* source_tab, 243 const ExtensionMsg_TabConnectionInfo& source,
244 const ExtensionMsg_ExternalConnectionInfo& info, 244 const ExtensionMsg_ExternalConnectionInfo& info,
245 const std::string& tls_channel_id, 245 const std::string& tls_channel_id,
246 bool* port_created, 246 bool* port_created,
247 ScriptContext* script_context) { 247 ScriptContext* script_context) {
248 v8::Isolate* isolate = script_context->isolate(); 248 v8::Isolate* isolate = script_context->isolate();
249 v8::HandleScope handle_scope(isolate); 249 v8::HandleScope handle_scope(isolate);
250 250
251 scoped_ptr<V8ValueConverter> converter(V8ValueConverter::create()); 251 scoped_ptr<V8ValueConverter> converter(V8ValueConverter::create());
252 252
253 const std::string& source_url_spec = info.source_url.spec(); 253 const std::string& source_url_spec = info.source_url.spec();
254 std::string target_extension_id = script_context->GetExtensionID(); 254 std::string target_extension_id = script_context->GetExtensionID();
255 const Extension* extension = script_context->extension(); 255 const Extension* extension = script_context->extension();
256 256
257 v8::Handle<v8::Value> tab = v8::Null(isolate); 257 v8::Handle<v8::Value> tab = v8::Null(isolate);
258 v8::Handle<v8::Value> tls_channel_id_value = v8::Undefined(isolate); 258 v8::Handle<v8::Value> tls_channel_id_value = v8::Undefined(isolate);
259 259
260 if (extension) { 260 if (extension) {
261 if (!source_tab->empty() && !extension->is_platform_app()) 261 if (!source.tab->empty() && !extension->is_platform_app())
262 tab = converter->ToV8Value(source_tab, script_context->v8_context()); 262 tab = converter->ToV8Value(source.tab, script_context->v8_context());
263 263
264 ExternallyConnectableInfo* externally_connectable = 264 ExternallyConnectableInfo* externally_connectable =
265 ExternallyConnectableInfo::Get(extension); 265 ExternallyConnectableInfo::Get(extension);
266 if (externally_connectable && 266 if (externally_connectable &&
267 externally_connectable->accepts_tls_channel_id) { 267 externally_connectable->accepts_tls_channel_id) {
268 tls_channel_id_value = v8::String::NewFromUtf8(isolate, 268 tls_channel_id_value = v8::String::NewFromUtf8(isolate,
269 tls_channel_id.c_str(), 269 tls_channel_id.c_str(),
270 v8::String::kNormalString, 270 v8::String::kNormalString,
271 tls_channel_id.size()); 271 tls_channel_id.size());
272 } 272 }
273 } 273 }
274 274
275 v8::Handle<v8::Value> arguments[] = { 275 v8::Handle<v8::Value> arguments[] = {
276 // portId 276 // portId
277 v8::Integer::New(isolate, target_port_id), 277 v8::Integer::New(isolate, target_port_id),
278 // channelName 278 // channelName
279 v8::String::NewFromUtf8(isolate, 279 v8::String::NewFromUtf8(isolate,
280 channel_name.c_str(), 280 channel_name.c_str(),
281 v8::String::kNormalString, 281 v8::String::kNormalString,
282 channel_name.size()), 282 channel_name.size()),
283 // sourceTab 283 // sourceTab
284 tab, 284 tab,
285 // source_frame_id
286 v8::Integer::New(isolate, source.frame_id),
285 // sourceExtensionId 287 // sourceExtensionId
286 v8::String::NewFromUtf8(isolate, 288 v8::String::NewFromUtf8(isolate,
287 info.source_id.c_str(), 289 info.source_id.c_str(),
288 v8::String::kNormalString, 290 v8::String::kNormalString,
289 info.source_id.size()), 291 info.source_id.size()),
290 // targetExtensionId 292 // targetExtensionId
291 v8::String::NewFromUtf8(isolate, 293 v8::String::NewFromUtf8(isolate,
292 target_extension_id.c_str(), 294 target_extension_id.c_str(),
293 v8::String::kNormalString, 295 v8::String::kNormalString,
294 target_extension_id.size()), 296 target_extension_id.size()),
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
365 ObjectBackedNativeHandler* MessagingBindings::Get(Dispatcher* dispatcher, 367 ObjectBackedNativeHandler* MessagingBindings::Get(Dispatcher* dispatcher,
366 ScriptContext* context) { 368 ScriptContext* context) {
367 return new ExtensionImpl(dispatcher, context); 369 return new ExtensionImpl(dispatcher, context);
368 } 370 }
369 371
370 // static 372 // static
371 void MessagingBindings::DispatchOnConnect( 373 void MessagingBindings::DispatchOnConnect(
372 const ScriptContextSet& context_set, 374 const ScriptContextSet& context_set,
373 int target_port_id, 375 int target_port_id,
374 const std::string& channel_name, 376 const std::string& channel_name,
375 const base::DictionaryValue& source_tab, 377 const ExtensionMsg_TabConnectionInfo& source,
376 const ExtensionMsg_ExternalConnectionInfo& info, 378 const ExtensionMsg_ExternalConnectionInfo& info,
377 const std::string& tls_channel_id, 379 const std::string& tls_channel_id,
378 content::RenderView* restrict_to_render_view) { 380 content::RenderView* restrict_to_render_view) {
379 bool port_created = false; 381 bool port_created = false;
380 context_set.ForEach(info.target_id, 382 context_set.ForEach(info.target_id,
381 restrict_to_render_view, 383 restrict_to_render_view,
382 base::Bind(&DispatchOnConnectToScriptContext, 384 base::Bind(&DispatchOnConnectToScriptContext,
383 target_port_id, 385 target_port_id,
384 channel_name, 386 channel_name,
385 &source_tab, 387 &source,
386 info, 388 info,
387 tls_channel_id, 389 tls_channel_id,
388 &port_created)); 390 &port_created));
389 391
390 // If we didn't create a port, notify the other end of the channel (treat it 392 // If we didn't create a port, notify the other end of the channel (treat it
391 // as a disconnect). 393 // as a disconnect).
392 if (!port_created) { 394 if (!port_created) {
393 content::RenderThread::Get()->Send(new ExtensionHostMsg_CloseChannel( 395 content::RenderThread::Get()->Send(new ExtensionHostMsg_CloseChannel(
394 target_port_id, kReceivingEndDoesntExistError)); 396 target_port_id, kReceivingEndDoesntExistError));
395 } 397 }
(...skipping 22 matching lines...) Expand all
418 const ScriptContextSet& context_set, 420 const ScriptContextSet& context_set,
419 int port_id, 421 int port_id,
420 const std::string& error_message, 422 const std::string& error_message,
421 content::RenderView* restrict_to_render_view) { 423 content::RenderView* restrict_to_render_view) {
422 context_set.ForEach( 424 context_set.ForEach(
423 restrict_to_render_view, 425 restrict_to_render_view,
424 base::Bind(&DispatchOnDisconnectToScriptContext, port_id, error_message)); 426 base::Bind(&DispatchOnDisconnectToScriptContext, port_id, error_message));
425 } 427 }
426 428
427 } // namespace extensions 429 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698