Commit f04e861b authored by dhollowa@chromium.org's avatar dhollowa@chromium.org

Move web_contents from SearchViewController to SearchTabHelper

Moves the web_contents from SearchViewController to SearchTabHelper.
This allows each NTP tab to hold its own state.

BUG=133529
TEST=Manual tests, create two new tabs, change one.  Observe differences between the two.
R=sky@chromium.org


Review URL: https://chromiumcodereview.appspot.com/10827055

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@149332 0039d316-1c4b-4281-b951-d872f2087c98
parent 8495af3b
......@@ -5,8 +5,8 @@
#include "chrome/browser/ui/search/search_tab_helper.h"
#include "chrome/browser/google/google_util.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/omnibox/omnibox_edit_model.h"
#include "chrome/browser/ui/search/search_model.h"
#include "chrome/browser/ui/tab_contents/tab_contents.h"
#include "chrome/common/url_constants.h"
#include "content/public/browser/navigation_controller.h"
......@@ -15,6 +15,7 @@
#include "content/public/browser/notification_service.h"
#include "content/public/browser/notification_types.h"
#include "content/public/browser/web_contents.h"
#include "ipc/ipc_message.h"
namespace {
......@@ -33,7 +34,7 @@ SearchTabHelper::SearchTabHelper(
bool is_search_enabled)
: WebContentsObserver(contents->web_contents()),
is_search_enabled_(is_search_enabled),
model_(new SearchModel(contents)) {
model_(contents) {
if (!is_search_enabled)
return;
......@@ -47,13 +48,30 @@ SearchTabHelper::SearchTabHelper(
SearchTabHelper::~SearchTabHelper() {
}
content::WebContents* SearchTabHelper::GetNTPWebContents() {
if (!ntp_web_contents_.get()) {
ntp_web_contents_.reset(content::WebContents::Create(
model_.tab_contents()->profile(),
model_.tab_contents()->web_contents()->GetSiteInstance(),
MSG_ROUTING_NONE,
NULL,
NULL));
ntp_web_contents_->GetController().LoadURL(
GURL(chrome::kChromeUINewTabURL),
content::Referrer(),
content::PAGE_TRANSITION_START_PAGE,
std::string());
}
return ntp_web_contents_.get();
}
void SearchTabHelper::OmniboxEditModelChanged(OmniboxEditModel* edit_model) {
if (!is_search_enabled_)
return;
if (model_->mode().is_ntp()) {
if (model_.mode().is_ntp()) {
if (edit_model->user_input_in_progress())
model_->SetMode(Mode(Mode::MODE_SEARCH, true));
model_.SetMode(Mode(Mode::MODE_SEARCH, true));
return;
}
......@@ -64,7 +82,7 @@ void SearchTabHelper::OmniboxEditModelChanged(OmniboxEditModel* edit_model) {
(edit_model->has_focus() && edit_model->user_input_in_progress())) {
mode = Mode::MODE_SEARCH;
}
model_->SetMode(Mode(mode, true));
model_.SetMode(Mode(mode, true));
}
void SearchTabHelper::NavigateToPendingEntry(
......@@ -74,6 +92,7 @@ void SearchTabHelper::NavigateToPendingEntry(
return;
UpdateModel(url);
FlushNTP(url);
}
void SearchTabHelper::Observe(
......@@ -84,6 +103,7 @@ void SearchTabHelper::Observe(
content::LoadCommittedDetails* committed_details =
content::Details<content::LoadCommittedDetails>(details).ptr();
UpdateModel(committed_details->entry->GetURL());
FlushNTP(committed_details->entry->GetURL());
}
void SearchTabHelper::UpdateModel(const GURL& url) {
......@@ -92,7 +112,14 @@ void SearchTabHelper::UpdateModel(const GURL& url) {
type = Mode::MODE_NTP;
else if (google_util::IsInstantExtendedAPIGoogleSearchUrl(url.spec()))
type = Mode::MODE_SEARCH;
model_->SetMode(Mode(type, true));
model_.SetMode(Mode(type, true));
}
void SearchTabHelper::FlushNTP(const GURL& url) {
if (!IsNTP(url) &&
!google_util::IsInstantExtendedAPIGoogleSearchUrl(url.spec())) {
ntp_web_contents_.reset();
}
}
} // namespace search
......
......@@ -7,6 +7,7 @@
#include "base/basictypes.h"
#include "base/memory/scoped_ptr.h"
#include "chrome/browser/ui/search/search_model.h"
#include "content/public/browser/notification_observer.h"
#include "content/public/browser/notification_registrar.h"
#include "content/public/browser/web_contents_observer.h"
......@@ -14,11 +15,13 @@
class OmniboxEditModel;
class TabContents;
namespace content {
class WebContents;
};
namespace chrome {
namespace search {
class SearchModel;
// Per-tab search "helper". Acts as the owner and controller of the tab's
// search UI model.
class SearchTabHelper : public content::WebContentsObserver,
......@@ -27,10 +30,13 @@ class SearchTabHelper : public content::WebContentsObserver,
SearchTabHelper(TabContents* contents, bool is_search_enabled);
virtual ~SearchTabHelper();
SearchModel* model() const {
return model_.get();
SearchModel* model() {
return &model_;
}
// Lazily create web contents for NTP. Owned by SearchTabHelper.
content::WebContents* GetNTPWebContents();
// Invoked when the OmniboxEditModel changes state in some way that might
// affect the search mode.
void OmniboxEditModelChanged(OmniboxEditModel* edit_model);
......@@ -49,10 +55,16 @@ class SearchTabHelper : public content::WebContentsObserver,
// Sets the mode of the model based on |url|.
void UpdateModel(const GURL& url);
// On navigation away from NTP and Search pages, delete |ntp_web_contents_|.
void FlushNTP(const GURL& url);
const bool is_search_enabled_;
// Model object for UI that cares about search state.
scoped_ptr<SearchModel> model_;
SearchModel model_;
// Lazily created web contents for NTP.
scoped_ptr<content::WebContents> ntp_web_contents_;
content::NotificationRegistrar registrar_;
......
......@@ -2495,7 +2495,6 @@ void BrowserView::ProcessTabSelected(TabContents* new_contents) {
if (search_view_controller_.get())
search_view_controller_->SetTabContents(new_contents);
#endif
RestackLocationBarContainer();
UpdateDevToolsForContents(new_contents);
if (!browser_->tab_strip_model()->closing_all() && GetWidget()->IsActive() &&
......@@ -2507,6 +2506,12 @@ void BrowserView::ProcessTabSelected(TabContents* new_contents) {
// Update all the UI bits.
UpdateTitleBar();
// Restacking needs to happen after other UI updates. This restores special
// "widget" stacking that governs the SearchViewController's NTP "content"
// area.
RestackLocationBarContainer();
// No need to update Toolbar because it's already updated in
// browser.cc.
}
......
......@@ -340,6 +340,7 @@ void SearchViewController::UpdateState() {
break;
}
SetState(new_state);
MaybeLoadNTP();
}
void SearchViewController::SetState(State state) {
......@@ -457,6 +458,9 @@ void SearchViewController::DestroyViews() {
omnibox_popup_view_parent_->parent()->RemoveChildView(
omnibox_popup_view_parent_);
if (content_view_)
content_view_->SetWebContents(NULL);
contents_container_->SetOverlay(NULL);
delete search_container_;
search_container_ = NULL;
......@@ -476,6 +480,14 @@ void SearchViewController::PopupVisibilityChanged() {
}
}
void SearchViewController::MaybeLoadNTP() {
if (state_ != STATE_NTP || !content_view_)
return;
content_view_->SetWebContents(
tab_contents_->search_tab_helper()->GetNTPWebContents());
}
chrome::search::SearchModel* SearchViewController::search_model() {
return tab_contents_ ? tab_contents_->search_tab_helper()->model() : NULL;
}
......
......@@ -102,6 +102,10 @@ class SearchViewController
// Invoked when the visibility of the omnibox popup changes.
void PopupVisibilityChanged();
// Load the NTP from the associated |SearchTabHelper| if in NTP mode
// and the current |tab_contents_| has changed.
void MaybeLoadNTP();
// Access active search model.
chrome::search::SearchModel* search_model();
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment