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.h" | 19 #include "content/browser/debugger/devtools_manager.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_mapper.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/load_from_memory_cache_details.h" | 25 #include "content/browser/load_from_memory_cache_details.h" |
24 #include "content/browser/load_notification_details.h" | 26 #include "content/browser/load_notification_details.h" |
25 #include "content/browser/renderer_host/render_process_host_impl.h" | 27 #include "content/browser/renderer_host/render_process_host_impl.h" |
26 #include "content/browser/renderer_host/render_view_host.h" | 28 #include "content/browser/renderer_host/render_view_host.h" |
27 #include "content/browser/renderer_host/render_widget_host_view.h" | 29 #include "content/browser/renderer_host/render_widget_host_view.h" |
28 #include "content/browser/renderer_host/resource_dispatcher_host.h" | 30 #include "content/browser/renderer_host/resource_dispatcher_host.h" |
29 #include "content/browser/renderer_host/resource_request_details.h" | 31 #include "content/browser/renderer_host/resource_request_details.h" |
30 #include "content/browser/site_instance.h" | 32 #include "content/browser/site_instance.h" |
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
155 params->current_history_list_offset = controller.last_committed_entry_index(); | 157 params->current_history_list_offset = controller.last_committed_entry_index(); |
156 params->current_history_list_length = controller.entry_count(); | 158 params->current_history_list_length = controller.entry_count(); |
157 params->url = entry.url(); | 159 params->url = entry.url(); |
158 params->referrer = entry.referrer(); | 160 params->referrer = entry.referrer(); |
159 params->transition = entry.transition_type(); | 161 params->transition = entry.transition_type(); |
160 params->state = entry.content_state(); | 162 params->state = entry.content_state(); |
161 params->navigation_type = | 163 params->navigation_type = |
162 GetNavigationType(controller.browser_context(), entry, reload_type); | 164 GetNavigationType(controller.browser_context(), entry, reload_type); |
163 params->request_time = base::Time::Now(); | 165 params->request_time = base::Time::Now(); |
164 params->extra_headers = entry.extra_headers(); | 166 params->extra_headers = entry.extra_headers(); |
| 167 params->opener_browsing_instance_frame_id = |
| 168 entry.opener_browsing_instance_frame_id(); |
165 | 169 |
166 if (delegate) | 170 if (delegate) |
167 delegate->AddNavigationHeaders(params->url, ¶ms->extra_headers); | 171 delegate->AddNavigationHeaders(params->url, ¶ms->extra_headers); |
168 } | 172 } |
169 | 173 |
170 } // namespace | 174 } // namespace |
171 | 175 |
172 | 176 |
173 // TabContents ---------------------------------------------------------------- | 177 // TabContents ---------------------------------------------------------------- |
174 | 178 |
(...skipping 26 matching lines...) Expand all Loading... |
201 #endif | 205 #endif |
202 is_showing_before_unload_dialog_(false), | 206 is_showing_before_unload_dialog_(false), |
203 opener_web_ui_type_(WebUI::kNoWebUI), | 207 opener_web_ui_type_(WebUI::kNoWebUI), |
204 closed_by_user_gesture_(false), | 208 closed_by_user_gesture_(false), |
205 minimum_zoom_percent_( | 209 minimum_zoom_percent_( |
206 static_cast<int>(content::kMinimumZoomFactor * 100)), | 210 static_cast<int>(content::kMinimumZoomFactor * 100)), |
207 maximum_zoom_percent_( | 211 maximum_zoom_percent_( |
208 static_cast<int>(content::kMaximumZoomFactor * 100)), | 212 static_cast<int>(content::kMaximumZoomFactor * 100)), |
209 temporary_zoom_settings_(false), | 213 temporary_zoom_settings_(false), |
210 content_restrictions_(0), | 214 content_restrictions_(0), |
211 view_type_(content::VIEW_TYPE_TAB_CONTENTS) { | 215 view_type_(content::VIEW_TYPE_TAB_CONTENTS), |
| 216 browsing_instance_frame_( |
| 217 browser_context->frame_mapper().AllocateNewTopLevelFrameId()) { |
212 render_manager_.Init(browser_context, site_instance, routing_id); | 218 render_manager_.Init(browser_context, site_instance, routing_id); |
213 | 219 |
| 220 // TODO(supersat): This is a hack and should be removed. |
| 221 if (routing_id > 0) { |
| 222 browser_context->frame_mapper().UpdateFrame( |
| 223 browsing_instance_frame_, render_view_host()->process()->GetID(), |
| 224 routing_id, -1 /* We don't know the frame id yet */); |
| 225 } |
| 226 |
214 // We have the initial size of the view be based on the size of the passed in | 227 // We have the initial size of the view be based on the size of the passed in |
215 // tab contents (normally a tab from the same window). | 228 // tab contents (normally a tab from the same window). |
216 view_->CreateView(base_tab_contents ? | 229 view_->CreateView(base_tab_contents ? |
217 base_tab_contents->view()->GetContainerSize() : gfx::Size()); | 230 base_tab_contents->view()->GetContainerSize() : gfx::Size()); |
218 | 231 |
219 #if defined(ENABLE_JAVA_BRIDGE) | 232 #if defined(ENABLE_JAVA_BRIDGE) |
220 java_bridge_dispatcher_host_manager_.reset( | 233 java_bridge_dispatcher_host_manager_.reset( |
221 new JavaBridgeDispatcherHostManager(this)); | 234 new JavaBridgeDispatcherHostManager(this)); |
222 #endif | 235 #endif |
223 } | 236 } |
(...skipping 23 matching lines...) Expand all Loading... |
247 host->view()->WillWmDestroy(); | 260 host->view()->WillWmDestroy(); |
248 } | 261 } |
249 #endif | 262 #endif |
250 | 263 |
251 // OnCloseStarted isn't called in unit tests. | 264 // OnCloseStarted isn't called in unit tests. |
252 if (!tab_close_start_time_.is_null()) { | 265 if (!tab_close_start_time_.is_null()) { |
253 UMA_HISTOGRAM_TIMES("Tab.Close", | 266 UMA_HISTOGRAM_TIMES("Tab.Close", |
254 base::TimeTicks::Now() - tab_close_start_time_); | 267 base::TimeTicks::Now() - tab_close_start_time_); |
255 } | 268 } |
256 | 269 |
| 270 delete browsing_instance_frame_; |
| 271 |
257 FOR_EACH_OBSERVER(TabContentsObserver, observers_, TabContentsDestroyed()); | 272 FOR_EACH_OBSERVER(TabContentsObserver, observers_, TabContentsDestroyed()); |
258 | 273 |
259 set_delegate(NULL); | 274 set_delegate(NULL); |
260 } | 275 } |
261 | 276 |
262 // TODO(cbentzel): Either remove the debugging code, or rename to SetDelegate. | 277 // TODO(cbentzel): Either remove the debugging code, or rename to SetDelegate. |
263 void TabContents::set_delegate(TabContentsDelegate* delegate) { | 278 void TabContents::set_delegate(TabContentsDelegate* delegate) { |
264 if (delegate == delegate_) | 279 if (delegate == delegate_) |
265 return; | 280 return; |
266 if (delegate_) | 281 if (delegate_) |
(...skipping 1031 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1298 // page. | 1313 // page. |
1299 UpdateTargetURL(details.entry->page_id(), GURL()); | 1314 UpdateTargetURL(details.entry->page_id(), GURL()); |
1300 } | 1315 } |
1301 | 1316 |
1302 if (!details.is_in_page) { | 1317 if (!details.is_in_page) { |
1303 // Once the main frame is navigated, we're no longer considered to have | 1318 // Once the main frame is navigated, we're no longer considered to have |
1304 // displayed insecure content. | 1319 // displayed insecure content. |
1305 displayed_insecure_content_ = false; | 1320 displayed_insecure_content_ = false; |
1306 } | 1321 } |
1307 | 1322 |
| 1323 DLOG(WARNING) << "DidNavigateMainFramePostCommit: " << |
| 1324 params.url << ", " << params.frame_id; |
| 1325 content::FrameMapper& mapper = browser_context()->frame_mapper(); |
| 1326 mapper.UpdateFrame(browsing_instance_frame_, |
| 1327 render_view_host()->process()->GetID(), |
| 1328 render_view_host()->routing_id(), |
| 1329 params.frame_id); |
| 1330 |
1308 // Notify observers about navigation. | 1331 // Notify observers about navigation. |
1309 FOR_EACH_OBSERVER(TabContentsObserver, observers_, | 1332 FOR_EACH_OBSERVER(TabContentsObserver, observers_, |
1310 DidNavigateMainFrame(details, params)); | 1333 DidNavigateMainFrame(details, params)); |
1311 } | 1334 } |
1312 | 1335 |
1313 void TabContents::DidNavigateAnyFramePostCommit( | 1336 void TabContents::DidNavigateAnyFramePostCommit( |
1314 RenderViewHost* render_view_host, | 1337 RenderViewHost* render_view_host, |
1315 const content::LoadCommittedDetails& details, | 1338 const content::LoadCommittedDetails& details, |
1316 const ViewHostMsg_FrameNavigate_Params& params) { | 1339 const ViewHostMsg_FrameNavigate_Params& params) { |
1317 // If we navigate, reset JavaScript state. This does nothing to prevent | 1340 // If we navigate, reset JavaScript state. This does nothing to prevent |
1318 // a malicious script from spamming messages, since the script could just | 1341 // a malicious script from spamming messages, since the script could just |
1319 // reload the page to stop blocking. | 1342 // reload the page to stop blocking. |
1320 if (dialog_creator_) { | 1343 if (dialog_creator_) { |
1321 dialog_creator_->ResetJavaScriptState(this); | 1344 dialog_creator_->ResetJavaScriptState(this); |
1322 dialog_creator_ = NULL; | 1345 dialog_creator_ = NULL; |
1323 } | 1346 } |
1324 | 1347 |
| 1348 // TODO(supersat): Logging for debugging purposes only. |
| 1349 DLOG(WARNING) << "DidNavigateAnyFramePostCommit: " |
| 1350 << "bifi = " << browsing_instance_frame_->id() |
| 1351 << ", process id = " << render_view_host->process()->GetID() |
| 1352 << ", rvh route = " << render_view_host->routing_id() |
| 1353 << ", frame_id = " << params.frame_id << ", url = " << |
| 1354 params.url; |
1325 // Notify observers about navigation. | 1355 // Notify observers about navigation. |
1326 FOR_EACH_OBSERVER(TabContentsObserver, observers_, | 1356 FOR_EACH_OBSERVER(TabContentsObserver, observers_, |
1327 DidNavigateAnyFrame(details, params)); | 1357 DidNavigateAnyFrame(details, params)); |
1328 } | 1358 } |
1329 | 1359 |
1330 void TabContents::UpdateMaxPageIDIfNecessary(SiteInstance* site_instance, | 1360 void TabContents::UpdateMaxPageIDIfNecessary(SiteInstance* site_instance, |
1331 RenderViewHost* rvh) { | 1361 RenderViewHost* rvh) { |
1332 // If we are creating a RVH for a restored controller, then we might | 1362 // If we are creating a RVH for a restored controller, then we might |
1333 // have more page IDs than the SiteInstance's current max page ID. We must | 1363 // have more page IDs than the SiteInstance's current max page ID. We must |
1334 // make sure that the max page ID is larger than any restored page ID. | 1364 // 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... |
1736 int32 page_id) { | 1766 int32 page_id) { |
1737 content::NotificationService::current()->Notify( | 1767 content::NotificationService::current()->Notify( |
1738 content::NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME, | 1768 content::NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME, |
1739 content::Source<TabContents>(this), | 1769 content::Source<TabContents>(this), |
1740 content::Details<int>(&page_id)); | 1770 content::Details<int>(&page_id)); |
1741 } | 1771 } |
1742 | 1772 |
1743 void TabContents::RequestOpenURL(const GURL& url, | 1773 void TabContents::RequestOpenURL(const GURL& url, |
1744 const GURL& referrer, | 1774 const GURL& referrer, |
1745 WindowOpenDisposition disposition, | 1775 WindowOpenDisposition disposition, |
1746 int64 source_frame_id) { | 1776 int64 source_frame_id, |
| 1777 int64 opener_browsing_instance_frame_id) { |
1747 TabContents* new_contents = NULL; | 1778 TabContents* new_contents = NULL; |
1748 content::PageTransition transition_type = content::PAGE_TRANSITION_LINK; | 1779 content::PageTransition transition_type = content::PAGE_TRANSITION_LINK; |
1749 if (render_manager_.web_ui()) { | 1780 if (render_manager_.web_ui()) { |
1750 // When we're a Web UI, it will provide a page transition type for us (this | 1781 // When we're a Web UI, it will provide a page transition type for us (this |
1751 // is so the new tab page can specify AUTO_BOOKMARK for automatically | 1782 // is so the new tab page can specify AUTO_BOOKMARK for automatically |
1752 // generated suggestions). | 1783 // generated suggestions). |
1753 // | 1784 // |
1754 // Note also that we hide the referrer for Web UI pages. We don't really | 1785 // Note also that we hide the referrer for Web UI pages. We don't really |
1755 // want web sites to see a referrer of "chrome://blah" (and some | 1786 // want web sites to see a referrer of "chrome://blah" (and some |
1756 // chrome: URLs might have search terms or other stuff we don't want to | 1787 // chrome: URLs might have search terms or other stuff we don't want to |
1757 // send to the site), so we send no referrer. | 1788 // send to the site), so we send no referrer. |
1758 new_contents = OpenURL(url, GURL(), disposition, | 1789 new_contents = OpenURL(url, GURL(), disposition, |
1759 render_manager_.web_ui()->link_transition_type()); | 1790 render_manager_.web_ui()->link_transition_type()); |
1760 transition_type = render_manager_.web_ui()->link_transition_type(); | 1791 transition_type = render_manager_.web_ui()->link_transition_type(); |
1761 } else { | 1792 } else { |
1762 new_contents = OpenURL(OpenURLParams( | 1793 new_contents = OpenURL(OpenURLParams( |
1763 url, referrer, disposition, content::PAGE_TRANSITION_LINK, | 1794 url, referrer, disposition, content::PAGE_TRANSITION_LINK, |
1764 true /* is_renderer_initiated */)); | 1795 true /* is_renderer_initiated */, opener_browsing_instance_frame_id)); |
1765 } | 1796 } |
1766 if (new_contents) { | 1797 if (new_contents) { |
1767 // Notify observers. | 1798 // Notify observers. |
1768 FOR_EACH_OBSERVER(TabContentsObserver, observers_, | 1799 FOR_EACH_OBSERVER(TabContentsObserver, observers_, |
1769 DidOpenRequestedURL(new_contents, | 1800 DidOpenRequestedURL(new_contents, |
1770 url, | 1801 url, |
1771 referrer, | 1802 referrer, |
1772 disposition, | 1803 disposition, |
1773 transition_type, | 1804 transition_type, |
1774 source_frame_id)); | 1805 source_frame_id)); |
(...skipping 276 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2051 RenderWidgetHostView* rwh_view = view()->CreateViewForWidget(rvh); | 2082 RenderWidgetHostView* rwh_view = view()->CreateViewForWidget(rvh); |
2052 // Can be NULL during tests. | 2083 // Can be NULL during tests. |
2053 if (rwh_view) | 2084 if (rwh_view) |
2054 rwh_view->SetSize(view()->GetContainerSize()); | 2085 rwh_view->SetSize(view()->GetContainerSize()); |
2055 } | 2086 } |
2056 | 2087 |
2057 bool TabContents::GotResponseToLockMouseRequest(bool allowed) { | 2088 bool TabContents::GotResponseToLockMouseRequest(bool allowed) { |
2058 return render_view_host() ? | 2089 return render_view_host() ? |
2059 render_view_host()->GotResponseToLockMouseRequest(allowed) : false; | 2090 render_view_host()->GotResponseToLockMouseRequest(allowed) : false; |
2060 } | 2091 } |
OLD | NEW |