| 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 722 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 1106   FOR_EACH_OBSERVER(WebContentsObserver, | 1129   FOR_EACH_OBSERVER(WebContentsObserver, | 
| 1107                     observers_, | 1130                     observers_, | 
| 1108                     DidCloneToNewWebContents(this, tc)); | 1131                     DidCloneToNewWebContents(this, tc)); | 
| 1109   return tc; | 1132   return tc; | 
| 1110 } | 1133 } | 
| 1111 | 1134 | 
| 1112 void WebContentsImpl::Observe(int type, | 1135 void WebContentsImpl::Observe(int type, | 
| 1113                               const NotificationSource& source, | 1136                               const NotificationSource& source, | 
| 1114                               const NotificationDetails& details) { | 1137                               const NotificationDetails& details) { | 
| 1115   switch (type) { | 1138   switch (type) { | 
| 1116     case NOTIFICATION_WEB_CONTENTS_DESTROYED: |  | 
| 1117       OnWebContentsDestroyed(Source<WebContents>(source).ptr()); |  | 
| 1118       break; |  | 
| 1119     case NOTIFICATION_RENDER_WIDGET_HOST_DESTROYED: { | 1139     case NOTIFICATION_RENDER_WIDGET_HOST_DESTROYED: { | 
| 1120       RenderWidgetHost* host = Source<RenderWidgetHost>(source).ptr(); | 1140       RenderWidgetHost* host = Source<RenderWidgetHost>(source).ptr(); | 
| 1121       for (PendingWidgetViews::iterator i = pending_widget_views_.begin(); | 1141       for (PendingWidgetViews::iterator i = pending_widget_views_.begin(); | 
| 1122            i != pending_widget_views_.end(); ++i) { | 1142            i != pending_widget_views_.end(); ++i) { | 
| 1123         if (host->GetView() == i->second) { | 1143         if (host->GetView() == i->second) { | 
| 1124           pending_widget_views_.erase(i); | 1144           pending_widget_views_.erase(i); | 
| 1125           break; | 1145           break; | 
| 1126         } | 1146         } | 
| 1127       } | 1147       } | 
| 1128       break; | 1148       break; | 
| (...skipping 29 matching lines...) Expand all  Loading... | 
| 1158           this, delegate, &render_view_host_delegate_view_)); | 1178           this, delegate, &render_view_host_delegate_view_)); | 
| 1159     } | 1179     } | 
| 1160     CHECK(render_view_host_delegate_view_); | 1180     CHECK(render_view_host_delegate_view_); | 
| 1161   } | 1181   } | 
| 1162   CHECK(view_.get()); | 1182   CHECK(view_.get()); | 
| 1163 | 1183 | 
| 1164   gfx::Size initial_size = params.initial_size; | 1184   gfx::Size initial_size = params.initial_size; | 
| 1165   view_->CreateView(initial_size, params.context); | 1185   view_->CreateView(initial_size, params.context); | 
| 1166 | 1186 | 
| 1167   // Listen for whether our opener gets destroyed. | 1187   // Listen for whether our opener gets destroyed. | 
| 1168   if (opener_) { | 1188   if (opener_) | 
| 1169     registrar_.Add(this, NOTIFICATION_WEB_CONTENTS_DESTROYED, | 1189     AddDestructionObserver(opener_); | 
| 1170                    Source<WebContents>(opener_)); |  | 
| 1171   } |  | 
| 1172 | 1190 | 
| 1173   registrar_.Add(this, | 1191   registrar_.Add(this, | 
| 1174                  NOTIFICATION_RENDER_WIDGET_HOST_DESTROYED, | 1192                  NOTIFICATION_RENDER_WIDGET_HOST_DESTROYED, | 
| 1175                  NotificationService::AllBrowserContextsAndSources()); | 1193                  NotificationService::AllBrowserContextsAndSources()); | 
| 1176 #if defined(ENABLE_JAVA_BRIDGE) | 1194 #if defined(ENABLE_JAVA_BRIDGE) | 
| 1177   java_bridge_dispatcher_host_manager_.reset( | 1195   java_bridge_dispatcher_host_manager_.reset( | 
| 1178       new JavaBridgeDispatcherHostManager(this)); | 1196       new JavaBridgeDispatcherHostManager(this)); | 
| 1179 #endif | 1197 #endif | 
| 1180 | 1198 | 
| 1181 #if defined(OS_ANDROID) | 1199 #if defined(OS_ANDROID) | 
| 1182   date_time_chooser_.reset(new DateTimeChooserAndroid()); | 1200   date_time_chooser_.reset(new DateTimeChooserAndroid()); | 
| 1183 #endif | 1201 #endif | 
| 1184 } | 1202 } | 
| 1185 | 1203 | 
| 1186 void WebContentsImpl::OnWebContentsDestroyed(WebContents* web_contents) { | 1204 void WebContentsImpl::OnWebContentsDestroyed(WebContentsImpl* web_contents) { | 
|  | 1205   RemoveDestructionObserver(web_contents); | 
|  | 1206 | 
| 1187   // Clear the opener if it has been closed. | 1207   // Clear the opener if it has been closed. | 
| 1188   if (web_contents == opener_) { | 1208   if (web_contents == opener_) { | 
| 1189     registrar_.Remove(this, NOTIFICATION_WEB_CONTENTS_DESTROYED, |  | 
| 1190                       Source<WebContents>(opener_)); |  | 
| 1191     opener_ = NULL; | 1209     opener_ = NULL; | 
| 1192     return; | 1210     return; | 
| 1193   } | 1211   } | 
| 1194   // Clear a pending contents that has been closed before being shown. | 1212   // Clear a pending contents that has been closed before being shown. | 
| 1195   for (PendingContents::iterator iter = pending_contents_.begin(); | 1213   for (PendingContents::iterator iter = pending_contents_.begin(); | 
| 1196        iter != pending_contents_.end(); | 1214        iter != pending_contents_.end(); | 
| 1197        ++iter) { | 1215        ++iter) { | 
| 1198     if (iter->second != web_contents) | 1216     if (iter->second != web_contents) | 
| 1199       continue; | 1217       continue; | 
| 1200     pending_contents_.erase(iter); | 1218     pending_contents_.erase(iter); | 
| 1201     registrar_.Remove(this, NOTIFICATION_WEB_CONTENTS_DESTROYED, |  | 
| 1202                       Source<WebContents>(web_contents)); |  | 
| 1203     return; | 1219     return; | 
| 1204   } | 1220   } | 
| 1205   NOTREACHED(); | 1221   NOTREACHED(); | 
| 1206 } | 1222 } | 
| 1207 | 1223 | 
|  | 1224 void WebContentsImpl::AddDestructionObserver(WebContentsImpl* web_contents) { | 
|  | 1225   if (!ContainsKey(destruction_observers_, web_contents)) { | 
|  | 1226     destruction_observers_[web_contents] = | 
|  | 1227         new DestructionObserver(this, web_contents); | 
|  | 1228   } | 
|  | 1229 } | 
|  | 1230 | 
|  | 1231 void WebContentsImpl::RemoveDestructionObserver(WebContentsImpl* web_contents) { | 
|  | 1232   DestructionObservers::iterator iter = | 
|  | 1233       destruction_observers_.find(web_contents); | 
|  | 1234   if (iter != destruction_observers_.end()) { | 
|  | 1235     delete destruction_observers_[web_contents]; | 
|  | 1236     destruction_observers_.erase(iter); | 
|  | 1237   } | 
|  | 1238 } | 
|  | 1239 | 
| 1208 void WebContentsImpl::AddObserver(WebContentsObserver* observer) { | 1240 void WebContentsImpl::AddObserver(WebContentsObserver* observer) { | 
| 1209   observers_.AddObserver(observer); | 1241   observers_.AddObserver(observer); | 
| 1210 } | 1242 } | 
| 1211 | 1243 | 
| 1212 void WebContentsImpl::RemoveObserver(WebContentsObserver* observer) { | 1244 void WebContentsImpl::RemoveObserver(WebContentsObserver* observer) { | 
| 1213   observers_.RemoveObserver(observer); | 1245   observers_.RemoveObserver(observer); | 
| 1214 } | 1246 } | 
| 1215 | 1247 | 
| 1216 void WebContentsImpl::Activate() { | 1248 void WebContentsImpl::Activate() { | 
| 1217   if (delegate_) | 1249   if (delegate_) | 
| (...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 1406       WebContentsViewPort* new_view = new_contents->view_.get(); | 1438       WebContentsViewPort* new_view = new_contents->view_.get(); | 
| 1407 | 1439 | 
| 1408       // TODO(brettw): It seems bogus that we have to call this function on the | 1440       // TODO(brettw): It seems bogus that we have to call this function on the | 
| 1409       // newly created object and give it one of its own member variables. | 1441       // newly created object and give it one of its own member variables. | 
| 1410       new_view->CreateViewForWidget(new_contents->GetRenderViewHost()); | 1442       new_view->CreateViewForWidget(new_contents->GetRenderViewHost()); | 
| 1411     } | 1443     } | 
| 1412     // Save the created window associated with the route so we can show it | 1444     // Save the created window associated with the route so we can show it | 
| 1413     // later. | 1445     // later. | 
| 1414     DCHECK_NE(MSG_ROUTING_NONE, route_id); | 1446     DCHECK_NE(MSG_ROUTING_NONE, route_id); | 
| 1415     pending_contents_[route_id] = new_contents; | 1447     pending_contents_[route_id] = new_contents; | 
| 1416     registrar_.Add(this, NOTIFICATION_WEB_CONTENTS_DESTROYED, | 1448     AddDestructionObserver(new_contents); | 
| 1417                    Source<WebContents>(new_contents)); |  | 
| 1418   } | 1449   } | 
| 1419 | 1450 | 
| 1420   if (delegate_) { | 1451   if (delegate_) { | 
| 1421     delegate_->WebContentsCreated( | 1452     delegate_->WebContentsCreated( | 
| 1422         this, params.opener_frame_id, params.frame_name, | 1453         this, params.opener_frame_id, params.frame_name, | 
| 1423         params.target_url, new_contents); | 1454         params.target_url, new_contents); | 
| 1424   } | 1455   } | 
| 1425 | 1456 | 
| 1426   if (params.opener_suppressed) { | 1457   if (params.opener_suppressed) { | 
| 1427     // When the opener is suppressed, the original renderer cannot access the | 1458     // When the opener is suppressed, the original renderer cannot access the | 
| (...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 1542   PendingContents::iterator iter = pending_contents_.find(route_id); | 1573   PendingContents::iterator iter = pending_contents_.find(route_id); | 
| 1543 | 1574 | 
| 1544   // Certain systems can block the creation of new windows. If we didn't succeed | 1575   // Certain systems can block the creation of new windows. If we didn't succeed | 
| 1545   // in creating one, just return NULL. | 1576   // in creating one, just return NULL. | 
| 1546   if (iter == pending_contents_.end()) { | 1577   if (iter == pending_contents_.end()) { | 
| 1547     return NULL; | 1578     return NULL; | 
| 1548   } | 1579   } | 
| 1549 | 1580 | 
| 1550   WebContentsImpl* new_contents = iter->second; | 1581   WebContentsImpl* new_contents = iter->second; | 
| 1551   pending_contents_.erase(route_id); | 1582   pending_contents_.erase(route_id); | 
| 1552   registrar_.Remove(this, NOTIFICATION_WEB_CONTENTS_DESTROYED, | 1583   RemoveDestructionObserver(new_contents); | 
| 1553                     Source<WebContents>(new_contents)); |  | 
| 1554 | 1584 | 
| 1555   // Don't initialize the guest WebContents immediately. | 1585   // Don't initialize the guest WebContents immediately. | 
| 1556   if (new_contents->GetRenderProcessHost()->IsGuest()) | 1586   if (new_contents->GetRenderProcessHost()->IsGuest()) | 
| 1557     return new_contents; | 1587     return new_contents; | 
| 1558 | 1588 | 
| 1559   if (!new_contents->GetRenderProcessHost()->HasConnection() || | 1589   if (!new_contents->GetRenderProcessHost()->HasConnection() || | 
| 1560       !new_contents->GetRenderViewHost()->GetView()) | 1590       !new_contents->GetRenderViewHost()->GetView()) | 
| 1561     return NULL; | 1591     return NULL; | 
| 1562 | 1592 | 
| 1563   // TODO(brettw): It seems bogus to reach into here and initialize the host. | 1593   // TODO(brettw): It seems bogus to reach into here and initialize the host. | 
| (...skipping 1426 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 2990 #if defined(OS_ANDROID) | 3020 #if defined(OS_ANDROID) | 
| 2991   if (delegate_) | 3021   if (delegate_) | 
| 2992     delegate_->LoadProgressChanged(this, progress); | 3022     delegate_->LoadProgressChanged(this, progress); | 
| 2993 #endif | 3023 #endif | 
| 2994 } | 3024 } | 
| 2995 | 3025 | 
| 2996 void WebContentsImpl::DidDisownOpener(RenderViewHost* rvh) { | 3026 void WebContentsImpl::DidDisownOpener(RenderViewHost* rvh) { | 
| 2997   if (opener_) { | 3027   if (opener_) { | 
| 2998     // Clear our opener so that future cross-process navigations don't have an | 3028     // Clear our opener so that future cross-process navigations don't have an | 
| 2999     // opener assigned. | 3029     // opener assigned. | 
| 3000     registrar_.Remove(this, NOTIFICATION_WEB_CONTENTS_DESTROYED, | 3030     RemoveDestructionObserver(opener_); | 
| 3001                       Source<WebContents>(opener_)); |  | 
| 3002     opener_ = NULL; | 3031     opener_ = NULL; | 
| 3003   } | 3032   } | 
| 3004 | 3033 | 
| 3005   // Notify all swapped out RenderViewHosts for this tab.  This is important | 3034   // Notify all swapped out RenderViewHosts for this tab.  This is important | 
| 3006   // in case we go back to them, or if another window in those processes tries | 3035   // in case we go back to them, or if another window in those processes tries | 
| 3007   // to access window.opener. | 3036   // to access window.opener. | 
| 3008   render_manager_.DidDisownOpener(rvh); | 3037   render_manager_.DidDisownOpener(rvh); | 
| 3009 } | 3038 } | 
| 3010 | 3039 | 
| 3011 void WebContentsImpl::DocumentAvailableInMainFrame( | 3040 void WebContentsImpl::DocumentAvailableInMainFrame( | 
| (...skipping 512 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 3524 } | 3553 } | 
| 3525 | 3554 | 
| 3526 BrowserPluginGuestManager* | 3555 BrowserPluginGuestManager* | 
| 3527     WebContentsImpl::GetBrowserPluginGuestManager() const { | 3556     WebContentsImpl::GetBrowserPluginGuestManager() const { | 
| 3528   return static_cast<BrowserPluginGuestManager*>( | 3557   return static_cast<BrowserPluginGuestManager*>( | 
| 3529       GetBrowserContext()->GetUserData( | 3558       GetBrowserContext()->GetUserData( | 
| 3530           browser_plugin::kBrowserPluginGuestManagerKeyName)); | 3559           browser_plugin::kBrowserPluginGuestManagerKeyName)); | 
| 3531 } | 3560 } | 
| 3532 | 3561 | 
| 3533 }  // namespace content | 3562 }  // namespace content | 
| OLD | NEW | 
|---|