Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(7299)

Unified Diff: chrome/browser/ui/views/location_bar/location_bar_view.cc

Issue 9479008: Re-factor location bar/toolbar code to get rid of the browser dependency. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: win fix Created 8 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/ui/views/location_bar/location_bar_view.cc
diff --git a/chrome/browser/ui/views/location_bar/location_bar_view.cc b/chrome/browser/ui/views/location_bar/location_bar_view.cc
index fc64f36ead2245082959674e3eab6955df11c302..2990bed15831385618b690ee0f18e6b676d5c2fe 100644
--- a/chrome/browser/ui/views/location_bar/location_bar_view.cc
+++ b/chrome/browser/ui/views/location_bar/location_bar_view.cc
@@ -115,11 +115,14 @@ static const int kBorderRoundCornerWidth = 5;
// LocationBarView -----------------------------------------------------------
-LocationBarView::LocationBarView(Browser* browser,
+LocationBarView::LocationBarView(Profile* profile,
+ CommandUpdater* command_updater,
ToolbarModel* model,
Delegate* delegate,
Mode mode)
- : browser_(browser),
+ : profile_(profile),
+ command_updater_(command_updater),
+ browser_(NULL),
model_(model),
delegate_(delegate),
disposition_(CURRENT_TAB),
@@ -152,7 +155,7 @@ LocationBarView::LocationBarView(Browser* browser,
}
edit_bookmarks_enabled_.Init(prefs::kEditBookmarksEnabled,
- browser_->profile()->GetPrefs(), this);
+ profile_->GetPrefs(), this);
}
LocationBarView::~LocationBarView() {
@@ -190,12 +193,11 @@ void LocationBarView::Init() {
// URL edit field.
// View container for URL edit field.
- Profile* profile = browser_->profile();
location_entry_.reset(OmniboxView::CreateOmniboxView(
this,
model_,
- profile,
- browser_->command_updater(),
+ profile_,
+ command_updater_,
mode_ == POPUP,
this));
SetLocationEntryFocusable(true);
@@ -205,12 +207,12 @@ void LocationBarView::Init() {
selected_keyword_view_ = new SelectedKeywordView(
kSelectedKeywordBackgroundImages, IDR_KEYWORD_SEARCH_MAGNIFIER,
- GetColor(ToolbarModel::NONE, TEXT), profile);
+ GetColor(ToolbarModel::NONE, TEXT), profile_);
AddChildView(selected_keyword_view_);
selected_keyword_view_->SetFont(font_);
selected_keyword_view_->SetVisible(false);
- keyword_hint_view_ = new KeywordHintView(profile);
+ keyword_hint_view_ = new KeywordHintView(profile_);
AddChildView(keyword_hint_view_);
keyword_hint_view_->SetVisible(false);
keyword_hint_view_->SetFont(font_);
@@ -225,7 +227,7 @@ void LocationBarView::Init() {
// The star is not visible in popups and in the app launcher.
if (browser_defaults::bookmarks_enabled && (mode_ == NORMAL)) {
- star_view_ = new StarView(browser_->command_updater());
+ star_view_ = new StarView(command_updater_);
AddChildView(star_view_);
star_view_->SetVisible(true);
}
@@ -302,7 +304,7 @@ void LocationBarView::SetAnimationOffset(int offset) {
void LocationBarView::Update(const WebContents* tab_for_state_restoring) {
bool star_enabled = star_view_ && !model_->input_in_progress() &&
edit_bookmarks_enabled_.GetValue();
- browser_->command_updater()->UpdateCommandEnabled(
+ command_updater_->UpdateCommandEnabled(
IDC_BOOKMARK_PAGE, star_enabled);
if (star_view_)
star_view_->SetVisible(star_enabled);
@@ -315,6 +317,14 @@ void LocationBarView::Update(const WebContents* tab_for_state_restoring) {
OnChanged();
}
+Browser* LocationBarView::FindBrowser() {
+ if (!browser_ && delegate_->GetTabContentsWrapper()) {
+ WebContents* tab = delegate_->GetTabContentsWrapper()->web_contents();
+ browser_ = Browser::GetBrowserForController(&tab->GetController(), NULL);
+ }
+ return browser_;
+}
+
void LocationBarView::UpdateContentSettingsIcons() {
RefreshContentSettingViews();
@@ -398,7 +408,7 @@ void LocationBarView::SetStarToggled(bool on) {
}
void LocationBarView::ShowStarBubble(const GURL& url, bool newly_bookmarked) {
- browser::ShowBookmarkBubbleView(star_view_, browser_->profile(), url,
+ browser::ShowBookmarkBubbleView(star_view_, profile_, url,
newly_bookmarked);
}
@@ -564,13 +574,13 @@ void LocationBarView::Layout() {
if (show_selected_keyword) {
if (selected_keyword_view_->keyword() != keyword) {
selected_keyword_view_->SetKeyword(keyword);
- Profile* profile = browser_->profile();
const TemplateURL* template_url =
- TemplateURLServiceFactory::GetForProfile(profile)->
+ TemplateURLServiceFactory::GetForProfile(profile_)->
GetTemplateURLForKeyword(keyword);
if (template_url && template_url->IsExtensionKeyword()) {
- const SkBitmap& bitmap = profile->GetExtensionService()->GetOmniboxIcon(
- template_url->GetExtensionId());
+ const SkBitmap& bitmap =
+ profile_->GetExtensionService()->GetOmniboxIcon(
+ template_url->GetExtensionId());
selected_keyword_view_->SetImage(bitmap);
selected_keyword_view_->set_is_extension_icon(true);
} else {
@@ -818,16 +828,16 @@ void LocationBarView::OnAutocompleteAccept(
transition_ = content::PageTransitionFromInt(
transition | content::PAGE_TRANSITION_FROM_ADDRESS_BAR);
- if (browser_->command_updater()) {
+ if (command_updater_) {
if (!alternate_nav_url.is_valid()) {
- browser_->command_updater()->ExecuteCommand(IDC_OPEN_CURRENT_URL);
+ command_updater_->ExecuteCommand(IDC_OPEN_CURRENT_URL);
} else {
AlternateNavURLFetcher* fetcher =
new AlternateNavURLFetcher(alternate_nav_url);
// The AlternateNavURLFetcher will listen for the pending navigation
// notification that will be issued as a result of the "open URL." It
// will automatically install itself into that navigation controller.
- browser_->command_updater()->ExecuteCommand(IDC_OPEN_CURRENT_URL);
+ command_updater_->ExecuteCommand(IDC_OPEN_CURRENT_URL);
if (fetcher->state() == AlternateNavURLFetcher::NOT_STARTED) {
// I'm not sure this should be reachable, but I'm not also sure enough
// that it shouldn't to stick in a NOTREACHED(). In any case, this is
@@ -934,7 +944,7 @@ void LocationBarView::RefreshPageActionViews() {
if (mode_ != NORMAL)
return;
- ExtensionService* service = browser_->profile()->GetExtensionService();
+ ExtensionService* service = profile_->GetExtensionService();
if (!service)
return;
@@ -1006,7 +1016,7 @@ void LocationBarView::OnMouseEvent(const views::MouseEvent& event, UINT msg) {
void LocationBarView::ShowFirstRunBubbleInternal() {
#if !defined(OS_CHROMEOS)
// First run bubble doesn't make sense for Chrome OS.
- FirstRunBubble::ShowBubble(browser_->profile(), location_icon_view_);
+ FirstRunBubble::ShowBubble(profile_, location_icon_view_);
#endif
}
@@ -1103,7 +1113,7 @@ bool LocationBarView::CanStartDragForView(View* sender,
void LocationBarView::ShowFirstRunBubble() {
// Wait until search engines have loaded to show the first run bubble.
TemplateURLService* url_service =
- TemplateURLServiceFactory::GetForProfile(browser_->profile());
+ TemplateURLServiceFactory::GetForProfile(profile_);
if (!url_service->loaded()) {
template_url_service_ = url_service;
template_url_service_->AddObserver(this);

Powered by Google App Engine
This is Rietveld 408576698