OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 #pragma once | 7 #pragma once |
8 | 8 |
9 #include "base/basictypes.h" | 9 #include "base/basictypes.h" |
10 #include "base/scoped_ptr.h" | 10 #include "base/scoped_ptr.h" |
11 #include "base/string16.h" | 11 #include "base/string16.h" |
12 #include "base/timer.h" | 12 #include "base/timer.h" |
13 #include "chrome/browser/instant/instant_commit_type.h" | 13 #include "chrome/browser/instant/instant_commit_type.h" |
14 #include "chrome/browser/search_engines/template_url_id.h" | 14 #include "chrome/browser/search_engines/template_url_id.h" |
15 #include "chrome/common/notification_observer.h" | 15 #include "chrome/common/notification_observer.h" |
16 #include "chrome/common/notification_registrar.h" | 16 #include "chrome/common/notification_registrar.h" |
17 #include "chrome/common/page_transition_types.h" | 17 #include "chrome/common/page_transition_types.h" |
18 #include "gfx/rect.h" | 18 #include "gfx/rect.h" |
19 #include "googleurl/src/gurl.h" | 19 #include "googleurl/src/gurl.h" |
20 | 20 |
21 class InstantLoaderDelegate; | 21 class InstantLoaderDelegate; |
22 class InstantLoaderManagerTest; | 22 class InstantLoaderManagerTest; |
23 class TabContents; | 23 class TabContents; |
| 24 class TabContentsWrapper; |
24 class TemplateURL; | 25 class TemplateURL; |
25 | 26 |
26 // InstantLoader does the loading of a particular URL for InstantController. | 27 // InstantLoader does the loading of a particular URL for InstantController. |
27 // InstantLoader notifies its delegate, which is typically InstantController, of | 28 // InstantLoader notifies its delegate, which is typically InstantController, of |
28 // all interesting events. | 29 // all interesting events. |
29 // | 30 // |
30 // InstantLoader is created with a TemplateURLID. If non-zero InstantLoader | 31 // InstantLoader is created with a TemplateURLID. If non-zero InstantLoader |
31 // first determines if the site actually supports instant. If it doesn't, the | 32 // first determines if the site actually supports instant. If it doesn't, the |
32 // delegate is notified by way of |InstantLoaderDoesntSupportInstant|. | 33 // delegate is notified by way of |InstantLoaderDoesntSupportInstant|. |
33 // | 34 // |
34 // If the TemplateURLID supplied to the constructor is zero, then the url is | 35 // If the TemplateURLID supplied to the constructor is zero, then the url is |
35 // loaded as is. | 36 // loaded as is. |
36 class InstantLoader : public NotificationObserver { | 37 class InstantLoader : public NotificationObserver { |
37 public: | 38 public: |
38 InstantLoader(InstantLoaderDelegate* delegate, TemplateURLID id); | 39 InstantLoader(InstantLoaderDelegate* delegate, TemplateURLID id); |
39 virtual ~InstantLoader(); | 40 virtual ~InstantLoader(); |
40 | 41 |
41 // Invoked to load a URL. |tab_contents| is the TabContents the preview is | 42 // Invoked to load a URL. |tab_contents| is the TabContents the preview is |
42 // going to be shown on top of and potentially replace. | 43 // going to be shown on top of and potentially replace. |
43 void Update(TabContents* tab_contents, | 44 void Update(TabContentsWrapper* tab_contents, |
44 const TemplateURL* template_url, | 45 const TemplateURL* template_url, |
45 const GURL& url, | 46 const GURL& url, |
46 PageTransition::Type transition_type, | 47 PageTransition::Type transition_type, |
47 const string16& user_text, | 48 const string16& user_text, |
48 string16* suggested_text); | 49 string16* suggested_text); |
49 | 50 |
50 // Sets the bounds of the omnibox (in screen coordinates). The bounds are | 51 // Sets the bounds of the omnibox (in screen coordinates). The bounds are |
51 // remembered until the preview is committed or destroyed. This is only used | 52 // remembered until the preview is committed or destroyed. This is only used |
52 // when showing results for a search provider that supports instant. | 53 // when showing results for a search provider that supports instant. |
53 void SetOmniboxBounds(const gfx::Rect& bounds); | 54 void SetOmniboxBounds(const gfx::Rect& bounds); |
54 | 55 |
55 // Returns true if the mouse is down as the result of activating the preview | 56 // Returns true if the mouse is down as the result of activating the preview |
56 // content. | 57 // content. |
57 bool IsMouseDownFromActivate(); | 58 bool IsMouseDownFromActivate(); |
58 | 59 |
59 // Releases the preview TabContents passing ownership to the caller. This is | 60 // Releases the preview TabContents passing ownership to the caller. This is |
60 // intended to be called when the preview TabContents is committed. This does | 61 // intended to be called when the preview TabContents is committed. This does |
61 // not notify the delegate. | 62 // not notify the delegate. |
62 TabContents* ReleasePreviewContents(InstantCommitType type); | 63 TabContentsWrapper* ReleasePreviewContents(InstantCommitType type); |
63 | 64 |
64 // Calls through to method of same name on delegate. | 65 // Calls through to method of same name on delegate. |
65 bool ShouldCommitInstantOnMouseUp(); | 66 bool ShouldCommitInstantOnMouseUp(); |
66 void CommitInstantLoader(); | 67 void CommitInstantLoader(); |
67 | 68 |
68 // Resets the template_url_id_ to zero and shows this loader. This is only | 69 // Resets the template_url_id_ to zero and shows this loader. This is only |
69 // intended to be invoked from InstantLoaderDoesntSupportInstant. | 70 // intended to be invoked from InstantLoaderDoesntSupportInstant. |
70 void ClearTemplateURLID(); | 71 void ClearTemplateURLID(); |
71 | 72 |
72 virtual void Observe(NotificationType type, | 73 virtual void Observe(NotificationType type, |
73 const NotificationSource& source, | 74 const NotificationSource& source, |
74 const NotificationDetails& details); | 75 const NotificationDetails& details); |
75 | 76 |
76 // The preview TabContents; may be null. | 77 // The preview TabContents; may be null. |
77 TabContents* preview_contents() const { return preview_contents_.get(); } | 78 TabContentsWrapper* preview_contents() const { |
| 79 return preview_contents_.get(); |
| 80 } |
78 | 81 |
79 // Returns true if the preview TabContents is ready to be shown. | 82 // Returns true if the preview TabContents is ready to be shown. |
80 bool ready() const { return ready_; } | 83 bool ready() const { return ready_; } |
81 | 84 |
82 const GURL& url() const { return url_; } | 85 const GURL& url() const { return url_; } |
83 | 86 |
84 // Are we showing instant results? | 87 // Are we showing instant results? |
85 bool is_showing_instant() const { return template_url_id_ != 0; } | 88 bool is_showing_instant() const { return template_url_id_ != 0; } |
86 | 89 |
87 // If we're showing instant this returns non-zero. | 90 // If we're showing instant this returns non-zero. |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
138 GURL url_; | 141 GURL url_; |
139 | 142 |
140 // The URL first used to load instant results. | 143 // The URL first used to load instant results. |
141 GURL initial_instant_url_; | 144 GURL initial_instant_url_; |
142 | 145 |
143 // Delegate of the preview TabContents. Used to detect when the user does some | 146 // Delegate of the preview TabContents. Used to detect when the user does some |
144 // gesture on the TabContents and the preview needs to be activated. | 147 // gesture on the TabContents and the preview needs to be activated. |
145 scoped_ptr<TabContentsDelegateImpl> preview_tab_contents_delegate_; | 148 scoped_ptr<TabContentsDelegateImpl> preview_tab_contents_delegate_; |
146 | 149 |
147 // The preview TabContents; may be null. | 150 // The preview TabContents; may be null. |
148 scoped_ptr<TabContents> preview_contents_; | 151 scoped_ptr<TabContentsWrapper> preview_contents_; |
149 | 152 |
150 // Is the preview_contents ready to be shown? | 153 // Is the preview_contents ready to be shown? |
151 bool ready_; | 154 bool ready_; |
152 | 155 |
153 // The text the user typed in the omnibox. | 156 // The text the user typed in the omnibox. |
154 string16 user_text_; | 157 string16 user_text_; |
155 | 158 |
156 // The latest suggestion from the page. | 159 // The latest suggestion from the page. |
157 string16 complete_suggested_text_; | 160 string16 complete_suggested_text_; |
158 | 161 |
(...skipping 11 matching lines...) Expand all Loading... |
170 // Timer used to update the bounds of the omnibox. | 173 // Timer used to update the bounds of the omnibox. |
171 base::OneShotTimer<InstantLoader> update_bounds_timer_; | 174 base::OneShotTimer<InstantLoader> update_bounds_timer_; |
172 | 175 |
173 // Used to get notifications about renderers coming and going. | 176 // Used to get notifications about renderers coming and going. |
174 NotificationRegistrar registrar_; | 177 NotificationRegistrar registrar_; |
175 | 178 |
176 DISALLOW_COPY_AND_ASSIGN(InstantLoader); | 179 DISALLOW_COPY_AND_ASSIGN(InstantLoader); |
177 }; | 180 }; |
178 | 181 |
179 #endif // CHROME_BROWSER_INSTANT_INSTANT_LOADER_H_ | 182 #endif // CHROME_BROWSER_INSTANT_INSTANT_LOADER_H_ |
OLD | NEW |