| 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 517 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 528 // TODO(creis): Should we fire even for interstitial pages? | 528 // TODO(creis): Should we fire even for interstitial pages? |
| 529 return notify_disconnection() && | 529 return notify_disconnection() && |
| 530 !showing_interstitial_page() && | 530 !showing_interstitial_page() && |
| 531 !render_view_host()->SuddenTerminationAllowed(); | 531 !render_view_host()->SuddenTerminationAllowed(); |
| 532 } | 532 } |
| 533 | 533 |
| 534 // TODO(adriansc): Remove this method once refactoring changed all call sites. | 534 // TODO(adriansc): Remove this method once refactoring changed all call sites. |
| 535 TabContents* TabContents::OpenURL(const GURL& url, | 535 TabContents* TabContents::OpenURL(const GURL& url, |
| 536 const GURL& referrer, | 536 const GURL& referrer, |
| 537 WindowOpenDisposition disposition, | 537 WindowOpenDisposition disposition, |
| 538 PageTransition::Type transition) { | 538 content::PageTransition transition) { |
| 539 return OpenURL(OpenURLParams(url, referrer, disposition, transition)); | 539 return OpenURL(OpenURLParams(url, referrer, disposition, transition)); |
| 540 } | 540 } |
| 541 | 541 |
| 542 TabContents* TabContents::OpenURL(const OpenURLParams& params) { | 542 TabContents* TabContents::OpenURL(const OpenURLParams& params) { |
| 543 if (delegate_) { | 543 if (delegate_) { |
| 544 TabContents* new_contents = delegate_->OpenURLFromTab(this, params); | 544 TabContents* new_contents = delegate_->OpenURLFromTab(this, params); |
| 545 // Notify observers. | 545 // Notify observers. |
| 546 FOR_EACH_OBSERVER(TabContentsObserver, observers_, | 546 FOR_EACH_OBSERVER(TabContentsObserver, observers_, |
| 547 DidOpenURL(params.url, params.referrer, | 547 DidOpenURL(params.url, params.referrer, |
| 548 params.disposition, params.transition)); | 548 params.disposition, params.transition)); |
| (...skipping 492 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1041 } | 1041 } |
| 1042 | 1042 |
| 1043 void TabContents::OnGoToEntryAtOffset(int offset) { | 1043 void TabContents::OnGoToEntryAtOffset(int offset) { |
| 1044 if (!delegate_ || delegate_->OnGoToEntryOffset(offset)) { | 1044 if (!delegate_ || delegate_->OnGoToEntryOffset(offset)) { |
| 1045 NavigationEntry* entry = controller_.GetEntryAtOffset(offset); | 1045 NavigationEntry* entry = controller_.GetEntryAtOffset(offset); |
| 1046 if (!entry) | 1046 if (!entry) |
| 1047 return; | 1047 return; |
| 1048 // Note that we don't call NavigationController::GotToOffset() as we don't | 1048 // Note that we don't call NavigationController::GotToOffset() as we don't |
| 1049 // want to create a pending navigation entry (it might end up lingering | 1049 // want to create a pending navigation entry (it might end up lingering |
| 1050 // http://crbug.com/51680). | 1050 // http://crbug.com/51680). |
| 1051 entry->set_transition_type(entry->transition_type() | | 1051 entry->set_transition_type( |
| 1052 PageTransition::FORWARD_BACK); | 1052 content::PageTransitionFromInt( |
| 1053 entry->transition_type() | |
| 1054 content::PAGE_TRANSITION_FORWARD_BACK)); |
| 1053 NavigateToEntry(*entry, NavigationController::NO_RELOAD); | 1055 NavigateToEntry(*entry, NavigationController::NO_RELOAD); |
| 1054 | 1056 |
| 1055 // If the entry is being restored and doesn't have a SiteInstance yet, fill | 1057 // If the entry is being restored and doesn't have a SiteInstance yet, fill |
| 1056 // it in now that we know. This allows us to find the entry when it commits. | 1058 // it in now that we know. This allows us to find the entry when it commits. |
| 1057 if (!entry->site_instance() && | 1059 if (!entry->site_instance() && |
| 1058 entry->restore_type() != NavigationEntry::RESTORE_NONE) { | 1060 entry->restore_type() != NavigationEntry::RESTORE_NONE) { |
| 1059 entry->set_site_instance(GetPendingSiteInstance()); | 1061 entry->set_site_instance(GetPendingSiteInstance()); |
| 1060 } | 1062 } |
| 1061 } | 1063 } |
| 1062 } | 1064 } |
| (...skipping 385 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1448 | 1450 |
| 1449 FOR_EACH_OBSERVER(TabContentsObserver, observers_, RenderViewGone()); | 1451 FOR_EACH_OBSERVER(TabContentsObserver, observers_, RenderViewGone()); |
| 1450 } | 1452 } |
| 1451 | 1453 |
| 1452 void TabContents::RenderViewDeleted(RenderViewHost* rvh) { | 1454 void TabContents::RenderViewDeleted(RenderViewHost* rvh) { |
| 1453 render_manager_.RenderViewDeleted(rvh); | 1455 render_manager_.RenderViewDeleted(rvh); |
| 1454 } | 1456 } |
| 1455 | 1457 |
| 1456 void TabContents::DidNavigate(RenderViewHost* rvh, | 1458 void TabContents::DidNavigate(RenderViewHost* rvh, |
| 1457 const ViewHostMsg_FrameNavigate_Params& params) { | 1459 const ViewHostMsg_FrameNavigate_Params& params) { |
| 1458 if (PageTransition::IsMainFrame(params.transition)) | 1460 if (content::PageTransitionIsMainFrame(params.transition)) |
| 1459 render_manager_.DidNavigateMainFrame(rvh); | 1461 render_manager_.DidNavigateMainFrame(rvh); |
| 1460 | 1462 |
| 1461 // Update the site of the SiteInstance if it doesn't have one yet. | 1463 // Update the site of the SiteInstance if it doesn't have one yet. |
| 1462 if (!GetSiteInstance()->has_site()) | 1464 if (!GetSiteInstance()->has_site()) |
| 1463 GetSiteInstance()->SetSite(params.url); | 1465 GetSiteInstance()->SetSite(params.url); |
| 1464 | 1466 |
| 1465 // Need to update MIME type here because it's referred to in | 1467 // Need to update MIME type here because it's referred to in |
| 1466 // UpdateNavigationCommands() called by RendererDidNavigate() to | 1468 // UpdateNavigationCommands() called by RendererDidNavigate() to |
| 1467 // determine whether or not to enable the encoding menu. | 1469 // determine whether or not to enable the encoding menu. |
| 1468 // It's updated only for the main frame. For a subframe, | 1470 // It's updated only for the main frame. For a subframe, |
| 1469 // RenderView::UpdateURL does not set params.contents_mime_type. | 1471 // RenderView::UpdateURL does not set params.contents_mime_type. |
| 1470 // (see http://code.google.com/p/chromium/issues/detail?id=2929 ) | 1472 // (see http://code.google.com/p/chromium/issues/detail?id=2929 ) |
| 1471 // TODO(jungshik): Add a test for the encoding menu to avoid | 1473 // TODO(jungshik): Add a test for the encoding menu to avoid |
| 1472 // regressing it again. | 1474 // regressing it again. |
| 1473 if (PageTransition::IsMainFrame(params.transition)) | 1475 if (content::PageTransitionIsMainFrame(params.transition)) |
| 1474 contents_mime_type_ = params.contents_mime_type; | 1476 contents_mime_type_ = params.contents_mime_type; |
| 1475 | 1477 |
| 1476 content::LoadCommittedDetails details; | 1478 content::LoadCommittedDetails details; |
| 1477 bool did_navigate = controller_.RendererDidNavigate(params, &details); | 1479 bool did_navigate = controller_.RendererDidNavigate(params, &details); |
| 1478 | 1480 |
| 1479 // Send notification about committed provisional loads. This notification is | 1481 // Send notification about committed provisional loads. This notification is |
| 1480 // different from the NAV_ENTRY_COMMITTED notification which doesn't include | 1482 // different from the NAV_ENTRY_COMMITTED notification which doesn't include |
| 1481 // the actual URL navigated to and isn't sent for AUTO_SUBFRAME navigations. | 1483 // the actual URL navigated to and isn't sent for AUTO_SUBFRAME navigations. |
| 1482 if (details.type != NavigationType::NAV_IGNORE) { | 1484 if (details.type != NavigationType::NAV_IGNORE) { |
| 1483 // For AUTO_SUBFRAME navigations, an event for the main frame is generated | 1485 // For AUTO_SUBFRAME navigations, an event for the main frame is generated |
| 1484 // that is not recorded in the navigation history. For the purpose of | 1486 // that is not recorded in the navigation history. For the purpose of |
| 1485 // tracking navigation events, we treat this event as a sub frame navigation | 1487 // tracking navigation events, we treat this event as a sub frame navigation |
| 1486 // event. | 1488 // event. |
| 1487 bool is_main_frame = did_navigate ? details.is_main_frame : false; | 1489 bool is_main_frame = did_navigate ? details.is_main_frame : false; |
| 1488 PageTransition::Type transition_type = params.transition; | 1490 content::PageTransition transition_type = params.transition; |
| 1489 // Whether or not a page transition was triggered by going backward or | 1491 // Whether or not a page transition was triggered by going backward or |
| 1490 // forward in the history is only stored in the navigation controller's | 1492 // forward in the history is only stored in the navigation controller's |
| 1491 // entry list. | 1493 // entry list. |
| 1492 if (did_navigate && | 1494 if (did_navigate && |
| 1493 (controller_.GetActiveEntry()->transition_type() & | 1495 (controller_.GetActiveEntry()->transition_type() & |
| 1494 PageTransition::FORWARD_BACK)) { | 1496 content::PAGE_TRANSITION_FORWARD_BACK)) { |
| 1495 transition_type = params.transition | PageTransition::FORWARD_BACK; | 1497 transition_type = content::PageTransitionFromInt( |
| 1498 params.transition | content::PAGE_TRANSITION_FORWARD_BACK); |
| 1496 } | 1499 } |
| 1497 // Notify observers about the commit of the provisional load. | 1500 // Notify observers about the commit of the provisional load. |
| 1498 FOR_EACH_OBSERVER(TabContentsObserver, observers_, | 1501 FOR_EACH_OBSERVER(TabContentsObserver, observers_, |
| 1499 DidCommitProvisionalLoadForFrame(params.frame_id, | 1502 DidCommitProvisionalLoadForFrame(params.frame_id, |
| 1500 is_main_frame, params.url, transition_type)); | 1503 is_main_frame, params.url, transition_type)); |
| 1501 } | 1504 } |
| 1502 | 1505 |
| 1503 if (!did_navigate) | 1506 if (!did_navigate) |
| 1504 return; // No navigation happened. | 1507 return; // No navigation happened. |
| 1505 | 1508 |
| (...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1661 content::NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME, | 1664 content::NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME, |
| 1662 Source<TabContents>(this), | 1665 Source<TabContents>(this), |
| 1663 Details<int>(&page_id)); | 1666 Details<int>(&page_id)); |
| 1664 } | 1667 } |
| 1665 | 1668 |
| 1666 void TabContents::RequestOpenURL(const GURL& url, | 1669 void TabContents::RequestOpenURL(const GURL& url, |
| 1667 const GURL& referrer, | 1670 const GURL& referrer, |
| 1668 WindowOpenDisposition disposition, | 1671 WindowOpenDisposition disposition, |
| 1669 int64 source_frame_id) { | 1672 int64 source_frame_id) { |
| 1670 TabContents* new_contents = NULL; | 1673 TabContents* new_contents = NULL; |
| 1671 PageTransition::Type transition_type = PageTransition::LINK; | 1674 content::PageTransition transition_type = content::PAGE_TRANSITION_LINK; |
| 1672 if (render_manager_.web_ui()) { | 1675 if (render_manager_.web_ui()) { |
| 1673 // When we're a Web UI, it will provide a page transition type for us (this | 1676 // When we're a Web UI, it will provide a page transition type for us (this |
| 1674 // is so the new tab page can specify AUTO_BOOKMARK for automatically | 1677 // is so the new tab page can specify AUTO_BOOKMARK for automatically |
| 1675 // generated suggestions). | 1678 // generated suggestions). |
| 1676 // | 1679 // |
| 1677 // Note also that we hide the referrer for Web UI pages. We don't really | 1680 // Note also that we hide the referrer for Web UI pages. We don't really |
| 1678 // want web sites to see a referrer of "chrome://blah" (and some | 1681 // want web sites to see a referrer of "chrome://blah" (and some |
| 1679 // chrome: URLs might have search terms or other stuff we don't want to | 1682 // chrome: URLs might have search terms or other stuff we don't want to |
| 1680 // send to the site), so we send no referrer. | 1683 // send to the site), so we send no referrer. |
| 1681 new_contents = OpenURL(url, GURL(), disposition, | 1684 new_contents = OpenURL(url, GURL(), disposition, |
| 1682 render_manager_.web_ui()->link_transition_type()); | 1685 render_manager_.web_ui()->link_transition_type()); |
| 1683 transition_type = render_manager_.web_ui()->link_transition_type(); | 1686 transition_type = render_manager_.web_ui()->link_transition_type(); |
| 1684 } else { | 1687 } else { |
| 1685 new_contents = OpenURL(url, referrer, disposition, PageTransition::LINK); | 1688 new_contents = OpenURL( |
| 1689 url, referrer, disposition, content::PAGE_TRANSITION_LINK); |
| 1686 } | 1690 } |
| 1687 if (new_contents) { | 1691 if (new_contents) { |
| 1688 // Notify observers. | 1692 // Notify observers. |
| 1689 FOR_EACH_OBSERVER(TabContentsObserver, observers_, | 1693 FOR_EACH_OBSERVER(TabContentsObserver, observers_, |
| 1690 DidOpenRequestedURL(new_contents, | 1694 DidOpenRequestedURL(new_contents, |
| 1691 url, | 1695 url, |
| 1692 referrer, | 1696 referrer, |
| 1693 disposition, | 1697 disposition, |
| 1694 transition_type, | 1698 transition_type, |
| 1695 source_frame_id)); | 1699 source_frame_id)); |
| (...skipping 269 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1965 | 1969 |
| 1966 void TabContents::set_encoding(const std::string& encoding) { | 1970 void TabContents::set_encoding(const std::string& encoding) { |
| 1967 encoding_ = content::GetContentClient()->browser()-> | 1971 encoding_ = content::GetContentClient()->browser()-> |
| 1968 GetCanonicalEncodingNameByAliasName(encoding); | 1972 GetCanonicalEncodingNameByAliasName(encoding); |
| 1969 } | 1973 } |
| 1970 | 1974 |
| 1971 void TabContents::CreateViewAndSetSizeForRVH(RenderViewHost* rvh) { | 1975 void TabContents::CreateViewAndSetSizeForRVH(RenderViewHost* rvh) { |
| 1972 RenderWidgetHostView* rwh_view = view()->CreateViewForWidget(rvh); | 1976 RenderWidgetHostView* rwh_view = view()->CreateViewForWidget(rvh); |
| 1973 rwh_view->SetSize(view()->GetContainerSize()); | 1977 rwh_view->SetSize(view()->GetContainerSize()); |
| 1974 } | 1978 } |
| OLD | NEW |