diff options
author | pkasting@chromium.org <pkasting@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-08-22 20:12:14 +0000 |
---|---|---|
committer | pkasting@chromium.org <pkasting@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-08-22 20:12:14 +0000 |
commit | a40be8bcb46f89a8e11616cd790495c2fdccc6e0 (patch) | |
tree | 070055c4df9a15d8ca8c0d4a4a735798ec4ef209 | |
parent | eacf28e772602086ea1ff4580a8d97b92c66e3b4 (diff) | |
download | chromium_src-a40be8bcb46f89a8e11616cd790495c2fdccc6e0.zip chromium_src-a40be8bcb46f89a8e11616cd790495c2fdccc6e0.tar.gz chromium_src-a40be8bcb46f89a8e11616cd790495c2fdccc6e0.tar.bz2 |
Instead of passing ToolbarModel*s around, have classes ask the Browser.
This makes it simpler to override the toolbar model for testing. This will be
useful in a future change where the OmniboxEditModel starts reading from the
toolbar model "under the hood" in UpdatePermanentText().
BUG=none
TEST=none
R=sky@chromium.org
Review URL: https://codereview.chromium.org/23365004
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@219087 0039d316-1c4b-4281-b951-d872f2087c98
44 files changed, 246 insertions, 231 deletions
diff --git a/chrome/browser/chromeos/login/simple_web_view_dialog.cc b/chrome/browser/chromeos/login/simple_web_view_dialog.cc index 8e1be13..215cb0f 100644 --- a/chrome/browser/chromeos/login/simple_web_view_dialog.cc +++ b/chrome/browser/chromeos/login/simple_web_view_dialog.cc @@ -168,6 +168,8 @@ void SimpleWebViewDialog::StartLoad(const GURL& url) { } void SimpleWebViewDialog::Init() { + toolbar_model_.reset(new ToolbarModelImpl(this)); + set_background(views::Background::CreateSolidBackground(SK_ColorWHITE)); // Back/Forward buttons. @@ -189,11 +191,9 @@ void SimpleWebViewDialog::Init() { forward_->SetAccessibleName(l10n_util::GetStringUTF16(IDS_ACCNAME_FORWARD)); forward_->set_id(VIEW_ID_FORWARD_BUTTON); - toolbar_model_.reset(new ToolbarModelImpl(this)); - // Location bar. location_bar_ = new LocationBarView(NULL, profile_, command_updater_.get(), - toolbar_model_.get(), this, true); + this, true); // Reload button. reload_ = new ReloadButton(location_bar_, command_updater_.get()); @@ -286,6 +286,14 @@ WebContents* SimpleWebViewDialog::GetWebContents() const { return NULL; } +ToolbarModel* SimpleWebViewDialog::GetToolbarModel() { + return toolbar_model_.get(); +} + +const ToolbarModel* SimpleWebViewDialog::GetToolbarModel() const { + return toolbar_model_.get(); +} + InstantController* SimpleWebViewDialog::GetInstant() { return NULL; } diff --git a/chrome/browser/chromeos/login/simple_web_view_dialog.h b/chrome/browser/chromeos/login/simple_web_view_dialog.h index cc867c5..f281620 100644 --- a/chrome/browser/chromeos/login/simple_web_view_dialog.h +++ b/chrome/browser/chromeos/login/simple_web_view_dialog.h @@ -79,6 +79,8 @@ class SimpleWebViewDialog : public views::ButtonListener, virtual void NavigationStateChanged(const content::WebContents* source, unsigned changed_flags) OVERRIDE; virtual content::WebContents* GetWebContents() const OVERRIDE; + virtual ToolbarModel* GetToolbarModel() OVERRIDE; + virtual const ToolbarModel* GetToolbarModel() const OVERRIDE; virtual InstantController* GetInstant() OVERRIDE; virtual views::Widget* CreateViewsBubble( views::BubbleDelegateView* bubble_delegate) OVERRIDE; diff --git a/chrome/browser/ui/browser.cc b/chrome/browser/ui/browser.cc index cf7613d..cbf706b 100644 --- a/chrome/browser/ui/browser.cc +++ b/chrome/browser/ui/browser.cc @@ -368,8 +368,7 @@ Browser::Browser(const CreateParams& params) toolbar_model_.reset(new ToolbarModelImpl(toolbar_model_delegate_.get())); search_model_.reset(new SearchModel()); - search_delegate_.reset( - new SearchDelegate(search_model_.get(), toolbar_model_.get())); + search_delegate_.reset(new SearchDelegate(search_model_.get())); registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_LOADED, content::Source<Profile>(profile_->GetOriginalProfile())); diff --git a/chrome/browser/ui/browser.h b/chrome/browser/ui/browser.h index 75604f4..7710549 100644 --- a/chrome/browser/ui/browser.h +++ b/chrome/browser/ui/browser.h @@ -239,6 +239,11 @@ class Browser : public TabStripModelObserver, BrowserWindow* window() const { return window_; } ToolbarModel* toolbar_model() { return toolbar_model_.get(); } const ToolbarModel* toolbar_model() const { return toolbar_model_.get(); } +#if defined(UNIT_TEST) + void swap_toolbar_models(scoped_ptr<ToolbarModel>* toolbar_model) { + toolbar_model->swap(toolbar_model_); + } +#endif TabStripModel* tab_strip_model() const { return tab_strip_model_.get(); } chrome::BrowserCommandController* command_controller() { return command_controller_.get(); diff --git a/chrome/browser/ui/cocoa/browser_window_controller.mm b/chrome/browser/ui/cocoa/browser_window_controller.mm index 8ddc8e6..7717c7e 100644 --- a/chrome/browser/ui/cocoa/browser_window_controller.mm +++ b/chrome/browser/ui/cocoa/browser_window_controller.mm @@ -361,11 +361,10 @@ enum { // registering for the appropriate command state changes from the back-end. // Adds the toolbar to the content area. toolbarController_.reset([[ToolbarController alloc] - initWithModel:browser->toolbar_model() - commands:browser->command_controller()->command_updater() - profile:browser->profile() - browser:browser - resizeDelegate:self]); + initWithCommands:browser->command_controller()->command_updater() + profile:browser->profile() + browser:browser + resizeDelegate:self]); [toolbarController_ setHasToolbar:[self hasToolbar] hasLocationBar:[self hasLocationBar]]; diff --git a/chrome/browser/ui/cocoa/location_bar/location_bar_view_mac.h b/chrome/browser/ui/cocoa/location_bar/location_bar_view_mac.h index e6f3f4c..79f2638 100644 --- a/chrome/browser/ui/cocoa/location_bar/location_bar_view_mac.h +++ b/chrome/browser/ui/cocoa/location_bar/location_bar_view_mac.h @@ -18,7 +18,6 @@ #include "chrome/browser/ui/omnibox/location_bar.h" #include "chrome/browser/ui/omnibox/omnibox_edit_controller.h" #include "chrome/browser/ui/search/search_model_observer.h" -#include "chrome/browser/ui/toolbar/toolbar_model.h" #include "chrome/common/content_settings_types.h" @class AutocompleteTextField; @@ -33,7 +32,6 @@ class PageActionDecoration; class Profile; class SelectedKeywordDecoration; class StarDecoration; -class ToolbarModel; class ZoomDecoration; class ZoomDecorationTest; @@ -49,7 +47,6 @@ class LocationBarViewMac : public LocationBar, public: LocationBarViewMac(AutocompleteTextField* field, CommandUpdater* command_updater, - ToolbarModel* toolbar_model, Profile* profile, Browser* browser); virtual ~LocationBarViewMac(); @@ -156,6 +153,8 @@ class LocationBarViewMac : public LocationBar, virtual string16 GetTitle() const OVERRIDE; virtual InstantController* GetInstant() OVERRIDE; virtual content::WebContents* GetWebContents() const OVERRIDE; + virtual ToolbarModel* GetToolbarModel() OVERRIDE; + virtual const ToolbarModel* GetToolbarModel() const OVERRIDE; NSImage* GetKeywordImage(const string16& keyword); @@ -172,7 +171,6 @@ class LocationBarViewMac : public LocationBar, const SearchModel::State& new_state) OVERRIDE; Browser* browser() const { return browser_; } - ToolbarModel* toolbar_model() const { return toolbar_model_; } private: friend ZoomDecorationTest; @@ -261,8 +259,6 @@ class LocationBarViewMac : public LocationBar, Browser* browser_; - ToolbarModel* toolbar_model_; // Weak, owned by Browser. - // The transition type to use for the navigation. content::PageTransition transition_; diff --git a/chrome/browser/ui/cocoa/location_bar/location_bar_view_mac.mm b/chrome/browser/ui/cocoa/location_bar/location_bar_view_mac.mm index aade0d9..b77818b 100644 --- a/chrome/browser/ui/cocoa/location_bar/location_bar_view_mac.mm +++ b/chrome/browser/ui/cocoa/location_bar/location_bar_view_mac.mm @@ -82,11 +82,9 @@ const static int kFirstRunBubbleYOffset = 1; LocationBarViewMac::LocationBarViewMac( AutocompleteTextField* field, CommandUpdater* command_updater, - ToolbarModel* toolbar_model, Profile* profile, Browser* browser) - : omnibox_view_(new OmniboxViewMac(this, toolbar_model, profile, - command_updater, field)), + : omnibox_view_(new OmniboxViewMac(this, profile, command_updater, field)), command_updater_(command_updater), field_(field), disposition_(CURRENT_TAB), @@ -100,7 +98,6 @@ LocationBarViewMac::LocationBarViewMac( mic_search_decoration_(new MicSearchDecoration(command_updater)), profile_(profile), browser_(browser), - toolbar_model_(toolbar_model), transition_(content::PageTransitionFromInt( content::PAGE_TRANSITION_TYPED | content::PAGE_TRANSITION_FROM_ADDRESS_BAR)), @@ -300,7 +297,7 @@ void LocationBarViewMac::OnSelectionBoundsChanged() { } void LocationBarViewMac::OnInputInProgress(bool in_progress) { - toolbar_model_->set_input_in_progress(in_progress); + GetToolbarModel()->set_input_in_progress(in_progress); Update(NULL); } @@ -360,6 +357,14 @@ WebContents* LocationBarViewMac::GetWebContents() const { return browser_->tab_strip_model()->GetActiveWebContents(); } +ToolbarModel* LocationBarViewMac::GetToolbarModel() { + return browser_->toolbar_model(); +} + +const ToolbarModel* LocationBarViewMac::GetToolbarModel() const { + return browser_->toolbar_model(); +} + PageActionDecoration* LocationBarViewMac::GetPageActionDecoration( ExtensionAction* page_action) { DCHECK(page_action); @@ -388,7 +393,7 @@ void LocationBarViewMac::SetPreviewEnabledPageAction( return; decoration->set_preview_enabled(preview_enabled); - decoration->UpdateVisibility(contents, toolbar_model_->GetURL()); + decoration->UpdateVisibility(contents, GetToolbarModel()->GetURL()); } NSRect LocationBarViewMac::GetPageActionFrame(ExtensionAction* page_action) { @@ -581,7 +586,7 @@ void LocationBarViewMac::PostNotification(NSString* notification) { } bool LocationBarViewMac::RefreshContentSettingsDecorations() { - const bool input_in_progress = toolbar_model_->input_in_progress(); + const bool input_in_progress = GetToolbarModel()->input_in_progress(); WebContents* web_contents = input_in_progress ? NULL : browser_->tab_strip_model()->GetActiveWebContents(); bool icons_updated = false; @@ -626,10 +631,10 @@ void LocationBarViewMac::RefreshPageActionDecorations() { } } - GURL url = toolbar_model_->GetURL(); + GURL url = GetToolbarModel()->GetURL(); for (size_t i = 0; i < page_action_decorations_.size(); ++i) { page_action_decorations_[i]->UpdateVisibility( - toolbar_model_->input_in_progress() ? NULL : web_contents, url); + GetToolbarModel()->input_in_progress() ? NULL : web_contents, url); } } @@ -682,13 +687,13 @@ void LocationBarViewMac::Layout() { selected_keyword_decoration_->SetVisible(true); selected_keyword_decoration_->SetKeyword(short_name, is_extension_keyword); selected_keyword_decoration_->SetImage(GetKeywordImage(keyword)); - } else if (toolbar_model_->GetSecurityLevel(false) == + } else if (GetToolbarModel()->GetSecurityLevel(false) == ToolbarModel::EV_SECURE) { // Switch from location icon to show the EV bubble instead. location_icon_decoration_->SetVisible(false); ev_bubble_decoration_->SetVisible(true); - string16 label(toolbar_model_->GetEVCertName()); + string16 label(GetToolbarModel()->GetEVCertName()); ev_bubble_decoration_->SetFullLabel(base::SysUTF16ToNSString(label)); } else if (!keyword.empty() && is_keyword_hint) { keyword_hint_decoration_->SetKeyword(short_name, @@ -714,7 +719,7 @@ void LocationBarViewMac::RedrawDecoration(LocationBarDecoration* decoration) { bool LocationBarViewMac::IsStarEnabled() { return [field_ isEditable] && browser_defaults::bookmarks_enabled && - !toolbar_model_->input_in_progress() && + !GetToolbarModel()->input_in_progress() && edit_bookmarks_enabled_.GetValue(); } @@ -731,7 +736,7 @@ void LocationBarViewMac::UpdateStarDecorationVisibility() { } bool LocationBarViewMac::UpdateMicSearchDecorationVisibility() { - bool is_visible = !toolbar_model_->input_in_progress() && + bool is_visible = !GetToolbarModel()->input_in_progress() && browser_->search_model()->voice_search_supported(); if (mic_search_decoration_->IsVisible() == is_visible) return false; diff --git a/chrome/browser/ui/cocoa/location_bar/zoom_decoration.mm b/chrome/browser/ui/cocoa/location_bar/zoom_decoration.mm index 3d375a9..0d60f5b 100644 --- a/chrome/browser/ui/cocoa/location_bar/zoom_decoration.mm +++ b/chrome/browser/ui/cocoa/location_bar/zoom_decoration.mm @@ -101,7 +101,7 @@ bool ZoomDecoration::IsAtDefaultZoom() const { } bool ZoomDecoration::ShouldShowDecoration() const { - if (owner_->toolbar_model()->input_in_progress()) + if (owner_->GetToolbarModel()->input_in_progress()) return false; if (bubble_) return true; diff --git a/chrome/browser/ui/cocoa/location_bar/zoom_decoration_browsertest.mm b/chrome/browser/ui/cocoa/location_bar/zoom_decoration_browsertest.mm index 11bfd1c..b4aeda6 100644 --- a/chrome/browser/ui/cocoa/location_bar/zoom_decoration_browsertest.mm +++ b/chrome/browser/ui/cocoa/location_bar/zoom_decoration_browsertest.mm @@ -21,7 +21,6 @@ class ZoomDecorationTest : public InProcessBrowserTest { protected: ZoomDecorationTest() : InProcessBrowserTest(), - old_toolbar_model_(NULL), should_quit_on_zoom_(false), zoom_callback_(base::Bind(&ZoomDecorationTest::OnZoomChanged, base::Unretained(this))) { @@ -30,15 +29,11 @@ class ZoomDecorationTest : public InProcessBrowserTest { virtual void SetUpOnMainThread() OVERRIDE { content::HostZoomMap::GetForBrowserContext( browser()->profile())->AddZoomLevelChangedCallback(zoom_callback_); - - old_toolbar_model_ = GetLocationBar()->toolbar_model_; - GetLocationBar()->toolbar_model_ = &test_toolbar_model_; } virtual void CleanUpOnMainThread() OVERRIDE { content::HostZoomMap::GetForBrowserContext( browser()->profile())->RemoveZoomLevelChangedCallback(zoom_callback_); - GetLocationBar()->toolbar_model_ = old_toolbar_model_; } LocationBarViewMac* GetLocationBar() const { @@ -76,10 +71,7 @@ class ZoomDecorationTest : public InProcessBrowserTest { } } - TestToolbarModel test_toolbar_model_; - private: - ToolbarModel* old_toolbar_model_; bool should_quit_on_zoom_; content::HostZoomMap::ZoomLevelChangedCallback zoom_callback_; @@ -115,7 +107,9 @@ IN_PROC_BROWSER_TEST_F(ZoomDecorationTest, HideOnInputProgress) { Zoom(content::PAGE_ZOOM_IN); EXPECT_TRUE(zoom_decoration->IsVisible()); - test_toolbar_model_.set_input_in_progress(true); + scoped_ptr<ToolbarModel> toolbar_model(new TestToolbarModel); + toolbar_model->set_input_in_progress(true); + browser()->swap_toolbar_models(&toolbar_model); GetLocationBar()->ZoomChangedForActiveTab(false); EXPECT_FALSE(zoom_decoration->IsVisible()); } diff --git a/chrome/browser/ui/cocoa/omnibox/omnibox_popup_view_mac_unittest.mm b/chrome/browser/ui/cocoa/omnibox/omnibox_popup_view_mac_unittest.mm index 2d2d0d3..82e0d18 100644 --- a/chrome/browser/ui/cocoa/omnibox/omnibox_popup_view_mac_unittest.mm +++ b/chrome/browser/ui/cocoa/omnibox/omnibox_popup_view_mac_unittest.mm @@ -332,7 +332,7 @@ TEST_F(OmniboxPopupViewMacTest, UpdatePopupAppearance) { [[NSTextField alloc] initWithFrame:NSMakeRect(0, 0, 100, 20)]); [[test_window() contentView] addSubview:field]; - OmniboxViewMac view(NULL, NULL, profile(), NULL, NULL); + OmniboxViewMac view(NULL, profile(), NULL, NULL); MockOmniboxPopupViewMac popup_view(&view, view.model(), field); popup_view.UpdatePopupAppearance(); diff --git a/chrome/browser/ui/cocoa/omnibox/omnibox_view_mac.h b/chrome/browser/ui/cocoa/omnibox/omnibox_view_mac.h index b52da56..5cb76b6 100644 --- a/chrome/browser/ui/cocoa/omnibox/omnibox_view_mac.h +++ b/chrome/browser/ui/cocoa/omnibox/omnibox_view_mac.h @@ -23,7 +23,6 @@ class OmniboxViewMac : public OmniboxView, public AutocompleteTextFieldObserver { public: OmniboxViewMac(OmniboxEditController* controller, - ToolbarModel* toolbar_model, Profile* profile, CommandUpdater* command_updater, AutocompleteTextField* field); diff --git a/chrome/browser/ui/cocoa/omnibox/omnibox_view_mac.mm b/chrome/browser/ui/cocoa/omnibox/omnibox_view_mac.mm index 2e2a7bb..5edacd7 100644 --- a/chrome/browser/ui/cocoa/omnibox/omnibox_view_mac.mm +++ b/chrome/browser/ui/cocoa/omnibox/omnibox_view_mac.mm @@ -133,11 +133,10 @@ NSColor* OmniboxViewMac::SuggestTextColor() { } OmniboxViewMac::OmniboxViewMac(OmniboxEditController* controller, - ToolbarModel* toolbar_model, Profile* profile, CommandUpdater* command_updater, AutocompleteTextField* field) - : OmniboxView(profile, controller, toolbar_model, command_updater), + : OmniboxView(profile, controller, command_updater), popup_view_(new OmniboxPopupViewMac(this, model(), field)), field_(field), saved_temporary_selection_(NSMakeRange(0, 0)), @@ -190,8 +189,8 @@ void OmniboxViewMac::Update(const WebContents* tab_for_state_restoring) { // that the field isn't always updated correctly. Figure out why // this is. Maybe this method should be refactored into more // specific cases. - bool user_visible = - model()->UpdatePermanentText(toolbar_model()->GetText(true)); + bool user_visible = model()->UpdatePermanentText( + controller()->GetToolbarModel()->GetText(true)); if (tab_for_state_restoring) { RevertAll(); @@ -225,7 +224,7 @@ void OmniboxViewMac::Update(const WebContents* tab_for_state_restoring) { // TODO(shess): This corresponds to _win and _gtk, except those // guard it with a test for whether the security level changed. // But AFAICT, that can only change if the text changed, and that - // code compares the toolbar_model() security level with the local + // code compares the toolbar model security level with the local // security level. Dig in and figure out why this isn't a no-op // that should go away. EmphasizeURLComponents(); @@ -465,7 +464,7 @@ void OmniboxViewMac::ApplyTextAttributes(const string16& display_text, // [Could it be to not change if no change? If so, I'm guessing // AppKit may already handle that.] const ToolbarModel::SecurityLevel security_level = - toolbar_model()->GetSecurityLevel(false); + controller()->GetToolbarModel()->GetSecurityLevel(false); // Emphasize the scheme for security UI display purposes (if necessary). if (!model()->user_input_in_progress() && model()->CurrentTextIsURL() && @@ -818,8 +817,8 @@ void OmniboxViewMac::CopyURLToPasteboard(NSPasteboard* pb) { DCHECK(CanCopy()); DCHECK(ShouldEnableCopyURL()); - string16 text = toolbar_model()->GetText(false); - GURL url = toolbar_model()->GetURL(); + string16 text = controller()->GetToolbarModel()->GetText(false); + GURL url = controller()->GetToolbarModel()->GetURL(); NSString* nstext = base::SysUTF16ToNSString(text); [pb declareTypes:[NSArray arrayWithObject:NSStringPboardType] owner:nil]; @@ -866,7 +865,8 @@ void OmniboxViewMac::OnPaste() { // platforms. Some refactor might be necessary to simplify this. Or at least // this method could call the OmniboxView version. bool OmniboxViewMac::ShouldEnableCopyURL() { - return toolbar_model()->WouldReplaceSearchURLWithSearchTerms(false); + return controller()->GetToolbarModel()->WouldReplaceSearchURLWithSearchTerms( + false); } bool OmniboxViewMac::CanPasteAndGo() { diff --git a/chrome/browser/ui/cocoa/omnibox/omnibox_view_mac_unittest.mm b/chrome/browser/ui/cocoa/omnibox/omnibox_view_mac_unittest.mm index 0749f66..9f60ae1 100644 --- a/chrome/browser/ui/cocoa/omnibox/omnibox_view_mac_unittest.mm +++ b/chrome/browser/ui/cocoa/omnibox/omnibox_view_mac_unittest.mm @@ -78,7 +78,8 @@ class TestingToolbarModelDelegate : public ToolbarModelDelegate { class TestingOmniboxEditController : public OmniboxEditController { public: - TestingOmniboxEditController() {} + explicit TestingOmniboxEditController(ToolbarModel* toolbar_model) + : toolbar_model_(toolbar_model) {} virtual ~TestingOmniboxEditController() {} // Overridden from OmniboxEditController: @@ -97,8 +98,14 @@ class TestingOmniboxEditController : public OmniboxEditController { virtual content::WebContents* GetWebContents() const OVERRIDE { return NULL; } + virtual ToolbarModel* GetToolbarModel() OVERRIDE { return toolbar_model_; } + virtual const ToolbarModel* GetToolbarModel() const OVERRIDE { + return toolbar_model_; + } private: + ToolbarModel* toolbar_model_; + DISALLOW_COPY_AND_ASSIGN(TestingOmniboxEditController); }; @@ -117,7 +124,7 @@ TEST_F(OmniboxViewMacTest, GetFieldFont) { TEST_F(OmniboxViewMacTest, TabToAutocomplete) { chrome::EnableInstantExtendedAPIForTesting(); - OmniboxViewMac view(NULL, NULL, profile(), NULL, NULL); + OmniboxViewMac view(NULL, profile(), NULL, NULL); // This is deleted by the omnibox view. MockOmniboxEditModel* model = @@ -149,9 +156,9 @@ TEST_F(OmniboxViewMacTest, SetGrayTextAutocompletion) { TestingToolbarModelDelegate delegate; ToolbarModelImpl toolbar_model(&delegate); - OmniboxViewMac view(NULL, &toolbar_model, profile(), NULL, field.get()); + TestingOmniboxEditController controller(&toolbar_model); + OmniboxViewMac view(&controller, profile(), NULL, field.get()); - TestingOmniboxEditController controller; // This is deleted by the omnibox view. MockOmniboxEditModel* model = new MockOmniboxEditModel(&view, &controller, profile()); @@ -172,7 +179,7 @@ TEST_F(OmniboxViewMacTest, SetGrayTextAutocompletion) { } TEST_F(OmniboxViewMacTest, UpDownArrow) { - OmniboxViewMac view(NULL, NULL, profile(), NULL, NULL); + OmniboxViewMac view(NULL, profile(), NULL, NULL); // This is deleted by the omnibox view. MockOmniboxEditModel* model = diff --git a/chrome/browser/ui/cocoa/toolbar/toolbar_controller.h b/chrome/browser/ui/cocoa/toolbar/toolbar_controller.h index c11e15d..b023897 100644 --- a/chrome/browser/ui/cocoa/toolbar/toolbar_controller.h +++ b/chrome/browser/ui/cocoa/toolbar/toolbar_controller.h @@ -27,7 +27,6 @@ class LocationBarViewMac; class Profile; @class ReloadButton; @class ToolbarButton; -class ToolbarModel; @class WrenchMenuController; namespace content { @@ -58,7 +57,6 @@ class NotificationBridge; IBOutlet BrowserActionsContainerView* browserActionsContainerView_; @private - ToolbarModel* toolbarModel_; // weak, one per window CommandUpdater* commands_; // weak, one per window Profile* profile_; // weak, one per window Browser* browser_; // weak, one per window @@ -98,12 +96,11 @@ class NotificationBridge; // Initialize the toolbar and register for command updates. The profile is // needed for initializing the location bar. The browser is needed for -// initializing the back/forward menus. -- (id)initWithModel:(ToolbarModel*)model - commands:(CommandUpdater*)commands - profile:(Profile*)profile - browser:(Browser*)browser - resizeDelegate:(id<ViewResizer>)resizeDelegate; +// the toolbar model and back/forward menus. +- (id)initWithCommands:(CommandUpdater*)commands + profile:(Profile*)profile + browser:(Browser*)browser + resizeDelegate:(id<ViewResizer>)resizeDelegate; // Get the C++ bridge object representing the location bar for this tab. - (LocationBarViewMac*)locationBarBridge; @@ -168,12 +165,11 @@ class NotificationBridge; @interface ToolbarController(ProtectedMethods) // Designated initializer which takes a nib name in order to allow subclasses // to load a different nib file. -- (id)initWithModel:(ToolbarModel*)model - commands:(CommandUpdater*)commands - profile:(Profile*)profile - browser:(Browser*)browser - resizeDelegate:(id<ViewResizer>)resizeDelegate - nibFileNamed:(NSString*)nibName; +- (id)initWithCommands:(CommandUpdater*)commands + profile:(Profile*)profile + browser:(Browser*)browser + resizeDelegate:(id<ViewResizer>)resizeDelegate + nibFileNamed:(NSString*)nibName; @end // A set of private methods used by tests, in the absence of "friends" in ObjC. diff --git a/chrome/browser/ui/cocoa/toolbar/toolbar_controller.mm b/chrome/browser/ui/cocoa/toolbar/toolbar_controller.mm index 6bd7e4d..d675586 100644 --- a/chrome/browser/ui/cocoa/toolbar/toolbar_controller.mm +++ b/chrome/browser/ui/cocoa/toolbar/toolbar_controller.mm @@ -46,7 +46,6 @@ #include "chrome/browser/ui/global_error/global_error_service_factory.h" #include "chrome/browser/ui/omnibox/omnibox_view.h" #include "chrome/browser/ui/tabs/tab_strip_model.h" -#include "chrome/browser/ui/toolbar/toolbar_model.h" #include "chrome/browser/ui/toolbar/wrench_menu_model.h" #include "chrome/browser/upgrade_detector.h" #include "chrome/common/net/url_fixer_upper.h" @@ -148,16 +147,14 @@ class NotificationBridge @synthesize browser = browser_; -- (id)initWithModel:(ToolbarModel*)model - commands:(CommandUpdater*)commands - profile:(Profile*)profile - browser:(Browser*)browser - resizeDelegate:(id<ViewResizer>)resizeDelegate - nibFileNamed:(NSString*)nibName { - DCHECK(model && commands && profile && [nibName length]); +- (id)initWithCommands:(CommandUpdater*)commands + profile:(Profile*)profile + browser:(Browser*)browser + resizeDelegate:(id<ViewResizer>)resizeDelegate + nibFileNamed:(NSString*)nibName { + DCHECK(commands && profile && [nibName length]); if ((self = [super initWithNibName:nibName bundle:base::mac::FrameworkBundle()])) { - toolbarModel_ = model; commands_ = commands; profile_ = profile; browser_ = browser; @@ -176,17 +173,15 @@ class NotificationBridge return self; } -- (id)initWithModel:(ToolbarModel*)model - commands:(CommandUpdater*)commands - profile:(Profile*)profile - browser:(Browser*)browser - resizeDelegate:(id<ViewResizer>)resizeDelegate { - if ((self = [self initWithModel:model - commands:commands - profile:profile - browser:browser - resizeDelegate:resizeDelegate - nibFileNamed:@"Toolbar"])) { +- (id)initWithCommands:(CommandUpdater*)commands + profile:(Profile*)profile + browser:(Browser*)browser + resizeDelegate:(id<ViewResizer>)resizeDelegate { + if ((self = [self initWithCommands:commands + profile:profile + browser:browser + resizeDelegate:resizeDelegate + nibFileNamed:@"Toolbar"])) { } return self; } @@ -270,8 +265,7 @@ class NotificationBridge [self initCommandStatus:commands_]; - locationBarView_.reset(new LocationBarViewMac(locationBar_, - commands_, toolbarModel_, + locationBarView_.reset(new LocationBarViewMac(locationBar_, commands_, profile_, browser_)); [locationBar_ setFont:[NSFont systemFontOfSize:[NSFont systemFontSize]]]; // Register pref observers for the optional home and page/options buttons diff --git a/chrome/browser/ui/cocoa/toolbar/toolbar_controller_unittest.mm b/chrome/browser/ui/cocoa/toolbar/toolbar_controller_unittest.mm index 8fb005e..dd160b4 100644 --- a/chrome/browser/ui/cocoa/toolbar/toolbar_controller_unittest.mm +++ b/chrome/browser/ui/cocoa/toolbar/toolbar_controller_unittest.mm @@ -61,11 +61,11 @@ class ToolbarControllerTest : public CocoaProfileTest { updater->UpdateCommandEnabled(IDC_FORWARD, false); resizeDelegate_.reset([[ViewResizerPong alloc] init]); bar_.reset( - [[ToolbarController alloc] initWithModel:browser()->toolbar_model() - commands:browser()->command_controller()->command_updater() - profile:profile() - browser:browser() - resizeDelegate:resizeDelegate_.get()]); + [[ToolbarController alloc] + initWithCommands:browser()->command_controller()->command_updater() + profile:profile() + browser:browser() + resizeDelegate:resizeDelegate_.get()]); EXPECT_TRUE([bar_ view]); NSView* parent = [test_window() contentView]; [parent addSubview:[bar_ view]]; diff --git a/chrome/browser/ui/gtk/browser_toolbar_gtk.cc b/chrome/browser/ui/gtk/browser_toolbar_gtk.cc index 8e95a16..ed004be 100644 --- a/chrome/browser/ui/gtk/browser_toolbar_gtk.cc +++ b/chrome/browser/ui/gtk/browser_toolbar_gtk.cc @@ -98,7 +98,6 @@ void SetWidgetHeightRequest(GtkWidget* widget, gpointer user_data) { BrowserToolbarGtk::BrowserToolbarGtk(Browser* browser, BrowserWindowGtk* window) : toolbar_(NULL), location_bar_(new LocationBarViewGtk(browser)), - model_(browser->toolbar_model()), is_wrench_menu_model_valid_(true), browser_(browser), window_(window), diff --git a/chrome/browser/ui/gtk/browser_toolbar_gtk.h b/chrome/browser/ui/gtk/browser_toolbar_gtk.h index db84493..bc3bc1f 100644 --- a/chrome/browser/ui/gtk/browser_toolbar_gtk.h +++ b/chrome/browser/ui/gtk/browser_toolbar_gtk.h @@ -33,7 +33,6 @@ class GtkThemeService; class LocationBar; class LocationBarViewGtk; class ReloadButtonGtk; -class ToolbarModel; namespace content { class WebContents; @@ -191,9 +190,6 @@ class BrowserToolbarGtk : public CommandObserver, // The image shown in GTK+ mode in the wrench button. GtkWidget* wrench_menu_image_; - // The model that contains the security level, text, icon to display... - ToolbarModel* model_; - GtkThemeService* theme_service_; scoped_ptr<MenuGtk> wrench_menu_; diff --git a/chrome/browser/ui/gtk/location_bar_view_gtk.cc b/chrome/browser/ui/gtk/location_bar_view_gtk.cc index 1b70265..61e021a 100644 --- a/chrome/browser/ui/gtk/location_bar_view_gtk.cc +++ b/chrome/browser/ui/gtk/location_bar_view_gtk.cc @@ -351,7 +351,6 @@ LocationBarViewGtk::LocationBarViewGtk(Browser* browser) tab_to_search_hint_icon_(NULL), tab_to_search_hint_trailing_label_(NULL), command_updater_(browser->command_controller()->command_updater()), - toolbar_model_(browser->toolbar_model()), browser_(browser), disposition_(CURRENT_TAB), transition_(content::PageTransitionFromInt( @@ -392,8 +391,9 @@ void LocationBarViewGtk::Init(bool popup_window_mode) { gtk_widget_set_redraw_on_allocate(hbox_.get(), TRUE); // Now initialize the OmniboxViewGtk. - location_entry_.reset(new OmniboxViewGtk(this, toolbar_model_, browser_, - browser_->profile(), command_updater_, popup_window_mode_, hbox_.get())); + location_entry_.reset(new OmniboxViewGtk(this, browser_, browser_->profile(), + command_updater_, popup_window_mode_, + hbox_.get())); location_entry_->Init(); g_signal_connect(hbox_.get(), "expose-event", @@ -619,6 +619,14 @@ WebContents* LocationBarViewGtk::GetWebContents() const { return browser_->tab_strip_model()->GetActiveWebContents(); } +ToolbarModel* LocationBarViewGtk::GetToolbarModel() { + return browser_->toolbar_model(); +} + +const ToolbarModel* LocationBarViewGtk::GetToolbarModel() const { + return browser_->toolbar_model(); +} + void LocationBarViewGtk::SetPreviewEnabledPageAction( ExtensionAction* page_action, bool preview_enabled) { @@ -793,9 +801,9 @@ void LocationBarViewGtk::OnInputInProgress(bool in_progress) { // This is identical to the Windows code, except that we don't proxy the call // back through the Toolbar, and just access the model here. // The edit should make sure we're only notified when something changes. - DCHECK_NE(toolbar_model_->input_in_progress(), in_progress); + DCHECK_NE(GetToolbarModel()->input_in_progress(), in_progress); - toolbar_model_->set_input_in_progress(in_progress); + GetToolbarModel()->set_input_in_progress(in_progress); Update(NULL); } @@ -871,7 +879,8 @@ void LocationBarViewGtk::UpdateContentSettingsIcons() { for (ScopedVector<PageToolViewGtk>::iterator i( content_setting_views_.begin()); i != content_setting_views_.end(); ++i) { - (*i)->Update(toolbar_model_->input_in_progress() ? NULL : GetWebContents()); + (*i)->Update(GetToolbarModel()->input_in_progress() ? + NULL : GetWebContents()); any_visible = (*i)->IsVisible() || any_visible; } @@ -916,7 +925,7 @@ void LocationBarViewGtk::UpdatePageActions() { for (size_t i = 0; i < page_action_views_.size(); i++) { page_action_views_[i]->UpdateVisibility( - toolbar_model_->input_in_progress() ? NULL : contents, url); + GetToolbarModel()->input_in_progress() ? NULL : contents, url); } gtk_widget_queue_draw(hbox_.get()); } @@ -1190,7 +1199,7 @@ void LocationBarViewGtk::UpdateSiteTypeArea() { GTK_IMAGE(location_icon_image_), theme_service_->GetImageNamed(resource_id).ToGdkPixbuf()); - if (toolbar_model_->GetSecurityLevel(false) == ToolbarModel::EV_SECURE) { + if (GetToolbarModel()->GetSecurityLevel(false) == ToolbarModel::EV_SECURE) { if (!gtk_util::IsActingAsRoundedWindow(site_type_event_box_)) { // Fun fact: If wee try to make |site_type_event_box_| act as a // rounded window while it doesn't have a visible window, GTK interprets @@ -1206,7 +1215,7 @@ void LocationBarViewGtk::UpdateSiteTypeArea() { gtk_util::BORDER_ALL); } - string16 info_text = toolbar_model_->GetEVCertName(); + string16 info_text = GetToolbarModel()->GetEVCertName(); gtk_label_set_text(GTK_LABEL(security_info_label_), UTF16ToUTF8(info_text).c_str()); @@ -1508,7 +1517,7 @@ gboolean LocationBarViewGtk::OnStarButtonPress(GtkWidget* widget, } void LocationBarViewGtk::ShowZoomBubble() { - if (toolbar_model_->input_in_progress() || !GetWebContents()) + if (GetToolbarModel()->input_in_progress() || !GetWebContents()) return; ZoomBubbleGtk::ShowBubble(GetWebContents(), true); @@ -1552,7 +1561,7 @@ void LocationBarViewGtk::UpdateZoomIcon() { ZoomController* zoom_controller = ZoomController::FromWebContents(web_contents); if (!zoom_controller || zoom_controller->IsAtDefaultZoom() || - toolbar_model_->input_in_progress()) { + GetToolbarModel()->input_in_progress()) { gtk_widget_hide(zoom_.get()); ZoomBubbleGtk::CloseBubble(); return; @@ -1592,7 +1601,7 @@ void LocationBarViewGtk::UpdateStarIcon() { // Indicate the star icon is not correctly sized. It will be marked as sized // when the next size-allocate signal is received by the star widget. star_sized_ = false; - bool star_enabled = !toolbar_model_->input_in_progress() && + bool star_enabled = !GetToolbarModel()->input_in_progress() && edit_bookmarks_enabled_.GetValue(); command_updater_->UpdateCommandEnabled(IDC_BOOKMARK_PAGE, star_enabled); command_updater_->UpdateCommandEnabled(IDC_BOOKMARK_PAGE_FROM_STAR, diff --git a/chrome/browser/ui/gtk/location_bar_view_gtk.h b/chrome/browser/ui/gtk/location_bar_view_gtk.h index b8dc178..d5b8db6 100644 --- a/chrome/browser/ui/gtk/location_bar_view_gtk.h +++ b/chrome/browser/ui/gtk/location_bar_view_gtk.h @@ -43,7 +43,6 @@ class ContentSettingBubbleGtk; class ExtensionAction; class GtkThemeService; class OmniboxViewGtk; -class ToolbarModel; namespace content { class WebContents; @@ -122,6 +121,8 @@ class LocationBarViewGtk : public OmniboxEditController, virtual string16 GetTitle() const OVERRIDE; virtual InstantController* GetInstant() OVERRIDE; virtual content::WebContents* GetWebContents() const OVERRIDE; + virtual ToolbarModel* GetToolbarModel() OVERRIDE; + virtual const ToolbarModel* GetToolbarModel() const OVERRIDE; // LocationBar: virtual void ShowFirstRunBubble() OVERRIDE; @@ -482,7 +483,6 @@ class LocationBarViewGtk : public OmniboxEditController, GtkWidget* location_entry_alignment_; CommandUpdater* command_updater_; - ToolbarModel* toolbar_model_; Browser* browser_; // When we get an OnAutocompleteAccept notification from the autocomplete diff --git a/chrome/browser/ui/gtk/omnibox/omnibox_view_gtk.cc b/chrome/browser/ui/gtk/omnibox/omnibox_view_gtk.cc index 5a59902..28e0462 100644 --- a/chrome/browser/ui/gtk/omnibox/omnibox_view_gtk.cc +++ b/chrome/browser/ui/gtk/omnibox/omnibox_view_gtk.cc @@ -176,13 +176,12 @@ void DoWriteToClipboard(const GURL& url, const string16& text) { } // namespace OmniboxViewGtk::OmniboxViewGtk(OmniboxEditController* controller, - ToolbarModel* toolbar_model, Browser* browser, Profile* profile, CommandUpdater* command_updater, bool popup_window_mode, GtkWidget* location_bar) - : OmniboxView(profile, controller, toolbar_model, command_updater), + : OmniboxView(profile, controller, command_updater), browser_(browser), text_view_(NULL), tag_table_(NULL), @@ -453,11 +452,11 @@ void OmniboxViewGtk::SaveStateToTab(WebContents* tab) { void OmniboxViewGtk::Update(const WebContents* contents) { // NOTE: We're getting the URL text here from the ToolbarModel. - bool visibly_changed_permanent_text = - model()->UpdatePermanentText(toolbar_model()->GetText(true)); + bool visibly_changed_permanent_text = model()->UpdatePermanentText( + controller()->GetToolbarModel()->GetText(true)); ToolbarModel::SecurityLevel security_level = - toolbar_model()->GetSecurityLevel(false); + controller()->GetToolbarModel()->GetSecurityLevel(false); bool changed_security_level = (security_level != security_level_); security_level_ = security_level; @@ -1261,7 +1260,8 @@ void OmniboxViewGtk::HandlePopulatePopup(GtkWidget* sender, GtkMenu* menu) { G_CALLBACK(HandleCopyURLClipboardThunk), this); gtk_widget_set_sensitive( copy_url_menuitem, - toolbar_model()->WouldReplaceSearchURLWithSearchTerms(false)); + controller()->GetToolbarModel()->WouldReplaceSearchURLWithSearchTerms( + false)); gtk_widget_show(copy_url_menuitem); } @@ -1564,8 +1564,8 @@ void OmniboxViewGtk::HandleCopyClipboard(GtkWidget* sender) { } void OmniboxViewGtk::HandleCopyURLClipboard(GtkWidget* sender) { - DoWriteToClipboard(toolbar_model()->GetURL(), - toolbar_model()->GetText(false)); + DoWriteToClipboard(controller()->GetToolbarModel()->GetURL(), + controller()->GetToolbarModel()->GetText(false)); } void OmniboxViewGtk::HandleCutClipboard(GtkWidget* sender) { diff --git a/chrome/browser/ui/gtk/omnibox/omnibox_view_gtk.h b/chrome/browser/ui/gtk/omnibox/omnibox_view_gtk.h index 8ec060f..eff5b7d 100644 --- a/chrome/browser/ui/gtk/omnibox/omnibox_view_gtk.h +++ b/chrome/browser/ui/gtk/omnibox/omnibox_view_gtk.h @@ -57,7 +57,6 @@ class OmniboxViewGtk : public OmniboxView, // In other use case, you should pass browser->profile() object as // profile parameter. OmniboxViewGtk(OmniboxEditController* controller, - ToolbarModel* toolbar_model, Browser* browser, Profile* profile, CommandUpdater* command_updater, diff --git a/chrome/browser/ui/gtk/omnibox/omnibox_view_gtk_unittest.cc b/chrome/browser/ui/gtk/omnibox/omnibox_view_gtk_unittest.cc index a77871a..e46b914 100644 --- a/chrome/browser/ui/gtk/omnibox/omnibox_view_gtk_unittest.cc +++ b/chrome/browser/ui/gtk/omnibox/omnibox_view_gtk_unittest.cc @@ -33,6 +33,8 @@ class OmniboxEditControllerMock : public OmniboxEditController { MOCK_CONST_METHOD0(GetTitle, string16()); MOCK_METHOD0(GetInstant, InstantController*()); MOCK_CONST_METHOD0(GetWebContents, content::WebContents*()); + MOCK_METHOD0(GetToolbarModel, ToolbarModel*()); + MOCK_CONST_METHOD0(GetToolbarModel, ToolbarModel*()); virtual ~OmniboxEditControllerMock() {} }; @@ -47,9 +49,7 @@ class OmniboxViewGtkTest : public PlatformTest { profile_.reset(new TestingProfile); window_ = gtk_window_new(GTK_WINDOW_POPUP); controller_.reset(new OmniboxEditControllerMock); - view_.reset(new OmniboxViewGtk(controller_.get(), NULL, - NULL, - profile_.get(), + view_.reset(new OmniboxViewGtk(controller_.get(), NULL, profile_.get(), NULL, false, window_)); view_->Init(); text_buffer_ = view_->text_buffer_; diff --git a/chrome/browser/ui/omnibox/omnibox_edit_controller.h b/chrome/browser/ui/omnibox/omnibox_edit_controller.h index b651739..82f0e4d 100644 --- a/chrome/browser/ui/omnibox/omnibox_edit_controller.h +++ b/chrome/browser/ui/omnibox/omnibox_edit_controller.h @@ -11,6 +11,7 @@ class GURL; class InstantController; +class ToolbarModel; namespace content { class WebContents; @@ -69,6 +70,9 @@ class OmniboxEditController { // Returns the WebContents of the currently active tab. virtual content::WebContents* GetWebContents() const = 0; + virtual ToolbarModel* GetToolbarModel() = 0; + virtual const ToolbarModel* GetToolbarModel() const = 0; + protected: virtual ~OmniboxEditController() {} }; diff --git a/chrome/browser/ui/omnibox/omnibox_edit_model.cc b/chrome/browser/ui/omnibox/omnibox_edit_model.cc index 456a6f4..5661b29 100644 --- a/chrome/browser/ui/omnibox/omnibox_edit_model.cc +++ b/chrome/browser/ui/omnibox/omnibox_edit_model.cc @@ -49,6 +49,7 @@ #include "chrome/browser/ui/omnibox/omnibox_view.h" #include "chrome/browser/ui/search/instant_controller.h" #include "chrome/browser/ui/search/search_tab_helper.h" +#include "chrome/browser/ui/toolbar/toolbar_model.h" #include "chrome/common/chrome_switches.h" #include "chrome/common/net/url_fixer_upper.h" #include "chrome/common/pref_names.h" @@ -357,7 +358,8 @@ void OmniboxEditModel::GetDataForURLExport(GURL* url, } bool OmniboxEditModel::CurrentTextIsURL() const { - if (view_->toolbar_model()->WouldReplaceSearchURLWithSearchTerms(false)) + if (controller_->GetToolbarModel()->WouldReplaceSearchURLWithSearchTerms( + false)) return false; // If current text is not composed of replaced search terms and @@ -385,7 +387,8 @@ void OmniboxEditModel::AdjustTextForCopy(int sel_min, // Do not adjust if selection did not start at the beginning of the field, or // if the URL was replaced by search terms. if ((sel_min != 0) || - view_->toolbar_model()->WouldReplaceSearchURLWithSearchTerms(false)) + controller_->GetToolbarModel()->WouldReplaceSearchURLWithSearchTerms( + false)) return; if (!user_input_in_progress_ && is_all_selected) { @@ -727,7 +730,8 @@ void OmniboxEditModel::OpenMatch(const AutocompleteMatch& match, RecordPercentageMatchHistogram( permanent_text_, current_text, - view_->toolbar_model()->WouldReplaceSearchURLWithSearchTerms(false), + controller_->GetToolbarModel()->WouldReplaceSearchURLWithSearchTerms( + false), match.transition); // Track whether the destination URL sends us to a search results page @@ -1188,7 +1192,8 @@ void OmniboxEditModel::GetInfoForCurrentText(AutocompleteMatch* match, DCHECK(match != NULL); if (!user_input_in_progress_ && - view_->toolbar_model()->WouldReplaceSearchURLWithSearchTerms(false)) { + controller_->GetToolbarModel()->WouldReplaceSearchURLWithSearchTerms( + false)) { // Any time the user hits enter on the unchanged omnibox, we should reload. // When we're not extracting search terms, AcceptInput() will take care of // this (see code referring to PAGE_TRANSITION_RELOAD there), but when we're @@ -1310,7 +1315,8 @@ AutocompleteInput::PageClassification OmniboxEditModel::ClassifyPage() const { return AutocompleteInput::BLANK; if (url == profile()->GetPrefs()->GetString(prefs::kHomePage)) return AutocompleteInput::HOMEPAGE; - if (view_->toolbar_model()->WouldReplaceSearchURLWithSearchTerms(true)) { + if (controller_->GetToolbarModel()->WouldReplaceSearchURLWithSearchTerms( + true)) { return AutocompleteInput::SEARCH_RESULT_PAGE_DOING_SEARCH_TERM_REPLACEMENT; } if (delegate_->IsSearchResultsPage()) { diff --git a/chrome/browser/ui/omnibox/omnibox_edit_unittest.cc b/chrome/browser/ui/omnibox/omnibox_edit_unittest.cc index 1424011..0374859 100644 --- a/chrome/browser/ui/omnibox/omnibox_edit_unittest.cc +++ b/chrome/browser/ui/omnibox/omnibox_edit_unittest.cc @@ -21,8 +21,8 @@ namespace { class TestingOmniboxView : public OmniboxView { public: - explicit TestingOmniboxView(ToolbarModel* model) - : OmniboxView(NULL, NULL, model, NULL) {} + explicit TestingOmniboxView(OmniboxEditController* controller) + : OmniboxView(NULL, controller, NULL) {} virtual void SaveStateToTab(WebContents* tab) OVERRIDE {} virtual void Update(const WebContents* tab_for_state_restoring) OVERRIDE {} @@ -88,7 +88,8 @@ class TestingOmniboxView : public OmniboxView { class TestingOmniboxEditController : public OmniboxEditController { public: - TestingOmniboxEditController() {} + explicit TestingOmniboxEditController(ToolbarModel* toolbar_model) + : toolbar_model_(toolbar_model) {} virtual void OnAutocompleteAccept(const GURL& url, WindowOpenDisposition disposition, content::PageTransition transition, @@ -104,8 +105,14 @@ class TestingOmniboxEditController : public OmniboxEditController { virtual WebContents* GetWebContents() const OVERRIDE { return NULL; } + virtual ToolbarModel* GetToolbarModel() OVERRIDE { return toolbar_model_; } + virtual const ToolbarModel* GetToolbarModel() const OVERRIDE { + return toolbar_model_; + } private: + ToolbarModel* toolbar_model_; + DISALLOW_COPY_AND_ASSIGN(TestingOmniboxEditController); }; @@ -173,8 +180,8 @@ TEST_F(AutocompleteEditTest, AdjustTextForCopy) { { "www.google.com/webhp?", 0, true, "hello world", "hello world", false, "", true }, }; - TestingOmniboxView view(toolbar_model()); - TestingOmniboxEditController controller; + TestingOmniboxEditController controller(toolbar_model()); + TestingOmniboxView view(&controller); TestingProfile profile; // NOTE: The TemplateURLService must be created before the // AutocompleteClassifier so that the SearchProvider gets a non-NULL diff --git a/chrome/browser/ui/omnibox/omnibox_view.cc b/chrome/browser/ui/omnibox/omnibox_view.cc index 4ef5518..883ec68 100644 --- a/chrome/browser/ui/omnibox/omnibox_view.cc +++ b/chrome/browser/ui/omnibox/omnibox_view.cc @@ -11,6 +11,8 @@ #include "base/strings/string_util.h" #include "base/strings/utf_string_conversions.h" #include "chrome/browser/autocomplete/autocomplete_match.h" +#include "chrome/browser/ui/omnibox/omnibox_edit_controller.h" +#include "chrome/browser/ui/toolbar/toolbar_model.h" #include "ui/base/clipboard/clipboard.h" // static @@ -99,7 +101,7 @@ int OmniboxView::GetIcon() const { model_->CurrentTextType() : AutocompleteMatchType::URL_WHAT_YOU_TYPED); } else { - return toolbar_model_->GetIcon(); + return controller_->GetToolbarModel()->GetIcon(); } } @@ -143,10 +145,8 @@ bool OmniboxView::IsIndicatingQueryRefinement() const { OmniboxView::OmniboxView(Profile* profile, OmniboxEditController* controller, - ToolbarModel* toolbar_model, CommandUpdater* command_updater) : controller_(controller), - toolbar_model_(toolbar_model), command_updater_(command_updater) { // |profile| can be NULL in tests. if (profile) diff --git a/chrome/browser/ui/omnibox/omnibox_view.h b/chrome/browser/ui/omnibox/omnibox_view.h index a138de5..62c4c63 100644 --- a/chrome/browser/ui/omnibox/omnibox_view.h +++ b/chrome/browser/ui/omnibox/omnibox_view.h @@ -18,7 +18,6 @@ #include "base/strings/utf_string_conversions.h" #include "chrome/browser/autocomplete/autocomplete_match.h" #include "chrome/browser/ui/omnibox/omnibox_edit_model.h" -#include "chrome/browser/ui/toolbar/toolbar_model.h" #include "content/public/common/url_constants.h" #include "ui/base/window_open_disposition.h" #include "ui/gfx/native_widget_types.h" @@ -60,9 +59,6 @@ class OmniboxView { CommandUpdater* command_updater() { return command_updater_; } const CommandUpdater* command_updater() const { return command_updater_; } - ToolbarModel* toolbar_model() { return toolbar_model_; } - const ToolbarModel* toolbar_model() const { return toolbar_model_; } - // For use when switching tabs, this saves the current state onto the tab so // that it can be restored during a later call to Update(). virtual void SaveStateToTab(content::WebContents* tab) = 0; @@ -251,7 +247,6 @@ class OmniboxView { protected: OmniboxView(Profile* profile, OmniboxEditController* controller, - ToolbarModel* toolbar_model, CommandUpdater* command_updater); // Internally invoked whenever the text changes in some way. @@ -266,6 +261,7 @@ class OmniboxView { virtual void EmphasizeURLComponents() = 0; OmniboxEditController* controller() { return controller_; } + const OmniboxEditController* controller() const { return controller_; } private: friend class OmniboxViewMacTest; @@ -273,7 +269,6 @@ class OmniboxView { // |model_| can be NULL in tests. scoped_ptr<OmniboxEditModel> model_; OmniboxEditController* controller_; - ToolbarModel* toolbar_model_; // The object that handles additional command functionality exposed on the // edit, such as invoking the keyword editor. diff --git a/chrome/browser/ui/search/search_delegate.cc b/chrome/browser/ui/search/search_delegate.cc index 2af2654..31e763d 100644 --- a/chrome/browser/ui/search/search_delegate.cc +++ b/chrome/browser/ui/search/search_delegate.cc @@ -7,8 +7,7 @@ #include "chrome/browser/ui/search/search_model.h" #include "chrome/browser/ui/search/search_tab_helper.h" -SearchDelegate::SearchDelegate(SearchModel* browser_search_model, - ToolbarModel* toolbar_model) +SearchDelegate::SearchDelegate(SearchModel* browser_search_model) : browser_model_(browser_search_model), tab_model_() { } diff --git a/chrome/browser/ui/search/search_delegate.h b/chrome/browser/ui/search/search_delegate.h index da8c8c4..c424453 100644 --- a/chrome/browser/ui/search/search_delegate.h +++ b/chrome/browser/ui/search/search_delegate.h @@ -9,8 +9,6 @@ #include "base/compiler_specific.h" #include "chrome/browser/ui/search/search_model_observer.h" -class ToolbarModel; - namespace content { class WebContents; } @@ -25,8 +23,7 @@ class SearchModel; // Browser-level model. class SearchDelegate : public SearchModelObserver { public: - SearchDelegate(SearchModel* browser_search_model, - ToolbarModel* toolbar_model); + explicit SearchDelegate(SearchModel* browser_search_model); virtual ~SearchDelegate(); // Overrides for SearchModelObserver: diff --git a/chrome/browser/ui/views/location_bar/generated_credit_card_view.cc b/chrome/browser/ui/views/location_bar/generated_credit_card_view.cc index 024bfb2..38ce6ad 100644 --- a/chrome/browser/ui/views/location_bar/generated_credit_card_view.cc +++ b/chrome/browser/ui/views/location_bar/generated_credit_card_view.cc @@ -9,10 +9,8 @@ #include "ui/gfx/image/image.h" GeneratedCreditCardView::GeneratedCreditCardView( - ToolbarModel* toolbar_model, LocationBarView::Delegate* delegate) - : toolbar_model_(toolbar_model), - delegate_(delegate) { + : delegate_(delegate) { Update(); } @@ -45,7 +43,7 @@ void GeneratedCreditCardView::OnClick() { autofill::GeneratedCreditCardBubbleController* GeneratedCreditCardView:: GetController() const { content::WebContents* wc = delegate_->GetWebContents(); - if (!wc || toolbar_model_->input_in_progress()) + if (!wc || delegate_->GetToolbarModel()->input_in_progress()) return NULL; return autofill::GeneratedCreditCardBubbleController::FromWebContents(wc); diff --git a/chrome/browser/ui/views/location_bar/generated_credit_card_view.h b/chrome/browser/ui/views/location_bar/generated_credit_card_view.h index c741985..5dda7f3 100644 --- a/chrome/browser/ui/views/location_bar/generated_credit_card_view.h +++ b/chrome/browser/ui/views/location_bar/generated_credit_card_view.h @@ -12,8 +12,6 @@ #include "chrome/browser/ui/views/location_bar/location_bar_view.h" #include "ui/views/controls/image_view.h" -class ToolbarModel; - namespace autofill { class GeneratedCreditCardBubbleController; } @@ -29,8 +27,7 @@ class GeneratedCreditCardBubbleController; //////////////////////////////////////////////////////////////////////////////// class GeneratedCreditCardView : public LocationBarDecorationView { public: - GeneratedCreditCardView(ToolbarModel* toolbar_model, - LocationBarView::Delegate* delegate); + explicit GeneratedCreditCardView(LocationBarView::Delegate* delegate); virtual ~GeneratedCreditCardView(); void Update(); @@ -45,7 +42,6 @@ class GeneratedCreditCardView : public LocationBarDecorationView { // current web contents. autofill::GeneratedCreditCardBubbleController* GetController() const; - ToolbarModel* toolbar_model_; // weak; outlives us. LocationBarView::Delegate* delegate_; // weak; outlives us. DISALLOW_COPY_AND_ASSIGN(GeneratedCreditCardView); 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 bc9ded4..bb78a3e 100644 --- a/chrome/browser/ui/views/location_bar/location_bar_view.cc +++ b/chrome/browser/ui/views/location_bar/location_bar_view.cc @@ -164,13 +164,11 @@ const char LocationBarView::kViewClassName[] = "LocationBarView"; LocationBarView::LocationBarView(Browser* browser, Profile* profile, CommandUpdater* command_updater, - ToolbarModel* model, Delegate* delegate, bool is_popup_mode) : browser_(browser), profile_(profile), command_updater_(command_updater), - model_(model), delegate_(delegate), disposition_(CURRENT_TAB), transition_(content::PageTransitionFromInt( @@ -280,8 +278,9 @@ void LocationBarView::Init() { AddChildView(ev_bubble_view_); // Initialize the Omnibox view. - location_entry_.reset(CreateOmniboxView(this, model_, profile_, - command_updater_, is_popup_mode_, this, font_list, font_y_offset)); + location_entry_.reset(CreateOmniboxView(this, profile_, command_updater_, + is_popup_mode_, this, font_list, + font_y_offset)); SetLocationEntryFocusable(true); location_entry_view_ = location_entry_->AddToView(this); @@ -361,10 +360,10 @@ void LocationBarView::Init() { AddChildView(content_blocked_view); } - generated_credit_card_view_ = new GeneratedCreditCardView(model_, delegate_); + generated_credit_card_view_ = new GeneratedCreditCardView(delegate_); AddChildView(generated_credit_card_view_); - zoom_view_ = new ZoomView(model_, delegate_); + zoom_view_ = new ZoomView(delegate_); zoom_view_->set_id(VIEW_ID_ZOOM_BUTTON); AddChildView(zoom_view_); @@ -497,7 +496,7 @@ void LocationBarView::SetAnimationOffset(int offset) { void LocationBarView::Update(const WebContents* tab_for_state_restoring) { mic_search_view_->SetVisible( - !model_->input_in_progress() && browser_ && + !GetToolbarModel()->input_in_progress() && browser_ && browser_->search_model()->voice_search_supported()); RefreshContentSettingViews(); generated_credit_card_view_->Update(); @@ -506,10 +505,10 @@ void LocationBarView::Update(const WebContents* tab_for_state_restoring) { RefreshPageActionViews(); RefreshScriptBubble(); open_pdf_in_reader_view_->Update( - model_->input_in_progress() ? NULL : GetWebContents()); + GetToolbarModel()->input_in_progress() ? NULL : GetWebContents()); bool star_enabled = browser_defaults::bookmarks_enabled && !is_popup_mode_ && - star_view_ && !model_->input_in_progress() && + star_view_ && !GetToolbarModel()->input_in_progress() && edit_bookmarks_enabled_.GetValue(); command_updater_->UpdateCommandEnabled(IDC_BOOKMARK_PAGE, star_enabled); @@ -558,7 +557,7 @@ void LocationBarView::InvalidatePageActions() { void LocationBarView::UpdateOpenPDFInReaderPrompt() { open_pdf_in_reader_view_->Update( - model_->input_in_progress() ? NULL : GetWebContents()); + GetToolbarModel()->input_in_progress() ? NULL : GetWebContents()); Layout(); SchedulePaint(); } @@ -597,7 +596,7 @@ void LocationBarView::SetPreviewEnabledPageAction(ExtensionAction* page_action, return; page_action_view->image_view()->set_preview_enabled(preview_enabled); - page_action_view->UpdateVisibility(contents, model_->GetURL()); + page_action_view->UpdateVisibility(contents, GetToolbarModel()->GetURL()); Layout(); SchedulePaint(); } @@ -739,8 +738,9 @@ void LocationBarView::Layout() { selected_keyword_view_->set_is_extension_icon(false); } } - } else if (model_->GetSecurityLevel(false) == ToolbarModel::EV_SECURE) { - ev_bubble_view_->SetLabel(model_->GetEVCertName()); + } else if (GetToolbarModel()->GetSecurityLevel(false) == + ToolbarModel::EV_SECURE) { + ev_bubble_view_->SetLabel(GetToolbarModel()->GetEVCertName()); // The largest fraction of the omnibox that can be taken by the EV bubble. const double kMaxBubbleFraction = 0.5; leading_decorations.AddDecoration(bubble_location_y, bubble_height, false, @@ -1111,6 +1111,14 @@ WebContents* LocationBarView::GetWebContents() const { return delegate_->GetWebContents(); } +ToolbarModel* LocationBarView::GetToolbarModel() { + return delegate_->GetToolbarModel(); +} + +const ToolbarModel* LocationBarView::GetToolbarModel() const { + return delegate_->GetToolbarModel(); +} + // static int LocationBarView::GetBuiltInHorizontalPaddingForChildViews() { return (ui::GetDisplayLayout() == ui::LAYOUT_TOUCH) ? @@ -1126,7 +1134,8 @@ int LocationBarView::GetHorizontalEdgeThickness() const { void LocationBarView::RefreshContentSettingViews() { for (ContentSettingViews::const_iterator i(content_setting_views_.begin()); i != content_setting_views_.end(); ++i) { - (*i)->Update(model_->input_in_progress() ? NULL : GetWebContents()); + (*i)->Update(GetToolbarModel()->input_in_progress() ? + NULL : GetWebContents()); } } @@ -1190,8 +1199,8 @@ void LocationBarView::RefreshPageActionViews() { for (PageActionViews::const_iterator i(page_action_views_.begin()); i != page_action_views_.end(); ++i) { - (*i)->UpdateVisibility(model_->input_in_progress() ? NULL : contents, - url); + (*i)->UpdateVisibility( + GetToolbarModel()->input_in_progress() ? NULL : contents, url); // Check if the visibility of the action changed and notify if it did. ExtensionAction* action = (*i)->image_view()->page_action(); @@ -1263,7 +1272,7 @@ void LocationBarView::PaintPageActionBackgrounds(gfx::Canvas* canvas) { const int32 tab_id = SessionID::IdForTab(web_contents); const ToolbarModel::SecurityLevel security_level = - model_->GetSecurityLevel(false); + GetToolbarModel()->GetSecurityLevel(false); const SkColor text_color = GetColor(security_level, TEXT); const SkColor background_color = GetColor(security_level, BACKGROUND); @@ -1530,7 +1539,7 @@ void LocationBarView::Observe(int type, void LocationBarView::ModelChanged(const SearchModel::State& old_state, const SearchModel::State& new_state) { - const bool visible = !model_->input_in_progress() && + const bool visible = !GetToolbarModel()->input_in_progress() && new_state.voice_search_supported; if (mic_search_view_->visible() != visible) { mic_search_view_->SetVisible(visible); diff --git a/chrome/browser/ui/views/location_bar/location_bar_view.h b/chrome/browser/ui/views/location_bar/location_bar_view.h index 2c14ff7..25139d1 100644 --- a/chrome/browser/ui/views/location_bar/location_bar_view.h +++ b/chrome/browser/ui/views/location_bar/location_bar_view.h @@ -96,6 +96,9 @@ class LocationBarView : public LocationBar, // Returns the InstantController, or NULL if there isn't one. virtual InstantController* GetInstant() = 0; + virtual ToolbarModel* GetToolbarModel() = 0; + virtual const ToolbarModel* GetToolbarModel() const = 0; + // Creates Widget for the given delegate. virtual views::Widget* CreateViewsBubble( views::BubbleDelegateView* bubble_delegate) = 0; @@ -134,7 +137,6 @@ class LocationBarView : public LocationBar, LocationBarView(Browser* browser, Profile* profile, CommandUpdater* command_updater, - ToolbarModel* model, Delegate* delegate, bool is_popup_mode); @@ -267,6 +269,8 @@ class LocationBarView : public LocationBar, virtual string16 GetTitle() const OVERRIDE; virtual InstantController* GetInstant() OVERRIDE; virtual content::WebContents* GetWebContents() const OVERRIDE; + virtual ToolbarModel* GetToolbarModel() OVERRIDE; + virtual const ToolbarModel* GetToolbarModel() const OVERRIDE; // views::View: virtual const char* GetClassName() const OVERRIDE; @@ -432,9 +436,6 @@ class LocationBarView : public LocationBar, // Command updater which corresponds to this View. CommandUpdater* command_updater_; - // The model. - ToolbarModel* model_; - // Our delegate. Delegate* delegate_; diff --git a/chrome/browser/ui/views/location_bar/zoom_view.cc b/chrome/browser/ui/views/location_bar/zoom_view.cc index 405fe5e..0ed27fb 100644 --- a/chrome/browser/ui/views/location_bar/zoom_view.cc +++ b/chrome/browser/ui/views/location_bar/zoom_view.cc @@ -16,10 +16,8 @@ #include "ui/base/resource/resource_bundle.h" #include "ui/gfx/size.h" -ZoomView::ZoomView(ToolbarModel* toolbar_model, - LocationBarView::Delegate* location_bar_delegate) - : toolbar_model_(toolbar_model), - location_bar_delegate_(location_bar_delegate) { +ZoomView::ZoomView(LocationBarView::Delegate* location_bar_delegate) + : location_bar_delegate_(location_bar_delegate) { set_accessibility_focusable(true); Update(NULL); LocationBarView::InitTouchableLocationBarChildView(this); @@ -30,7 +28,7 @@ ZoomView::~ZoomView() { void ZoomView::Update(ZoomController* zoom_controller) { if (!zoom_controller || zoom_controller->IsAtDefaultZoom() || - toolbar_model_->input_in_progress()) { + location_bar_delegate_->GetToolbarModel()->input_in_progress()) { SetVisible(false); ZoomBubbleView::CloseBubble(); return; diff --git a/chrome/browser/ui/views/location_bar/zoom_view.h b/chrome/browser/ui/views/location_bar/zoom_view.h index bc3876d..0bac5d2 100644 --- a/chrome/browser/ui/views/location_bar/zoom_view.h +++ b/chrome/browser/ui/views/location_bar/zoom_view.h @@ -10,7 +10,6 @@ #include "chrome/browser/ui/views/location_bar/location_bar_view.h" #include "ui/views/controls/image_view.h" -class ToolbarModel; class ZoomController; // View for the zoom icon in the Omnibox. @@ -21,8 +20,7 @@ class ZoomView : public views::ImageView { // tabs, it cannot be provided in the constructor. Instead, a // LocationBarView::Delegate is passed here so that it can be queried for the // current WebContents as needed. - ZoomView(ToolbarModel* toolbar_model, - LocationBarView::Delegate* location_bar_delegate); + explicit ZoomView(LocationBarView::Delegate* location_bar_delegate); virtual ~ZoomView(); // Updates the image and its tooltip appropriately, hiding or showing the icon @@ -45,9 +43,6 @@ class ZoomView : public views::ImageView { // widget. void ActivateBubble(); - // Toolbar model used to test whether location bar input is in progress. - ToolbarModel* toolbar_model_; - // The delegate used to get the currently visible WebContents. LocationBarView::Delegate* location_bar_delegate_; diff --git a/chrome/browser/ui/views/omnibox/omnibox_view_views.cc b/chrome/browser/ui/views/omnibox/omnibox_view_views.cc index 522996e..c58534a 100644 --- a/chrome/browser/ui/views/omnibox/omnibox_view_views.cc +++ b/chrome/browser/ui/views/omnibox/omnibox_view_views.cc @@ -99,14 +99,13 @@ bool IsOmniboxAutoCompletionForImeEnabled() { const char OmniboxViewViews::kViewClassName[] = "OmniboxViewViews"; OmniboxViewViews::OmniboxViewViews(OmniboxEditController* controller, - ToolbarModel* toolbar_model, Profile* profile, CommandUpdater* command_updater, bool popup_window_mode, LocationBarView* location_bar, const gfx::FontList& font_list, int font_y_offset) - : OmniboxView(profile, controller, toolbar_model, command_updater), + : OmniboxView(profile, controller, command_updater), popup_window_mode_(popup_window_mode), security_level_(ToolbarModel::NONE), ime_composing_before_change_(false), @@ -203,7 +202,8 @@ void OmniboxViewViews::OnMouseReleased(const ui::MouseEvent& event) { // query is common enough that we do click-to-place-cursor). if ((event.IsOnlyLeftMouseButton() || event.IsOnlyRightMouseButton()) && select_all_on_mouse_release_ && - !toolbar_model()->WouldReplaceSearchURLWithSearchTerms(false)) { + !controller()->GetToolbarModel()->WouldReplaceSearchURLWithSearchTerms( + false)) { // Select all in the reverse direction so as not to scroll the caret // into view and shift the contents jarringly. SelectAll(true); @@ -366,10 +366,10 @@ void OmniboxViewViews::SaveStateToTab(content::WebContents* tab) { void OmniboxViewViews::Update(const content::WebContents* contents) { // NOTE: We're getting the URL text here from the ToolbarModel. - bool visibly_changed_permanent_text = - model()->UpdatePermanentText(toolbar_model()->GetText(true)); + bool visibly_changed_permanent_text = model()->UpdatePermanentText( + controller()->GetToolbarModel()->GetText(true)); ToolbarModel::SecurityLevel security_level = - toolbar_model()->GetSecurityLevel(false); + controller()->GetToolbarModel()->GetSecurityLevel(false); bool changed_security_level = (security_level != security_level_); security_level_ = security_level; @@ -778,9 +778,10 @@ void OmniboxViewViews::UpdateContextMenu(ui::SimpleMenuModel* menu_contents) { bool OmniboxViewViews::IsCommandIdEnabled(int command_id) const { if (command_id == IDS_PASTE_AND_GO) return model()->CanPasteAndGo(GetClipboardText()); - if (command_id == IDC_COPY_URL) - return toolbar_model()->WouldReplaceSearchURLWithSearchTerms(false); - return command_updater()->IsCommandEnabled(command_id); + if (command_id != IDC_COPY_URL) + return command_updater()->IsCommandEnabled(command_id); + return controller()->GetToolbarModel()->WouldReplaceSearchURLWithSearchTerms( + false); } bool OmniboxViewViews::IsItemForCommandIdDynamic(int command_id) const { @@ -899,7 +900,8 @@ string16 OmniboxViewViews::GetSelectedText() const { } void OmniboxViewViews::CopyURL() { - DoCopyURL(toolbar_model()->GetURL(), toolbar_model()->GetText(false)); + DoCopyURL(controller()->GetToolbarModel()->GetURL(), + controller()->GetToolbarModel()->GetText(false)); } void OmniboxViewViews::OnPaste() { diff --git a/chrome/browser/ui/views/omnibox/omnibox_view_views.h b/chrome/browser/ui/views/omnibox/omnibox_view_views.h index f853248..dff230c 100644 --- a/chrome/browser/ui/views/omnibox/omnibox_view_views.h +++ b/chrome/browser/ui/views/omnibox/omnibox_view_views.h @@ -42,7 +42,6 @@ class OmniboxViewViews static const char kViewClassName[]; OmniboxViewViews(OmniboxEditController* controller, - ToolbarModel* toolbar_model, Profile* profile, CommandUpdater* command_updater, bool popup_window_mode, diff --git a/chrome/browser/ui/views/omnibox/omnibox_view_win.cc b/chrome/browser/ui/views/omnibox/omnibox_view_win.cc index 6be567f..2ecd259 100644 --- a/chrome/browser/ui/views/omnibox/omnibox_view_win.cc +++ b/chrome/browser/ui/views/omnibox/omnibox_view_win.cc @@ -460,14 +460,12 @@ const int kTwipsPerInch = 1440; HMODULE OmniboxViewWin::loaded_library_module_ = NULL; OmniboxViewWin::OmniboxViewWin(OmniboxEditController* controller, - ToolbarModel* toolbar_model, LocationBarView* location_bar, CommandUpdater* command_updater, bool popup_window_mode, const gfx::FontList& font_list, int font_y_offset) - : OmniboxView(location_bar->profile(), controller, toolbar_model, - command_updater), + : OmniboxView(location_bar->profile(), controller, command_updater), popup_view_(OmniboxPopupContentsView::Create( font_list, this, model(), location_bar)), location_bar_(location_bar), @@ -599,11 +597,11 @@ void OmniboxViewWin::SaveStateToTab(WebContents* tab) { } void OmniboxViewWin::Update(const WebContents* tab_for_state_restoring) { - const bool visibly_changed_permanent_text = - model()->UpdatePermanentText(toolbar_model()->GetText(true)); + const bool visibly_changed_permanent_text = model()->UpdatePermanentText( + controller()->GetToolbarModel()->GetText(true)); const ToolbarModel::SecurityLevel security_level = - toolbar_model()->GetSecurityLevel(false); + controller()->GetToolbarModel()->GetSecurityLevel(false); const bool changed_security_level = (security_level != security_level_); // Bail early when no visible state will actually change (prevents an @@ -1105,7 +1103,8 @@ int OmniboxViewWin::OnPerformDropImpl(const ui::DropTargetEvent& event, } void OmniboxViewWin::CopyURL() { - DoCopyURL(toolbar_model()->GetURL(), toolbar_model()->GetText(false)); + DoCopyURL(controller()->GetToolbarModel()->GetURL(), + controller()->GetToolbarModel()->GetText(false)); } bool OmniboxViewWin::SkipDefaultKeyEventProcessing(const ui::KeyEvent& event) { @@ -1177,7 +1176,8 @@ bool OmniboxViewWin::IsCommandIdEnabled(int command_id) const { return !!CanCopy(); case IDC_COPY_URL: return !!CanCopy() && - toolbar_model()->WouldReplaceSearchURLWithSearchTerms(false); + controller()->GetToolbarModel()->WouldReplaceSearchURLWithSearchTerms( + false); case IDC_PASTE: return !!CanPaste(); case IDS_PASTE_AND_GO: @@ -2801,7 +2801,8 @@ void OmniboxViewWin::SelectAllIfNecessary(MouseButton button, // query is common enough that we do click-to-place-cursor). if (tracking_click_[button] && !IsDrag(click_point_[button], point) && - !toolbar_model()->WouldReplaceSearchURLWithSearchTerms(false)) { + !controller()->GetToolbarModel()->WouldReplaceSearchURLWithSearchTerms( + false)) { // Select all in the reverse direction so as not to scroll the caret // into view and shift the contents jarringly. SelectAll(true); diff --git a/chrome/browser/ui/views/omnibox/omnibox_view_win.h b/chrome/browser/ui/views/omnibox/omnibox_view_win.h index 89a91b6..df1a239 100644 --- a/chrome/browser/ui/views/omnibox/omnibox_view_win.h +++ b/chrome/browser/ui/views/omnibox/omnibox_view_win.h @@ -59,7 +59,6 @@ class OmniboxViewWin DECLARE_WND_SUPERCLASS(L"Chrome_OmniboxView", MSFTEDIT_CLASS); OmniboxViewWin(OmniboxEditController* controller, - ToolbarModel* toolbar_model, LocationBarView* parent_view, CommandUpdater* command_updater, bool popup_window_mode, diff --git a/chrome/browser/ui/views/omnibox/omnibox_views.cc b/chrome/browser/ui/views/omnibox/omnibox_views.cc index 14bec61..fc9dc1f 100644 --- a/chrome/browser/ui/views/omnibox/omnibox_views.cc +++ b/chrome/browser/ui/views/omnibox/omnibox_views.cc @@ -28,7 +28,6 @@ OmniboxViewWin* GetOmniboxViewWin(OmniboxView* view) { } OmniboxView* CreateOmniboxView(OmniboxEditController* controller, - ToolbarModel* toolbar_model, Profile* profile, CommandUpdater* command_updater, bool popup_window_mode, @@ -37,14 +36,13 @@ OmniboxView* CreateOmniboxView(OmniboxEditController* controller, int font_y_offset) { #if defined(OS_WIN) && !defined(USE_AURA) if (!views::Textfield::IsViewsTextfieldEnabled()) { - return new OmniboxViewWin( - controller, toolbar_model, location_bar, command_updater, - popup_window_mode, font_list, font_y_offset); + return new OmniboxViewWin(controller, location_bar, command_updater, + popup_window_mode, font_list, font_y_offset); } #endif OmniboxViewViews* omnibox = new OmniboxViewViews( - controller, toolbar_model, profile, command_updater, popup_window_mode, - location_bar, font_list, font_y_offset); + controller, profile, command_updater, popup_window_mode, location_bar, + font_list, font_y_offset); omnibox->Init(); return omnibox; } diff --git a/chrome/browser/ui/views/omnibox/omnibox_views.h b/chrome/browser/ui/views/omnibox/omnibox_views.h index 1cbc947..66c29f8 100644 --- a/chrome/browser/ui/views/omnibox/omnibox_views.h +++ b/chrome/browser/ui/views/omnibox/omnibox_views.h @@ -12,7 +12,6 @@ class OmniboxView; class OmniboxViewViews; class OmniboxViewWin; class Profile; -class ToolbarModel; namespace gfx { class FontList; @@ -30,7 +29,6 @@ OmniboxViewWin* GetOmniboxViewWin(OmniboxView* view); // Creates an OmniboxView of the appropriate type; Views or Win. OmniboxView* CreateOmniboxView(OmniboxEditController* controller, - ToolbarModel* toolbar_model, Profile* profile, CommandUpdater* command_updater, bool popup_window_mode, diff --git a/chrome/browser/ui/views/toolbar_view.cc b/chrome/browser/ui/views/toolbar_view.cc index e48a145..0eb501a 100644 --- a/chrome/browser/ui/views/toolbar_view.cc +++ b/chrome/browser/ui/views/toolbar_view.cc @@ -115,8 +115,7 @@ const int ToolbarView::kVertSpacing = 5; // ToolbarView, public: ToolbarView::ToolbarView(Browser* browser) - : model_(browser->toolbar_model()), - back_(NULL), + : back_(NULL), forward_(NULL), reload_(NULL), home_(NULL), @@ -187,7 +186,7 @@ void ToolbarView::Init() { // Have to create this before |reload_| as |reload_|'s constructor needs it. location_bar_ = new LocationBarView( browser_, browser_->profile(), - browser_->command_controller()->command_updater(), model_, this, + browser_->command_controller()->command_updater(), this, display_mode_ == DISPLAYMODE_LOCATION); reload_ = new ReloadButton(location_bar_, @@ -348,6 +347,14 @@ WebContents* ToolbarView::GetWebContents() const { return browser_->tab_strip_model()->GetActiveWebContents(); } +ToolbarModel* ToolbarView::GetToolbarModel() { + return browser_->toolbar_model(); +} + +const ToolbarModel* ToolbarView::GetToolbarModel() const { + return browser_->toolbar_model(); +} + InstantController* ToolbarView::GetInstant() { return browser_->instant_controller() ? browser_->instant_controller()->instant() : NULL; @@ -376,9 +383,9 @@ PageActionImageView* ToolbarView::CreatePageActionImageView( void ToolbarView::OnInputInProgress(bool in_progress) { // The edit should make sure we're only notified when something changes. - DCHECK_NE(model_->input_in_progress(), in_progress); + DCHECK_NE(GetToolbarModel()->input_in_progress(), in_progress); - model_->set_input_in_progress(in_progress); + GetToolbarModel()->set_input_in_progress(in_progress); location_bar_->Update(NULL); } diff --git a/chrome/browser/ui/views/toolbar_view.h b/chrome/browser/ui/views/toolbar_view.h index c871855..8ea25bc 100644 --- a/chrome/browser/ui/views/toolbar_view.h +++ b/chrome/browser/ui/views/toolbar_view.h @@ -94,6 +94,8 @@ class ToolbarView : public views::AccessiblePaneView, // Overridden from LocationBarView::Delegate: virtual content::WebContents* GetWebContents() const OVERRIDE; + virtual ToolbarModel* GetToolbarModel() OVERRIDE; + virtual const ToolbarModel* GetToolbarModel() const OVERRIDE; virtual InstantController* GetInstant() OVERRIDE; virtual views::Widget* CreateViewsBubble( views::BubbleDelegateView* bubble_delegate) OVERRIDE; @@ -195,9 +197,6 @@ class ToolbarView : public views::AccessiblePaneView, int content_shadow_height() const; - // The model that contains the security level, text, icon to display... - ToolbarModel* model_; - // Controls views::ImageButton* back_; views::ImageButton* forward_; |