Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(47)

Side by Side Diff: chrome/browser/ui/search/search_tab_helper.h

Issue 16035020: Move instant support to SearchTabHelper. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Addressed nits Created 7 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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_SEARCH_TAB_HELPER_H_ 5 #ifndef CHROME_BROWSER_UI_SEARCH_SEARCH_TAB_HELPER_H_
6 #define CHROME_BROWSER_UI_SEARCH_SEARCH_TAB_HELPER_H_ 6 #define CHROME_BROWSER_UI_SEARCH_SEARCH_TAB_HELPER_H_
7 7
8 #include <vector> 8 #include <vector>
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/gtest_prod_util.h"
12 #include "chrome/browser/ui/search/search_model.h" 13 #include "chrome/browser/ui/search/search_model.h"
13 #include "chrome/common/instant_types.h" 14 #include "chrome/common/instant_types.h"
14 #include "content/public/browser/notification_observer.h" 15 #include "content/public/browser/notification_observer.h"
15 #include "content/public/browser/notification_registrar.h" 16 #include "content/public/browser/notification_registrar.h"
16 #include "content/public/browser/web_contents_observer.h" 17 #include "content/public/browser/web_contents_observer.h"
17 #include "content/public/browser/web_contents_user_data.h" 18 #include "content/public/browser/web_contents_user_data.h"
18 19
19 namespace content { 20 namespace content {
20 class WebContents; 21 class WebContents;
21 } 22 }
22 23
24 class InstantPageTest;
25
23 // Per-tab search "helper". Acts as the owner and controller of the tab's 26 // Per-tab search "helper". Acts as the owner and controller of the tab's
24 // search UI model. 27 // search UI model.
28 //
29 // When the page is finished loading, SearchTabHelper determines the instant
30 // support for the page. When a navigation entry is committed (except for
31 // in-page navigations), SearchTabHelper resets the instant support state to
32 // INSTANT_SUPPORT_UNKNOWN and cause support to be determined again.
25 class SearchTabHelper : public content::NotificationObserver, 33 class SearchTabHelper : public content::NotificationObserver,
26 public content::WebContentsObserver, 34 public content::WebContentsObserver,
27 public content::WebContentsUserData<SearchTabHelper> { 35 public content::WebContentsUserData<SearchTabHelper> {
28 public: 36 public:
29 virtual ~SearchTabHelper(); 37 virtual ~SearchTabHelper();
30 38
31 SearchModel* model() { 39 SearchModel* model() {
32 return &model_; 40 return &model_;
33 } 41 }
34 42
35 // Invoked when the OmniboxEditModel changes state in some way that might 43 // Invoked when the OmniboxEditModel changes state in some way that might
36 // affect the search mode. 44 // affect the search mode.
37 void OmniboxEditModelChanged(bool user_input_in_progress, 45 void OmniboxEditModelChanged(bool user_input_in_progress,
38 bool cancelling, 46 bool cancelling,
39 bool popup_is_open, 47 bool popup_is_open,
40 bool user_text_is_empty); 48 bool user_text_is_empty);
41 49
42 // Invoked when the active navigation entry is updated in some way that might 50 // Invoked when the active navigation entry is updated in some way that might
43 // affect the search mode. This is used by Instant when it "fixes up" the 51 // affect the search mode. This is used by Instant when it "fixes up" the
44 // virtual URL of the active entry. Regular navigations are captured through 52 // virtual URL of the active entry. Regular navigations are captured through
45 // the notification system and shouldn't call this method. 53 // the notification system and shouldn't call this method.
46 void NavigationEntryUpdated(); 54 void NavigationEntryUpdated();
47 55
48 // Updates |last_known_most_visited_items_| with |items|. 56 // Updates |last_known_most_visited_items_| with |items|.
49 // Returns false if |items| matches the |last_known_most_visited_items_|. 57 // Returns false if |items| matches the |last_known_most_visited_items_|.
50 bool UpdateLastKnownMostVisitedItems( 58 bool UpdateLastKnownMostVisitedItems(
51 const std::vector<InstantMostVisitedItem>& items); 59 const std::vector<InstantMostVisitedItem>& items);
52 60
61 // Invoked to update the instant support state.
62 void InstantSupportChanged(bool supports_instant);
63
64 // Returns true if the page supports instant. If the instant support state is
65 // not determined or if the page does not support instant returns false.
66 bool SupportsInstant() const;
67
53 private: 68 private:
54 friend class content::WebContentsUserData<SearchTabHelper>; 69 friend class content::WebContentsUserData<SearchTabHelper>;
70 friend class InstantPageTest;
71 FRIEND_TEST_ALL_PREFIXES(InstantPageTest,
72 DetermineIfPageSupportsInstant_Local);
73 FRIEND_TEST_ALL_PREFIXES(InstantPageTest,
74 DetermineIfPageSupportsInstant_NonLocal);
75 FRIEND_TEST_ALL_PREFIXES(InstantPageTest,
76 PageURLDoesntBelongToInstantRenderer);
77 FRIEND_TEST_ALL_PREFIXES(InstantPageTest, PageSupportsInstant);
55 78
56 explicit SearchTabHelper(content::WebContents* web_contents); 79 explicit SearchTabHelper(content::WebContents* web_contents);
57 80
58 // Overridden from content::NotificationObserver: 81 // Overridden from content::NotificationObserver:
59 virtual void Observe(int type, 82 virtual void Observe(int type,
60 const content::NotificationSource& source, 83 const content::NotificationSource& source,
61 const content::NotificationDetails& details) OVERRIDE; 84 const content::NotificationDetails& details) OVERRIDE;
62 85
63 // Overridden from contents::WebContentsObserver: 86 // Overridden from contents::WebContentsObserver:
64 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; 87 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE;
88 virtual void DidFinishLoad(
89 int64 frame_id,
90 const GURL& validated_url,
91 bool is_main_frame,
92 content::RenderViewHost* render_view_host) OVERRIDE;
65 93
66 // Sets the mode of the model based on the current URL of web_contents(). 94 // Sets the mode of the model based on the current URL of web_contents().
67 void UpdateMode(); 95 void UpdateMode();
68 96
97 // Tells the renderer to determine if the page supports the Instant API, which
98 // results in a call to OnInstantSupportDetermined() when the reply
99 // is received.
100 void DetermineIfPageSupportsInstant();
101
102 // Handler for when Instant support has been determined.
103 void OnInstantSupportDetermined(int page_id, bool supports_instant);
104
69 // Handlers for SearchBox API to show and hide top bars (bookmark and info 105 // Handlers for SearchBox API to show and hide top bars (bookmark and info
70 // bars). 106 // bars).
71 void OnSearchBoxShowBars(int page_id); 107 void OnSearchBoxShowBars(int page_id);
72 void OnSearchBoxHideBars(int page_id); 108 void OnSearchBoxHideBars(int page_id);
73 109
74 const bool is_search_enabled_; 110 const bool is_search_enabled_;
75 111
76 // Tracks the last value passed to OmniboxEditModelChanged(). 112 // Tracks the last value passed to OmniboxEditModelChanged().
77 bool user_input_in_progress_; 113 bool user_input_in_progress_;
78 bool popup_is_open_; 114 bool popup_is_open_;
79 bool user_text_is_empty_; 115 bool user_text_is_empty_;
80 116
81 // Model object for UI that cares about search state. 117 // Model object for UI that cares about search state.
82 SearchModel model_; 118 SearchModel model_;
83 119
84 content::NotificationRegistrar registrar_; 120 content::NotificationRegistrar registrar_;
85 121
86 content::WebContents* web_contents_; 122 content::WebContents* web_contents_;
87 123
88 // Tracks the last set of most visited items sent to the InstantPage renderer. 124 // Tracks the last set of most visited items sent to the InstantPage renderer.
89 // Used to prevent sending duplicate IPC messages to the renderer. 125 // Used to prevent sending duplicate IPC messages to the renderer.
90 std::vector<InstantMostVisitedItem> last_known_most_visited_items_; 126 std::vector<InstantMostVisitedItem> last_known_most_visited_items_;
91 127
92 DISALLOW_COPY_AND_ASSIGN(SearchTabHelper); 128 DISALLOW_COPY_AND_ASSIGN(SearchTabHelper);
93 }; 129 };
94 130
95 #endif // CHROME_BROWSER_UI_SEARCH_SEARCH_TAB_HELPER_H_ 131 #endif // CHROME_BROWSER_UI_SEARCH_SEARCH_TAB_HELPER_H_
OLDNEW
« no previous file with comments | « chrome/browser/ui/search/search_model_unittest.cc ('k') | chrome/browser/ui/search/search_tab_helper.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698