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

Side by Side Diff: Source/bindings/v8/V8WindowShell.cpp

Issue 180773003: Simplify the way to initialize context (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 6 years, 9 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) 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 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
87 : m_frame(frame) 87 : m_frame(frame)
88 , m_world(world) 88 , m_world(world)
89 , m_isolate(isolate) 89 , m_isolate(isolate)
90 { 90 {
91 } 91 }
92 92
93 void V8WindowShell::disposeContext(GlobalDetachmentBehavior behavior) 93 void V8WindowShell::disposeContext(GlobalDetachmentBehavior behavior)
94 { 94 {
95 m_perContextData.clear(); 95 m_perContextData.clear();
96 96
97 if (!m_contextHolder) 97 if (!m_perContextData)
98 return; 98 return;
99 99
100 v8::HandleScope handleScope(m_isolate); 100 v8::HandleScope handleScope(m_isolate);
101 v8::Handle<v8::Context> context = m_contextHolder->context(); 101 v8::Handle<v8::Context> context = m_perContextData->context();
102 m_frame->loader().client()->willReleaseScriptContext(context, m_world->world Id()); 102 m_frame->loader().client()->willReleaseScriptContext(context, m_world->world Id());
103 103
104 if (behavior == DetachGlobal) 104 if (behavior == DetachGlobal)
105 context->DetachGlobal(); 105 context->DetachGlobal();
106 106
107 m_contextHolder.clear(); 107 m_perContextData.clear();
108 108
109 // It's likely that disposing the context has created a lot of 109 // It's likely that disposing the context has created a lot of
110 // garbage. Notify V8 about this so it'll have a chance of cleaning 110 // garbage. Notify V8 about this so it'll have a chance of cleaning
111 // it up when idle. 111 // it up when idle.
112 V8GCForContextDispose::instanceTemplate().notifyContextDisposed(m_frame->isM ainFrame()); 112 V8GCForContextDispose::instanceTemplate().notifyContextDisposed(m_frame->isM ainFrame());
113 } 113 }
114 114
115 void V8WindowShell::clearForClose(bool destroyGlobal) 115 void V8WindowShell::clearForClose(bool destroyGlobal)
116 { 116 {
117 if (destroyGlobal) 117 if (destroyGlobal)
118 m_global.clear(); 118 m_global.clear();
119 119
120 if (!m_contextHolder) 120 if (!m_perContextData)
121 return; 121 return;
122 122
123 m_document.clear(); 123 m_document.clear();
124 disposeContext(DoNotDetachGlobal); 124 disposeContext(DoNotDetachGlobal);
125 } 125 }
126 126
127 void V8WindowShell::clearForNavigation() 127 void V8WindowShell::clearForNavigation()
128 { 128 {
129 if (!m_contextHolder) 129 if (!m_perContextData)
130 return; 130 return;
131 131
132 v8::HandleScope handleScope(m_isolate); 132 v8::HandleScope handleScope(m_isolate);
133 m_document.clear(); 133 m_document.clear();
134 134
135 v8::Handle<v8::Context> context = m_contextHolder->context(); 135 v8::Handle<v8::Context> context = m_perContextData->context();
136 v8::Context::Scope contextScope(context); 136 v8::Context::Scope contextScope(context);
137 137
138 // Clear the document wrapper cache before turning on access checks on 138 // Clear the document wrapper cache before turning on access checks on
139 // the old DOMWindow wrapper. This way, access to the document wrapper 139 // the old DOMWindow wrapper. This way, access to the document wrapper
140 // will be protected by the security checks on the DOMWindow wrapper. 140 // will be protected by the security checks on the DOMWindow wrapper.
141 clearDocumentProperty(); 141 clearDocumentProperty();
142 142
143 v8::Handle<v8::Object> windowWrapper = V8Window::findInstanceInPrototypeChai n(m_global.newLocal(m_isolate), m_isolate); 143 v8::Handle<v8::Object> windowWrapper = V8Window::findInstanceInPrototypeChai n(m_global.newLocal(m_isolate), m_isolate);
144 ASSERT(!windowWrapper.IsEmpty()); 144 ASSERT(!windowWrapper.IsEmpty());
145 windowWrapper->TurnOnAccessCheck(); 145 windowWrapper->TurnOnAccessCheck();
(...skipping 30 matching lines...) Expand all
176 // have its own properties. window.foo = 'x' is delegated to the 176 // have its own properties. window.foo = 'x' is delegated to the
177 // inner window. 177 // inner window.
178 // 178 //
179 // When a frame navigates to a new page, the inner window is cut off 179 // When a frame navigates to a new page, the inner window is cut off
180 // the outer window, and the outer window identify is preserved for 180 // the outer window, and the outer window identify is preserved for
181 // the frame. However, a new inner window is created for the new page. 181 // the frame. However, a new inner window is created for the new page.
182 // If there are JS code holds a closure to the old inner window, 182 // If there are JS code holds a closure to the old inner window,
183 // it won't be able to reach the outer window via its global object. 183 // it won't be able to reach the outer window via its global object.
184 bool V8WindowShell::initializeIfNeeded() 184 bool V8WindowShell::initializeIfNeeded()
185 { 185 {
186 if (m_contextHolder) 186 if (m_perContextData)
187 return true; 187 return true;
188 188
189 ASSERT(!contextBeingInitialized); 189 ASSERT(!contextBeingInitialized);
190 contextBeingInitialized = true; 190 contextBeingInitialized = true;
191 bool result = initialize(); 191 bool result = initialize();
192 contextBeingInitialized = false; 192 contextBeingInitialized = false;
193 return result; 193 return result;
194 } 194 }
195 195
196 bool V8WindowShell::initialize() 196 bool V8WindowShell::initialize()
197 { 197 {
198 TRACE_EVENT0("v8", "V8WindowShell::initialize"); 198 TRACE_EVENT0("v8", "V8WindowShell::initialize");
199 TRACE_EVENT_SCOPED_SAMPLING_STATE("Blink", "InitializeWindow"); 199 TRACE_EVENT_SCOPED_SAMPLING_STATE("Blink", "InitializeWindow");
200 200
201 v8::HandleScope handleScope(m_isolate); 201 v8::HandleScope handleScope(m_isolate);
202 202
203 createContext(); 203 createContext();
204 204
205 if (!m_contextHolder) 205 if (!m_perContextData)
206 return false; 206 return false;
207 207
208 v8::Handle<v8::Context> context = m_contextHolder->context(); 208 v8::Handle<v8::Context> context = m_perContextData->context();
209
210 V8PerContextDataHolder::install(context, m_world.get());
211 bool isMainWorld = m_world->isMainWorld();
212
213 v8::Context::Scope contextScope(context); 209 v8::Context::Scope contextScope(context);
214 210
215 if (m_global.isEmpty()) { 211 if (m_global.isEmpty()) {
216 m_global.set(m_isolate, context->Global()); 212 m_global.set(m_isolate, context->Global());
217 if (m_global.isEmpty()) { 213 if (m_global.isEmpty()) {
218 disposeContext(DoNotDetachGlobal); 214 disposeContext(DoNotDetachGlobal);
219 return false; 215 return false;
220 } 216 }
221 } 217 }
222 218
223 if (!isMainWorld) { 219 if (!m_world->isMainWorld()) {
224 V8WindowShell* mainWindow = m_frame->script().existingWindowShell(DOMWra pperWorld::mainWorld()); 220 V8WindowShell* mainWindow = m_frame->script().existingWindowShell(DOMWra pperWorld::mainWorld());
225 if (mainWindow && !mainWindow->context().IsEmpty()) 221 if (mainWindow && !mainWindow->context().IsEmpty())
226 setInjectedScriptContextDebugId(context, m_frame->script().contextDe bugId(mainWindow->context())); 222 setInjectedScriptContextDebugId(context, m_frame->script().contextDe bugId(mainWindow->context()));
227 } 223 }
228 224
229 m_perContextData = V8PerContextData::create(context);
230 if (!m_perContextData->init()) {
231 disposeContext(DoNotDetachGlobal);
232 return false;
233 }
234 m_perContextData->setActivityLogger(V8DOMActivityLogger::activityLogger(m_wo rld->worldId())); 225 m_perContextData->setActivityLogger(V8DOMActivityLogger::activityLogger(m_wo rld->worldId()));
235 if (!installDOMWindow()) { 226 if (!installDOMWindow()) {
236 disposeContext(DoNotDetachGlobal); 227 disposeContext(DoNotDetachGlobal);
237 return false; 228 return false;
238 } 229 }
239 230
240 if (isMainWorld) { 231 if (m_world->isMainWorld()) {
241 updateDocument(); 232 updateDocument();
242 if (m_frame->document()) { 233 if (m_frame->document()) {
243 setSecurityToken(m_frame->document()->securityOrigin()); 234 setSecurityToken(m_frame->document()->securityOrigin());
244 ContentSecurityPolicy* csp = m_frame->document()->contentSecurityPol icy(); 235 ContentSecurityPolicy* csp = m_frame->document()->contentSecurityPol icy();
245 context->AllowCodeGenerationFromStrings(csp->allowEval(0, ContentSec urityPolicy::SuppressReport)); 236 context->AllowCodeGenerationFromStrings(csp->allowEval(0, ContentSec urityPolicy::SuppressReport));
246 context->SetErrorMessageForCodeGenerationFromStrings(v8String(m_isol ate, csp->evalDisabledErrorMessage())); 237 context->SetErrorMessageForCodeGenerationFromStrings(v8String(m_isol ate, csp->evalDisabledErrorMessage()));
247 } 238 }
248 } else { 239 } else {
249 // Using the default security token means that the canAccess is always 240 // Using the default security token means that the canAccess is always
250 // called, which is slow. 241 // called, which is slow.
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
287 int worldId = m_world->worldId(); 278 int worldId = m_world->worldId();
288 for (size_t i = 0; i < extensions.size(); ++i) { 279 for (size_t i = 0; i < extensions.size(); ++i) {
289 if (!m_frame->loader().client()->allowScriptExtension(extensions[i]->nam e(), extensionGroup, worldId)) 280 if (!m_frame->loader().client()->allowScriptExtension(extensions[i]->nam e(), extensionGroup, worldId))
290 continue; 281 continue;
291 282
292 extensionNames[index++] = extensions[i]->name(); 283 extensionNames[index++] = extensions[i]->name();
293 } 284 }
294 v8::ExtensionConfiguration extensionConfiguration(index, extensionNames.get( )); 285 v8::ExtensionConfiguration extensionConfiguration(index, extensionNames.get( ));
295 286
296 v8::Handle<v8::Context> context = v8::Context::New(m_isolate, &extensionConf iguration, globalTemplate, m_global.newLocal(m_isolate)); 287 v8::Handle<v8::Context> context = v8::Context::New(m_isolate, &extensionConf iguration, globalTemplate, m_global.newLocal(m_isolate));
297 if (!context.IsEmpty()) { 288 if (context.IsEmpty())
298 m_contextHolder = adoptPtr(new gin::ContextHolder(m_isolate)); 289 return;
299 m_contextHolder->SetContext(context); 290 m_perContextData = V8PerContextData::create(context, m_world.get());
300 }
301 291
302 double contextCreationDurationInMilliseconds = (currentTime() - contextCreat ionStartInSeconds) * 1000; 292 double contextCreationDurationInMilliseconds = (currentTime() - contextCreat ionStartInSeconds) * 1000;
303 const char* histogramName = "WebCore.V8WindowShell.createContext.MainWorld"; 293 const char* histogramName = "WebCore.V8WindowShell.createContext.MainWorld";
304 if (!m_world->isMainWorld()) 294 if (!m_world->isMainWorld())
305 histogramName = "WebCore.V8WindowShell.createContext.IsolatedWorld"; 295 histogramName = "WebCore.V8WindowShell.createContext.IsolatedWorld";
306 blink::Platform::current()->histogramCustomCounts(histogramName, contextCrea tionDurationInMilliseconds, 0, 10000, 50); 296 blink::Platform::current()->histogramCustomCounts(histogramName, contextCrea tionDurationInMilliseconds, 0, 10000, 50);
307 } 297 }
308 298
309 static v8::Handle<v8::Object> toInnerGlobalObject(v8::Handle<v8::Context> contex t) 299 static v8::Handle<v8::Object> toInnerGlobalObject(v8::Handle<v8::Context> contex t)
310 { 300 {
311 return v8::Handle<v8::Object>::Cast(context->Global()->GetPrototype()); 301 return v8::Handle<v8::Object>::Cast(context->Global()->GetPrototype());
312 } 302 }
313 303
314 bool V8WindowShell::installDOMWindow() 304 bool V8WindowShell::installDOMWindow()
315 { 305 {
316 DOMWindow* window = m_frame->domWindow(); 306 DOMWindow* window = m_frame->domWindow();
317 v8::Local<v8::Object> windowWrapper = V8ObjectConstructor::newInstance(V8Per ContextData::from(m_contextHolder->context())->constructorForType(&V8Window::wra pperTypeInfo)); 307 v8::Local<v8::Object> windowWrapper = V8ObjectConstructor::newInstance(V8Per ContextData::from(m_perContextData->context())->constructorForType(&V8Window::wr apperTypeInfo));
318 if (windowWrapper.IsEmpty()) 308 if (windowWrapper.IsEmpty())
319 return false; 309 return false;
320 310
321 V8Window::installPerContextEnabledProperties(windowWrapper, window, m_isolat e); 311 V8Window::installPerContextEnabledProperties(windowWrapper, window, m_isolat e);
322 312
323 V8DOMWrapper::setNativeInfo(v8::Handle<v8::Object>::Cast(windowWrapper->GetP rototype()), &V8Window::wrapperTypeInfo, window); 313 V8DOMWrapper::setNativeInfo(v8::Handle<v8::Object>::Cast(windowWrapper->GetP rototype()), &V8Window::wrapperTypeInfo, window);
324 314
325 // Install the windowWrapper as the prototype of the innerGlobalObject. 315 // Install the windowWrapper as the prototype of the innerGlobalObject.
326 // The full structure of the global object is as follows: 316 // The full structure of the global object is as follows:
327 // 317 //
328 // outerGlobalObject (Empty object, remains after navigation) 318 // outerGlobalObject (Empty object, remains after navigation)
329 // -- has prototype --> innerGlobalObject (Holds global variables, changes during navigation) 319 // -- has prototype --> innerGlobalObject (Holds global variables, changes during navigation)
330 // -- has prototype --> DOMWindow instance 320 // -- has prototype --> DOMWindow instance
331 // -- has prototype --> Window.prototype 321 // -- has prototype --> Window.prototype
332 // -- has prototype --> Object.prototype 322 // -- has prototype --> Object.prototype
333 // 323 //
334 // Note: Much of this prototype structure is hidden from web content. The 324 // Note: Much of this prototype structure is hidden from web content. The
335 // outer, inner, and DOMWindow instance all appear to be the same 325 // outer, inner, and DOMWindow instance all appear to be the same
336 // JavaScript object. 326 // JavaScript object.
337 // 327 //
338 v8::Handle<v8::Object> innerGlobalObject = toInnerGlobalObject(m_contextHold er->context()); 328 v8::Handle<v8::Object> innerGlobalObject = toInnerGlobalObject(m_perContextD ata->context());
339 V8DOMWrapper::setNativeInfo(innerGlobalObject, &V8Window::wrapperTypeInfo, w indow); 329 V8DOMWrapper::setNativeInfo(innerGlobalObject, &V8Window::wrapperTypeInfo, w indow);
340 innerGlobalObject->SetPrototype(windowWrapper); 330 innerGlobalObject->SetPrototype(windowWrapper);
341 V8DOMWrapper::associateObjectWithWrapper<V8Window>(PassRefPtr<DOMWindow>(win dow), &V8Window::wrapperTypeInfo, windowWrapper, m_isolate, WrapperConfiguration ::Dependent); 331 V8DOMWrapper::associateObjectWithWrapper<V8Window>(PassRefPtr<DOMWindow>(win dow), &V8Window::wrapperTypeInfo, windowWrapper, m_isolate, WrapperConfiguration ::Dependent);
342 return true; 332 return true;
343 } 333 }
344 334
345 void V8WindowShell::updateDocumentWrapper(v8::Handle<v8::Object> wrapper) 335 void V8WindowShell::updateDocumentWrapper(v8::Handle<v8::Object> wrapper)
346 { 336 {
347 ASSERT(m_world->isMainWorld()); 337 ASSERT(m_world->isMainWorld());
348 m_document.set(m_isolate, wrapper); 338 m_document.set(m_isolate, wrapper);
349 } 339 }
350 340
351 void V8WindowShell::updateDocumentProperty() 341 void V8WindowShell::updateDocumentProperty()
352 { 342 {
353 if (!m_world->isMainWorld()) 343 if (!m_world->isMainWorld())
354 return; 344 return;
355 345
356 v8::HandleScope handleScope(m_isolate); 346 v8::HandleScope handleScope(m_isolate);
357 v8::Handle<v8::Context> context = m_contextHolder->context(); 347 v8::Handle<v8::Context> context = m_perContextData->context();
358 v8::Context::Scope contextScope(context); 348 v8::Context::Scope contextScope(context);
359 349
360 v8::Handle<v8::Value> documentWrapper = toV8(m_frame->document(), v8::Handle <v8::Object>(), context->GetIsolate()); 350 v8::Handle<v8::Value> documentWrapper = toV8(m_frame->document(), v8::Handle <v8::Object>(), context->GetIsolate());
361 ASSERT(documentWrapper == m_document.newLocal(m_isolate) || m_document.isEmp ty()); 351 ASSERT(documentWrapper == m_document.newLocal(m_isolate) || m_document.isEmp ty());
362 if (m_document.isEmpty()) 352 if (m_document.isEmpty())
363 updateDocumentWrapper(v8::Handle<v8::Object>::Cast(documentWrapper)); 353 updateDocumentWrapper(v8::Handle<v8::Object>::Cast(documentWrapper));
364 checkDocumentWrapper(m_document.newLocal(m_isolate), m_frame->document()); 354 checkDocumentWrapper(m_document.newLocal(m_isolate), m_frame->document());
365 355
366 // If instantiation of the document wrapper fails, clear the cache 356 // If instantiation of the document wrapper fails, clear the cache
367 // and let the DOMWindow accessor handle access to the document. 357 // and let the DOMWindow accessor handle access to the document.
368 if (documentWrapper.IsEmpty()) { 358 if (documentWrapper.IsEmpty()) {
369 clearDocumentProperty(); 359 clearDocumentProperty();
370 return; 360 return;
371 } 361 }
372 ASSERT(documentWrapper->IsObject()); 362 ASSERT(documentWrapper->IsObject());
373 context->Global()->ForceSet(v8AtomicString(m_isolate, "document"), documentW rapper, static_cast<v8::PropertyAttribute>(v8::ReadOnly | v8::DontDelete)); 363 context->Global()->ForceSet(v8AtomicString(m_isolate, "document"), documentW rapper, static_cast<v8::PropertyAttribute>(v8::ReadOnly | v8::DontDelete));
374 364
375 // We also stash a reference to the document on the inner global object so t hat 365 // We also stash a reference to the document on the inner global object so t hat
376 // DOMWindow objects we obtain from JavaScript references are guaranteed to have 366 // DOMWindow objects we obtain from JavaScript references are guaranteed to have
377 // live Document objects. 367 // live Document objects.
378 setHiddenValue(m_isolate, toInnerGlobalObject(context), "document", document Wrapper); 368 setHiddenValue(m_isolate, toInnerGlobalObject(context), "document", document Wrapper);
379 } 369 }
380 370
381 void V8WindowShell::clearDocumentProperty() 371 void V8WindowShell::clearDocumentProperty()
382 { 372 {
383 ASSERT(m_contextHolder); 373 ASSERT(m_perContextData);
384 if (!m_world->isMainWorld()) 374 if (!m_world->isMainWorld())
385 return; 375 return;
386 v8::HandleScope handleScope(m_isolate); 376 v8::HandleScope handleScope(m_isolate);
387 m_contextHolder->context()->Global()->ForceDelete(v8AtomicString(m_isolate, "document")); 377 m_perContextData->context()->Global()->ForceDelete(v8AtomicString(m_isolate, "document"));
388 } 378 }
389 379
390 void V8WindowShell::setSecurityToken(SecurityOrigin* origin) 380 void V8WindowShell::setSecurityToken(SecurityOrigin* origin)
391 { 381 {
392 ASSERT(m_world->isMainWorld()); 382 ASSERT(m_world->isMainWorld());
393 // If two tokens are equal, then the SecurityOrigins canAccess each other. 383 // If two tokens are equal, then the SecurityOrigins canAccess each other.
394 // If two tokens are not equal, then we have to call canAccess. 384 // If two tokens are not equal, then we have to call canAccess.
395 // Note: we can't use the HTTPOrigin if it was set from the DOM. 385 // Note: we can't use the HTTPOrigin if it was set from the DOM.
396 String token; 386 String token;
397 // We stick with an empty token if document.domain was modified or if we 387 // We stick with an empty token if document.domain was modified or if we
398 // are in the initial empty document, so that we can do a full canAccess 388 // are in the initial empty document, so that we can do a full canAccess
399 // check in those cases. 389 // check in those cases.
400 if (!origin->domainWasSetInDOM() 390 if (!origin->domainWasSetInDOM()
401 && !m_frame->loader().stateMachine()->isDisplayingInitialEmptyDocument() ) 391 && !m_frame->loader().stateMachine()->isDisplayingInitialEmptyDocument() )
402 token = origin->toString(); 392 token = origin->toString();
403 393
404 // An empty or "null" token means we always have to call 394 // An empty or "null" token means we always have to call
405 // canAccess. The toString method on securityOrigins returns the 395 // canAccess. The toString method on securityOrigins returns the
406 // string "null" for empty security origins and for security 396 // string "null" for empty security origins and for security
407 // origins that should only allow access to themselves. In this 397 // origins that should only allow access to themselves. In this
408 // case, we use the global object as the security token to avoid 398 // case, we use the global object as the security token to avoid
409 // calling canAccess when a script accesses its own objects. 399 // calling canAccess when a script accesses its own objects.
410 v8::HandleScope handleScope(m_isolate); 400 v8::HandleScope handleScope(m_isolate);
411 v8::Handle<v8::Context> context = m_contextHolder->context(); 401 v8::Handle<v8::Context> context = m_perContextData->context();
412 if (token.isEmpty() || token == "null") { 402 if (token.isEmpty() || token == "null") {
413 context->UseDefaultSecurityToken(); 403 context->UseDefaultSecurityToken();
414 return; 404 return;
415 } 405 }
416 406
417 CString utf8Token = token.utf8(); 407 CString utf8Token = token.utf8();
418 // NOTE: V8 does identity comparison in fast path, must use a symbol 408 // NOTE: V8 does identity comparison in fast path, must use a symbol
419 // as the security token. 409 // as the security token.
420 context->SetSecurityToken(v8AtomicString(m_isolate, utf8Token.data(), utf8To ken.length())); 410 context->SetSecurityToken(v8AtomicString(m_isolate, utf8Token.data(), utf8To ken.length()));
421 } 411 }
422 412
423 void V8WindowShell::updateDocument() 413 void V8WindowShell::updateDocument()
424 { 414 {
425 ASSERT(m_world->isMainWorld()); 415 ASSERT(m_world->isMainWorld());
426 if (m_global.isEmpty()) 416 if (m_global.isEmpty())
427 return; 417 return;
428 if (!m_contextHolder) 418 if (!m_perContextData)
429 return; 419 return;
430 updateDocumentProperty(); 420 updateDocumentProperty();
431 updateSecurityOrigin(m_frame->document()->securityOrigin()); 421 updateSecurityOrigin(m_frame->document()->securityOrigin());
432 } 422 }
433 423
434 static v8::Handle<v8::Value> getNamedProperty(HTMLDocument* htmlDocument, const AtomicString& key, v8::Handle<v8::Object> creationContext, v8::Isolate* isolate) 424 static v8::Handle<v8::Value> getNamedProperty(HTMLDocument* htmlDocument, const AtomicString& key, v8::Handle<v8::Object> creationContext, v8::Isolate* isolate)
435 { 425 {
436 if (!htmlDocument->hasNamedItem(key) && !htmlDocument->hasExtraNamedItem(key )) 426 if (!htmlDocument->hasNamedItem(key) && !htmlDocument->hasExtraNamedItem(key ))
437 return v8Undefined(); 427 return v8Undefined();
438 428
(...skipping 26 matching lines...) Expand all
465 if (prototype->IsObject()) { 455 if (prototype->IsObject()) {
466 v8SetReturnValue(info, prototype.As<v8::Object>()->Get(property)); 456 v8SetReturnValue(info, prototype.As<v8::Object>()->Get(property));
467 return; 457 return;
468 } 458 }
469 } 459 }
470 460
471 void V8WindowShell::namedItemAdded(HTMLDocument* document, const AtomicString& n ame) 461 void V8WindowShell::namedItemAdded(HTMLDocument* document, const AtomicString& n ame)
472 { 462 {
473 ASSERT(m_world->isMainWorld()); 463 ASSERT(m_world->isMainWorld());
474 464
475 if (!m_contextHolder) 465 if (!m_perContextData)
476 return; 466 return;
477 467
478 v8::HandleScope handleScope(m_isolate); 468 v8::HandleScope handleScope(m_isolate);
479 v8::Context::Scope contextScope(m_contextHolder->context()); 469 v8::Context::Scope contextScope(m_perContextData->context());
480 470
481 ASSERT(!m_document.isEmpty()); 471 ASSERT(!m_document.isEmpty());
482 v8::Handle<v8::Object> documentHandle = m_document.newLocal(m_isolate); 472 v8::Handle<v8::Object> documentHandle = m_document.newLocal(m_isolate);
483 checkDocumentWrapper(documentHandle, document); 473 checkDocumentWrapper(documentHandle, document);
484 documentHandle->SetAccessor(v8String(m_isolate, name), getter); 474 documentHandle->SetAccessor(v8String(m_isolate, name), getter);
485 } 475 }
486 476
487 void V8WindowShell::namedItemRemoved(HTMLDocument* document, const AtomicString& name) 477 void V8WindowShell::namedItemRemoved(HTMLDocument* document, const AtomicString& name)
488 { 478 {
489 ASSERT(m_world->isMainWorld()); 479 ASSERT(m_world->isMainWorld());
490 480
491 if (!m_contextHolder) 481 if (!m_perContextData)
492 return; 482 return;
493 483
494 if (document->hasNamedItem(name) || document->hasExtraNamedItem(name)) 484 if (document->hasNamedItem(name) || document->hasExtraNamedItem(name))
495 return; 485 return;
496 486
497 v8::HandleScope handleScope(m_isolate); 487 v8::HandleScope handleScope(m_isolate);
498 v8::Context::Scope contextScope(m_contextHolder->context()); 488 v8::Context::Scope contextScope(m_perContextData->context());
499 489
500 ASSERT(!m_document.isEmpty()); 490 ASSERT(!m_document.isEmpty());
501 v8::Handle<v8::Object> documentHandle = m_document.newLocal(m_isolate); 491 v8::Handle<v8::Object> documentHandle = m_document.newLocal(m_isolate);
502 checkDocumentWrapper(documentHandle, document); 492 checkDocumentWrapper(documentHandle, document);
503 documentHandle->Delete(v8String(m_isolate, name)); 493 documentHandle->Delete(v8String(m_isolate, name));
504 } 494 }
505 495
506 void V8WindowShell::updateSecurityOrigin(SecurityOrigin* origin) 496 void V8WindowShell::updateSecurityOrigin(SecurityOrigin* origin)
507 { 497 {
508 ASSERT(m_world->isMainWorld()); 498 ASSERT(m_world->isMainWorld());
509 if (!m_contextHolder) 499 if (!m_perContextData)
510 return; 500 return;
511 v8::HandleScope handleScope(m_isolate); 501 v8::HandleScope handleScope(m_isolate);
512 setSecurityToken(origin); 502 setSecurityToken(origin);
513 } 503 }
514 504
515 bool V8WindowShell::contextHasCorrectPrototype(v8::Handle<v8::Context> context) 505 bool V8WindowShell::contextHasCorrectPrototype(v8::Handle<v8::Context> context)
516 { 506 {
517 if (!isMainThread()) 507 if (!isMainThread())
518 return true; 508 return true;
519 // We're initializing the context, so it is not yet in a status where we can 509 // We're initializing the context, so it is not yet in a status where we can
520 // validate the context. 510 // validate the context.
521 if (contextBeingInitialized) 511 if (contextBeingInitialized)
522 return true; 512 return true;
523 return !!toDOMWindow(context); 513 return !!toDOMWindow(context);
524 } 514 }
525 515
526 } // WebCore 516 } // WebCore
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698