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

Side by Side Diff: chrome/browser/ui/browser_instant_controller.h

Issue 12386019: Instant: Use only one hidden WebContents per profile. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 9 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright 2012 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef CHROME_BROWSER_UI_BROWSER_INSTANT_CONTROLLER_H_ 5 #ifndef CHROME_BROWSER_UI_BROWSER_INSTANT_CONTROLLER_H_
6 #define CHROME_BROWSER_UI_BROWSER_INSTANT_CONTROLLER_H_ 6 #define CHROME_BROWSER_UI_BROWSER_INSTANT_CONTROLLER_H_
7 7
8 #include "base/basictypes.h" 8 #include "base/basictypes.h"
9 #include "base/compiler_specific.h" 9 #include "base/memory/scoped_ptr.h"
10 #include "base/prefs/public/pref_change_registrar.h"
11 #include "chrome/browser/instant/instant_controller.h"
12 #include "chrome/browser/instant/instant_unload_handler.h" 10 #include "chrome/browser/instant/instant_unload_handler.h"
13 #include "chrome/browser/ui/search/search_model_observer.h" 11 #include "content/public/common/page_transition_types.h"
14 #include "content/public/browser/notification_observer.h"
15 #include "content/public/browser/notification_registrar.h"
16 #include "ui/base/window_open_disposition.h" 12 #include "ui/base/window_open_disposition.h"
17 13
18 class Browser; 14 class Browser;
15 class GURL;
16 class InstantController;
19 struct InstantSuggestion; 17 struct InstantSuggestion;
20 class PrefRegistrySyncable;
21 class PrefService;
22 class Profile;
23 class ThemeService;
24 18
25 namespace content { 19 namespace content {
26 class WebContents; 20 class WebContents;
27 } 21 }
28 22
29 namespace gfx { 23 namespace gfx {
30 class Rect; 24 class Rect;
31 } 25 }
32 26
33 namespace chrome { 27 namespace chrome {
34 28
35 class BrowserInstantController : public content::NotificationObserver, 29 // BrowserInstantController is a bridge between Browser and InstantController.
36 public search::SearchModelObserver { 30 // It is owned by Browser, and in turn, owns InstantController.
31 class BrowserInstantController {
37 public: 32 public:
38 explicit BrowserInstantController(Browser* browser); 33 explicit BrowserInstantController(Browser* browser);
39 virtual ~BrowserInstantController(); 34 virtual ~BrowserInstantController();
40 35
41 // Returns true if Instant is enabled in a visible, preview-showing mode. 36 InstantController* instant() const { return instant_.get(); }
42 static bool IsInstantEnabled(Profile* profile);
43 37
44 // Registers Instant related preferences. 38 // --------------------------------------------------------------------------
45 static void RegisterUserPrefs(PrefService* prefs, 39 // Methods invoked by |browser_|
46 PrefRegistrySyncable* registry);
47 40
48 // If |url| is the new tab page URL, set |target_contents| to the preloaded 41 // If |url| is the new tab page URL, sets |target_contents| to the preloaded
49 // NTP contents from InstantController. If |source_contents| is not NULL, we 42 // NTP contents from InstantController. If |source_contents| is not NULL, we
50 // replace it with the new |target_contents| in the tabstrip and delete 43 // replace it with the new |target_contents| in the tabstrip and delete
51 // |source_contents|. Otherwise, the caller owns |target_contents| and is 44 // |source_contents|. Otherwise, the caller owns |target_contents| and is
52 // responsible for inserting it into the tabstrip. 45 // responsible for inserting it into the tabstrip.
53 // 46 //
54 // Returns true if and only if we update |target_contents|. 47 // Returns true if and only if we update |target_contents|.
55 bool MaybeSwapInInstantNTPContents( 48 bool MaybeSwapInInstantNTPContents(const GURL& url,
56 const GURL& url, 49 content::WebContents* source_contents,
57 content::WebContents* source_contents, 50 content::WebContents** target_contents);
58 content::WebContents** target_contents);
59 51
60 // Commits the current Instant, returning true on success. This is intended 52 // Commits the current Instant overlay, returning true on success. This is
61 // for use from OpenCurrentURL. 53 // intended to be invoked by |browser_| from OpenCurrentURL.
62 bool OpenInstant(WindowOpenDisposition disposition); 54 bool OpenInstant(WindowOpenDisposition disposition);
63 55
64 // Returns the Profile associated with the Browser that owns this object. 56 // --------------------------------------------------------------------------
65 Profile* profile() const; 57 // Methods invoked by |instant_|
66 58
67 // Returns the InstantController or NULL if there is no InstantController for 59 // Commits the |overlay| by merging it into the active tab or a new tab.
68 // this BrowserInstantController. 60 void CommitInstant(scoped_ptr<content::WebContents> overlay,
69 InstantController* instant() { return &instant_; } 61 content::PageTransition transition,
62 bool in_new_tab);
70 63
71 // Invoked by |instant_| to commit the |preview| by merging it into the active 64 // Autocompletes the |suggestion| into the omnibox.
72 // tab or adding it as a new tab.
73 void CommitInstant(scoped_ptr<content::WebContents> preview, bool in_new_tab);
74
75 // Invoked by |instant_| to autocomplete the |suggestion| into the omnibox.
76 void SetInstantSuggestion(const InstantSuggestion& suggestion); 65 void SetInstantSuggestion(const InstantSuggestion& suggestion);
77 66
78 // Invoked by |instant_| to commit the omnibox's suggested text. 67 // Commits the omnibox's suggested text (gray text).
79 // Call-through to OmniboxEditModel::CommitSuggestedText.
80 void CommitSuggestedText(bool skip_inline_autocomplete); 68 void CommitSuggestedText(bool skip_inline_autocomplete);
81 69
82 // Invoked by |instant_| to get the bounds that the preview is placed at, 70 // Returns the bounds that the overlay is placed at, in screen coordinates.
83 // in screen coordinates. 71 gfx::Rect GetInstantBounds() const;
84 gfx::Rect GetInstantBounds();
85 72
86 // Invoked by |instant_| to notify that the preview gained focus, usually due 73 // Notifies |browser_| that the overlay gained focus, usually due to the user
87 // to the user clicking on it. 74 // clicking on it.
88 void InstantPreviewFocused(); 75 void InstantOverlayFocused();
89 76
90 // Invoked by |instant_| to give the omnibox focus invisibly. 77 // Focuses the omnibox invisibly.
91 void FocusOmniboxInvisibly(); 78 void FocusOmniboxInvisibly();
92 79
93 // Invoked by |instant_| to get the currently active tab, over which the 80 // Returns the currently active tab, over which the overlay would be shown.
94 // preview would be shown.
95 content::WebContents* GetActiveWebContents() const; 81 content::WebContents* GetActiveWebContents() const;
96 82
97 // Invoked by |browser_| when the active tab changes. 83 // Requests |browser_| to perform a browser-initiated navigation.
98 void ActiveTabChanged();
99
100 // Invoked by |browser_| when the active tab is about to be deactivated.
101 void TabDeactivated(content::WebContents* contents);
102
103 // Invoked by |instant_| or |browser_| to update theme information for NTP.
104 // Set |parse_theme_info| to true to force re-parsing of theme information.
105 void UpdateThemeInfo(bool parse_theme_info);
106
107 // Invoked by the InstantController when it wants to open a URL.
108 void OpenURL(const GURL& url, 84 void OpenURL(const GURL& url,
109 content::PageTransition transition, 85 content::PageTransition transition,
110 WindowOpenDisposition disposition); 86 WindowOpenDisposition disposition);
111 87
112 // Sets the stored omnibox bounds.
113 void SetOmniboxBounds(const gfx::Rect& bounds);
114
115 private: 88 private:
116 // Sets the value of |instant_| based on value from profile. Invoked
117 // on pref change.
118 void ResetInstant();
119
120 // Overridden from search::SearchModelObserver:
121 virtual void ModeChanged(const search::Mode& old_mode,
122 const search::Mode& new_mode) OVERRIDE;
123
124 // content::NotificationObserver implementation.
125 virtual void Observe(int type,
126 const content::NotificationSource& source,
127 const content::NotificationDetails& details) OVERRIDE;
128
129 // Helper for handling theme change.
130 void OnThemeChanged(ThemeService* theme_service);
131
132 // Replaces the contents at tab |index| with |new_contents| and deletes the 89 // Replaces the contents at tab |index| with |new_contents| and deletes the
133 // existing contents. 90 // existing contents.
134 void ReplaceWebContentsAt(int index, 91 void ReplaceWebContentsAt(int index,
135 scoped_ptr<content::WebContents> new_contents); 92 scoped_ptr<content::WebContents> new_contents);
136 93
137 Browser* const browser_; 94 Browser* const browser_;
138 95 scoped_ptr<InstantController> instant_;
139 InstantController instant_;
140 InstantUnloadHandler instant_unload_handler_; 96 InstantUnloadHandler instant_unload_handler_;
141 97
142 // Theme-related data for NTP preview to adopt themes.
143 bool initialized_theme_info_; // True if theme_info_ has been initialized.
144 ThemeBackgroundInfo theme_info_;
145
146 PrefChangeRegistrar profile_pref_registrar_;
147
148 content::NotificationRegistrar registrar_;
149
150 DISALLOW_COPY_AND_ASSIGN(BrowserInstantController); 98 DISALLOW_COPY_AND_ASSIGN(BrowserInstantController);
151 }; 99 };
152 100
153 } // namespace chrome 101 } // namespace chrome
154 102
155 #endif // CHROME_BROWSER_UI_BROWSER_INSTANT_CONTROLLER_H_ 103 #endif // CHROME_BROWSER_UI_BROWSER_INSTANT_CONTROLLER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698