Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #ifndef CHROME_BROWSER_INSTANT_INSTANT_PAGE_H_ | |
| 6 #define CHROME_BROWSER_INSTANT_INSTANT_PAGE_H_ | |
| 7 | |
| 8 #include <vector> | |
| 9 | |
| 10 #include "base/basictypes.h" | |
| 11 #include "base/compiler_specific.h" | |
| 12 #include "base/string16.h" | |
| 13 #include "chrome/common/instant_types.h" | |
| 14 #include "content/public/browser/web_contents_observer.h" | |
| 15 | |
| 16 namespace chrome { | |
| 17 namespace search { | |
| 18 struct Mode; | |
| 19 } | |
| 20 } | |
| 21 | |
| 22 namespace content { | |
| 23 class WebContents; | |
| 24 } | |
| 25 | |
| 26 namespace gfx { | |
| 27 class Rect; | |
| 28 } | |
| 29 | |
|
sreeram
2013/01/22 19:26:59
Add these includes:
content/public/common/page_tra
samarth
2013/01/25 21:08:40
Done.
| |
| 30 // InstantPage is used to exchange messages with a page that implements the | |
| 31 // Instant/Embedded Search API (http://dev.chromium.org/embeddedsearch). | |
| 32 // InstantPage is not used directly but via one of its derived classes: | |
| 33 // InstantOverlay, InstantNTP and InstantTab. | |
| 34 class InstantPage : public content::WebContentsObserver { | |
| 35 public: | |
| 36 // InstantPage calls its delegate in response to messages received from the | |
| 37 // page or in response to certain changes in the page. Each method is called | |
| 38 // with the |contents| corresponding to the page we are observing. | |
| 39 class Delegate { | |
| 40 public: | |
| 41 // Called upon determination of Instant API support. Either in response to | |
| 42 // the page loading or because we recevied some other message. | |
|
sreeram
2013/01/22 19:26:59
"received"
samarth
2013/01/25 21:08:40
Done.
| |
| 43 virtual void InstantSupportDetermined(const content::WebContents* contents, | |
| 44 bool supports_instant) = 0; | |
| 45 | |
| 46 // Called when the underlying RenderView crashed. | |
| 47 virtual void InstantPageRenderViewGone( | |
| 48 const content::WebContents* contents) = 0; | |
| 49 | |
| 50 // Called when the page is about to navigate to |url|. | |
| 51 virtual void InstantPageAboutToNavigateMainFrame( | |
| 52 const content::WebContents* contents, | |
| 53 const GURL& url) = 0; | |
| 54 | |
| 55 // Called when the page has suggestions. Usually in response to Change(), | |
|
sreeram
2013/01/22 19:26:59
Change -> Update
samarth
2013/01/25 21:08:40
Done.
| |
| 56 // SendAutocompleteResults() or UpOrDownKeyPressed(). | |
| 57 virtual void SetSuggestions( | |
| 58 const content::WebContents* contents, | |
| 59 const std::vector<InstantSuggestion>& suggestions) = 0; | |
| 60 | |
| 61 // Called when the page wants to be shown. Usually in response to Change(), | |
|
sreeram
2013/01/22 19:26:59
Change -> Update
samarth
2013/01/25 21:08:40
Done.
| |
| 62 // SendAutocompleteResults() or SearchModeChanged(). | |
| 63 virtual void ShowInstantPreview(const content::WebContents* contents, | |
| 64 InstantShownReason reason, | |
| 65 int height, | |
| 66 InstantSizeUnits units) = 0; | |
| 67 | |
| 68 // Called when the page wants the browser to start capturing user key | |
| 69 // strokes. | |
| 70 virtual void StartCapturingKeyStrokes( | |
| 71 const content::WebContents* contents) = 0; | |
| 72 | |
| 73 // Called when the page wants the browser to stop capturing user key | |
| 74 // strokes. | |
| 75 virtual void StopCapturingKeyStrokes(content::WebContents* contents) = 0; | |
|
sreeram
2013/01/22 19:26:59
Make the comments on these two methods clearer. Ta
samarth
2013/01/25 21:08:40
Done.
| |
| 76 | |
| 77 // Called when the page wants to navigate to the specified URL. | |
| 78 virtual void NavigateToURL(const content::WebContents* contents, | |
| 79 const GURL& url, | |
| 80 content::PageTransition transition) = 0; | |
| 81 | |
| 82 // Called when the page is considered stale. | |
| 83 virtual void OnStalePage(const content::WebContents* contents) = 0; | |
|
sreeram
2013/01/22 19:26:59
This is too hacky for my taste. Figure out a clean
samarth
2013/01/25 21:08:40
You're right. Got rid of the InstantLoader relate
| |
| 84 | |
| 85 // Called when |new_contents| has been swapped into the page (usually | |
| 86 // because a prerendered page was navigated to). | |
| 87 virtual void InstantPageSwappedContents( | |
| 88 content::WebContents* new_contents) = 0; | |
| 89 | |
| 90 // Called when the page gains focus. | |
| 91 virtual void InstantPageFocused(const content::WebContents* contents) = 0; | |
| 92 | |
| 93 // Called when the user clicks on the page. | |
| 94 virtual void InstantPageClicked(const content::WebContents* contents) = 0; | |
| 95 | |
| 96 // Called when a URL is about to be opened using the underlying contents. | |
| 97 // Should return true to allow the URL to open. | |
| 98 virtual bool InstantPageAboutToOpenURL( | |
| 99 const content::WebContents* contents) = 0; | |
|
sreeram
2013/01/22 19:26:59
Could you reorder these so that the three "open UR
Shishir
2013/01/25 20:41:13
In the present code there are two places where the
samarth
2013/01/25 21:08:40
Added more comments for NavigateToURL. Got rid of
| |
| 100 | |
| 101 protected: | |
| 102 virtual ~Delegate(); | |
| 103 }; | |
| 104 | |
| 105 virtual ~InstantPage(); | |
| 106 | |
| 107 // The WebContents corresponding to the page we're talking to. May be NULL. | |
| 108 content::WebContents* contents() const { return contents_; } | |
| 109 | |
| 110 // Returns true if the page is known to support the Instant API. This starts | |
| 111 // out false, and is set to true whenever we get any message from the page. | |
| 112 // Once true, it never becomes false (the page isn't expected to drop API | |
| 113 // support suddenly). | |
| 114 bool supports_instant() const { return supports_instant_; } | |
| 115 | |
| 116 // Tells the page that the user typed |text| into the omnibox. If |verbatim| | |
| 117 // is false, the page predicts the query the user means to type and fetches | |
| 118 // results for the prediction. If |verbatim| is true, |text| is taken as the | |
| 119 // exact query (no prediction is made). | |
| 120 virtual void Update(const string16& text, | |
|
sreeram
2013/01/22 19:26:59
No need for this to be virtual, I think.
samarth
2013/01/25 21:08:40
This is virtual to allow InstantOverlay to overrid
| |
| 121 size_t selection_start, | |
| 122 size_t selection_end, | |
| 123 bool verbatim); | |
| 124 | |
| 125 // Tells the page that the user pressed Enter in the omnibox. | |
| 126 void Submit(const string16& text); | |
| 127 | |
| 128 // Tells the page that the user clicked on it. Nothing is being cancelled; the | |
| 129 // poor choice of name merely reflects the IPC of the same (poor) name. | |
| 130 void Cancel(const string16& text); | |
| 131 | |
| 132 // Tells the page the bounds of the omnibox dropdown (in screen coordinates). | |
| 133 // This is used by the page to offset the results to avoid them being covered | |
| 134 // by the omnibox dropdown. | |
| 135 void SetPopupBounds(const gfx::Rect& bounds); | |
| 136 | |
| 137 // Tells the page what size start and end margins to use. | |
| 138 void SetMarginSize(const int start, const int end); | |
|
sreeram
2013/01/22 19:26:59
Remove the const. This falls into const-craziness
samarth
2013/01/25 21:08:40
Agree that these consts are useless. Removed.
| |
| 139 | |
| 140 // Tells the renderer to determine if the page supports the Instant API, which | |
| 141 // results in a call to InstantSupportDetermined() when the reply is received. | |
| 142 void DetermineIfPageSupportsInstant(); | |
| 143 | |
| 144 // Tells the page about the available autocomplete results. | |
| 145 void SendAutocompleteResults( | |
| 146 const std::vector<InstantAutocompleteResult>& results); | |
| 147 | |
| 148 // Tells the page that the user pressed Up or Down in the omnibox. |count| is | |
| 149 // a repeat count, negative for moving up, positive for moving down. | |
| 150 void UpOrDownKeyPressed(int count); | |
| 151 | |
| 152 // Tells the page that the active tab's search mode has changed. | |
| 153 void SearchModeChanged(const chrome::search::Mode& mode); | |
| 154 | |
| 155 // Tells the page about the current theme background. | |
| 156 void SendThemeBackgroundInfo(const ThemeBackgroundInfo& theme_info); | |
| 157 | |
| 158 // Tells the page about the current theme area height. | |
| 159 void SendThemeAreaHeight(int height); | |
| 160 | |
| 161 // Tells the page whether it is allowed to display Instant results. | |
| 162 void SetDisplayInstantResults(bool display_instant_results); | |
| 163 | |
| 164 // Tells the page whether the browser is capturing user key strokes. | |
| 165 void KeyCaptureChanged(bool is_key_capture_enabled); | |
| 166 | |
| 167 protected: | |
| 168 // Doesn't take ownership of |delegate|. | |
| 169 explicit InstantPage(Delegate* delegate); | |
| 170 | |
| 171 // Sets |contents| as the page to communicate with. |contents| may be NULL, | |
| 172 // which effectively stops all communication. | |
| 173 void SetContents(content::WebContents* contents); | |
| 174 | |
| 175 Delegate* delegate() const { return delegate_; } | |
| 176 | |
| 177 // These functions are called before processing messages received from the | |
| 178 // page. By default, all messages are handled, but any derived classes may | |
| 179 // choose to ingore some or all of the received messages by overriding these | |
| 180 // methods. | |
| 181 virtual bool ShouldProcessRenderViewGone() const; | |
| 182 virtual bool ShouldProcessAboutToNavigateMainFrame() const; | |
| 183 virtual bool ShouldProcessSetSuggestions() const; | |
| 184 virtual bool ShouldProcessShowInstantPreview() const; | |
| 185 virtual bool ShouldProcessStartCapturingKeyStrokes() const; | |
| 186 virtual bool ShouldProcessStopCapturingKeyStrokes() const; | |
| 187 virtual bool ShouldProcessNavigateToURL() const; | |
|
sreeram
2013/01/22 19:26:59
I'd remove "const" from these methods. In general,
samarth
2013/01/25 21:08:40
I wouldn't expect a "bool ShouldProcess..." method
| |
| 188 | |
| 189 private: | |
| 190 // Overridden from content::WebContentsObserver: | |
| 191 virtual void DidFinishLoad( | |
| 192 int64 frame_id, | |
| 193 const GURL& validated_url, | |
| 194 bool is_main_frame, | |
| 195 content::RenderViewHost* render_view_host) OVERRIDE; | |
| 196 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; | |
| 197 virtual void RenderViewGone(base::TerminationStatus status) OVERRIDE; | |
| 198 virtual void DidCommitProvisionalLoadForFrame( | |
| 199 int64 frame_id, | |
| 200 bool is_main_frame, | |
| 201 const GURL& url, | |
| 202 content::PageTransition transition_type, | |
| 203 content::RenderViewHost* render_view_host) OVERRIDE; | |
| 204 | |
| 205 void OnSetSuggestions(int page_id, | |
| 206 const std::vector<InstantSuggestion>& suggestions); | |
| 207 void OnInstantSupportDetermined(int page_id, bool supports_instant); | |
| 208 void OnShowInstantPreview(int page_id, | |
| 209 InstantShownReason reason, | |
| 210 int height, | |
| 211 InstantSizeUnits units); | |
| 212 void OnStartCapturingKeyStrokes(int page_id); | |
| 213 void OnStopCapturingKeyStrokes(int page_id); | |
| 214 void OnSearchBoxNavigate(int page_id, const GURL& url, | |
| 215 content::PageTransition transition); | |
| 216 | |
| 217 Delegate* const delegate_; | |
| 218 content::WebContents* contents_; | |
| 219 bool supports_instant_; | |
|
sreeram
2013/01/22 19:26:59
DISALLOW_COPY_AND_ASSIGN()?
samarth
2013/01/25 21:08:40
Is it necessary here? I'm adding them to the subc
dhollowa
2013/01/29 02:37:53
The style guide is pretty clear on this point. Al
samarth
2013/01/29 05:42:01
Done.
| |
| 220 }; | |
| 221 | |
| 222 #endif // CHROME_BROWSER_INSTANT_INSTANT_PAGE_H_ | |
| OLD | NEW |