Chromium Code Reviews| 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 <stdint.h> | 7 #include <stdint.h> |
| 8 | 8 |
| 9 #include <map> | 9 #include <map> |
| 10 #include <string> | 10 #include <string> |
| (...skipping 251 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 262 RouteFunction("OpenChannelToNativeApp", "runtime.connectNative", | 262 RouteFunction("OpenChannelToNativeApp", "runtime.connectNative", |
| 263 base::Bind(&MessagingBindings::OpenChannelToNativeApp, | 263 base::Bind(&MessagingBindings::OpenChannelToNativeApp, |
| 264 base::Unretained(this))); | 264 base::Unretained(this))); |
| 265 RouteFunction( | 265 RouteFunction( |
| 266 "OpenChannelToTab", | 266 "OpenChannelToTab", |
| 267 base::Bind(&MessagingBindings::OpenChannelToTab, base::Unretained(this))); | 267 base::Bind(&MessagingBindings::OpenChannelToTab, base::Unretained(this))); |
| 268 } | 268 } |
| 269 | 269 |
| 270 MessagingBindings::~MessagingBindings() { | 270 MessagingBindings::~MessagingBindings() { |
| 271 g_messaging_map.Get().erase(context()); | 271 g_messaging_map.Get().erase(context()); |
| 272 if (ports_created_normal_ > 0 || ports_created_in_before_unload_ > 0 || | |
| 273 ports_created_in_unload_ > 0) { | |
|
Ilya Sherman
2016/11/14 18:00:28
I don't really understand this check -- why do you
Devlin
2016/11/14 18:50:33
I think the vast majority of contexts will never c
Ilya Sherman
2016/11/14 19:00:44
It just seems like you'll have a weird bias where
| |
| 274 UMA_HISTOGRAM_COUNTS_100( | |
| 275 "Extensions.Messaging.ExtensionPortsCreated.InBeforeUnload", | |
| 276 ports_created_in_before_unload_); | |
| 277 UMA_HISTOGRAM_COUNTS_100( | |
| 278 "Extensions.Messaging.ExtensionPortsCreated.InUnload", | |
| 279 ports_created_in_unload_); | |
| 280 UMA_HISTOGRAM_COUNTS_100( | |
| 281 "Extensions.Messaging.ExtensionPortsCreated.Normal", | |
| 282 ports_created_normal_); | |
|
Ilya Sherman
2016/11/14 18:00:28
Optional: FWIW, it would probably be more memory e
Devlin
2016/11/14 18:50:33
As discussed offline, actually going for UMA_HISTO
| |
| 283 } | |
| 272 } | 284 } |
| 273 | 285 |
| 274 // static | 286 // static |
| 275 void MessagingBindings::ValidateMessagePort( | 287 void MessagingBindings::ValidateMessagePort( |
| 276 const ScriptContextSet& context_set, | 288 const ScriptContextSet& context_set, |
| 277 int global_port_id, | 289 int global_port_id, |
| 278 content::RenderFrame* render_frame) { | 290 content::RenderFrame* render_frame) { |
| 279 int routing_id = render_frame->GetRoutingID(); | 291 int routing_id = render_frame->GetRoutingID(); |
| 280 | 292 |
| 281 bool has_port = false; | 293 bool has_port = false; |
| (...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 443 | 455 |
| 444 info.target_id = *v8::String::Utf8Value(args[0]); | 456 info.target_id = *v8::String::Utf8Value(args[0]); |
| 445 info.source_url = context()->url(); | 457 info.source_url = context()->url(); |
| 446 std::string channel_name = *v8::String::Utf8Value(args[1]); | 458 std::string channel_name = *v8::String::Utf8Value(args[1]); |
| 447 // TODO(devlin): Why is this not part of info? | 459 // TODO(devlin): Why is this not part of info? |
| 448 bool include_tls_channel_id = | 460 bool include_tls_channel_id = |
| 449 args.Length() > 2 ? args[2]->BooleanValue() : false; | 461 args.Length() > 2 ? args[2]->BooleanValue() : false; |
| 450 | 462 |
| 451 ExtensionFrameHelper* frame_helper = ExtensionFrameHelper::Get(render_frame); | 463 ExtensionFrameHelper* frame_helper = ExtensionFrameHelper::Get(render_frame); |
| 452 DCHECK(frame_helper); | 464 DCHECK(frame_helper); |
| 453 frame_helper->RequestPortId( | 465 |
| 454 info, channel_name, include_tls_channel_id, | 466 blink::WebLocalFrame* web_frame = render_frame->GetWebFrame(); |
| 455 base::Bind(&MessagingBindings::SetGlobalPortId, | 467 // If the frame is unloading, we need to assign the port id synchronously to |
| 456 weak_ptr_factory_.GetWeakPtr(), local_id)); | 468 // avoid dropping the message on the floor; see crbug.com/660706. |
| 469 // TODO(devlin): Investigate whether we need to continue supporting this long- | |
| 470 // term, and, if so, find an alternative that doesn't require synchronous | |
| 471 // IPCs. | |
| 472 if (!web_frame->document().isNull() && | |
| 473 (web_frame->document().unloadStartedDoNotUse() || | |
| 474 web_frame->document().processingBeforeUnloadDoNotUse())) { | |
| 475 ports_created_in_before_unload_ += | |
| 476 web_frame->document().processingBeforeUnloadDoNotUse() ? 1 : 0; | |
| 477 ports_created_in_unload_ += | |
| 478 web_frame->document().unloadStartedDoNotUse() ? 1 : 0; | |
| 479 int global_id = frame_helper->RequestSyncPortId(info, channel_name, | |
| 480 include_tls_channel_id); | |
| 481 ports_[local_id]->SetGlobalId(global_id); | |
| 482 } else { | |
| 483 ++ports_created_normal_; | |
| 484 frame_helper->RequestPortId( | |
| 485 info, channel_name, include_tls_channel_id, | |
| 486 base::Bind(&MessagingBindings::SetGlobalPortId, | |
| 487 weak_ptr_factory_.GetWeakPtr(), local_id)); | |
| 488 } | |
| 457 | 489 |
| 458 args.GetReturnValue().Set(static_cast<int32_t>(local_id)); | 490 args.GetReturnValue().Set(static_cast<int32_t>(local_id)); |
| 459 } | 491 } |
| 460 | 492 |
| 461 void MessagingBindings::OpenChannelToNativeApp( | 493 void MessagingBindings::OpenChannelToNativeApp( |
| 462 const v8::FunctionCallbackInfo<v8::Value>& args) { | 494 const v8::FunctionCallbackInfo<v8::Value>& args) { |
| 463 // The Javascript code should validate/fill the arguments. | 495 // The Javascript code should validate/fill the arguments. |
| 464 CHECK_EQ(args.Length(), 1); | 496 CHECK_EQ(args.Length(), 1); |
| 465 CHECK(args[0]->IsString()); | 497 CHECK(args[0]->IsString()); |
| 466 // This should be checked by our function routing code. | 498 // This should be checked by our function routing code. |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 553 DCHECK(iter != disconnected_ports_.end()); | 585 DCHECK(iter != disconnected_ports_.end()); |
| 554 iter->second->SetGlobalId(global_id); | 586 iter->second->SetGlobalId(global_id); |
| 555 // Setting the global id dispatches pending messages, so we can delete the | 587 // Setting the global id dispatches pending messages, so we can delete the |
| 556 // port now. | 588 // port now. |
| 557 disconnected_ports_.erase(iter); | 589 disconnected_ports_.erase(iter); |
| 558 } | 590 } |
| 559 | 591 |
| 560 int MessagingBindings::GetNextLocalId() { return next_local_id_++; } | 592 int MessagingBindings::GetNextLocalId() { return next_local_id_++; } |
| 561 | 593 |
| 562 } // namespace extensions | 594 } // namespace extensions |
| OLD | NEW |