Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 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_INSTANT_INSTANT_PAGE_H_ | 5 #ifndef CHROME_BROWSER_INSTANT_INSTANT_PAGE_H_ |
| 6 #define CHROME_BROWSER_INSTANT_INSTANT_PAGE_H_ | 6 #define CHROME_BROWSER_INSTANT_INSTANT_PAGE_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/memory/scoped_ptr.h" | |
| 12 #include "base/string16.h" | 13 #include "base/string16.h" |
| 13 #include "chrome/common/instant_types.h" | 14 #include "chrome/common/instant_types.h" |
| 15 #include "chrome/common/omnibox_types.h" | |
| 14 #include "content/public/browser/web_contents_observer.h" | 16 #include "content/public/browser/web_contents_observer.h" |
| 15 #include "content/public/common/page_transition_types.h" | 17 #include "content/public/common/page_transition_types.h" |
| 18 #include "ui/base/window_open_disposition.h" | |
| 16 | 19 |
| 17 class GURL; | 20 class GURL; |
| 21 class InstantService; | |
| 18 | 22 |
| 19 namespace content { | 23 namespace content { |
| 20 class WebContents; | 24 class WebContents; |
| 21 } | 25 } |
| 22 | 26 |
| 23 namespace gfx { | 27 namespace gfx { |
| 24 class Rect; | 28 class Rect; |
| 25 } | 29 } |
| 26 | 30 |
| 31 namespace IPC { | |
| 32 class Message; | |
| 33 } | |
| 34 | |
| 27 // InstantPage is used to exchange messages with a page that implements the | 35 // InstantPage is used to exchange messages with a page that implements the |
| 28 // Instant/Embedded Search API (http://dev.chromium.org/embeddedsearch). | 36 // Instant/Embedded Search API (http://dev.chromium.org/embeddedsearch). |
| 29 // InstantPage is not used directly but via one of its derived classes: | |
| 30 // InstantOverlay, InstantNTP and InstantTab. | |
| 31 class InstantPage : public content::WebContentsObserver { | 37 class InstantPage : public content::WebContentsObserver { |
| 32 public: | 38 public: |
| 33 // InstantPage calls its delegate in response to messages received from the | 39 // InstantPage calls its delegate in response to messages received from the |
| 34 // page. Each method is called with the |contents| corresponding to the page | 40 // page. Each method is called with the |contents| corresponding to the page |
| 35 // we are observing. | 41 // we are observing. |
| 36 class Delegate { | 42 class Delegate { |
| 37 public: | 43 public: |
| 38 // Called when a RenderView is created, so that state can be initialized. | 44 // Called when the underlying RenderView crashed. |
| 39 virtual void InstantPageRenderViewCreated( | 45 virtual void RenderViewGone(const content::WebContents* contents) = 0; |
| 46 | |
| 47 // Called to request the delegate to initialize searchbox state, such as | |
| 48 // theme, omnibox font, size, width, margin, Instant preference, etc. | |
| 49 virtual void InitSearchBox(const content::WebContents* contents) = 0; | |
| 50 | |
| 51 // Called whem messages are received from the page. See instant_messages.h | |
| 52 // for details. | |
| 53 virtual void InstantSupportDetermined( | |
| 40 const content::WebContents* contents) = 0; | 54 const content::WebContents* contents) = 0; |
| 41 | 55 virtual void SetSuggestion(const content::WebContents* contents, |
| 42 // Called upon determination of Instant API support. Either in response to | 56 const InstantSuggestion& suggestion) = 0; |
| 43 // the page loading or because we received some other message. | |
| 44 virtual void InstantSupportDetermined(const content::WebContents* contents, | |
| 45 bool supports_instant) = 0; | |
| 46 | |
| 47 // Called when the underlying RenderView crashed. | |
| 48 virtual void InstantPageRenderViewGone( | |
| 49 const content::WebContents* contents) = 0; | |
| 50 | |
| 51 // Called when the page is about to navigate to |url|. | |
| 52 virtual void InstantPageAboutToNavigateMainFrame( | |
| 53 const content::WebContents* contents, | |
| 54 const GURL& url) = 0; | |
| 55 | |
| 56 // Called when the page has suggestions. Usually in response to Update(), | |
| 57 // SendAutocompleteResults() or UpOrDownKeyPressed(). | |
| 58 virtual void SetSuggestions( | |
| 59 const content::WebContents* contents, | |
| 60 const std::vector<InstantSuggestion>& suggestions) = 0; | |
| 61 | |
| 62 // Called when the page wants to be shown. Usually in response to Update() | |
| 63 // or SendAutocompleteResults(). | |
| 64 virtual void ShowInstantOverlay(const content::WebContents* contents, | |
| 65 InstantShownReason reason, | |
| 66 int height, | |
| 67 InstantSizeUnits units) = 0; | |
| 68 | |
| 69 // Called when the page wants the omnibox to be focused. | |
| 70 virtual void FocusOmnibox(const content::WebContents* contents) = 0; | |
| 71 | |
| 72 // Called when the page wants the omnibox to start capturing user key | |
| 73 // strokes. If this call is processed successfully, the omnibox will not | |
| 74 // look focused visibly but any user key strokes will go to the omnibox. | |
| 75 // Currently, this is implemented by focusing the omnibox invisibly. | |
| 76 virtual void StartCapturingKeyStrokes( | |
| 77 const content::WebContents* contents) = 0; | |
| 78 | |
| 79 // Called when the page wants the omnibox to stop capturing user key | |
| 80 // strokes. | |
| 81 virtual void StopCapturingKeyStrokes(content::WebContents* contents) = 0; | |
| 82 | |
| 83 // Called when the page wants to navigate to |url|. Usually used by the | |
| 84 // page to navigate to privileged destinations (e.g. chrome:// URLs) or to | |
| 85 // navigate to URLs that are hidden from the page using Restricted IDs (rid | |
| 86 // in the API). | |
| 87 virtual void NavigateToURL(const content::WebContents* contents, | 57 virtual void NavigateToURL(const content::WebContents* contents, |
| 88 const GURL& url, | 58 const GURL& url, |
| 89 content::PageTransition transition, | 59 content::PageTransition transition, |
| 90 WindowOpenDisposition disposition) = 0; | 60 WindowOpenDisposition disposition) = 0; |
| 91 | 61 virtual void ShowOverlay(const content::WebContents* contents, |
| 92 // Called when the SearchBox wants to delete a Most Visited item. | 62 int height, |
| 93 virtual void DeleteMostVisitedItem(const GURL& url) = 0; | 63 InstantSizeUnits height_units) = 0; |
| 94 | 64 virtual void SetFocusState(const content::WebContents* contents, |
|
Jered
2013/03/26 16:36:42
Can we call this SetOmniboxFocusState?
| |
| 95 // Called when the SearchBox wants to undo a Most Visited deletion. | 65 OmniboxFocusState focus_state) = 0; |
| 96 virtual void UndoMostVisitedDeletion(const GURL& url) = 0; | 66 virtual void DeleteMostVisitedItem(const content::WebContents* contents, |
| 97 | 67 const GURL& url) = 0; |
| 98 // Called when the SearchBox wants to undo all Most Visited deletions. | 68 virtual void UndoMostVisitedItemDeletion( |
| 99 virtual void UndoAllMostVisitedDeletions() = 0; | 69 const content::WebContents* contents, |
| 70 const GURL& url) = 0; | |
| 71 virtual void UndoAllMostVisitedItemDeletions( | |
| 72 const content::WebContents* contents) = 0; | |
| 100 | 73 |
| 101 protected: | 74 protected: |
| 102 virtual ~Delegate(); | 75 virtual ~Delegate(); |
| 103 }; | 76 }; |
| 104 | 77 |
| 78 InstantPage(Delegate* delegate, InstantService* service); | |
| 105 virtual ~InstantPage(); | 79 virtual ~InstantPage(); |
| 106 | 80 |
| 107 // The WebContents corresponding to the page we're talking to. May be NULL. | 81 // The WebContents corresponding to the page we're talking to. May be NULL. |
| 108 content::WebContents* contents() const { return web_contents(); } | 82 content::WebContents* contents() const { return web_contents(); } |
| 109 | 83 |
| 84 // Starts observing / communicating with |contents|. If |contents| is NULL, | |
| 85 // effectively stops all communication. | |
| 86 void SetContents(content::WebContents* contents); | |
| 87 | |
| 110 // Returns true if the page is known to support the Instant API. This starts | 88 // 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. | 89 // 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 | 90 // Once true, it never becomes false as long as the page doesn't navigate (the |
| 113 // support suddenly). | 91 // page isn't expected to drop API support suddenly). |
| 114 bool supports_instant() const { return supports_instant_; } | 92 bool supports_instant() const { return supports_instant_; } |
| 93 void set_supports_instant(bool supports_instant) { | |
| 94 supports_instant_ = supports_instant; | |
| 95 } | |
| 115 | 96 |
| 116 // Tells the page that the user typed |text| into the omnibox. If |verbatim| | 97 // Returns true if the page has navigated since the last call to Change(). |
| 117 // is false, the page predicts the query the user means to type and fetches | 98 bool navigated_after_change() const { return navigated_after_change_; } |
| 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, | |
| 121 size_t selection_start, | |
| 122 size_t selection_end, | |
| 123 bool verbatim); | |
| 124 | 99 |
| 125 // Tells the page that the user pressed Enter in the omnibox. | 100 // Sends messages to the page. See instant_messages.h for details. |
| 126 void Submit(const string16& text); | 101 void DetermineInstantSupport(); |
| 127 | 102 void Change(const string16& query, |
| 128 // Tells the page that the user clicked on it. Nothing is being cancelled; the | 103 bool verbatim, |
| 129 // poor choice of name merely reflects the IPC of the same (poor) name. | 104 size_t selection_start, |
| 130 void Cancel(const string16& text); | 105 size_t selection_end); |
| 131 | 106 void Submit(const string16& query); |
| 132 // Tells the page the bounds of the omnibox dropdown (in screen coordinates). | 107 void AutocompleteResults( |
| 133 // This is used by the page to offset the results to avoid them being covered | 108 const std::vector<InstantAutocompleteResult>& results); |
| 134 // by the omnibox dropdown. | 109 void Select(int count); |
| 135 void SetPopupBounds(const gfx::Rect& bounds); | 110 void Cancel(const string16& query); |
| 136 | 111 void Blur(const string16& query); |
| 137 // Tells the page the bounds of the omnibox (in screen coordinates). This is | 112 void PopupBounds(const gfx::Rect& bounds); |
| 138 // used by the page to align text or assets properly with the omnibox. | 113 void OmniboxBounds(const gfx::Rect& bounds); |
| 139 void SetOmniboxBounds(const gfx::Rect& bounds); | 114 void KeyCaptureChanged(bool is_key_capture_enabled); |
| 140 | 115 void DisplayInstantResults(bool display_instant_results); |
| 141 // Tells the page about the font information. | 116 void ThemeChanged(const ThemeBackgroundInfo& theme_info); |
| 142 void InitializeFonts(); | 117 void FontChanged(const string16& font_name, size_t font_size); |
| 143 | 118 void MostVisitedItems(const std::vector<MostVisitedItem>& items); |
| 144 // Grant renderer-side chrome-search: access rights for select origins. | |
| 145 void GrantChromeSearchAccessFromOrigin(const GURL& origin_url); | 119 void GrantChromeSearchAccessFromOrigin(const GURL& origin_url); |
| 146 | 120 |
| 147 // Tells the renderer to determine if the page supports the Instant API, which | |
| 148 // results in a call to InstantSupportDetermined() when the reply is received. | |
| 149 void DetermineIfPageSupportsInstant(); | |
| 150 | |
| 151 // Tells the page about the available autocomplete results. | |
| 152 void SendAutocompleteResults( | |
| 153 const std::vector<InstantAutocompleteResult>& results); | |
| 154 | |
| 155 // Tells the page that the user pressed Up or Down in the omnibox. |count| is | |
| 156 // a repeat count, negative for moving up, positive for moving down. | |
| 157 void UpOrDownKeyPressed(int count); | |
| 158 | |
| 159 // Tells the page that the user pressed Esc in the omnibox after having | |
| 160 // arrowed down in the suggestions. The page should reset the selection to | |
| 161 // the first suggestion. |user_text| is what the omnibox has been reset to. | |
| 162 void CancelSelection(const string16& user_text); | |
| 163 | |
| 164 // Tells the page about the current theme background. | |
| 165 void SendThemeBackgroundInfo(const ThemeBackgroundInfo& theme_info); | |
| 166 | |
| 167 // Tells the page whether it is allowed to display Instant results. | |
| 168 void SetDisplayInstantResults(bool display_instant_results); | |
| 169 | |
| 170 // Tells the page whether the browser is capturing user key strokes. | |
| 171 void KeyCaptureChanged(bool is_key_capture_enabled); | |
| 172 | |
| 173 // Tells the page about new Most Visited data. | |
| 174 void SendMostVisitedItems(const std::vector<MostVisitedItem>& items); | |
| 175 | |
| 176 protected: | |
| 177 explicit InstantPage(Delegate* delegate); | |
| 178 | |
| 179 // Sets |contents| as the page to communicate with. |contents| may be NULL, | |
| 180 // which effectively stops all communication. | |
| 181 void SetContents(content::WebContents* contents); | |
| 182 | |
| 183 Delegate* delegate() const { return delegate_; } | |
| 184 | |
| 185 // These functions are called before processing messages received from the | |
|
samarth
2013/03/11 19:03:24
I can't see InstantExtendedController yet, but are
| |
| 186 // page. By default, all messages are handled, but any derived classes may | |
| 187 // choose to ingore some or all of the received messages by overriding these | |
| 188 // methods. | |
| 189 virtual bool ShouldProcessRenderViewCreated(); | |
| 190 virtual bool ShouldProcessRenderViewGone(); | |
| 191 virtual bool ShouldProcessAboutToNavigateMainFrame(); | |
| 192 virtual bool ShouldProcessSetSuggestions(); | |
| 193 virtual bool ShouldProcessShowInstantOverlay(); | |
| 194 virtual bool ShouldProcessFocusOmnibox(); | |
| 195 virtual bool ShouldProcessStartCapturingKeyStrokes(); | |
| 196 virtual bool ShouldProcessStopCapturingKeyStrokes(); | |
| 197 virtual bool ShouldProcessNavigateToURL(); | |
| 198 | |
| 199 private: | 121 private: |
| 200 // Overridden from content::WebContentsObserver: | 122 // Overridden from content::WebContentsObserver: |
| 201 virtual void RenderViewCreated( | 123 virtual void RenderViewGone(base::TerminationStatus status) OVERRIDE; |
| 202 content::RenderViewHost* render_view_host) OVERRIDE; | 124 virtual void DidNavigateMainFrame( |
| 125 const content::LoadCommittedDetails& details, | |
| 126 const content::FrameNavigateParams& params) OVERRIDE; | |
| 203 virtual void DidFinishLoad( | 127 virtual void DidFinishLoad( |
| 204 int64 frame_id, | 128 int64 frame_id, |
| 205 const GURL& validated_url, | 129 const GURL& validated_url, |
| 206 bool is_main_frame, | 130 bool is_main_frame, |
| 207 content::RenderViewHost* render_view_host) OVERRIDE; | 131 content::RenderViewHost* render_view_host) OVERRIDE; |
| 208 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; | 132 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; |
| 209 virtual void RenderViewGone(base::TerminationStatus status) OVERRIDE; | |
| 210 virtual void DidCommitProvisionalLoadForFrame( | |
| 211 int64 frame_id, | |
| 212 bool is_main_frame, | |
| 213 const GURL& url, | |
| 214 content::PageTransition transition_type, | |
| 215 content::RenderViewHost* render_view_host) OVERRIDE; | |
| 216 | 133 |
| 217 void OnSetSuggestions(int page_id, | 134 void SendMessage(scoped_ptr<IPC::Message> message); |
| 218 const std::vector<InstantSuggestion>& suggestions); | 135 |
| 219 void OnInstantSupportDetermined(int page_id, bool supports_instant); | 136 void OnInstantSupportDetermined(int page_id, bool supports_instant); |
| 220 void OnShowInstantOverlay(int page_id, | 137 void OnSetSuggestion(int page_id, const InstantSuggestion& suggestion); |
| 221 InstantShownReason reason, | 138 void OnNavigateToURL(int page_id, |
| 222 int height, | 139 const GURL& url, |
| 223 InstantSizeUnits units); | 140 content::PageTransition transition, |
| 224 void OnFocusOmnibox(int page_id); | 141 WindowOpenDisposition disposition); |
| 225 void OnStartCapturingKeyStrokes(int page_id); | 142 void OnShowOverlay(int page_id, int height, InstantSizeUnits height_units); |
| 226 void OnStopCapturingKeyStrokes(int page_id); | 143 void OnSetFocusState(int page_id, OmniboxFocusState focus_state); |
| 227 void OnSearchBoxNavigate(int page_id, | 144 void OnDeleteMostVisitedItem(int page_id, const GURL& url); |
| 228 const GURL& url, | 145 void OnUndoMostVisitedItemDeletion(int page_id, const GURL& url); |
| 229 content::PageTransition transition, | 146 void OnUndoAllMostVisitedItemDeletions(int page_id); |
| 230 WindowOpenDisposition disposition); | |
| 231 void OnDeleteMostVisitedItem(const GURL& url); | |
| 232 void OnUndoMostVisitedDeletion(const GURL& url); | |
| 233 void OnUndoAllMostVisitedDeletions(); | |
| 234 | 147 |
| 235 Delegate* const delegate_; | 148 Delegate* const delegate_; |
| 149 InstantService* const service_; | |
| 150 int routing_id_; | |
| 236 bool supports_instant_; | 151 bool supports_instant_; |
| 152 bool navigated_after_change_; | |
| 237 | 153 |
| 238 DISALLOW_COPY_AND_ASSIGN(InstantPage); | 154 DISALLOW_COPY_AND_ASSIGN(InstantPage); |
| 239 }; | 155 }; |
| 240 | 156 |
| 241 #endif // CHROME_BROWSER_INSTANT_INSTANT_PAGE_H_ | 157 #endif // CHROME_BROWSER_INSTANT_INSTANT_PAGE_H_ |
| OLD | NEW |