Fire an error if a pref used in the UI is missing once all prefs are fetched.
[chromium-blink-merge.git] / chrome / browser / devtools / devtools_ui_bindings.h
blobbd84f680c0c6c782b98084460995ebbfdb4fb5a7
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 "content/public/browser/notification_observer.h"
23 #include "content/public/browser/notification_registrar.h"
24 #include "net/url_request/url_fetcher_delegate.h"
25 #include "ui/gfx/geometry/size.h"
27 class DevToolsAndroidBridge;
28 class InfoBarService;
29 class Profile;
31 namespace content {
32 struct FileChooserParams;
33 class WebContents;
36 // Base implementation of DevTools bindings around front-end.
37 class DevToolsUIBindings : public content::NotificationObserver,
38 public content::DevToolsFrontendHost::Delegate,
39 public DevToolsEmbedderMessageDispatcher::Delegate,
40 public DevToolsAndroidBridge::DeviceCountListener,
41 public content::DevToolsAgentHostClient,
42 public net::URLFetcherDelegate {
43 public:
44 static DevToolsUIBindings* ForWebContents(
45 content::WebContents* web_contents);
46 static GURL ApplyThemeToURL(Profile* profile, const GURL& base_url);
48 class Delegate {
49 public:
50 virtual ~Delegate() {}
51 virtual void ActivateWindow() = 0;
52 virtual void CloseWindow() = 0;
53 virtual void SetInspectedPageBounds(const gfx::Rect& rect) = 0;
54 virtual void InspectElementCompleted() = 0;
55 virtual void SetIsDocked(bool is_docked) = 0;
56 virtual void OpenInNewTab(const std::string& url) = 0;
57 virtual void SetWhitelistedShortcuts(const std::string& message) = 0;
59 virtual void InspectedContentsClosing() = 0;
60 virtual void OnLoadCompleted() = 0;
61 virtual InfoBarService* GetInfoBarService() = 0;
62 virtual void RenderProcessGone(bool crashed) = 0;
65 explicit DevToolsUIBindings(content::WebContents* web_contents);
66 ~DevToolsUIBindings() override;
68 content::WebContents* web_contents() { return web_contents_; }
69 Profile* profile() { return profile_; }
70 content::DevToolsAgentHost* agent_host() { return agent_host_.get(); }
72 // Takes ownership over the |delegate|.
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);
78 void AttachTo(const scoped_refptr<content::DevToolsAgentHost>& agent_host);
79 void Reattach();
80 void Detach();
81 bool IsAttachedTo(content::DevToolsAgentHost* agent_host);
83 private:
84 // content::NotificationObserver overrides.
85 void Observe(int type,
86 const content::NotificationSource& source,
87 const content::NotificationDetails& details) override;
89 // content::DevToolsFrontendHost::Delegate implementation.
90 void HandleMessageFromDevToolsFrontend(const std::string& message) override;
91 void HandleMessageFromDevToolsFrontendToBackend(
92 const std::string& message) override;
94 // content::DevToolsAgentHostClient implementation.
95 void DispatchProtocolMessage(content::DevToolsAgentHost* agent_host,
96 const std::string& message) override;
97 void AgentHostClosed(content::DevToolsAgentHost* agent_host,
98 bool replaced_with_another_client) override;
100 // DevToolsEmbedderMessageDispatcher::Delegate implementation.
101 void ActivateWindow() override;
102 void CloseWindow() override;
103 void LoadCompleted() override;
104 void SetInspectedPageBounds(const gfx::Rect& rect) override;
105 void InspectElementCompleted() override;
106 void InspectedURLChanged(const std::string& url) override;
107 void LoadNetworkResource(const DispatchCallback& callback,
108 const std::string& url,
109 const std::string& headers,
110 int stream_id) override;
111 void SetIsDocked(const DispatchCallback& callback, bool is_docked) override;
112 void OpenInNewTab(const std::string& url) override;
113 void SaveToFile(const std::string& url,
114 const std::string& content,
115 bool save_as) override;
116 void AppendToFile(const std::string& url,
117 const std::string& content) override;
118 void RequestFileSystems() override;
119 void AddFileSystem() override;
120 void RemoveFileSystem(const std::string& file_system_path) override;
121 void UpgradeDraggedFileSystemPermissions(
122 const std::string& file_system_url) override;
123 void IndexPath(int index_request_id,
124 const std::string& file_system_path) override;
125 void StopIndexing(int index_request_id) override;
126 void SearchInPath(int search_request_id,
127 const std::string& file_system_path,
128 const std::string& query) override;
129 void SetWhitelistedShortcuts(const std::string& message) override;
130 void ZoomIn() override;
131 void ZoomOut() override;
132 void ResetZoom() override;
133 void OpenUrlOnRemoteDeviceAndInspect(const std::string& browser_id,
134 const std::string& url) override;
135 void SetDeviceCountUpdatesEnabled(bool enabled) override;
136 void SetDevicesUpdatesEnabled(bool enabled) override;
137 void SendMessageToBrowser(const std::string& message) override;
138 void RecordActionUMA(const std::string& name, int action) override;
139 void SendJsonRequest(const DispatchCallback& callback,
140 const std::string& browser_id,
141 const std::string& url) override;
143 // net::URLFetcherDelegate overrides.
144 void OnURLFetchComplete(const net::URLFetcher* source) override;
146 void EnableRemoteDeviceCounter(bool enable);
148 void SendMessageAck(int request_id,
149 const base::Value* arg1);
151 // DevToolsAndroidBridge::DeviceCountListener override:
152 void DeviceCountChanged(int count) override;
154 // Forwards discovered devices to frontend.
155 virtual void DevicesUpdated(const std::string& source,
156 const base::ListValue& targets);
158 void DocumentOnLoadCompletedInMainFrame();
159 void DidNavigateMainFrame();
160 void FrontendLoaded();
162 void JsonReceived(const DispatchCallback& callback,
163 int result,
164 const std::string& message);
166 // DevToolsFileHelper callbacks.
167 void FileSavedAs(const std::string& url);
168 void CanceledFileSaveAs(const std::string& url);
169 void AppendedTo(const std::string& url);
170 void FileSystemsLoaded(
171 const std::vector<DevToolsFileHelper::FileSystem>& file_systems);
172 void FileSystemAdded(const DevToolsFileHelper::FileSystem& file_system);
173 void IndexingTotalWorkCalculated(int request_id,
174 const std::string& file_system_path,
175 int total_work);
176 void IndexingWorked(int request_id,
177 const std::string& file_system_path,
178 int worked);
179 void IndexingDone(int request_id, const std::string& file_system_path);
180 void SearchCompleted(int request_id,
181 const std::string& file_system_path,
182 const std::vector<std::string>& file_paths);
183 typedef base::Callback<void(bool)> InfoBarCallback;
184 void ShowDevToolsConfirmInfoBar(const base::string16& message,
185 const InfoBarCallback& callback);
187 // Theme and extensions support.
188 void UpdateTheme();
189 void AddDevToolsExtensionsToClient();
191 class FrontendWebContentsObserver;
192 friend class FrontendWebContentsObserver;
193 scoped_ptr<FrontendWebContentsObserver> frontend_contents_observer_;
195 Profile* profile_;
196 DevToolsAndroidBridge* android_bridge_;
197 content::WebContents* web_contents_;
198 scoped_ptr<Delegate> delegate_;
199 scoped_refptr<content::DevToolsAgentHost> agent_host_;
200 content::NotificationRegistrar registrar_;
201 scoped_ptr<content::DevToolsFrontendHost> frontend_host_;
202 scoped_ptr<DevToolsFileHelper> file_helper_;
203 scoped_refptr<DevToolsFileSystemIndexer> file_system_indexer_;
204 typedef std::map<
205 int,
206 scoped_refptr<DevToolsFileSystemIndexer::FileSystemIndexingJob> >
207 IndexingJobsMap;
208 IndexingJobsMap indexing_jobs_;
210 bool device_count_updates_enabled_;
211 bool devices_updates_enabled_;
212 bool frontend_loaded_;
213 scoped_ptr<DevToolsTargetsUIHandler> remote_targets_handler_;
214 scoped_ptr<DevToolsEmbedderMessageDispatcher> embedder_message_dispatcher_;
215 GURL url_;
216 using PendingRequestsMap = std::map<const net::URLFetcher*, DispatchCallback>;
217 PendingRequestsMap pending_requests_;
218 base::WeakPtrFactory<DevToolsUIBindings> weak_factory_;
220 DISALLOW_COPY_AND_ASSIGN(DevToolsUIBindings);
223 #endif // CHROME_BROWSER_DEVTOOLS_DEVTOOLS_UI_BINDINGS_H_