Only grant permissions to new extensions from sync if they have the expected version
[chromium-blink-merge.git] / chrome / browser / devtools / devtools_ui_bindings.h
blobb3a83f45a017886829f7a4ddffabc1d5d6c02861
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);
78 content::DevToolsExternalAgentProxyDelegate* CreateWebSocketAPIChannel();
80 private:
82 // content::DevToolsFrontendHost::Delegate implementation.
83 void HandleMessageFromDevToolsFrontend(const std::string& message) override;
84 void HandleMessageFromDevToolsFrontendToBackend(
85 const std::string& message) override;
87 // content::DevToolsAgentHostClient implementation.
88 void DispatchProtocolMessage(content::DevToolsAgentHost* agent_host,
89 const std::string& message) override;
90 void AgentHostClosed(content::DevToolsAgentHost* agent_host,
91 bool replaced_with_another_client) override;
93 // DevToolsEmbedderMessageDispatcher::Delegate implementation.
94 void ActivateWindow() override;
95 void CloseWindow() override;
96 void LoadCompleted() override;
97 void SetInspectedPageBounds(const gfx::Rect& rect) override;
98 void InspectElementCompleted() override;
99 void InspectedURLChanged(const std::string& url) override;
100 void LoadNetworkResource(const DispatchCallback& callback,
101 const std::string& url,
102 const std::string& headers,
103 int stream_id) override;
104 void SetIsDocked(const DispatchCallback& callback, bool is_docked) override;
105 void OpenInNewTab(const std::string& url) override;
106 void SaveToFile(const std::string& url,
107 const std::string& content,
108 bool save_as) override;
109 void AppendToFile(const std::string& url,
110 const std::string& content) override;
111 void RequestFileSystems() override;
112 void AddFileSystem() override;
113 void RemoveFileSystem(const std::string& file_system_path) override;
114 void UpgradeDraggedFileSystemPermissions(
115 const std::string& file_system_url) override;
116 void IndexPath(int index_request_id,
117 const std::string& file_system_path) override;
118 void StopIndexing(int index_request_id) override;
119 void SearchInPath(int search_request_id,
120 const std::string& file_system_path,
121 const std::string& query) override;
122 void SetWhitelistedShortcuts(const std::string& message) override;
123 void ZoomIn() override;
124 void ZoomOut() override;
125 void ResetZoom() override;
126 void SetDevicesUpdatesEnabled(bool enabled) override;
127 void SendMessageToBrowser(const std::string& message) override;
128 void RecordEnumeratedHistogram(const std::string& name,
129 int sample,
130 int boundary_value) override;
131 void SendJsonRequest(const DispatchCallback& callback,
132 const std::string& browser_id,
133 const std::string& url) override;
134 void SendFrontendAPINotification(const std::string& message) override;
135 void GetPreferences(const DispatchCallback& callback) override;
136 void SetPreference(const std::string& name,
137 const std::string& value) override;
138 void RemovePreference(const std::string& name) override;
139 void ClearPreferences() override;
141 // net::URLFetcherDelegate overrides.
142 void OnURLFetchComplete(const net::URLFetcher* source) override;
144 void EnableRemoteDeviceCounter(bool enable);
146 void SendMessageAck(int request_id,
147 const base::Value* arg1);
149 // DevToolsAndroidBridge::DeviceCountListener override:
150 void DeviceCountChanged(int count) override;
152 // Forwards discovered devices to frontend.
153 virtual void DevicesUpdated(const std::string& source,
154 const base::ListValue& targets);
156 void DocumentOnLoadCompletedInMainFrame();
157 void DidNavigateMainFrame();
158 void FrontendLoaded();
160 void JsonReceived(const DispatchCallback& callback,
161 int result,
162 const std::string& message);
164 // DevToolsFileHelper callbacks.
165 void FileSavedAs(const std::string& url);
166 void CanceledFileSaveAs(const std::string& url);
167 void AppendedTo(const std::string& url);
168 void FileSystemsLoaded(
169 const std::vector<DevToolsFileHelper::FileSystem>& file_systems);
170 void FileSystemAdded(const DevToolsFileHelper::FileSystem& file_system);
171 void IndexingTotalWorkCalculated(int request_id,
172 const std::string& file_system_path,
173 int total_work);
174 void IndexingWorked(int request_id,
175 const std::string& file_system_path,
176 int worked);
177 void IndexingDone(int request_id, const std::string& file_system_path);
178 void SearchCompleted(int request_id,
179 const std::string& file_system_path,
180 const std::vector<std::string>& file_paths);
181 typedef base::Callback<void(bool)> InfoBarCallback;
182 void ShowDevToolsConfirmInfoBar(const base::string16& message,
183 const InfoBarCallback& callback);
185 // Extensions support.
186 void AddDevToolsExtensionsToClient();
188 class FrontendWebContentsObserver;
189 class WebSocketAPIChannel;
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 scoped_ptr<content::DevToolsFrontendHost> frontend_host_;
198 scoped_ptr<DevToolsFileHelper> file_helper_;
199 scoped_refptr<DevToolsFileSystemIndexer> file_system_indexer_;
200 typedef std::map<
201 int,
202 scoped_refptr<DevToolsFileSystemIndexer::FileSystemIndexingJob> >
203 IndexingJobsMap;
204 IndexingJobsMap indexing_jobs_;
206 bool devices_updates_enabled_;
207 bool frontend_loaded_;
208 scoped_ptr<DevToolsTargetsUIHandler> remote_targets_handler_;
209 scoped_ptr<DevToolsEmbedderMessageDispatcher> embedder_message_dispatcher_;
210 GURL url_;
211 using PendingRequestsMap = std::map<const net::URLFetcher*, DispatchCallback>;
212 PendingRequestsMap pending_requests_;
213 WebSocketAPIChannel* open_api_channel_;
214 base::WeakPtrFactory<DevToolsUIBindings> weak_factory_;
216 DISALLOW_COPY_AND_ASSIGN(DevToolsUIBindings);
219 #endif // CHROME_BROWSER_DEVTOOLS_DEVTOOLS_UI_BINDINGS_H_