| 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" |
| (...skipping 30 matching lines...) Expand all Loading... |
| 59 // swapped-in the next time the user navigates to the New Tab Page. It is | 60 // 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. | 61 // never shown to the user in an uncommitted state. |
| 61 // (3) An InstantTab instance which points to the currently active tab, if it | 62 // (3) An InstantTab instance which points to the currently active tab, if it |
| 62 // supports the Embedded Search API. | 63 // supports the Embedded Search API. |
| 63 // | 64 // |
| 64 // All three are backed by a WebContents. InstantOverlay and InstantNTP own | 65 // All three are backed by a WebContents. InstantOverlay and InstantNTP own |
| 65 // their corresponding WebContents; InstantTab does not. In non-extended mode, | 66 // their corresponding WebContents; InstantTab does not. In non-extended mode, |
| 66 // only an InstantOverlay instance is kept. | 67 // only an InstantOverlay instance is kept. |
| 67 // | 68 // |
| 68 // InstantController is owned by Browser via BrowserInstantController. | 69 // InstantController is owned by Browser via BrowserInstantController. |
| 69 class InstantController : public InstantPage::Delegate { | 70 class InstantController : public InstantPage::Delegate, |
| 71 public InstantServiceObserver { |
| 70 public: | 72 public: |
| 71 // For reporting fallbacks to local overlay. | 73 // For reporting fallbacks to local overlay. |
| 72 enum InstantFallbackReason { | 74 enum InstantFallbackReason { |
| 73 INSTANT_FALLBACK_NONE = 0, | 75 INSTANT_FALLBACK_NONE = 0, |
| 74 INSTANT_FALLBACK_UNKNOWN = 1, | 76 INSTANT_FALLBACK_UNKNOWN = 1, |
| 75 INSTANT_FALLBACK_INSTANT_URL_EMPTY = 2, | 77 INSTANT_FALLBACK_INSTANT_URL_EMPTY = 2, |
| 76 INSTANT_FALLBACK_ORIGIN_PATH_MISMATCH = 3, | 78 INSTANT_FALLBACK_ORIGIN_PATH_MISMATCH = 3, |
| 77 INSTANT_FALLBACK_INSTANT_NOT_SUPPORTED = 4, | 79 INSTANT_FALLBACK_INSTANT_NOT_SUPPORTED = 4, |
| 78 INSTANT_FALLBACK_NO_OVERLAY = 5, | 80 INSTANT_FALLBACK_NO_OVERLAY = 5, |
| 79 INSTANT_FALLBACK_MAX = 6, | 81 INSTANT_FALLBACK_MAX = 6, |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 186 void ActiveTabChanged(); | 188 void ActiveTabChanged(); |
| 187 | 189 |
| 188 // The user is about to switch tabs. Commit the overlay if needed. | 190 // The user is about to switch tabs. Commit the overlay if needed. |
| 189 void TabDeactivated(content::WebContents* contents); | 191 void TabDeactivated(content::WebContents* contents); |
| 190 | 192 |
| 191 // Sets whether Instant should show result overlays. |use_local_page_only| | 193 // 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 | 194 // will force the use of baked-in page as the Instant URL and is only |
| 193 // applicable if |extended_enabled_| is true. | 195 // applicable if |extended_enabled_| is true. |
| 194 void SetInstantEnabled(bool instant_enabled, bool use_local_page_only); | 196 void SetInstantEnabled(bool instant_enabled, bool use_local_page_only); |
| 195 | 197 |
| 196 // The theme has changed. Pass the message to the overlay page. | 198 // Overridden from InstantServiceObserver: |
| 197 void ThemeChanged(const ThemeBackgroundInfo& theme_info); | 199 virtual void ThemeInfoChanged(const ThemeBackgroundInfo& theme_info) OVERRIDE; |
| 198 | 200 |
| 199 // Called when someone else swapped in a different contents in the |overlay_|. | 201 // Called when someone else swapped in a different contents in the |overlay_|. |
| 200 void SwappedOverlayContents(); | 202 void SwappedOverlayContents(); |
| 201 | 203 |
| 202 // Called when contents for |overlay_| received focus. | 204 // Called when contents for |overlay_| received focus. |
| 203 void FocusedOverlayContents(); | 205 void FocusedOverlayContents(); |
| 204 | 206 |
| 205 // Called when the |overlay_| might be stale. If it's actually stale, and the | 207 // 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_| | 208 // omnibox doesn't have focus, and the overlay isn't showing, the |overlay_| |
| 207 // is deleted and recreated. Else the refresh is skipped. | 209 // is deleted and recreated. Else the refresh is skipped. |
| (...skipping 28 matching lines...) Expand all Loading... |
| 236 | 238 |
| 237 // Returns the transition type of the last AutocompleteMatch passed to Update. | 239 // Returns the transition type of the last AutocompleteMatch passed to Update. |
| 238 content::PageTransition last_transition_type() const { | 240 content::PageTransition last_transition_type() const { |
| 239 return last_transition_type_; | 241 return last_transition_type_; |
| 240 } | 242 } |
| 241 | 243 |
| 242 // Non-const for Add/RemoveObserver only. Other model changes should only | 244 // Non-const for Add/RemoveObserver only. Other model changes should only |
| 243 // happen through the InstantController interface. | 245 // happen through the InstantController interface. |
| 244 InstantOverlayModel* model() { return &model_; } | 246 InstantOverlayModel* model() { return &model_; } |
| 245 | 247 |
| 248 // Sends a request to InstantService to update the InstantServiceObservers |
| 249 // about the theme background information. |
| 250 void UpdateThemeInfo(); |
| 251 |
| 246 protected: | 252 protected: |
| 247 // Accessors are made protected for testing purposes. | 253 // Accessors are made protected for testing purposes. |
| 248 virtual bool extended_enabled() const; | 254 virtual bool extended_enabled() const; |
| 249 | 255 |
| 250 virtual InstantOverlay* overlay() const; | 256 virtual InstantOverlay* overlay() const; |
| 251 virtual InstantTab* instant_tab() const; | 257 virtual InstantTab* instant_tab() const; |
| 252 virtual InstantNTP* ntp() const; | 258 virtual InstantNTP* ntp() const; |
| 253 | 259 |
| 254 private: | 260 private: |
| 255 friend class InstantExtendedManualTest; | 261 friend class InstantExtendedManualTest; |
| (...skipping 287 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 |