| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2008, 2009 Google Inc. All rights reserved. | 2 * Copyright (C) 2008, 2009 Google Inc. All rights reserved. |
| 3 * Copyright (C) 2009 Apple Inc. All rights reserved. | 3 * Copyright (C) 2009 Apple Inc. All rights reserved. |
| 4 * Copyright (C) 2014 Opera Software ASA. All rights reserved. | 4 * Copyright (C) 2014 Opera Software ASA. All rights reserved. |
| 5 * | 5 * |
| 6 * Redistribution and use in source and binary forms, with or without | 6 * Redistribution and use in source and binary forms, with or without |
| 7 * modification, are permitted provided that the following conditions are | 7 * modification, are permitted provided that the following conditions are |
| 8 * met: | 8 * met: |
| 9 * | 9 * |
| 10 * * Redistributions of source code must retain the above copyright | 10 * * Redistributions of source code must retain the above copyright |
| (...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 155 { | 155 { |
| 156 if (m_windowProxy->isContextInitialized()) | 156 if (m_windowProxy->isContextInitialized()) |
| 157 return false; | 157 return false; |
| 158 return windowProxy(DOMWrapperWorld::mainWorld())->isContextInitialized(); | 158 return windowProxy(DOMWrapperWorld::mainWorld())->isContextInitialized(); |
| 159 } | 159 } |
| 160 | 160 |
| 161 WindowProxy* ScriptController::existingWindowProxy(DOMWrapperWorld& world) | 161 WindowProxy* ScriptController::existingWindowProxy(DOMWrapperWorld& world) |
| 162 { | 162 { |
| 163 if (world.isMainWorld()) | 163 if (world.isMainWorld()) |
| 164 return m_windowProxy->isContextInitialized() ? m_windowProxy.get() : 0; | 164 return m_windowProxy->isContextInitialized() ? m_windowProxy.get() : 0; |
| 165 | 165 return 0; |
| 166 IsolatedWorldMap::iterator iter = m_isolatedWorlds.find(world.worldId()); | |
| 167 if (iter == m_isolatedWorlds.end()) | |
| 168 return 0; | |
| 169 return iter->value->isContextInitialized() ? iter->value.get() : 0; | |
| 170 } | 166 } |
| 171 | 167 |
| 172 WindowProxy* ScriptController::windowProxy(DOMWrapperWorld& world) | 168 WindowProxy* ScriptController::windowProxy(DOMWrapperWorld& world) |
| 173 { | 169 { |
| 174 WindowProxy* windowProxy = 0; | 170 m_windowProxy->initializeIfNeeded(); |
| 175 if (world.isMainWorld()) { | 171 return m_windowProxy.get(); |
| 176 windowProxy = m_windowProxy.get(); | |
| 177 } else { | |
| 178 IsolatedWorldMap::iterator iter = m_isolatedWorlds.find(world.worldId())
; | |
| 179 if (iter != m_isolatedWorlds.end()) { | |
| 180 windowProxy = iter->value.get(); | |
| 181 } else { | |
| 182 OwnPtr<WindowProxy> isolatedWorldWindowProxy = WindowProxy::create(m
_frame, world, m_isolate); | |
| 183 windowProxy = isolatedWorldWindowProxy.get(); | |
| 184 m_isolatedWorlds.set(world.worldId(), isolatedWorldWindowProxy.relea
se()); | |
| 185 } | |
| 186 } | |
| 187 windowProxy->initializeIfNeeded(); | |
| 188 return windowProxy; | |
| 189 } | 172 } |
| 190 | 173 |
| 191 V8Extensions& ScriptController::registeredExtensions() | 174 V8Extensions& ScriptController::registeredExtensions() |
| 192 { | 175 { |
| 193 DEFINE_STATIC_LOCAL(V8Extensions, extensions, ()); | 176 DEFINE_STATIC_LOCAL(V8Extensions, extensions, ()); |
| 194 return extensions; | 177 return extensions; |
| 195 } | 178 } |
| 196 | 179 |
| 197 void ScriptController::registerExtensionIfNeeded(v8::Extension* extension) | 180 void ScriptController::registerExtensionIfNeeded(v8::Extension* extension) |
| 198 { | 181 { |
| (...skipping 16 matching lines...) Expand all Loading... |
| 215 for (IsolatedWorldMap::iterator iter = m_isolatedWorlds.begin(); iter != m_i
solatedWorlds.end(); ++iter) | 198 for (IsolatedWorldMap::iterator iter = m_isolatedWorlds.begin(); iter != m_i
solatedWorlds.end(); ++iter) |
| 216 iter->value->clearForNavigation(); | 199 iter->value->clearForNavigation(); |
| 217 blink::Platform::current()->histogramCustomCounts("WebCore.ScriptController.
clearWindowProxy", (currentTime() - start) * 1000, 0, 10000, 50); | 200 blink::Platform::current()->histogramCustomCounts("WebCore.ScriptController.
clearWindowProxy", (currentTime() - start) * 1000, 0, 10000, 50); |
| 218 } | 201 } |
| 219 | 202 |
| 220 void ScriptController::setCaptureCallStackForUncaughtExceptions(bool value) | 203 void ScriptController::setCaptureCallStackForUncaughtExceptions(bool value) |
| 221 { | 204 { |
| 222 v8::V8::SetCaptureStackTraceForUncaughtExceptions(value, ScriptCallStack::ma
xCallStackSizeToCapture, stackTraceOptions); | 205 v8::V8::SetCaptureStackTraceForUncaughtExceptions(value, ScriptCallStack::ma
xCallStackSizeToCapture, stackTraceOptions); |
| 223 } | 206 } |
| 224 | 207 |
| 225 void ScriptController::setWorldDebugId(int worldId, int debuggerId) | 208 void ScriptController::setWorldDebugId(int debuggerId) |
| 226 { | 209 { |
| 227 ASSERT(debuggerId > 0); | 210 ASSERT(debuggerId > 0); |
| 228 bool isMainWorld = worldId == MainWorldId; | 211 if (!m_windowProxy || !m_windowProxy->isContextInitialized()) |
| 229 WindowProxy* windowProxy = 0; | |
| 230 if (isMainWorld) { | |
| 231 windowProxy = m_windowProxy.get(); | |
| 232 } else { | |
| 233 IsolatedWorldMap::iterator iter = m_isolatedWorlds.find(worldId); | |
| 234 if (iter != m_isolatedWorlds.end()) | |
| 235 windowProxy = iter->value.get(); | |
| 236 } | |
| 237 if (!windowProxy || !windowProxy->isContextInitialized()) | |
| 238 return; | 212 return; |
| 239 v8::HandleScope scope(m_isolate); | 213 v8::HandleScope scope(m_isolate); |
| 240 v8::Local<v8::Context> context = windowProxy->context(); | 214 v8::Local<v8::Context> context = m_windowProxy->context(); |
| 241 const char* worldName = isMainWorld ? "page" : "injected"; | 215 V8PerContextDebugData::setContextDebugData(context, "page", debuggerId); |
| 242 V8PerContextDebugData::setContextDebugData(context, worldName, debuggerId); | |
| 243 } | 216 } |
| 244 | 217 |
| 245 void ScriptController::updateDocument() | 218 void ScriptController::updateDocument() |
| 246 { | 219 { |
| 247 // For an uninitialized main window windowProxy, do not incur the cost of co
ntext initialization. | 220 // For an uninitialized main window windowProxy, do not incur the cost of co
ntext initialization. |
| 248 if (!m_windowProxy->isGlobalInitialized()) | 221 if (!m_windowProxy->isGlobalInitialized()) |
| 249 return; | 222 return; |
| 250 | 223 |
| 251 if (!initializeMainWorld()) | 224 if (!initializeMainWorld()) |
| 252 windowProxy(DOMWrapperWorld::mainWorld())->updateDocument(); | 225 windowProxy(DOMWrapperWorld::mainWorld())->updateDocument(); |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 287 | 260 |
| 288 v8::Local<v8::Value> object = executeScriptAndReturnValue(scriptState->conte
xt(), sourceCode); | 261 v8::Local<v8::Value> object = executeScriptAndReturnValue(scriptState->conte
xt(), sourceCode); |
| 289 m_sourceURL = savedSourceURL; | 262 m_sourceURL = savedSourceURL; |
| 290 | 263 |
| 291 if (object.IsEmpty()) | 264 if (object.IsEmpty()) |
| 292 return v8::Local<v8::Value>(); | 265 return v8::Local<v8::Value>(); |
| 293 | 266 |
| 294 return handleScope.Escape(object); | 267 return handleScope.Escape(object); |
| 295 } | 268 } |
| 296 | 269 |
| 297 void ScriptController::executeScriptInIsolatedWorld(int worldID, const Vector<Sc
riptSourceCode>& sources, int extensionGroup, Vector<v8::Local<v8::Value> >* res
ults) | |
| 298 { | |
| 299 ASSERT(worldID > 0); | |
| 300 | |
| 301 RefPtr<DOMWrapperWorld> world = DOMWrapperWorld::ensureIsolatedWorld(worldID
, extensionGroup); | |
| 302 WindowProxy* isolatedWorldWindowProxy = windowProxy(*world); | |
| 303 if (!isolatedWorldWindowProxy->isContextInitialized()) | |
| 304 return; | |
| 305 | |
| 306 ScriptState* scriptState = isolatedWorldWindowProxy->scriptState(); | |
| 307 v8::EscapableHandleScope handleScope(scriptState->isolate()); | |
| 308 ScriptState::Scope scope(scriptState); | |
| 309 v8::Local<v8::Array> resultArray = v8::Array::New(m_isolate, sources.size())
; | |
| 310 | |
| 311 for (size_t i = 0; i < sources.size(); ++i) { | |
| 312 v8::Local<v8::Value> evaluationResult = executeScriptAndReturnValue(scri
ptState->context(), sources[i]); | |
| 313 if (evaluationResult.IsEmpty()) | |
| 314 evaluationResult = v8::Local<v8::Value>::New(m_isolate, v8::Undefine
d(m_isolate)); | |
| 315 resultArray->Set(i, evaluationResult); | |
| 316 } | |
| 317 | |
| 318 if (results) { | |
| 319 for (size_t i = 0; i < resultArray->Length(); ++i) | |
| 320 results->append(handleScope.Escape(resultArray->Get(i))); | |
| 321 } | |
| 322 } | |
| 323 | |
| 324 void ScriptController::executeModuleScript(AbstractModule& module, const String&
source, const TextPosition& textPosition) | 270 void ScriptController::executeModuleScript(AbstractModule& module, const String&
source, const TextPosition& textPosition) |
| 325 { | 271 { |
| 326 v8::HandleScope handleScope(m_isolate); | 272 v8::HandleScope handleScope(m_isolate); |
| 327 v8::Handle<v8::Context> context = toV8Context(m_frame, DOMWrapperWorld::main
World()); | 273 v8::Handle<v8::Context> context = toV8Context(m_frame, DOMWrapperWorld::main
World()); |
| 328 if (context.IsEmpty()) | 274 if (context.IsEmpty()) |
| 329 return; | 275 return; |
| 330 | 276 |
| 331 ScriptState* scriptState = ScriptState::from(context); | 277 ScriptState* scriptState = ScriptState::from(context); |
| 332 ScriptState::Scope scope(scriptState); | 278 ScriptState::Scope scope(scriptState); |
| 333 | 279 |
| (...skipping 23 matching lines...) Expand all Loading... |
| 357 scriptModule.resolvedDependencies.append(actual); | 303 scriptModule.resolvedDependencies.append(actual); |
| 358 } | 304 } |
| 359 } | 305 } |
| 360 } | 306 } |
| 361 } | 307 } |
| 362 | 308 |
| 363 V8ScriptRunner::runModule(m_isolate, m_frame->document(), scriptModule); | 309 V8ScriptRunner::runModule(m_isolate, m_frame->document(), scriptModule); |
| 364 } | 310 } |
| 365 | 311 |
| 366 } // namespace blink | 312 } // namespace blink |
| OLD | NEW |