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 "chrome/browser/devtools/devtools_contents_resizing_strategy.h" | 8 #include "chrome/browser/devtools/devtools_contents_resizing_strategy.h" |
9 #include "chrome/browser/devtools/devtools_toggle_action.h" | 9 #include "chrome/browser/devtools/devtools_toggle_action.h" |
10 #include "chrome/browser/devtools/devtools_ui_bindings.h" | 10 #include "chrome/browser/devtools/devtools_ui_bindings.h" |
11 #include "content/public/browser/web_contents_delegate.h" | 11 #include "content/public/browser/web_contents_delegate.h" |
12 #include "content/public/browser/web_contents_observer.h" | 12 #include "content/public/browser/web_contents_observer.h" |
13 | 13 |
14 class Browser; | 14 class Browser; |
15 class BrowserWindow; | 15 class BrowserWindow; |
16 class DevToolsWindowTesting; | |
17 class DevToolsEventForwarder; | 16 class DevToolsEventForwarder; |
18 | 17 |
19 namespace content { | 18 namespace content { |
20 class DevToolsAgentHost; | 19 class DevToolsAgentHost; |
21 struct NativeWebKeyboardEvent; | 20 struct NativeWebKeyboardEvent; |
22 class RenderViewHost; | 21 class RenderViewHost; |
23 } | 22 } |
24 | 23 |
25 namespace user_prefs { | 24 namespace user_prefs { |
26 class PrefRegistrySyncable; | 25 class PrefRegistrySyncable; |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
65 | 64 |
66 // Open or reveal DevTools window, and perform the specified action. | 65 // Open or reveal DevTools window, and perform the specified action. |
67 static DevToolsWindow* OpenDevToolsWindow( | 66 static DevToolsWindow* OpenDevToolsWindow( |
68 content::RenderViewHost* inspected_rvh, | 67 content::RenderViewHost* inspected_rvh, |
69 const DevToolsToggleAction& action); | 68 const DevToolsToggleAction& action); |
70 | 69 |
71 // Open or reveal DevTools window, with no special action. | 70 // Open or reveal DevTools window, with no special action. |
72 static DevToolsWindow* OpenDevToolsWindow( | 71 static DevToolsWindow* OpenDevToolsWindow( |
73 content::RenderViewHost* inspected_rvh); | 72 content::RenderViewHost* inspected_rvh); |
74 | 73 |
| 74 static DevToolsWindow* OpenDevToolsWindowForTest( |
| 75 content::RenderViewHost* inspected_rvh, bool is_docked); |
| 76 static DevToolsWindow* OpenDevToolsWindowForTest( |
| 77 Browser* browser, bool is_docked); |
| 78 |
75 // Perform specified action for current WebContents inside a |browser|. | 79 // Perform specified action for current WebContents inside a |browser|. |
76 // This may close currently open DevTools window. | 80 // This may close currently open DevTools window. |
77 static DevToolsWindow* ToggleDevToolsWindow( | 81 static DevToolsWindow* ToggleDevToolsWindow( |
78 Browser* browser, | 82 Browser* browser, |
79 const DevToolsToggleAction& action); | 83 const DevToolsToggleAction& action); |
80 | 84 |
81 // External frontend is always undocked. | 85 // External frontend is always undocked. |
82 static void OpenExternalFrontend( | 86 static void OpenExternalFrontend( |
83 Profile* profile, | 87 Profile* profile, |
84 const std::string& frontend_uri, | 88 const std::string& frontend_uri, |
85 content::DevToolsAgentHost* agent_host); | 89 content::DevToolsAgentHost* agent_host); |
86 | 90 |
87 // Worker frontend is always undocked. | 91 // Worker frontend is always undocked. |
88 static DevToolsWindow* OpenDevToolsWindowForWorker( | 92 static DevToolsWindow* OpenDevToolsWindowForWorker( |
89 Profile* profile, | 93 Profile* profile, |
90 content::DevToolsAgentHost* worker_agent); | 94 content::DevToolsAgentHost* worker_agent); |
91 | 95 |
92 static void InspectElement( | 96 static void InspectElement( |
93 content::RenderViewHost* inspected_rvh, int x, int y); | 97 content::RenderViewHost* inspected_rvh, int x, int y); |
94 | 98 |
| 99 Browser* browser_for_test() { return browser_; } |
| 100 content::WebContents* web_contents_for_test() { return main_web_contents_; } |
| 101 |
95 // Sets closure to be called after load is done. If already loaded, calls | 102 // Sets closure to be called after load is done. If already loaded, calls |
96 // closure immediately. | 103 // closure immediately. |
97 void SetLoadCompletedCallback(const base::Closure& closure); | 104 void SetLoadCompletedCallback(const base::Closure& closure); |
98 | 105 |
99 // Forwards an unhandled keyboard event to the DevTools frontend. | 106 // Forwards an unhandled keyboard event to the DevTools frontend. |
100 bool ForwardKeyboardEvent(const content::NativeWebKeyboardEvent& event); | 107 bool ForwardKeyboardEvent(const content::NativeWebKeyboardEvent& event); |
101 | 108 |
102 // BeforeUnload interception //////////////////////////////////////////////// | 109 // BeforeUnload interception //////////////////////////////////////////////// |
103 | 110 |
104 // In order to preserve any edits the user may have made in devtools, the | 111 // In order to preserve any edits the user may have made in devtools, the |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
167 | 174 |
168 // Returns true if devtools window would like to hook beforeunload event | 175 // Returns true if devtools window would like to hook beforeunload event |
169 // of this |contents|. | 176 // of this |contents|. |
170 static bool NeedsToInterceptBeforeUnload(content::WebContents* contents); | 177 static bool NeedsToInterceptBeforeUnload(content::WebContents* contents); |
171 | 178 |
172 // Notify devtools window that closing of |contents| was cancelled | 179 // Notify devtools window that closing of |contents| was cancelled |
173 // by user. | 180 // by user. |
174 static void OnPageCloseCanceled(content::WebContents* contents); | 181 static void OnPageCloseCanceled(content::WebContents* contents); |
175 | 182 |
176 private: | 183 private: |
177 friend class DevToolsWindowTesting; | 184 friend class DevToolsSanityTest; |
| 185 friend class BrowserWindowControllerTest; |
178 | 186 |
179 // DevTools lifecycle typically follows this way: | 187 // DevTools lifecycle typically follows this way: |
180 // - Toggle/Open: client call; | 188 // - Toggle/Open: client call; |
181 // - Create; | 189 // - Create; |
182 // - ScheduleShow: setup window to be functional, but not yet show; | 190 // - ScheduleShow: setup window to be functional, but not yet show; |
183 // - DocumentOnLoadCompletedInMainFrame: frontend loaded; | 191 // - DocumentOnLoadCompletedInMainFrame: frontend loaded; |
184 // - SetIsDocked: frontend decided on docking state; | 192 // - SetIsDocked: frontend decided on docking state; |
185 // - OnLoadCompleted: ready to present frontend; | 193 // - OnLoadCompleted: ready to present frontend; |
186 // - Show: actually placing frontend WebContents to a Browser or docked place; | 194 // - Show: actually placing frontend WebContents to a Browser or docked place; |
187 // - DoAction: perform action passed in Toggle/Open; | 195 // - DoAction: perform action passed in Toggle/Open; |
(...skipping 12 matching lines...) Expand all Loading... |
200 DevToolsWindow(Profile* profile, | 208 DevToolsWindow(Profile* profile, |
201 const GURL& frontend_url, | 209 const GURL& frontend_url, |
202 content::RenderViewHost* inspected_rvh, | 210 content::RenderViewHost* inspected_rvh, |
203 bool can_dock); | 211 bool can_dock); |
204 | 212 |
205 static DevToolsWindow* Create(Profile* profile, | 213 static DevToolsWindow* Create(Profile* profile, |
206 const GURL& frontend_url, | 214 const GURL& frontend_url, |
207 content::RenderViewHost* inspected_rvh, | 215 content::RenderViewHost* inspected_rvh, |
208 bool shared_worker_frontend, | 216 bool shared_worker_frontend, |
209 bool external_frontend, | 217 bool external_frontend, |
210 bool can_dock, | 218 bool can_dock); |
211 const std::string& settings); | |
212 static GURL GetDevToolsURL(Profile* profile, | 219 static GURL GetDevToolsURL(Profile* profile, |
213 const GURL& base_url, | 220 const GURL& base_url, |
214 bool shared_worker_frontend, | 221 bool shared_worker_frontend, |
215 bool external_frontend, | 222 bool external_frontend, |
216 bool can_dock, | 223 bool can_dock); |
217 const std::string& settings); | |
218 static DevToolsWindow* FindDevToolsWindow(content::DevToolsAgentHost*); | 224 static DevToolsWindow* FindDevToolsWindow(content::DevToolsAgentHost*); |
219 static DevToolsWindow* AsDevToolsWindow(content::WebContents*); | 225 static DevToolsWindow* AsDevToolsWindow(content::WebContents*); |
220 static DevToolsWindow* CreateDevToolsWindowForWorker(Profile* profile); | 226 static DevToolsWindow* CreateDevToolsWindowForWorker(Profile* profile); |
221 static DevToolsWindow* ToggleDevToolsWindow( | 227 static DevToolsWindow* ToggleDevToolsWindow( |
222 content::RenderViewHost* inspected_rvh, | 228 content::RenderViewHost* inspected_rvh, |
223 bool force_open, | 229 bool force_open, |
224 const DevToolsToggleAction& action, | 230 const DevToolsToggleAction& action); |
225 const std::string& settings); | |
226 | 231 |
227 static std::string GetDevToolsWindowPlacementPrefKey(); | 232 static std::string GetDevToolsWindowPlacementPrefKey(); |
228 | 233 |
229 // content::WebContentsDelegate: | 234 // content::WebContentsDelegate: |
230 virtual content::WebContents* OpenURLFromTab( | 235 virtual content::WebContents* OpenURLFromTab( |
231 content::WebContents* source, | 236 content::WebContents* source, |
232 const content::OpenURLParams& params) OVERRIDE; | 237 const content::OpenURLParams& params) OVERRIDE; |
233 virtual void ActivateContents(content::WebContents* contents) OVERRIDE; | 238 virtual void ActivateContents(content::WebContents* contents) OVERRIDE; |
234 virtual void AddNewContents(content::WebContents* source, | 239 virtual void AddNewContents(content::WebContents* source, |
235 content::WebContents* new_contents, | 240 content::WebContents* new_contents, |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
283 virtual void OnLoadCompleted() OVERRIDE; | 288 virtual void OnLoadCompleted() OVERRIDE; |
284 virtual InfoBarService* GetInfoBarService() OVERRIDE; | 289 virtual InfoBarService* GetInfoBarService() OVERRIDE; |
285 virtual void RenderProcessGone() OVERRIDE; | 290 virtual void RenderProcessGone() OVERRIDE; |
286 | 291 |
287 void CreateDevToolsBrowser(); | 292 void CreateDevToolsBrowser(); |
288 BrowserWindow* GetInspectedBrowserWindow(); | 293 BrowserWindow* GetInspectedBrowserWindow(); |
289 void ScheduleShow(const DevToolsToggleAction& action); | 294 void ScheduleShow(const DevToolsToggleAction& action); |
290 void Show(const DevToolsToggleAction& action); | 295 void Show(const DevToolsToggleAction& action); |
291 void DoAction(const DevToolsToggleAction& action); | 296 void DoAction(const DevToolsToggleAction& action); |
292 void LoadCompleted(); | 297 void LoadCompleted(); |
| 298 void SetIsDockedAndShowImmediatelyForTest(bool is_docked); |
293 void UpdateBrowserToolbar(); | 299 void UpdateBrowserToolbar(); |
294 void UpdateBrowserWindow(); | 300 void UpdateBrowserWindow(); |
295 content::WebContents* GetInspectedWebContents(); | 301 content::WebContents* GetInspectedWebContents(); |
296 | 302 |
297 scoped_ptr<ObserverWithAccessor> inspected_contents_observer_; | 303 scoped_ptr<ObserverWithAccessor> inspected_contents_observer_; |
298 | 304 |
299 Profile* profile_; | 305 Profile* profile_; |
300 content::WebContents* main_web_contents_; | 306 content::WebContents* main_web_contents_; |
301 content::WebContents* toolbox_web_contents_; | 307 content::WebContents* toolbox_web_contents_; |
302 DevToolsUIBindings* bindings_; | 308 DevToolsUIBindings* bindings_; |
303 Browser* browser_; | 309 Browser* browser_; |
304 bool is_docked_; | 310 bool is_docked_; |
305 const bool can_dock_; | 311 const bool can_dock_; |
306 LifeStage life_stage_; | 312 LifeStage life_stage_; |
307 DevToolsToggleAction action_on_load_; | 313 DevToolsToggleAction action_on_load_; |
| 314 bool ignore_set_is_docked_; |
308 DevToolsContentsResizingStrategy contents_resizing_strategy_; | 315 DevToolsContentsResizingStrategy contents_resizing_strategy_; |
309 // True if we're in the process of handling a beforeunload event originating | 316 // True if we're in the process of handling a beforeunload event originating |
310 // from the inspected webcontents, see InterceptPageBeforeUnload for details. | 317 // from the inspected webcontents, see InterceptPageBeforeUnload for details. |
311 bool intercepted_page_beforeunload_; | 318 bool intercepted_page_beforeunload_; |
312 base::Closure load_completed_callback_; | 319 base::Closure load_completed_callback_; |
313 base::Closure close_callback_; | |
314 | 320 |
315 base::TimeTicks inspect_element_start_time_; | 321 base::TimeTicks inspect_element_start_time_; |
316 scoped_ptr<DevToolsEventForwarder> event_forwarder_; | 322 scoped_ptr<DevToolsEventForwarder> event_forwarder_; |
317 | 323 |
318 friend class DevToolsEventForwarder; | 324 friend class DevToolsEventForwarder; |
319 DISALLOW_COPY_AND_ASSIGN(DevToolsWindow); | 325 DISALLOW_COPY_AND_ASSIGN(DevToolsWindow); |
320 }; | 326 }; |
321 | 327 |
322 #endif // CHROME_BROWSER_DEVTOOLS_DEVTOOLS_WINDOW_H_ | 328 #endif // CHROME_BROWSER_DEVTOOLS_DEVTOOLS_WINDOW_H_ |
OLD | NEW |