diff options
-rw-r--r-- | chrome/browser/cocoa/autocomplete_text_field_cell_unittest.mm | 4 | ||||
-rw-r--r-- | chrome/browser/cocoa/autocomplete_text_field_unittest.mm | 12 | ||||
-rw-r--r-- | chrome/browser/cocoa/location_bar_view_mac.h | 15 | ||||
-rw-r--r-- | chrome/browser/cocoa/location_bar_view_mac.mm | 30 | ||||
-rw-r--r-- | chrome/browser/cocoa/toolbar_controller.mm | 4 | ||||
-rw-r--r-- | chrome/browser/gtk/location_bar_view_gtk.cc | 14 | ||||
-rw-r--r-- | chrome/browser/gtk/location_bar_view_gtk.h | 3 | ||||
-rw-r--r-- | chrome/browser/views/location_bar_view.cc | 6 | ||||
-rw-r--r-- | chrome/browser/views/location_bar_view.h | 9 |
9 files changed, 59 insertions, 38 deletions
diff --git a/chrome/browser/cocoa/autocomplete_text_field_cell_unittest.mm b/chrome/browser/cocoa/autocomplete_text_field_cell_unittest.mm index 7c5246b..a83cdab 100644 --- a/chrome/browser/cocoa/autocomplete_text_field_cell_unittest.mm +++ b/chrome/browser/cocoa/autocomplete_text_field_cell_unittest.mm @@ -1,4 +1,4 @@ -// Copyright (c) 2009 The Chromium Authors. All rights reserved. +// Copyright (c) 2010 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. @@ -43,7 +43,7 @@ class TestPageActionViewList : public LocationBarViewMac::PageActionViewList { class AutocompleteTextFieldCellTest : public CocoaTest { public: - AutocompleteTextFieldCellTest() : security_image_view_(NULL, NULL), + AutocompleteTextFieldCellTest() : security_image_view_(NULL, NULL, NULL), page_action_views_() { // Make sure this is wide enough to play games with the cell // decorations. diff --git a/chrome/browser/cocoa/autocomplete_text_field_unittest.mm b/chrome/browser/cocoa/autocomplete_text_field_unittest.mm index 8b3c00b..4adfa6a 100644 --- a/chrome/browser/cocoa/autocomplete_text_field_unittest.mm +++ b/chrome/browser/cocoa/autocomplete_text_field_unittest.mm @@ -1,4 +1,4 @@ -// Copyright (c) 2009 The Chromium Authors. All rights reserved. +// Copyright (c) 2010 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. @@ -22,8 +22,10 @@ using ::testing::StrictMock; namespace { class MockSecurityImageView : public LocationBarViewMac::SecurityImageView { public: - MockSecurityImageView(Profile* profile, ToolbarModel* model) - : LocationBarViewMac::SecurityImageView(profile, model) {} + MockSecurityImageView(LocationBarViewMac* owner, + Profile* profile, + ToolbarModel* model) + : LocationBarViewMac::SecurityImageView(owner, profile, model) {} MOCK_METHOD0(OnMousePressed, bool()); }; @@ -573,7 +575,7 @@ TEST_F(AutocompleteTextFieldTest, TripleClickSelectsAll) { TEST_F(AutocompleteTextFieldObserverTest, SecurityIconMouseDown) { AutocompleteTextFieldCell* cell = [field_ autocompleteTextFieldCell]; - MockSecurityImageView security_image_view(NULL, NULL); + MockSecurityImageView security_image_view(NULL, NULL, NULL); [cell setSecurityImageView:&security_image_view]; security_image_view.SetImageShown( LocationBarViewMac::SecurityImageView::LOCK); @@ -591,7 +593,7 @@ TEST_F(AutocompleteTextFieldObserverTest, SecurityIconMouseDown) { TEST_F(AutocompleteTextFieldObserverTest, PageActionMouseDown) { AutocompleteTextFieldCell* cell = [field_ autocompleteTextFieldCell]; - MockSecurityImageView security_image_view(NULL, NULL); + MockSecurityImageView security_image_view(NULL, NULL, NULL); security_image_view.SetImageShown( LocationBarViewMac::SecurityImageView::LOCK); [cell setSecurityImageView:&security_image_view]; diff --git a/chrome/browser/cocoa/location_bar_view_mac.h b/chrome/browser/cocoa/location_bar_view_mac.h index dbe5760..19d88d1 100644 --- a/chrome/browser/cocoa/location_bar_view_mac.h +++ b/chrome/browser/cocoa/location_bar_view_mac.h @@ -40,7 +40,8 @@ class LocationBarViewMac : public AutocompleteEditController, const BubblePositioner* bubble_positioner, CommandUpdater* command_updater, ToolbarModel* toolbar_model, - Profile* profile); + Profile* profile, + Browser* browser); virtual ~LocationBarViewMac(); // Overridden from LocationBar: @@ -74,6 +75,9 @@ class LocationBarViewMac : public AutocompleteEditController, // saved state from the tab (for tab switching). void Update(const TabContents* tab, bool should_restore_state); + // Returns the current TabContents. + TabContents* GetTabContents() const; + // Sets preview_enabled_ for the PageActionImageView associated with this // |page_action|. If |preview_enabled|, the location bar will display the // PageAction icon even if it has not been activated by the extension. @@ -166,7 +170,9 @@ class LocationBarViewMac : public AutocompleteEditController, WARNING }; - SecurityImageView(Profile* profile, ToolbarModel* model); + SecurityImageView(LocationBarViewMac* owner, + Profile* profile, + ToolbarModel* model); virtual ~SecurityImageView(); // Sets the image to the appropriate icon. @@ -184,6 +190,9 @@ class LocationBarViewMac : public AutocompleteEditController, // time it's needed. scoped_nsobject<NSImage> warning_icon_; + // The location bar view that owns us. + LocationBarViewMac* owner_; + Profile* profile_; ToolbarModel* model_; @@ -354,6 +363,8 @@ class LocationBarViewMac : public AutocompleteEditController, Profile* profile_; + Browser* browser_; + ToolbarModel* toolbar_model_; // Weak, owned by Browser. // Image used in drawing keyword hint. diff --git a/chrome/browser/cocoa/location_bar_view_mac.mm b/chrome/browser/cocoa/location_bar_view_mac.mm index fca4078..afcf1b0 100644 --- a/chrome/browser/cocoa/location_bar_view_mac.mm +++ b/chrome/browser/cocoa/location_bar_view_mac.mm @@ -86,15 +86,17 @@ LocationBarViewMac::LocationBarViewMac( const BubblePositioner* bubble_positioner, CommandUpdater* command_updater, ToolbarModel* toolbar_model, - Profile* profile) + Profile* profile, + Browser* browser) : edit_view_(new AutocompleteEditViewMac(this, bubble_positioner, toolbar_model, profile, command_updater, field)), command_updater_(command_updater), field_(field), disposition_(CURRENT_TAB), - security_image_view_(profile, toolbar_model), + security_image_view_(this, profile, toolbar_model), page_action_views_(this, profile, toolbar_model), profile_(profile), + browser_(browser), toolbar_model_(toolbar_model), transition_(PageTransition::TYPED) { AutocompleteTextFieldCell* cell = [field_ autocompleteTextFieldCell]; @@ -346,14 +348,14 @@ int LocationBarViewMac::PageActionVisibleCount() { return static_cast<int>(page_action_views_.VisibleCount()); } +TabContents* LocationBarViewMac::GetTabContents() const { + return browser_->GetSelectedTabContents(); +} + void LocationBarViewMac::SetPreviewEnabledPageAction( ExtensionAction* page_action, bool preview_enabled) { DCHECK(page_action); - Browser* browser = BrowserList::GetLastActive(); - // GetLastActive returns NULL in current unit testing. - if (!browser) - return; - TabContents* contents = browser->GetSelectedTabContents(); + TabContents* contents = GetTabContents(); if (!contents) return; page_action_views_.RefreshViews(); @@ -476,8 +478,7 @@ void LocationBarViewMac::Observe(NotificationType type, const NotificationDetails& details) { switch (type.value) { case NotificationType::EXTENSION_PAGE_ACTION_VISIBILITY_CHANGED: { - TabContents* contents = - BrowserList::GetLastActive()->GetSelectedTabContents(); + TabContents* contents = GetTabContents(); if (Details<TabContents>(contents) != details) return; @@ -534,10 +535,12 @@ void LocationBarViewMac::LocationBarImageView::SetVisible(bool visible) { // SecurityImageView------------------------------------------------------------ LocationBarViewMac::SecurityImageView::SecurityImageView( + LocationBarViewMac* owner, Profile* profile, ToolbarModel* model) : lock_icon_(nil), warning_icon_(nil), + owner_(owner), profile_(profile), model_(model) {} @@ -566,7 +569,7 @@ void LocationBarViewMac::SecurityImageView::SetImageShown(Image image) { } bool LocationBarViewMac::SecurityImageView::OnMousePressed() { - TabContents* tab = BrowserList::GetLastActive()->GetSelectedTabContents(); + TabContents* tab = owner_->GetTabContents(); NavigationEntry* nav_entry = tab->controller().GetActiveEntry(); if (!nav_entry) { NOTREACHED(); @@ -814,12 +817,7 @@ void LocationBarViewMac::PageActionViewList::RefreshViews() { if (views_.empty()) return; - Browser* browser = BrowserList::GetLastActive(); - // The last-active browser can be NULL during startup. - if (!browser) - return; - - TabContents* contents = browser->GetSelectedTabContents(); + TabContents* contents = owner_->GetTabContents(); if (!contents) return; diff --git a/chrome/browser/cocoa/toolbar_controller.mm b/chrome/browser/cocoa/toolbar_controller.mm index eb7cd90..db26a5d 100644 --- a/chrome/browser/cocoa/toolbar_controller.mm +++ b/chrome/browser/cocoa/toolbar_controller.mm @@ -1,4 +1,4 @@ -// Copyright (c) 2009 The Chromium Authors. All rights reserved. +// Copyright (c) 2010 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. @@ -214,7 +214,7 @@ class PrefObserverBridge : public NotificationObserver { locationBarView_.reset(new LocationBarViewMac(locationBar_, bubblePositioner_.get(), commands_, toolbarModel_, - profile_)); + profile_, browser_)); [locationBar_ setFont:[NSFont systemFontOfSize:[NSFont systemFontSize]]]; [[NSNotificationCenter defaultCenter] addObserver:self diff --git a/chrome/browser/gtk/location_bar_view_gtk.cc b/chrome/browser/gtk/location_bar_view_gtk.cc index 66af2aa..49e8929 100644 --- a/chrome/browser/gtk/location_bar_view_gtk.cc +++ b/chrome/browser/gtk/location_bar_view_gtk.cc @@ -360,6 +360,9 @@ void LocationBarViewGtk::SetProfile(Profile* profile) { profile_ = profile; } +TabContents* LocationBarViewGtk::GetTabContents() const { + return browser_->GetSelectedTabContents(); +} void LocationBarViewGtk::SetPreviewEnabledPageAction( ExtensionAction *page_action, @@ -534,7 +537,7 @@ void LocationBarViewGtk::FocusSearch() { } void LocationBarViewGtk::UpdateContentBlockedIcons() { - const TabContents* tab_contents = browser_->GetSelectedTabContents(); + const TabContents* tab_contents = GetTabContents(); for (ScopedVector<ContentBlockedViewGtk>::iterator i( content_blocked_views_.begin()); i != content_blocked_views_.end(); ++i) { @@ -572,7 +575,7 @@ void LocationBarViewGtk::UpdatePageActions() { NotificationService::NoDetails()); } - TabContents* contents = browser_->GetSelectedTabContents(); + TabContents* contents = GetTabContents(); if (!page_action_views_.empty() && contents) { GURL url = GURL(WideToUTF8(toolbar_model_->GetText())); @@ -844,7 +847,7 @@ gboolean LocationBarViewGtk::OnSecurityIconPressed( GtkWidget* sender, GdkEventButton* event, LocationBarViewGtk* location_bar) { - TabContents* tab = BrowserList::GetLastActive()->GetSelectedTabContents(); + TabContents* tab = location_bar->GetTabContents(); NavigationEntry* nav_entry = tab->controller().GetActiveEntry(); if (!nav_entry) { NOTREACHED(); @@ -1004,8 +1007,7 @@ gboolean LocationBarViewGtk::ContentBlockedViewGtk::OnButtonPressed( gfx::Rect bounds = gtk_util::GetWidgetRectRelativeToToplevel(sender); - TabContents* tab_contents = - BrowserList::GetLastActive()->GetSelectedTabContents(); + TabContents* tab_contents = parent_->GetTabContents(); if (!tab_contents) return true; GURL url = tab_contents->GetURL(); @@ -1226,7 +1228,7 @@ gboolean LocationBarViewGtk::PageActionViewGtk::OnButtonPressed( gboolean LocationBarViewGtk::PageActionViewGtk::OnExposeEvent( GtkWidget* widget, GdkEventExpose* event) { - TabContents* contents = owner_->browser_->GetSelectedTabContents(); + TabContents* contents = owner_->GetTabContents(); if (!contents) return FALSE; diff --git a/chrome/browser/gtk/location_bar_view_gtk.h b/chrome/browser/gtk/location_bar_view_gtk.h index 6e6cfb5..dcd6a26 100644 --- a/chrome/browser/gtk/location_bar_view_gtk.h +++ b/chrome/browser/gtk/location_bar_view_gtk.h @@ -58,6 +58,9 @@ class LocationBarViewGtk : public AutocompleteEditController, // Returns the widget the caller should host. You must call Init() first. GtkWidget* widget() { return hbox_.get(); } + // Returns the current TabContents. + TabContents* GetTabContents() const; + // Sets |preview_enabled| for the PageActionViewGtk associated with this // |page_action|. If |preview_enabled| is true, the view will display the // page action's icon even though it has not been activated by the extension. diff --git a/chrome/browser/views/location_bar_view.cc b/chrome/browser/views/location_bar_view.cc index eb8bd88..c9bbf1d 100644 --- a/chrome/browser/views/location_bar_view.cc +++ b/chrome/browser/views/location_bar_view.cc @@ -137,7 +137,7 @@ LocationBarView::LocationBarView(Profile* profile, selected_keyword_view_(profile), keyword_hint_view_(profile), type_to_search_view_(l10n_util::GetString(IDS_OMNIBOX_EMPTY_TEXT)), - security_image_view_(profile, model, bubble_positioner), + security_image_view_(this, profile, model, bubble_positioner), popup_window_mode_(popup_window_mode), first_run_bubble_(this), bubble_positioner_(bubble_positioner) { @@ -1282,10 +1282,12 @@ SkBitmap* LocationBarView:: ContentBlockedImageView::icons_[CONTENT_SETTINGS_NUM_TYPES] = { NULL }; LocationBarView::SecurityImageView::SecurityImageView( + const LocationBarView* parent, Profile* profile, ToolbarModel* model, const BubblePositioner* bubble_positioner) : LocationBarImageView(bubble_positioner), + parent_(parent), profile_(profile), model_(model) { if (!lock_icon_) { @@ -1315,7 +1317,7 @@ void LocationBarView::SecurityImageView::SetImageShown(Image image) { bool LocationBarView::SecurityImageView::OnMousePressed( const views::MouseEvent& event) { - TabContents* tab = BrowserList::GetLastActive()->GetSelectedTabContents(); + TabContents* tab = parent_->GetTabContents(); NavigationEntry* nav_entry = tab->controller().GetActiveEntry(); if (!nav_entry) { NOTREACHED(); diff --git a/chrome/browser/views/location_bar_view.h b/chrome/browser/views/location_bar_view.h index 4554efb..d2fefaa 100644 --- a/chrome/browser/views/location_bar_view.h +++ b/chrome/browser/views/location_bar_view.h @@ -102,8 +102,7 @@ class LocationBarView : public LocationBar, void SetProfile(Profile* profile); Profile* profile() { return profile_; } - // Returns the current TabContents. This should only be used by the - // ContentBlockedImageView. + // Returns the current TabContents. TabContents* GetTabContents() const; // Sets |preview_enabled| for the PageAction View associated with this @@ -328,7 +327,8 @@ class LocationBarView : public LocationBar, WARNING }; - SecurityImageView(Profile* profile, + SecurityImageView(const LocationBarView* parent, + Profile* profile, ToolbarModel* model_, const BubblePositioner* bubble_positioner); virtual ~SecurityImageView(); @@ -354,6 +354,9 @@ class LocationBarView : public LocationBar, // image. ShowInfoBubbleTask* show_info_bubble_task_; + // The owning LocationBarView. + const LocationBarView* parent_; + Profile* profile_; ToolbarModel* model_; |