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

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

Issue 558213002: Simplify DOMWindowProperty and its unregistration. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Iterate instead Created 6 years, 3 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 | Annotate | Revision Log
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2011 Google, Inc. All Rights Reserved. 2 * Copyright (C) 2011 Google, Inc. All Rights Reserved.
3 * Copyright (C) 2012 Apple Inc. All Rights Reserved. 3 * Copyright (C) 2012 Apple Inc. All Rights Reserved.
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 16 matching lines...) Expand all
27 #include "config.h" 27 #include "config.h"
28 #include "core/frame/DOMWindowProperty.h" 28 #include "core/frame/DOMWindowProperty.h"
29 29
30 #include "core/frame/LocalDOMWindow.h" 30 #include "core/frame/LocalDOMWindow.h"
31 #include "core/frame/LocalFrame.h" 31 #include "core/frame/LocalFrame.h"
32 32
33 namespace blink { 33 namespace blink {
34 34
35 DOMWindowProperty::DOMWindowProperty(LocalFrame* frame) 35 DOMWindowProperty::DOMWindowProperty(LocalFrame* frame)
36 : m_frame(frame) 36 : m_frame(frame)
37 , m_associatedDOMWindow(nullptr)
38 { 37 {
39 // FIXME: For now it *is* acceptable for a DOMWindowProperty to be created w ith a null frame. 38 // FIXME: For now it *is* acceptable for a DOMWindowProperty to be created w ith a null frame.
40 // See fast/dom/navigator-detached-no-crash.html for the recipe. 39 // See fast/dom/navigator-detached-no-crash.html for the recipe.
41 // We should fix that. <rdar://problem/11567132> 40 // We should fix that. <rdar://problem/11567132>
42 if (m_frame) { 41 if (m_frame)
43 m_associatedDOMWindow = m_frame->domWindow(); 42 m_frame->domWindow()->registerProperty(this);
44 m_associatedDOMWindow->registerProperty(this);
45 }
46 } 43 }
47 44
48 #if !ENABLE(OILPAN) 45 DEFINE_EMPTY_DESTRUCTOR_WILL_BE_REMOVED(DOMWindowProperty);
49 DOMWindowProperty::~DOMWindowProperty()
50 {
51 if (m_associatedDOMWindow)
52 m_associatedDOMWindow->unregisterProperty(this);
53
54 m_associatedDOMWindow = nullptr;
55 m_frame = nullptr;
56 }
57 #endif
58 46
59 void DOMWindowProperty::willDestroyGlobalObjectInFrame() 47 void DOMWindowProperty::willDestroyGlobalObjectInFrame()
60 { 48 {
61 // If the property is getting this callback it must have been created with a LocalFrame/LocalDOMWindow and it should still have them. 49 // If the property is getting this callback it must have been created with a LocalFrame/LocalDOMWindow and it should still have them.
62 ASSERT(m_frame); 50 ASSERT(m_frame);
63 ASSERT(m_associatedDOMWindow);
64 51
65 // DOMWindowProperty lifetime isn't tied directly to the LocalDOMWindow itse lf so it is important that it unregister 52 // DOMWindowProperty's registered lifetime is controlled by LocalDOMWindow. After
66 // itself from any LocalDOMWindow it is associated with if that LocalDOMWind ow is going away. 53 // the willDestroyGlobalObjectInFrame() notifications, LocalDOMWindow clears out
67 if (m_associatedDOMWindow) 54 // all registrations. Hence no need to unregister.
68 m_associatedDOMWindow->unregisterProperty(this);
69 m_associatedDOMWindow = nullptr;
70 m_frame = nullptr; 55 m_frame = nullptr;
71 } 56 }
72 57
73 void DOMWindowProperty::willDetachGlobalObjectFromFrame() 58 void DOMWindowProperty::willDetachGlobalObjectFromFrame()
74 { 59 {
75 // If the property is getting this callback it must have been created with a LocalFrame/LocalDOMWindow and it should still have them. 60 // If the property is getting this callback it must have been created with a LocalFrame/LocalDOMWindow and it should still have them.
76 ASSERT(m_frame); 61 ASSERT(m_frame);
77 ASSERT(m_associatedDOMWindow);
78 } 62 }
79 63
80 void DOMWindowProperty::trace(Visitor* visitor) 64 } // namespace blink
81 {
82 visitor->trace(m_associatedDOMWindow);
83 }
84
85 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698