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