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

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

Powered by Google App Engine
This is Rietveld 408576698