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 |
11 #include "base/basictypes.h" | 11 #include "base/basictypes.h" |
12 #include "base/memory/scoped_ptr.h" | 12 #include "base/memory/scoped_ptr.h" |
13 #include "base/memory/weak_ptr.h" | 13 #include "base/memory/weak_ptr.h" |
14 #include "base/strings/string16.h" | 14 #include "base/strings/string16.h" |
15 #include "chrome/browser/devtools/devtools_embedder_message_dispatcher.h" | 15 #include "chrome/browser/devtools/devtools_embedder_message_dispatcher.h" |
16 #include "chrome/browser/devtools/devtools_file_helper.h" | 16 #include "chrome/browser/devtools/devtools_file_helper.h" |
17 #include "chrome/browser/devtools/devtools_file_system_indexer.h" | 17 #include "chrome/browser/devtools/devtools_file_system_indexer.h" |
18 #include "chrome/browser/devtools/devtools_toggle_action.h" | 18 #include "chrome/browser/devtools/devtools_toggle_action.h" |
19 #include "content/public/browser/devtools_client_host.h" | 19 #include "content/public/browser/devtools_client_host.h" |
20 #include "content/public/browser/devtools_frontend_host_delegate.h" | 20 #include "content/public/browser/devtools_frontend_host_delegate.h" |
21 #include "content/public/browser/notification_observer.h" | 21 #include "content/public/browser/notification_observer.h" |
22 #include "content/public/browser/notification_registrar.h" | 22 #include "content/public/browser/notification_registrar.h" |
23 #include "content/public/browser/web_contents_delegate.h" | 23 #include "content/public/browser/web_contents_delegate.h" |
| 24 #include "ui/gfx/insets.h" |
| 25 #include "ui/gfx/size.h" |
24 | 26 |
25 class Browser; | 27 class Browser; |
26 class BrowserWindow; | 28 class BrowserWindow; |
27 class DevToolsControllerTest; | 29 class DevToolsControllerTest; |
28 class Profile; | 30 class Profile; |
29 | 31 |
30 namespace base { | 32 namespace base { |
31 class Value; | 33 class Value; |
32 } | 34 } |
33 | 35 |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
89 | 91 |
90 // Exposed for testing, normal clients should not use this method. | 92 // Exposed for testing, normal clients should not use this method. |
91 static DevToolsWindow* ToggleDevToolsWindow( | 93 static DevToolsWindow* ToggleDevToolsWindow( |
92 content::RenderViewHost* inspected_rvh, | 94 content::RenderViewHost* inspected_rvh, |
93 bool force_open, | 95 bool force_open, |
94 const DevToolsToggleAction& action); | 96 const DevToolsToggleAction& action); |
95 | 97 |
96 static void InspectElement( | 98 static void InspectElement( |
97 content::RenderViewHost* inspected_rvh, int x, int y); | 99 content::RenderViewHost* inspected_rvh, int x, int y); |
98 | 100 |
99 static int GetMinimumWidth(); | |
100 static int GetMinimumHeight(); | |
101 static int GetMinimizedHeight(); | 101 static int GetMinimizedHeight(); |
102 | 102 |
103 // content::DevToolsFrontendHostDelegate: | 103 // content::DevToolsFrontendHostDelegate: |
104 virtual void InspectedContentsClosing() OVERRIDE; | 104 virtual void InspectedContentsClosing() OVERRIDE; |
105 | 105 |
106 content::WebContents* web_contents() { return web_contents_; } | 106 content::WebContents* web_contents() { return web_contents_; } |
107 Browser* browser() { return browser_; } // For tests. | 107 Browser* browser() { return browser_; } // For tests. |
108 DevToolsDockSide dock_side() const { return dock_side_; } | 108 DevToolsDockSide dock_side() const { return dock_side_; } |
109 | 109 |
110 content::RenderViewHost* GetRenderViewHost(); | 110 content::RenderViewHost* GetRenderViewHost(); |
111 content::DevToolsClientHost* GetDevToolsClientHostForTest(); | 111 content::DevToolsClientHost* GetDevToolsClientHostForTest(); |
112 | 112 |
113 // Returns preferred devtools window width for given |container_width|. It | 113 // Inspected WebContents is placed over DevTools WebContents in docked mode. |
114 // tries to use the saved window width, or, if none exists, 1/3 of the | 114 // The following methods return the insets of inspected WebContents |
115 // container width, then clamps to try and ensure both devtools and content | 115 // relative to DevTools WebContents. |
116 // are at least somewhat visible. | 116 gfx::Insets GetContentsInsets() const; |
117 // Called only for the case when devtools window is docked to the side. | |
118 int GetWidth(int container_width); | |
119 | 117 |
120 // Returns preferred devtools window height for given |container_height|. | 118 // Minimum size of the docked DevTools WebContents. This includes |
121 // Uses the same logic as GetWidth. | 119 // the overlaying inspected WebContents size. |
122 // Called only for the case when devtools window is docked to bottom. | 120 gfx::Size GetMinimumSize() const; |
123 int GetHeight(int container_height); | |
124 | |
125 // Stores preferred devtools window width for this instance. | |
126 void SetWidth(int width); | |
127 | |
128 // Stores preferred devtools window height for this instance. | |
129 void SetHeight(int height); | |
130 | 121 |
131 void Show(const DevToolsToggleAction& action); | 122 void Show(const DevToolsToggleAction& action); |
132 | 123 |
133 // BeforeUnload interception //////////////////////////////////////////////// | 124 // BeforeUnload interception //////////////////////////////////////////////// |
134 | 125 |
135 // 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 |
136 // beforeunload event of the inspected page is hooked - devtools gets the | 127 // beforeunload event of the inspected page is hooked - devtools gets the |
137 // 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 |
138 // 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 |
139 // 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 |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
201 static bool NeedsToInterceptBeforeUnload(content::WebContents* contents); | 192 static bool NeedsToInterceptBeforeUnload(content::WebContents* contents); |
202 | 193 |
203 // Notify devtools window that closing of |contents| was cancelled | 194 // Notify devtools window that closing of |contents| was cancelled |
204 // by user. | 195 // by user. |
205 static void OnPageCloseCanceled(content::WebContents* contents); | 196 static void OnPageCloseCanceled(content::WebContents* contents); |
206 | 197 |
207 void SetDockSideForTest(DevToolsDockSide dock_side); | 198 void SetDockSideForTest(DevToolsDockSide dock_side); |
208 | 199 |
209 private: | 200 private: |
210 friend class DevToolsControllerTest; | 201 friend class DevToolsControllerTest; |
| 202 friend class BrowserWindowControllerTest; |
211 | 203 |
212 DevToolsWindow(Profile* profile, | 204 DevToolsWindow(Profile* profile, |
213 const GURL& frontend_url, | 205 const GURL& frontend_url, |
214 content::RenderViewHost* inspected_rvh, | 206 content::RenderViewHost* inspected_rvh, |
215 DevToolsDockSide dock_side); | 207 DevToolsDockSide dock_side); |
216 | 208 |
217 static DevToolsWindow* Create(Profile* profile, | 209 static DevToolsWindow* Create(Profile* profile, |
218 const GURL& frontend_url, | 210 const GURL& frontend_url, |
219 content::RenderViewHost* inspected_rvh, | 211 content::RenderViewHost* inspected_rvh, |
220 DevToolsDockSide dock_side, | 212 DevToolsDockSide dock_side, |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
272 const content::FileChooserParams& params) OVERRIDE; | 264 const content::FileChooserParams& params) OVERRIDE; |
273 virtual void WebContentsFocused(content::WebContents* contents) OVERRIDE; | 265 virtual void WebContentsFocused(content::WebContents* contents) OVERRIDE; |
274 | 266 |
275 // content::DevToolsFrontendHostDelegate override: | 267 // content::DevToolsFrontendHostDelegate override: |
276 virtual void DispatchOnEmbedder(const std::string& message) OVERRIDE; | 268 virtual void DispatchOnEmbedder(const std::string& message) OVERRIDE; |
277 | 269 |
278 // DevToolsEmbedderMessageDispatcher::Delegate overrides: | 270 // DevToolsEmbedderMessageDispatcher::Delegate overrides: |
279 virtual void ActivateWindow() OVERRIDE; | 271 virtual void ActivateWindow() OVERRIDE; |
280 virtual void ActivateContents(content::WebContents* contents) OVERRIDE; | 272 virtual void ActivateContents(content::WebContents* contents) OVERRIDE; |
281 virtual void CloseWindow() OVERRIDE; | 273 virtual void CloseWindow() OVERRIDE; |
282 virtual void SetWindowBounds(int x, int y, int width, int height) OVERRIDE; | 274 virtual void SetContentsInsets( |
| 275 int left, int top, int right, int bottom) OVERRIDE; |
283 virtual void MoveWindow(int x, int y) OVERRIDE; | 276 virtual void MoveWindow(int x, int y) OVERRIDE; |
284 virtual void SetDockSide(const std::string& side) OVERRIDE; | 277 virtual void SetDockSide(const std::string& side) OVERRIDE; |
285 virtual void OpenInNewTab(const std::string& url) OVERRIDE; | 278 virtual void OpenInNewTab(const std::string& url) OVERRIDE; |
286 virtual void SaveToFile(const std::string& url, | 279 virtual void SaveToFile(const std::string& url, |
287 const std::string& content, | 280 const std::string& content, |
288 bool save_as) OVERRIDE; | 281 bool save_as) OVERRIDE; |
289 virtual void AppendToFile(const std::string& url, | 282 virtual void AppendToFile(const std::string& url, |
290 const std::string& content) OVERRIDE; | 283 const std::string& content) OVERRIDE; |
291 virtual void RequestFileSystems() OVERRIDE; | 284 virtual void RequestFileSystems() OVERRIDE; |
292 virtual void AddFileSystem() OVERRIDE; | 285 virtual void AddFileSystem() OVERRIDE; |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
340 | 333 |
341 class InspectedWebContentsObserver; | 334 class InspectedWebContentsObserver; |
342 scoped_ptr<InspectedWebContentsObserver> inspected_contents_observer_; | 335 scoped_ptr<InspectedWebContentsObserver> inspected_contents_observer_; |
343 class FrontendWebContentsObserver; | 336 class FrontendWebContentsObserver; |
344 friend class FrontendWebContentsObserver; | 337 friend class FrontendWebContentsObserver; |
345 scoped_ptr<FrontendWebContentsObserver> frontend_contents_observer_; | 338 scoped_ptr<FrontendWebContentsObserver> frontend_contents_observer_; |
346 | 339 |
347 Profile* profile_; | 340 Profile* profile_; |
348 content::WebContents* web_contents_; | 341 content::WebContents* web_contents_; |
349 Browser* browser_; | 342 Browser* browser_; |
| 343 // TODO(dgozman): move dock side knowledge entirely to frontend. |
350 DevToolsDockSide dock_side_; | 344 DevToolsDockSide dock_side_; |
351 bool is_loaded_; | 345 bool is_loaded_; |
352 DevToolsToggleAction action_on_load_; | 346 DevToolsToggleAction action_on_load_; |
353 content::NotificationRegistrar registrar_; | 347 content::NotificationRegistrar registrar_; |
354 scoped_ptr<content::DevToolsClientHost> frontend_host_; | 348 scoped_ptr<content::DevToolsClientHost> frontend_host_; |
355 scoped_ptr<DevToolsFileHelper> file_helper_; | 349 scoped_ptr<DevToolsFileHelper> file_helper_; |
356 scoped_refptr<DevToolsFileSystemIndexer> file_system_indexer_; | 350 scoped_refptr<DevToolsFileSystemIndexer> file_system_indexer_; |
357 typedef std::map< | 351 typedef std::map< |
358 int, | 352 int, |
359 scoped_refptr<DevToolsFileSystemIndexer::FileSystemIndexingJob> > | 353 scoped_refptr<DevToolsFileSystemIndexer::FileSystemIndexingJob> > |
360 IndexingJobsMap; | 354 IndexingJobsMap; |
361 IndexingJobsMap indexing_jobs_; | 355 IndexingJobsMap indexing_jobs_; |
362 int width_; | 356 gfx::Insets contents_insets_; |
363 int height_; | |
364 DevToolsDockSide dock_side_before_minimized_; | 357 DevToolsDockSide dock_side_before_minimized_; |
365 // True if we're in the process of handling a beforeunload event originating | 358 // True if we're in the process of handling a beforeunload event originating |
366 // from the inspected webcontents, see InterceptPageBeforeUnload for details. | 359 // from the inspected webcontents, see InterceptPageBeforeUnload for details. |
367 bool intercepted_page_beforeunload_; | 360 bool intercepted_page_beforeunload_; |
368 | 361 |
369 scoped_ptr<DevToolsEmbedderMessageDispatcher> embedder_message_dispatcher_; | 362 scoped_ptr<DevToolsEmbedderMessageDispatcher> embedder_message_dispatcher_; |
370 base::WeakPtrFactory<DevToolsWindow> weak_factory_; | 363 base::WeakPtrFactory<DevToolsWindow> weak_factory_; |
371 DISALLOW_COPY_AND_ASSIGN(DevToolsWindow); | 364 DISALLOW_COPY_AND_ASSIGN(DevToolsWindow); |
372 }; | 365 }; |
373 | 366 |
374 #endif // CHROME_BROWSER_DEVTOOLS_DEVTOOLS_WINDOW_H_ | 367 #endif // CHROME_BROWSER_DEVTOOLS_DEVTOOLS_WINDOW_H_ |
OLD | NEW |