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_
11 #include "base/basictypes.h"
12 #include "base/memory/scoped_ptr.h"
13 #include "base/memory/weak_ptr.h"
14 #include "base/prefs/pref_change_registrar.h"
15 #include "base/strings/string16.h"
16 #include "chrome/browser/devtools/device/devtools_android_bridge.h"
17 #include "chrome/browser/devtools/devtools_embedder_message_dispatcher.h"
18 #include "chrome/browser/devtools/devtools_file_helper.h"
19 #include "chrome/browser/devtools/devtools_file_system_indexer.h"
20 #include "chrome/browser/devtools/devtools_targets_ui.h"
21 #include "content/public/browser/devtools_agent_host.h"
22 #include "content/public/browser/devtools_frontend_host.h"
23 #include "net/url_request/url_fetcher_delegate.h"
24 #include "ui/gfx/geometry/size.h"
26 class DevToolsAndroidBridge
;
31 struct FileChooserParams
;
35 // Base implementation of DevTools bindings around front-end.
36 class DevToolsUIBindings
:public content::DevToolsFrontendHost::Delegate
,
37 public DevToolsEmbedderMessageDispatcher::Delegate
,
38 public DevToolsAndroidBridge::DeviceCountListener
,
39 public content::DevToolsAgentHostClient
,
40 public net::URLFetcherDelegate
{
42 static DevToolsUIBindings
* ForWebContents(
43 content::WebContents
* web_contents
);
47 virtual ~Delegate() {}
48 virtual void ActivateWindow() = 0;
49 virtual void CloseWindow() = 0;
50 virtual void SetInspectedPageBounds(const gfx::Rect
& rect
) = 0;
51 virtual void InspectElementCompleted() = 0;
52 virtual void SetIsDocked(bool is_docked
) = 0;
53 virtual void OpenInNewTab(const std::string
& url
) = 0;
54 virtual void SetWhitelistedShortcuts(const std::string
& message
) = 0;
56 virtual void InspectedContentsClosing() = 0;
57 virtual void OnLoadCompleted() = 0;
58 virtual InfoBarService
* GetInfoBarService() = 0;
59 virtual void RenderProcessGone(bool crashed
) = 0;
62 explicit DevToolsUIBindings(content::WebContents
* web_contents
);
63 ~DevToolsUIBindings() override
;
65 content::WebContents
* web_contents() { return web_contents_
; }
66 Profile
* profile() { return profile_
; }
67 content::DevToolsAgentHost
* agent_host() { return agent_host_
.get(); }
69 // Takes ownership over the |delegate|.
70 void SetDelegate(Delegate
* delegate
);
71 void CallClientFunction(const std::string
& function_name
,
72 const base::Value
* arg1
,
73 const base::Value
* arg2
,
74 const base::Value
* arg3
);
75 void AttachTo(const scoped_refptr
<content::DevToolsAgentHost
>& agent_host
);
78 bool IsAttachedTo(content::DevToolsAgentHost
* agent_host
);
79 content::DevToolsExternalAgentProxyDelegate
* CreateWebSocketAPIChannel();
83 // content::DevToolsFrontendHost::Delegate implementation.
84 void HandleMessageFromDevToolsFrontend(const std::string
& message
) override
;
85 void HandleMessageFromDevToolsFrontendToBackend(
86 const std::string
& message
) override
;
88 // content::DevToolsAgentHostClient implementation.
89 void DispatchProtocolMessage(content::DevToolsAgentHost
* agent_host
,
90 const std::string
& message
) override
;
91 void AgentHostClosed(content::DevToolsAgentHost
* agent_host
,
92 bool replaced_with_another_client
) override
;
94 // DevToolsEmbedderMessageDispatcher::Delegate implementation.
95 void ActivateWindow() override
;
96 void CloseWindow() override
;
97 void LoadCompleted() override
;
98 void SetInspectedPageBounds(const gfx::Rect
& rect
) override
;
99 void InspectElementCompleted() override
;
100 void InspectedURLChanged(const std::string
& url
) override
;
101 void LoadNetworkResource(const DispatchCallback
& callback
,
102 const std::string
& url
,
103 const std::string
& headers
,
104 int stream_id
) override
;
105 void SetIsDocked(const DispatchCallback
& callback
, bool is_docked
) override
;
106 void OpenInNewTab(const std::string
& url
) override
;
107 void SaveToFile(const std::string
& url
,
108 const std::string
& content
,
109 bool save_as
) override
;
110 void AppendToFile(const std::string
& url
,
111 const std::string
& content
) override
;
112 void RequestFileSystems() override
;
113 void AddFileSystem() override
;
114 void RemoveFileSystem(const std::string
& file_system_path
) override
;
115 void UpgradeDraggedFileSystemPermissions(
116 const std::string
& file_system_url
) override
;
117 void IndexPath(int index_request_id
,
118 const std::string
& file_system_path
) override
;
119 void StopIndexing(int index_request_id
) override
;
120 void SearchInPath(int search_request_id
,
121 const std::string
& file_system_path
,
122 const std::string
& query
) override
;
123 void SetWhitelistedShortcuts(const std::string
& message
) override
;
124 void ZoomIn() override
;
125 void ZoomOut() override
;
126 void ResetZoom() override
;
127 void SetDevicesDiscoveryConfig(
128 bool discover_usb_devices
,
129 bool port_forwarding_enabled
,
130 const std::string
& port_forwarding_config
) override
;
131 void SetDevicesUpdatesEnabled(bool enabled
) override
;
132 void PerformActionOnRemotePage(const std::string
& page_id
,
133 const std::string
& action
) override
;
134 void SendMessageToBrowser(const std::string
& message
) override
;
135 void RecordEnumeratedHistogram(const std::string
& name
,
137 int boundary_value
) override
;
138 void SendJsonRequest(const DispatchCallback
& callback
,
139 const std::string
& browser_id
,
140 const std::string
& url
) override
;
141 void SendFrontendAPINotification(const std::string
& message
) override
;
142 void GetPreferences(const DispatchCallback
& callback
) override
;
143 void SetPreference(const std::string
& name
,
144 const std::string
& value
) override
;
145 void RemovePreference(const std::string
& name
) override
;
146 void ClearPreferences() override
;
148 // net::URLFetcherDelegate overrides.
149 void OnURLFetchComplete(const net::URLFetcher
* source
) override
;
151 void EnableRemoteDeviceCounter(bool enable
);
153 void SendMessageAck(int request_id
,
154 const base::Value
* arg1
);
156 // DevToolsAndroidBridge::DeviceCountListener override:
157 void DeviceCountChanged(int count
) override
;
159 // Forwards discovered devices to frontend.
160 virtual void DevicesUpdated(const std::string
& source
,
161 const base::ListValue
& targets
);
163 void DocumentOnLoadCompletedInMainFrame();
164 void DidNavigateMainFrame();
165 void FrontendLoaded();
167 void JsonReceived(const DispatchCallback
& callback
,
169 const std::string
& message
);
170 void DevicesDiscoveryConfigUpdated();
172 // DevToolsFileHelper callbacks.
173 void FileSavedAs(const std::string
& url
);
174 void CanceledFileSaveAs(const std::string
& url
);
175 void AppendedTo(const std::string
& url
);
176 void FileSystemsLoaded(
177 const std::vector
<DevToolsFileHelper::FileSystem
>& file_systems
);
178 void FileSystemAdded(const DevToolsFileHelper::FileSystem
& file_system
);
179 void IndexingTotalWorkCalculated(int request_id
,
180 const std::string
& file_system_path
,
182 void IndexingWorked(int request_id
,
183 const std::string
& file_system_path
,
185 void IndexingDone(int request_id
, const std::string
& file_system_path
);
186 void SearchCompleted(int request_id
,
187 const std::string
& file_system_path
,
188 const std::vector
<std::string
>& file_paths
);
189 typedef base::Callback
<void(bool)> InfoBarCallback
;
190 void ShowDevToolsConfirmInfoBar(const base::string16
& message
,
191 const InfoBarCallback
& callback
);
193 // Extensions support.
194 void AddDevToolsExtensionsToClient();
196 class FrontendWebContentsObserver
;
197 class WebSocketAPIChannel
;
198 scoped_ptr
<FrontendWebContentsObserver
> frontend_contents_observer_
;
201 DevToolsAndroidBridge
* android_bridge_
;
202 content::WebContents
* web_contents_
;
203 scoped_ptr
<Delegate
> delegate_
;
204 scoped_refptr
<content::DevToolsAgentHost
> agent_host_
;
205 scoped_ptr
<content::DevToolsFrontendHost
> frontend_host_
;
206 scoped_ptr
<DevToolsFileHelper
> file_helper_
;
207 scoped_refptr
<DevToolsFileSystemIndexer
> file_system_indexer_
;
210 scoped_refptr
<DevToolsFileSystemIndexer::FileSystemIndexingJob
> >
212 IndexingJobsMap indexing_jobs_
;
214 bool devices_updates_enabled_
;
215 bool frontend_loaded_
;
216 scoped_ptr
<DevToolsTargetsUIHandler
> remote_targets_handler_
;
217 PrefChangeRegistrar pref_change_registrar_
;
218 scoped_ptr
<DevToolsEmbedderMessageDispatcher
> embedder_message_dispatcher_
;
220 using PendingRequestsMap
= std::map
<const net::URLFetcher
*, DispatchCallback
>;
221 PendingRequestsMap pending_requests_
;
222 WebSocketAPIChannel
* open_api_channel_
;
223 base::WeakPtrFactory
<DevToolsUIBindings
> weak_factory_
;
225 DISALLOW_COPY_AND_ASSIGN(DevToolsUIBindings
);
228 #endif // CHROME_BROWSER_DEVTOOLS_DEVTOOLS_UI_BINDINGS_H_