| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2008, 2009, 2011 Google Inc. All rights reserved. | 2 * Copyright (C) 2008, 2009, 2011 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 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 92 } | 92 } |
| 93 | 93 |
| 94 void V8WindowShell::disposeContext() | 94 void V8WindowShell::disposeContext() |
| 95 { | 95 { |
| 96 m_perContextData.clear(); | 96 m_perContextData.clear(); |
| 97 | 97 |
| 98 if (m_context.isEmpty()) | 98 if (m_context.isEmpty()) |
| 99 return; | 99 return; |
| 100 | 100 |
| 101 v8::HandleScope handleScope(m_isolate); | 101 v8::HandleScope handleScope(m_isolate); |
| 102 m_frame->loader()->client()->willReleaseScriptContext(m_context.newLocal(m_i
solate), m_world->worldId()); | 102 m_frame->loader().client()->willReleaseScriptContext(m_context.newLocal(m_is
olate), m_world->worldId()); |
| 103 | 103 |
| 104 m_context.clear(); | 104 m_context.clear(); |
| 105 | 105 |
| 106 // It's likely that disposing the context has created a lot of | 106 // It's likely that disposing the context has created a lot of |
| 107 // garbage. Notify V8 about this so it'll have a chance of cleaning | 107 // garbage. Notify V8 about this so it'll have a chance of cleaning |
| 108 // it up when idle. | 108 // it up when idle. |
| 109 bool isMainFrame = m_frame->page() && (m_frame->page()->mainFrame() == m_fra
me); | 109 bool isMainFrame = m_frame->page() && (m_frame->page()->mainFrame() == m_fra
me); |
| 110 V8GCForContextDispose::instance().notifyContextDisposed(isMainFrame); | 110 V8GCForContextDispose::instance().notifyContextDisposed(isMainFrame); |
| 111 } | 111 } |
| 112 | 112 |
| (...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 244 // document domain | 244 // document domain |
| 245 // changes. | 245 // changes. |
| 246 context->UseDefaultSecurityToken(); | 246 context->UseDefaultSecurityToken(); |
| 247 | 247 |
| 248 SecurityOrigin* origin = m_world->isolatedWorldSecurityOrigin(); | 248 SecurityOrigin* origin = m_world->isolatedWorldSecurityOrigin(); |
| 249 if (origin && InspectorInstrumentation::hasFrontends()) { | 249 if (origin && InspectorInstrumentation::hasFrontends()) { |
| 250 ScriptState* scriptState = ScriptState::forContext(v8::Local<v8::Con
text>::New(m_isolate, context)); | 250 ScriptState* scriptState = ScriptState::forContext(v8::Local<v8::Con
text>::New(m_isolate, context)); |
| 251 InspectorInstrumentation::didCreateIsolatedContext(m_frame, scriptSt
ate, origin); | 251 InspectorInstrumentation::didCreateIsolatedContext(m_frame, scriptSt
ate, origin); |
| 252 } | 252 } |
| 253 } | 253 } |
| 254 m_frame->loader()->client()->didCreateScriptContext(context, m_world->extens
ionGroup(), m_world->worldId()); | 254 m_frame->loader().client()->didCreateScriptContext(context, m_world->extensi
onGroup(), m_world->worldId()); |
| 255 return true; | 255 return true; |
| 256 } | 256 } |
| 257 | 257 |
| 258 void V8WindowShell::createContext() | 258 void V8WindowShell::createContext() |
| 259 { | 259 { |
| 260 // The activeDocumentLoader pointer could be 0 during frame shutdown. | 260 // The activeDocumentLoader pointer could be 0 during frame shutdown. |
| 261 // FIXME: Can we remove this check? | 261 // FIXME: Can we remove this check? |
| 262 if (!m_frame->loader()->activeDocumentLoader()) | 262 if (!m_frame->loader().activeDocumentLoader()) |
| 263 return; | 263 return; |
| 264 | 264 |
| 265 // Create a new environment using an empty template for the shadow | 265 // Create a new environment using an empty template for the shadow |
| 266 // object. Reuse the global object if one has been created earlier. | 266 // object. Reuse the global object if one has been created earlier. |
| 267 v8::Handle<v8::ObjectTemplate> globalTemplate = V8Window::GetShadowObjectTem
plate(m_isolate, m_world->isMainWorld() ? MainWorld : IsolatedWorld); | 267 v8::Handle<v8::ObjectTemplate> globalTemplate = V8Window::GetShadowObjectTem
plate(m_isolate, m_world->isMainWorld() ? MainWorld : IsolatedWorld); |
| 268 if (globalTemplate.IsEmpty()) | 268 if (globalTemplate.IsEmpty()) |
| 269 return; | 269 return; |
| 270 | 270 |
| 271 double contextCreationStartInSeconds = currentTime(); | 271 double contextCreationStartInSeconds = currentTime(); |
| 272 | 272 |
| 273 // Used to avoid sleep calls in unload handlers. | 273 // Used to avoid sleep calls in unload handlers. |
| 274 if (DateExtension::get()) | 274 if (DateExtension::get()) |
| 275 ScriptController::registerExtensionIfNeeded(DateExtension::get()); | 275 ScriptController::registerExtensionIfNeeded(DateExtension::get()); |
| 276 | 276 |
| 277 // Dynamically tell v8 about our extensions now. | 277 // Dynamically tell v8 about our extensions now. |
| 278 const V8Extensions& extensions = ScriptController::registeredExtensions(); | 278 const V8Extensions& extensions = ScriptController::registeredExtensions(); |
| 279 OwnPtr<const char*[]> extensionNames = adoptArrayPtr(new const char*[extensi
ons.size()]); | 279 OwnPtr<const char*[]> extensionNames = adoptArrayPtr(new const char*[extensi
ons.size()]); |
| 280 int index = 0; | 280 int index = 0; |
| 281 int extensionGroup = m_world->extensionGroup(); | 281 int extensionGroup = m_world->extensionGroup(); |
| 282 int worldId = m_world->worldId(); | 282 int worldId = m_world->worldId(); |
| 283 for (size_t i = 0; i < extensions.size(); ++i) { | 283 for (size_t i = 0; i < extensions.size(); ++i) { |
| 284 // Ensure our date extension is always allowed. | 284 // Ensure our date extension is always allowed. |
| 285 if (extensions[i] != DateExtension::get() | 285 if (extensions[i] != DateExtension::get() |
| 286 && !m_frame->loader()->client()->allowScriptExtension(extensions[i]-
>name(), extensionGroup, worldId)) | 286 && !m_frame->loader().client()->allowScriptExtension(extensions[i]->
name(), extensionGroup, worldId)) |
| 287 continue; | 287 continue; |
| 288 | 288 |
| 289 extensionNames[index++] = extensions[i]->name(); | 289 extensionNames[index++] = extensions[i]->name(); |
| 290 } | 290 } |
| 291 v8::ExtensionConfiguration extensionConfiguration(index, extensionNames.get(
)); | 291 v8::ExtensionConfiguration extensionConfiguration(index, extensionNames.get(
)); |
| 292 | 292 |
| 293 v8::HandleScope handleScope(m_isolate); | 293 v8::HandleScope handleScope(m_isolate); |
| 294 m_context.set(m_isolate, v8::Context::New(m_isolate, &extensionConfiguration
, globalTemplate, m_global.newLocal(m_isolate))); | 294 m_context.set(m_isolate, v8::Context::New(m_isolate, &extensionConfiguration
, globalTemplate, m_global.newLocal(m_isolate))); |
| 295 | 295 |
| 296 double contextCreationDurationInMilliseconds = (currentTime() - contextCreat
ionStartInSeconds) * 1000; | 296 double contextCreationDurationInMilliseconds = (currentTime() - contextCreat
ionStartInSeconds) * 1000; |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 387 // Ask the document's SecurityOrigin to generate a security token. | 387 // Ask the document's SecurityOrigin to generate a security token. |
| 388 // If two tokens are equal, then the SecurityOrigins canAccess each other. | 388 // If two tokens are equal, then the SecurityOrigins canAccess each other. |
| 389 // If two tokens are not equal, then we have to call canAccess. | 389 // If two tokens are not equal, then we have to call canAccess. |
| 390 // Note: we can't use the HTTPOrigin if it was set from the DOM. | 390 // Note: we can't use the HTTPOrigin if it was set from the DOM. |
| 391 SecurityOrigin* origin = document->securityOrigin(); | 391 SecurityOrigin* origin = document->securityOrigin(); |
| 392 String token; | 392 String token; |
| 393 // We stick with an empty token if document.domain was modified or if we | 393 // We stick with an empty token if document.domain was modified or if we |
| 394 // are in the initial empty document, so that we can do a full canAccess | 394 // are in the initial empty document, so that we can do a full canAccess |
| 395 // check in those cases. | 395 // check in those cases. |
| 396 if (!origin->domainWasSetInDOM() | 396 if (!origin->domainWasSetInDOM() |
| 397 && !m_frame->loader()->stateMachine()->isDisplayingInitialEmptyDocument(
)) | 397 && !m_frame->loader().stateMachine()->isDisplayingInitialEmptyDocument()
) |
| 398 token = document->securityOrigin()->toString(); | 398 token = document->securityOrigin()->toString(); |
| 399 | 399 |
| 400 // An empty or "null" token means we always have to call | 400 // An empty or "null" token means we always have to call |
| 401 // canAccess. The toString method on securityOrigins returns the | 401 // canAccess. The toString method on securityOrigins returns the |
| 402 // string "null" for empty security origins and for security | 402 // string "null" for empty security origins and for security |
| 403 // origins that should only allow access to themselves. In this | 403 // origins that should only allow access to themselves. In this |
| 404 // case, we use the global object as the security token to avoid | 404 // case, we use the global object as the security token to avoid |
| 405 // calling canAccess when a script accesses its own objects. | 405 // calling canAccess when a script accesses its own objects. |
| 406 v8::HandleScope handleScope(m_isolate); | 406 v8::HandleScope handleScope(m_isolate); |
| 407 v8::Handle<v8::Context> context = m_context.newLocal(m_isolate); | 407 v8::Handle<v8::Context> context = m_context.newLocal(m_isolate); |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 502 void V8WindowShell::updateSecurityOrigin() | 502 void V8WindowShell::updateSecurityOrigin() |
| 503 { | 503 { |
| 504 ASSERT(m_world->isMainWorld()); | 504 ASSERT(m_world->isMainWorld()); |
| 505 if (m_context.isEmpty()) | 505 if (m_context.isEmpty()) |
| 506 return; | 506 return; |
| 507 v8::HandleScope handleScope(m_isolate); | 507 v8::HandleScope handleScope(m_isolate); |
| 508 setSecurityToken(); | 508 setSecurityToken(); |
| 509 } | 509 } |
| 510 | 510 |
| 511 } // WebCore | 511 } // WebCore |
| OLD | NEW |