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 |
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
123 int GetHeight(int container_height); | 123 int GetHeight(int container_height); |
124 | 124 |
125 // Stores preferred devtools window width for this instance. | 125 // Stores preferred devtools window width for this instance. |
126 void SetWidth(int width); | 126 void SetWidth(int width); |
127 | 127 |
128 // Stores preferred devtools window height for this instance. | 128 // Stores preferred devtools window height for this instance. |
129 void SetHeight(int height); | 129 void SetHeight(int height); |
130 | 130 |
131 void Show(const DevToolsToggleAction& action); | 131 void Show(const DevToolsToggleAction& action); |
132 | 132 |
| 133 // BeforeUnload interception //////////////////////////////////////////////// |
| 134 |
| 135 // 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 |
| 137 // 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 |
| 139 // it. This way 2 dialogs may be displayed: one from the devtools asking the |
| 140 // user to confirm that they're ok with their devtools edits going away and |
| 141 // another from the webpage as the result of its beforeunload handler. |
| 142 // The following set of methods handle beforeunload event flow through |
| 143 // devtools window. When the |contents| with devtools opened on them are |
| 144 // getting closed, the following sequence of calls takes place: |
| 145 // 1. |DevToolsWindow::InterceptPageBeforeUnload| is called and indicates |
| 146 // whether devtools intercept the beforeunload event. |
| 147 // If InterceptPageBeforeUnload() returns true then the following steps |
| 148 // will take place; otherwise only step 4 will be reached and none of the |
| 149 // corresponding functions in steps 2 & 3 will get called. |
| 150 // 2. |DevToolsWindow::InterceptPageBeforeUnload| fires beforeunload event |
| 151 // for devtools frontend, which will asynchronously call |
| 152 // |WebContentsDelegate::BeforeUnloadFired| method. |
| 153 // In case of docked devtools window, devtools are set as a delegate for |
| 154 // its frontend, so method |DevToolsWindow::BeforeUnloadFired| will be |
| 155 // called directly. |
| 156 // If devtools window is undocked it's not set as the delegate so the call |
| 157 // to BeforeUnloadFired is proxied through HandleBeforeUnload() rather |
| 158 // than getting called directly. |
| 159 // 3a. If |DevToolsWindow::BeforeUnloadFired| is called with |proceed|=false |
| 160 // it calls throught to the content's BeforeUnloadFired(), which from the |
| 161 // WebContents perspective looks the same as the |content|'s own |
| 162 // beforeunload dialog having had it's 'stay on this page' button clicked. |
| 163 // 3b. If |proceed| = true, then it fires beforeunload event on |contents| |
| 164 // and everything proceeds as it normally would without the Devtools |
| 165 // interception. |
| 166 // 4. If the user cancels the dialog put up by either the WebContents or |
| 167 // devtools frontend, then |contents|'s |BeforeUnloadFired| callback is |
| 168 // called with the proceed argument set to false, this causes |
| 169 // |DevToolsWindow::OnPageCloseCancelled| to be called. |
| 170 |
| 171 // Devtools window in undocked state is not set as a delegate of |
| 172 // its frontend. Instead, an instance of browser is set as the delegate, and |
| 173 // thus beforeunload event callback from devtools frontend is not delivered |
| 174 // to the instance of devtools window, which is solely responsible for |
| 175 // managing custom beforeunload event flow. |
| 176 // This is a helper method to route callback from |
| 177 // |Browser::BeforeUnloadFired| back to |DevToolsWindow::BeforeUnloadFired|. |
| 178 // * |proceed| - true if the user clicked 'ok' in the beforeunload dialog, |
| 179 // false otherwise. |
| 180 // * |proceed_to_fire_unload| - output parameter, whether we should continue |
| 181 // to fire the unload event or stop things here. |
| 182 // Returns true if devtools window is in a state of intercepting beforeunload |
| 183 // event and if it will manage unload process on its own. |
| 184 static bool HandleBeforeUnload(content::WebContents* contents, |
| 185 bool proceed, |
| 186 bool* proceed_to_fire_unload); |
| 187 |
| 188 // Returns true if this contents beforeunload event was intercepted by |
| 189 // devtools and false otherwise. If the event was intercepted, caller should |
| 190 // not fire beforeunlaod event on |contents| itself as devtools window will |
| 191 // take care of it, otherwise caller should continue handling the event as |
| 192 // usual. |
| 193 static bool InterceptPageBeforeUnload(content::WebContents* contents); |
| 194 |
| 195 // Returns true if devtools browser has already fired its beforeunload event |
| 196 // as a result of beforeunload event interception. |
| 197 static bool HasFiredBeforeUnloadEventForDevToolsBrowser(Browser* browser); |
| 198 |
| 199 // Returns true if devtools window would like to hook beforeunload event |
| 200 // of this |contents|. |
| 201 static bool NeedsToInterceptBeforeUnload(content::WebContents* contents); |
| 202 |
| 203 // Notify devtools window that closing of |contents| was cancelled |
| 204 // by user. |
| 205 static void OnPageCloseCanceled(content::WebContents* contents); |
| 206 |
| 207 void SetDockSideForTest(DevToolsDockSide dock_side); |
| 208 |
133 private: | 209 private: |
134 friend class DevToolsControllerTest; | 210 friend class DevToolsControllerTest; |
135 | 211 |
136 DevToolsWindow(Profile* profile, | 212 DevToolsWindow(Profile* profile, |
137 const GURL& frontend_url, | 213 const GURL& frontend_url, |
138 content::RenderViewHost* inspected_rvh, | 214 content::RenderViewHost* inspected_rvh, |
139 DevToolsDockSide dock_side); | 215 DevToolsDockSide dock_side); |
140 | 216 |
141 static DevToolsWindow* Create(Profile* profile, | 217 static DevToolsWindow* Create(Profile* profile, |
142 const GURL& frontend_url, | 218 const GURL& frontend_url, |
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
274 scoped_ptr<DevToolsFileHelper> file_helper_; | 350 scoped_ptr<DevToolsFileHelper> file_helper_; |
275 scoped_refptr<DevToolsFileSystemIndexer> file_system_indexer_; | 351 scoped_refptr<DevToolsFileSystemIndexer> file_system_indexer_; |
276 typedef std::map< | 352 typedef std::map< |
277 int, | 353 int, |
278 scoped_refptr<DevToolsFileSystemIndexer::FileSystemIndexingJob> > | 354 scoped_refptr<DevToolsFileSystemIndexer::FileSystemIndexingJob> > |
279 IndexingJobsMap; | 355 IndexingJobsMap; |
280 IndexingJobsMap indexing_jobs_; | 356 IndexingJobsMap indexing_jobs_; |
281 int width_; | 357 int width_; |
282 int height_; | 358 int height_; |
283 DevToolsDockSide dock_side_before_minimized_; | 359 DevToolsDockSide dock_side_before_minimized_; |
| 360 // True if we're in the process of handling a beforeunload event originating |
| 361 // from the inspected webcontents, see InterceptPageBeforeUnload for details. |
| 362 bool intercepted_page_beforeunload_; |
284 | 363 |
285 scoped_ptr<DevToolsEmbedderMessageDispatcher> embedder_message_dispatcher_; | 364 scoped_ptr<DevToolsEmbedderMessageDispatcher> embedder_message_dispatcher_; |
286 base::WeakPtrFactory<DevToolsWindow> weak_factory_; | 365 base::WeakPtrFactory<DevToolsWindow> weak_factory_; |
287 DISALLOW_COPY_AND_ASSIGN(DevToolsWindow); | 366 DISALLOW_COPY_AND_ASSIGN(DevToolsWindow); |
288 }; | 367 }; |
289 | 368 |
290 #endif // CHROME_BROWSER_DEVTOOLS_DEVTOOLS_WINDOW_H_ | 369 #endif // CHROME_BROWSER_DEVTOOLS_DEVTOOLS_WINDOW_H_ |
OLD | NEW |