Add a minor text member to ui::MenuModel.
[chromium-blink-merge.git] / chrome / browser / ui / browser_instant_controller.h
blob66598ef3b9f4aa1d99893fb550ce5747edfd5dc7
1 // Copyright 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef CHROME_BROWSER_UI_BROWSER_INSTANT_CONTROLLER_H_
6 #define CHROME_BROWSER_UI_BROWSER_INSTANT_CONTROLLER_H_
8 #include <string>
10 #include "base/basictypes.h"
11 #include "base/compiler_specific.h"
12 #include "base/prefs/pref_change_registrar.h"
13 #include "chrome/browser/ui/search/instant_controller.h"
14 #include "chrome/browser/ui/search/instant_unload_handler.h"
15 #include "chrome/browser/ui/search/search_model_observer.h"
16 #include "ui/base/window_open_disposition.h"
18 class Browser;
19 struct InstantSuggestion;
20 class Profile;
22 namespace content {
23 class WebContents;
26 namespace gfx {
27 class Rect;
30 class BrowserInstantController : public SearchModelObserver {
31 public:
32 explicit BrowserInstantController(Browser* browser);
33 virtual ~BrowserInstantController();
35 // If |url| is the new tab page URL, set |target_contents| to the preloaded
36 // NTP contents from InstantController. If |source_contents| is not NULL, we
37 // replace it with the new |target_contents| in the tabstrip and delete
38 // |source_contents|. Otherwise, the caller owns |target_contents| and is
39 // responsible for inserting it into the tabstrip.
41 // Returns true if and only if we update |target_contents|.
42 bool MaybeSwapInInstantNTPContents(
43 const GURL& url,
44 content::WebContents* source_contents,
45 content::WebContents** target_contents);
47 // Commits the current Instant, returning true on success. This is intended
48 // for use from OpenCurrentURL.
49 bool OpenInstant(WindowOpenDisposition disposition, const GURL& url);
51 // Returns the Profile associated with the Browser that owns this object.
52 Profile* profile() const;
54 // Returns the InstantController or NULL if there is no InstantController for
55 // this BrowserInstantController.
56 InstantController* instant() { return &instant_; }
58 // Invoked by |instant_| to change the omnibox focus.
59 void FocusOmnibox(OmniboxFocusState state);
61 // Invoked by |instant_| to get the currently active tab.
62 content::WebContents* GetActiveWebContents() const;
64 // Invoked by |browser_| when the active tab changes.
65 void ActiveTabChanged();
67 // Invoked by |browser_| when the active tab is about to be deactivated.
68 void TabDeactivated(content::WebContents* contents);
70 // Invoked by the InstantController when it wants to open a URL.
71 void OpenURL(const GURL& url,
72 content::PageTransition transition,
73 WindowOpenDisposition disposition);
75 // Invoked by |instant_| to paste the |text| (or clipboard content if text is
76 // empty) into the omnibox. It will set focus to the omnibox if the omnibox is
77 // not focused.
78 void PasteIntoOmnibox(const string16& text);
80 // Sets the stored omnibox bounds.
81 void SetOmniboxBounds(const gfx::Rect& bounds);
83 // Sets the current query to prefetch if any.
84 void SetSuggestionToPrefetch(const InstantSuggestion& suggestion);
86 // Notifies |instant_| to toggle voice search.
87 void ToggleVoiceSearch();
89 private:
90 // Overridden from search::SearchModelObserver:
91 virtual void ModelChanged(const SearchModel::State& old_state,
92 const SearchModel::State& new_state) OVERRIDE;
94 // Called when the default search provider changes. Revokes the searchbox API
95 // privileges for any existing WebContents (that belong to the erstwhile
96 // default search provider) by simply reloading all such WebContents. This
97 // ensures that they are reloaded in a non-privileged renderer process.
98 void OnDefaultSearchProviderChanged(const std::string& pref_name);
100 // Replaces the contents at tab |index| with |new_contents| and deletes the
101 // existing contents.
102 void ReplaceWebContentsAt(int index,
103 scoped_ptr<content::WebContents> new_contents);
105 Browser* const browser_;
107 InstantController instant_;
108 InstantUnloadHandler instant_unload_handler_;
110 PrefChangeRegistrar profile_pref_registrar_;
112 DISALLOW_COPY_AND_ASSIGN(BrowserInstantController);
115 #endif // CHROME_BROWSER_UI_BROWSER_INSTANT_CONTROLLER_H_