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_SEARCH_INSTANT_CONTROLLER_H_ | 5 #ifndef CHROME_BROWSER_UI_SEARCH_INSTANT_CONTROLLER_H_ |
6 #define CHROME_BROWSER_UI_SEARCH_INSTANT_CONTROLLER_H_ | 6 #define CHROME_BROWSER_UI_SEARCH_INSTANT_CONTROLLER_H_ |
7 | 7 |
8 #include <list> | 8 #include <list> |
9 #include <string> | 9 #include <string> |
10 #include <utility> | 10 #include <utility> |
11 #include <vector> | 11 #include <vector> |
12 | 12 |
13 #include "base/basictypes.h" | 13 #include "base/basictypes.h" |
14 #include "base/gtest_prod_util.h" | 14 #include "base/gtest_prod_util.h" |
15 #include "base/memory/scoped_ptr.h" | 15 #include "base/memory/scoped_ptr.h" |
16 #include "base/strings/string16.h" | 16 #include "base/strings/string16.h" |
17 #include "base/time.h" | 17 #include "base/time.h" |
18 #include "base/timer.h" | 18 #include "base/timer.h" |
19 #include "chrome/browser/search/instant_service_observer.h" | |
19 #include "chrome/browser/ui/omnibox/omnibox_edit_model.h" | 20 #include "chrome/browser/ui/omnibox/omnibox_edit_model.h" |
20 #include "chrome/browser/ui/search/instant_commit_type.h" | 21 #include "chrome/browser/ui/search/instant_commit_type.h" |
21 #include "chrome/browser/ui/search/instant_overlay_model.h" | 22 #include "chrome/browser/ui/search/instant_overlay_model.h" |
22 #include "chrome/browser/ui/search/instant_page.h" | 23 #include "chrome/browser/ui/search/instant_page.h" |
23 #include "chrome/common/instant_types.h" | 24 #include "chrome/common/instant_types.h" |
24 #include "chrome/common/omnibox_focus_state.h" | 25 #include "chrome/common/omnibox_focus_state.h" |
25 #include "chrome/common/search_types.h" | 26 #include "chrome/common/search_types.h" |
26 #include "content/public/common/page_transition_types.h" | 27 #include "content/public/common/page_transition_types.h" |
27 #include "googleurl/src/gurl.h" | 28 #include "googleurl/src/gurl.h" |
28 #include "ui/base/window_open_disposition.h" | 29 #include "ui/base/window_open_disposition.h" |
29 #include "ui/gfx/native_widget_types.h" | 30 #include "ui/gfx/native_widget_types.h" |
30 #include "ui/gfx/rect.h" | 31 #include "ui/gfx/rect.h" |
31 | 32 |
32 struct AutocompleteMatch; | 33 struct AutocompleteMatch; |
33 struct InstantAutocompleteResult; | 34 struct InstantAutocompleteResult; |
34 | 35 |
35 class AutocompleteProvider; | 36 class AutocompleteProvider; |
36 class AutocompleteResult; | 37 class AutocompleteResult; |
37 class BrowserInstantController; | 38 class BrowserInstantController; |
38 class InstantNTP; | 39 class InstantNTP; |
39 class InstantOverlay; | 40 class InstantOverlay; |
41 class InstantService; | |
40 class InstantTab; | 42 class InstantTab; |
41 class TemplateURL; | 43 class TemplateURL; |
42 | 44 |
43 namespace content { | 45 namespace content { |
44 class WebContents; | 46 class WebContents; |
45 } | 47 } |
46 | 48 |
47 // Macro used for logging debug events. |message| should be a std::string. | 49 // Macro used for logging debug events. |message| should be a std::string. |
48 #define LOG_INSTANT_DEBUG_EVENT(controller, message) \ | 50 #define LOG_INSTANT_DEBUG_EVENT(controller, message) \ |
49 controller->LogDebugEvent(message) | 51 controller->LogDebugEvent(message) |
50 | 52 |
51 // InstantController drives Chrome Instant, i.e., the browser implementation of | 53 // InstantController drives Chrome Instant, i.e., the browser implementation of |
52 // the Embedded Search API (see http://dev.chromium.org/embeddedsearch). | 54 // the Embedded Search API (see http://dev.chromium.org/embeddedsearch). |
53 // | 55 // |
54 // In extended mode, InstantController maintains and coordinates three | 56 // In extended mode, InstantController maintains and coordinates three |
55 // instances of InstantPage: | 57 // instances of InstantPage: |
56 // (1) An InstantOverlay instance that is used to show search suggestions and | 58 // (1) An InstantOverlay instance that is used to show search suggestions and |
57 // results in an overlay over a non-search page. | 59 // results in an overlay over a non-search page. |
58 // (2) An InstantNTP instance which is a preloaded search page that will be | 60 // (2) An InstantNTP instance which is a preloaded search page that will be |
59 // swapped-in the next time the user navigates to the New Tab Page. It is | 61 // swapped-in the next time the user navigates to the New Tab Page. It is |
60 // never shown to the user in an uncommitted state. | 62 // never shown to the user in an uncommitted state. |
61 // (3) An InstantTab instance which points to the currently active tab, if it | 63 // (3) An InstantTab instance which points to the currently active tab, if it |
62 // supports the Embedded Search API. | 64 // supports the Embedded Search API. |
63 // | 65 // |
64 // All three are backed by a WebContents. InstantOverlay and InstantNTP own | 66 // All three are backed by a WebContents. InstantOverlay and InstantNTP own |
65 // their corresponding WebContents; InstantTab does not. In non-extended mode, | 67 // their corresponding WebContents; InstantTab does not. In non-extended mode, |
66 // only an InstantOverlay instance is kept. | 68 // only an InstantOverlay instance is kept. |
67 // | 69 // |
68 // InstantController is owned by Browser via BrowserInstantController. | 70 // InstantController is owned by Browser via BrowserInstantController. |
69 class InstantController : public InstantPage::Delegate { | 71 class InstantController : public InstantPage::Delegate, |
72 public InstantServiceObserver { | |
70 public: | 73 public: |
71 // For reporting fallbacks to local overlay. | 74 // For reporting fallbacks to local overlay. |
72 enum InstantFallbackReason { | 75 enum InstantFallbackReason { |
73 INSTANT_FALLBACK_NONE = 0, | 76 INSTANT_FALLBACK_NONE = 0, |
74 INSTANT_FALLBACK_UNKNOWN = 1, | 77 INSTANT_FALLBACK_UNKNOWN = 1, |
75 INSTANT_FALLBACK_INSTANT_URL_EMPTY = 2, | 78 INSTANT_FALLBACK_INSTANT_URL_EMPTY = 2, |
76 INSTANT_FALLBACK_ORIGIN_PATH_MISMATCH = 3, | 79 INSTANT_FALLBACK_ORIGIN_PATH_MISMATCH = 3, |
77 INSTANT_FALLBACK_INSTANT_NOT_SUPPORTED = 4, | 80 INSTANT_FALLBACK_INSTANT_NOT_SUPPORTED = 4, |
78 INSTANT_FALLBACK_NO_OVERLAY = 5, | 81 INSTANT_FALLBACK_NO_OVERLAY = 5, |
79 INSTANT_FALLBACK_MAX = 6, | 82 INSTANT_FALLBACK_MAX = 6, |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
186 void ActiveTabChanged(); | 189 void ActiveTabChanged(); |
187 | 190 |
188 // The user is about to switch tabs. Commit the overlay if needed. | 191 // The user is about to switch tabs. Commit the overlay if needed. |
189 void TabDeactivated(content::WebContents* contents); | 192 void TabDeactivated(content::WebContents* contents); |
190 | 193 |
191 // Sets whether Instant should show result overlays. |use_local_page_only| | 194 // Sets whether Instant should show result overlays. |use_local_page_only| |
192 // will force the use of baked-in page as the Instant URL and is only | 195 // will force the use of baked-in page as the Instant URL and is only |
193 // applicable if |extended_enabled_| is true. | 196 // applicable if |extended_enabled_| is true. |
194 void SetInstantEnabled(bool instant_enabled, bool use_local_page_only); | 197 void SetInstantEnabled(bool instant_enabled, bool use_local_page_only); |
195 | 198 |
196 // The theme has changed. Pass the message to the overlay page. | 199 // Overridden from InstantServiceObserver: |
samarth
2013/06/19 05:34:54
This can be private I think.
kmadhusu
2013/06/19 17:43:30
Done.
| |
197 void ThemeChanged(const ThemeBackgroundInfo& theme_info); | 200 virtual void ThemeInfoChanged(const ThemeBackgroundInfo& theme_info) OVERRIDE; |
198 | 201 |
199 // Called when someone else swapped in a different contents in the |overlay_|. | 202 // Called when someone else swapped in a different contents in the |overlay_|. |
200 void SwappedOverlayContents(); | 203 void SwappedOverlayContents(); |
201 | 204 |
202 // Called when contents for |overlay_| received focus. | 205 // Called when contents for |overlay_| received focus. |
203 void FocusedOverlayContents(); | 206 void FocusedOverlayContents(); |
204 | 207 |
205 // Called when the |overlay_| might be stale. If it's actually stale, and the | 208 // Called when the |overlay_| might be stale. If it's actually stale, and the |
206 // omnibox doesn't have focus, and the overlay isn't showing, the |overlay_| | 209 // omnibox doesn't have focus, and the overlay isn't showing, the |overlay_| |
207 // is deleted and recreated. Else the refresh is skipped. | 210 // is deleted and recreated. Else the refresh is skipped. |
(...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
435 | 438 |
436 // Populates InstantAutocompleteResult with AutocompleteMatch details. | 439 // Populates InstantAutocompleteResult with AutocompleteMatch details. |
437 // |autocomplete_match_index| specifies the index of |match| in the | 440 // |autocomplete_match_index| specifies the index of |match| in the |
438 // AutocompleteResult. If the |match| is obtained from auto complete | 441 // AutocompleteResult. If the |match| is obtained from auto complete |
439 // providers, then the |autocomplete_match_index| is set to kNoMatchIndex. | 442 // providers, then the |autocomplete_match_index| is set to kNoMatchIndex. |
440 void PopulateInstantAutocompleteResultFromMatch( | 443 void PopulateInstantAutocompleteResultFromMatch( |
441 const AutocompleteMatch& match, | 444 const AutocompleteMatch& match, |
442 size_t autocomplete_match_index, | 445 size_t autocomplete_match_index, |
443 InstantAutocompleteResult* result); | 446 InstantAutocompleteResult* result); |
444 | 447 |
448 // Returns the InstantService for the browser profile. | |
449 InstantService* GetInstantService() const; | |
450 | |
445 BrowserInstantController* const browser_; | 451 BrowserInstantController* const browser_; |
446 | 452 |
447 // Whether the extended API and regular API are enabled. If both are false, | 453 // Whether the extended API and regular API are enabled. If both are false, |
448 // Instant is effectively disabled. | 454 // Instant is effectively disabled. |
449 const bool extended_enabled_; | 455 const bool extended_enabled_; |
450 bool instant_enabled_; | 456 bool instant_enabled_; |
451 | 457 |
452 // If true, the Instant URL is set to kChromeSearchLocalNtpUrl. | 458 // If true, the Instant URL is set to kChromeSearchLocalNtpUrl. |
453 bool use_local_page_only_; | 459 bool use_local_page_only_; |
454 | 460 |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
543 // MODE_SEARCH_SUGGESTIONS, except in those cases where this is false. | 549 // MODE_SEARCH_SUGGESTIONS, except in those cases where this is false. |
544 bool allow_overlay_to_show_search_suggestions_; | 550 bool allow_overlay_to_show_search_suggestions_; |
545 | 551 |
546 // List of events and their timestamps, useful in debugging Instant behaviour. | 552 // List of events and their timestamps, useful in debugging Instant behaviour. |
547 mutable std::list<std::pair<int64, std::string> > debug_events_; | 553 mutable std::list<std::pair<int64, std::string> > debug_events_; |
548 | 554 |
549 DISALLOW_COPY_AND_ASSIGN(InstantController); | 555 DISALLOW_COPY_AND_ASSIGN(InstantController); |
550 }; | 556 }; |
551 | 557 |
552 #endif // CHROME_BROWSER_UI_SEARCH_INSTANT_CONTROLLER_H_ | 558 #endif // CHROME_BROWSER_UI_SEARCH_INSTANT_CONTROLLER_H_ |
OLD | NEW |