diff options
26 files changed, 172 insertions, 674 deletions
diff --git a/chrome/browser/browser.cc b/chrome/browser/browser.cc index d29d7ce..bb3a4ea 100644 --- a/chrome/browser/browser.cc +++ b/chrome/browser/browser.cc @@ -1390,12 +1390,8 @@ TabContents* Browser::CreateTabContentsForURL( const GURL& url, const GURL& referrer, Profile* profile, PageTransition::Type transition, bool defer_load, SiteInstance* instance) const { - // Create an appropriate tab contents. - GURL real_url = url; - TabContentsType type = TabContents::TypeForURL(&real_url); - DCHECK(type != TAB_CONTENTS_UNKNOWN_TYPE); - - TabContents* contents = TabContents::CreateWithType(type, profile, instance); + WebContents* contents = new WebContents(profile, instance, + MSG_ROUTING_NONE, NULL); contents->SetupController(profile); if (!defer_load) { diff --git a/chrome/browser/browser.vcproj b/chrome/browser/browser.vcproj index 0ffd40e..4b16b72 100644 --- a/chrome/browser/browser.vcproj +++ b/chrome/browser/browser.vcproj @@ -2298,14 +2298,6 @@ > </File> <File - RelativePath=".\tab_contents\tab_contents_factory.cc" - > - </File> - <File - RelativePath=".\tab_contents\tab_contents_factory.h" - > - </File> - <File RelativePath=".\tab_contents\tab_contents_type.h" > </File> diff --git a/chrome/browser/browser_commands_unittest.cc b/chrome/browser/browser_commands_unittest.cc index e30bf44..5c74844 100644 --- a/chrome/browser/browser_commands_unittest.cc +++ b/chrome/browser/browser_commands_unittest.cc @@ -8,6 +8,7 @@ #include "chrome/browser/browser_list.h" #include "chrome/browser/tab_contents/navigation_controller.h" #include "chrome/browser/tab_contents/navigation_entry.h" +#include "chrome/common/url_constants.h" #include "chrome/test/browser_with_test_window_test.h" #include "chrome/test/testing_profile.h" @@ -16,10 +17,12 @@ typedef BrowserWithTestWindowTest BrowserCommandsTest; // Tests IDC_SELECT_TAB_0, IDC_SELECT_NEXT_TAB, IDC_SELECT_PREVIOUS_TAB and // IDC_SELECT_LAST_TAB. TEST_F(BrowserCommandsTest, TabNavigationAccelerators) { + GURL about_blank(chrome::kAboutBlankURL); + // Create three tabs. - AddTestingTab(browser()); - AddTestingTab(browser()); - AddTestingTab(browser()); + AddTab(browser(), about_blank); + AddTab(browser(), about_blank); + AddTab(browser(), about_blank); // Select the second tab. browser()->SelectTabContentsAt(1, false); @@ -43,13 +46,12 @@ TEST_F(BrowserCommandsTest, TabNavigationAccelerators) { // Tests IDC_DUPLICATE_TAB. TEST_F(BrowserCommandsTest, DuplicateTab) { - GURL url1 = test_url_with_path("1"); - GURL url2 = test_url_with_path("2"); - GURL url3 = test_url_with_path("3"); + GURL url1("http://foo/1"); + GURL url2("http://foo/2"); + GURL url3("http://foo/3"); // Navigate to the three urls, then go back. - AddTestingTab(browser()); - NavigateAndCommitActiveTab(url1); + AddTab(browser(), url1); NavigateAndCommitActiveTab(url2); NavigateAndCommitActiveTab(url3); @@ -81,8 +83,8 @@ TEST_F(BrowserCommandsTest, BookmarkCurrentPage) { profile()->BlockUntilBookmarkModelLoaded(); // Navigate to a url. - GURL url1 = test_url_with_path("1"); - AddTestingTab(browser()); + GURL url1("http://foo/1"); + AddTab(browser(), url1); browser()->OpenURL(url1, GURL(), CURRENT_TAB, PageTransition::TYPED); // TODO(beng): remove this once we can use WebContentses directly in testing diff --git a/chrome/browser/navigation_controller_unittest.cc b/chrome/browser/navigation_controller_unittest.cc index 3803cf5..2b7130b 100644 --- a/chrome/browser/navigation_controller_unittest.cc +++ b/chrome/browser/navigation_controller_unittest.cc @@ -15,13 +15,11 @@ #include "chrome/browser/tab_contents/navigation_entry.h" #include "chrome/browser/tab_contents/tab_contents.h" #include "chrome/browser/tab_contents/tab_contents_delegate.h" -#include "chrome/browser/tab_contents/tab_contents_factory.h" #include "chrome/common/notification_registrar.h" #include "chrome/common/notification_service.h" #include "chrome/common/render_messages.h" #include "chrome/common/stl_util-inl.h" #include "chrome/test/test_notification_tracker.h" -#include "chrome/test/test_tab_contents.h" #include "chrome/test/testing_profile.h" #include "net/base/net_util.h" #include "testing/gtest/include/gtest/gtest.h" diff --git a/chrome/browser/sessions/session_types.cc b/chrome/browser/sessions/session_types.cc index 06c95d0..b6372ad 100644 --- a/chrome/browser/sessions/session_types.cc +++ b/chrome/browser/sessions/session_types.cc @@ -11,16 +11,12 @@ // static NavigationEntry* TabNavigation::ToNavigationEntry(int page_id) const { - GURL real_url = url_; - TabContentsType type = TabContents::TypeForURL(&real_url); - DCHECK(type != TAB_CONTENTS_UNKNOWN_TYPE); - NavigationEntry* entry = new NavigationEntry( - type, + TAB_CONTENTS_WEB, NULL, // The site instance for restored tabs is sent on navigation // (WebContents::GetSiteInstanceForEntry). page_id, - real_url, + url_, referrer_, title_, // Use a transition type of reload so that we don't incorrectly diff --git a/chrome/browser/tab_contents/navigation_controller.cc b/chrome/browser/tab_contents/navigation_controller.cc index 3db44d7..cf286f2 100644 --- a/chrome/browser/tab_contents/navigation_controller.cc +++ b/chrome/browser/tab_contents/navigation_controller.cc @@ -10,10 +10,12 @@ #include "base/time.h" #include "chrome/browser/browser_about_handler.h" #include "chrome/browser/browser_process.h" +#include "chrome/browser/browser_url_handler.h" #include "chrome/browser/sessions/session_types.h" #include "chrome/browser/tab_contents/navigation_entry.h" #include "chrome/browser/tab_contents/repost_form_warning.h" #include "chrome/browser/tab_contents/site_instance.h" +#include "chrome/browser/tab_contents/web_contents.h" #include "chrome/common/navigation_types.h" #include "chrome/common/notification_service.h" #include "chrome/common/render_messages.h" @@ -85,43 +87,6 @@ bool AreURLsInPageNavigation(const GURL& existing_url, const GURL& new_url) { } // namespace -// TabContentsCollector --------------------------------------------------- - -// We never destroy a TabContents synchronously because there are some -// complex code path that cause the current TabContents to be in the call -// stack. So instead, we use a TabContentsCollector which either destroys -// the TabContents or does nothing if it has been cancelled. -class TabContentsCollector : public Task { - public: - TabContentsCollector(NavigationController* target, - TabContentsType target_type) - : target_(target), - target_type_(target_type) { - } - - void Cancel() { - target_ = NULL; - } - - virtual void Run() { - if (target_) { - // Note: this will cancel this task as a side effect so target_ is - // now null. - TabContents* tc = target_->GetTabContents(target_type_); - tc->Destroy(); - } - } - - private: - // The NavigationController we are acting on. - NavigationController* target_; - - // The TabContentsType that needs to be collected. - TabContentsType target_type_; - - DISALLOW_EVIL_CONSTRUCTORS(TabContentsCollector); -}; - // NavigationController --------------------------------------------------- // static @@ -151,13 +116,13 @@ NavigationController::NavigationController(TabContents* contents, last_committed_entry_index_(-1), pending_entry_index_(-1), transient_entry_index_(-1), - active_contents_(contents), + tab_contents_(contents), max_restored_page_id_(-1), ALLOW_THIS_IN_INITIALIZER_LIST(ssl_manager_(this, NULL)), needs_reload_(false), load_pending_entry_when_active_(false) { if (contents) - RegisterTabContents(contents); + contents->set_controller(this); DCHECK(profile_); } @@ -170,7 +135,7 @@ NavigationController::NavigationController( last_committed_entry_index_(-1), pending_entry_index_(-1), transient_entry_index_(-1), - active_contents_(NULL), + tab_contents_(NULL), max_restored_page_id_(-1), ALLOW_THIS_IN_INITIALIZER_LIST(ssl_manager_(this, NULL)), needs_reload_(true), @@ -187,9 +152,6 @@ NavigationController::NavigationController( } NavigationController::~NavigationController() { - DCHECK(tab_contents_map_.empty()); - DCHECK(tab_contents_collector_map_.empty()); - DiscardNonCommittedEntriesInternal(); NotificationService::current()->Notify( @@ -199,9 +161,7 @@ NavigationController::~NavigationController() { } TabContents* NavigationController::GetTabContents(TabContentsType t) { - // Make sure the TabContents is no longer scheduled for collection. - CancelTabContentsCollection(t); - return tab_contents_map_[t]; + return tab_contents_; } void NavigationController::Reload(bool check_for_repost) { @@ -216,7 +176,7 @@ void NavigationController::Reload(bool check_for_repost) { // The user is asking to reload a page with POST data. Prompt to make sure // they really want to do this. If they do, the dialog will call us back // with check_for_repost = false. - active_contents_->Activate(); + tab_contents_->Activate(); RunRepostFormWarningDialog(this); } else { // Base the navigation on where we are now... @@ -396,84 +356,33 @@ void NavigationController::RemoveEntryAtIndex(int index, } void NavigationController::Destroy() { - // Close all tab contents owned by this controller. We make a list on the - // stack because they are removed from the map as they are Destroyed - // (invalidating the iterators), which may or may not occur synchronously. - // We also keep track of any NULL entries in the map so that we can clean - // them out. - std::list<TabContents*> tabs_to_destroy; - std::list<TabContentsType> tab_types_to_erase; - for (TabContentsMap::iterator i = tab_contents_map_.begin(); - i != tab_contents_map_.end(); ++i) { - if (i->second) - tabs_to_destroy.push_back(i->second); - else - tab_types_to_erase.push_back(i->first); - } - - // Clean out all NULL entries in the map so that we know empty map means all - // tabs destroyed. This is needed since TabContentsWasDestroyed() won't get - // called for types that are in our map with a NULL contents. (We don't do - // this by iterating over TAB_CONTENTS_NUM_TYPES because some tests create - // additional types.) - for (std::list<TabContentsType>::iterator i = tab_types_to_erase.begin(); - i != tab_types_to_erase.end(); ++i) { - TabContentsMap::iterator map_iterator = tab_contents_map_.find(*i); - if (map_iterator != tab_contents_map_.end()) { - DCHECK(!map_iterator->second); - tab_contents_map_.erase(map_iterator); - } - } - - // Cancel all the TabContentsCollectors. - for (TabContentsCollectorMap::iterator i = - tab_contents_collector_map_.begin(); - i != tab_contents_collector_map_.end(); ++i) { - DCHECK(i->second); - i->second->Cancel(); - } - tab_contents_collector_map_.clear(); - - - // Finally destroy all the tab contents. - for (std::list<TabContents*>::iterator i = tabs_to_destroy.begin(); - i != tabs_to_destroy.end(); ++i) { - (*i)->Destroy(); - } - // We are deleted at this point. + // TODO(brettw) the destruction of TabContents/NavigationController makes no + // sense (see TabContentsWasDestroyed) + tab_contents_->Destroy(); + // We are now deleted. } void NavigationController::TabContentsWasDestroyed(TabContentsType type) { - TabContentsMap::iterator i = tab_contents_map_.find(type); - DCHECK(i != tab_contents_map_.end()); - tab_contents_map_.erase(i); - - // Make sure we cancel any collector for that TabContents. - CancelTabContentsCollection(type); - - // If that was the last tab to be destroyed, delete ourselves. - if (tab_contents_map_.empty()) - delete this; + // TODO(brettw) the destruction of TabContents/NavigationController makes no + // sense (see Destroy). + delete this; } NavigationEntry* NavigationController::CreateNavigationEntry( const GURL& url, const GURL& referrer, PageTransition::Type transition) { - GURL real_url = url; - TabContentsType type; - - // If the active contents supports |url|, use it. - // Note: in both cases, we give TabContents a chance to rewrite the URL. + // Allow the browser URL handler to rewrite the URL. This will, for example, + // remove "view-source:" from the beginning of the URL to get the URL that + // will actually be loaded. This real URL won't be shown to the user, just + // used internally. // - // TODO(brettw): The BrowserURLHandler::HandleBrowserURL call should just be - // moved here from inside TypeForURL once the tab contents types are removed. - TabContents* active = active_contents(); - if (active && active->SupportsURL(&real_url)) - type = active->type(); - else - type = TabContents::TypeForURL(&real_url); + // TODO(brettw) this should be changed to something like GURL RewriteURL(GURL) + // rather than the current complex form. + GURL loaded_url(url); + TabContentsType type; + BrowserURLHandler::HandleBrowserURL(&loaded_url, &type); - NavigationEntry* entry = new NavigationEntry(type, NULL, -1, real_url, - referrer, + NavigationEntry* entry = new NavigationEntry(TAB_CONTENTS_WEB, NULL, -1, + loaded_url, referrer, string16(), transition); entry->set_display_url(url); entry->set_user_typed_url(url); @@ -492,7 +401,7 @@ void NavigationController::AddTransientEntry(NavigationEntry* entry) { DiscardTransientEntry(); entries_.insert(entries_.begin() + index, linked_ptr<NavigationEntry>(entry)); transient_entry_index_ = index; - active_contents_->NotifyNavigationStateChanged( + tab_contents_->NotifyNavigationStateChanged( TabContents::INVALIDATE_EVERYTHING); } @@ -562,7 +471,7 @@ bool NavigationController::RendererDidNavigate( // pending entry is what this navigation is for. There is a similar TODO // w.r.t. the pending entry in RendererDidNavigateToNewPage. if (pending_entry_index_ >= 0) - pending_entry_->set_site_instance(active_contents_->GetSiteInstance()); + pending_entry_->set_site_instance(tab_contents_->GetSiteInstance()); // Do navigation-type specific actions. These will make and commit an entry. details->type = ClassifyNavigation(params); @@ -622,9 +531,6 @@ bool NavigationController::RendererDidNavigate( details->http_status_code = params.http_status_code; NotifyNavigationEntryCommitted(details); - // It is now a safe time to schedule collection for any tab contents of a - // different type, because a navigation is necessary to get back to them. - ScheduleTabContentsCollectionForInactiveTabs(); return true; } @@ -639,7 +545,7 @@ NavigationType::Type NavigationController::ClassifyNavigation( return NavigationType::NAV_IGNORE; } - if (params.page_id > active_contents_->GetMaxPageID()) { + if (params.page_id > tab_contents_->GetMaxPageID()) { // Greater page IDs than we've ever seen before are new pages. We may or may // not have a pending entry for the page, and this may or may not be the // main frame. @@ -660,8 +566,8 @@ NavigationType::Type NavigationController::ClassifyNavigation( // Now we know that the notification is for an existing page. Find that entry. int existing_entry_index = GetEntryIndexWithPageID( - active_contents_->type(), - active_contents_->GetSiteInstance(), + tab_contents_->type(), + tab_contents_->GetSiteInstance(), params.page_id); if (existing_entry_index == -1) { // The page was not found. It could have been pruned because of the limit on @@ -724,14 +630,14 @@ void NavigationController::RendererDidNavigateToNewPage( // type must always be normal. new_entry->set_page_type(NavigationEntry::NORMAL_PAGE); } else { - new_entry = new NavigationEntry(active_contents_->type()); + new_entry = new NavigationEntry(tab_contents_->type()); } new_entry->set_url(params.url); new_entry->set_referrer(params.referrer); new_entry->set_page_id(params.page_id); new_entry->set_transition_type(params.transition); - new_entry->set_site_instance(active_contents_->GetSiteInstance()); + new_entry->set_site_instance(tab_contents_->GetSiteInstance()); new_entry->set_has_post_data(params.is_post); InsertEntry(new_entry); @@ -746,8 +652,8 @@ void NavigationController::RendererDidNavigateToExistingPage( // guaranteed to exist by ClassifyNavigation, and we just need to update it // with new information from the renderer. int entry_index = GetEntryIndexWithPageID( - active_contents_->type(), - active_contents_->GetSiteInstance(), + tab_contents_->type(), + tab_contents_->GetSiteInstance(), params.page_id); DCHECK(entry_index >= 0 && entry_index < static_cast<int>(entries_.size())); @@ -758,8 +664,8 @@ void NavigationController::RendererDidNavigateToExistingPage( // assigned. entry->set_url(params.url); DCHECK(entry->site_instance() == NULL || - entry->site_instance() == active_contents_->GetSiteInstance()); - entry->set_site_instance(active_contents_->GetSiteInstance()); + entry->site_instance() == tab_contents_->GetSiteInstance()); + entry->set_site_instance(tab_contents_->GetSiteInstance()); // The entry we found in the list might be pending if the user hit // back/forward/reload. This load should commit it (since it's already in the @@ -779,8 +685,8 @@ void NavigationController::RendererDidNavigateToSamePage( // entry for this page ID. This entry is guaranteed to exist by // ClassifyNavigation. All we need to do is update the existing entry. NavigationEntry* existing_entry = GetEntryWithPageID( - active_contents_->type(), - active_contents_->GetSiteInstance(), + tab_contents_->type(), + tab_contents_->GetSiteInstance(), params.page_id); // We assign the entry's unique ID to be that of the new one. Since this is @@ -797,8 +703,8 @@ void NavigationController::RendererDidNavigateInPage( "WebKit should only tell us about in-page navs for the main frame."; // We're guaranteed to have an entry for this one. NavigationEntry* existing_entry = GetEntryWithPageID( - active_contents_->type(), - active_contents_->GetSiteInstance(), + tab_contents_->type(), + tab_contents_->GetSiteInstance(), params.page_id); // Reference fragment navigation. We're guaranteed to have the last_committed @@ -833,8 +739,8 @@ bool NavigationController::RendererDidNavigateAutoSubframe( // navigation entry. This is case "2." in NAV_AUTO_SUBFRAME comment in the // header file. In case "1." this will be a NOP. int entry_index = GetEntryIndexWithPageID( - active_contents_->type(), - active_contents_->GetSiteInstance(), + tab_contents_->type(), + tab_contents_->GetSiteInstance(), params.page_id); if (entry_index < 0 || entry_index >= static_cast<int>(entries_.size())) { @@ -882,8 +788,8 @@ void NavigationController::CommitPendingEntry() { // TabContents types. For WebContents, the IDs are generated by the // renderer, so we can't do this. details.type = NavigationType::NEW_PAGE; - pending_entry_->set_page_id(active_contents_->GetMaxPageID() + 1); - active_contents_->UpdateMaxPageID(pending_entry_->page_id()); + pending_entry_->set_page_id(tab_contents_->GetMaxPageID() + 1); + tab_contents_->UpdateMaxPageID(pending_entry_->page_id()); InsertEntry(new NavigationEntry(*pending_entry_)); } @@ -916,39 +822,10 @@ void NavigationController::DiscardNonCommittedEntries() { bool transient = transient_entry_index_ != -1; DiscardNonCommittedEntriesInternal(); - // Synchronize the active_contents_ to the last committed entry. - NavigationEntry* last_entry = GetLastCommittedEntry(); - if (last_entry && last_entry->tab_type() != active_contents_->type()) { - TabContents* from_contents = active_contents_; - from_contents->set_is_active(false); - - // Switch back to the previous tab contents. - active_contents_ = GetTabContents(last_entry->tab_type()); - DCHECK(active_contents_); - - active_contents_->set_is_active(true); - - // If we are transitioning from two types of WebContents, we need to migrate - // the download shelf if it is visible. The download shelf may have been - // created before the error that caused us to discard the entry. - TabContents::MigrateShelf(from_contents, active_contents_); - - if (from_contents->delegate()) { - from_contents->delegate()->ReplaceContents(from_contents, - active_contents_); - } - - // The entry we just discarded needed a different TabContents type. We no - // longer need it but we can't destroy it just yet because the TabContents - // is very likely involved in the current stack. - DCHECK(from_contents != active_contents_); - ScheduleTabContentsCollection(from_contents->type()); - } - // If there was a transient entry, invalidate everything so the new active // entry state is shown. if (transient) { - active_contents_->NotifyNavigationStateChanged( + tab_contents_->NotifyNavigationStateChanged( TabContents::INVALIDATE_EVERYTHING); } } @@ -988,7 +865,7 @@ void NavigationController::InsertEntry(NavigationEntry* entry) { last_committed_entry_index_ = static_cast<int>(entries_.size()) - 1; // This is a new page ID, so we need everybody to know about it. - active_contents_->UpdateMaxPageID(entry->page_id()); + tab_contents_->UpdateMaxPageID(entry->page_id()); } void NavigationController::SetWindowID(const SessionID& id) { @@ -999,7 +876,7 @@ void NavigationController::SetWindowID(const SessionID& id) { } void NavigationController::NavigateToPendingEntry(bool reload) { - TabContents* from_contents = active_contents_; + TabContents* from_contents = tab_contents_; // For session history navigations only the pending_entry_index_ is set. if (!pending_entry_) { @@ -1013,7 +890,7 @@ void NavigationController::NavigateToPendingEntry(bool reload) { TabContents* contents = GetTabContentsCreateIfNecessary(*pending_entry_); contents->set_is_active(true); - active_contents_ = contents; + tab_contents_ = contents; if (from_contents && from_contents != contents && from_contents->delegate()) from_contents->delegate()->ReplaceContents(from_contents, contents); @@ -1028,7 +905,7 @@ void NavigationController::NotifyNavigationEntryCommitted( // TODO(pkasting): http://b/1113079 Probably these explicit notification paths // should be removed, and interested parties should just listen for the // notification below instead. - active_contents_->NotifyNavigationStateChanged( + tab_contents_->NotifyNavigationStateChanged( TabContents::INVALIDATE_EVERYTHING); details->entry = GetActiveEntry(); @@ -1040,46 +917,13 @@ void NavigationController::NotifyNavigationEntryCommitted( TabContents* NavigationController::GetTabContentsCreateIfNecessary( const NavigationEntry& entry) { - TabContents* contents = GetTabContents(entry.tab_type()); - if (!contents) { - contents = TabContents::CreateWithType(entry.tab_type(), profile_, - entry.site_instance()); - if (!contents->AsWebContents()) { - // Update the max page id, otherwise the newly created TabContents may - // have reset its max page id resulting in all new navigations. We only - // do this for non-WebContents as WebContents takes care of this via its - // SiteInstance. If this creation is the result of a restore, WebContents - // handles invoking ReservePageIDRange to make sure the renderer's - // max_page_id is updated to reflect the restored range of page ids. - int32 max_page_id = contents->GetMaxPageID(); - for (size_t i = 0; i < entries_.size(); ++i) { - if (entries_[i]->tab_type() == entry.tab_type()) - max_page_id = std::max(max_page_id, entries_[i]->page_id()); - } - contents->UpdateMaxPageID(max_page_id); - } - RegisterTabContents(contents); - } - - // We should not be trying to collect this tab contents. - DCHECK(tab_contents_collector_map_.find(contents->type()) == - tab_contents_collector_map_.end()); + if (tab_contents_) + return tab_contents_; - return contents; -} - -void NavigationController::RegisterTabContents(TabContents* some_contents) { - DCHECK(some_contents); - TabContentsType t = some_contents->type(); - TabContents* tc; - if ((tc = tab_contents_map_[t]) != some_contents) { - if (tc) { - NOTREACHED() << "Should not happen. Multiple contents for one type"; - } else { - tab_contents_map_[t] = some_contents; - some_contents->set_controller(this); - } - } + tab_contents_ = new WebContents(profile_, entry.site_instance(), + MSG_ROUTING_NONE, NULL); + tab_contents_->set_controller(this); + return tab_contents_; // TODO(brettw) it's stupid to both set and return it. } // static @@ -1139,47 +983,6 @@ NavigationController* NavigationController::Clone() { return nc; } -void NavigationController::ScheduleTabContentsCollectionForInactiveTabs() { - int index = GetCurrentEntryIndex(); - if (index < 0 || GetPendingEntryIndex() != -1) - return; - - TabContentsType active_type = GetEntryAtIndex(index)->tab_type(); - for (TabContentsMap::iterator i = tab_contents_map_.begin(); - i != tab_contents_map_.end(); ++i) { - if (i->first != active_type) - ScheduleTabContentsCollection(i->first); - } -} - -void NavigationController::ScheduleTabContentsCollection(TabContentsType t) { - TabContentsCollectorMap::const_iterator i = - tab_contents_collector_map_.find(t); - - // The tab contents is already scheduled for collection. - if (i != tab_contents_collector_map_.end()) - return; - - // If we currently don't have a TabContents for t, skip. - if (tab_contents_map_.find(t) == tab_contents_map_.end()) - return; - - // Create a collector and schedule it. - TabContentsCollector* tcc = new TabContentsCollector(this, t); - tab_contents_collector_map_[t] = tcc; - MessageLoop::current()->PostTask(FROM_HERE, tcc); -} - -void NavigationController::CancelTabContentsCollection(TabContentsType t) { - TabContentsCollectorMap::iterator i = tab_contents_collector_map_.find(t); - - if (i != tab_contents_collector_map_.end()) { - DCHECK(i->second); - i->second->Cancel(); - tab_contents_collector_map_.erase(i); - } -} - void NavigationController::FinishRestore(int selected_index) { DCHECK(selected_index >= 0 && selected_index < GetEntryCount()); ConfigureEntriesForRestore(&entries_); @@ -1189,7 +992,7 @@ void NavigationController::FinishRestore(int selected_index) { last_committed_entry_index_ = selected_index; // Callers assume we have an active_contents after restoring, so set it now. - active_contents_ = GetTabContentsCreateIfNecessary(*entries_[selected_index]); + tab_contents_ = GetTabContentsCreateIfNecessary(*entries_[selected_index]); } void NavigationController::DiscardNonCommittedEntriesInternal() { diff --git a/chrome/browser/tab_contents/navigation_controller.h b/chrome/browser/tab_contents/navigation_controller.h index 04160dc..91d6602 100644 --- a/chrome/browser/tab_contents/navigation_controller.h +++ b/chrome/browser/tab_contents/navigation_controller.h @@ -313,7 +313,7 @@ class NavigationController { // // TODO(brettw) this should be removed in preference to tab_contents(). TabContents* active_contents() const { - return active_contents_; + return tab_contents_; } // Returns the tab contents associated with this controller. Non-NULL except @@ -321,7 +321,7 @@ class NavigationController { TabContents* tab_contents() const { // This currently returns the active tab contents which should be renamed to // tab_contents. - return active_contents_; + return tab_contents_; } // For use by TabContents ---------------------------------------------------- @@ -447,10 +447,6 @@ class NavigationController { // parent is |parent|. Becomes part of |entry|'s SiteInstance. TabContents* GetTabContentsCreateIfNecessary(const NavigationEntry& entry); - // Register the provided tab contents. This tab contents will be owned - // and deleted by this navigation controller - void RegisterTabContents(TabContents* some_contents); - // Sets the max restored page ID this NavigationController has seen, if it // was restored from a previous session. void set_max_restored_page_id(int max_id) { max_restored_page_id_ = max_id; } @@ -458,18 +454,6 @@ class NavigationController { NavigationEntry* CreateNavigationEntry(const GURL& url, const GURL& referrer, PageTransition::Type transition); - // Invokes ScheduleTabContentsCollection for all TabContents but the active - // one. - void ScheduleTabContentsCollectionForInactiveTabs(); - - // Schedule the TabContents currently allocated for |tc| for collection. - // The TabContents will be destroyed later from a different event. - void ScheduleTabContentsCollection(TabContentsType t); - - // Cancel the collection of the TabContents allocated for |tc|. This method - // is used when we keep using a TabContents because a provisional load failed. - void CancelTabContentsCollection(TabContentsType t); - // Invoked after session/tab restore or cloning a tab. Resets the transition // type of the entries, updates the max page id and creates the active // contents. @@ -479,11 +463,10 @@ class NavigationController { // The new entry will become the active one. void InsertEntry(NavigationEntry* entry); - // Discards the pending and transient entries without updating - // active_contents_. + // Discards the pending and transient entries. void DiscardNonCommittedEntriesInternal(); - // Discards the transient entry without updating active_contents_. + // Discards the transient entry. void DiscardTransientEntry(); // --------------------------------------------------------------------------- @@ -518,21 +501,9 @@ class NavigationController { // after the transient entry will become invalid if you navigate forward. int transient_entry_index_; - // Tab contents. One entry per type used. The tab controller owns - // every tab contents used. - typedef std::map<TabContentsType, TabContents*> TabContentsMap; - TabContentsMap tab_contents_map_; - - // A map of TabContentsType -> TabContentsCollector containing all the - // pending collectors. - typedef std::map<TabContentsType, TabContentsCollector*> - TabContentsCollectorMap; - TabContentsCollectorMap tab_contents_collector_map_; - - // The tab contents that is currently active. - // TODO(brettw) this should be renamed to tab_contents_ and comments clarified - // that it never changes. - TabContents* active_contents_; + // The tab contents associated with the controller. Possibly NULL during + // setup. + TabContents* tab_contents_; // The max restored page ID in this controller, if it was restored. We must // store this so that WebContents can tell any renderer in charge of one of diff --git a/chrome/browser/tab_contents/tab_contents.cc b/chrome/browser/tab_contents/tab_contents.cc index d24c1cd1..8c491e6 100644 --- a/chrome/browser/tab_contents/tab_contents.cc +++ b/chrome/browser/tab_contents/tab_contents.cc @@ -120,12 +120,7 @@ void TabContents::SetupController(Profile* profile) { } bool TabContents::SupportsURL(GURL* url) { - GURL u(*url); - if (TabContents::TypeForURL(&u) == type()) { - *url = u; - return true; - } - return false; + return true; } const GURL& TabContents::GetURL() const { @@ -341,22 +336,6 @@ void TabContents::CloseAllSuppressedPopups() { } #endif -void TabContents::Focus() { -#if defined(OS_WIN) - HWND container_hwnd = GetNativeView(); - if (!container_hwnd) - return; - - views::FocusManager* focus_manager = - views::FocusManager::GetFocusManager(container_hwnd); - DCHECK(focus_manager); - views::View* v = focus_manager->GetViewForWindow(container_hwnd, true); - DCHECK(v); - if (v) - v->RequestFocus(); -#endif -} - void TabContents::AddInfoBar(InfoBarDelegate* delegate) { // Look through the existing InfoBarDelegates we have for a match. If we've // already got one that matches, then we don't add the new one. diff --git a/chrome/browser/tab_contents/tab_contents.h b/chrome/browser/tab_contents/tab_contents.h index e013bdb..7ccc275 100644 --- a/chrome/browser/tab_contents/tab_contents.h +++ b/chrome/browser/tab_contents/tab_contents.h @@ -80,28 +80,6 @@ class TabContents : public PageNavigator, static void RegisterUserPrefs(PrefService* prefs); - // Factory ------------------------------------------------------------------- - // (implemented in tab_contents_factory.cc) - - // Creates a new TabContents of the given type. Will reuse the given - // instance's renderer, if it is not null. The given render view host factory - // will be passed to the new TabContents (it may be NULL). - static TabContents* CreateWithType(TabContentsType type, - Profile* profile, - SiteInstance* instance); - - // Returns the type of TabContents needed to handle the URL. |url| may - // end up being modified to contain the _real_ url being loaded if the - // parameter was an alias (such as about: urls and chrome- urls). - static TabContentsType TypeForURL(GURL* url); - - // This method can be used to register a new TabContents type dynamically, - // which can be very useful for unit testing. If factory is null, then the - // tab contents type is unregistered. Returns the previously registered - // factory for the given type or null if there was none. - static TabContentsFactory* RegisterFactory(TabContentsType type, - TabContentsFactory* factory); - // Creation & destruction ---------------------------------------------------- // Request this tab to shut down. This kills the tab's NavigationController, @@ -365,7 +343,7 @@ class TabContents : public PageNavigator, } // Make the tab the focused window. - virtual void Focus(); + virtual void Focus() = 0; // Invoked the first time this tab is getting the focus through TAB traversal. // By default this does nothing, but is overridden to set the focus for the diff --git a/chrome/browser/tab_contents/tab_contents_factory.cc b/chrome/browser/tab_contents/tab_contents_factory.cc deleted file mode 100644 index cbe5a68..0000000 --- a/chrome/browser/tab_contents/tab_contents_factory.cc +++ /dev/null @@ -1,104 +0,0 @@ -// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "base/string_util.h" -#include "chrome/browser/browser_about_handler.h" -#include "chrome/browser/browser_url_handler.h" -#include "chrome/browser/dom_ui/debugger_ui.h" -#include "chrome/browser/dom_ui/new_tab_ui.h" -#include "chrome/browser/profile.h" -#include "chrome/browser/renderer_host/render_process_host.h" -#include "chrome/browser/tab_contents/tab_contents.h" -#include "chrome/browser/tab_contents/tab_contents_factory.h" -#include "chrome/browser/tab_contents/web_contents.h" -#include "chrome/common/url_constants.h" -#include "net/base/net_util.h" - - -typedef std::map<TabContentsType, TabContentsFactory*> TabContentsFactoryMap; -static TabContentsFactoryMap* g_extra_types; // Only allocated if needed. - -// static -TabContentsType TabContentsFactory::NextUnusedType() { - int type = static_cast<int>(TAB_CONTENTS_NUM_TYPES); - if (g_extra_types) { - for (TabContentsFactoryMap::iterator i = g_extra_types->begin(); - i != g_extra_types->end(); ++i) { - type = std::max(type, static_cast<int>(i->first)); - } - } - return static_cast<TabContentsType>(type + 1); -} - -// static -TabContents* TabContents::CreateWithType(TabContentsType type, - Profile* profile, - SiteInstance* instance) { - TabContents* contents = NULL; - - switch (type) { - case TAB_CONTENTS_WEB: - contents = new WebContents(profile, instance, MSG_ROUTING_NONE, NULL); - break; - default: - if (g_extra_types) { - TabContentsFactoryMap::const_iterator it = g_extra_types->find(type); - if (it != g_extra_types->end()) { - contents = it->second->CreateInstance(); - break; - } - } - NOTREACHED() << "Don't know how to create tab contents of type " << type; - contents = NULL; - } - - return contents; -} - -// static -TabContentsType TabContents::TypeForURL(GURL* url) { - // The BrowserURLHandler::HandleBrowserURL call should just be inside the - // NavigationController once this class is deleted. - DCHECK(url); - if (g_extra_types) { - TabContentsFactoryMap::const_iterator it = g_extra_types->begin(); - for (; it != g_extra_types->end(); ++it) { - if (it->second->CanHandleURL(*url)) - return it->first; - } - } - - // Try to handle as a browser URL. If successful, |url| will end up - // containing the real url being loaded (browser url's are just an alias). - TabContentsType type(TAB_CONTENTS_UNKNOWN_TYPE); - if (BrowserURLHandler::HandleBrowserURL(url, &type)) - return type; - - // NOTE: Even the empty string can be loaded by a WebContents. - return TAB_CONTENTS_WEB; -} - -// static -TabContentsFactory* TabContents::RegisterFactory(TabContentsType type, - TabContentsFactory* factory) { - if (!g_extra_types) - g_extra_types = new TabContentsFactoryMap; - - TabContentsFactory* prev_factory = NULL; - TabContentsFactoryMap::const_iterator prev = g_extra_types->find(type); - if (prev != g_extra_types->end()) - prev_factory = prev->second; - - if (factory) { - g_extra_types->insert(TabContentsFactoryMap::value_type(type, factory)); - } else { - g_extra_types->erase(type); - if (g_extra_types->empty()) { - delete g_extra_types; - g_extra_types = NULL; - } - } - - return prev_factory; -} diff --git a/chrome/browser/tab_contents/tab_contents_factory.h b/chrome/browser/tab_contents/tab_contents_factory.h deleted file mode 100644 index e140bc7..0000000 --- a/chrome/browser/tab_contents/tab_contents_factory.h +++ /dev/null @@ -1,29 +0,0 @@ -// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef CHROME_BROWSER_TAB_CONTENTS_TAB_CONTENTS_FACTORY_H_ -#define CHROME_BROWSER_TAB_CONTENTS_TAB_CONTENTS_FACTORY_H_ - -#include <string> -#include "chrome/browser/tab_contents/tab_contents_type.h" - -class GURL; -class TabContents; - -// Extend from this class to implement a custom tab contents type. See -// TabContents::RegisterFactory. -class TabContentsFactory { - public: - // Returns the next unused TabContentsType after TAB_CONTENTS_NUM_TYPES. - static TabContentsType NextUnusedType(); - - // Returns a new TabContents instance of the associated type. - virtual TabContents* CreateInstance() = 0; - - // Returns true if this factory can be used to create a TabContents instance - // capable of handling the given URL. NOTE: the given url can be empty. - virtual bool CanHandleURL(const GURL& url) = 0; -}; - -#endif // CHROME_BROWSER_TAB_CONTENTS_TAB_CONTENTS_FACTORY_H_ diff --git a/chrome/browser/tab_contents/web_contents.cc b/chrome/browser/tab_contents/web_contents.cc index 81c3e7a..45b4bbd 100644 --- a/chrome/browser/tab_contents/web_contents.cc +++ b/chrome/browser/tab_contents/web_contents.cc @@ -708,6 +708,10 @@ bool WebContents::IsActiveEntry(int32 page_id) { active_entry->page_id() == page_id); } +void WebContents::Focus() { + view_->Focus(); +} + void WebContents::SetInitialFocus(bool reverse) { render_view_host()->SetInitialFocus(reverse); } diff --git a/chrome/browser/tab_contents/web_contents.h b/chrome/browser/tab_contents/web_contents.h index 09cdba3..b89efd3 100644 --- a/chrome/browser/tab_contents/web_contents.h +++ b/chrome/browser/tab_contents/web_contents.h @@ -146,6 +146,7 @@ class WebContents : public TabContents, virtual bool IsBookmarkBarAlwaysVisible(); virtual void SetDownloadShelfVisible(bool visible); virtual void PopupNotificationVisibilityChanged(bool visible); + virtual void Focus(); // Retarded pass-throughs to the view. // TODO(brettw) fix this, tab contents shouldn't have these methods, probably diff --git a/chrome/browser/tab_contents/web_contents_view.h b/chrome/browser/tab_contents/web_contents_view.h index 2efd6f2..ef20996 100644 --- a/chrome/browser/tab_contents/web_contents_view.h +++ b/chrome/browser/tab_contents/web_contents_view.h @@ -110,6 +110,9 @@ class WebContentsView : public RenderViewHostDelegate::View { // RenderWidgetHost is deleted. Removes |host| from internal maps. void RenderWidgetHostDestroyed(RenderWidgetHost* host); + // Sets focus to the native widget for this tab. + virtual void Focus() = 0; + // Sets focus to the appropriate element when the tab contents is shown the // first time. virtual void SetInitialFocus() = 0; diff --git a/chrome/browser/tab_contents/web_contents_view_gtk.cc b/chrome/browser/tab_contents/web_contents_view_gtk.cc index 809c6c9..95d44e5 100644 --- a/chrome/browser/tab_contents/web_contents_view_gtk.cc +++ b/chrome/browser/tab_contents/web_contents_view_gtk.cc @@ -166,6 +166,9 @@ bool WebContentsViewGtk::GetFindBarWindowInfo(gfx::Point* position, return false; } +void WebContentsViewGtk::Focus() { +} + void WebContentsViewGtk::SetInitialFocus() { if (web_contents()->FocusLocationBarByDefault()) web_contents()->delegate()->SetFocusToLocationBar(); diff --git a/chrome/browser/tab_contents/web_contents_view_gtk.h b/chrome/browser/tab_contents/web_contents_view_gtk.h index 0a56287..ab8c9b38 100644 --- a/chrome/browser/tab_contents/web_contents_view_gtk.h +++ b/chrome/browser/tab_contents/web_contents_view_gtk.h @@ -39,6 +39,7 @@ class WebContentsViewGtk : public WebContentsView { virtual void ReparentFindWindow(Browser* new_browser) const; virtual bool GetFindBarWindowInfo(gfx::Point* position, bool* fully_visible) const; + virtual void Focus(); virtual void SetInitialFocus(); virtual void StoreFocus(); virtual void RestoreFocus(); diff --git a/chrome/browser/tab_contents/web_contents_view_mac.h b/chrome/browser/tab_contents/web_contents_view_mac.h index f85bc98..2e33317 100644 --- a/chrome/browser/tab_contents/web_contents_view_mac.h +++ b/chrome/browser/tab_contents/web_contents_view_mac.h @@ -54,6 +54,7 @@ class WebContentsViewMac : public WebContentsView, virtual void HideFindBar(bool end_session); virtual bool GetFindBarWindowInfo(gfx::Point* position, bool* fully_visible) const; + virtual void Focus(); virtual void SetInitialFocus(); virtual void StoreFocus(); virtual void RestoreFocus(); diff --git a/chrome/browser/tab_contents/web_contents_view_mac.mm b/chrome/browser/tab_contents/web_contents_view_mac.mm index 793e42b..9feadc1 100644 --- a/chrome/browser/tab_contents/web_contents_view_mac.mm +++ b/chrome/browser/tab_contents/web_contents_view_mac.mm @@ -145,6 +145,9 @@ bool WebContentsViewMac::GetFindBarWindowInfo(gfx::Point* position, return true; } +void WebContentsViewMac::Focus() { +} + void WebContentsViewMac::SetInitialFocus() { // TODO(port) } diff --git a/chrome/browser/tab_contents/web_contents_view_win.cc b/chrome/browser/tab_contents/web_contents_view_win.cc index 8b949c9..863fa86 100644 --- a/chrome/browser/tab_contents/web_contents_view_win.cc +++ b/chrome/browser/tab_contents/web_contents_view_win.cc @@ -229,6 +229,23 @@ void WebContentsViewWin::SizeContents(const gfx::Size& size) { WasSized(size); } +void WebContentsViewWin::Focus() { + /*HWND container_hwnd = GetNativeView(); + if (!container_hwnd) + return; + + views::FocusManager* focus_manager = + views::FocusManager::GetFocusManager(container_hwnd); + if (!focus_manager) + return; // During testing we have no focus manager. + views::View* v = focus_manager->GetViewForWindow(container_hwnd, true); + DCHECK(v); + if (v) + v->RequestFocus();*/ + views::View* asdf = GetRootView(); + asdf->RequestFocus(); +} + void WebContentsViewWin::SetInitialFocus() { if (web_contents()->FocusLocationBarByDefault()) web_contents()->delegate()->SetFocusToLocationBar(); diff --git a/chrome/browser/tab_contents/web_contents_view_win.h b/chrome/browser/tab_contents/web_contents_view_win.h index 6eeb77e..c3a33e6 100644 --- a/chrome/browser/tab_contents/web_contents_view_win.h +++ b/chrome/browser/tab_contents/web_contents_view_win.h @@ -39,6 +39,7 @@ class WebContentsViewWin : public WebContentsView, virtual void SetPageTitle(const std::wstring& title); virtual void Invalidate(); virtual void SizeContents(const gfx::Size& size); + virtual void Focus(); virtual void SetInitialFocus(); virtual void StoreFocus(); virtual void RestoreFocus(); diff --git a/chrome/chrome.gyp b/chrome/chrome.gyp index cfa4ee4..e5c2b58 100644 --- a/chrome/chrome.gyp +++ b/chrome/chrome.gyp @@ -1080,8 +1080,6 @@ 'browser/tab_contents/tab_contents.cc', 'browser/tab_contents/tab_contents.h', 'browser/tab_contents/tab_contents_delegate.h', - 'browser/tab_contents/tab_contents_factory.cc', - 'browser/tab_contents/tab_contents_factory.h', 'browser/tab_contents/tab_contents_type.h', 'browser/tab_contents/tab_util.cc', 'browser/tab_contents/tab_util.h', @@ -2248,8 +2246,6 @@ 'test/in_process_browser_test.h', 'test/test_notification_tracker.cc', 'test/test_notification_tracker.h', - 'test/test_tab_contents.cc', - 'test/test_tab_contents.h', 'test/v8_unit_test.cc', 'test/v8_unit_test.h', 'views/controls/label_unittest.cc', diff --git a/chrome/test/browser_with_test_window_test.cc b/chrome/test/browser_with_test_window_test.cc index 3c2e879..1881a54 100644 --- a/chrome/test/browser_with_test_window_test.cc +++ b/chrome/test/browser_with_test_window_test.cc @@ -9,7 +9,9 @@ #include "chrome/test/test_browser_window.h" #include "chrome/test/testing_profile.h" -BrowserWithTestWindowTest::BrowserWithTestWindowTest() { +BrowserWithTestWindowTest::BrowserWithTestWindowTest() + : rph_factory_(), + rvh_factory_(&rph_factory_) { OleInitialize(NULL); } @@ -17,8 +19,6 @@ void BrowserWithTestWindowTest::SetUp() { // NOTE: I have a feeling we're going to want virtual methods for creating // these, as such they're in SetUp instead of the constructor. profile_.reset(new TestingProfile()); - tab_contents_factory_.reset( - TestTabContentsFactory::CreateAndRegisterFactory()); browser_.reset(new Browser(Browser::TYPE_NORMAL, profile())); window_.reset(new TestBrowserWindow(browser())); browser_->set_window(window_.get()); @@ -33,7 +33,6 @@ BrowserWithTestWindowTest::~BrowserWithTestWindowTest() { // loop. browser_.reset(NULL); window_.reset(NULL); - tab_contents_factory_.reset(NULL); profile_.reset(NULL); MessageLoop::current()->PostTask(FROM_HERE, new MessageLoop::QuitTask); @@ -42,31 +41,35 @@ BrowserWithTestWindowTest::~BrowserWithTestWindowTest() { OleUninitialize(); } -void BrowserWithTestWindowTest::AddTestingTab(Browser* browser) { - TestTabContents* tab_contents = tab_contents_factory_->CreateInstanceImpl(); - tab_contents->SetupController(profile()); - browser->tabstrip_model()->AddTabContents( - tab_contents, 0, PageTransition::TYPED, true); +TestRenderViewHost* BrowserWithTestWindowTest::TestRenderViewHostForTab( + TabContents* tab_contents) { + return static_cast<TestRenderViewHost*>( + tab_contents->AsWebContents()->render_view_host()); +} + +void BrowserWithTestWindowTest::AddTab(Browser* browser, const GURL& url) { + TabContents* new_tab = browser->AddTabWithURL(url, GURL(), + PageTransition::TYPED, true, + 0, NULL); + CommitPendingLoadAsNewNavigation(new_tab->controller(), url); +} + +void BrowserWithTestWindowTest::CommitPendingLoadAsNewNavigation( + NavigationController* controller, + const GURL& url) { + TestRenderViewHost* test_rvh = + TestRenderViewHostForTab(controller->tab_contents()); + MockRenderProcessHost* mock_rph = static_cast<MockRenderProcessHost*>( + test_rvh->process()); + + test_rvh->SendNavigate(mock_rph->max_page_id() + 1, url); } void BrowserWithTestWindowTest::NavigateAndCommit( NavigationController* controller, const GURL& url) { controller->LoadURL(url, GURL(), 0); - - // Commit the load. - // TODO(brettw) once this uses TestRenderViewHost, we should call SendNavigate - // on it instead of doing this stuff. - ViewHostMsg_FrameNavigate_Params params; - params.page_id = reinterpret_cast<TestTabContents*>( - controller->tab_contents())->GetNextPageID(); - params.url = url; - params.transition = PageTransition::LINK; - params.should_update_history = false; - params.gesture = NavigationGestureUser; - params.is_post = false; - NavigationController::LoadCommittedDetails details; - controller->RendererDidNavigate(params, &details); + CommitPendingLoadAsNewNavigation(controller, url); } void BrowserWithTestWindowTest::NavigateAndCommitActiveTab(const GURL& url) { diff --git a/chrome/test/browser_with_test_window_test.h b/chrome/test/browser_with_test_window_test.h index dfcb520..eb5d02a 100644 --- a/chrome/test/browser_with_test_window_test.h +++ b/chrome/test/browser_with_test_window_test.h @@ -8,24 +8,33 @@ #include <string> #include "base/message_loop.h" -#include "chrome/test/test_tab_contents.h" +#include "chrome/browser/renderer_host/test_render_view_host.h" #include "testing/gtest/include/gtest/gtest.h" class Browser; +class GURL; +class NavigationController; class TestBrowserWindow; class TestingProfile; // Base class for browser based unit tests. BrowserWithTestWindowTest creates a // Browser with a TestingProfile and TestBrowserWindow. To add a tab use -// AddTestingTab. This adds a Tab whose TabContents is a TestTabContents. -// Use the method test_url_with_path to obtain a URL that targets the -// TestTabContents. For example, the following adds a tab and navigates to +// AddTestingTab. For example, the following adds a tab and navigates to // two URLs that target the TestTabContents: -// AddTestingTab(browser()); -// browser()->OpenURL(test_url_with_path("1"), GURL(), CURRENT_TAB, -// PageTransition::TYPED); -// browser()->OpenURL(test_url_with_path("1"), GURL(), CURRENT_TAB, +// +// // Add a new tab and navigate it. This will be at index 0. +// AddTab(browser(), GURL("http://foo/1")); +// NavigationController* controller = +// browser()->GetTabContentsAt(0)->controller(); +// +// // Navigate somewhere else. +// GURL url2("http://foo/2"); +// NavigateAndCommit(controller, url2); +// +// // This is equivalent to the above, and lets you test pending navigations. +// browser()->OpenURL(GURL("http://foo/2"), GURL(), CURRENT_TAB, // PageTransition::TYPED); +// CommitPendingLoadAsNewNavigation(controller, url2); // // Subclasses must invoke BrowserWithTestWindowTest::SetUp as it is responsible // for creating the various objects of this class. @@ -36,21 +45,23 @@ class BrowserWithTestWindowTest : public testing::Test { virtual void SetUp(); + // Returns the current RenderViewHost for the current tab as a + // TestRenderViewHost. + TestRenderViewHost* TestRenderViewHostForTab(TabContents* tab_contents); + protected: Browser* browser() const { return browser_.get(); } TestingProfile* profile() const { return profile_.get(); } - // Adds a tab to |browser| whose TabContents comes from a - // TestTabContentsFactory. Use test_url_with_path to obtain a URL that - // that uses the newly created TabContents. - void AddTestingTab(Browser* browser); + // Adds a tab to |browser| with the given URL and commits the load. + // This is a convenience function. The new tab will be added at index 0. + void AddTab(Browser* browser, const GURL& url); - // Returns a GURL that targets the testing TabContents created by way of - // AddTestingTab. - GURL test_url_with_path(const std::string& path) const { - return tab_contents_factory_->test_url_with_path(path); - } + // Commits the pending load as if we went to a new page (as opposed to back or + // forward). + void CommitPendingLoadAsNewNavigation(NavigationController* controller, + const GURL& url); // Creates a pending navigation on the given navigation controller to the // given URL with the default parameters and the commits the load with a page @@ -67,10 +78,12 @@ class BrowserWithTestWindowTest : public testing::Test { MessageLoopForUI ui_loop_; scoped_ptr<TestingProfile> profile_; - scoped_ptr<TestTabContentsFactory> tab_contents_factory_; scoped_ptr<TestBrowserWindow> window_; scoped_ptr<Browser> browser_; + MockRenderProcessHostFactory rph_factory_; + TestRenderViewHostFactory rvh_factory_; + DISALLOW_COPY_AND_ASSIGN(BrowserWithTestWindowTest); }; diff --git a/chrome/test/test_tab_contents.cc b/chrome/test/test_tab_contents.cc deleted file mode 100644 index 92bec46..0000000 --- a/chrome/test/test_tab_contents.cc +++ /dev/null @@ -1,20 +0,0 @@ -// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "chrome/test/test_tab_contents.h" - -#include "chrome/browser/tab_contents/navigation_entry.h" -#include "chrome/common/render_messages.h" - -// static -SiteInstance* TestTabContents::site_instance_ = NULL; - -TestTabContents::TestTabContents(TabContentsType type) - : TabContents(type), - next_page_id_(1) { -} - -bool TestTabContents::NavigateToPendingEntry(bool reload) { - return true; -} diff --git a/chrome/test/test_tab_contents.h b/chrome/test/test_tab_contents.h deleted file mode 100644 index 91d3114..0000000 --- a/chrome/test/test_tab_contents.h +++ /dev/null @@ -1,102 +0,0 @@ -// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef CHROME_BROWSER_TEST_TEST_TAB_CONTENTS_H_ -#define CHROME_BROWSER_TEST_TEST_TAB_CONTENTS_H_ - -#include "base/string_util.h" -#include "chrome/browser/tab_contents/tab_contents_factory.h" -#include "chrome/browser/tab_contents/tab_contents.h" - -// TabContents typed created by TestTabContentsFactory. -class TestTabContents : public TabContents { - public: - explicit TestTabContents(TabContentsType type); - - // Sets the site instance used by *ALL* TestTabContents. - static void set_site_instance(SiteInstance* site_instance) { - site_instance_ = site_instance; - } - - int GetNextPageID() { - return next_page_id_++; - } - - // Overridden from TabContents so we can provide a non-NULL site instance in - // some cases. To use, the test will have to set the site_instance_ member - // variable to some site instance it creates. - virtual SiteInstance* GetSiteInstance() const { - return site_instance_; - } - - // Overrides to be more like WebContents (don't autocommit). - virtual bool NavigateToPendingEntry(bool reload); - - private: - static SiteInstance* site_instance_; - - int next_page_id_; - - DISALLOW_COPY_AND_ASSIGN(TestTabContents); -}; - -// TestTabContentsFactory is a TabContentsFactory that can be used for tests. -// -// Use the CreateAndRegisterFactory method to create and register a new -// TestTabContentsFactory. You can use scheme() to determine the resulting -// scheme and type() for the resulting TabContentsType. -// -// TestTabContentsFactory unregisters itself from the TabContentsFactory in its -// destructor. -class TestTabContentsFactory : public TabContentsFactory { - public: - // Creates a new TestTabContentsFactory and registers it for the next - // free TabContentsType. The destructor unregisters the factory. - static TestTabContentsFactory* CreateAndRegisterFactory() { - TabContentsType new_type = TabContentsFactory::NextUnusedType(); - TestTabContentsFactory* new_factory = - new TestTabContentsFactory( - new_type, "test" + IntToString(static_cast<int>(new_type))); - TabContents::RegisterFactory(new_type, new_factory); - return new_factory; - } - - TestTabContentsFactory(TabContentsType type, const std::string& scheme) - : type_(type), - scheme_(scheme) { - } - - ~TestTabContentsFactory() { - TabContents::RegisterFactory(type_, NULL); - } - - virtual TabContents* CreateInstance() { - return CreateInstanceImpl(); - } - - TestTabContents* CreateInstanceImpl() { - return new TestTabContents(type_); - } - - virtual bool CanHandleURL(const GURL& url) { - return url.SchemeIs(scheme_.c_str()); - } - - const std::string& scheme() const { return scheme_; } - - GURL test_url_with_path(const std::string& path) const { - return GURL(scheme() + ":" + path); - } - - TabContentsType type() const { return type_; } - - private: - TabContentsType type_; - - const std::string scheme_; - - DISALLOW_COPY_AND_ASSIGN(TestTabContentsFactory); -}; - -#endif // CHROME_BROWSER_TEST_TEST_TAB_CONTENTS_H_ diff --git a/chrome/test/unit/unittests.vcproj b/chrome/test/unit/unittests.vcproj index 4711923f..ecf0c17 100644 --- a/chrome/test/unit/unittests.vcproj +++ b/chrome/test/unit/unittests.vcproj @@ -835,14 +835,6 @@ > </File> <File - RelativePath="..\test_tab_contents.cc" - > - </File> - <File - RelativePath="..\test_tab_contents.h" - > - </File> - <File RelativePath="..\..\browser\tab_contents\test_web_contents.cc" > </File> |