OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/tab_contents/tab_contents.h" | 5 #include "content/browser/tab_contents/tab_contents.h" |
6 | 6 |
7 #include <cmath> | 7 #include <cmath> |
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 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
194 | 194 |
195 render_manager_.Init(profile, site_instance, routing_id); | 195 render_manager_.Init(profile, site_instance, routing_id); |
196 | 196 |
197 // We have the initial size of the view be based on the size of the passed in | 197 // We have the initial size of the view be based on the size of the passed in |
198 // tab contents (normally a tab from the same window). | 198 // tab contents (normally a tab from the same window). |
199 view_->CreateView(base_tab_contents ? | 199 view_->CreateView(base_tab_contents ? |
200 base_tab_contents->view()->GetContainerSize() : gfx::Size()); | 200 base_tab_contents->view()->GetContainerSize() : gfx::Size()); |
201 | 201 |
202 registrar_.Add(this, NotificationType::RENDER_WIDGET_HOST_DESTROYED, | 202 registrar_.Add(this, NotificationType::RENDER_WIDGET_HOST_DESTROYED, |
203 NotificationService::AllSources()); | 203 NotificationService::AllSources()); |
| 204 |
| 205 // Can only add observers after render_manager_.Init() is called, since that's |
| 206 // what sets up the render_view_host which TabContentObserver's constructor |
| 207 // uses to get the routing_id. |
| 208 AddObservers(); |
204 } | 209 } |
205 | 210 |
206 TabContents::~TabContents() { | 211 TabContents::~TabContents() { |
207 is_being_destroyed_ = true; | 212 is_being_destroyed_ = true; |
208 | 213 |
209 // We don't want any notifications while we're running our destructor. | 214 // We don't want any notifications while we're running our destructor. |
210 registrar_.RemoveAll(); | 215 registrar_.RemoveAll(); |
211 | 216 |
212 // Clear out any JavaScript state. | 217 // Clear out any JavaScript state. |
213 if (delegate_) | 218 if (delegate_) |
(...skipping 25 matching lines...) Expand all Loading... |
239 #endif | 244 #endif |
240 | 245 |
241 // OnCloseStarted isn't called in unit tests. | 246 // OnCloseStarted isn't called in unit tests. |
242 if (!tab_close_start_time_.is_null()) { | 247 if (!tab_close_start_time_.is_null()) { |
243 UMA_HISTOGRAM_TIMES("Tab.Close", | 248 UMA_HISTOGRAM_TIMES("Tab.Close", |
244 base::TimeTicks::Now() - tab_close_start_time_); | 249 base::TimeTicks::Now() - tab_close_start_time_); |
245 } | 250 } |
246 | 251 |
247 FOR_EACH_OBSERVER(TabContentsObserver, observers_, TabContentsDestroyed()); | 252 FOR_EACH_OBSERVER(TabContentsObserver, observers_, TabContentsDestroyed()); |
248 | 253 |
| 254 net::NetworkChangeNotifier::RemoveOnlineStateObserver(this); |
| 255 |
249 set_delegate(NULL); | 256 set_delegate(NULL); |
250 } | 257 } |
251 | 258 |
252 // TODO(cbentzel): Either remove the debugging code, or rename to SetDelegate. | 259 // TODO(cbentzel): Either remove the debugging code, or rename to SetDelegate. |
253 void TabContents::set_delegate(TabContentsDelegate* delegate) { | 260 void TabContents::set_delegate(TabContentsDelegate* delegate) { |
254 if (delegate == delegate_) | 261 if (delegate == delegate_) |
255 return; | 262 return; |
256 if (delegate_) | 263 if (delegate_) |
257 delegate_->Detach(this); | 264 delegate_->Detach(this); |
258 delegate_ = delegate; | 265 delegate_ = delegate; |
259 if (delegate_) | 266 if (delegate_) |
260 delegate_->Attach(this); | 267 delegate_->Attach(this); |
261 } | 268 } |
262 | 269 |
| 270 void TabContents::AddObservers() { |
| 271 net::NetworkChangeNotifier::AddOnlineStateObserver(this); |
| 272 } |
| 273 |
263 bool TabContents::OnMessageReceived(const IPC::Message& message) { | 274 bool TabContents::OnMessageReceived(const IPC::Message& message) { |
264 if (web_ui() && web_ui()->OnMessageReceived(message)) | 275 if (web_ui() && web_ui()->OnMessageReceived(message)) |
265 return true; | 276 return true; |
266 | 277 |
267 ObserverListBase<TabContentsObserver>::Iterator it(observers_); | 278 ObserverListBase<TabContentsObserver>::Iterator it(observers_); |
268 TabContentsObserver* observer; | 279 TabContentsObserver* observer; |
269 while ((observer = it.GetNext()) != NULL) | 280 while ((observer = it.GetNext()) != NULL) |
270 if (observer->OnMessageReceived(message)) | 281 if (observer->OnMessageReceived(message)) |
271 return true; | 282 return true; |
272 | 283 |
(...skipping 1550 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1823 } | 1834 } |
1824 | 1835 |
1825 void TabContents::SwapInRenderViewHost(RenderViewHost* rvh) { | 1836 void TabContents::SwapInRenderViewHost(RenderViewHost* rvh) { |
1826 render_manager_.SwapInRenderViewHost(rvh); | 1837 render_manager_.SwapInRenderViewHost(rvh); |
1827 } | 1838 } |
1828 | 1839 |
1829 void TabContents::CreateViewAndSetSizeForRVH(RenderViewHost* rvh) { | 1840 void TabContents::CreateViewAndSetSizeForRVH(RenderViewHost* rvh) { |
1830 RenderWidgetHostView* rwh_view = view()->CreateViewForWidget(rvh); | 1841 RenderWidgetHostView* rwh_view = view()->CreateViewForWidget(rvh); |
1831 rwh_view->SetSize(view()->GetContainerSize()); | 1842 rwh_view->SetSize(view()->GetContainerSize()); |
1832 } | 1843 } |
| 1844 |
| 1845 void TabContents::OnOnlineStateChanged(bool online) { |
| 1846 render_view_host()->Send(new ViewMsg_NetworkStateChanged( |
| 1847 render_view_host()->routing_id(), online)); |
| 1848 } |
OLD | NEW |