Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(133)

Side by Side Diff: chrome/browser/devtools/devtools_window.h

Issue 108213012: [DevTools] Remove dock side knowledge from browser. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Mac tests Created 6 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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. This method will return only fully initialized
73 // window ready to be presented in UI.
74 // For immediately-ready-to-use but maybe not yet fully initialized DevTools
75 // use |GetInstanceForInspectedRenderViewHost| instead.
76 static DevToolsWindow* GetDockedInstanceForInspectedTab( 76 static DevToolsWindow* GetDockedInstanceForInspectedTab(
77 content::WebContents* inspected_tab); 77 content::WebContents* inspected_tab);
78
78 static bool IsDevToolsWindow(content::RenderViewHost* window_rvh); 79 static bool IsDevToolsWindow(content::RenderViewHost* window_rvh);
80
81 // Open or reveal DevTools window, and perform the specified action.
82 static DevToolsWindow* OpenDevToolsWindow(
83 content::RenderViewHost* inspected_rvh,
84 const DevToolsToggleAction& action);
85
86 // Open or reveal DevTools window, with no special action.
87 static DevToolsWindow* OpenDevToolsWindow(
88 content::RenderViewHost* inspected_rvh);
89
90 static DevToolsWindow* OpenDevToolsWindowForTest(
91 content::RenderViewHost* inspected_rvh, bool is_docked);
92 static DevToolsWindow* OpenDevToolsWindowForTest(
93 Browser* browser, bool is_docked);
94
95 // Perform specified action for current WebContents inside a |browser|.
96 // This may close currently open DevTools window.
97 static DevToolsWindow* ToggleDevToolsWindow(
98 Browser* browser,
99 const DevToolsToggleAction& action);
100
101 // External frontend is always undocked.
102 static void OpenExternalFrontend(
103 Profile* profile,
104 const std::string& frontend_uri,
105 content::DevToolsAgentHost* agent_host);
106
107 // Worker frontend is always undocked.
79 static DevToolsWindow* OpenDevToolsWindowForWorker( 108 static DevToolsWindow* OpenDevToolsWindowForWorker(
80 Profile* profile, 109 Profile* profile,
81 content::DevToolsAgentHost* worker_agent); 110 content::DevToolsAgentHost* worker_agent);
82 static DevToolsWindow* CreateDevToolsWindowForWorker(Profile* profile);
83 static DevToolsWindow* OpenDevToolsWindow(
84 content::RenderViewHost* inspected_rvh);
85 static DevToolsWindow* ToggleDevToolsWindow(
86 Browser* browser,
87 const DevToolsToggleAction& action);
88 static void OpenExternalFrontend(Profile* profile,
89 const std::string& frontend_uri,
90 content::DevToolsAgentHost* agent_host);
91
92 // Exposed for testing, normal clients should not use this method.
93 static DevToolsWindow* ToggleDevToolsWindow(
94 content::RenderViewHost* inspected_rvh,
95 bool force_open,
96 const DevToolsToggleAction& action);
97 111
98 static void InspectElement( 112 static void InspectElement(
99 content::RenderViewHost* inspected_rvh, int x, int y); 113 content::RenderViewHost* inspected_rvh, int x, int y);
100 114
101 static int GetMinimizedHeight(); 115 static int GetMinimizedHeight();
102 116
103 // content::DevToolsFrontendHostDelegate: 117 // content::DevToolsFrontendHostDelegate:
104 virtual void InspectedContentsClosing() OVERRIDE; 118 virtual void InspectedContentsClosing() OVERRIDE;
105 119
106 content::WebContents* web_contents() { return web_contents_; } 120 content::WebContents* web_contents() { return web_contents_; }
107 Browser* browser() { return browser_; } // For tests. 121 Browser* browser() { return browser_; } // For tests.
108 DevToolsDockSide dock_side() const { return dock_side_; }
109 122
110 content::RenderViewHost* GetRenderViewHost(); 123 content::RenderViewHost* GetRenderViewHost();
111 content::DevToolsClientHost* GetDevToolsClientHostForTest();
112 124
113 // Inspected WebContents is placed over DevTools WebContents in docked mode. 125 // Inspected WebContents is placed over DevTools WebContents in docked mode.
114 // The following methods return the insets of inspected WebContents 126 // The following methods return the insets of inspected WebContents
115 // relative to DevTools WebContents. 127 // relative to DevTools WebContents.
116 gfx::Insets GetContentsInsets() const; 128 gfx::Insets GetContentsInsets() const;
117 129
118 // Minimum size of the docked DevTools WebContents. This includes 130 // Minimum size of the docked DevTools WebContents. This includes
119 // the overlaying inspected WebContents size. 131 // the overlaying inspected WebContents size.
120 gfx::Size GetMinimumSize() const; 132 gfx::Size GetMinimumSize() const;
121 133
122 void Show(const DevToolsToggleAction& action);
123
124 // BeforeUnload interception //////////////////////////////////////////////// 134 // BeforeUnload interception ////////////////////////////////////////////////
125 135
126 // In order to preserve any edits the user may have made in devtools, the 136 // 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 137 // 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 138 // 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 139 // 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 140 // 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 141 // 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. 142 // another from the webpage as the result of its beforeunload handler.
133 // The following set of methods handle beforeunload event flow through 143 // The following set of methods handle beforeunload event flow through
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
188 static bool HasFiredBeforeUnloadEventForDevToolsBrowser(Browser* browser); 198 static bool HasFiredBeforeUnloadEventForDevToolsBrowser(Browser* browser);
189 199
190 // Returns true if devtools window would like to hook beforeunload event 200 // Returns true if devtools window would like to hook beforeunload event
191 // of this |contents|. 201 // of this |contents|.
192 static bool NeedsToInterceptBeforeUnload(content::WebContents* contents); 202 static bool NeedsToInterceptBeforeUnload(content::WebContents* contents);
193 203
194 // Notify devtools window that closing of |contents| was cancelled 204 // Notify devtools window that closing of |contents| was cancelled
195 // by user. 205 // by user.
196 static void OnPageCloseCanceled(content::WebContents* contents); 206 static void OnPageCloseCanceled(content::WebContents* contents);
197 207
198 void SetDockSideForTest(DevToolsDockSide dock_side);
199
200 private: 208 private:
201 friend class DevToolsControllerTest; 209 friend class DevToolsControllerTest;
210 friend class DevToolsSanityTest;
202 friend class BrowserWindowControllerTest; 211 friend class BrowserWindowControllerTest;
203 212
213 // DevTools initialization typically follows this way:
214 // - Toggle/Open: client call;
215 // - Create;
216 // - ScheduleShow: setup window to be functional, but not yet show;
217 // - DocumentOnLoadCompletedInMainFrame: frontend loaded;
218 // - SetIsDocked: frontend decided on docking state;
219 // - OnLoadCompleted: ready to present frontend;
220 // - Show: actually placing frontend WebContents to a Browser or docked place;
221 // - DoAction: perform action passed in Toggle/Open.
222 enum LoadState {
223 kNotLoaded,
224 kOnLoadFired, // Implies SetIsDocked was not yet called.
225 kIsDockedSet, // Implies DocumentOnLoadCompleted was not yet called.
226 kLoadCompleted
227 };
228
204 DevToolsWindow(Profile* profile, 229 DevToolsWindow(Profile* profile,
205 const GURL& frontend_url, 230 const GURL& frontend_url,
206 content::RenderViewHost* inspected_rvh, 231 content::RenderViewHost* inspected_rvh,
207 DevToolsDockSide dock_side); 232 bool can_dock);
208 233
209 static DevToolsWindow* Create(Profile* profile, 234 static DevToolsWindow* Create(Profile* profile,
210 const GURL& frontend_url, 235 const GURL& frontend_url,
211 content::RenderViewHost* inspected_rvh, 236 content::RenderViewHost* inspected_rvh,
212 DevToolsDockSide dock_side,
213 bool shared_worker_frontend, 237 bool shared_worker_frontend,
214 bool external_frontend, 238 bool external_frontend,
215 bool can_dock); 239 bool can_dock);
216 static GURL GetDevToolsURL(Profile* profile, 240 static GURL GetDevToolsURL(Profile* profile,
217 const GURL& base_url, 241 const GURL& base_url,
218 DevToolsDockSide dock_side,
219 bool shared_worker_frontend, 242 bool shared_worker_frontend,
220 bool external_frontend, 243 bool external_frontend,
221 bool can_dock); 244 bool can_dock);
222 static DevToolsWindow* FindDevToolsWindow(content::DevToolsAgentHost*); 245 static DevToolsWindow* FindDevToolsWindow(content::DevToolsAgentHost*);
223 static DevToolsWindow* AsDevToolsWindow(content::RenderViewHost*); 246 static DevToolsWindow* AsDevToolsWindow(content::RenderViewHost*);
224 static DevToolsDockSide GetDockSideFromPrefs(Profile* profile); 247 static DevToolsWindow* CreateDevToolsWindowForWorker(Profile* profile);
225 static std::string SideToString(DevToolsDockSide dock_side); 248 static bool IsDockedFromString(const std::string& dock_side);
226 static DevToolsDockSide SideFromString(const std::string& dock_side);
227 static bool FindInspectedBrowserAndTabIndex( 249 static bool FindInspectedBrowserAndTabIndex(
228 content::WebContents* inspected_web_contents, Browser**, int* tab); 250 content::WebContents* inspected_web_contents, Browser**, int* tab);
251 static DevToolsWindow* ToggleDevToolsWindow(
252 content::RenderViewHost* inspected_rvh,
253 bool force_open,
254 const DevToolsToggleAction& action);
229 255
230 // content::NotificationObserver: 256 // content::NotificationObserver:
231 virtual void Observe(int type, 257 virtual void Observe(int type,
232 const content::NotificationSource& source, 258 const content::NotificationSource& source,
233 const content::NotificationDetails& details) OVERRIDE; 259 const content::NotificationDetails& details) OVERRIDE;
234 260
235 // content::WebContentsDelegate: 261 // content::WebContentsDelegate:
236 virtual content::WebContents* OpenURLFromTab( 262 virtual content::WebContents* OpenURLFromTab(
237 content::WebContents* source, 263 content::WebContents* source,
238 const content::OpenURLParams& params) OVERRIDE; 264 const content::OpenURLParams& params) OVERRIDE;
(...skipping 29 matching lines...) Expand all
268 virtual void DispatchOnEmbedder(const std::string& message) OVERRIDE; 294 virtual void DispatchOnEmbedder(const std::string& message) OVERRIDE;
269 295
270 // DevToolsEmbedderMessageDispatcher::Delegate overrides: 296 // DevToolsEmbedderMessageDispatcher::Delegate overrides:
271 virtual void ActivateWindow() OVERRIDE; 297 virtual void ActivateWindow() OVERRIDE;
272 virtual void ActivateContents(content::WebContents* contents) OVERRIDE; 298 virtual void ActivateContents(content::WebContents* contents) OVERRIDE;
273 virtual void CloseWindow() OVERRIDE; 299 virtual void CloseWindow() OVERRIDE;
274 virtual void SetContentsInsets( 300 virtual void SetContentsInsets(
275 int left, int top, int right, int bottom) OVERRIDE; 301 int left, int top, int right, int bottom) OVERRIDE;
276 virtual void MoveWindow(int x, int y) OVERRIDE; 302 virtual void MoveWindow(int x, int y) OVERRIDE;
277 virtual void SetDockSide(const std::string& side) OVERRIDE; 303 virtual void SetDockSide(const std::string& side) OVERRIDE;
304 virtual void SetIsDocked(bool is_docked) OVERRIDE;
278 virtual void OpenInNewTab(const std::string& url) OVERRIDE; 305 virtual void OpenInNewTab(const std::string& url) OVERRIDE;
279 virtual void SaveToFile(const std::string& url, 306 virtual void SaveToFile(const std::string& url,
280 const std::string& content, 307 const std::string& content,
281 bool save_as) OVERRIDE; 308 bool save_as) OVERRIDE;
282 virtual void AppendToFile(const std::string& url, 309 virtual void AppendToFile(const std::string& url,
283 const std::string& content) OVERRIDE; 310 const std::string& content) OVERRIDE;
284 virtual void RequestFileSystems() OVERRIDE; 311 virtual void RequestFileSystems() OVERRIDE;
285 virtual void AddFileSystem() OVERRIDE; 312 virtual void AddFileSystem() OVERRIDE;
286 virtual void RemoveFileSystem(const std::string& file_system_path) OVERRIDE; 313 virtual void RemoveFileSystem(const std::string& file_system_path) OVERRIDE;
287 virtual void UpgradeDraggedFileSystemPermissions( 314 virtual void UpgradeDraggedFileSystemPermissions(
(...skipping 20 matching lines...) Expand all
308 int worked); 335 int worked);
309 void IndexingDone(int request_id, const std::string& file_system_path); 336 void IndexingDone(int request_id, const std::string& file_system_path);
310 void SearchCompleted(int request_id, 337 void SearchCompleted(int request_id,
311 const std::string& file_system_path, 338 const std::string& file_system_path,
312 const std::vector<std::string>& file_paths); 339 const std::vector<std::string>& file_paths);
313 void ShowDevToolsConfirmInfoBar(const base::string16& message, 340 void ShowDevToolsConfirmInfoBar(const base::string16& message,
314 const InfoBarCallback& callback); 341 const InfoBarCallback& callback);
315 342
316 void CreateDevToolsBrowser(); 343 void CreateDevToolsBrowser();
317 BrowserWindow* GetInspectedBrowserWindow(); 344 BrowserWindow* GetInspectedBrowserWindow();
318 bool IsInspectedBrowserPopup(); 345 void ScheduleShow(const DevToolsToggleAction& action);
319 void UpdateFrontendDockSide(); 346 void Show(const DevToolsToggleAction& action);
320 void ScheduleAction(const DevToolsToggleAction& action); 347 void DoAction(const DevToolsToggleAction& action);
321 void DoAction(); 348 void LoadCompleted();
349 void SetIsDockedAndShowImmediatelyForTest(bool is_docked);
322 void UpdateTheme(); 350 void UpdateTheme();
323 void AddDevToolsExtensionsToClient(); 351 void AddDevToolsExtensionsToClient();
324 void CallClientFunction(const std::string& function_name, 352 void CallClientFunction(const std::string& function_name,
325 const base::Value* arg1, 353 const base::Value* arg1,
326 const base::Value* arg2, 354 const base::Value* arg2,
327 const base::Value* arg3); 355 const base::Value* arg3);
328 void UpdateBrowserToolbar(); 356 void UpdateBrowserToolbar();
329 bool IsDocked();
330 void Restore();
331 content::WebContents* GetInspectedWebContents(); 357 content::WebContents* GetInspectedWebContents();
332 void DocumentOnLoadCompletedInMainFrame(); 358 void DocumentOnLoadCompletedInMainFrame();
333 359
334 class InspectedWebContentsObserver; 360 class InspectedWebContentsObserver;
335 scoped_ptr<InspectedWebContentsObserver> inspected_contents_observer_; 361 scoped_ptr<InspectedWebContentsObserver> inspected_contents_observer_;
336 class FrontendWebContentsObserver; 362 class FrontendWebContentsObserver;
337 friend class FrontendWebContentsObserver; 363 friend class FrontendWebContentsObserver;
338 scoped_ptr<FrontendWebContentsObserver> frontend_contents_observer_; 364 scoped_ptr<FrontendWebContentsObserver> frontend_contents_observer_;
339 365
340 Profile* profile_; 366 Profile* profile_;
341 content::WebContents* web_contents_; 367 content::WebContents* web_contents_;
342 Browser* browser_; 368 Browser* browser_;
343 // TODO(dgozman): move dock side knowledge entirely to frontend. 369 bool is_docked_;
344 DevToolsDockSide dock_side_; 370 bool can_dock_;
345 bool is_loaded_; 371 LoadState load_state_;
346 DevToolsToggleAction action_on_load_; 372 DevToolsToggleAction action_on_load_;
373 bool ignore_set_is_docked_for_test_;
347 content::NotificationRegistrar registrar_; 374 content::NotificationRegistrar registrar_;
348 scoped_ptr<content::DevToolsClientHost> frontend_host_; 375 scoped_ptr<content::DevToolsClientHost> frontend_host_;
349 scoped_ptr<DevToolsFileHelper> file_helper_; 376 scoped_ptr<DevToolsFileHelper> file_helper_;
350 scoped_refptr<DevToolsFileSystemIndexer> file_system_indexer_; 377 scoped_refptr<DevToolsFileSystemIndexer> file_system_indexer_;
351 typedef std::map< 378 typedef std::map<
352 int, 379 int,
353 scoped_refptr<DevToolsFileSystemIndexer::FileSystemIndexingJob> > 380 scoped_refptr<DevToolsFileSystemIndexer::FileSystemIndexingJob> >
354 IndexingJobsMap; 381 IndexingJobsMap;
355 IndexingJobsMap indexing_jobs_; 382 IndexingJobsMap indexing_jobs_;
356 gfx::Insets contents_insets_; 383 gfx::Insets contents_insets_;
357 DevToolsDockSide dock_side_before_minimized_;
358 // True if we're in the process of handling a beforeunload event originating 384 // True if we're in the process of handling a beforeunload event originating
359 // from the inspected webcontents, see InterceptPageBeforeUnload for details. 385 // from the inspected webcontents, see InterceptPageBeforeUnload for details.
360 bool intercepted_page_beforeunload_; 386 bool intercepted_page_beforeunload_;
361 387
362 scoped_ptr<DevToolsEmbedderMessageDispatcher> embedder_message_dispatcher_; 388 scoped_ptr<DevToolsEmbedderMessageDispatcher> embedder_message_dispatcher_;
363 base::WeakPtrFactory<DevToolsWindow> weak_factory_; 389 base::WeakPtrFactory<DevToolsWindow> weak_factory_;
364 DISALLOW_COPY_AND_ASSIGN(DevToolsWindow); 390 DISALLOW_COPY_AND_ASSIGN(DevToolsWindow);
365 }; 391 };
366 392
367 #endif // CHROME_BROWSER_DEVTOOLS_DEVTOOLS_WINDOW_H_ 393 #endif // CHROME_BROWSER_DEVTOOLS_DEVTOOLS_WINDOW_H_
OLDNEW
« no previous file with comments | « chrome/browser/devtools/devtools_toggle_action.cc ('k') | chrome/browser/devtools/devtools_window.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698