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/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 "ui/gfx/geometry/size.h"
30 struct FileChooserParams
;
34 // Base implementation of DevTools bindings around front-end.
35 class DevToolsUIBindings
: public content::NotificationObserver
,
36 public content::DevToolsFrontendHost::Delegate
,
37 public DevToolsEmbedderMessageDispatcher::Delegate
,
38 public DevToolsAndroidBridge::DeviceCountListener
,
39 public content::DevToolsAgentHostClient
{
41 static DevToolsUIBindings
* ForWebContents(
42 content::WebContents
* web_contents
);
43 static GURL
ApplyThemeToURL(Profile
* profile
, const GURL
& base_url
);
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
);
81 // content::NotificationObserver overrides.
82 void Observe(int type
,
83 const content::NotificationSource
& source
,
84 const content::NotificationDetails
& details
) override
;
86 // content::DevToolsFrontendHost::Delegate implementation.
87 void HandleMessageFromDevToolsFrontend(const std::string
& message
) override
;
88 void HandleMessageFromDevToolsFrontendToBackend(
89 const std::string
& message
) override
;
91 // content::DevToolsAgentHostClient implementation.
92 void DispatchProtocolMessage(content::DevToolsAgentHost
* agent_host
,
93 const std::string
& message
) override
;
94 void AgentHostClosed(content::DevToolsAgentHost
* agent_host
,
95 bool replaced_with_another_client
) override
;
97 // DevToolsEmbedderMessageDispatcher::Delegate implementation.
98 void ActivateWindow() override
;
99 void CloseWindow() override
;
100 void LoadCompleted() override
;
101 void SetInspectedPageBounds(const gfx::Rect
& rect
) override
;
102 void InspectElementCompleted() override
;
103 void InspectedURLChanged(const std::string
& url
) override
;
104 void SetIsDocked(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 request_id
, const std::string
& file_system_path
) override
;
117 void StopIndexing(int request_id
) override
;
118 void SearchInPath(int 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 OpenUrlOnRemoteDeviceAndInspect(const std::string
& browser_id
,
126 const std::string
& url
) override
;
127 void SetDeviceCountUpdatesEnabled(bool enabled
) override
;
128 void SetDevicesUpdatesEnabled(bool enabled
) override
;
129 void SendMessageToBrowser(const std::string
& message
) override
;
130 void RecordActionUMA(const std::string
& name
, int action
) override
;
132 void EnableRemoteDeviceCounter(bool enable
);
134 // DevToolsAndroidBridge::DeviceCountListener override:
135 void DeviceCountChanged(int count
) override
;
137 // Forwards discovered devices to frontend.
138 virtual void DevicesUpdated(const std::string
& source
,
139 const base::ListValue
& targets
);
141 void DocumentOnLoadCompletedInMainFrame();
142 void DidNavigateMainFrame();
143 void FrontendLoaded();
145 // DevToolsFileHelper callbacks.
146 void FileSavedAs(const std::string
& url
);
147 void CanceledFileSaveAs(const std::string
& url
);
148 void AppendedTo(const std::string
& url
);
149 void FileSystemsLoaded(
150 const std::vector
<DevToolsFileHelper::FileSystem
>& file_systems
);
151 void FileSystemAdded(const DevToolsFileHelper::FileSystem
& file_system
);
152 void IndexingTotalWorkCalculated(int request_id
,
153 const std::string
& file_system_path
,
155 void IndexingWorked(int request_id
,
156 const std::string
& file_system_path
,
158 void IndexingDone(int request_id
, const std::string
& file_system_path
);
159 void SearchCompleted(int request_id
,
160 const std::string
& file_system_path
,
161 const std::vector
<std::string
>& file_paths
);
162 typedef base::Callback
<void(bool)> InfoBarCallback
;
163 void ShowDevToolsConfirmInfoBar(const base::string16
& message
,
164 const InfoBarCallback
& callback
);
166 // Theme and extensions support.
168 void AddDevToolsExtensionsToClient();
170 class FrontendWebContentsObserver
;
171 friend class FrontendWebContentsObserver
;
172 scoped_ptr
<FrontendWebContentsObserver
> frontend_contents_observer_
;
175 content::WebContents
* web_contents_
;
176 scoped_ptr
<Delegate
> delegate_
;
177 scoped_refptr
<content::DevToolsAgentHost
> agent_host_
;
178 content::NotificationRegistrar registrar_
;
179 scoped_ptr
<content::DevToolsFrontendHost
> frontend_host_
;
180 scoped_ptr
<DevToolsFileHelper
> file_helper_
;
181 scoped_refptr
<DevToolsFileSystemIndexer
> file_system_indexer_
;
184 scoped_refptr
<DevToolsFileSystemIndexer::FileSystemIndexingJob
> >
186 IndexingJobsMap indexing_jobs_
;
188 bool device_count_updates_enabled_
;
189 bool devices_updates_enabled_
;
190 bool frontend_loaded_
;
191 scoped_ptr
<DevToolsTargetsUIHandler
> remote_targets_handler_
;
192 scoped_ptr
<DevToolsEmbedderMessageDispatcher
> embedder_message_dispatcher_
;
194 base::WeakPtrFactory
<DevToolsUIBindings
> weak_factory_
;
196 DISALLOW_COPY_AND_ASSIGN(DevToolsUIBindings
);
199 #endif // CHROME_BROWSER_DEVTOOLS_DEVTOOLS_UI_BINDINGS_H_