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

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

Issue 306853002: Replace Context::Scope with ScriptState::Scope (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 6 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 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 ScriptValue InjectedScriptManager::createInjectedScript(const String& scriptSour ce, 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 ScriptState::Scope scope(inspectedScriptState);
80
81 v8::Local<v8::Context> inspectedContext = inspectedScriptState->context();
82 v8::Context::Scope contextScope(inspectedContext);
83 80
84 // Call custom code to create InjectedScripHost wrapper specific for the con text 81 // Call custom code to create InjectedScripHost wrapper specific for the con text
85 // instead of calling toV8() that would create the 82 // instead of calling toV8() that would create the
86 // wrapper in the current context. 83 // wrapper in the current context.
87 // FIXME: make it possible to use generic bindings factory for InjectedScrip tHost. 84 // FIXME: make it possible to use generic bindings factory for InjectedScrip tHost.
88 v8::Local<v8::Object> scriptHostWrapper = createInjectedScriptHostV8Wrapper( m_injectedScriptHost.get(), inspectedContext->GetIsolate()); 85 v8::Local<v8::Object> scriptHostWrapper = createInjectedScriptHostV8Wrapper( m_injectedScriptHost.get(), inspectedScriptState->isolate());
89 if (scriptHostWrapper.IsEmpty()) 86 if (scriptHostWrapper.IsEmpty())
90 return ScriptValue(); 87 return ScriptValue();
91 88
92 // Inject javascript into the context. The compiled script is supposed to ev aluate into 89 // 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 90 // 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, 91 // 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 92 // 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. 93 // 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); 94 v8::Local<v8::Value> value = V8ScriptRunner::compileAndRunInternalScript(v8S tring(isolate, scriptSource), isolate);
98 ASSERT(!value.IsEmpty()); 95 ASSERT(!value.IsEmpty());
99 ASSERT(value->IsFunction()); 96 ASSERT(value->IsFunction());
100 97
101 v8::Local<v8::Object> windowGlobal = inspectedContext->Global(); 98 v8::Local<v8::Object> windowGlobal = inspectedScriptState->context()->Global ();
102 v8::Handle<v8::Value> info[] = { scriptHostWrapper, windowGlobal, v8::Number ::New(inspectedContext->GetIsolate(), id) }; 99 v8::Handle<v8::Value> info[] = { scriptHostWrapper, windowGlobal, v8::Number ::New(inspectedScriptState->isolate(), id) };
103 v8::Local<v8::Value> injectedScriptValue = V8ScriptRunner::callInternalFunct ion(v8::Local<v8::Function>::Cast(value), windowGlobal, WTF_ARRAY_LENGTH(info), info, inspectedContext->GetIsolate()); 100 v8::Local<v8::Value> injectedScriptValue = V8ScriptRunner::callInternalFunct ion(v8::Local<v8::Function>::Cast(value), windowGlobal, WTF_ARRAY_LENGTH(info), info, inspectedScriptState->isolate());
104 return ScriptValue(inspectedScriptState, injectedScriptValue); 101 return ScriptValue(inspectedScriptState, injectedScriptValue);
105 } 102 }
106 103
107 bool InjectedScriptManager::canAccessInspectedWindow(ScriptState* scriptState) 104 bool InjectedScriptManager::canAccessInspectedWindow(ScriptState* scriptState)
108 { 105 {
109 v8::HandleScope handleScope(scriptState->isolate()); 106 ScriptState::Scope scope(scriptState);
110 v8::Local<v8::Context> context = scriptState->context(); 107 v8::Local<v8::Object> global = scriptState->context()->Global();
111 v8::Local<v8::Object> global = context->Global();
112 if (global.IsEmpty()) 108 if (global.IsEmpty())
113 return false; 109 return false;
114 v8::Handle<v8::Object> holder = V8Window::findInstanceInPrototypeChain(globa l, context->GetIsolate()); 110 v8::Handle<v8::Object> holder = V8Window::findInstanceInPrototypeChain(globa l, scriptState->isolate());
115 if (holder.IsEmpty()) 111 if (holder.IsEmpty())
116 return false; 112 return false;
117 LocalFrame* frame = V8Window::toNative(holder)->frame(); 113 LocalFrame* frame = V8Window::toNative(holder)->frame();
118 114
119 v8::Context::Scope contextScope(context);
120 return BindingSecurity::shouldAllowAccessToFrame(scriptState->isolate(), fra me, DoNotReportSecurityError); 115 return BindingSecurity::shouldAllowAccessToFrame(scriptState->isolate(), fra me, DoNotReportSecurityError);
121 } 116 }
122 117
123 void InjectedScriptManager::setWeakCallback(const v8::WeakCallbackData<v8::Objec t, InjectedScriptManager::CallbackData>& data) 118 void InjectedScriptManager::setWeakCallback(const v8::WeakCallbackData<v8::Objec t, InjectedScriptManager::CallbackData>& data)
124 { 119 {
125 data.GetParameter()->handle.clear(); 120 data.GetParameter()->handle.clear();
126 data.GetParameter()->host.clear(); 121 data.GetParameter()->host.clear();
127 delete data.GetParameter(); 122 delete data.GetParameter();
128 } 123 }
129 124
130 } // namespace WebCore 125 } // namespace WebCore
OLDNEW
« no previous file with comments | « Source/bindings/v8/custom/V8InjectedScriptHostCustom.cpp ('k') | Source/core/inspector/InspectorOverlay.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698