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_JAVASCRIPT_DISABLED = 6, | 82 INSTANT_FALLBACK_JAVASCRIPT_DISABLED = 6, |
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
187 void ActiveTabChanged(); | 190 void ActiveTabChanged(); |
188 | 191 |
189 // The user is about to switch tabs. Commit the overlay if needed. | 192 // The user is about to switch tabs. Commit the overlay if needed. |
190 void TabDeactivated(content::WebContents* contents); | 193 void TabDeactivated(content::WebContents* contents); |
191 | 194 |
192 // Sets whether Instant should show result overlays. |use_local_page_only| | 195 // Sets whether Instant should show result overlays. |use_local_page_only| |
193 // will force the use of baked-in page as the Instant URL and is only | 196 // will force the use of baked-in page as the Instant URL and is only |
194 // applicable if |extended_enabled_| is true. | 197 // applicable if |extended_enabled_| is true. |
195 void SetInstantEnabled(bool instant_enabled, bool use_local_page_only); | 198 void SetInstantEnabled(bool instant_enabled, bool use_local_page_only); |
196 | 199 |
197 // The theme has changed. Pass the message to the overlay page. | |
198 void ThemeChanged(const ThemeBackgroundInfo& theme_info); | |
199 | |
200 // Called when someone else swapped in a different contents in the |overlay_|. | 200 // Called when someone else swapped in a different contents in the |overlay_|. |
201 void SwappedOverlayContents(); | 201 void SwappedOverlayContents(); |
202 | 202 |
203 // Called when contents for |overlay_| received focus. | 203 // Called when contents for |overlay_| received focus. |
204 void FocusedOverlayContents(); | 204 void FocusedOverlayContents(); |
205 | 205 |
206 // Called when the |overlay_| might be stale. If it's actually stale, and the | 206 // Called when the |overlay_| might be stale. If it's actually stale, and the |
207 // omnibox doesn't have focus, and the overlay isn't showing, the |overlay_| | 207 // omnibox doesn't have focus, and the overlay isn't showing, the |overlay_| |
208 // is deleted and recreated. Else the refresh is skipped. | 208 // is deleted and recreated. Else the refresh is skipped. |
209 void ReloadOverlayIfStale(); | 209 void ReloadOverlayIfStale(); |
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
363 virtual void FocusOmnibox(const content::WebContents* contents, | 363 virtual void FocusOmnibox(const content::WebContents* contents, |
364 OmniboxFocusState state) OVERRIDE; | 364 OmniboxFocusState state) OVERRIDE; |
365 virtual void NavigateToURL( | 365 virtual void NavigateToURL( |
366 const content::WebContents* contents, | 366 const content::WebContents* contents, |
367 const GURL& url, | 367 const GURL& url, |
368 content::PageTransition transition, | 368 content::PageTransition transition, |
369 WindowOpenDisposition disposition, | 369 WindowOpenDisposition disposition, |
370 bool is_search_type) OVERRIDE; | 370 bool is_search_type) OVERRIDE; |
371 virtual void InstantPageLoadFailed(content::WebContents* contents) OVERRIDE; | 371 virtual void InstantPageLoadFailed(content::WebContents* contents) OVERRIDE; |
372 | 372 |
| 373 // Overridden from InstantServiceObserver: |
| 374 virtual void ThemeInfoChanged(const ThemeBackgroundInfo& theme_info) OVERRIDE; |
| 375 |
373 // Invoked by the InstantLoader when the Instant page wants to delete a | 376 // Invoked by the InstantLoader when the Instant page wants to delete a |
374 // Most Visited item. | 377 // Most Visited item. |
375 virtual void DeleteMostVisitedItem(const GURL& url) OVERRIDE; | 378 virtual void DeleteMostVisitedItem(const GURL& url) OVERRIDE; |
376 | 379 |
377 // Invoked by the InstantLoader when the Instant page wants to undo a | 380 // Invoked by the InstantLoader when the Instant page wants to undo a |
378 // Most Visited deletion. | 381 // Most Visited deletion. |
379 virtual void UndoMostVisitedDeletion(const GURL& url) OVERRIDE; | 382 virtual void UndoMostVisitedDeletion(const GURL& url) OVERRIDE; |
380 | 383 |
381 // Invoked by the InstantLoader when the Instant page wants to undo all | 384 // Invoked by the InstantLoader when the Instant page wants to undo all |
382 // Most Visited deletions. | 385 // Most Visited deletions. |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
453 | 456 |
454 // Populates InstantAutocompleteResult with AutocompleteMatch details. | 457 // Populates InstantAutocompleteResult with AutocompleteMatch details. |
455 // |autocomplete_match_index| specifies the index of |match| in the | 458 // |autocomplete_match_index| specifies the index of |match| in the |
456 // AutocompleteResult. If the |match| is obtained from auto complete | 459 // AutocompleteResult. If the |match| is obtained from auto complete |
457 // providers, then the |autocomplete_match_index| is set to kNoMatchIndex. | 460 // providers, then the |autocomplete_match_index| is set to kNoMatchIndex. |
458 void PopulateInstantAutocompleteResultFromMatch( | 461 void PopulateInstantAutocompleteResultFromMatch( |
459 const AutocompleteMatch& match, | 462 const AutocompleteMatch& match, |
460 size_t autocomplete_match_index, | 463 size_t autocomplete_match_index, |
461 InstantAutocompleteResult* result); | 464 InstantAutocompleteResult* result); |
462 | 465 |
| 466 // Returns the InstantService for the browser profile. |
| 467 InstantService* GetInstantService() const; |
| 468 |
463 BrowserInstantController* const browser_; | 469 BrowserInstantController* const browser_; |
464 | 470 |
465 // Whether the extended API and regular API are enabled. If both are false, | 471 // Whether the extended API and regular API are enabled. If both are false, |
466 // Instant is effectively disabled. | 472 // Instant is effectively disabled. |
467 const bool extended_enabled_; | 473 const bool extended_enabled_; |
468 bool instant_enabled_; | 474 bool instant_enabled_; |
469 | 475 |
470 // If true, the Instant URL is set to kChromeSearchLocalNtpUrl. | 476 // If true, the Instant URL is set to kChromeSearchLocalNtpUrl. |
471 bool use_local_page_only_; | 477 bool use_local_page_only_; |
472 | 478 |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
561 // MODE_SEARCH_SUGGESTIONS, except in those cases where this is false. | 567 // MODE_SEARCH_SUGGESTIONS, except in those cases where this is false. |
562 bool allow_overlay_to_show_search_suggestions_; | 568 bool allow_overlay_to_show_search_suggestions_; |
563 | 569 |
564 // List of events and their timestamps, useful in debugging Instant behaviour. | 570 // List of events and their timestamps, useful in debugging Instant behaviour. |
565 mutable std::list<std::pair<int64, std::string> > debug_events_; | 571 mutable std::list<std::pair<int64, std::string> > debug_events_; |
566 | 572 |
567 DISALLOW_COPY_AND_ASSIGN(InstantController); | 573 DISALLOW_COPY_AND_ASSIGN(InstantController); |
568 }; | 574 }; |
569 | 575 |
570 #endif // CHROME_BROWSER_UI_SEARCH_INSTANT_CONTROLLER_H_ | 576 #endif // CHROME_BROWSER_UI_SEARCH_INSTANT_CONTROLLER_H_ |
OLD | NEW |