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

Side by Side Diff: chrome/browser/extensions/extension_message_service.cc

Issue 150125: Send port disconnect events when a frame is unloaded. (Closed)
Patch Set: from linux Created 11 years, 5 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
OLDNEW
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2009 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/browser/extensions/extension_message_service.h" 5 #include "chrome/browser/extensions/extension_message_service.h"
6 6
7 #include "base/json_writer.h" 7 #include "base/json_writer.h"
8 #include "base/singleton.h" 8 #include "base/singleton.h"
9 #include "base/stl_util-inl.h" 9 #include "base/stl_util-inl.h"
10 #include "base/values.h" 10 #include "base/values.h"
(...skipping 272 matching lines...) Expand 10 before | Expand all | Expand 10 after
283 // describe the originating tab to the target extension. 283 // describe the originating tab to the target extension.
284 // This isn't really appropriate here, the originating tab 284 // This isn't really appropriate here, the originating tab
285 // information should be supplied by the caller for 285 // information should be supplied by the caller for
286 // automation-initiated ports. 286 // automation-initiated ports.
287 OpenChannelOnUIThreadImpl(routing_id, port1_id, source, port2_id, 287 OpenChannelOnUIThreadImpl(routing_id, port1_id, source, port2_id,
288 process_id, source_process_id); 288 process_id, source_process_id);
289 289
290 return port2_id; 290 return port2_id;
291 } 291 }
292 292
293 void ExtensionMessageService::CloseAutomationChannel(int port_id) { 293 void ExtensionMessageService::CloseChannel(int port_id) {
294 DCHECK_EQ(MessageLoop::current()->type(), MessageLoop::TYPE_UI); 294 DCHECK_EQ(MessageLoop::current()->type(), MessageLoop::TYPE_UI);
295 295
296 // TODO(siggi): Cleanup from the tab seems to beat this to the punch. 296 // Note: The channel might be gone already, if the other side closed first.
297 // DCHECK(channels_[GET_CHANNEL_ID(port_id)].port1 != NULL); 297 MessageChannelMap::iterator it = channels_.find(GET_CHANNEL_ID(port_id));
298 // TODO(siggi): should we notify the other side of the port? 298 if (it != channels_.end())
299 channels_.erase(GET_CHANNEL_ID(port_id)); 299 CloseChannelImpl(it, port_id);
300 }
301
302 void ExtensionMessageService::CloseChannelImpl(
303 MessageChannelMap::iterator channel_iter, int port_id) {
304 DCHECK_EQ(MessageLoop::current()->type(), MessageLoop::TYPE_UI);
305
306 // Notify the other side.
307 if (port_id == GET_CHANNEL_PORT1(channel_iter->first)) {
308 DispatchOnDisconnect(channel_iter->second.port2, port_id);
309 } else {
310 DCHECK_EQ(port_id, GET_CHANNEL_PORT2(channel_iter->first));
311 DispatchOnDisconnect(channel_iter->second.port1, port_id);
312 }
313
314 channels_.erase(channel_iter);
300 } 315 }
301 316
302 void ExtensionMessageService::PostMessageFromRenderer( 317 void ExtensionMessageService::PostMessageFromRenderer(
303 int port_id, const std::string& message) { 318 int port_id, const std::string& message) {
304 DCHECK_EQ(MessageLoop::current()->type(), MessageLoop::TYPE_UI); 319 DCHECK_EQ(MessageLoop::current()->type(), MessageLoop::TYPE_UI);
305 320
306 MessageChannelMap::iterator iter = 321 MessageChannelMap::iterator iter =
307 channels_.find(GET_CHANNEL_ID(port_id)); 322 channels_.find(GET_CHANNEL_ID(port_id));
308 if (iter == channels_.end()) 323 if (iter == channels_.end())
309 return; 324 return;
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
358 } 373 }
359 } 374 }
360 } 375 }
361 376
362 // Close any channels that share this renderer. We notify the opposite 377 // Close any channels that share this renderer. We notify the opposite
363 // port that his pair has closed. 378 // port that his pair has closed.
364 for (MessageChannelMap::iterator it = channels_.begin(); 379 for (MessageChannelMap::iterator it = channels_.begin();
365 it != channels_.end(); ) { 380 it != channels_.end(); ) {
366 MessageChannelMap::iterator current = it++; 381 MessageChannelMap::iterator current = it++;
367 if (current->second.port1 == renderer) { 382 if (current->second.port1 == renderer) {
368 DispatchOnDisconnect(current->second.port2, 383 CloseChannelImpl(current, GET_CHANNEL_PORT1(current->first));
369 GET_CHANNEL_PORT1(current->first));
370 channels_.erase(current);
371 } else if (current->second.port2 == renderer) { 384 } else if (current->second.port2 == renderer) {
372 DispatchOnDisconnect(current->second.port1, 385 CloseChannelImpl(current, GET_CHANNEL_PORT2(current->first));
373 GET_CHANNEL_PORT2(current->first));
374 channels_.erase(current);
375 } 386 }
376 } 387 }
377 } 388 }
OLDNEW
« no previous file with comments | « chrome/browser/extensions/extension_message_service.h ('k') | chrome/browser/renderer_host/browser_render_process_host.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698