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 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
72 { | 72 { |
73 ASSERT(V8Document::toNative(wrapper) == document); | 73 ASSERT(V8Document::toNative(wrapper) == document); |
74 ASSERT(!document->isHTMLDocument() || (V8Document::toNative(v8::Handle<v8::O
bject>::Cast(wrapper->GetPrototype())) == document)); | 74 ASSERT(!document->isHTMLDocument() || (V8Document::toNative(v8::Handle<v8::O
bject>::Cast(wrapper->GetPrototype())) == document)); |
75 } | 75 } |
76 | 76 |
77 static void setInjectedScriptContextDebugId(v8::Handle<v8::Context> targetContex
t, int debugId) | 77 static void setInjectedScriptContextDebugId(v8::Handle<v8::Context> targetContex
t, int debugId) |
78 { | 78 { |
79 V8PerContextDebugData::setContextDebugData(targetContext, "injected", debugI
d); | 79 V8PerContextDebugData::setContextDebugData(targetContext, "injected", debugI
d); |
80 } | 80 } |
81 | 81 |
| 82 V8DOMWindowShell::ContextScope::ContextScope(V8DOMWindowShell* shell, ContextDes
criptor descriptor) |
| 83 : m_scope(descriptor == DomContext ? shell->m_context.newLocal(shell->m_isol
ate) : shell->m_contextForBlinkJS.newLocal(shell->m_isolate)) |
| 84 { |
| 85 } |
| 86 |
| 87 V8DOMWindowShell* V8DOMWindowShell::ContextScope::currentWindowShell() |
| 88 { |
| 89 DOMWindow* window = activeDOMWindow(); |
| 90 if (!window) |
| 91 return 0; |
| 92 Document* document = window->document(); |
| 93 if (!document) |
| 94 return 0; |
| 95 Frame* frame = document->frame(); |
| 96 if (!frame) |
| 97 return 0; |
| 98 ScriptController* script = frame->script(); |
| 99 if (!script) |
| 100 return 0; |
| 101 return script->windowShell(DOMWrapperWorld::current()); |
| 102 } |
| 103 |
82 PassOwnPtr<V8DOMWindowShell> V8DOMWindowShell::create(Frame* frame, PassRefPtr<D
OMWrapperWorld> world, v8::Isolate* isolate) | 104 PassOwnPtr<V8DOMWindowShell> V8DOMWindowShell::create(Frame* frame, PassRefPtr<D
OMWrapperWorld> world, v8::Isolate* isolate) |
83 { | 105 { |
84 return adoptPtr(new V8DOMWindowShell(frame, world, isolate)); | 106 return adoptPtr(new V8DOMWindowShell(frame, world, isolate)); |
85 } | 107 } |
86 | 108 |
87 V8DOMWindowShell::V8DOMWindowShell(Frame* frame, PassRefPtr<DOMWrapperWorld> wor
ld, v8::Isolate* isolate) | 109 V8DOMWindowShell::V8DOMWindowShell(Frame* frame, PassRefPtr<DOMWrapperWorld> wor
ld, v8::Isolate* isolate) |
88 : m_frame(frame) | 110 : m_frame(frame) |
89 , m_world(world) | 111 , m_world(world) |
90 , m_isolate(isolate) | 112 , m_isolate(isolate) |
91 { | 113 { |
92 } | 114 } |
93 | 115 |
94 void V8DOMWindowShell::disposeContext() | 116 void V8DOMWindowShell::disposeContext() |
95 { | 117 { |
96 m_perContextData.clear(); | 118 m_perContextData.clear(); |
| 119 m_perContextDataForBlinkJS.clear(); |
97 | 120 |
98 if (m_context.isEmpty()) | 121 if (m_context.isEmpty()) |
99 return; | 122 return; |
100 | 123 |
101 v8::HandleScope handleScope(m_isolate); | 124 v8::HandleScope handleScope(m_isolate); |
102 m_frame->loader()->client()->willReleaseScriptContext(m_context.newLocal(m_i
solate), m_world->worldId()); | 125 m_frame->loader()->client()->willReleaseScriptContext(m_context.newLocal(m_i
solate), m_world->worldId()); |
103 | 126 |
104 m_context.clear(); | 127 m_context.clear(); |
| 128 m_contextForBlinkJS.clear(); |
105 | 129 |
106 // It's likely that disposing the context has created a lot of | 130 // 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 | 131 // garbage. Notify V8 about this so it'll have a chance of cleaning |
108 // it up when idle. | 132 // it up when idle. |
109 bool isMainFrame = m_frame->page() && (m_frame->page()->mainFrame() == m_fra
me); | 133 bool isMainFrame = m_frame->page() && (m_frame->page()->mainFrame() == m_fra
me); |
110 V8GCForContextDispose::instance().notifyContextDisposed(isMainFrame); | 134 V8GCForContextDispose::instance().notifyContextDisposed(isMainFrame); |
111 } | 135 } |
112 | 136 |
113 void V8DOMWindowShell::clearForClose(bool destroyGlobal) | 137 void V8DOMWindowShell::clearForClose(bool destroyGlobal) |
114 { | 138 { |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
214 if (mainWindow && !mainWindow->context().IsEmpty()) | 238 if (mainWindow && !mainWindow->context().IsEmpty()) |
215 setInjectedScriptContextDebugId(context, m_frame->script()->contextD
ebugId(mainWindow->context())); | 239 setInjectedScriptContextDebugId(context, m_frame->script()->contextD
ebugId(mainWindow->context())); |
216 } | 240 } |
217 | 241 |
218 m_perContextData = V8PerContextData::create(context); | 242 m_perContextData = V8PerContextData::create(context); |
219 if (!m_perContextData->init()) { | 243 if (!m_perContextData->init()) { |
220 disposeContext(); | 244 disposeContext(); |
221 return false; | 245 return false; |
222 } | 246 } |
223 m_perContextData->setActivityLogger(DOMWrapperWorld::activityLogger(m_world-
>worldId())); | 247 m_perContextData->setActivityLogger(DOMWrapperWorld::activityLogger(m_world-
>worldId())); |
| 248 |
| 249 { |
| 250 v8::Handle<v8::Context> contextForBlinkJS = m_contextForBlinkJS.newLocal
(m_isolate); |
| 251 v8::Context::Scope contextScope(contextForBlinkJS); |
| 252 m_perContextDataForBlinkJS = V8PerContextData::create(contextForBlinkJS)
; |
| 253 if (!m_perContextDataForBlinkJS->init()) { |
| 254 disposeContext(); |
| 255 return false; |
| 256 } |
| 257 m_perContextDataForBlinkJS->setActivityLogger(DOMWrapperWorld::activityL
ogger(m_world->worldId())); |
| 258 } |
| 259 |
224 if (!installDOMWindow()) { | 260 if (!installDOMWindow()) { |
225 disposeContext(); | 261 disposeContext(); |
226 return false; | 262 return false; |
227 } | 263 } |
228 | 264 |
229 if (isMainWorld) { | 265 if (isMainWorld) { |
230 updateDocument(); | 266 updateDocument(); |
231 setSecurityToken(); | 267 setSecurityToken(); |
232 if (m_frame->document()) { | 268 if (m_frame->document()) { |
233 ContentSecurityPolicy* csp = m_frame->document()->contentSecurityPol
icy(); | 269 ContentSecurityPolicy* csp = m_frame->document()->contentSecurityPol
icy(); |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
286 if (extensions[i] != DateExtension::get() | 322 if (extensions[i] != DateExtension::get() |
287 && !m_frame->loader()->client()->allowScriptExtension(extensions[i]-
>name(), extensionGroup, worldId)) | 323 && !m_frame->loader()->client()->allowScriptExtension(extensions[i]-
>name(), extensionGroup, worldId)) |
288 continue; | 324 continue; |
289 | 325 |
290 extensionNames[index++] = extensions[i]->name(); | 326 extensionNames[index++] = extensions[i]->name(); |
291 } | 327 } |
292 v8::ExtensionConfiguration extensionConfiguration(index, extensionNames.get(
)); | 328 v8::ExtensionConfiguration extensionConfiguration(index, extensionNames.get(
)); |
293 | 329 |
294 v8::HandleScope handleScope(m_isolate); | 330 v8::HandleScope handleScope(m_isolate); |
295 m_context.set(m_isolate, v8::Context::New(m_isolate, &extensionConfiguration
, globalTemplate, m_global.newLocal(m_isolate))); | 331 m_context.set(m_isolate, v8::Context::New(m_isolate, &extensionConfiguration
, globalTemplate, m_global.newLocal(m_isolate))); |
| 332 m_contextForBlinkJS.set(m_isolate, v8::Context::New(m_isolate, 0, globalTemp
late)); |
296 | 333 |
297 double contextCreationDurationInMilliseconds = (currentTime() - contextCreat
ionStartInSeconds) * 1000; | 334 double contextCreationDurationInMilliseconds = (currentTime() - contextCreat
ionStartInSeconds) * 1000; |
298 const char* histogramName = "WebCore.V8DOMWindowShell.createContext.MainWorl
d"; | 335 const char* histogramName = "WebCore.V8DOMWindowShell.createContext.MainWorl
d"; |
299 if (!m_world->isMainWorld()) | 336 if (!m_world->isMainWorld()) |
300 histogramName = "WebCore.V8DOMWindowShell.createContext.IsolatedWorld"; | 337 histogramName = "WebCore.V8DOMWindowShell.createContext.IsolatedWorld"; |
301 HistogramSupport::histogramCustomCounts(histogramName, contextCreationDurati
onInMilliseconds, 0, 10000, 50); | 338 HistogramSupport::histogramCustomCounts(histogramName, contextCreationDurati
onInMilliseconds, 0, 10000, 50); |
302 } | 339 } |
303 | 340 |
304 bool V8DOMWindowShell::installDOMWindow() | 341 bool V8DOMWindowShell::installDOMWindow() |
305 { | 342 { |
(...skipping 17 matching lines...) Expand all Loading... |
323 // -- has prototype --> Object.prototype | 360 // -- has prototype --> Object.prototype |
324 // | 361 // |
325 // Note: Much of this prototype structure is hidden from web content. The | 362 // Note: Much of this prototype structure is hidden from web content. The |
326 // outer, inner, and DOMWindow instance all appear to be the same | 363 // outer, inner, and DOMWindow instance all appear to be the same |
327 // JavaScript object. | 364 // JavaScript object. |
328 // | 365 // |
329 v8::Handle<v8::Object> innerGlobalObject = toInnerGlobalObject(m_context.new
Local(m_isolate)); | 366 v8::Handle<v8::Object> innerGlobalObject = toInnerGlobalObject(m_context.new
Local(m_isolate)); |
330 V8DOMWrapper::setNativeInfo(innerGlobalObject, &V8DOMWindow::info, window); | 367 V8DOMWrapper::setNativeInfo(innerGlobalObject, &V8DOMWindow::info, window); |
331 innerGlobalObject->SetPrototype(windowWrapper); | 368 innerGlobalObject->SetPrototype(windowWrapper); |
332 V8DOMWrapper::associateObjectWithWrapper(PassRefPtr<DOMWindow>(window), &V8D
OMWindow::info, windowWrapper, m_isolate, WrapperConfiguration::Dependent); | 369 V8DOMWrapper::associateObjectWithWrapper(PassRefPtr<DOMWindow>(window), &V8D
OMWindow::info, windowWrapper, m_isolate, WrapperConfiguration::Dependent); |
| 370 |
| 371 v8::Handle<v8::Object> innerGlobalObjectForBlinkJS = toInnerGlobalObject(m_c
ontextForBlinkJS.newLocal(m_isolate)); |
| 372 V8DOMWrapper::setNativeInfo(innerGlobalObjectForBlinkJS, &V8DOMWindow::info,
window); |
| 373 innerGlobalObjectForBlinkJS->SetPrototype(windowWrapper); |
| 374 V8DOMWrapper::associateObjectWithWrapper(PassRefPtr<DOMWindow>(window), &V8D
OMWindow::info, windowWrapper, m_isolate, WrapperConfiguration::Dependent); |
| 375 |
333 DOMWrapperWorld::setInitializingWindow(false); | 376 DOMWrapperWorld::setInitializingWindow(false); |
334 return true; | 377 return true; |
335 } | 378 } |
336 | 379 |
337 void V8DOMWindowShell::updateDocumentWrapper(v8::Handle<v8::Object> wrapper) | 380 void V8DOMWindowShell::updateDocumentWrapper(v8::Handle<v8::Object> wrapper) |
338 { | 381 { |
339 ASSERT(m_world->isMainWorld()); | 382 ASSERT(m_world->isMainWorld()); |
340 m_document.set(m_isolate, wrapper); | 383 m_document.set(m_isolate, wrapper); |
341 } | 384 } |
342 | 385 |
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
503 void V8DOMWindowShell::updateSecurityOrigin() | 546 void V8DOMWindowShell::updateSecurityOrigin() |
504 { | 547 { |
505 ASSERT(m_world->isMainWorld()); | 548 ASSERT(m_world->isMainWorld()); |
506 if (m_context.isEmpty()) | 549 if (m_context.isEmpty()) |
507 return; | 550 return; |
508 v8::HandleScope handleScope; | 551 v8::HandleScope handleScope; |
509 setSecurityToken(); | 552 setSecurityToken(); |
510 } | 553 } |
511 | 554 |
512 } // WebCore | 555 } // WebCore |
OLD | NEW |