OLD | NEW |
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 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
55 return callbackDataPtr; | 55 return callbackDataPtr; |
56 } | 56 } |
57 | 57 |
58 void InjectedScriptManager::removeCallbackData(InjectedScriptManager::CallbackDa
ta* callbackData) | 58 void InjectedScriptManager::removeCallbackData(InjectedScriptManager::CallbackDa
ta* callbackData) |
59 { | 59 { |
60 ASSERT(m_callbackDataSet.contains(callbackData)); | 60 ASSERT(m_callbackDataSet.contains(callbackData)); |
61 callbackData->dispose(); | 61 callbackData->dispose(); |
62 m_callbackDataSet.remove(callbackData); | 62 m_callbackDataSet.remove(callbackData); |
63 } | 63 } |
64 | 64 |
65 static v8::Local<v8::Object> createInjectedScriptHostV8Wrapper(PassRefPtrWillBeR
awPtr<InjectedScriptHost> host, InjectedScriptManager* injectedScriptManager, v8
::Local<v8::Object> creationContext, v8::Isolate* isolate) | 65 static v8::Local<v8::Object> createInjectedScriptHostV8Wrapper(v8::Isolate* isol
ate, PassRefPtrWillBeRawPtr<InjectedScriptHost> host, InjectedScriptManager* inj
ectedScriptManager, v8::Local<v8::Object> creationContext) |
66 { | 66 { |
67 ASSERT(host); | 67 ASSERT(host); |
68 | 68 |
69 v8::Local<v8::Object> wrapper = V8DOMWrapper::createWrapper(isolate, creatio
nContext, &V8InjectedScriptHost::wrapperTypeInfo, host.get()); | 69 v8::Local<v8::Object> wrapper = V8DOMWrapper::createWrapper(isolate, creatio
nContext, &V8InjectedScriptHost::wrapperTypeInfo, host.get()); |
70 if (UNLIKELY(wrapper.IsEmpty())) | 70 if (UNLIKELY(wrapper.IsEmpty())) |
71 return wrapper; | 71 return wrapper; |
72 | 72 |
73 // Create a weak reference to the v8 wrapper of InspectorBackend to deref | 73 // Create a weak reference to the v8 wrapper of InspectorBackend to deref |
74 // InspectorBackend when the wrapper is garbage collected. | 74 // InspectorBackend when the wrapper is garbage collected. |
75 InjectedScriptManager::CallbackData* callbackData = injectedScriptManager->c
reateCallbackData(injectedScriptManager); | 75 InjectedScriptManager::CallbackData* callbackData = injectedScriptManager->c
reateCallbackData(injectedScriptManager); |
76 callbackData->host = host.get(); | 76 callbackData->host = host.get(); |
77 callbackData->handle.set(isolate, wrapper); | 77 callbackData->handle.set(isolate, wrapper); |
78 callbackData->handle.setWeak(callbackData, &InjectedScriptManager::setWeakCa
llback); | 78 callbackData->handle.setWeak(callbackData, &InjectedScriptManager::setWeakCa
llback); |
79 | 79 |
80 V8DOMWrapper::setNativeInfo(wrapper, &V8InjectedScriptHost::wrapperTypeInfo,
host.get()); | 80 V8DOMWrapper::setNativeInfo(wrapper, &V8InjectedScriptHost::wrapperTypeInfo,
host.get()); |
81 ASSERT(V8DOMWrapper::hasInternalFieldsSet(wrapper)); | 81 ASSERT(V8DOMWrapper::hasInternalFieldsSet(wrapper)); |
82 return wrapper; | 82 return wrapper; |
83 } | 83 } |
84 | 84 |
85 ScriptValue InjectedScriptManager::createInjectedScript(const String& scriptSour
ce, ScriptState* inspectedScriptState, int id, InjectedScriptNative* injectedScr
iptNative) | 85 ScriptValue InjectedScriptManager::createInjectedScript(const String& scriptSour
ce, ScriptState* inspectedScriptState, int id, InjectedScriptNative* injectedScr
iptNative) |
86 { | 86 { |
87 v8::Isolate* isolate = inspectedScriptState->isolate(); | 87 v8::Isolate* isolate = inspectedScriptState->isolate(); |
88 ScriptState::Scope scope(inspectedScriptState); | 88 ScriptState::Scope scope(inspectedScriptState); |
89 | 89 |
90 // Call custom code to create InjectedScripHost wrapper specific for the con
text | 90 // Call custom code to create InjectedScripHost wrapper specific for the con
text |
91 // instead of calling toV8() that would create the | 91 // instead of calling toV8() that would create the |
92 // wrapper in the current context. | 92 // wrapper in the current context. |
93 // FIXME: make it possible to use generic bindings factory for InjectedScrip
tHost. | 93 // FIXME: make it possible to use generic bindings factory for InjectedScrip
tHost. |
94 v8::Local<v8::Object> scriptHostWrapper = createInjectedScriptHostV8Wrapper(
m_injectedScriptHost, this, inspectedScriptState->context()->Global(), inspected
ScriptState->isolate()); | 94 v8::Local<v8::Object> scriptHostWrapper = createInjectedScriptHostV8Wrapper(
inspectedScriptState->isolate(), m_injectedScriptHost, this, inspectedScriptStat
e->context()->Global()); |
95 if (scriptHostWrapper.IsEmpty()) | 95 if (scriptHostWrapper.IsEmpty()) |
96 return ScriptValue(); | 96 return ScriptValue(); |
97 | 97 |
98 injectedScriptNative->setOnInjectedScriptHost(scriptHostWrapper); | 98 injectedScriptNative->setOnInjectedScriptHost(scriptHostWrapper); |
99 | 99 |
100 // Inject javascript into the context. The compiled script is supposed to ev
aluate into | 100 // 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 | 101 // 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, | 102 // 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 | 103 // 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. | 104 // to create and configure InjectedScript instance that is going to be used
by the inspector. |
(...skipping 24 matching lines...) Expand all Loading... |
129 return BindingSecurity::shouldAllowAccessToFrame(scriptState->isolate(), fra
me, DoNotReportSecurityError); | 129 return BindingSecurity::shouldAllowAccessToFrame(scriptState->isolate(), fra
me, DoNotReportSecurityError); |
130 } | 130 } |
131 | 131 |
132 void InjectedScriptManager::setWeakCallback(const v8::WeakCallbackInfo<InjectedS
criptManager::CallbackData>& data) | 132 void InjectedScriptManager::setWeakCallback(const v8::WeakCallbackInfo<InjectedS
criptManager::CallbackData>& data) |
133 { | 133 { |
134 InjectedScriptManager::CallbackData* callbackData = data.GetParameter(); | 134 InjectedScriptManager::CallbackData* callbackData = data.GetParameter(); |
135 callbackData->injectedScriptManager->removeCallbackData(callbackData); | 135 callbackData->injectedScriptManager->removeCallbackData(callbackData); |
136 } | 136 } |
137 | 137 |
138 } // namespace blink | 138 } // namespace blink |
OLD | NEW |