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

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

Issue 2514523002: [Extensions] Make port creation synchronous in unload handlers (Closed)
Patch Set: Created 4 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
« no previous file with comments | « extensions/renderer/messaging_bindings.h ('k') | third_party/WebKit/Source/web/WebDocument.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 <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
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) {
274 UMA_HISTOGRAM_COUNTS_1000(
275 "Extensions.Messaging.ExtensionPortsCreated.InBeforeUnload",
276 ports_created_in_before_unload_);
277 UMA_HISTOGRAM_COUNTS_1000(
278 "Extensions.Messaging.ExtensionPortsCreated.InUnload",
279 ports_created_in_unload_);
280 UMA_HISTOGRAM_COUNTS_1000(
281 "Extensions.Messaging.ExtensionPortsCreated.Normal",
282 ports_created_normal_);
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
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
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
OLDNEW
« no previous file with comments | « extensions/renderer/messaging_bindings.h ('k') | third_party/WebKit/Source/web/WebDocument.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698