OLD | NEW |
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 <string> | |
9 | |
10 #include "base/basictypes.h" | 8 #include "base/basictypes.h" |
11 #include "base/compiler_specific.h" | 9 #include "base/memory/scoped_ptr.h" |
12 #include "base/prefs/public/pref_change_registrar.h" | |
13 #include "chrome/browser/instant/instant_controller.h" | |
14 #include "chrome/browser/instant/instant_unload_handler.h" | 10 #include "chrome/browser/instant/instant_unload_handler.h" |
15 #include "chrome/browser/ui/search/search_model_observer.h" | 11 #include "content/public/common/page_transition_types.h" |
16 #include "content/public/browser/notification_observer.h" | |
17 #include "content/public/browser/notification_registrar.h" | |
18 #include "ui/base/window_open_disposition.h" | 12 #include "ui/base/window_open_disposition.h" |
19 | 13 |
20 class Browser; | 14 class Browser; |
| 15 class GURL; |
| 16 class InstantController; |
21 struct InstantSuggestion; | 17 struct InstantSuggestion; |
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 // If |url| is the new tab page URL, set |target_contents| to the preloaded | 36 InstantController* instant() const { return instant_.get(); } |
| 37 |
| 38 // -------------------------------------------------------------------------- |
| 39 // Methods invoked by |browser_| |
| 40 |
| 41 // If |url| is the new tab page URL, sets |target_contents| to the preloaded |
42 // NTP contents from InstantController. If |source_contents| is not NULL, we | 42 // NTP contents from InstantController. If |source_contents| is not NULL, we |
43 // 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 |
44 // |source_contents|. Otherwise, the caller owns |target_contents| and is | 44 // |source_contents|. Otherwise, the caller owns |target_contents| and is |
45 // responsible for inserting it into the tabstrip. | 45 // responsible for inserting it into the tabstrip. |
46 // | 46 // |
47 // Returns true if and only if we update |target_contents|. | 47 // Returns true if and only if we update |target_contents|. |
48 bool MaybeSwapInInstantNTPContents( | 48 bool MaybeSwapInInstantNTPContents(const GURL& url, |
49 const GURL& url, | 49 content::WebContents* source_contents, |
50 content::WebContents* source_contents, | 50 content::WebContents** target_contents); |
51 content::WebContents** target_contents); | |
52 | 51 |
53 // Commits the current Instant, returning true on success. This is intended | 52 // Commits the current Instant overlay, returning true on success. This is |
54 // for use from OpenCurrentURL. | 53 // intended to be invoked by |browser_| from OpenCurrentURL. |
55 bool OpenInstant(WindowOpenDisposition disposition); | 54 bool OpenInstant(WindowOpenDisposition disposition); |
56 | 55 |
57 // Returns the Profile associated with the Browser that owns this object. | 56 // -------------------------------------------------------------------------- |
58 Profile* profile() const; | 57 // Methods invoked by |instant_| |
59 | 58 |
60 // 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. |
61 // this BrowserInstantController. | 60 void CommitInstant(scoped_ptr<content::WebContents> overlay, |
62 InstantController* instant() { return &instant_; } | 61 content::PageTransition transition, |
| 62 bool in_new_tab); |
63 | 63 |
64 // Invoked by |instant_| to commit the |overlay| by merging it into the active | 64 // Autocompletes the |suggestion| into the omnibox. |
65 // tab or adding it as a new tab. | |
66 void CommitInstant(scoped_ptr<content::WebContents> overlay, bool in_new_tab); | |
67 | |
68 // Invoked by |instant_| to autocomplete the |suggestion| into the omnibox. | |
69 void SetInstantSuggestion(const InstantSuggestion& suggestion); | 65 void SetInstantSuggestion(const InstantSuggestion& suggestion); |
70 | 66 |
71 // Invoked by |instant_| to commit the omnibox's suggested text. | 67 // Commits the omnibox's suggested text (gray text). |
72 // Call-through to OmniboxEditModel::CommitSuggestedText. | |
73 void CommitSuggestedText(bool skip_inline_autocomplete); | 68 void CommitSuggestedText(bool skip_inline_autocomplete); |
74 | 69 |
75 // Invoked by |instant_| to get the bounds that the overlay is placed at, | 70 // Returns the bounds that the overlay is placed at, in screen coordinates. |
76 // in screen coordinates. | 71 gfx::Rect GetInstantBounds() const; |
77 gfx::Rect GetInstantBounds(); | |
78 | 72 |
79 // Invoked by |instant_| to notify that the overlay gained focus, usually due | 73 // Notifies |browser_| that the overlay gained focus, usually due to the user |
80 // to the user clicking on it. | 74 // clicking on it. |
81 void InstantOverlayFocused(); | 75 void InstantOverlayFocused(); |
82 | 76 |
83 // Invoked by |instant_| to give the omnibox focus, with the option of making | 77 // Requests that the omnibox be focused, optionally hiding the caret. |
84 // the caret invisible. | |
85 void FocusOmnibox(bool caret_visibility); | 78 void FocusOmnibox(bool caret_visibility); |
86 | 79 |
87 // 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. |
88 // overlay would be shown. | |
89 content::WebContents* GetActiveWebContents() const; | 81 content::WebContents* GetActiveWebContents() const; |
90 | 82 |
91 // Invoked by |browser_| when the active tab changes. | 83 // Requests |browser_| to perform a browser-initiated navigation. |
92 void ActiveTabChanged(); | |
93 | |
94 // Invoked by |browser_| when the active tab is about to be deactivated. | |
95 void TabDeactivated(content::WebContents* contents); | |
96 | |
97 // Invoked by |instant_| to update theme information for NTP. | |
98 void UpdateThemeInfo(); | |
99 | |
100 // Invoked by the InstantController when it wants to open a URL. | |
101 void OpenURL(const GURL& url, | 84 void OpenURL(const GURL& url, |
102 content::PageTransition transition, | 85 content::PageTransition transition, |
103 WindowOpenDisposition disposition); | 86 WindowOpenDisposition disposition); |
104 | 87 |
105 // Sets the stored omnibox bounds. | |
106 void SetOmniboxBounds(const gfx::Rect& bounds); | |
107 | |
108 private: | 88 private: |
109 // Sets the value of |instant_| based on value from profile. Invoked | |
110 // on pref change. | |
111 void ResetInstant(const std::string& pref_name); | |
112 | |
113 // Overridden from search::SearchModelObserver: | |
114 virtual void ModeChanged(const search::Mode& old_mode, | |
115 const search::Mode& new_mode) OVERRIDE; | |
116 | |
117 // content::NotificationObserver implementation. | |
118 virtual void Observe(int type, | |
119 const content::NotificationSource& source, | |
120 const content::NotificationDetails& details) OVERRIDE; | |
121 | |
122 // Helper for handling theme change. | |
123 void OnThemeChanged(ThemeService* theme_service); | |
124 | |
125 // 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 |
126 // existing contents. | 90 // existing contents. |
127 void ReplaceWebContentsAt(int index, | 91 void ReplaceWebContentsAt(int index, |
128 scoped_ptr<content::WebContents> new_contents); | 92 scoped_ptr<content::WebContents> new_contents); |
129 | 93 |
130 Browser* const browser_; | 94 Browser* const browser_; |
131 | 95 scoped_ptr<InstantController> instant_; |
132 InstantController instant_; | |
133 InstantUnloadHandler instant_unload_handler_; | 96 InstantUnloadHandler instant_unload_handler_; |
134 | 97 |
135 // Theme-related data for NTP overlay to adopt themes. | |
136 bool initialized_theme_info_; // True if theme_info_ has been initialized. | |
137 ThemeBackgroundInfo theme_info_; | |
138 | |
139 PrefChangeRegistrar profile_pref_registrar_; | |
140 | |
141 content::NotificationRegistrar registrar_; | |
142 | |
143 DISALLOW_COPY_AND_ASSIGN(BrowserInstantController); | 98 DISALLOW_COPY_AND_ASSIGN(BrowserInstantController); |
144 }; | 99 }; |
145 | 100 |
146 } // namespace chrome | 101 } // namespace chrome |
147 | 102 |
148 #endif // CHROME_BROWSER_UI_BROWSER_INSTANT_CONTROLLER_H_ | 103 #endif // CHROME_BROWSER_UI_BROWSER_INSTANT_CONTROLLER_H_ |
OLD | NEW |