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_INSTANT_INSTANT_CLIENT_H_ | 5 #ifndef CHROME_BROWSER_INSTANT_INSTANT_API_WRAPPER_H_ |
6 #define CHROME_BROWSER_INSTANT_INSTANT_CLIENT_H_ | 6 #define CHROME_BROWSER_INSTANT_INSTANT_API_WRAPPER_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/string16.h" | 12 #include "base/string16.h" |
13 #include "chrome/common/instant_types.h" | 13 #include "chrome/common/instant_types.h" |
14 #include "content/public/browser/web_contents_observer.h" | 14 #include "content/public/browser/web_contents_observer.h" |
15 | 15 |
16 namespace chrome { | 16 namespace chrome { |
17 namespace search { | 17 namespace search { |
18 struct Mode; | 18 struct Mode; |
19 } | 19 } |
20 } | 20 } |
21 | 21 |
22 namespace content { | 22 namespace content { |
23 class WebContents; | 23 class WebContents; |
24 } | 24 } |
25 | 25 |
26 namespace gfx { | 26 namespace gfx { |
27 class Rect; | 27 class Rect; |
28 } | 28 } |
29 | 29 |
30 // InstantClient is used to exchange messages between its delegate and a page | 30 // InstantAPIWrapper is used for exchanging messages with a page that supports |
31 // that supports the Instant API (http://dev.chromium.org/searchbox). | 31 // the Instant/Embedded Search API (http://dev.chromium.org/embeddedsearch). |
32 class InstantClient : public content::WebContentsObserver { | 32 // |
33 // The messages received by InstantAPIWrapper are sent to a class that | |
34 // implements InstantAPIWrapper::Receiver, unless the message is intercepted and | |
35 // cancelled by InstantAPIWrapper::Controller. | |
36 class InstantAPIWrapper : public content::WebContentsObserver { | |
dhollowa
2013/01/14 19:59:39
Not a fan of this name. How about just InstantPag
samarth
2013/01/22 15:59:06
Done.
| |
33 public: | 37 public: |
34 // When InstantClient receives messages from the page, it calls the following | 38 // When InstantAPIWrapper receives a message, it first checks with its |
35 // methods on its delegate. | 39 // Controller to see whether it should process the message. |
36 class Delegate { | 40 class Controller { |
Jered
2013/01/14 18:22:34
Calling this a controller feels a bit off. Some of
dhollowa
2013/01/14 19:59:39
+1. And this should not be pure-virtual, there sh
samarth
2013/01/22 15:59:06
Done.
| |
37 public: | 41 public: |
42 // Returns true if the page is known to support the Instant API. This starts | |
43 // out false, and is set to true whenever we get any message from the page. | |
44 // Once true, it never becomes false (the page isn't expected to drop API | |
45 // support suddenly). | |
46 virtual bool supports_instant() const = 0; | |
Jered
2013/01/14 18:22:34
Consider just implementing these in the Wrapper, s
samarth
2013/01/22 15:59:06
Done.
| |
47 virtual void set_supports_instant(bool supports_instant) = 0; | |
48 | |
49 // Called when Update() is called on the API. | |
50 virtual void OnUpdate() = 0; | |
Jered
2013/01/14 18:22:34
Can whoever is calling Update() do this?
samarth
2013/01/22 15:59:06
Just overriding Update() now in InstantOverlay. (
| |
51 | |
52 // These functions are called before processing messages received from the | |
53 // page. If the controller returns false, the message is ignored. | |
54 // (See corresponding functions in Receiver for details for each of these.) | |
55 virtual bool OnRenderViewGone() const = 0; | |
56 virtual bool OnAboutToNavigateMainFrame() const = 0; | |
57 virtual bool OnSetSuggestions() const = 0; | |
58 virtual bool OnShowInstantPreview() const = 0; | |
59 virtual bool OnStartCapturingKeyStrokes() const = 0; | |
60 virtual bool OnStopCapturingKeyStrokes() const = 0; | |
61 virtual bool OnNavigateToURL() const = 0; | |
62 | |
63 protected: | |
64 virtual ~Controller(); | |
65 }; | |
66 | |
67 // InstantAPIWrapper calls one of the methods on Receiver after receiving a | |
68 // message from the page. Each method is called with the |contents| | |
69 // corresponding to the page from which the message was received. | |
70 class Receiver { | |
dhollowa
2013/01/14 19:59:39
I preferred the original name "Delegate".
samarth
2013/01/22 15:59:06
Done.
| |
71 public: | |
72 // Called upon determination of Instant API support. Either in response to | |
73 // the page loading or because we recevied some other message. | |
74 virtual void InstantSupportDetermined(const content::WebContents* contents, | |
75 bool supports_instant) = 0; | |
76 | |
77 // Called when the underlying RenderView crashed. | |
78 virtual void InstantPageRenderViewGone( | |
79 const content::WebContents* contents) = 0; | |
80 | |
81 // Called when the page is about to navigate. | |
82 virtual void InstantPageAboutToNavigateMainFrame( | |
83 const content::WebContents* contents, | |
84 const GURL& url) = 0; | |
85 | |
38 // Called when the page has suggestions. Usually in response to Change(), | 86 // Called when the page has suggestions. Usually in response to Change(), |
39 // SendAutocompleteResults() or UpOrDownKeyPressed(). | 87 // SendAutocompleteResults() or UpOrDownKeyPressed(). |
40 virtual void SetSuggestions( | 88 virtual void SetSuggestions( |
89 const content::WebContents* contents, | |
41 const std::vector<InstantSuggestion>& suggestions) = 0; | 90 const std::vector<InstantSuggestion>& suggestions) = 0; |
42 | 91 |
43 // Called upon determination of Instant API support. Usually in response to | |
44 // SetContents() or when the page first finishes loading. | |
45 virtual void InstantSupportDetermined(bool supports_instant) = 0; | |
46 | |
47 // Called when the page wants to be shown. Usually in response to Change(), | 92 // Called when the page wants to be shown. Usually in response to Change(), |
48 // SendAutocompleteResults() or SearchModeChanged(). | 93 // SendAutocompleteResults() or SearchModeChanged(). |
49 virtual void ShowInstantPreview(InstantShownReason reason, | 94 virtual void ShowInstantPreview(const content::WebContents* contents, |
95 InstantShownReason reason, | |
50 int height, | 96 int height, |
51 InstantSizeUnits units) = 0; | 97 InstantSizeUnits units) = 0; |
52 | 98 |
53 // Called when the page wants the browser to start capturing user key | 99 // Called when the page wants the browser to start capturing user key |
54 // strokes. | 100 // strokes. |
55 virtual void StartCapturingKeyStrokes() = 0; | 101 virtual void StartCapturingKeyStrokes( |
102 const content::WebContents* contents) = 0; | |
56 | 103 |
57 // Called when the page wants the browser to stop capturing user key | 104 // Called when the page wants the browser to stop capturing user key |
58 // strokes. | 105 // strokes. |
59 virtual void StopCapturingKeyStrokes() = 0; | 106 virtual void StopCapturingKeyStrokes(content::WebContents* contents) = 0; |
60 | 107 |
61 // Called when the underlying RenderView crashes. | 108 // Called when the page wants to navigate to the specified URL. |
62 virtual void RenderViewGone() = 0; | 109 virtual void NavigateToURL(const content::WebContents* contents, |
63 | 110 const GURL& url, |
64 // Called when the page is about to navigate. | |
65 virtual void AboutToNavigateMainFrame(const GURL& url) = 0; | |
66 | |
67 // Called when the SearchBox wants to navigate to the specified URL. | |
68 virtual void NavigateToURL(const GURL& url, | |
69 content::PageTransition transition) = 0; | 111 content::PageTransition transition) = 0; |
70 | 112 |
71 protected: | 113 protected: |
72 virtual ~Delegate(); | 114 virtual ~Receiver(); |
73 }; | 115 }; |
74 | 116 |
75 // Doesn't take ownership of |delegate|. | 117 // Doesn't take ownership of |controller| or |receiver|. |
76 explicit InstantClient(Delegate* delegate); | 118 InstantAPIWrapper(Controller* controller, Receiver* receiver); |
77 virtual ~InstantClient(); | 119 virtual ~InstantAPIWrapper(); |
78 | 120 |
79 // Sets |contents| as the page to communicate with. |contents| can be NULL, | 121 // Sets |contents| as the page to communicate with. |contents| can be NULL, |
80 // which effectively stops all communication. | 122 // which effectively stops all communication. |
81 void SetContents(content::WebContents* contents); | 123 void SetContents(content::WebContents* contents); |
82 | 124 |
83 // Tells the page that the user typed |text| into the omnibox. If |verbatim| | 125 // Tells the page that the user typed |text| into the omnibox. If |verbatim| |
84 // is false, the page predicts the query the user means to type and fetches | 126 // is false, the page predicts the query the user means to type and fetches |
85 // results for the prediction. If |verbatim| is true, |text| is taken as the | 127 // results for the prediction. If |verbatim| is true, |text| is taken as the |
86 // exact query (no prediction is made). | 128 // exact query (no prediction is made). |
87 void Update(const string16& text, | 129 void Update(const string16& text, |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
152 void InstantSupportDetermined(int page_id, bool result); | 194 void InstantSupportDetermined(int page_id, bool result); |
153 void ShowInstantPreview(int page_id, | 195 void ShowInstantPreview(int page_id, |
154 InstantShownReason reason, | 196 InstantShownReason reason, |
155 int height, | 197 int height, |
156 InstantSizeUnits units); | 198 InstantSizeUnits units); |
157 void StartCapturingKeyStrokes(int page_id); | 199 void StartCapturingKeyStrokes(int page_id); |
158 void StopCapturingKeyStrokes(int page_id); | 200 void StopCapturingKeyStrokes(int page_id); |
159 void SearchBoxNavigate(int page_id, const GURL& url, | 201 void SearchBoxNavigate(int page_id, const GURL& url, |
160 content::PageTransition transition); | 202 content::PageTransition transition); |
161 | 203 |
162 Delegate* const delegate_; | 204 Controller* const controller_; |
205 Receiver* const receiver_; | |
163 | 206 |
164 DISALLOW_COPY_AND_ASSIGN(InstantClient); | 207 DISALLOW_COPY_AND_ASSIGN(InstantAPIWrapper); |
165 }; | 208 }; |
166 | 209 |
167 #endif // CHROME_BROWSER_INSTANT_INSTANT_CLIENT_H_ | 210 #endif // CHROME_BROWSER_INSTANT_INSTANT_API_WRAPPER_H_ |
OLD | NEW |