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. |
| 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 SetIsDockedForTest(bool is_docked); |
| 199 |
| 200 // Use with care. DevTools frontend page may be disfunctional after this call. |
| 201 void SetIsDockedAndShowImmediatelyForTest(bool is_docked); |
199 | 202 |
200 private: | 203 private: |
201 friend class DevToolsControllerTest; | 204 friend class DevToolsControllerTest; |
| 205 friend class DevToolsSanityTest; |
202 friend class BrowserWindowControllerTest; | 206 friend class BrowserWindowControllerTest; |
203 | 207 |
| 208 enum LoadState { |
| 209 kNotLoaded = 0, |
| 210 kOnLoadFired = 1 << 0, |
| 211 kIsDockedSet = 1 << 1, |
| 212 kLoadCompleted = kOnLoadFired | kIsDockedSet |
| 213 }; |
| 214 typedef int LoadStateMask; |
| 215 |
204 DevToolsWindow(Profile* profile, | 216 DevToolsWindow(Profile* profile, |
205 const GURL& frontend_url, | 217 const GURL& frontend_url, |
206 content::RenderViewHost* inspected_rvh, | 218 content::RenderViewHost* inspected_rvh, |
207 DevToolsDockSide dock_side); | 219 bool can_dock); |
208 | 220 |
209 static DevToolsWindow* Create(Profile* profile, | 221 static DevToolsWindow* Create(Profile* profile, |
210 const GURL& frontend_url, | 222 const GURL& frontend_url, |
211 content::RenderViewHost* inspected_rvh, | 223 content::RenderViewHost* inspected_rvh, |
212 DevToolsDockSide dock_side, | |
213 bool shared_worker_frontend, | 224 bool shared_worker_frontend, |
214 bool external_frontend, | 225 bool external_frontend, |
215 bool can_dock); | 226 bool can_dock); |
216 static GURL GetDevToolsURL(Profile* profile, | 227 static GURL GetDevToolsURL(Profile* profile, |
217 const GURL& base_url, | 228 const GURL& base_url, |
218 DevToolsDockSide dock_side, | |
219 bool shared_worker_frontend, | 229 bool shared_worker_frontend, |
220 bool external_frontend, | 230 bool external_frontend, |
221 bool can_dock); | 231 bool can_dock); |
222 static DevToolsWindow* FindDevToolsWindow(content::DevToolsAgentHost*); | 232 static DevToolsWindow* FindDevToolsWindow(content::DevToolsAgentHost*); |
223 static DevToolsWindow* AsDevToolsWindow(content::RenderViewHost*); | 233 static DevToolsWindow* AsDevToolsWindow(content::RenderViewHost*); |
224 static DevToolsDockSide GetDockSideFromPrefs(Profile* profile); | 234 static DevToolsWindow* CreateDevToolsWindowForWorker(Profile* profile); |
225 static std::string SideToString(DevToolsDockSide dock_side); | 235 static bool IsDockedFromString(const std::string& dock_side); |
226 static DevToolsDockSide SideFromString(const std::string& dock_side); | |
227 static bool FindInspectedBrowserAndTabIndex( | 236 static bool FindInspectedBrowserAndTabIndex( |
228 content::WebContents* inspected_web_contents, Browser**, int* tab); | 237 content::WebContents* inspected_web_contents, Browser**, int* tab); |
| 238 static DevToolsWindow* ToggleDevToolsWindow( |
| 239 content::RenderViewHost* inspected_rvh, |
| 240 bool force_open, |
| 241 const DevToolsToggleAction& action); |
229 | 242 |
230 // content::NotificationObserver: | 243 // content::NotificationObserver: |
231 virtual void Observe(int type, | 244 virtual void Observe(int type, |
232 const content::NotificationSource& source, | 245 const content::NotificationSource& source, |
233 const content::NotificationDetails& details) OVERRIDE; | 246 const content::NotificationDetails& details) OVERRIDE; |
234 | 247 |
235 // content::WebContentsDelegate: | 248 // content::WebContentsDelegate: |
236 virtual content::WebContents* OpenURLFromTab( | 249 virtual content::WebContents* OpenURLFromTab( |
237 content::WebContents* source, | 250 content::WebContents* source, |
238 const content::OpenURLParams& params) OVERRIDE; | 251 const content::OpenURLParams& params) OVERRIDE; |
(...skipping 29 matching lines...) Expand all Loading... |
268 virtual void DispatchOnEmbedder(const std::string& message) OVERRIDE; | 281 virtual void DispatchOnEmbedder(const std::string& message) OVERRIDE; |
269 | 282 |
270 // DevToolsEmbedderMessageDispatcher::Delegate overrides: | 283 // DevToolsEmbedderMessageDispatcher::Delegate overrides: |
271 virtual void ActivateWindow() OVERRIDE; | 284 virtual void ActivateWindow() OVERRIDE; |
272 virtual void ActivateContents(content::WebContents* contents) OVERRIDE; | 285 virtual void ActivateContents(content::WebContents* contents) OVERRIDE; |
273 virtual void CloseWindow() OVERRIDE; | 286 virtual void CloseWindow() OVERRIDE; |
274 virtual void SetContentsInsets( | 287 virtual void SetContentsInsets( |
275 int left, int top, int right, int bottom) OVERRIDE; | 288 int left, int top, int right, int bottom) OVERRIDE; |
276 virtual void MoveWindow(int x, int y) OVERRIDE; | 289 virtual void MoveWindow(int x, int y) OVERRIDE; |
277 virtual void SetDockSide(const std::string& side) OVERRIDE; | 290 virtual void SetDockSide(const std::string& side) OVERRIDE; |
| 291 virtual void SetIsDocked(bool is_docked) OVERRIDE; |
278 virtual void OpenInNewTab(const std::string& url) OVERRIDE; | 292 virtual void OpenInNewTab(const std::string& url) OVERRIDE; |
279 virtual void SaveToFile(const std::string& url, | 293 virtual void SaveToFile(const std::string& url, |
280 const std::string& content, | 294 const std::string& content, |
281 bool save_as) OVERRIDE; | 295 bool save_as) OVERRIDE; |
282 virtual void AppendToFile(const std::string& url, | 296 virtual void AppendToFile(const std::string& url, |
283 const std::string& content) OVERRIDE; | 297 const std::string& content) OVERRIDE; |
284 virtual void RequestFileSystems() OVERRIDE; | 298 virtual void RequestFileSystems() OVERRIDE; |
285 virtual void AddFileSystem() OVERRIDE; | 299 virtual void AddFileSystem() OVERRIDE; |
286 virtual void RemoveFileSystem(const std::string& file_system_path) OVERRIDE; | 300 virtual void RemoveFileSystem(const std::string& file_system_path) OVERRIDE; |
287 virtual void UpgradeDraggedFileSystemPermissions( | 301 virtual void UpgradeDraggedFileSystemPermissions( |
(...skipping 20 matching lines...) Expand all Loading... |
308 int worked); | 322 int worked); |
309 void IndexingDone(int request_id, const std::string& file_system_path); | 323 void IndexingDone(int request_id, const std::string& file_system_path); |
310 void SearchCompleted(int request_id, | 324 void SearchCompleted(int request_id, |
311 const std::string& file_system_path, | 325 const std::string& file_system_path, |
312 const std::vector<std::string>& file_paths); | 326 const std::vector<std::string>& file_paths); |
313 void ShowDevToolsConfirmInfoBar(const base::string16& message, | 327 void ShowDevToolsConfirmInfoBar(const base::string16& message, |
314 const InfoBarCallback& callback); | 328 const InfoBarCallback& callback); |
315 | 329 |
316 void CreateDevToolsBrowser(); | 330 void CreateDevToolsBrowser(); |
317 BrowserWindow* GetInspectedBrowserWindow(); | 331 BrowserWindow* GetInspectedBrowserWindow(); |
318 bool IsInspectedBrowserPopup(); | 332 void ScheduleShow(const DevToolsToggleAction& action); |
319 void UpdateFrontendDockSide(); | 333 void Show(const DevToolsToggleAction& action); |
320 void ScheduleAction(const DevToolsToggleAction& action); | 334 void DoAction(const DevToolsToggleAction& action); |
321 void DoAction(); | 335 void LoadCompleted(); |
322 void UpdateTheme(); | 336 void UpdateTheme(); |
323 void AddDevToolsExtensionsToClient(); | 337 void AddDevToolsExtensionsToClient(); |
324 void CallClientFunction(const std::string& function_name, | 338 void CallClientFunction(const std::string& function_name, |
325 const base::Value* arg1, | 339 const base::Value* arg1, |
326 const base::Value* arg2, | 340 const base::Value* arg2, |
327 const base::Value* arg3); | 341 const base::Value* arg3); |
328 void UpdateBrowserToolbar(); | 342 void UpdateBrowserToolbar(); |
329 bool IsDocked(); | |
330 void Restore(); | |
331 content::WebContents* GetInspectedWebContents(); | 343 content::WebContents* GetInspectedWebContents(); |
332 void DocumentOnLoadCompletedInMainFrame(); | 344 void DocumentOnLoadCompletedInMainFrame(); |
333 | 345 |
334 class InspectedWebContentsObserver; | 346 class InspectedWebContentsObserver; |
335 scoped_ptr<InspectedWebContentsObserver> inspected_contents_observer_; | 347 scoped_ptr<InspectedWebContentsObserver> inspected_contents_observer_; |
336 class FrontendWebContentsObserver; | 348 class FrontendWebContentsObserver; |
337 friend class FrontendWebContentsObserver; | 349 friend class FrontendWebContentsObserver; |
338 scoped_ptr<FrontendWebContentsObserver> frontend_contents_observer_; | 350 scoped_ptr<FrontendWebContentsObserver> frontend_contents_observer_; |
339 | 351 |
340 Profile* profile_; | 352 Profile* profile_; |
341 content::WebContents* web_contents_; | 353 content::WebContents* web_contents_; |
342 Browser* browser_; | 354 Browser* browser_; |
343 // TODO(dgozman): move dock side knowledge entirely to frontend. | 355 bool is_docked_; |
344 DevToolsDockSide dock_side_; | 356 bool can_dock_; |
345 bool is_loaded_; | 357 LoadStateMask load_state_mask_; |
346 DevToolsToggleAction action_on_load_; | 358 DevToolsToggleAction action_on_load_; |
| 359 bool set_is_docked_for_test_on_load_; |
347 content::NotificationRegistrar registrar_; | 360 content::NotificationRegistrar registrar_; |
348 scoped_ptr<content::DevToolsClientHost> frontend_host_; | 361 scoped_ptr<content::DevToolsClientHost> frontend_host_; |
349 scoped_ptr<DevToolsFileHelper> file_helper_; | 362 scoped_ptr<DevToolsFileHelper> file_helper_; |
350 scoped_refptr<DevToolsFileSystemIndexer> file_system_indexer_; | 363 scoped_refptr<DevToolsFileSystemIndexer> file_system_indexer_; |
351 typedef std::map< | 364 typedef std::map< |
352 int, | 365 int, |
353 scoped_refptr<DevToolsFileSystemIndexer::FileSystemIndexingJob> > | 366 scoped_refptr<DevToolsFileSystemIndexer::FileSystemIndexingJob> > |
354 IndexingJobsMap; | 367 IndexingJobsMap; |
355 IndexingJobsMap indexing_jobs_; | 368 IndexingJobsMap indexing_jobs_; |
356 gfx::Insets contents_insets_; | 369 gfx::Insets contents_insets_; |
357 DevToolsDockSide dock_side_before_minimized_; | |
358 // True if we're in the process of handling a beforeunload event originating | 370 // True if we're in the process of handling a beforeunload event originating |
359 // from the inspected webcontents, see InterceptPageBeforeUnload for details. | 371 // from the inspected webcontents, see InterceptPageBeforeUnload for details. |
360 bool intercepted_page_beforeunload_; | 372 bool intercepted_page_beforeunload_; |
361 | 373 |
362 scoped_ptr<DevToolsEmbedderMessageDispatcher> embedder_message_dispatcher_; | 374 scoped_ptr<DevToolsEmbedderMessageDispatcher> embedder_message_dispatcher_; |
363 base::WeakPtrFactory<DevToolsWindow> weak_factory_; | 375 base::WeakPtrFactory<DevToolsWindow> weak_factory_; |
364 DISALLOW_COPY_AND_ASSIGN(DevToolsWindow); | 376 DISALLOW_COPY_AND_ASSIGN(DevToolsWindow); |
365 }; | 377 }; |
366 | 378 |
367 #endif // CHROME_BROWSER_DEVTOOLS_DEVTOOLS_WINDOW_H_ | 379 #endif // CHROME_BROWSER_DEVTOOLS_DEVTOOLS_WINDOW_H_ |
OLD | NEW |