Popular sites on the NTP: check that experiment group StartsWith (rather than IS...
[chromium-blink-merge.git] / chrome / browser / devtools / devtools_ui_bindings.h
bloba705d7e6ebd3d0dc81e10faac6a8825dae682249
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 "net/url_request/url_fetcher_delegate.h"
23 #include "ui/gfx/geometry/size.h"
25 class DevToolsAndroidBridge;
26 class InfoBarService;
27 class Profile;
29 namespace content {
30 struct FileChooserParams;
31 class WebContents;
34 // Base implementation of DevTools bindings around front-end.
35 class DevToolsUIBindings :public content::DevToolsFrontendHost::Delegate,
36 public DevToolsEmbedderMessageDispatcher::Delegate,
37 public DevToolsAndroidBridge::DeviceCountListener,
38 public content::DevToolsAgentHostClient,
39 public net::URLFetcherDelegate {
40 public:
41 static DevToolsUIBindings* ForWebContents(
42 content::WebContents* web_contents);
44 class Delegate {
45 public:
46 virtual ~Delegate() {}
47 virtual void ActivateWindow() = 0;
48 virtual void CloseWindow() = 0;
49 virtual void SetInspectedPageBounds(const gfx::Rect& rect) = 0;
50 virtual void InspectElementCompleted() = 0;
51 virtual void SetIsDocked(bool is_docked) = 0;
52 virtual void OpenInNewTab(const std::string& url) = 0;
53 virtual void SetWhitelistedShortcuts(const std::string& message) = 0;
55 virtual void InspectedContentsClosing() = 0;
56 virtual void OnLoadCompleted() = 0;
57 virtual InfoBarService* GetInfoBarService() = 0;
58 virtual void RenderProcessGone(bool crashed) = 0;
61 explicit DevToolsUIBindings(content::WebContents* web_contents);
62 ~DevToolsUIBindings() override;
64 content::WebContents* web_contents() { return web_contents_; }
65 Profile* profile() { return profile_; }
66 content::DevToolsAgentHost* agent_host() { return agent_host_.get(); }
68 // Takes ownership over the |delegate|.
69 void SetDelegate(Delegate* delegate);
70 void CallClientFunction(const std::string& function_name,
71 const base::Value* arg1,
72 const base::Value* arg2,
73 const base::Value* arg3);
74 void AttachTo(const scoped_refptr<content::DevToolsAgentHost>& agent_host);
75 void Reattach();
76 void Detach();
77 bool IsAttachedTo(content::DevToolsAgentHost* agent_host);
79 private:
81 // content::DevToolsFrontendHost::Delegate implementation.
82 void HandleMessageFromDevToolsFrontend(const std::string& message) override;
83 void HandleMessageFromDevToolsFrontendToBackend(
84 const std::string& message) override;
86 // content::DevToolsAgentHostClient implementation.
87 void DispatchProtocolMessage(content::DevToolsAgentHost* agent_host,
88 const std::string& message) override;
89 void AgentHostClosed(content::DevToolsAgentHost* agent_host,
90 bool replaced_with_another_client) override;
92 // DevToolsEmbedderMessageDispatcher::Delegate implementation.
93 void ActivateWindow() override;
94 void CloseWindow() override;
95 void LoadCompleted() override;
96 void SetInspectedPageBounds(const gfx::Rect& rect) override;
97 void InspectElementCompleted() override;
98 void InspectedURLChanged(const std::string& url) override;
99 void LoadNetworkResource(const DispatchCallback& callback,
100 const std::string& url,
101 const std::string& headers,
102 int stream_id) override;
103 void SetIsDocked(const DispatchCallback& callback, bool is_docked) override;
104 void OpenInNewTab(const std::string& url) override;
105 void SaveToFile(const std::string& url,
106 const std::string& content,
107 bool save_as) override;
108 void AppendToFile(const std::string& url,
109 const std::string& content) override;
110 void RequestFileSystems() override;
111 void AddFileSystem() override;
112 void RemoveFileSystem(const std::string& file_system_path) override;
113 void UpgradeDraggedFileSystemPermissions(
114 const std::string& file_system_url) override;
115 void IndexPath(int index_request_id,
116 const std::string& file_system_path) override;
117 void StopIndexing(int index_request_id) override;
118 void SearchInPath(int search_request_id,
119 const std::string& file_system_path,
120 const std::string& query) override;
121 void SetWhitelistedShortcuts(const std::string& message) override;
122 void ZoomIn() override;
123 void ZoomOut() override;
124 void ResetZoom() override;
125 void SetDevicesUpdatesEnabled(bool enabled) override;
126 void SendMessageToBrowser(const std::string& message) override;
127 void RecordEnumeratedHistogram(const std::string& name,
128 int sample,
129 int boundary_value) override;
130 void SendJsonRequest(const DispatchCallback& callback,
131 const std::string& browser_id,
132 const std::string& url) override;
133 void GetPreferences(const DispatchCallback& callback) override;
134 void SetPreference(const std::string& name,
135 const std::string& value) override;
136 void RemovePreference(const std::string& name) override;
137 void ClearPreferences() override;
139 // net::URLFetcherDelegate overrides.
140 void OnURLFetchComplete(const net::URLFetcher* source) override;
142 void EnableRemoteDeviceCounter(bool enable);
144 void SendMessageAck(int request_id,
145 const base::Value* arg1);
147 // DevToolsAndroidBridge::DeviceCountListener override:
148 void DeviceCountChanged(int count) override;
150 // Forwards discovered devices to frontend.
151 virtual void DevicesUpdated(const std::string& source,
152 const base::ListValue& targets);
154 void DocumentOnLoadCompletedInMainFrame();
155 void DidNavigateMainFrame();
156 void FrontendLoaded();
158 void JsonReceived(const DispatchCallback& callback,
159 int result,
160 const std::string& message);
162 // DevToolsFileHelper callbacks.
163 void FileSavedAs(const std::string& url);
164 void CanceledFileSaveAs(const std::string& url);
165 void AppendedTo(const std::string& url);
166 void FileSystemsLoaded(
167 const std::vector<DevToolsFileHelper::FileSystem>& file_systems);
168 void FileSystemAdded(const DevToolsFileHelper::FileSystem& file_system);
169 void IndexingTotalWorkCalculated(int request_id,
170 const std::string& file_system_path,
171 int total_work);
172 void IndexingWorked(int request_id,
173 const std::string& file_system_path,
174 int worked);
175 void IndexingDone(int request_id, const std::string& file_system_path);
176 void SearchCompleted(int request_id,
177 const std::string& file_system_path,
178 const std::vector<std::string>& file_paths);
179 typedef base::Callback<void(bool)> InfoBarCallback;
180 void ShowDevToolsConfirmInfoBar(const base::string16& message,
181 const InfoBarCallback& callback);
183 // Extensions support.
184 void AddDevToolsExtensionsToClient();
186 class FrontendWebContentsObserver;
187 friend class FrontendWebContentsObserver;
188 scoped_ptr<FrontendWebContentsObserver> frontend_contents_observer_;
190 Profile* profile_;
191 DevToolsAndroidBridge* android_bridge_;
192 content::WebContents* web_contents_;
193 scoped_ptr<Delegate> delegate_;
194 scoped_refptr<content::DevToolsAgentHost> agent_host_;
195 scoped_ptr<content::DevToolsFrontendHost> frontend_host_;
196 scoped_ptr<DevToolsFileHelper> file_helper_;
197 scoped_refptr<DevToolsFileSystemIndexer> file_system_indexer_;
198 typedef std::map<
199 int,
200 scoped_refptr<DevToolsFileSystemIndexer::FileSystemIndexingJob> >
201 IndexingJobsMap;
202 IndexingJobsMap indexing_jobs_;
204 bool devices_updates_enabled_;
205 bool frontend_loaded_;
206 scoped_ptr<DevToolsTargetsUIHandler> remote_targets_handler_;
207 scoped_ptr<DevToolsEmbedderMessageDispatcher> embedder_message_dispatcher_;
208 GURL url_;
209 using PendingRequestsMap = std::map<const net::URLFetcher*, DispatchCallback>;
210 PendingRequestsMap pending_requests_;
211 base::WeakPtrFactory<DevToolsUIBindings> weak_factory_;
213 DISALLOW_COPY_AND_ASSIGN(DevToolsUIBindings);
216 #endif // CHROME_BROWSER_DEVTOOLS_DEVTOOLS_UI_BINDINGS_H_