OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef CHROME_BROWSER_DEVTOOLS_DEVTOOLS_WINDOW_H_ | 5 #ifndef CHROME_BROWSER_DEVTOOLS_DEVTOOLS_WINDOW_H_ |
6 #define CHROME_BROWSER_DEVTOOLS_DEVTOOLS_WINDOW_H_ | 6 #define CHROME_BROWSER_DEVTOOLS_DEVTOOLS_WINDOW_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
42 } | 42 } |
43 | 43 |
44 namespace IPC { | 44 namespace IPC { |
45 class Message; | 45 class Message; |
46 } | 46 } |
47 | 47 |
48 namespace user_prefs { | 48 namespace user_prefs { |
49 class PrefRegistrySyncable; | 49 class PrefRegistrySyncable; |
50 } | 50 } |
51 | 51 |
52 enum DevToolsDockSide { | |
53 DEVTOOLS_DOCK_SIDE_UNDOCKED = 0, | |
54 DEVTOOLS_DOCK_SIDE_BOTTOM, | |
55 DEVTOOLS_DOCK_SIDE_RIGHT, | |
56 DEVTOOLS_DOCK_SIDE_MINIMIZED | |
57 }; | |
58 | |
59 class DevToolsWindow : private content::NotificationObserver, | 52 class DevToolsWindow : private content::NotificationObserver, |
60 private content::WebContentsDelegate, | 53 private content::WebContentsDelegate, |
61 private content::DevToolsFrontendHostDelegate, | 54 private content::DevToolsFrontendHostDelegate, |
62 private DevToolsEmbedderMessageDispatcher::Delegate { | 55 private DevToolsEmbedderMessageDispatcher::Delegate { |
63 public: | 56 public: |
64 typedef base::Callback<void(bool)> InfoBarCallback; | 57 typedef base::Callback<void(bool)> InfoBarCallback; |
65 | 58 |
66 static const char kDevToolsApp[]; | 59 static const char kDevToolsApp[]; |
67 | 60 |
68 virtual ~DevToolsWindow(); | 61 virtual ~DevToolsWindow(); |
69 | 62 |
70 static std::string GetDevToolsWindowPlacementPrefKey(); | 63 static std::string GetDevToolsWindowPlacementPrefKey(); |
71 static void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry); | 64 static void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry); |
65 | |
72 // Return the DevToolsWindow for the given RenderViewHost if one exists, | 66 // Return the DevToolsWindow for the given RenderViewHost if one exists, |
73 // otherwise NULL. | 67 // otherwise NULL. |
74 static DevToolsWindow* GetInstanceForInspectedRenderViewHost( | 68 static DevToolsWindow* GetInstanceForInspectedRenderViewHost( |
75 content::RenderViewHost* inspected_rvh); | 69 content::RenderViewHost* inspected_rvh); |
70 | |
71 // Return the DevToolsWindow for the given WebContents if one exists and is | |
72 // docked, otherwise NULL. | |
76 static DevToolsWindow* GetDockedInstanceForInspectedTab( | 73 static DevToolsWindow* GetDockedInstanceForInspectedTab( |
77 content::WebContents* inspected_tab); | 74 content::WebContents* inspected_tab); |
75 | |
78 static bool IsDevToolsWindow(content::RenderViewHost* window_rvh); | 76 static bool IsDevToolsWindow(content::RenderViewHost* window_rvh); |
77 | |
79 static DevToolsWindow* OpenDevToolsWindowForWorker( | 78 static DevToolsWindow* OpenDevToolsWindowForWorker( |
80 Profile* profile, | 79 Profile* profile, |
81 content::DevToolsAgentHost* worker_agent); | 80 content::DevToolsAgentHost* worker_agent); |
82 static DevToolsWindow* CreateDevToolsWindowForWorker(Profile* profile); | 81 |
82 // Open or focus existing DevTools window, and perform the specified action. | |
pfeldman
2014/01/09 12:52:01
Open or reveal DevTools window
dgozman
2014/01/14 15:26:17
Done.
| |
83 static DevToolsWindow* OpenDevToolsWindow( | |
84 content::RenderViewHost* inspected_rvh, | |
85 const DevToolsToggleAction& action); | |
86 | |
87 // Open or focus existing DevTools window, with no special action. | |
83 static DevToolsWindow* OpenDevToolsWindow( | 88 static DevToolsWindow* OpenDevToolsWindow( |
84 content::RenderViewHost* inspected_rvh); | 89 content::RenderViewHost* inspected_rvh); |
90 | |
91 // Perform specified action for current WebContents inside a |browser|. | |
92 // This may close currently open DevTools window. | |
85 static DevToolsWindow* ToggleDevToolsWindow( | 93 static DevToolsWindow* ToggleDevToolsWindow( |
86 Browser* browser, | 94 Browser* browser, |
87 const DevToolsToggleAction& action); | 95 const DevToolsToggleAction& action); |
88 static void OpenExternalFrontend(Profile* profile, | |
89 const std::string& frontend_uri, | |
90 content::DevToolsAgentHost* agent_host); | |
91 | 96 |
92 // Exposed for testing, normal clients should not use this method. | 97 static void OpenExternalFrontend( |
93 static DevToolsWindow* ToggleDevToolsWindow( | 98 Profile* profile, |
94 content::RenderViewHost* inspected_rvh, | 99 const std::string& frontend_uri, |
95 bool force_open, | 100 content::DevToolsAgentHost* agent_host); |
96 const DevToolsToggleAction& action); | |
97 | 101 |
98 static void InspectElement( | 102 static void InspectElement( |
99 content::RenderViewHost* inspected_rvh, int x, int y); | 103 content::RenderViewHost* inspected_rvh, int x, int y); |
100 | 104 |
101 static int GetMinimizedHeight(); | 105 static int GetMinimizedHeight(); |
102 | 106 |
103 // content::DevToolsFrontendHostDelegate: | 107 // content::DevToolsFrontendHostDelegate: |
104 virtual void InspectedContentsClosing() OVERRIDE; | 108 virtual void InspectedContentsClosing() OVERRIDE; |
105 | 109 |
106 content::WebContents* web_contents() { return web_contents_; } | 110 content::WebContents* web_contents() { return web_contents_; } |
107 Browser* browser() { return browser_; } // For tests. | 111 Browser* browser() { return browser_; } // For tests. |
108 DevToolsDockSide dock_side() const { return dock_side_; } | |
109 | 112 |
110 content::RenderViewHost* GetRenderViewHost(); | 113 content::RenderViewHost* GetRenderViewHost(); |
111 content::DevToolsClientHost* GetDevToolsClientHostForTest(); | |
112 | 114 |
113 // Inspected WebContents is placed over DevTools WebContents in docked mode. | 115 // Inspected WebContents is placed over DevTools WebContents in docked mode. |
114 // The following methods return the insets of inspected WebContents | 116 // The following methods return the insets of inspected WebContents |
115 // relative to DevTools WebContents. | 117 // relative to DevTools WebContents. |
116 gfx::Insets GetContentsInsets() const; | 118 gfx::Insets GetContentsInsets() const; |
117 | 119 |
118 // Minimum size of the docked DevTools WebContents. This includes | 120 // Minimum size of the docked DevTools WebContents. This includes |
119 // the overlaying inspected WebContents size. | 121 // the overlaying inspected WebContents size. |
120 gfx::Size GetMinimumSize() const; | 122 gfx::Size GetMinimumSize() const; |
121 | 123 |
122 void Show(const DevToolsToggleAction& action); | |
123 | |
124 // BeforeUnload interception //////////////////////////////////////////////// | 124 // BeforeUnload interception //////////////////////////////////////////////// |
125 | 125 |
126 // In order to preserve any edits the user may have made in devtools, the | 126 // In order to preserve any edits the user may have made in devtools, the |
127 // beforeunload event of the inspected page is hooked - devtools gets the | 127 // beforeunload event of the inspected page is hooked - devtools gets the |
128 // first shot at handling beforeunload and presents a dialog to the user. If | 128 // first shot at handling beforeunload and presents a dialog to the user. If |
129 // the user accepts the dialog then the script is given a chance to handle | 129 // the user accepts the dialog then the script is given a chance to handle |
130 // it. This way 2 dialogs may be displayed: one from the devtools asking the | 130 // it. This way 2 dialogs may be displayed: one from the devtools asking the |
131 // user to confirm that they're ok with their devtools edits going away and | 131 // user to confirm that they're ok with their devtools edits going away and |
132 // another from the webpage as the result of its beforeunload handler. | 132 // another from the webpage as the result of its beforeunload handler. |
133 // The following set of methods handle beforeunload event flow through | 133 // The following set of methods handle beforeunload event flow through |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
188 static bool HasFiredBeforeUnloadEventForDevToolsBrowser(Browser* browser); | 188 static bool HasFiredBeforeUnloadEventForDevToolsBrowser(Browser* browser); |
189 | 189 |
190 // Returns true if devtools window would like to hook beforeunload event | 190 // Returns true if devtools window would like to hook beforeunload event |
191 // of this |contents|. | 191 // of this |contents|. |
192 static bool NeedsToInterceptBeforeUnload(content::WebContents* contents); | 192 static bool NeedsToInterceptBeforeUnload(content::WebContents* contents); |
193 | 193 |
194 // Notify devtools window that closing of |contents| was cancelled | 194 // Notify devtools window that closing of |contents| was cancelled |
195 // by user. | 195 // by user. |
196 static void OnPageCloseCanceled(content::WebContents* contents); | 196 static void OnPageCloseCanceled(content::WebContents* contents); |
197 | 197 |
198 void SetDockSideForTest(DevToolsDockSide dock_side); | 198 void SetIsDockedAndShowImmediatelyForTest(bool is_docked); |
199 | 199 |
200 private: | 200 private: |
201 friend class DevToolsControllerTest; | 201 friend class DevToolsControllerTest; |
202 friend class DevToolsSanityTest; | |
202 friend class BrowserWindowControllerTest; | 203 friend class BrowserWindowControllerTest; |
203 | 204 |
205 enum LoadState { | |
206 kNotLoaded = 0, | |
207 kOnLoadFired = 1 << 0, | |
208 kIsDockedSet = 1 << 1, | |
209 kLoadCompleted = kOnLoadFired | kIsDockedSet | |
210 }; | |
211 typedef int LoadStateMask; | |
pfeldman
2014/01/09 12:52:01
nuke
dgozman
2014/01/14 15:26:17
Done.
| |
212 | |
204 DevToolsWindow(Profile* profile, | 213 DevToolsWindow(Profile* profile, |
205 const GURL& frontend_url, | 214 const GURL& frontend_url, |
206 content::RenderViewHost* inspected_rvh, | 215 content::RenderViewHost* inspected_rvh, |
207 DevToolsDockSide dock_side); | 216 bool can_dock); |
208 | 217 |
209 static DevToolsWindow* Create(Profile* profile, | 218 static DevToolsWindow* Create(Profile* profile, |
210 const GURL& frontend_url, | 219 const GURL& frontend_url, |
211 content::RenderViewHost* inspected_rvh, | 220 content::RenderViewHost* inspected_rvh, |
212 DevToolsDockSide dock_side, | |
213 bool shared_worker_frontend, | 221 bool shared_worker_frontend, |
214 bool external_frontend, | 222 bool external_frontend, |
215 bool can_dock); | 223 bool can_dock); |
216 static GURL GetDevToolsURL(Profile* profile, | 224 static GURL GetDevToolsURL(Profile* profile, |
217 const GURL& base_url, | 225 const GURL& base_url, |
218 DevToolsDockSide dock_side, | |
219 bool shared_worker_frontend, | 226 bool shared_worker_frontend, |
220 bool external_frontend, | 227 bool external_frontend, |
221 bool can_dock); | 228 bool can_dock); |
222 static DevToolsWindow* FindDevToolsWindow(content::DevToolsAgentHost*); | 229 static DevToolsWindow* FindDevToolsWindow(content::DevToolsAgentHost*); |
223 static DevToolsWindow* AsDevToolsWindow(content::RenderViewHost*); | 230 static DevToolsWindow* AsDevToolsWindow(content::RenderViewHost*); |
224 static DevToolsDockSide GetDockSideFromPrefs(Profile* profile); | 231 static DevToolsWindow* CreateDevToolsWindowForWorker(Profile* profile); |
225 static std::string SideToString(DevToolsDockSide dock_side); | 232 static bool IsDockedFromString(const std::string& dock_side); |
226 static DevToolsDockSide SideFromString(const std::string& dock_side); | |
227 static bool FindInspectedBrowserAndTabIndex( | 233 static bool FindInspectedBrowserAndTabIndex( |
228 content::WebContents* inspected_web_contents, Browser**, int* tab); | 234 content::WebContents* inspected_web_contents, Browser**, int* tab); |
235 static DevToolsWindow* ToggleDevToolsWindow( | |
236 content::RenderViewHost* inspected_rvh, | |
237 bool force_open, | |
238 const DevToolsToggleAction& action); | |
229 | 239 |
230 // content::NotificationObserver: | 240 // content::NotificationObserver: |
231 virtual void Observe(int type, | 241 virtual void Observe(int type, |
232 const content::NotificationSource& source, | 242 const content::NotificationSource& source, |
233 const content::NotificationDetails& details) OVERRIDE; | 243 const content::NotificationDetails& details) OVERRIDE; |
234 | 244 |
235 // content::WebContentsDelegate: | 245 // content::WebContentsDelegate: |
236 virtual content::WebContents* OpenURLFromTab( | 246 virtual content::WebContents* OpenURLFromTab( |
237 content::WebContents* source, | 247 content::WebContents* source, |
238 const content::OpenURLParams& params) OVERRIDE; | 248 const content::OpenURLParams& params) OVERRIDE; |
(...skipping 29 matching lines...) Expand all Loading... | |
268 virtual void DispatchOnEmbedder(const std::string& message) OVERRIDE; | 278 virtual void DispatchOnEmbedder(const std::string& message) OVERRIDE; |
269 | 279 |
270 // DevToolsEmbedderMessageDispatcher::Delegate overrides: | 280 // DevToolsEmbedderMessageDispatcher::Delegate overrides: |
271 virtual void ActivateWindow() OVERRIDE; | 281 virtual void ActivateWindow() OVERRIDE; |
272 virtual void ActivateContents(content::WebContents* contents) OVERRIDE; | 282 virtual void ActivateContents(content::WebContents* contents) OVERRIDE; |
273 virtual void CloseWindow() OVERRIDE; | 283 virtual void CloseWindow() OVERRIDE; |
274 virtual void SetContentsInsets( | 284 virtual void SetContentsInsets( |
275 int left, int top, int right, int bottom) OVERRIDE; | 285 int left, int top, int right, int bottom) OVERRIDE; |
276 virtual void MoveWindow(int x, int y) OVERRIDE; | 286 virtual void MoveWindow(int x, int y) OVERRIDE; |
277 virtual void SetDockSide(const std::string& side) OVERRIDE; | 287 virtual void SetDockSide(const std::string& side) OVERRIDE; |
288 virtual void SetIsDocked(bool is_docked) OVERRIDE; | |
278 virtual void OpenInNewTab(const std::string& url) OVERRIDE; | 289 virtual void OpenInNewTab(const std::string& url) OVERRIDE; |
279 virtual void SaveToFile(const std::string& url, | 290 virtual void SaveToFile(const std::string& url, |
280 const std::string& content, | 291 const std::string& content, |
281 bool save_as) OVERRIDE; | 292 bool save_as) OVERRIDE; |
282 virtual void AppendToFile(const std::string& url, | 293 virtual void AppendToFile(const std::string& url, |
283 const std::string& content) OVERRIDE; | 294 const std::string& content) OVERRIDE; |
284 virtual void RequestFileSystems() OVERRIDE; | 295 virtual void RequestFileSystems() OVERRIDE; |
285 virtual void AddFileSystem() OVERRIDE; | 296 virtual void AddFileSystem() OVERRIDE; |
286 virtual void RemoveFileSystem(const std::string& file_system_path) OVERRIDE; | 297 virtual void RemoveFileSystem(const std::string& file_system_path) OVERRIDE; |
287 virtual void UpgradeDraggedFileSystemPermissions( | 298 virtual void UpgradeDraggedFileSystemPermissions( |
(...skipping 20 matching lines...) Expand all Loading... | |
308 int worked); | 319 int worked); |
309 void IndexingDone(int request_id, const std::string& file_system_path); | 320 void IndexingDone(int request_id, const std::string& file_system_path); |
310 void SearchCompleted(int request_id, | 321 void SearchCompleted(int request_id, |
311 const std::string& file_system_path, | 322 const std::string& file_system_path, |
312 const std::vector<std::string>& file_paths); | 323 const std::vector<std::string>& file_paths); |
313 void ShowDevToolsConfirmInfoBar(const base::string16& message, | 324 void ShowDevToolsConfirmInfoBar(const base::string16& message, |
314 const InfoBarCallback& callback); | 325 const InfoBarCallback& callback); |
315 | 326 |
316 void CreateDevToolsBrowser(); | 327 void CreateDevToolsBrowser(); |
317 BrowserWindow* GetInspectedBrowserWindow(); | 328 BrowserWindow* GetInspectedBrowserWindow(); |
318 bool IsInspectedBrowserPopup(); | 329 void ScheduleShow(const DevToolsToggleAction& action); |
319 void UpdateFrontendDockSide(); | 330 void Show(const DevToolsToggleAction& action); |
320 void ScheduleAction(const DevToolsToggleAction& action); | 331 void DoAction(const DevToolsToggleAction& action); |
321 void DoAction(); | 332 void LoadCompleted(); |
322 void UpdateTheme(); | 333 void UpdateTheme(); |
323 void AddDevToolsExtensionsToClient(); | 334 void AddDevToolsExtensionsToClient(); |
324 void CallClientFunction(const std::string& function_name, | 335 void CallClientFunction(const std::string& function_name, |
325 const base::Value* arg1, | 336 const base::Value* arg1, |
326 const base::Value* arg2, | 337 const base::Value* arg2, |
327 const base::Value* arg3); | 338 const base::Value* arg3); |
328 void UpdateBrowserToolbar(); | 339 void UpdateBrowserToolbar(); |
329 bool IsDocked(); | |
330 void Restore(); | |
331 content::WebContents* GetInspectedWebContents(); | 340 content::WebContents* GetInspectedWebContents(); |
332 void DocumentOnLoadCompletedInMainFrame(); | 341 void DocumentOnLoadCompletedInMainFrame(); |
333 | 342 |
334 class InspectedWebContentsObserver; | 343 class InspectedWebContentsObserver; |
335 scoped_ptr<InspectedWebContentsObserver> inspected_contents_observer_; | 344 scoped_ptr<InspectedWebContentsObserver> inspected_contents_observer_; |
336 class FrontendWebContentsObserver; | 345 class FrontendWebContentsObserver; |
337 friend class FrontendWebContentsObserver; | 346 friend class FrontendWebContentsObserver; |
338 scoped_ptr<FrontendWebContentsObserver> frontend_contents_observer_; | 347 scoped_ptr<FrontendWebContentsObserver> frontend_contents_observer_; |
339 | 348 |
340 Profile* profile_; | 349 Profile* profile_; |
341 content::WebContents* web_contents_; | 350 content::WebContents* web_contents_; |
342 Browser* browser_; | 351 Browser* browser_; |
343 // TODO(dgozman): move dock side knowledge entirely to frontend. | 352 bool is_docked_; |
344 DevToolsDockSide dock_side_; | 353 bool can_dock_; |
345 bool is_loaded_; | 354 LoadStateMask load_state_mask_; |
pfeldman
2014/01/09 12:52:01
LoadState
dgozman
2014/01/14 15:26:17
Done.
| |
346 DevToolsToggleAction action_on_load_; | 355 DevToolsToggleAction action_on_load_; |
356 bool set_is_docked_for_test_on_load_; | |
347 content::NotificationRegistrar registrar_; | 357 content::NotificationRegistrar registrar_; |
348 scoped_ptr<content::DevToolsClientHost> frontend_host_; | 358 scoped_ptr<content::DevToolsClientHost> frontend_host_; |
349 scoped_ptr<DevToolsFileHelper> file_helper_; | 359 scoped_ptr<DevToolsFileHelper> file_helper_; |
350 scoped_refptr<DevToolsFileSystemIndexer> file_system_indexer_; | 360 scoped_refptr<DevToolsFileSystemIndexer> file_system_indexer_; |
351 typedef std::map< | 361 typedef std::map< |
352 int, | 362 int, |
353 scoped_refptr<DevToolsFileSystemIndexer::FileSystemIndexingJob> > | 363 scoped_refptr<DevToolsFileSystemIndexer::FileSystemIndexingJob> > |
354 IndexingJobsMap; | 364 IndexingJobsMap; |
355 IndexingJobsMap indexing_jobs_; | 365 IndexingJobsMap indexing_jobs_; |
356 gfx::Insets contents_insets_; | 366 gfx::Insets contents_insets_; |
357 DevToolsDockSide dock_side_before_minimized_; | |
358 // True if we're in the process of handling a beforeunload event originating | 367 // True if we're in the process of handling a beforeunload event originating |
359 // from the inspected webcontents, see InterceptPageBeforeUnload for details. | 368 // from the inspected webcontents, see InterceptPageBeforeUnload for details. |
360 bool intercepted_page_beforeunload_; | 369 bool intercepted_page_beforeunload_; |
361 | 370 |
362 scoped_ptr<DevToolsEmbedderMessageDispatcher> embedder_message_dispatcher_; | 371 scoped_ptr<DevToolsEmbedderMessageDispatcher> embedder_message_dispatcher_; |
363 base::WeakPtrFactory<DevToolsWindow> weak_factory_; | 372 base::WeakPtrFactory<DevToolsWindow> weak_factory_; |
364 DISALLOW_COPY_AND_ASSIGN(DevToolsWindow); | 373 DISALLOW_COPY_AND_ASSIGN(DevToolsWindow); |
365 }; | 374 }; |
366 | 375 |
367 #endif // CHROME_BROWSER_DEVTOOLS_DEVTOOLS_WINDOW_H_ | 376 #endif // CHROME_BROWSER_DEVTOOLS_DEVTOOLS_WINDOW_H_ |
OLD | NEW |