| OLD | NEW |
| 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 Loading... |
| 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 Loading... |
| 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 729 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1113 FOR_EACH_OBSERVER(WebContentsObserver, | 1136 FOR_EACH_OBSERVER(WebContentsObserver, |
| 1114 observers_, | 1137 observers_, |
| 1115 DidCloneToNewWebContents(this, tc)); | 1138 DidCloneToNewWebContents(this, tc)); |
| 1116 return tc; | 1139 return tc; |
| 1117 } | 1140 } |
| 1118 | 1141 |
| 1119 void WebContentsImpl::Observe(int type, | 1142 void WebContentsImpl::Observe(int type, |
| 1120 const NotificationSource& source, | 1143 const NotificationSource& source, |
| 1121 const NotificationDetails& details) { | 1144 const NotificationDetails& details) { |
| 1122 switch (type) { | 1145 switch (type) { |
| 1123 case NOTIFICATION_WEB_CONTENTS_DESTROYED: | |
| 1124 OnWebContentsDestroyed(Source<WebContents>(source).ptr()); | |
| 1125 break; | |
| 1126 case NOTIFICATION_RENDER_WIDGET_HOST_DESTROYED: { | 1146 case NOTIFICATION_RENDER_WIDGET_HOST_DESTROYED: { |
| 1127 RenderWidgetHost* host = Source<RenderWidgetHost>(source).ptr(); | 1147 RenderWidgetHost* host = Source<RenderWidgetHost>(source).ptr(); |
| 1128 for (PendingWidgetViews::iterator i = pending_widget_views_.begin(); | 1148 for (PendingWidgetViews::iterator i = pending_widget_views_.begin(); |
| 1129 i != pending_widget_views_.end(); ++i) { | 1149 i != pending_widget_views_.end(); ++i) { |
| 1130 if (host->GetView() == i->second) { | 1150 if (host->GetView() == i->second) { |
| 1131 pending_widget_views_.erase(i); | 1151 pending_widget_views_.erase(i); |
| 1132 break; | 1152 break; |
| 1133 } | 1153 } |
| 1134 } | 1154 } |
| 1135 break; | 1155 break; |
| (...skipping 29 matching lines...) Expand all Loading... |
| 1165 this, delegate, &render_view_host_delegate_view_)); | 1185 this, delegate, &render_view_host_delegate_view_)); |
| 1166 } | 1186 } |
| 1167 CHECK(render_view_host_delegate_view_); | 1187 CHECK(render_view_host_delegate_view_); |
| 1168 } | 1188 } |
| 1169 CHECK(view_.get()); | 1189 CHECK(view_.get()); |
| 1170 | 1190 |
| 1171 gfx::Size initial_size = params.initial_size; | 1191 gfx::Size initial_size = params.initial_size; |
| 1172 view_->CreateView(initial_size, params.context); | 1192 view_->CreateView(initial_size, params.context); |
| 1173 | 1193 |
| 1174 // Listen for whether our opener gets destroyed. | 1194 // Listen for whether our opener gets destroyed. |
| 1175 if (opener_) { | 1195 if (opener_) |
| 1176 registrar_.Add(this, NOTIFICATION_WEB_CONTENTS_DESTROYED, | 1196 AddDestructionObserver(opener_); |
| 1177 Source<WebContents>(opener_)); | |
| 1178 } | |
| 1179 | 1197 |
| 1180 registrar_.Add(this, | 1198 registrar_.Add(this, |
| 1181 NOTIFICATION_RENDER_WIDGET_HOST_DESTROYED, | 1199 NOTIFICATION_RENDER_WIDGET_HOST_DESTROYED, |
| 1182 NotificationService::AllBrowserContextsAndSources()); | 1200 NotificationService::AllBrowserContextsAndSources()); |
| 1183 #if defined(ENABLE_JAVA_BRIDGE) | 1201 #if defined(ENABLE_JAVA_BRIDGE) |
| 1184 java_bridge_dispatcher_host_manager_.reset( | 1202 java_bridge_dispatcher_host_manager_.reset( |
| 1185 new JavaBridgeDispatcherHostManager(this)); | 1203 new JavaBridgeDispatcherHostManager(this)); |
| 1186 #endif | 1204 #endif |
| 1187 | 1205 |
| 1188 #if defined(OS_ANDROID) | 1206 #if defined(OS_ANDROID) |
| 1189 date_time_chooser_.reset(new DateTimeChooserAndroid()); | 1207 date_time_chooser_.reset(new DateTimeChooserAndroid()); |
| 1190 #endif | 1208 #endif |
| 1191 } | 1209 } |
| 1192 | 1210 |
| 1193 void WebContentsImpl::OnWebContentsDestroyed(WebContents* web_contents) { | 1211 void WebContentsImpl::OnWebContentsDestroyed(WebContentsImpl* web_contents) { |
| 1212 RemoveDestructionObserver(web_contents); |
| 1213 |
| 1194 // Clear the opener if it has been closed. | 1214 // Clear the opener if it has been closed. |
| 1195 if (web_contents == opener_) { | 1215 if (web_contents == opener_) { |
| 1196 registrar_.Remove(this, NOTIFICATION_WEB_CONTENTS_DESTROYED, | |
| 1197 Source<WebContents>(opener_)); | |
| 1198 opener_ = NULL; | 1216 opener_ = NULL; |
| 1199 return; | 1217 return; |
| 1200 } | 1218 } |
| 1201 // Clear a pending contents that has been closed before being shown. | 1219 // Clear a pending contents that has been closed before being shown. |
| 1202 for (PendingContents::iterator iter = pending_contents_.begin(); | 1220 for (PendingContents::iterator iter = pending_contents_.begin(); |
| 1203 iter != pending_contents_.end(); | 1221 iter != pending_contents_.end(); |
| 1204 ++iter) { | 1222 ++iter) { |
| 1205 if (iter->second != web_contents) | 1223 if (iter->second != web_contents) |
| 1206 continue; | 1224 continue; |
| 1207 pending_contents_.erase(iter); | 1225 pending_contents_.erase(iter); |
| 1208 registrar_.Remove(this, NOTIFICATION_WEB_CONTENTS_DESTROYED, | |
| 1209 Source<WebContents>(web_contents)); | |
| 1210 return; | 1226 return; |
| 1211 } | 1227 } |
| 1212 NOTREACHED(); | 1228 NOTREACHED(); |
| 1213 } | 1229 } |
| 1214 | 1230 |
| 1231 void WebContentsImpl::AddDestructionObserver(WebContentsImpl* web_contents) { |
| 1232 if (!ContainsKey(destruction_observers_, web_contents)) { |
| 1233 destruction_observers_[web_contents] = |
| 1234 new DestructionObserver(this, web_contents); |
| 1235 } |
| 1236 } |
| 1237 |
| 1238 void WebContentsImpl::RemoveDestructionObserver(WebContentsImpl* web_contents) { |
| 1239 DestructionObservers::iterator iter = |
| 1240 destruction_observers_.find(web_contents); |
| 1241 if (iter != destruction_observers_.end()) { |
| 1242 delete destruction_observers_[web_contents]; |
| 1243 destruction_observers_.erase(iter); |
| 1244 } |
| 1245 } |
| 1246 |
| 1215 void WebContentsImpl::AddObserver(WebContentsObserver* observer) { | 1247 void WebContentsImpl::AddObserver(WebContentsObserver* observer) { |
| 1216 observers_.AddObserver(observer); | 1248 observers_.AddObserver(observer); |
| 1217 } | 1249 } |
| 1218 | 1250 |
| 1219 void WebContentsImpl::RemoveObserver(WebContentsObserver* observer) { | 1251 void WebContentsImpl::RemoveObserver(WebContentsObserver* observer) { |
| 1220 observers_.RemoveObserver(observer); | 1252 observers_.RemoveObserver(observer); |
| 1221 } | 1253 } |
| 1222 | 1254 |
| 1223 void WebContentsImpl::Activate() { | 1255 void WebContentsImpl::Activate() { |
| 1224 if (delegate_) | 1256 if (delegate_) |
| (...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1413 WebContentsViewPort* new_view = new_contents->view_.get(); | 1445 WebContentsViewPort* new_view = new_contents->view_.get(); |
| 1414 | 1446 |
| 1415 // TODO(brettw): It seems bogus that we have to call this function on the | 1447 // TODO(brettw): It seems bogus that we have to call this function on the |
| 1416 // newly created object and give it one of its own member variables. | 1448 // newly created object and give it one of its own member variables. |
| 1417 new_view->CreateViewForWidget(new_contents->GetRenderViewHost()); | 1449 new_view->CreateViewForWidget(new_contents->GetRenderViewHost()); |
| 1418 } | 1450 } |
| 1419 // Save the created window associated with the route so we can show it | 1451 // Save the created window associated with the route so we can show it |
| 1420 // later. | 1452 // later. |
| 1421 DCHECK_NE(MSG_ROUTING_NONE, route_id); | 1453 DCHECK_NE(MSG_ROUTING_NONE, route_id); |
| 1422 pending_contents_[route_id] = new_contents; | 1454 pending_contents_[route_id] = new_contents; |
| 1423 registrar_.Add(this, NOTIFICATION_WEB_CONTENTS_DESTROYED, | 1455 AddDestructionObserver(new_contents); |
| 1424 Source<WebContents>(new_contents)); | |
| 1425 } | 1456 } |
| 1426 | 1457 |
| 1427 if (delegate_) { | 1458 if (delegate_) { |
| 1428 delegate_->WebContentsCreated( | 1459 delegate_->WebContentsCreated( |
| 1429 this, params.opener_frame_id, params.frame_name, | 1460 this, params.opener_frame_id, params.frame_name, |
| 1430 params.target_url, new_contents); | 1461 params.target_url, new_contents); |
| 1431 } | 1462 } |
| 1432 | 1463 |
| 1433 if (params.opener_suppressed) { | 1464 if (params.opener_suppressed) { |
| 1434 // When the opener is suppressed, the original renderer cannot access the | 1465 // When the opener is suppressed, the original renderer cannot access the |
| (...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1549 PendingContents::iterator iter = pending_contents_.find(route_id); | 1580 PendingContents::iterator iter = pending_contents_.find(route_id); |
| 1550 | 1581 |
| 1551 // Certain systems can block the creation of new windows. If we didn't succeed | 1582 // Certain systems can block the creation of new windows. If we didn't succeed |
| 1552 // in creating one, just return NULL. | 1583 // in creating one, just return NULL. |
| 1553 if (iter == pending_contents_.end()) { | 1584 if (iter == pending_contents_.end()) { |
| 1554 return NULL; | 1585 return NULL; |
| 1555 } | 1586 } |
| 1556 | 1587 |
| 1557 WebContentsImpl* new_contents = iter->second; | 1588 WebContentsImpl* new_contents = iter->second; |
| 1558 pending_contents_.erase(route_id); | 1589 pending_contents_.erase(route_id); |
| 1559 registrar_.Remove(this, NOTIFICATION_WEB_CONTENTS_DESTROYED, | 1590 RemoveDestructionObserver(new_contents); |
| 1560 Source<WebContents>(new_contents)); | |
| 1561 | 1591 |
| 1562 // Don't initialize the guest WebContents immediately. | 1592 // Don't initialize the guest WebContents immediately. |
| 1563 if (new_contents->GetRenderProcessHost()->IsGuest()) | 1593 if (new_contents->GetRenderProcessHost()->IsGuest()) |
| 1564 return new_contents; | 1594 return new_contents; |
| 1565 | 1595 |
| 1566 if (!new_contents->GetRenderProcessHost()->HasConnection() || | 1596 if (!new_contents->GetRenderProcessHost()->HasConnection() || |
| 1567 !new_contents->GetRenderViewHost()->GetView()) | 1597 !new_contents->GetRenderViewHost()->GetView()) |
| 1568 return NULL; | 1598 return NULL; |
| 1569 | 1599 |
| 1570 // TODO(brettw): It seems bogus to reach into here and initialize the host. | 1600 // TODO(brettw): It seems bogus to reach into here and initialize the host. |
| (...skipping 1438 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3009 #if defined(OS_ANDROID) | 3039 #if defined(OS_ANDROID) |
| 3010 if (delegate_) | 3040 if (delegate_) |
| 3011 delegate_->LoadProgressChanged(this, progress); | 3041 delegate_->LoadProgressChanged(this, progress); |
| 3012 #endif | 3042 #endif |
| 3013 } | 3043 } |
| 3014 | 3044 |
| 3015 void WebContentsImpl::DidDisownOpener(RenderViewHost* rvh) { | 3045 void WebContentsImpl::DidDisownOpener(RenderViewHost* rvh) { |
| 3016 if (opener_) { | 3046 if (opener_) { |
| 3017 // Clear our opener so that future cross-process navigations don't have an | 3047 // Clear our opener so that future cross-process navigations don't have an |
| 3018 // opener assigned. | 3048 // opener assigned. |
| 3019 registrar_.Remove(this, NOTIFICATION_WEB_CONTENTS_DESTROYED, | 3049 RemoveDestructionObserver(opener_); |
| 3020 Source<WebContents>(opener_)); | |
| 3021 opener_ = NULL; | 3050 opener_ = NULL; |
| 3022 } | 3051 } |
| 3023 | 3052 |
| 3024 // Notify all swapped out RenderViewHosts for this tab. This is important | 3053 // Notify all swapped out RenderViewHosts for this tab. This is important |
| 3025 // in case we go back to them, or if another window in those processes tries | 3054 // in case we go back to them, or if another window in those processes tries |
| 3026 // to access window.opener. | 3055 // to access window.opener. |
| 3027 render_manager_.DidDisownOpener(rvh); | 3056 render_manager_.DidDisownOpener(rvh); |
| 3028 } | 3057 } |
| 3029 | 3058 |
| 3030 void WebContentsImpl::DocumentAvailableInMainFrame( | 3059 void WebContentsImpl::DocumentAvailableInMainFrame( |
| (...skipping 512 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3543 } | 3572 } |
| 3544 | 3573 |
| 3545 BrowserPluginGuestManager* | 3574 BrowserPluginGuestManager* |
| 3546 WebContentsImpl::GetBrowserPluginGuestManager() const { | 3575 WebContentsImpl::GetBrowserPluginGuestManager() const { |
| 3547 return static_cast<BrowserPluginGuestManager*>( | 3576 return static_cast<BrowserPluginGuestManager*>( |
| 3548 GetBrowserContext()->GetUserData( | 3577 GetBrowserContext()->GetUserData( |
| 3549 browser_plugin::kBrowserPluginGuestManagerKeyName)); | 3578 browser_plugin::kBrowserPluginGuestManagerKeyName)); |
| 3550 } | 3579 } |
| 3551 | 3580 |
| 3552 } // namespace content | 3581 } // namespace content |
| OLD | NEW |