Make castv2 performance test work.
[chromium-blink-merge.git] / chrome / browser / devtools / devtools_ui_bindings.h
blobdd238c770bb68dfc3dc0e0bc2ebca914500fecdd
1 // Copyright 2014 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.
5 #ifndef CHROME_BROWSER_DEVTOOLS_DEVTOOLS_UI_BINDINGS_H_
6 #define CHROME_BROWSER_DEVTOOLS_DEVTOOLS_UI_BINDINGS_H_
8 #include <string>
9 #include <vector>
11 #include "base/basictypes.h"
12 #include "base/memory/scoped_ptr.h"
13 #include "base/memory/weak_ptr.h"
14 #include "base/strings/string16.h"
15 #include "chrome/browser/devtools/device/devtools_android_bridge.h"
16 #include "chrome/browser/devtools/devtools_embedder_message_dispatcher.h"
17 #include "chrome/browser/devtools/devtools_file_helper.h"
18 #include "chrome/browser/devtools/devtools_file_system_indexer.h"
19 #include "chrome/browser/devtools/devtools_targets_ui.h"
20 #include "content/public/browser/devtools_agent_host.h"
21 #include "content/public/browser/devtools_frontend_host.h"
22 #include "content/public/browser/notification_observer.h"
23 #include "content/public/browser/notification_registrar.h"
24 #include "net/url_request/url_fetcher_delegate.h"
25 #include "ui/gfx/geometry/size.h"
27 class DevToolsAndroidBridge;
28 class InfoBarService;
29 class Profile;
31 namespace content {
32 struct FileChooserParams;
33 class WebContents;
36 // Base implementation of DevTools bindings around front-end.
37 class DevToolsUIBindings : public content::NotificationObserver,
38 public content::DevToolsFrontendHost::Delegate,
39 public DevToolsEmbedderMessageDispatcher::Delegate,
40 public DevToolsAndroidBridge::DeviceCountListener,
41 public content::DevToolsAgentHostClient,
42 public net::URLFetcherDelegate {
43 public:
44 static DevToolsUIBindings* ForWebContents(
45 content::WebContents* web_contents);
46 static GURL ApplyThemeToURL(Profile* profile, const GURL& base_url);
48 class Delegate {
49 public:
50 virtual ~Delegate() {}
51 virtual void ActivateWindow() = 0;
52 virtual void CloseWindow() = 0;
53 virtual void SetInspectedPageBounds(const gfx::Rect& rect) = 0;
54 virtual void InspectElementCompleted() = 0;
55 virtual void SetIsDocked(bool is_docked) = 0;
56 virtual void OpenInNewTab(const std::string& url) = 0;
57 virtual void SetWhitelistedShortcuts(const std::string& message) = 0;
59 virtual void InspectedContentsClosing() = 0;
60 virtual void OnLoadCompleted() = 0;
61 virtual InfoBarService* GetInfoBarService() = 0;
62 virtual void RenderProcessGone(bool crashed) = 0;
65 explicit DevToolsUIBindings(content::WebContents* web_contents);
66 ~DevToolsUIBindings() override;
68 content::WebContents* web_contents() { return web_contents_; }
69 Profile* profile() { return profile_; }
70 content::DevToolsAgentHost* agent_host() { return agent_host_.get(); }
72 // Takes ownership over the |delegate|.
73 void SetDelegate(Delegate* delegate);
74 void CallClientFunction(const std::string& function_name,
75 const base::Value* arg1,
76 const base::Value* arg2,
77 const base::Value* arg3);
78 void AttachTo(const scoped_refptr<content::DevToolsAgentHost>& agent_host);
79 void Reattach();
80 void Detach();
81 bool IsAttachedTo(content::DevToolsAgentHost* agent_host);
83 private:
84 // content::NotificationObserver overrides.
85 void Observe(int type,
86 const content::NotificationSource& source,
87 const content::NotificationDetails& details) override;
89 // content::DevToolsFrontendHost::Delegate implementation.
90 void HandleMessageFromDevToolsFrontend(const std::string& message) override;
91 void HandleMessageFromDevToolsFrontendToBackend(
92 const std::string& message) override;
94 // content::DevToolsAgentHostClient implementation.
95 void DispatchProtocolMessage(content::DevToolsAgentHost* agent_host,
96 const std::string& message) override;
97 void AgentHostClosed(content::DevToolsAgentHost* agent_host,
98 bool replaced_with_another_client) override;
100 // DevToolsEmbedderMessageDispatcher::Delegate implementation.
101 void ActivateWindow() override;
102 void CloseWindow() override;
103 void LoadCompleted() override;
104 void SetInspectedPageBounds(const gfx::Rect& rect) override;
105 void InspectElementCompleted() override;
106 void InspectedURLChanged(const std::string& url) override;
107 void LoadNetworkResource(const DispatchCallback& callback,
108 const std::string& url,
109 const std::string& headers,
110 int stream_id) override;
111 void SetIsDocked(const DispatchCallback& callback, bool is_docked) override;
112 void OpenInNewTab(const std::string& url) override;
113 void SaveToFile(const std::string& url,
114 const std::string& content,
115 bool save_as) override;
116 void AppendToFile(const std::string& url,
117 const std::string& content) override;
118 void RequestFileSystems() override;
119 void AddFileSystem() override;
120 void RemoveFileSystem(const std::string& file_system_path) override;
121 void UpgradeDraggedFileSystemPermissions(
122 const std::string& file_system_url) override;
123 void IndexPath(int index_request_id,
124 const std::string& file_system_path) override;
125 void StopIndexing(int index_request_id) override;
126 void SearchInPath(int search_request_id,
127 const std::string& file_system_path,
128 const std::string& query) override;
129 void SetWhitelistedShortcuts(const std::string& message) override;
130 void ZoomIn() override;
131 void ZoomOut() override;
132 void ResetZoom() override;
133 void SetDevicesUpdatesEnabled(bool enabled) override;
134 void SendMessageToBrowser(const std::string& message) override;
135 void RecordActionUMA(const std::string& name, int action) override;
136 void SendJsonRequest(const DispatchCallback& callback,
137 const std::string& browser_id,
138 const std::string& url) override;
140 // net::URLFetcherDelegate overrides.
141 void OnURLFetchComplete(const net::URLFetcher* source) override;
143 void EnableRemoteDeviceCounter(bool enable);
145 void SendMessageAck(int request_id,
146 const base::Value* arg1);
148 // DevToolsAndroidBridge::DeviceCountListener override:
149 void DeviceCountChanged(int count) override;
151 // Forwards discovered devices to frontend.
152 virtual void DevicesUpdated(const std::string& source,
153 const base::ListValue& targets);
155 void DocumentOnLoadCompletedInMainFrame();
156 void DidNavigateMainFrame();
157 void FrontendLoaded();
159 void JsonReceived(const DispatchCallback& callback,
160 int result,
161 const std::string& message);
163 // DevToolsFileHelper callbacks.
164 void FileSavedAs(const std::string& url);
165 void CanceledFileSaveAs(const std::string& url);
166 void AppendedTo(const std::string& url);
167 void FileSystemsLoaded(
168 const std::vector<DevToolsFileHelper::FileSystem>& file_systems);
169 void FileSystemAdded(const DevToolsFileHelper::FileSystem& file_system);
170 void IndexingTotalWorkCalculated(int request_id,
171 const std::string& file_system_path,
172 int total_work);
173 void IndexingWorked(int request_id,
174 const std::string& file_system_path,
175 int worked);
176 void IndexingDone(int request_id, const std::string& file_system_path);
177 void SearchCompleted(int request_id,
178 const std::string& file_system_path,
179 const std::vector<std::string>& file_paths);
180 typedef base::Callback<void(bool)> InfoBarCallback;
181 void ShowDevToolsConfirmInfoBar(const base::string16& message,
182 const InfoBarCallback& callback);
184 // Theme and extensions support.
185 void UpdateTheme();
186 void AddDevToolsExtensionsToClient();
188 class FrontendWebContentsObserver;
189 friend class FrontendWebContentsObserver;
190 scoped_ptr<FrontendWebContentsObserver> frontend_contents_observer_;
192 Profile* profile_;
193 DevToolsAndroidBridge* android_bridge_;
194 content::WebContents* web_contents_;
195 scoped_ptr<Delegate> delegate_;
196 scoped_refptr<content::DevToolsAgentHost> agent_host_;
197 content::NotificationRegistrar registrar_;
198 scoped_ptr<content::DevToolsFrontendHost> frontend_host_;
199 scoped_ptr<DevToolsFileHelper> file_helper_;
200 scoped_refptr<DevToolsFileSystemIndexer> file_system_indexer_;
201 typedef std::map<
202 int,
203 scoped_refptr<DevToolsFileSystemIndexer::FileSystemIndexingJob> >
204 IndexingJobsMap;
205 IndexingJobsMap indexing_jobs_;
207 bool devices_updates_enabled_;
208 bool frontend_loaded_;
209 scoped_ptr<DevToolsTargetsUIHandler> remote_targets_handler_;
210 scoped_ptr<DevToolsEmbedderMessageDispatcher> embedder_message_dispatcher_;
211 GURL url_;
212 using PendingRequestsMap = std::map<const net::URLFetcher*, DispatchCallback>;
213 PendingRequestsMap pending_requests_;
214 base::WeakPtrFactory<DevToolsUIBindings> weak_factory_;
216 DISALLOW_COPY_AND_ASSIGN(DevToolsUIBindings);
219 #endif // CHROME_BROWSER_DEVTOOLS_DEVTOOLS_UI_BINDINGS_H_