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_delegate.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::DevToolsFrontendHostDelegate,
38 public DevToolsEmbedderMessageDispatcher::Delegate,
39 public DevToolsAndroidBridge::DeviceCountListener {
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 SetContentsInsets(
51 int left, int top, int right, int bottom) = 0;
52 virtual void SetContentsResizingStrategy(
53 const gfx::Insets& insets, const gfx::Size& min_size) = 0;
54 virtual void InspectElementCompleted() = 0;
55 virtual void MoveWindow(int x, int y) = 0;
56 virtual void SetIsDocked(bool is_docked) = 0;
57 virtual void OpenInNewTab(const std::string& url) = 0;
58 virtual void SetWhitelistedShortcuts(const std::string& message) = 0;
60 virtual void InspectedContentsClosing() = 0;
61 virtual void OnLoadCompleted() = 0;
62 virtual InfoBarService* GetInfoBarService() = 0;
63 virtual void RenderProcessGone() = 0;
66 explicit DevToolsUIBindings(content::WebContents* web_contents);
67 virtual ~DevToolsUIBindings();
69 content::WebContents* web_contents() { return web_contents_; }
70 Profile* profile() { return profile_; }
71 content::DevToolsClientHost* frontend_host() { return frontend_host_.get(); }
73 void SetDelegate(Delegate* delegate);
74 void CallClientFunction(const std::string& function_name,
75 const base::Value* arg1,
76 const base::Value* arg2,
77 const base::Value* arg3);
80 // content::NotificationObserver:
81 virtual void Observe(int type,
82 const content::NotificationSource& source,
83 const content::NotificationDetails& details) OVERRIDE;
85 // content::DevToolsFrontendHostDelegate override:
86 virtual void InspectedContentsClosing() OVERRIDE;
87 virtual void DispatchOnEmbedder(const std::string& message) OVERRIDE;
89 // DevToolsEmbedderMessageDispatcher::Delegate overrides:
90 virtual void ActivateWindow() OVERRIDE;
91 virtual void CloseWindow() OVERRIDE;
92 virtual void SetContentsInsets(
93 int left, int top, int right, int bottom) OVERRIDE;
94 virtual void SetContentsResizingStrategy(
95 const gfx::Insets& insets, const gfx::Size& min_size) OVERRIDE;
96 virtual void InspectElementCompleted() OVERRIDE;
97 virtual void InspectedURLChanged(const std::string& url) OVERRIDE;
98 virtual void MoveWindow(int x, int y) OVERRIDE;
99 virtual void SetIsDocked(bool is_docked) OVERRIDE;
100 virtual void OpenInNewTab(const std::string& url) OVERRIDE;
101 virtual void SaveToFile(const std::string& url,
102 const std::string& content,
103 bool save_as) OVERRIDE;
104 virtual void AppendToFile(const std::string& url,
105 const std::string& content) OVERRIDE;
106 virtual void RequestFileSystems() OVERRIDE;
107 virtual void AddFileSystem() OVERRIDE;
108 virtual void RemoveFileSystem(const std::string& file_system_path) OVERRIDE;
109 virtual void UpgradeDraggedFileSystemPermissions(
110 const std::string& file_system_url) OVERRIDE;
111 virtual void IndexPath(int request_id,
112 const std::string& file_system_path) OVERRIDE;
113 virtual void StopIndexing(int request_id) OVERRIDE;
114 virtual void SearchInPath(int request_id,
115 const std::string& file_system_path,
116 const std::string& query) OVERRIDE;
117 virtual void SetWhitelistedShortcuts(const std::string& message) OVERRIDE;
118 virtual void ZoomIn() OVERRIDE;
119 virtual void ZoomOut() OVERRIDE;
120 virtual void ResetZoom() OVERRIDE;
121 virtual void OpenUrlOnRemoteDeviceAndInspect(const std::string& browser_id,
122 const std::string& url) OVERRIDE;
123 virtual void StartRemoteDevicesListener() OVERRIDE;
124 virtual void StopRemoteDevicesListener() OVERRIDE;
125 virtual void EnableRemoteDeviceCounter(bool enable) OVERRIDE;
127 // DevToolsAndroidBridge::DeviceCountListener override:
128 virtual void DeviceCountChanged(int count) OVERRIDE;
130 // Forwards discovered devices to frontend.
131 virtual void PopulateRemoteDevices(const std::string& source,
132 scoped_ptr<base::ListValue> targets);
134 void DocumentOnLoadCompletedInMainFrame();
136 // DevToolsFileHelper callbacks.
137 void FileSavedAs(const std::string& url);
138 void CanceledFileSaveAs(const std::string& url);
139 void AppendedTo(const std::string& url);
140 void FileSystemsLoaded(
141 const std::vector<DevToolsFileHelper::FileSystem>& file_systems);
142 void FileSystemAdded(const DevToolsFileHelper::FileSystem& file_system);
143 void IndexingTotalWorkCalculated(int request_id,
144 const std::string& file_system_path,
146 void IndexingWorked(int request_id,
147 const std::string& file_system_path,
149 void IndexingDone(int request_id, const std::string& file_system_path);
150 void SearchCompleted(int request_id,
151 const std::string& file_system_path,
152 const std::vector<std::string>& file_paths);
153 typedef base::Callback<void(bool)> InfoBarCallback;
154 void ShowDevToolsConfirmInfoBar(const base::string16& message,
155 const InfoBarCallback& callback);
157 // Theme and extensions support.
159 void AddDevToolsExtensionsToClient();
161 class FrontendWebContentsObserver;
162 friend class FrontendWebContentsObserver;
163 scoped_ptr<FrontendWebContentsObserver> frontend_contents_observer_;
166 content::WebContents* web_contents_;
167 scoped_ptr<Delegate> delegate_;
168 bool device_listener_enabled_;
169 content::NotificationRegistrar registrar_;
170 scoped_ptr<content::DevToolsClientHost> 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 scoped_ptr<DevToolsTargetsUIHandler> remote_targets_handler_;
180 scoped_ptr<DevToolsEmbedderMessageDispatcher> embedder_message_dispatcher_;
181 base::WeakPtrFactory<DevToolsUIBindings> weak_factory_;
183 DISALLOW_COPY_AND_ASSIGN(DevToolsUIBindings);
186 #endif // CHROME_BROWSER_DEVTOOLS_DEVTOOLS_UI_BINDINGS_H_