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" |
11 #include "base/metrics/stats_counters.h" | 11 #include "base/metrics/stats_counters.h" |
12 #include "base/string16.h" | 12 #include "base/string16.h" |
13 #include "base/string_util.h" | 13 #include "base/string_util.h" |
14 #include "base/time.h" | 14 #include "base/time.h" |
15 #include "base/utf_string_conversions.h" | 15 #include "base/utf_string_conversions.h" |
16 #include "content/browser/browser_context.h" | 16 #include "content/browser/browser_context.h" |
| 17 #include "content/browser/browsing_instance_frame_id.h" |
17 #include "content/browser/child_process_security_policy.h" | 18 #include "content/browser/child_process_security_policy.h" |
18 #include "content/browser/debugger/devtools_manager_impl.h" | 19 #include "content/browser/debugger/devtools_manager_impl.h" |
19 #include "content/browser/download/download_manager.h" | 20 #include "content/browser/download/download_manager.h" |
20 #include "content/browser/download/download_stats.h" | 21 #include "content/browser/download/download_stats.h" |
| 22 #include "content/browser/frame_map.h" |
21 #include "content/browser/host_zoom_map.h" | 23 #include "content/browser/host_zoom_map.h" |
22 #include "content/browser/in_process_webkit/session_storage_namespace.h" | 24 #include "content/browser/in_process_webkit/session_storage_namespace.h" |
23 #include "content/browser/intents/intents_host_impl.h" | 25 #include "content/browser/intents/intents_host_impl.h" |
24 #include "content/browser/load_from_memory_cache_details.h" | 26 #include "content/browser/load_from_memory_cache_details.h" |
25 #include "content/browser/load_notification_details.h" | 27 #include "content/browser/load_notification_details.h" |
26 #include "content/browser/renderer_host/render_process_host_impl.h" | 28 #include "content/browser/renderer_host/render_process_host_impl.h" |
27 #include "content/browser/renderer_host/render_view_host.h" | 29 #include "content/browser/renderer_host/render_view_host.h" |
28 #include "content/browser/renderer_host/render_widget_host_view.h" | 30 #include "content/browser/renderer_host/render_widget_host_view.h" |
29 #include "content/browser/renderer_host/resource_dispatcher_host.h" | 31 #include "content/browser/renderer_host/resource_dispatcher_host.h" |
30 #include "content/browser/renderer_host/resource_request_details.h" | 32 #include "content/browser/renderer_host/resource_request_details.h" |
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
160 params->current_history_list_offset = controller.last_committed_entry_index(); | 162 params->current_history_list_offset = controller.last_committed_entry_index(); |
161 params->current_history_list_length = controller.entry_count(); | 163 params->current_history_list_length = controller.entry_count(); |
162 params->url = entry.url(); | 164 params->url = entry.url(); |
163 params->referrer = entry.referrer(); | 165 params->referrer = entry.referrer(); |
164 params->transition = entry.transition_type(); | 166 params->transition = entry.transition_type(); |
165 params->state = entry.content_state(); | 167 params->state = entry.content_state(); |
166 params->navigation_type = | 168 params->navigation_type = |
167 GetNavigationType(controller.browser_context(), entry, reload_type); | 169 GetNavigationType(controller.browser_context(), entry, reload_type); |
168 params->request_time = base::Time::Now(); | 170 params->request_time = base::Time::Now(); |
169 params->extra_headers = entry.extra_headers(); | 171 params->extra_headers = entry.extra_headers(); |
| 172 params->opener_browsing_instance_frame_id = |
| 173 entry.opener_browsing_instance_frame_id(); |
170 params->transferred_request_child_id = | 174 params->transferred_request_child_id = |
171 entry.transferred_global_request_id().child_id; | 175 entry.transferred_global_request_id().child_id; |
172 params->transferred_request_request_id = | 176 params->transferred_request_request_id = |
173 entry.transferred_global_request_id().request_id; | 177 entry.transferred_global_request_id().request_id; |
174 | 178 |
175 if (delegate) | 179 if (delegate) |
176 delegate->AddNavigationHeaders(params->url, ¶ms->extra_headers); | 180 delegate->AddNavigationHeaders(params->url, ¶ms->extra_headers); |
177 } | 181 } |
178 | 182 |
179 } // namespace | 183 } // namespace |
(...skipping 30 matching lines...) Expand all Loading... |
210 #endif | 214 #endif |
211 is_showing_before_unload_dialog_(false), | 215 is_showing_before_unload_dialog_(false), |
212 opener_web_ui_type_(WebUI::kNoWebUI), | 216 opener_web_ui_type_(WebUI::kNoWebUI), |
213 closed_by_user_gesture_(false), | 217 closed_by_user_gesture_(false), |
214 minimum_zoom_percent_( | 218 minimum_zoom_percent_( |
215 static_cast<int>(content::kMinimumZoomFactor * 100)), | 219 static_cast<int>(content::kMinimumZoomFactor * 100)), |
216 maximum_zoom_percent_( | 220 maximum_zoom_percent_( |
217 static_cast<int>(content::kMaximumZoomFactor * 100)), | 221 static_cast<int>(content::kMaximumZoomFactor * 100)), |
218 temporary_zoom_settings_(false), | 222 temporary_zoom_settings_(false), |
219 content_restrictions_(0), | 223 content_restrictions_(0), |
220 view_type_(content::VIEW_TYPE_TAB_CONTENTS) { | 224 view_type_(content::VIEW_TYPE_TAB_CONTENTS), |
| 225 browsing_instance_frame_( |
| 226 browser_context->frame_mapper().AllocateNewTopLevelFrameId()) { |
221 render_manager_.Init(browser_context, site_instance, routing_id); | 227 render_manager_.Init(browser_context, site_instance, routing_id); |
222 | 228 |
| 229 // TODO(supersat): This is a hack and should be removed. |
| 230 if (routing_id > 0) { |
| 231 browser_context->frame_mapper().UpdateFrame( |
| 232 browsing_instance_frame_, render_view_host()->process()->GetID(), |
| 233 routing_id, -1 /* We don't know the frame id yet */); |
| 234 } |
| 235 |
223 // We have the initial size of the view be based on the size of the passed in | 236 // We have the initial size of the view be based on the size of the passed in |
224 // tab contents (normally a tab from the same window). | 237 // tab contents (normally a tab from the same window). |
225 view_->CreateView(base_tab_contents ? | 238 view_->CreateView(base_tab_contents ? |
226 base_tab_contents->view()->GetContainerSize() : gfx::Size()); | 239 base_tab_contents->view()->GetContainerSize() : gfx::Size()); |
227 | 240 |
228 #if defined(ENABLE_JAVA_BRIDGE) | 241 #if defined(ENABLE_JAVA_BRIDGE) |
229 java_bridge_dispatcher_host_manager_.reset( | 242 java_bridge_dispatcher_host_manager_.reset( |
230 new JavaBridgeDispatcherHostManager(this)); | 243 new JavaBridgeDispatcherHostManager(this)); |
231 #endif | 244 #endif |
232 } | 245 } |
(...skipping 23 matching lines...) Expand all Loading... |
256 host->view()->WillWmDestroy(); | 269 host->view()->WillWmDestroy(); |
257 } | 270 } |
258 #endif | 271 #endif |
259 | 272 |
260 // OnCloseStarted isn't called in unit tests. | 273 // OnCloseStarted isn't called in unit tests. |
261 if (!tab_close_start_time_.is_null()) { | 274 if (!tab_close_start_time_.is_null()) { |
262 UMA_HISTOGRAM_TIMES("Tab.Close", | 275 UMA_HISTOGRAM_TIMES("Tab.Close", |
263 base::TimeTicks::Now() - tab_close_start_time_); | 276 base::TimeTicks::Now() - tab_close_start_time_); |
264 } | 277 } |
265 | 278 |
| 279 // Remove the top-level frame from the frame mapper |
| 280 browser_context()->frame_mapper().RemoveFrame(browsing_instance_frame_); |
| 281 // TODO(supersat): This should probably remove the proxy on the other side |
| 282 delete browsing_instance_frame_; |
| 283 |
266 FOR_EACH_OBSERVER(TabContentsObserver, observers_, TabContentsDestroyed()); | 284 FOR_EACH_OBSERVER(TabContentsObserver, observers_, TabContentsDestroyed()); |
267 | 285 |
268 set_delegate(NULL); | 286 set_delegate(NULL); |
269 } | 287 } |
270 | 288 |
271 // TODO(cbentzel): Either remove the debugging code, or rename to SetDelegate. | 289 // TODO(cbentzel): Either remove the debugging code, or rename to SetDelegate. |
272 void TabContents::set_delegate(TabContentsDelegate* delegate) { | 290 void TabContents::set_delegate(TabContentsDelegate* delegate) { |
273 if (delegate == delegate_) | 291 if (delegate == delegate_) |
274 return; | 292 return; |
275 if (delegate_) | 293 if (delegate_) |
(...skipping 1023 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1299 // page. | 1317 // page. |
1300 UpdateTargetURL(details.entry->page_id(), GURL()); | 1318 UpdateTargetURL(details.entry->page_id(), GURL()); |
1301 } | 1319 } |
1302 | 1320 |
1303 if (!details.is_in_page) { | 1321 if (!details.is_in_page) { |
1304 // Once the main frame is navigated, we're no longer considered to have | 1322 // Once the main frame is navigated, we're no longer considered to have |
1305 // displayed insecure content. | 1323 // displayed insecure content. |
1306 displayed_insecure_content_ = false; | 1324 displayed_insecure_content_ = false; |
1307 } | 1325 } |
1308 | 1326 |
| 1327 DLOG(WARNING) << "DidNavigateMainFramePostCommit: " << |
| 1328 params.url << ", " << params.frame_id; |
| 1329 content::FrameMap& mapper = browser_context()->frame_mapper(); |
| 1330 mapper.UpdateFrame(browsing_instance_frame_, |
| 1331 render_view_host()->process()->GetID(), |
| 1332 render_view_host()->routing_id(), |
| 1333 params.frame_id); |
| 1334 |
1309 // Notify observers about navigation. | 1335 // Notify observers about navigation. |
1310 FOR_EACH_OBSERVER(TabContentsObserver, observers_, | 1336 FOR_EACH_OBSERVER(TabContentsObserver, observers_, |
1311 DidNavigateMainFrame(details, params)); | 1337 DidNavigateMainFrame(details, params)); |
1312 } | 1338 } |
1313 | 1339 |
1314 void TabContents::DidNavigateAnyFramePostCommit( | 1340 void TabContents::DidNavigateAnyFramePostCommit( |
1315 RenderViewHost* render_view_host, | 1341 RenderViewHost* render_view_host, |
1316 const content::LoadCommittedDetails& details, | 1342 const content::LoadCommittedDetails& details, |
1317 const ViewHostMsg_FrameNavigate_Params& params) { | 1343 const ViewHostMsg_FrameNavigate_Params& params) { |
1318 // If we navigate, reset JavaScript state. This does nothing to prevent | 1344 // If we navigate, reset JavaScript state. This does nothing to prevent |
1319 // a malicious script from spamming messages, since the script could just | 1345 // a malicious script from spamming messages, since the script could just |
1320 // reload the page to stop blocking. | 1346 // reload the page to stop blocking. |
1321 if (dialog_creator_) { | 1347 if (dialog_creator_) { |
1322 dialog_creator_->ResetJavaScriptState(this); | 1348 dialog_creator_->ResetJavaScriptState(this); |
1323 dialog_creator_ = NULL; | 1349 dialog_creator_ = NULL; |
1324 } | 1350 } |
1325 | 1351 |
| 1352 // TODO(supersat): Logging for debugging purposes only. |
| 1353 DLOG(WARNING) << "DidNavigateAnyFramePostCommit: " |
| 1354 << "bifi = " << browsing_instance_frame_->id() |
| 1355 << ", process id = " << render_view_host->process()->GetID() |
| 1356 << ", rvh route = " << render_view_host->routing_id() |
| 1357 << ", frame_id = " << params.frame_id << ", url = " << |
| 1358 params.url; |
1326 // Notify observers about navigation. | 1359 // Notify observers about navigation. |
1327 FOR_EACH_OBSERVER(TabContentsObserver, observers_, | 1360 FOR_EACH_OBSERVER(TabContentsObserver, observers_, |
1328 DidNavigateAnyFrame(details, params)); | 1361 DidNavigateAnyFrame(details, params)); |
1329 } | 1362 } |
1330 | 1363 |
1331 void TabContents::UpdateMaxPageIDIfNecessary(SiteInstance* site_instance, | 1364 void TabContents::UpdateMaxPageIDIfNecessary(SiteInstance* site_instance, |
1332 RenderViewHost* rvh) { | 1365 RenderViewHost* rvh) { |
1333 // If we are creating a RVH for a restored controller, then we might | 1366 // If we are creating a RVH for a restored controller, then we might |
1334 // have more page IDs than the SiteInstance's current max page ID. We must | 1367 // have more page IDs than the SiteInstance's current max page ID. We must |
1335 // make sure that the max page ID is larger than any restored page ID. | 1368 // make sure that the max page ID is larger than any restored page ID. |
(...skipping 401 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1737 int32 page_id) { | 1770 int32 page_id) { |
1738 content::NotificationService::current()->Notify( | 1771 content::NotificationService::current()->Notify( |
1739 content::NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME, | 1772 content::NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME, |
1740 content::Source<TabContents>(this), | 1773 content::Source<TabContents>(this), |
1741 content::Details<int>(&page_id)); | 1774 content::Details<int>(&page_id)); |
1742 } | 1775 } |
1743 | 1776 |
1744 void TabContents::RequestOpenURL(const GURL& url, | 1777 void TabContents::RequestOpenURL(const GURL& url, |
1745 const content::Referrer& referrer, | 1778 const content::Referrer& referrer, |
1746 WindowOpenDisposition disposition, | 1779 WindowOpenDisposition disposition, |
1747 int64 source_frame_id) { | 1780 int64 source_frame_id, |
| 1781 int64 opener_browsing_instance_frame_id) { |
1748 // Delegate to RequestTransferURL because this is just the generic | 1782 // Delegate to RequestTransferURL because this is just the generic |
1749 // case where |old_request_id| is empty. | 1783 // case where |old_request_id| is empty. |
1750 RequestTransferURL(url, referrer, disposition, source_frame_id, | 1784 RequestTransferURL(url, referrer, disposition, source_frame_id, |
1751 GlobalRequestID()); | 1785 opener_browsing_instance_frame_id, GlobalRequestID()); |
1752 } | 1786 } |
1753 | 1787 |
1754 void TabContents::RequestTransferURL(const GURL& url, | 1788 void TabContents::RequestTransferURL(const GURL& url, |
1755 const content::Referrer& referrer, | 1789 const content::Referrer& referrer, |
1756 WindowOpenDisposition disposition, | 1790 WindowOpenDisposition disposition, |
1757 int64 source_frame_id, | 1791 int64 source_frame_id, |
| 1792 int64 opener_browsing_instance_frame_id, |
1758 const GlobalRequestID& old_request_id) { | 1793 const GlobalRequestID& old_request_id) { |
1759 TabContents* new_contents = NULL; | 1794 TabContents* new_contents = NULL; |
1760 content::PageTransition transition_type = content::PAGE_TRANSITION_LINK; | 1795 content::PageTransition transition_type = content::PAGE_TRANSITION_LINK; |
1761 if (render_manager_.web_ui()) { | 1796 if (render_manager_.web_ui()) { |
1762 // When we're a Web UI, it will provide a page transition type for us (this | 1797 // When we're a Web UI, it will provide a page transition type for us (this |
1763 // is so the new tab page can specify AUTO_BOOKMARK for automatically | 1798 // is so the new tab page can specify AUTO_BOOKMARK for automatically |
1764 // generated suggestions). | 1799 // generated suggestions). |
1765 // | 1800 // |
1766 // Note also that we hide the referrer for Web UI pages. We don't really | 1801 // Note also that we hide the referrer for Web UI pages. We don't really |
1767 // want web sites to see a referrer of "chrome://blah" (and some | 1802 // want web sites to see a referrer of "chrome://blah" (and some |
1768 // chrome: URLs might have search terms or other stuff we don't want to | 1803 // chrome: URLs might have search terms or other stuff we don't want to |
1769 // send to the site), so we send no referrer. | 1804 // send to the site), so we send no referrer. |
1770 OpenURLParams params(url, content::Referrer(), disposition, | 1805 OpenURLParams params(url, content::Referrer(), disposition, |
1771 render_manager_.web_ui()->link_transition_type(), | 1806 render_manager_.web_ui()->link_transition_type(), |
1772 false /* is_renderer_initiated */); | 1807 false /* is_renderer_initiated */); |
1773 params.transferred_global_request_id = old_request_id; | 1808 params.transferred_global_request_id = old_request_id; |
1774 new_contents = OpenURL(params); | 1809 new_contents = OpenURL(params); |
1775 transition_type = render_manager_.web_ui()->link_transition_type(); | 1810 transition_type = render_manager_.web_ui()->link_transition_type(); |
1776 } else { | 1811 } else { |
1777 OpenURLParams params(url, referrer, disposition, | 1812 OpenURLParams params(url, referrer, disposition, |
1778 content::PAGE_TRANSITION_LINK, true /* is_renderer_initiated */); | 1813 content::PAGE_TRANSITION_LINK, true /* is_renderer_initiated */, |
| 1814 opener_browsing_instance_frame_id); |
1779 params.transferred_global_request_id = old_request_id; | 1815 params.transferred_global_request_id = old_request_id; |
1780 new_contents = OpenURL(params); | 1816 new_contents = OpenURL(params); |
1781 } | 1817 } |
1782 if (new_contents) { | 1818 if (new_contents) { |
1783 // Notify observers. | 1819 // Notify observers. |
1784 FOR_EACH_OBSERVER(TabContentsObserver, observers_, | 1820 FOR_EACH_OBSERVER(TabContentsObserver, observers_, |
1785 DidOpenRequestedURL(new_contents, | 1821 DidOpenRequestedURL(new_contents, |
1786 url, | 1822 url, |
1787 referrer, | 1823 referrer, |
1788 disposition, | 1824 disposition, |
(...skipping 279 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2068 RenderWidgetHostView* rwh_view = view()->CreateViewForWidget(rvh); | 2104 RenderWidgetHostView* rwh_view = view()->CreateViewForWidget(rvh); |
2069 // Can be NULL during tests. | 2105 // Can be NULL during tests. |
2070 if (rwh_view) | 2106 if (rwh_view) |
2071 rwh_view->SetSize(view()->GetContainerSize()); | 2107 rwh_view->SetSize(view()->GetContainerSize()); |
2072 } | 2108 } |
2073 | 2109 |
2074 bool TabContents::GotResponseToLockMouseRequest(bool allowed) { | 2110 bool TabContents::GotResponseToLockMouseRequest(bool allowed) { |
2075 return render_view_host() ? | 2111 return render_view_host() ? |
2076 render_view_host()->GotResponseToLockMouseRequest(allowed) : false; | 2112 render_view_host()->GotResponseToLockMouseRequest(allowed) : false; |
2077 } | 2113 } |
OLD | NEW |