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 "base/basictypes.h" | 8 #include "base/basictypes.h" |
9 #include "base/compiler_specific.h" | 9 #include "base/compiler_specific.h" |
10 #include "base/prefs/public/pref_change_registrar.h" | 10 #include "base/prefs/public/pref_change_registrar.h" |
11 #include "chrome/browser/instant/instant_controller.h" | 11 #include "chrome/browser/instant/instant_controller.h" |
12 #include "chrome/browser/instant/instant_unload_handler.h" | 12 #include "chrome/browser/instant/instant_unload_handler.h" |
| 13 #include "chrome/browser/ui/browser.h" |
13 #include "chrome/browser/ui/search/search_model_observer.h" | 14 #include "chrome/browser/ui/search/search_model_observer.h" |
14 #include "content/public/browser/notification_observer.h" | 15 #include "content/public/browser/notification_observer.h" |
15 #include "content/public/browser/notification_registrar.h" | 16 #include "content/public/browser/notification_registrar.h" |
16 #include "ui/base/window_open_disposition.h" | 17 #include "ui/base/window_open_disposition.h" |
17 | 18 |
18 class Browser; | 19 class Browser; |
19 struct InstantSuggestion; | 20 struct InstantSuggestion; |
20 class PrefServiceSyncable; | 21 class PrefServiceSyncable; |
21 class Profile; | 22 class Profile; |
22 class ThemeService; | 23 class ThemeService; |
(...skipping 13 matching lines...) Expand all Loading... |
36 public: | 37 public: |
37 explicit BrowserInstantController(Browser* browser); | 38 explicit BrowserInstantController(Browser* browser); |
38 virtual ~BrowserInstantController(); | 39 virtual ~BrowserInstantController(); |
39 | 40 |
40 // Returns true if Instant is enabled in a visible, preview-showing mode. | 41 // Returns true if Instant is enabled in a visible, preview-showing mode. |
41 static bool IsInstantEnabled(Profile* profile); | 42 static bool IsInstantEnabled(Profile* profile); |
42 | 43 |
43 // Registers Instant related preferences. | 44 // Registers Instant related preferences. |
44 static void RegisterUserPrefs(PrefServiceSyncable* prefs); | 45 static void RegisterUserPrefs(PrefServiceSyncable* prefs); |
45 | 46 |
| 47 // If |url| is the new tab page URL, set |target_contents| to the preloaded |
| 48 // NTP contents from InstantController. If |source_contents| is not NULL, we |
| 49 // replace it with the new |target_contents| in the tabstrip and delete |
| 50 // |source_contents|. Otherwise, the caller owns |target_contents| and is |
| 51 // responsible for inserting it into the tabstrip. |
| 52 // |
| 53 // Returns true if and only if we update |target_contents|. |
| 54 bool MaybeSwapInInstantContents( |
| 55 const GURL& url, |
| 56 content::WebContents* source_contents, |
| 57 content::WebContents** target_contents); |
| 58 |
46 // Commits the current Instant, returning true on success. This is intended | 59 // Commits the current Instant, returning true on success. This is intended |
47 // for use from OpenCurrentURL. | 60 // for use from OpenCurrentURL. |
48 bool OpenInstant(WindowOpenDisposition disposition); | 61 bool OpenInstant(WindowOpenDisposition disposition); |
49 | 62 |
| 63 // Returns the Profile associated with the Browser that owns this object. |
| 64 Profile* profile() const { return browser_->profile(); } |
| 65 |
50 // Returns the InstantController or NULL if there is no InstantController for | 66 // Returns the InstantController or NULL if there is no InstantController for |
51 // this BrowserInstantController. | 67 // this BrowserInstantController. |
52 InstantController* instant() { return &instant_; } | 68 InstantController* instant() { return &instant_; } |
53 | 69 |
54 // Invoked by |instant_| to commit the |preview| by merging it into the active | 70 // Invoked by |instant_| to commit the |preview| by merging it into the active |
55 // tab or adding it as a new tab. We take ownership of |preview|. | 71 // tab or adding it as a new tab. |
56 void CommitInstant(content::WebContents* preview, bool in_new_tab); | 72 void CommitInstant(scoped_ptr<content::WebContents> preview, bool in_new_tab); |
57 | 73 |
58 // Invoked by |instant_| to autocomplete the |suggestion| into the omnibox. | 74 // Invoked by |instant_| to autocomplete the |suggestion| into the omnibox. |
59 void SetInstantSuggestion(const InstantSuggestion& suggestion); | 75 void SetInstantSuggestion(const InstantSuggestion& suggestion); |
60 | 76 |
61 // Invoked by |instant_| to get the bounds that the preview is placed at, | 77 // Invoked by |instant_| to get the bounds that the preview is placed at, |
62 // in screen coordinated. | 78 // in screen coordinated. |
63 gfx::Rect GetInstantBounds(); | 79 gfx::Rect GetInstantBounds(); |
64 | 80 |
65 // Invoked by |instant_| to notify that the preview gained focus, usually due | 81 // Invoked by |instant_| to notify that the preview gained focus, usually due |
66 // to the user clicking on it. | 82 // to the user clicking on it. |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
106 virtual void Observe(int type, | 122 virtual void Observe(int type, |
107 const content::NotificationSource& source, | 123 const content::NotificationSource& source, |
108 const content::NotificationDetails& details) OVERRIDE; | 124 const content::NotificationDetails& details) OVERRIDE; |
109 | 125 |
110 // Helper for handling theme change. | 126 // Helper for handling theme change. |
111 void OnThemeChanged(ThemeService* theme_service); | 127 void OnThemeChanged(ThemeService* theme_service); |
112 | 128 |
113 // Helper for handling theme area height change. | 129 // Helper for handling theme area height change. |
114 void OnThemeAreaHeightChanged(int height); | 130 void OnThemeAreaHeightChanged(int height); |
115 | 131 |
| 132 // Replaces the contents at tab |index| with |new_contents| and deletes the |
| 133 // existing contents. |
| 134 void ReplaceWebContentsAt(int index, |
| 135 scoped_ptr<content::WebContents> new_contents); |
| 136 |
116 Browser* const browser_; | 137 Browser* const browser_; |
117 | 138 |
118 InstantController instant_; | 139 InstantController instant_; |
119 InstantUnloadHandler instant_unload_handler_; | 140 InstantUnloadHandler instant_unload_handler_; |
120 | 141 |
121 // Theme-related data for NTP preview to adopt themes. | 142 // Theme-related data for NTP preview to adopt themes. |
122 bool initialized_theme_info_; // True if theme_info_ has been initialized. | 143 bool initialized_theme_info_; // True if theme_info_ has been initialized. |
123 ThemeBackgroundInfo theme_info_; | 144 ThemeBackgroundInfo theme_info_; |
124 int theme_area_height_; | 145 int theme_area_height_; |
125 | 146 |
126 PrefChangeRegistrar profile_pref_registrar_; | 147 PrefChangeRegistrar profile_pref_registrar_; |
127 | 148 |
128 content::NotificationRegistrar registrar_; | 149 content::NotificationRegistrar registrar_; |
129 | 150 |
130 DISALLOW_COPY_AND_ASSIGN(BrowserInstantController); | 151 DISALLOW_COPY_AND_ASSIGN(BrowserInstantController); |
131 }; | 152 }; |
132 | 153 |
133 } // namespace chrome | 154 } // namespace chrome |
134 | 155 |
135 #endif // CHROME_BROWSER_UI_BROWSER_INSTANT_CONTROLLER_H_ | 156 #endif // CHROME_BROWSER_UI_BROWSER_INSTANT_CONTROLLER_H_ |
OLD | NEW |