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