OLD | NEW |
| (Empty) |
1 // Copyright 2017 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_UI_APP_LIST_SEARCH_ANSWER_WEB_CONTENTS_DELEGATE_H_ | |
6 #define CHROME_BROWSER_UI_APP_LIST_SEARCH_ANSWER_WEB_CONTENTS_DELEGATE_H_ | |
7 | |
8 #include <memory> | |
9 #include <string> | |
10 | |
11 #include "base/time/time.h" | |
12 #include "content/public/browser/web_contents_delegate.h" | |
13 #include "content/public/browser/web_contents_observer.h" | |
14 #include "ui/app_list/search_provider.h" | |
15 #include "url/gurl.h" | |
16 | |
17 class Profile; | |
18 | |
19 namespace app_list { | |
20 class AppListModel; | |
21 } | |
22 | |
23 namespace net { | |
24 class HttpResponseHeaders; | |
25 } | |
26 | |
27 namespace views { | |
28 class View; | |
29 class WebView; | |
30 } | |
31 | |
32 namespace app_list { | |
33 | |
34 // Search provider for the answer card. | |
35 class SearchAnswerWebContentsDelegate : public SearchProvider, | |
36 public content::WebContentsDelegate, | |
37 public content::WebContentsObserver { | |
38 public: | |
39 SearchAnswerWebContentsDelegate(Profile* profile, | |
40 app_list::AppListModel* model); | |
41 | |
42 ~SearchAnswerWebContentsDelegate() override; | |
43 | |
44 // Returns a pointer to the web view for the web contents managed by this | |
45 // class. The object is owned by this class and has property | |
46 // 'set_owned_by_client()' set. | |
47 views::View* web_view(); | |
48 | |
49 // SearchProvider overrides: | |
50 void Start(bool is_voice_query, const base::string16& query) override; | |
51 void Stop() override {} | |
52 | |
53 // content::WebContentsDelegate overrides: | |
54 void UpdatePreferredSize(content::WebContents* web_contents, | |
55 const gfx::Size& pref_size) override; | |
56 | |
57 content::WebContents* OpenURLFromTab( | |
58 content::WebContents* source, | |
59 const content::OpenURLParams& params) override; | |
60 | |
61 bool HandleContextMenu(const content::ContextMenuParams& params) override; | |
62 | |
63 // content::WebContentsObserver overrides: | |
64 void DidFinishNavigation( | |
65 content::NavigationHandle* navigation_handle) override; | |
66 void DidStopLoading() override; | |
67 void DidGetUserInteraction(const blink::WebInputEvent::Type type) override; | |
68 | |
69 private: | |
70 bool IsCardSizeOk() const; | |
71 void RecordReceivedAnswerFinalResult(); | |
72 void OnResultAvailable(bool is_available); | |
73 bool ParseResponseHeaders(const net::HttpResponseHeaders* headers); | |
74 | |
75 // Unowned pointer to the associated profile. | |
76 Profile* const profile_; | |
77 | |
78 // Unowned pointer to app list model. | |
79 app_list::AppListModel* const model_; | |
80 | |
81 // Web view for the web contents managed by this class. | |
82 const std::unique_ptr<views::WebView> web_view_; | |
83 | |
84 // Whether have received a server response for the current query string, and | |
85 // the response contains an answer. | |
86 bool received_answer_ = false; | |
87 | |
88 // Web contents managed by this class. | |
89 const std::unique_ptr<content::WebContents> web_contents_; | |
90 | |
91 // If valid, URL of the answer server. Otherwise, search answers are disabled. | |
92 GURL answer_server_url_; | |
93 | |
94 // URL of the current answer server request. | |
95 GURL current_request_url_; | |
96 | |
97 // Time when the current server request started. | |
98 base::TimeTicks server_request_start_time_; | |
99 | |
100 // Time when the current server response loaded. | |
101 base::TimeTicks answer_loaded_time_; | |
102 | |
103 // When in the dark run mode, indicates whether we mimic that the server | |
104 // response contains an answer. | |
105 bool dark_run_received_answer_ = false; | |
106 | |
107 // Url to open when the user clicks at the result. | |
108 std::string result_url_; | |
109 | |
110 DISALLOW_COPY_AND_ASSIGN(SearchAnswerWebContentsDelegate); | |
111 }; | |
112 | |
113 } // namespace app_list | |
114 | |
115 #endif // CHROME_BROWSER_UI_APP_LIST_SEARCH_ANSWER_WEB_CONTENTS_DELEGATE_H_ | |
OLD | NEW |