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

Side by Side Diff: content/browser/web_contents/web_contents_impl.cc

Issue 14651029: content: Remove usage of NOTIFICATION_WEB_CONTENTS_DESTROYED from content (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: trybots Created 7 years, 7 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "content/browser/web_contents/web_contents_impl.h" 5 #include "content/browser/web_contents/web_contents_impl.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "base/command_line.h" 9 #include "base/command_line.h"
10 #include "base/metrics/histogram.h" 10 #include "base/metrics/histogram.h"
(...skipping 266 matching lines...) Expand 10 before | Expand all | Expand 10 after
277 } 277 }
278 278
279 new_contents->Init(params); 279 new_contents->Init(params);
280 return new_contents; 280 return new_contents;
281 } 281 }
282 282
283 WebContents* WebContents::FromRenderViewHost(const RenderViewHost* rvh) { 283 WebContents* WebContents::FromRenderViewHost(const RenderViewHost* rvh) {
284 return rvh->GetDelegate()->GetAsWebContents(); 284 return rvh->GetDelegate()->GetAsWebContents();
285 } 285 }
286 286
287 // WebContentsImpl::DestructionObserver ----------------------------------------
288
289 class WebContentsImpl::DestructionObserver : public WebContentsObserver {
290 public:
291 DestructionObserver(WebContentsImpl* owner, WebContents* watched_contents)
292 : WebContentsObserver(watched_contents),
293 owner_(owner) {
294 }
295
296 // WebContentsObserver:
297 virtual void WebContentsDestroyed(WebContents* web_contents) OVERRIDE {
298 owner_->OnWebContentsDestroyed(static_cast<WebContentsImpl*>(web_contents));
299 }
300
301 private:
302 WebContentsImpl* owner_;
303
304 DISALLOW_COPY_AND_ASSIGN(DestructionObserver);
305 };
306
287 // WebContentsImpl ------------------------------------------------------------- 307 // WebContentsImpl -------------------------------------------------------------
288 308
289 WebContentsImpl::WebContentsImpl( 309 WebContentsImpl::WebContentsImpl(
290 BrowserContext* browser_context, 310 BrowserContext* browser_context,
291 WebContentsImpl* opener) 311 WebContentsImpl* opener)
292 : delegate_(NULL), 312 : delegate_(NULL),
293 controller_(this, browser_context), 313 controller_(this, browser_context),
294 render_view_host_delegate_view_(NULL), 314 render_view_host_delegate_view_(NULL),
295 opener_(opener), 315 opener_(opener),
296 #if defined(OS_WIN) && defined(USE_AURA) 316 #if defined(OS_WIN) && defined(USE_AURA)
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
364 unload_start_time = before_unload_end_time_; 384 unload_start_time = before_unload_end_time_;
365 UMA_HISTOGRAM_TIMES("Tab.Close", now - close_start_time_); 385 UMA_HISTOGRAM_TIMES("Tab.Close", now - close_start_time_);
366 UMA_HISTOGRAM_TIMES("Tab.Close.UnloadTime", now - unload_start_time); 386 UMA_HISTOGRAM_TIMES("Tab.Close.UnloadTime", now - unload_start_time);
367 } 387 }
368 388
369 FOR_EACH_OBSERVER(WebContentsObserver, 389 FOR_EACH_OBSERVER(WebContentsObserver,
370 observers_, 390 observers_,
371 WebContentsImplDestroyed()); 391 WebContentsImplDestroyed());
372 392
373 SetDelegate(NULL); 393 SetDelegate(NULL);
394
395 STLDeleteContainerPairSecondPointers(destruction_observers_.begin(),
396 destruction_observers_.end());
374 } 397 }
375 398
376 WebContentsImpl* WebContentsImpl::CreateWithOpener( 399 WebContentsImpl* WebContentsImpl::CreateWithOpener(
377 const WebContents::CreateParams& params, 400 const WebContents::CreateParams& params,
378 WebContentsImpl* opener) { 401 WebContentsImpl* opener) {
379 WebContentsImpl* new_contents = new WebContentsImpl( 402 WebContentsImpl* new_contents = new WebContentsImpl(
380 params.browser_context, opener); 403 params.browser_context, opener);
381 404
382 new_contents->Init(params); 405 new_contents->Init(params);
383 return new_contents; 406 return new_contents;
(...skipping 715 matching lines...) Expand 10 before | Expand all | Expand 10 after
1099 FOR_EACH_OBSERVER(WebContentsObserver, 1122 FOR_EACH_OBSERVER(WebContentsObserver,
1100 observers_, 1123 observers_,
1101 DidCloneToNewWebContents(this, tc)); 1124 DidCloneToNewWebContents(this, tc));
1102 return tc; 1125 return tc;
1103 } 1126 }
1104 1127
1105 void WebContentsImpl::Observe(int type, 1128 void WebContentsImpl::Observe(int type,
1106 const NotificationSource& source, 1129 const NotificationSource& source,
1107 const NotificationDetails& details) { 1130 const NotificationDetails& details) {
1108 switch (type) { 1131 switch (type) {
1109 case NOTIFICATION_WEB_CONTENTS_DESTROYED:
1110 OnWebContentsDestroyed(Source<WebContents>(source).ptr());
1111 break;
1112 case NOTIFICATION_RENDER_WIDGET_HOST_DESTROYED: { 1132 case NOTIFICATION_RENDER_WIDGET_HOST_DESTROYED: {
1113 RenderWidgetHost* host = Source<RenderWidgetHost>(source).ptr(); 1133 RenderWidgetHost* host = Source<RenderWidgetHost>(source).ptr();
1114 for (PendingWidgetViews::iterator i = pending_widget_views_.begin(); 1134 for (PendingWidgetViews::iterator i = pending_widget_views_.begin();
1115 i != pending_widget_views_.end(); ++i) { 1135 i != pending_widget_views_.end(); ++i) {
1116 if (host->GetView() == i->second) { 1136 if (host->GetView() == i->second) {
1117 pending_widget_views_.erase(i); 1137 pending_widget_views_.erase(i);
1118 break; 1138 break;
1119 } 1139 }
1120 } 1140 }
1121 break; 1141 break;
(...skipping 29 matching lines...) Expand all
1151 this, delegate, &render_view_host_delegate_view_)); 1171 this, delegate, &render_view_host_delegate_view_));
1152 } 1172 }
1153 CHECK(render_view_host_delegate_view_); 1173 CHECK(render_view_host_delegate_view_);
1154 } 1174 }
1155 CHECK(view_.get()); 1175 CHECK(view_.get());
1156 1176
1157 gfx::Size initial_size = params.initial_size; 1177 gfx::Size initial_size = params.initial_size;
1158 view_->CreateView(initial_size, params.context); 1178 view_->CreateView(initial_size, params.context);
1159 1179
1160 // Listen for whether our opener gets destroyed. 1180 // Listen for whether our opener gets destroyed.
1161 if (opener_) { 1181 if (opener_)
1162 registrar_.Add(this, NOTIFICATION_WEB_CONTENTS_DESTROYED, 1182 AddDestructionObserver(opener_);
1163 Source<WebContents>(opener_));
1164 }
1165 1183
1166 registrar_.Add(this, 1184 registrar_.Add(this,
1167 NOTIFICATION_RENDER_WIDGET_HOST_DESTROYED, 1185 NOTIFICATION_RENDER_WIDGET_HOST_DESTROYED,
1168 NotificationService::AllBrowserContextsAndSources()); 1186 NotificationService::AllBrowserContextsAndSources());
1169 #if defined(ENABLE_JAVA_BRIDGE) 1187 #if defined(ENABLE_JAVA_BRIDGE)
1170 java_bridge_dispatcher_host_manager_.reset( 1188 java_bridge_dispatcher_host_manager_.reset(
1171 new JavaBridgeDispatcherHostManager(this)); 1189 new JavaBridgeDispatcherHostManager(this));
1172 #endif 1190 #endif
1173 1191
1174 #if defined(OS_ANDROID) 1192 #if defined(OS_ANDROID)
1175 date_time_chooser_.reset(new DateTimeChooserAndroid()); 1193 date_time_chooser_.reset(new DateTimeChooserAndroid());
1176 #endif 1194 #endif
1177 } 1195 }
1178 1196
1179 void WebContentsImpl::OnWebContentsDestroyed(WebContents* web_contents) { 1197 void WebContentsImpl::OnWebContentsDestroyed(WebContentsImpl* web_contents) {
1198 RemoveDestructionObserver(web_contents);
1199
1180 // Clear the opener if it has been closed. 1200 // Clear the opener if it has been closed.
1181 if (web_contents == opener_) { 1201 if (web_contents == opener_) {
1182 registrar_.Remove(this, NOTIFICATION_WEB_CONTENTS_DESTROYED,
1183 Source<WebContents>(opener_));
1184 opener_ = NULL; 1202 opener_ = NULL;
1185 return; 1203 return;
1186 } 1204 }
1187 // Clear a pending contents that has been closed before being shown. 1205 // Clear a pending contents that has been closed before being shown.
1188 for (PendingContents::iterator iter = pending_contents_.begin(); 1206 for (PendingContents::iterator iter = pending_contents_.begin();
1189 iter != pending_contents_.end(); 1207 iter != pending_contents_.end();
1190 ++iter) { 1208 ++iter) {
1191 if (iter->second != web_contents) 1209 if (iter->second != web_contents)
1192 continue; 1210 continue;
1193 pending_contents_.erase(iter); 1211 pending_contents_.erase(iter);
1194 registrar_.Remove(this, NOTIFICATION_WEB_CONTENTS_DESTROYED,
1195 Source<WebContents>(web_contents));
1196 return; 1212 return;
1197 } 1213 }
1198 NOTREACHED(); 1214 NOTREACHED();
1199 } 1215 }
1200 1216
1217 void WebContentsImpl::AddDestructionObserver(WebContentsImpl* web_contents) {
1218 if (!ContainsKey(destruction_observers_, web_contents)) {
1219 destruction_observers_[web_contents] =
1220 new DestructionObserver(this, web_contents);
1221 }
1222 }
1223
1224 void WebContentsImpl::RemoveDestructionObserver(WebContentsImpl* web_contents) {
1225 DestructionObservers::iterator iter =
1226 destruction_observers_.find(web_contents);
1227 if (iter != destruction_observers_.end()) {
1228 delete destruction_observers_[web_contents];
1229 destruction_observers_.erase(iter);
1230 }
1231 }
1232
1201 void WebContentsImpl::AddObserver(WebContentsObserver* observer) { 1233 void WebContentsImpl::AddObserver(WebContentsObserver* observer) {
1202 observers_.AddObserver(observer); 1234 observers_.AddObserver(observer);
1203 } 1235 }
1204 1236
1205 void WebContentsImpl::RemoveObserver(WebContentsObserver* observer) { 1237 void WebContentsImpl::RemoveObserver(WebContentsObserver* observer) {
1206 observers_.RemoveObserver(observer); 1238 observers_.RemoveObserver(observer);
1207 } 1239 }
1208 1240
1209 void WebContentsImpl::Activate() { 1241 void WebContentsImpl::Activate() {
1210 if (delegate_) 1242 if (delegate_)
(...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after
1399 WebContentsViewPort* new_view = new_contents->view_.get(); 1431 WebContentsViewPort* new_view = new_contents->view_.get();
1400 1432
1401 // TODO(brettw): It seems bogus that we have to call this function on the 1433 // TODO(brettw): It seems bogus that we have to call this function on the
1402 // newly created object and give it one of its own member variables. 1434 // newly created object and give it one of its own member variables.
1403 new_view->CreateViewForWidget(new_contents->GetRenderViewHost()); 1435 new_view->CreateViewForWidget(new_contents->GetRenderViewHost());
1404 } 1436 }
1405 // Save the created window associated with the route so we can show it 1437 // Save the created window associated with the route so we can show it
1406 // later. 1438 // later.
1407 DCHECK_NE(MSG_ROUTING_NONE, route_id); 1439 DCHECK_NE(MSG_ROUTING_NONE, route_id);
1408 pending_contents_[route_id] = new_contents; 1440 pending_contents_[route_id] = new_contents;
1409 registrar_.Add(this, NOTIFICATION_WEB_CONTENTS_DESTROYED, 1441 AddDestructionObserver(new_contents);
1410 Source<WebContents>(new_contents));
1411 } 1442 }
1412 1443
1413 if (delegate_) { 1444 if (delegate_) {
1414 delegate_->WebContentsCreated( 1445 delegate_->WebContentsCreated(
1415 this, params.opener_frame_id, params.frame_name, 1446 this, params.opener_frame_id, params.frame_name,
1416 params.target_url, new_contents); 1447 params.target_url, new_contents);
1417 } 1448 }
1418 1449
1419 if (params.opener_suppressed) { 1450 if (params.opener_suppressed) {
1420 // When the opener is suppressed, the original renderer cannot access the 1451 // When the opener is suppressed, the original renderer cannot access the
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
1535 PendingContents::iterator iter = pending_contents_.find(route_id); 1566 PendingContents::iterator iter = pending_contents_.find(route_id);
1536 1567
1537 // Certain systems can block the creation of new windows. If we didn't succeed 1568 // Certain systems can block the creation of new windows. If we didn't succeed
1538 // in creating one, just return NULL. 1569 // in creating one, just return NULL.
1539 if (iter == pending_contents_.end()) { 1570 if (iter == pending_contents_.end()) {
1540 return NULL; 1571 return NULL;
1541 } 1572 }
1542 1573
1543 WebContentsImpl* new_contents = iter->second; 1574 WebContentsImpl* new_contents = iter->second;
1544 pending_contents_.erase(route_id); 1575 pending_contents_.erase(route_id);
1545 registrar_.Remove(this, NOTIFICATION_WEB_CONTENTS_DESTROYED, 1576 RemoveDestructionObserver(new_contents);
1546 Source<WebContents>(new_contents));
1547 1577
1548 // Don't initialize the guest WebContents immediately. 1578 // Don't initialize the guest WebContents immediately.
1549 if (new_contents->GetRenderProcessHost()->IsGuest()) 1579 if (new_contents->GetRenderProcessHost()->IsGuest())
1550 return new_contents; 1580 return new_contents;
1551 1581
1552 if (!new_contents->GetRenderProcessHost()->HasConnection() || 1582 if (!new_contents->GetRenderProcessHost()->HasConnection() ||
1553 !new_contents->GetRenderViewHost()->GetView()) 1583 !new_contents->GetRenderViewHost()->GetView())
1554 return NULL; 1584 return NULL;
1555 1585
1556 // TODO(brettw): It seems bogus to reach into here and initialize the host. 1586 // TODO(brettw): It seems bogus to reach into here and initialize the host.
(...skipping 1427 matching lines...) Expand 10 before | Expand all | Expand 10 after
2984 #if defined(OS_ANDROID) 3014 #if defined(OS_ANDROID)
2985 if (delegate_) 3015 if (delegate_)
2986 delegate_->LoadProgressChanged(this, progress); 3016 delegate_->LoadProgressChanged(this, progress);
2987 #endif 3017 #endif
2988 } 3018 }
2989 3019
2990 void WebContentsImpl::DidDisownOpener(RenderViewHost* rvh) { 3020 void WebContentsImpl::DidDisownOpener(RenderViewHost* rvh) {
2991 if (opener_) { 3021 if (opener_) {
2992 // Clear our opener so that future cross-process navigations don't have an 3022 // Clear our opener so that future cross-process navigations don't have an
2993 // opener assigned. 3023 // opener assigned.
2994 registrar_.Remove(this, NOTIFICATION_WEB_CONTENTS_DESTROYED, 3024 RemoveDestructionObserver(opener_);
2995 Source<WebContents>(opener_));
2996 opener_ = NULL; 3025 opener_ = NULL;
2997 } 3026 }
2998 3027
2999 // Notify all swapped out RenderViewHosts for this tab. This is important 3028 // Notify all swapped out RenderViewHosts for this tab. This is important
3000 // in case we go back to them, or if another window in those processes tries 3029 // in case we go back to them, or if another window in those processes tries
3001 // to access window.opener. 3030 // to access window.opener.
3002 render_manager_.DidDisownOpener(rvh); 3031 render_manager_.DidDisownOpener(rvh);
3003 } 3032 }
3004 3033
3005 void WebContentsImpl::DocumentAvailableInMainFrame( 3034 void WebContentsImpl::DocumentAvailableInMainFrame(
(...skipping 512 matching lines...) Expand 10 before | Expand all | Expand 10 after
3518 } 3547 }
3519 3548
3520 BrowserPluginGuestManager* 3549 BrowserPluginGuestManager*
3521 WebContentsImpl::GetBrowserPluginGuestManager() const { 3550 WebContentsImpl::GetBrowserPluginGuestManager() const {
3522 return static_cast<BrowserPluginGuestManager*>( 3551 return static_cast<BrowserPluginGuestManager*>(
3523 GetBrowserContext()->GetUserData( 3552 GetBrowserContext()->GetUserData(
3524 browser_plugin::kBrowserPluginGuestManagerKeyName)); 3553 browser_plugin::kBrowserPluginGuestManagerKeyName));
3525 } 3554 }
3526 3555
3527 } // namespace content 3556 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698