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

Side by Side Diff: Source/core/frame/LocalDOMWindow.cpp

Issue 861773003: Inform the WebFrameClient of BeforeUnload/Unload handlers (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 5 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 /* 1 /*
2 * Copyright (C) 2006, 2007, 2008, 2010 Apple Inc. All rights reserved. 2 * Copyright (C) 2006, 2007, 2008, 2010 Apple Inc. All rights reserved.
3 * Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies) 3 * Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies)
4 * 4 *
5 * Redistribution and use in source and binary forms, with or without 5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions 6 * modification, are permitted provided that the following conditions
7 * are met: 7 * are met:
8 * 1. Redistributions of source code must retain the above copyright 8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright 10 * 2. Redistributions in binary form must reproduce the above copyright
(...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after
224 DEFINE_STATIC_LOCAL(DOMWindowSet, windowsWithBeforeUnloadEventListeners, ()) ; 224 DEFINE_STATIC_LOCAL(DOMWindowSet, windowsWithBeforeUnloadEventListeners, ()) ;
225 return windowsWithBeforeUnloadEventListeners; 225 return windowsWithBeforeUnloadEventListeners;
226 } 226 }
227 227
228 static void addUnloadEventListener(LocalDOMWindow* domWindow) 228 static void addUnloadEventListener(LocalDOMWindow* domWindow)
229 { 229 {
230 DOMWindowSet& set = windowsWithUnloadEventListeners(); 230 DOMWindowSet& set = windowsWithUnloadEventListeners();
231 if (set.isEmpty()) 231 if (set.isEmpty())
232 disableSuddenTermination(); 232 disableSuddenTermination();
233 set.add(domWindow); 233 set.add(domWindow);
234 domWindow->frame()->loader().client()->suddenTerminationDisablerChanged(
235 1, FrameLoaderClient::UnloadHandler);
234 } 236 }
235 237
236 static void removeUnloadEventListener(LocalDOMWindow* domWindow) 238 static void removeUnloadEventListener(LocalDOMWindow* domWindow)
237 { 239 {
238 DOMWindowSet& set = windowsWithUnloadEventListeners(); 240 DOMWindowSet& set = windowsWithUnloadEventListeners();
239 DOMWindowSet::iterator it = set.find(domWindow); 241 DOMWindowSet::iterator it = set.find(domWindow);
240 if (it == set.end()) 242 if (it == set.end())
241 return; 243 return;
242 set.remove(it); 244 set.remove(it);
243 if (set.isEmpty()) 245 if (set.isEmpty())
244 enableSuddenTermination(); 246 enableSuddenTermination();
Nate Chapin 2015/01/20 18:46:49 Will we eventually be able to remove these enable/
clamy 2015/01/21 13:46:31 Yes, when the chromium side patch lands we should
Nate Chapin 2015/01/21 19:51:42 Interesting, I would have thought that local stora
247 domWindow->frame()->loader().client()->suddenTerminationDisablerChanged(
Nate Chapin 2015/01/20 18:46:49 Is this safe? domWindow->frame() can be null at ve
clamy 2015/01/21 13:46:31 In that case I added a check for domWindow->frame(
Nate Chapin 2015/01/21 19:51:42 I did a quick look and didn't see anything that wo
248 -1, FrameLoaderClient::UnloadHandler);
245 } 249 }
246 250
247 static void removeAllUnloadEventListeners(LocalDOMWindow* domWindow) 251 static void removeAllUnloadEventListeners(LocalDOMWindow* domWindow)
248 { 252 {
249 DOMWindowSet& set = windowsWithUnloadEventListeners(); 253 DOMWindowSet& set = windowsWithUnloadEventListeners();
250 DOMWindowSet::iterator it = set.find(domWindow); 254 DOMWindowSet::iterator it = set.find(domWindow);
251 if (it == set.end()) 255 if (it == set.end())
252 return; 256 return;
257 int numHandlers = set.count(domWindow);
253 set.removeAll(it); 258 set.removeAll(it);
254 if (set.isEmpty()) 259 if (set.isEmpty())
255 enableSuddenTermination(); 260 enableSuddenTermination();
261 domWindow->frame()->loader().client()->suddenTerminationDisablerChanged(
262 -numHandlers, FrameLoaderClient::UnloadHandler);
256 } 263 }
257 264
258 static void addBeforeUnloadEventListener(LocalDOMWindow* domWindow) 265 static void addBeforeUnloadEventListener(LocalDOMWindow* domWindow)
259 { 266 {
260 DOMWindowSet& set = windowsWithBeforeUnloadEventListeners(); 267 DOMWindowSet& set = windowsWithBeforeUnloadEventListeners();
261 if (set.isEmpty()) 268 if (set.isEmpty())
262 disableSuddenTermination(); 269 disableSuddenTermination();
263 set.add(domWindow); 270 set.add(domWindow);
271 domWindow->frame()->loader().client()->suddenTerminationDisablerChanged(
272 1, FrameLoaderClient::BeforeUnloadHandler);
264 } 273 }
265 274
266 static void removeBeforeUnloadEventListener(LocalDOMWindow* domWindow) 275 static void removeBeforeUnloadEventListener(LocalDOMWindow* domWindow)
267 { 276 {
268 DOMWindowSet& set = windowsWithBeforeUnloadEventListeners(); 277 DOMWindowSet& set = windowsWithBeforeUnloadEventListeners();
269 DOMWindowSet::iterator it = set.find(domWindow); 278 DOMWindowSet::iterator it = set.find(domWindow);
270 if (it == set.end()) 279 if (it == set.end())
271 return; 280 return;
272 set.remove(it); 281 set.remove(it);
273 if (set.isEmpty()) 282 if (set.isEmpty())
274 enableSuddenTermination(); 283 enableSuddenTermination();
284 domWindow->frame()->loader().client()->suddenTerminationDisablerChanged(
285 -1, FrameLoaderClient::BeforeUnloadHandler);
275 } 286 }
276 287
277 static void removeAllBeforeUnloadEventListeners(LocalDOMWindow* domWindow) 288 static void removeAllBeforeUnloadEventListeners(LocalDOMWindow* domWindow)
278 { 289 {
279 DOMWindowSet& set = windowsWithBeforeUnloadEventListeners(); 290 DOMWindowSet& set = windowsWithBeforeUnloadEventListeners();
280 DOMWindowSet::iterator it = set.find(domWindow); 291 DOMWindowSet::iterator it = set.find(domWindow);
281 if (it == set.end()) 292 if (it == set.end())
282 return; 293 return;
294 int numHandlers = set.count(domWindow);
283 set.removeAll(it); 295 set.removeAll(it);
284 if (set.isEmpty()) 296 if (set.isEmpty())
285 enableSuddenTermination(); 297 enableSuddenTermination();
298 domWindow->frame()->loader().client()->suddenTerminationDisablerChanged(
299 -numHandlers, FrameLoaderClient::BeforeUnloadHandler);
286 } 300 }
287 301
288 static bool allowsBeforeUnloadListeners(LocalDOMWindow* window) 302 static bool allowsBeforeUnloadListeners(LocalDOMWindow* window)
289 { 303 {
290 ASSERT_ARG(window, window); 304 ASSERT_ARG(window, window);
291 LocalFrame* frame = window->frame(); 305 LocalFrame* frame = window->frame();
292 if (!frame) 306 if (!frame)
293 return false; 307 return false;
294 return frame->isMainFrame(); 308 return frame->isMainFrame();
295 } 309 }
(...skipping 1619 matching lines...) Expand 10 before | Expand all | Expand 10 after
1915 return m_frameObserver->frame(); 1929 return m_frameObserver->frame();
1916 } 1930 }
1917 1931
1918 v8::Handle<v8::Object> LocalDOMWindow::wrap(v8::Handle<v8::Object> creationConte xt, v8::Isolate* isolate) 1932 v8::Handle<v8::Object> LocalDOMWindow::wrap(v8::Handle<v8::Object> creationConte xt, v8::Isolate* isolate)
1919 { 1933 {
1920 ASSERT_NOT_REACHED(); // LocalDOMWindow has [Custom=ToV8]. 1934 ASSERT_NOT_REACHED(); // LocalDOMWindow has [Custom=ToV8].
1921 return v8::Handle<v8::Object>(); 1935 return v8::Handle<v8::Object>();
1922 } 1936 }
1923 1937
1924 } // namespace blink 1938 } // namespace blink
OLDNEW
« no previous file with comments | « no previous file | Source/core/loader/FrameLoaderClient.h » ('j') | Source/core/loader/FrameLoaderClient.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698