OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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_INSTANT_INSTANT_LOADER_H_ | 5 #ifndef CHROME_BROWSER_INSTANT_INSTANT_LOADER_H_ |
6 #define CHROME_BROWSER_INSTANT_INSTANT_LOADER_H_ | 6 #define CHROME_BROWSER_INSTANT_INSTANT_LOADER_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
11 #include "base/compiler_specific.h" | 11 #include "base/compiler_specific.h" |
12 #include "base/memory/ref_counted.h" | 12 #include "base/memory/ref_counted.h" |
13 #include "base/memory/scoped_ptr.h" | 13 #include "base/memory/scoped_ptr.h" |
14 #include "base/string16.h" | 14 #include "base/string16.h" |
15 #include "chrome/browser/history/history_types.h" | 15 #include "chrome/browser/history/history_types.h" |
16 #include "chrome/browser/instant/instant_commit_type.h" | 16 #include "chrome/browser/instant/instant_commit_type.h" |
17 #include "content/public/browser/notification_observer.h" | 17 #include "content/public/browser/notification_observer.h" |
18 #include "content/public/browser/notification_registrar.h" | 18 #include "content/public/browser/notification_registrar.h" |
19 | 19 |
20 struct InstantAutocompleteResult; | 20 struct InstantAutocompleteResult; |
21 class InstantLoaderDelegate; | 21 class InstantController; |
22 class TabContents; | 22 class TabContents; |
23 | 23 |
24 namespace content { | 24 namespace content { |
25 class NotificationDetails; | 25 class NotificationDetails; |
26 class NotificationSource; | 26 class NotificationSource; |
27 class WebContents; | 27 class WebContents; |
28 } | 28 } |
29 | 29 |
30 namespace gfx { | 30 namespace gfx { |
31 class Rect; | 31 class Rect; |
32 } | 32 } |
33 | 33 |
34 // InstantLoader is created with an "Instant URL". It loads the URL and tells | 34 // InstantLoader is created with an "Instant URL". It loads the URL and tells |
35 // its delegate (usually InstantController) of all interesting events. For | 35 // the InstantController of all interesting events. For example, it determines |
36 // example, it determines if the page actually supports the Instant API | 36 // if the page supports the Instant API (http://dev.chromium.org/searchbox) and |
37 // (http://dev.chromium.org/searchbox) and forwards messages (such as queries | 37 // forwards messages (such as queries and autocomplete suggestions) between the |
38 // and autocomplete suggestions) between the page and the delegate. | 38 // page and the controller. |
39 class InstantLoader : public content::NotificationObserver { | 39 class InstantLoader : public content::NotificationObserver { |
40 public: | 40 public: |
41 // Returns the Instant loader for |web_contents| if it's used for Instant. | 41 // Returns the Instant loader for |web_contents| if it's used for Instant. |
42 static InstantLoader* FromWebContents(content::WebContents* web_contents); | 42 static InstantLoader* FromWebContents(content::WebContents* web_contents); |
43 | 43 |
44 // Creates a new empty WebContents. Use Init() to actually load |instant_url|. | 44 // Creates a new empty WebContents. Use Init() to actually load |instant_url|. |
45 // |tab_contents| is the page the preview will be shown on top of and | 45 // |tab_contents| is the page the preview will be shown on top of and |
46 // potentially replace. |instant_url| is typically the instant_url field of | 46 // potentially replace. |instant_url| is typically the instant_url field of |
47 // the default search engine's TemplateURL, with the "{searchTerms}" parameter | 47 // the default search engine's TemplateURL, with the "{searchTerms}" parameter |
48 // replaced with an empty string. | 48 // replaced with an empty string. |
49 InstantLoader(InstantLoaderDelegate* delegate, | 49 InstantLoader(InstantController* controller, |
50 const std::string& instant_url, | 50 const std::string& instant_url, |
51 const TabContents* tab_contents); | 51 const TabContents* tab_contents); |
52 virtual ~InstantLoader(); | 52 virtual ~InstantLoader(); |
53 | 53 |
54 // Initializes |preview_contents_| and loads |instant_url_|. | 54 // Initializes |preview_contents_| and loads |instant_url_|. |
55 void Init(); | 55 void Init(); |
56 | 56 |
57 // Tells the preview page that the user typed |user_text| into the omnibox. | 57 // Tells the preview page that the user typed |user_text| into the omnibox. |
58 // If |verbatim| is false, the page predicts the query the user means to type | 58 // If |verbatim| is false, the page predicts the query the user means to type |
59 // and fetches results for the prediction. If |verbatim| is true, |user_text| | 59 // and fetches results for the prediction. If |verbatim| is true, |user_text| |
(...skipping 22 matching lines...) Expand all Loading... |
82 // Tells the preview page that the active tab's "NTP status" has changed. | 82 // Tells the preview page that the active tab's "NTP status" has changed. |
83 void OnActiveTabModeChanged(bool active_tab_is_ntp); | 83 void OnActiveTabModeChanged(bool active_tab_is_ntp); |
84 | 84 |
85 // Called by the history tab helper with the information that it would have | 85 // Called by the history tab helper with the information that it would have |
86 // added to the history service had this web contents not been used for | 86 // added to the history service had this web contents not been used for |
87 // Instant. | 87 // Instant. |
88 void DidNavigate(const history::HistoryAddPageArgs& add_page_args); | 88 void DidNavigate(const history::HistoryAddPageArgs& add_page_args); |
89 | 89 |
90 // Releases the preview TabContents passing ownership to the caller. This | 90 // Releases the preview TabContents passing ownership to the caller. This |
91 // should be called when the preview is committed. Notifies the page but not | 91 // should be called when the preview is committed. Notifies the page but not |
92 // the delegate. |text| is the final omnibox text being committed. NOTE: The | 92 // the controller. |text| is the final omnibox text being committed. NOTE: The |
93 // caller should destroy this loader object right after this method, since | 93 // caller should destroy this loader object right after this method, since |
94 // none of the other methods will work once the preview has been released. | 94 // none of the other methods will work once the preview has been released. |
95 TabContents* ReleasePreviewContents(InstantCommitType type, | 95 TabContents* ReleasePreviewContents(InstantCommitType type, |
96 const string16& text) WARN_UNUSED_RESULT; | 96 const string16& text) WARN_UNUSED_RESULT; |
97 | 97 |
98 // The preview TabContents. The loader retains ownership. This will be | 98 // The preview TabContents. The loader retains ownership. This will be |
99 // non-NULL until ReleasePreviewContents() is called. | 99 // non-NULL until ReleasePreviewContents() is called. |
100 TabContents* preview_contents() const { return preview_contents_.get(); } | 100 TabContents* preview_contents() const { return preview_contents_.get(); } |
101 | 101 |
102 // Returns true if the preview page is known to support the Instant API. This | 102 // Returns true if the preview page is known to support the Instant API. This |
(...skipping 21 matching lines...) Expand all Loading... |
124 const content::NotificationDetails& details) OVERRIDE; | 124 const content::NotificationDetails& details) OVERRIDE; |
125 | 125 |
126 private: | 126 private: |
127 class WebContentsDelegateImpl; | 127 class WebContentsDelegateImpl; |
128 | 128 |
129 void SetupPreviewContents(); | 129 void SetupPreviewContents(); |
130 void CleanupPreviewContents(); | 130 void CleanupPreviewContents(); |
131 void ReplacePreviewContents(content::WebContents* old_contents, | 131 void ReplacePreviewContents(content::WebContents* old_contents, |
132 content::WebContents* new_contents); | 132 content::WebContents* new_contents); |
133 | 133 |
134 InstantLoaderDelegate* const loader_delegate_; | 134 InstantController* const controller_; |
135 | 135 |
136 // See comments on the getter above. | 136 // See comments on the getter above. |
137 scoped_ptr<TabContents> preview_contents_; | 137 scoped_ptr<TabContents> preview_contents_; |
138 | 138 |
139 // Delegate of the preview WebContents. Used to detect when the user does some | 139 // Delegate of the preview WebContents. Used to detect when the user does some |
140 // gesture on the WebContents and the preview needs to be activated. | 140 // gesture on the WebContents and the preview needs to be activated. |
141 scoped_ptr<WebContentsDelegateImpl> preview_delegate_; | 141 scoped_ptr<WebContentsDelegateImpl> preview_delegate_; |
142 | 142 |
143 // See comments on the getter above. | 143 // See comments on the getter above. |
144 bool supports_instant_; | 144 bool supports_instant_; |
145 | 145 |
146 // See comments on the getter above. | 146 // See comments on the getter above. |
147 const std::string instant_url_; | 147 const std::string instant_url_; |
148 | 148 |
149 // Used to get notifications about renderers coming and going. | 149 // Used to get notifications about renderers coming and going. |
150 content::NotificationRegistrar registrar_; | 150 content::NotificationRegistrar registrar_; |
151 | 151 |
152 // See comments on the getter above. | 152 // See comments on the getter above. |
153 history::HistoryAddPageArgs last_navigation_; | 153 history::HistoryAddPageArgs last_navigation_; |
154 | 154 |
155 DISALLOW_IMPLICIT_CONSTRUCTORS(InstantLoader); | 155 DISALLOW_COPY_AND_ASSIGN(InstantLoader); |
156 }; | 156 }; |
157 | 157 |
158 #endif // CHROME_BROWSER_INSTANT_INSTANT_LOADER_H_ | 158 #endif // CHROME_BROWSER_INSTANT_INSTANT_LOADER_H_ |
OLD | NEW |