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_client_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/size.h"
30 class DevToolsClientHost;
31 struct FileChooserParams;
35 // Base implementation of DevTools bindings around front-end.
36 class DevToolsUIBindings : public content::NotificationObserver,
37 public content::DevToolsFrontendHost::Delegate,
38 public DevToolsEmbedderMessageDispatcher::Delegate,
39 public DevToolsAndroidBridge::DeviceCountListener,
40 public content::DevToolsClientHost {
42 static GURL ApplyThemeToURL(Profile* profile, const GURL& base_url);
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 MoveWindow(int x, int y) = 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() = 0;
62 DevToolsUIBindings(content::WebContents* web_contents, const GURL& url);
63 virtual ~DevToolsUIBindings();
65 content::WebContents* web_contents() { return web_contents_; }
66 Profile* profile() { return profile_; }
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);
75 // content::NotificationObserver overrides.
76 virtual void Observe(int type,
77 const content::NotificationSource& source,
78 const content::NotificationDetails& details) OVERRIDE;
80 // content::DevToolsFrontendHost::Delegate implementation.
81 virtual void HandleMessageFromDevToolsFrontend(
82 const std::string& message) OVERRIDE;
83 virtual void HandleMessageFromDevToolsFrontendToBackend(
84 const std::string& message) OVERRIDE;
86 // content::DevToolsClientHost implementation.
87 virtual void DispatchOnInspectorFrontend(const std::string& message) OVERRIDE;
88 virtual void InspectedContentsClosing() OVERRIDE;
89 virtual void ReplacedWithAnotherClient() OVERRIDE;
91 // DevToolsEmbedderMessageDispatcher::Delegate implementation.
92 virtual void ActivateWindow() OVERRIDE;
93 virtual void CloseWindow() OVERRIDE;
94 virtual void SetInspectedPageBounds(const gfx::Rect& rect) OVERRIDE;
95 virtual void InspectElementCompleted() OVERRIDE;
96 virtual void InspectedURLChanged(const std::string& url) OVERRIDE;
97 virtual void MoveWindow(int x, int y) OVERRIDE;
98 virtual void SetIsDocked(bool is_docked) OVERRIDE;
99 virtual void OpenInNewTab(const std::string& url) OVERRIDE;
100 virtual void SaveToFile(const std::string& url,
101 const std::string& content,
102 bool save_as) OVERRIDE;
103 virtual void AppendToFile(const std::string& url,
104 const std::string& content) OVERRIDE;
105 virtual void RequestFileSystems() OVERRIDE;
106 virtual void AddFileSystem() OVERRIDE;
107 virtual void RemoveFileSystem(const std::string& file_system_path) OVERRIDE;
108 virtual void UpgradeDraggedFileSystemPermissions(
109 const std::string& file_system_url) OVERRIDE;
110 virtual void IndexPath(int request_id,
111 const std::string& file_system_path) OVERRIDE;
112 virtual void StopIndexing(int request_id) OVERRIDE;
113 virtual void SearchInPath(int request_id,
114 const std::string& file_system_path,
115 const std::string& query) OVERRIDE;
116 virtual void SetWhitelistedShortcuts(const std::string& message) OVERRIDE;
117 virtual void ZoomIn() OVERRIDE;
118 virtual void ZoomOut() OVERRIDE;
119 virtual void ResetZoom() OVERRIDE;
120 virtual void OpenUrlOnRemoteDeviceAndInspect(const std::string& browser_id,
121 const std::string& url) OVERRIDE;
122 virtual void SetDeviceCountUpdatesEnabled(bool enabled) OVERRIDE;
123 virtual void SetDevicesUpdatesEnabled(bool enabled) OVERRIDE;
124 virtual void SendMessageToBrowser(const std::string& message) OVERRIDE;
126 void EnableRemoteDeviceCounter(bool enable);
128 // DevToolsAndroidBridge::DeviceCountListener override:
129 virtual void DeviceCountChanged(int count) OVERRIDE;
131 // Forwards discovered devices to frontend.
132 virtual void DevicesUpdated(const std::string& source,
133 const base::ListValue& targets);
135 void DocumentOnLoadCompletedInMainFrame();
137 // DevToolsFileHelper callbacks.
138 void FileSavedAs(const std::string& url);
139 void CanceledFileSaveAs(const std::string& url);
140 void AppendedTo(const std::string& url);
141 void FileSystemsLoaded(
142 const std::vector<DevToolsFileHelper::FileSystem>& file_systems);
143 void FileSystemAdded(const DevToolsFileHelper::FileSystem& file_system);
144 void IndexingTotalWorkCalculated(int request_id,
145 const std::string& file_system_path,
147 void IndexingWorked(int request_id,
148 const std::string& file_system_path,
150 void IndexingDone(int request_id, const std::string& file_system_path);
151 void SearchCompleted(int request_id,
152 const std::string& file_system_path,
153 const std::vector<std::string>& file_paths);
154 typedef base::Callback<void(bool)> InfoBarCallback;
155 void ShowDevToolsConfirmInfoBar(const base::string16& message,
156 const InfoBarCallback& callback);
158 // Theme and extensions support.
160 void AddDevToolsExtensionsToClient();
162 class FrontendWebContentsObserver;
163 friend class FrontendWebContentsObserver;
164 scoped_ptr<FrontendWebContentsObserver> frontend_contents_observer_;
167 content::WebContents* web_contents_;
168 scoped_ptr<Delegate> delegate_;
169 content::NotificationRegistrar registrar_;
170 scoped_ptr<content::DevToolsFrontendHost> frontend_host_;
171 scoped_ptr<DevToolsFileHelper> file_helper_;
172 scoped_refptr<DevToolsFileSystemIndexer> file_system_indexer_;
175 scoped_refptr<DevToolsFileSystemIndexer::FileSystemIndexingJob> >
177 IndexingJobsMap indexing_jobs_;
179 bool device_count_updates_enabled_;
180 bool devices_updates_enabled_;
181 scoped_ptr<DevToolsTargetsUIHandler> remote_targets_handler_;
182 scoped_ptr<DevToolsEmbedderMessageDispatcher> embedder_message_dispatcher_;
184 base::WeakPtrFactory<DevToolsUIBindings> weak_factory_;
186 DISALLOW_COPY_AND_ASSIGN(DevToolsUIBindings);
189 #endif // CHROME_BROWSER_DEVTOOLS_DEVTOOLS_UI_BINDINGS_H_