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

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

Issue 1149383005: DevTools: remove InjectedScriptHost.idl, implement the binding without generator (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 5 years, 6 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) 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 14 matching lines...) Expand all
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 */ 29 */
30 30
31 #include "config.h" 31 #include "config.h"
32 #include "core/inspector/InjectedScriptManager.h" 32 #include "core/inspector/InjectedScriptManager.h"
33 33
34 #include "bindings/core/v8/BindingSecurity.h" 34 #include "bindings/core/v8/BindingSecurity.h"
35 #include "bindings/core/v8/ScopedPersistent.h"
36 #include "bindings/core/v8/ScriptValue.h" 35 #include "bindings/core/v8/ScriptValue.h"
37 #include "bindings/core/v8/V8Binding.h"
38 #include "bindings/core/v8/V8Debugger.h"
39 #include "bindings/core/v8/V8InjectedScriptHost.h"
40 #include "bindings/core/v8/V8ObjectConstructor.h"
41 #include "bindings/core/v8/V8ScriptRunner.h" 36 #include "bindings/core/v8/V8ScriptRunner.h"
42 #include "bindings/core/v8/V8Window.h" 37 #include "bindings/core/v8/V8Window.h"
38 #include "bindings/core/v8/inspector/V8InjectedScriptHost.h"
43 #include "core/frame/LocalDOMWindow.h" 39 #include "core/frame/LocalDOMWindow.h"
44 #include "core/inspector/InjectedScriptHost.h" 40 #include "core/inspector/InjectedScriptHost.h"
45 #include "core/inspector/InjectedScriptNative.h" 41 #include "core/inspector/InjectedScriptNative.h"
46 #include "wtf/RefPtr.h" 42 #include "wtf/RefPtr.h"
47 43
48 namespace blink { 44 namespace blink {
49 45
50 InjectedScriptManager::CallbackData* InjectedScriptManager::createCallbackData()
51 {
52 OwnPtrWillBeRawPtr<InjectedScriptManager::CallbackData> callbackData = Injec tedScriptManager::CallbackData::create(this);
53 InjectedScriptManager::CallbackData* callbackDataPtr = callbackData.get();
54 m_callbackDataSet.add(callbackData.release());
55 return callbackDataPtr;
56 }
57
58 void InjectedScriptManager::removeCallbackData(InjectedScriptManager::CallbackDa ta* callbackData)
59 {
60 ASSERT(m_callbackDataSet.contains(callbackData));
61 callbackData->dispose();
62 m_callbackDataSet.remove(callbackData);
63 }
64
65 static v8::Local<v8::Object> createInjectedScriptHostV8Wrapper(v8::Isolate* isol ate, PassRefPtrWillBeRawPtr<InjectedScriptHost> host, InjectedScriptManager* inj ectedScriptManager, v8::Local<v8::Object> creationContext)
66 {
67 ASSERT(host);
68
69 v8::Local<v8::Object> wrapper = V8DOMWrapper::createWrapper(isolate, creatio nContext, &V8InjectedScriptHost::wrapperTypeInfo, host.get());
70 if (UNLIKELY(wrapper.IsEmpty()))
71 return wrapper;
72
73 // Create a weak reference to the v8 wrapper of InspectorBackend to deref
74 // InspectorBackend when the wrapper is garbage collected.
75 InjectedScriptManager::CallbackData* callbackData = injectedScriptManager->c reateCallbackData();
76 callbackData->host = host.get();
77 callbackData->handle.set(isolate, wrapper);
78 callbackData->handle.setWeak(callbackData, &InjectedScriptManager::setWeakCa llback);
79
80 V8DOMWrapper::setNativeInfo(wrapper, &V8InjectedScriptHost::wrapperTypeInfo, host.get());
81 ASSERT(V8DOMWrapper::hasInternalFieldsSet(wrapper));
82 return wrapper;
83 }
84
85 ScriptValue InjectedScriptManager::createInjectedScript(const String& scriptSour ce, ScriptState* inspectedScriptState, int id, InjectedScriptNative* injectedScr iptNative) 46 ScriptValue InjectedScriptManager::createInjectedScript(const String& scriptSour ce, ScriptState* inspectedScriptState, int id, InjectedScriptNative* injectedScr iptNative)
86 { 47 {
87 v8::Isolate* isolate = inspectedScriptState->isolate(); 48 v8::Isolate* isolate = inspectedScriptState->isolate();
88 ScriptState::Scope scope(inspectedScriptState); 49 ScriptState::Scope scope(inspectedScriptState);
89 50
90 // Call custom code to create InjectedScripHost wrapper specific for the con text 51 v8::Local<v8::FunctionTemplate> wrapperTemplate = m_injectedScriptHost->wrap perTemplate(isolate);
91 // instead of calling toV8() that would create the 52 if (wrapperTemplate.IsEmpty()) {
92 // wrapper in the current context. 53 wrapperTemplate = V8InjectedScriptHost::createWrapperTemplate(isolate);
93 // FIXME: make it possible to use generic bindings factory for InjectedScrip tHost. 54 m_injectedScriptHost->setWrapperTemplate(wrapperTemplate, isolate);
94 v8::Local<v8::Object> scriptHostWrapper = createInjectedScriptHostV8Wrapper( inspectedScriptState->isolate(), m_injectedScriptHost, this, inspectedScriptStat e->context()->Global()); 55 }
56
57 v8::Local<v8::Object> scriptHostWrapper = V8InjectedScriptHost::wrap(isolate , wrapperTemplate, m_injectedScriptHost);
95 if (scriptHostWrapper.IsEmpty()) 58 if (scriptHostWrapper.IsEmpty())
96 return ScriptValue(); 59 return ScriptValue();
97 60
98 injectedScriptNative->setOnInjectedScriptHost(scriptHostWrapper); 61 injectedScriptNative->setOnInjectedScriptHost(scriptHostWrapper);
99 62
100 // Inject javascript into the context. The compiled script is supposed to ev aluate into 63 // Inject javascript into the context. The compiled script is supposed to ev aluate into
101 // a single anonymous function(it's anonymous to avoid cluttering the global object with 64 // a single anonymous function(it's anonymous to avoid cluttering the global object with
102 // inspector's stuff) the function is called a few lines below with Injected ScriptHost wrapper, 65 // inspector's stuff) the function is called a few lines below with Injected ScriptHost wrapper,
103 // injected script id and explicit reference to the inspected global object. The function is expected 66 // injected script id and explicit reference to the inspected global object. The function is expected
104 // to create and configure InjectedScript instance that is going to be used by the inspector. 67 // to create and configure InjectedScript instance that is going to be used by the inspector.
(...skipping 17 matching lines...) Expand all
122 if (global.IsEmpty()) 85 if (global.IsEmpty())
123 return false; 86 return false;
124 v8::Local<v8::Object> holder = V8Window::findInstanceInPrototypeChain(global , scriptState->isolate()); 87 v8::Local<v8::Object> holder = V8Window::findInstanceInPrototypeChain(global , scriptState->isolate());
125 if (holder.IsEmpty()) 88 if (holder.IsEmpty())
126 return false; 89 return false;
127 LocalFrame* frame = toLocalDOMWindow(V8Window::toImpl(holder))->frame(); 90 LocalFrame* frame = toLocalDOMWindow(V8Window::toImpl(holder))->frame();
128 91
129 return BindingSecurity::shouldAllowAccessToFrame(scriptState->isolate(), fra me, DoNotReportSecurityError); 92 return BindingSecurity::shouldAllowAccessToFrame(scriptState->isolate(), fra me, DoNotReportSecurityError);
130 } 93 }
131 94
132 void InjectedScriptManager::setWeakCallback(const v8::WeakCallbackInfo<InjectedS criptManager::CallbackData>& data)
133 {
134 InjectedScriptManager::CallbackData* callbackData = data.GetParameter();
135 callbackData->injectedScriptManager->removeCallbackData(callbackData);
136 }
137
138 } // namespace blink 95 } // namespace blink
OLDNEW
« no previous file with comments | « Source/bindings/core/v8/custom/V8InjectedScriptHostCustom.cpp ('k') | Source/bindings/core/v8/custom/custom.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698