| 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 18 matching lines...) Expand all Loading... |
| 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 "V8InjectedScriptHost.h" | 34 #include "V8InjectedScriptHost.h" |
| 35 #include "V8Window.h" | 35 #include "V8Window.h" |
| 36 #include "bindings/v8/BindingSecurity.h" | 36 #include "bindings/v8/BindingSecurity.h" |
| 37 #include "bindings/v8/ScopedPersistent.h" | 37 #include "bindings/v8/ScopedPersistent.h" |
| 38 #include "bindings/v8/ScriptDebugServer.h" | 38 #include "bindings/v8/ScriptDebugServer.h" |
| 39 #include "bindings/v8/ScriptObject.h" | 39 #include "bindings/v8/ScriptValue.h" |
| 40 #include "bindings/v8/V8Binding.h" | 40 #include "bindings/v8/V8Binding.h" |
| 41 #include "bindings/v8/V8ObjectConstructor.h" | 41 #include "bindings/v8/V8ObjectConstructor.h" |
| 42 #include "bindings/v8/V8ScriptRunner.h" | 42 #include "bindings/v8/V8ScriptRunner.h" |
| 43 #include "core/inspector/InjectedScriptHost.h" | 43 #include "core/inspector/InjectedScriptHost.h" |
| 44 #include "core/frame/DOMWindow.h" | 44 #include "core/frame/DOMWindow.h" |
| 45 #include "wtf/RefPtr.h" | 45 #include "wtf/RefPtr.h" |
| 46 | 46 |
| 47 namespace WebCore { | 47 namespace WebCore { |
| 48 | 48 |
| 49 struct InjectedScriptManager::CallbackData { | 49 struct InjectedScriptManager::CallbackData { |
| (...skipping 16 matching lines...) Expand all Loading... |
| 66 V8DOMWrapper::setNativeInfo(instanceTemplate, &V8InjectedScriptHost::wrapper
TypeInfo, host); | 66 V8DOMWrapper::setNativeInfo(instanceTemplate, &V8InjectedScriptHost::wrapper
TypeInfo, host); |
| 67 // Create a weak reference to the v8 wrapper of InspectorBackend to deref | 67 // Create a weak reference to the v8 wrapper of InspectorBackend to deref |
| 68 // InspectorBackend when the wrapper is garbage collected. | 68 // InspectorBackend when the wrapper is garbage collected. |
| 69 InjectedScriptManager::CallbackData* data = new InjectedScriptManager::Callb
ackData; | 69 InjectedScriptManager::CallbackData* data = new InjectedScriptManager::Callb
ackData; |
| 70 data->host = host; | 70 data->host = host; |
| 71 data->handle.set(isolate, instanceTemplate); | 71 data->handle.set(isolate, instanceTemplate); |
| 72 data->handle.setWeak(data, &InjectedScriptManager::setWeakCallback); | 72 data->handle.setWeak(data, &InjectedScriptManager::setWeakCallback); |
| 73 return instanceTemplate; | 73 return instanceTemplate; |
| 74 } | 74 } |
| 75 | 75 |
| 76 ScriptObject InjectedScriptManager::createInjectedScript(const String& scriptSou
rce, ScriptState* inspectedScriptState, int id) | 76 ScriptValue InjectedScriptManager::createInjectedScript(const String& scriptSour
ce, ScriptState* inspectedScriptState, int id) |
| 77 { | 77 { |
| 78 v8::Isolate* isolate = inspectedScriptState->isolate(); | 78 v8::Isolate* isolate = inspectedScriptState->isolate(); |
| 79 v8::HandleScope handleScope(isolate); | 79 v8::HandleScope handleScope(isolate); |
| 80 | 80 |
| 81 v8::Local<v8::Context> inspectedContext = inspectedScriptState->context(); | 81 v8::Local<v8::Context> inspectedContext = inspectedScriptState->context(); |
| 82 v8::Context::Scope contextScope(inspectedContext); | 82 v8::Context::Scope contextScope(inspectedContext); |
| 83 | 83 |
| 84 // Call custom code to create InjectedScripHost wrapper specific for the con
text | 84 // Call custom code to create InjectedScripHost wrapper specific for the con
text |
| 85 // instead of calling toV8() that would create the | 85 // instead of calling toV8() that would create the |
| 86 // wrapper in the current context. | 86 // wrapper in the current context. |
| 87 // FIXME: make it possible to use generic bindings factory for InjectedScrip
tHost. | 87 // FIXME: make it possible to use generic bindings factory for InjectedScrip
tHost. |
| 88 v8::Local<v8::Object> scriptHostWrapper = createInjectedScriptHostV8Wrapper(
m_injectedScriptHost.get(), inspectedContext->GetIsolate()); | 88 v8::Local<v8::Object> scriptHostWrapper = createInjectedScriptHostV8Wrapper(
m_injectedScriptHost.get(), inspectedContext->GetIsolate()); |
| 89 if (scriptHostWrapper.IsEmpty()) | 89 if (scriptHostWrapper.IsEmpty()) |
| 90 return ScriptObject(); | 90 return ScriptValue(); |
| 91 | 91 |
| 92 // Inject javascript into the context. The compiled script is supposed to ev
aluate into | 92 // Inject javascript into the context. The compiled script is supposed to ev
aluate into |
| 93 // a single anonymous function(it's anonymous to avoid cluttering the global
object with | 93 // a single anonymous function(it's anonymous to avoid cluttering the global
object with |
| 94 // inspector's stuff) the function is called a few lines below with Injected
ScriptHost wrapper, | 94 // inspector's stuff) the function is called a few lines below with Injected
ScriptHost wrapper, |
| 95 // injected script id and explicit reference to the inspected global object.
The function is expected | 95 // injected script id and explicit reference to the inspected global object.
The function is expected |
| 96 // to create and configure InjectedScript instance that is going to be used
by the inspector. | 96 // to create and configure InjectedScript instance that is going to be used
by the inspector. |
| 97 v8::Local<v8::Value> value = V8ScriptRunner::compileAndRunInternalScript(v8S
tring(isolate, scriptSource), isolate); | 97 v8::Local<v8::Value> value = V8ScriptRunner::compileAndRunInternalScript(v8S
tring(isolate, scriptSource), isolate); |
| 98 ASSERT(!value.IsEmpty()); | 98 ASSERT(!value.IsEmpty()); |
| 99 ASSERT(value->IsFunction()); | 99 ASSERT(value->IsFunction()); |
| 100 | 100 |
| 101 v8::Local<v8::Object> windowGlobal = inspectedContext->Global(); | 101 v8::Local<v8::Object> windowGlobal = inspectedContext->Global(); |
| 102 v8::Handle<v8::Value> info[] = { scriptHostWrapper, windowGlobal, v8::Number
::New(inspectedContext->GetIsolate(), id) }; | 102 v8::Handle<v8::Value> info[] = { scriptHostWrapper, windowGlobal, v8::Number
::New(inspectedContext->GetIsolate(), id) }; |
| 103 v8::Local<v8::Value> injectedScriptValue = V8ScriptRunner::callInternalFunct
ion(v8::Local<v8::Function>::Cast(value), windowGlobal, WTF_ARRAY_LENGTH(info),
info, inspectedContext->GetIsolate()); | 103 v8::Local<v8::Value> injectedScriptValue = V8ScriptRunner::callInternalFunct
ion(v8::Local<v8::Function>::Cast(value), windowGlobal, WTF_ARRAY_LENGTH(info),
info, inspectedContext->GetIsolate()); |
| 104 return ScriptObject(inspectedScriptState, v8::Handle<v8::Object>::Cast(injec
tedScriptValue)); | 104 return ScriptValue(inspectedScriptState, injectedScriptValue); |
| 105 } | 105 } |
| 106 | 106 |
| 107 bool InjectedScriptManager::canAccessInspectedWindow(ScriptState* scriptState) | 107 bool InjectedScriptManager::canAccessInspectedWindow(ScriptState* scriptState) |
| 108 { | 108 { |
| 109 v8::HandleScope handleScope(scriptState->isolate()); | 109 v8::HandleScope handleScope(scriptState->isolate()); |
| 110 v8::Local<v8::Context> context = scriptState->context(); | 110 v8::Local<v8::Context> context = scriptState->context(); |
| 111 v8::Local<v8::Object> global = context->Global(); | 111 v8::Local<v8::Object> global = context->Global(); |
| 112 if (global.IsEmpty()) | 112 if (global.IsEmpty()) |
| 113 return false; | 113 return false; |
| 114 v8::Handle<v8::Object> holder = V8Window::findInstanceInPrototypeChain(globa
l, context->GetIsolate()); | 114 v8::Handle<v8::Object> holder = V8Window::findInstanceInPrototypeChain(globa
l, context->GetIsolate()); |
| 115 if (holder.IsEmpty()) | 115 if (holder.IsEmpty()) |
| 116 return false; | 116 return false; |
| 117 LocalFrame* frame = V8Window::toNative(holder)->frame(); | 117 LocalFrame* frame = V8Window::toNative(holder)->frame(); |
| 118 | 118 |
| 119 v8::Context::Scope contextScope(context); | 119 v8::Context::Scope contextScope(context); |
| 120 return BindingSecurity::shouldAllowAccessToFrame(scriptState->isolate(), fra
me, DoNotReportSecurityError); | 120 return BindingSecurity::shouldAllowAccessToFrame(scriptState->isolate(), fra
me, DoNotReportSecurityError); |
| 121 } | 121 } |
| 122 | 122 |
| 123 void InjectedScriptManager::setWeakCallback(const v8::WeakCallbackData<v8::Objec
t, InjectedScriptManager::CallbackData>& data) | 123 void InjectedScriptManager::setWeakCallback(const v8::WeakCallbackData<v8::Objec
t, InjectedScriptManager::CallbackData>& data) |
| 124 { | 124 { |
| 125 data.GetParameter()->handle.clear(); | 125 data.GetParameter()->handle.clear(); |
| 126 data.GetParameter()->host.clear(); | 126 data.GetParameter()->host.clear(); |
| 127 delete data.GetParameter(); | 127 delete data.GetParameter(); |
| 128 } | 128 } |
| 129 | 129 |
| 130 } // namespace WebCore | 130 } // namespace WebCore |
| OLD | NEW |