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 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
268 const content::FileChooserParams& params) OVERRIDE; | 259 const content::FileChooserParams& params) OVERRIDE; |
269 virtual void WebContentsFocused(content::WebContents* contents) OVERRIDE; | 260 virtual void WebContentsFocused(content::WebContents* contents) OVERRIDE; |
270 | 261 |
271 // content::DevToolsFrontendHostDelegate override: | 262 // content::DevToolsFrontendHostDelegate override: |
272 virtual void DispatchOnEmbedder(const std::string& message) OVERRIDE; | 263 virtual void DispatchOnEmbedder(const std::string& message) OVERRIDE; |
273 | 264 |
274 // DevToolsEmbedderMessageDispatcher::Delegate overrides: | 265 // DevToolsEmbedderMessageDispatcher::Delegate overrides: |
275 virtual void ActivateWindow() OVERRIDE; | 266 virtual void ActivateWindow() OVERRIDE; |
276 virtual void ActivateContents(content::WebContents* contents) OVERRIDE; | 267 virtual void ActivateContents(content::WebContents* contents) OVERRIDE; |
277 virtual void CloseWindow() OVERRIDE; | 268 virtual void CloseWindow() OVERRIDE; |
278 virtual void SetWindowBounds(int x, int y, int width, int height) OVERRIDE; | 269 virtual void SetContentsInsets( |
| 270 int left, int top, int right, int bottom) OVERRIDE; |
279 virtual void MoveWindow(int x, int y) OVERRIDE; | 271 virtual void MoveWindow(int x, int y) OVERRIDE; |
280 virtual void SetDockSide(const std::string& side) OVERRIDE; | 272 virtual void SetDockSide(const std::string& side) OVERRIDE; |
281 virtual void OpenInNewTab(const std::string& url) OVERRIDE; | 273 virtual void OpenInNewTab(const std::string& url) OVERRIDE; |
282 virtual void SaveToFile(const std::string& url, | 274 virtual void SaveToFile(const std::string& url, |
283 const std::string& content, | 275 const std::string& content, |
284 bool save_as) OVERRIDE; | 276 bool save_as) OVERRIDE; |
285 virtual void AppendToFile(const std::string& url, | 277 virtual void AppendToFile(const std::string& url, |
286 const std::string& content) OVERRIDE; | 278 const std::string& content) OVERRIDE; |
287 virtual void RequestFileSystems() OVERRIDE; | 279 virtual void RequestFileSystems() OVERRIDE; |
288 virtual void AddFileSystem() OVERRIDE; | 280 virtual void AddFileSystem() OVERRIDE; |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
337 | 329 |
338 class InspectedWebContentsObserver; | 330 class InspectedWebContentsObserver; |
339 scoped_ptr<InspectedWebContentsObserver> inspected_contents_observer_; | 331 scoped_ptr<InspectedWebContentsObserver> inspected_contents_observer_; |
340 class FrontendWebContentsObserver; | 332 class FrontendWebContentsObserver; |
341 friend class FrontendWebContentsObserver; | 333 friend class FrontendWebContentsObserver; |
342 scoped_ptr<FrontendWebContentsObserver> frontend_contents_observer_; | 334 scoped_ptr<FrontendWebContentsObserver> frontend_contents_observer_; |
343 | 335 |
344 Profile* profile_; | 336 Profile* profile_; |
345 content::WebContents* web_contents_; | 337 content::WebContents* web_contents_; |
346 Browser* browser_; | 338 Browser* browser_; |
| 339 // TODO(dgozman): move dock side knowledge entirely to frontend. |
347 DevToolsDockSide dock_side_; | 340 DevToolsDockSide dock_side_; |
348 bool is_loaded_; | 341 bool is_loaded_; |
349 DevToolsToggleAction action_on_load_; | 342 DevToolsToggleAction action_on_load_; |
350 content::NotificationRegistrar registrar_; | 343 content::NotificationRegistrar registrar_; |
351 scoped_ptr<content::DevToolsClientHost> frontend_host_; | 344 scoped_ptr<content::DevToolsClientHost> frontend_host_; |
352 scoped_ptr<DevToolsFileHelper> file_helper_; | 345 scoped_ptr<DevToolsFileHelper> file_helper_; |
353 scoped_refptr<DevToolsFileSystemIndexer> file_system_indexer_; | 346 scoped_refptr<DevToolsFileSystemIndexer> file_system_indexer_; |
354 typedef std::map< | 347 typedef std::map< |
355 int, | 348 int, |
356 scoped_refptr<DevToolsFileSystemIndexer::FileSystemIndexingJob> > | 349 scoped_refptr<DevToolsFileSystemIndexer::FileSystemIndexingJob> > |
357 IndexingJobsMap; | 350 IndexingJobsMap; |
358 IndexingJobsMap indexing_jobs_; | 351 IndexingJobsMap indexing_jobs_; |
359 int width_; | 352 gfx::Insets contents_insets_; |
360 int height_; | |
361 DevToolsDockSide dock_side_before_minimized_; | 353 DevToolsDockSide dock_side_before_minimized_; |
362 // True if we're in the process of handling a beforeunload event originating | 354 // True if we're in the process of handling a beforeunload event originating |
363 // from the inspected webcontents, see InterceptPageBeforeUnload for details. | 355 // from the inspected webcontents, see InterceptPageBeforeUnload for details. |
364 bool intercepted_page_beforeunload_; | 356 bool intercepted_page_beforeunload_; |
365 | 357 |
366 scoped_ptr<DevToolsEmbedderMessageDispatcher> embedder_message_dispatcher_; | 358 scoped_ptr<DevToolsEmbedderMessageDispatcher> embedder_message_dispatcher_; |
367 base::WeakPtrFactory<DevToolsWindow> weak_factory_; | 359 base::WeakPtrFactory<DevToolsWindow> weak_factory_; |
368 DISALLOW_COPY_AND_ASSIGN(DevToolsWindow); | 360 DISALLOW_COPY_AND_ASSIGN(DevToolsWindow); |
369 }; | 361 }; |
370 | 362 |
371 #endif // CHROME_BROWSER_DEVTOOLS_DEVTOOLS_WINDOW_H_ | 363 #endif // CHROME_BROWSER_DEVTOOLS_DEVTOOLS_WINDOW_H_ |
OLD | NEW |