Chromium Code Reviews| 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 handling //////////////////////////////////////////////////// | |
|
jeremy
2013/11/12 10:52:46
nit: beforeunload interception ?
lushnikov
2013/11/12 13:37:37
Done.
| |
| 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 edits going away and another | |
| 141 // 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 | |
|
jeremy
2013/11/12 10:52:46
nit: "the devtools", also capitalization of devtoo
lushnikov
2013/11/12 13:37:37
Done.
| |
| 144 // getting closed, the following sequence of calls takes place: | |
| 145 // 1. Instead of firing beforeunload event on |contents|, | |
| 146 // method |DevToolsWindow::InterceptPageBeforeUnload| gets called. | |
| 147 // 2. DevTools fire beforeunload event for its own frontend and wait for ack, | |
| 148 // which by the means of |HandleBeforeUnload| helper method always hits | |
|
jeremy
2013/11/12 10:52:46
I'm not clear on the flow here - InterceptPageBefo
lushnikov
2013/11/12 13:37:37
Rewrote the comment with more details; should look
| |
| 149 // |DevToolsWindow::BeforeUnloadFired|. The ack has user decision | |
| 150 // whether he wants to close DevTools or not. | |
| 151 // 3a. If user decides not to close DevTools, callback method | |
| 152 // |WebContentsDelegate::BeforeUnloadFired| gets called on |contents| | |
| 153 // delegate with the |proceed| argument set to false. This looks as if | |
| 154 // |contents| got its beforeunload event fired and user rejected page | |
| 155 // close. | |
|
jeremy
2013/11/12 10:52:46
This is completely invisible from the web page's p
lushnikov
2013/11/12 13:37:37
That's right.
| |
| 156 // 3b. If user decides to close DevTools window, DevTools fire beforeunload | |
| 157 // event on |contents|. | |
|
jeremy
2013/11/12 10:52:46
add - "and everything proceeds as it normally woul
lushnikov
2013/11/12 13:37:37
Done.
| |
| 158 // 4. Whenever delegate of the |contents| gets |BeforeUnloadFired| callback | |
|
jeremy
2013/11/12 10:52:46
"If the user cancels the dialog put up by the WebC
lushnikov
2013/11/12 13:37:37
Slightly corrected detail; Done.
| |
| 159 // with |proceed| argument set to false, method | |
| 160 // |DevToolsWindow::OnPageCloseCancelled| gets called. | |
| 161 | |
| 162 // DevTools window in undocked state is not set as a delegate of | |
| 163 // its frontend. Instead, an instance of browser does, and thus | |
|
jeremy
2013/11/12 10:52:46
*"does" -> "is set as the delegate"
lushnikov
2013/11/12 13:37:37
Done.
| |
| 164 // beforeunload event callback from DevTools frontend is not delivered to | |
| 165 // the instance of DevTools window, which is solely responsible for managing | |
| 166 // custom beforeunload event flow. | |
| 167 // This is a helper method to route callback from | |
| 168 // |Browser::BeforeUnloadFired| back to |DevToolsWindow::BeforeUnloadFired|. | |
| 169 // Returns true if routing was successful. | |
|
jeremy
2013/11/12 10:52:46
Comment needs to document parameters and return va
lushnikov
2013/11/12 13:37:37
Done.
| |
| 170 static bool HandleBeforeUnload(content::WebContents* contents, | |
| 171 bool proceed, | |
| 172 bool* proceed_to_fire_unload); | |
| 173 | |
| 174 // This function returns true if there is a DevTools window inspecting | |
| 175 // given |contents| which would like to manage beforeunload event | |
| 176 // flow itself. In this case clients should not fire beforeunload | |
|
jeremy
2013/11/12 10:52:46
"manage beforeunload event flow itself" -> "interc
lushnikov
2013/11/12 13:37:37
Done.
| |
| 177 // event on |contents| themselfes as DevTools window will take care of it. | |
| 178 static bool InterceptPageBeforeUnload(content::WebContents* contents); | |
| 179 | |
| 180 // Returns true if DevTools browser window could be closed. | |
|
jeremy
2013/11/12 10:52:46
I assume this function returns true if there are n
lushnikov
2013/11/12 13:37:37
I renamed this method and put a more descriptive c
| |
| 181 static bool ShouldCloseDevToolsBrowser(Browser* browser); | |
| 182 | |
| 183 // Returns true if DevTools window would like to hook beforeunload event | |
| 184 // of this |contents|. | |
| 185 static bool NeedsToInterceptBeforeUnload(content::WebContents* contents); | |
| 186 | |
| 187 // Notify DevTools window that closing of |contents| was cancelled | |
| 188 // by user. | |
| 189 static void OnPageCloseCanceled(content::WebContents* contents); | |
| 190 | |
| 191 void SetDockSideForTest(DevToolsDockSide dock_side); | |
|
jeremy
2013/11/12 10:52:46
Thank you for writing up these comments, they make
| |
| 192 | |
| 133 private: | 193 private: |
| 134 friend class DevToolsControllerTest; | 194 friend class DevToolsControllerTest; |
| 135 | 195 |
| 136 DevToolsWindow(Profile* profile, | 196 DevToolsWindow(Profile* profile, |
| 137 const GURL& frontend_url, | 197 const GURL& frontend_url, |
| 138 content::RenderViewHost* inspected_rvh, | 198 content::RenderViewHost* inspected_rvh, |
| 139 DevToolsDockSide dock_side); | 199 DevToolsDockSide dock_side); |
| 140 | 200 |
| 141 static DevToolsWindow* Create(Profile* profile, | 201 static DevToolsWindow* Create(Profile* profile, |
| 142 const GURL& frontend_url, | 202 const GURL& frontend_url, |
| (...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 274 scoped_ptr<DevToolsFileHelper> file_helper_; | 334 scoped_ptr<DevToolsFileHelper> file_helper_; |
| 275 scoped_refptr<DevToolsFileSystemIndexer> file_system_indexer_; | 335 scoped_refptr<DevToolsFileSystemIndexer> file_system_indexer_; |
| 276 typedef std::map< | 336 typedef std::map< |
| 277 int, | 337 int, |
| 278 scoped_refptr<DevToolsFileSystemIndexer::FileSystemIndexingJob> > | 338 scoped_refptr<DevToolsFileSystemIndexer::FileSystemIndexingJob> > |
| 279 IndexingJobsMap; | 339 IndexingJobsMap; |
| 280 IndexingJobsMap indexing_jobs_; | 340 IndexingJobsMap indexing_jobs_; |
| 281 int width_; | 341 int width_; |
| 282 int height_; | 342 int height_; |
| 283 DevToolsDockSide dock_side_before_minimized_; | 343 DevToolsDockSide dock_side_before_minimized_; |
| 344 bool inspected_page_is_closing_; | |
| 284 | 345 |
| 285 scoped_ptr<DevToolsEmbedderMessageDispatcher> embedder_message_dispatcher_; | 346 scoped_ptr<DevToolsEmbedderMessageDispatcher> embedder_message_dispatcher_; |
| 286 base::WeakPtrFactory<DevToolsWindow> weak_factory_; | 347 base::WeakPtrFactory<DevToolsWindow> weak_factory_; |
| 287 DISALLOW_COPY_AND_ASSIGN(DevToolsWindow); | 348 DISALLOW_COPY_AND_ASSIGN(DevToolsWindow); |
| 288 }; | 349 }; |
| 289 | 350 |
| 290 #endif // CHROME_BROWSER_DEVTOOLS_DEVTOOLS_WINDOW_H_ | 351 #endif // CHROME_BROWSER_DEVTOOLS_DEVTOOLS_WINDOW_H_ |
| OLD | NEW |