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

Side by Side Diff: Source/bindings/core/v8/custom/V8InjectedScriptManager.cpp

Issue 452043002: InjectedScriptManager::CallbackData should be disposed when an associated worker thread terminates (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 6 years, 4 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
« no previous file with comments | « no previous file | Source/core/inspector/InjectedScriptManager.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2012 Google Inc. All rights reserved. 2 * Copyright (C) 2012 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 28 matching lines...) Expand all
39 #include "bindings/core/v8/V8InjectedScriptHost.h" 39 #include "bindings/core/v8/V8InjectedScriptHost.h"
40 #include "bindings/core/v8/V8ObjectConstructor.h" 40 #include "bindings/core/v8/V8ObjectConstructor.h"
41 #include "bindings/core/v8/V8ScriptRunner.h" 41 #include "bindings/core/v8/V8ScriptRunner.h"
42 #include "bindings/core/v8/V8Window.h" 42 #include "bindings/core/v8/V8Window.h"
43 #include "core/frame/LocalDOMWindow.h" 43 #include "core/frame/LocalDOMWindow.h"
44 #include "core/inspector/InjectedScriptHost.h" 44 #include "core/inspector/InjectedScriptHost.h"
45 #include "wtf/RefPtr.h" 45 #include "wtf/RefPtr.h"
46 46
47 namespace blink { 47 namespace blink {
48 48
49 struct InjectedScriptManager::CallbackData { 49 InjectedScriptManager::CallbackData* InjectedScriptManager::createCallbackData(I njectedScriptManager* injectedScriptManager)
50 ScopedPersistent<v8::Object> handle; 50 {
51 RefPtrWillBePersistent<InjectedScriptHost> host; 51 OwnPtr<InjectedScriptManager::CallbackData> callbackData = adoptPtr(new Inje ctedScriptManager::CallbackData());
52 }; 52 InjectedScriptManager::CallbackData* callbackDataPtr = callbackData.get();
53 callbackData->injectedScriptManager = injectedScriptManager;
54 m_callbackDataSet.add(callbackData.release());
55 return callbackDataPtr;
56 }
53 57
54 static v8::Local<v8::Object> createInjectedScriptHostV8Wrapper(InjectedScriptHos t* host, v8::Isolate* isolate) 58 void InjectedScriptManager::removeCallbackData(InjectedScriptManager::CallbackDa ta* callbackData)
55 { 59 {
56 v8::Local<v8::Function> function = V8InjectedScriptHost::domTemplate(isolate )->GetFunction(); 60 fprintf(stderr, "b %p\n", callbackData);
aandrey 2014/08/11 07:36:17 this also got commited
haraken 2014/08/11 07:40:20 oh, sorry. Let me fix it asap.
57 if (function.IsEmpty()) { 61 ASSERT(m_callbackDataSet.contains(callbackData));
58 // Return if allocation failed. 62 fprintf(stderr, "c %p\n", callbackData);
59 return v8::Local<v8::Object>(); 63 m_callbackDataSet.remove(callbackData);
60 } 64 fprintf(stderr, "d %p\n", callbackData);
61 v8::Local<v8::Object> instanceTemplate = V8ObjectConstructor::newInstance(is olate, function); 65 }
62 if (instanceTemplate.IsEmpty()) { 66
63 // Avoid setting the wrapper if allocation failed. 67 static v8::Local<v8::Object> createInjectedScriptHostV8Wrapper(PassRefPtrWillBeR awPtr<InjectedScriptHost> host, InjectedScriptManager* injectedScriptManager, v8 ::Handle<v8::Object> creationContext, v8::Isolate* isolate)
64 return v8::Local<v8::Object>(); 68 {
65 } 69 ASSERT(host);
66 #if ENABLE(OILPAN) 70
67 V8DOMWrapper::setNativeInfoWithPersistentHandle(instanceTemplate, &V8Injecte dScriptHost::wrapperTypeInfo, host, new Persistent<InjectedScriptHost>(host)); 71 v8::Handle<v8::Object> wrapper = V8DOMWrapper::createWrapper(creationContext , &V8InjectedScriptHost::wrapperTypeInfo, V8InjectedScriptHost::toInternalPointe r(host.get()), isolate);
68 #else 72 if (UNLIKELY(wrapper.IsEmpty()))
69 V8DOMWrapper::setNativeInfo(instanceTemplate, &V8InjectedScriptHost::wrapper TypeInfo, host); 73 return wrapper;
70 #endif 74
71 // Create a weak reference to the v8 wrapper of InspectorBackend to deref 75 // Create a weak reference to the v8 wrapper of InspectorBackend to deref
72 // InspectorBackend when the wrapper is garbage collected. 76 // InspectorBackend when the wrapper is garbage collected.
73 InjectedScriptManager::CallbackData* data = new InjectedScriptManager::Callb ackData; 77 InjectedScriptManager::CallbackData* callbackData = injectedScriptManager->c reateCallbackData(injectedScriptManager);
74 data->host = host; 78 callbackData->host = host.get();
75 data->handle.set(isolate, instanceTemplate); 79 callbackData->handle.set(isolate, wrapper);
76 data->handle.setWeak(data, &InjectedScriptManager::setWeakCallback); 80 callbackData->handle.setWeak(callbackData, &InjectedScriptManager::setWeakCa llback);
77 return instanceTemplate; 81
82 #if ENABLE(OILPAN)
83 V8DOMWrapper::setNativeInfoWithPersistentHandle(wrapper, &V8InjectedScriptHo st::wrapperTypeInfo, V8InjectedScriptHost::toInternalPointer(host), &callbackDat a->host);
84 #else
85 V8DOMWrapper::setNativeInfo(wrapper, &V8InjectedScriptHost::wrapperTypeInfo, V8InjectedScriptHost::toInternalPointer(host.get()));
86 #endif
87 ASSERT(V8DOMWrapper::isDOMWrapper(wrapper));
88 return wrapper;
78 } 89 }
79 90
80 ScriptValue InjectedScriptManager::createInjectedScript(const String& scriptSour ce, ScriptState* inspectedScriptState, int id) 91 ScriptValue InjectedScriptManager::createInjectedScript(const String& scriptSour ce, ScriptState* inspectedScriptState, int id)
81 { 92 {
82 v8::Isolate* isolate = inspectedScriptState->isolate(); 93 v8::Isolate* isolate = inspectedScriptState->isolate();
83 ScriptState::Scope scope(inspectedScriptState); 94 ScriptState::Scope scope(inspectedScriptState);
84 95
85 // Call custom code to create InjectedScripHost wrapper specific for the con text 96 // Call custom code to create InjectedScripHost wrapper specific for the con text
86 // instead of calling toV8() that would create the 97 // instead of calling toV8() that would create the
87 // wrapper in the current context. 98 // wrapper in the current context.
88 // FIXME: make it possible to use generic bindings factory for InjectedScrip tHost. 99 // FIXME: make it possible to use generic bindings factory for InjectedScrip tHost.
89 v8::Local<v8::Object> scriptHostWrapper = createInjectedScriptHostV8Wrapper( m_injectedScriptHost.get(), inspectedScriptState->isolate()); 100 v8::Local<v8::Object> scriptHostWrapper = createInjectedScriptHostV8Wrapper( m_injectedScriptHost, this, inspectedScriptState->context()->Global(), inspected ScriptState->isolate());
90 if (scriptHostWrapper.IsEmpty()) 101 if (scriptHostWrapper.IsEmpty())
91 return ScriptValue(); 102 return ScriptValue();
92 103
93 // Inject javascript into the context. The compiled script is supposed to ev aluate into 104 // Inject javascript into the context. The compiled script is supposed to ev aluate into
94 // a single anonymous function(it's anonymous to avoid cluttering the global object with 105 // a single anonymous function(it's anonymous to avoid cluttering the global object with
95 // inspector's stuff) the function is called a few lines below with Injected ScriptHost wrapper, 106 // inspector's stuff) the function is called a few lines below with Injected ScriptHost wrapper,
96 // injected script id and explicit reference to the inspected global object. The function is expected 107 // injected script id and explicit reference to the inspected global object. The function is expected
97 // to create and configure InjectedScript instance that is going to be used by the inspector. 108 // to create and configure InjectedScript instance that is going to be used by the inspector.
98 v8::Local<v8::Value> value = V8ScriptRunner::compileAndRunInternalScript(v8S tring(isolate, scriptSource), isolate); 109 v8::Local<v8::Value> value = V8ScriptRunner::compileAndRunInternalScript(v8S tring(isolate, scriptSource), isolate);
99 ASSERT(!value.IsEmpty()); 110 ASSERT(!value.IsEmpty());
(...skipping 14 matching lines...) Expand all
114 v8::Handle<v8::Object> holder = V8Window::findInstanceInPrototypeChain(globa l, scriptState->isolate()); 125 v8::Handle<v8::Object> holder = V8Window::findInstanceInPrototypeChain(globa l, scriptState->isolate());
115 if (holder.IsEmpty()) 126 if (holder.IsEmpty())
116 return false; 127 return false;
117 LocalFrame* frame = V8Window::toNative(holder)->frame(); 128 LocalFrame* frame = V8Window::toNative(holder)->frame();
118 129
119 return BindingSecurity::shouldAllowAccessToFrame(scriptState->isolate(), fra me, DoNotReportSecurityError); 130 return BindingSecurity::shouldAllowAccessToFrame(scriptState->isolate(), fra me, DoNotReportSecurityError);
120 } 131 }
121 132
122 void InjectedScriptManager::setWeakCallback(const v8::WeakCallbackData<v8::Objec t, InjectedScriptManager::CallbackData>& data) 133 void InjectedScriptManager::setWeakCallback(const v8::WeakCallbackData<v8::Objec t, InjectedScriptManager::CallbackData>& data)
123 { 134 {
124 data.GetParameter()->handle.clear(); 135 InjectedScriptManager::CallbackData* callbackData = data.GetParameter();
125 data.GetParameter()->host.clear(); 136 fprintf(stderr, "a %p\n", callbackData);
126 delete data.GetParameter(); 137 callbackData->injectedScriptManager->removeCallbackData(callbackData);
127 } 138 }
128 139
129 } // namespace blink 140 } // namespace blink
OLDNEW
« no previous file with comments | « no previous file | Source/core/inspector/InjectedScriptManager.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698