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

Side by Side Diff: third_party/WebKit/Source/bindings/core/v8/WindowProxy.cpp

Issue 2737553007: Duplicate WindowProxy::disposeContext() into subclasses. (Closed)
Patch Set: Created 3 years, 9 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) 2008, 2009, 2011 Google Inc. All rights reserved. 2 * Copyright (C) 2008, 2009, 2011 Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * 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 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
54 54
55 WindowProxy::WindowProxy(v8::Isolate* isolate, 55 WindowProxy::WindowProxy(v8::Isolate* isolate,
56 Frame& frame, 56 Frame& frame,
57 RefPtr<DOMWrapperWorld> world) 57 RefPtr<DOMWrapperWorld> world)
58 : m_isolate(isolate), 58 : m_isolate(isolate),
59 m_frame(frame), 59 m_frame(frame),
60 60
61 m_world(std::move(world)), 61 m_world(std::move(world)),
62 m_lifecycle(Lifecycle::ContextUninitialized) {} 62 m_lifecycle(Lifecycle::ContextUninitialized) {}
63 63
64 void WindowProxy::disposeContext(GlobalDetachmentBehavior behavior) {
65 DCHECK(m_lifecycle == Lifecycle::ContextInitialized);
66
67 if (behavior == DetachGlobal) {
68 v8::Local<v8::Context> context = m_scriptState->context();
69 // Clean up state on the global proxy, which will be reused.
70 if (!m_globalProxy.isEmpty()) {
71 // TODO(yukishiino): This DCHECK failed on Canary (M57) and Dev (M56).
72 // We need to figure out why m_globalProxy != context->Global().
73 DCHECK(m_globalProxy == context->Global());
74 DCHECK_EQ(toScriptWrappable(context->Global()),
75 toScriptWrappable(
76 context->Global()->GetPrototype().As<v8::Object>()));
77 m_globalProxy.get().SetWrapperClassId(0);
78 }
79 V8DOMWrapper::clearNativeInfo(m_isolate, context->Global());
80 m_scriptState->detachGlobalObject();
81 }
82
83 m_scriptState->disposePerContextData();
84
85 // It's likely that disposing the context has created a lot of
86 // garbage. Notify V8 about this so it'll have a chance of cleaning
87 // it up when idle.
88 V8GCForContextDispose::instance().notifyContextDisposed(
89 m_frame->isMainFrame());
90
91 DCHECK(m_lifecycle == Lifecycle::ContextInitialized);
92 m_lifecycle = Lifecycle::ContextDetached;
93 }
94
95 void WindowProxy::clearForClose() { 64 void WindowProxy::clearForClose() {
96 disposeContext(DoNotDetachGlobal); 65 disposeContext(DoNotDetachGlobal);
97 } 66 }
98 67
99 void WindowProxy::clearForNavigation() { 68 void WindowProxy::clearForNavigation() {
100 disposeContext(DetachGlobal); 69 disposeContext(DetachGlobal);
101 } 70 }
102 71
103 v8::Local<v8::Object> WindowProxy::globalIfNotDetached() { 72 v8::Local<v8::Object> WindowProxy::globalIfNotDetached() {
104 if (m_lifecycle == Lifecycle::ContextInitialized) { 73 if (m_lifecycle == Lifecycle::ContextInitialized) {
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
170 // it won't be able to reach the outer window via its global object. 139 // it won't be able to reach the outer window via its global object.
171 void WindowProxy::initializeIfNeeded() { 140 void WindowProxy::initializeIfNeeded() {
172 // TODO(haraken): It is wrong to re-initialize an already detached window 141 // TODO(haraken): It is wrong to re-initialize an already detached window
173 // proxy. This must be 'if(m_lifecycle == Lifecycle::ContextUninitialized)'. 142 // proxy. This must be 'if(m_lifecycle == Lifecycle::ContextUninitialized)'.
174 if (m_lifecycle != Lifecycle::ContextInitialized) { 143 if (m_lifecycle != Lifecycle::ContextInitialized) {
175 initialize(); 144 initialize();
176 } 145 }
177 } 146 }
178 147
179 } // namespace blink 148 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698