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

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

Issue 334283004: Rename DOMWindow to LocalDOMWindow (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Rebase Created 6 years, 6 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 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
123 void V8WindowShell::clearForNavigation() 123 void V8WindowShell::clearForNavigation()
124 { 124 {
125 if (!isContextInitialized()) 125 if (!isContextInitialized())
126 return; 126 return;
127 127
128 ScriptState::Scope scope(m_scriptState.get()); 128 ScriptState::Scope scope(m_scriptState.get());
129 129
130 m_document.clear(); 130 m_document.clear();
131 131
132 // Clear the document wrapper cache before turning on access checks on 132 // Clear the document wrapper cache before turning on access checks on
133 // the old DOMWindow wrapper. This way, access to the document wrapper 133 // the old LocalDOMWindow wrapper. This way, access to the document wrapper
134 // will be protected by the security checks on the DOMWindow wrapper. 134 // will be protected by the security checks on the LocalDOMWindow wrapper.
135 clearDocumentProperty(); 135 clearDocumentProperty();
136 136
137 v8::Handle<v8::Object> windowWrapper = V8Window::findInstanceInPrototypeChai n(m_global.newLocal(m_isolate), m_isolate); 137 v8::Handle<v8::Object> windowWrapper = V8Window::findInstanceInPrototypeChai n(m_global.newLocal(m_isolate), m_isolate);
138 ASSERT(!windowWrapper.IsEmpty()); 138 ASSERT(!windowWrapper.IsEmpty());
139 windowWrapper->TurnOnAccessCheck(); 139 windowWrapper->TurnOnAccessCheck();
140 disposeContext(DetachGlobal); 140 disposeContext(DetachGlobal);
141 } 141 }
142 142
143 // Create a new environment and setup the global object. 143 // Create a new environment and setup the global object.
144 // 144 //
145 // The global object corresponds to a DOMWindow instance. However, to 145 // The global object corresponds to a LocalDOMWindow instance. However, to
146 // allow properties of the JS DOMWindow instance to be shadowed, we 146 // allow properties of the JS LocalDOMWindow instance to be shadowed, we
147 // use a shadow object as the global object and use the JS DOMWindow 147 // use a shadow object as the global object and use the JS LocalDOMWindow
148 // instance as the prototype for that shadow object. The JS DOMWindow 148 // instance as the prototype for that shadow object. The JS LocalDOMWindow
149 // instance is undetectable from JavaScript code because the __proto__ 149 // instance is undetectable from JavaScript code because the __proto__
150 // accessors skip that object. 150 // accessors skip that object.
151 // 151 //
152 // The shadow object and the DOMWindow instance are seen as one object 152 // The shadow object and the LocalDOMWindow instance are seen as one object
153 // from JavaScript. The JavaScript object that corresponds to a 153 // from JavaScript. The JavaScript object that corresponds to a
154 // DOMWindow instance is the shadow object. When mapping a DOMWindow 154 // LocalDOMWindow instance is the shadow object. When mapping a LocalDOMWindow
155 // instance to a V8 object, we return the shadow object. 155 // instance to a V8 object, we return the shadow object.
156 // 156 //
157 // To implement split-window, see 157 // To implement split-window, see
158 // 1) https://bugs.webkit.org/show_bug.cgi?id=17249 158 // 1) https://bugs.webkit.org/show_bug.cgi?id=17249
159 // 2) https://wiki.mozilla.org/Gecko:SplitWindow 159 // 2) https://wiki.mozilla.org/Gecko:SplitWindow
160 // 3) https://bugzilla.mozilla.org/show_bug.cgi?id=296639 160 // 3) https://bugzilla.mozilla.org/show_bug.cgi?id=296639
161 // we need to split the shadow object further into two objects: 161 // we need to split the shadow object further into two objects:
162 // an outer window and an inner window. The inner window is the hidden 162 // an outer window and an inner window. The inner window is the hidden
163 // prototype of the outer window. The inner window is the default 163 // prototype of the outer window. The inner window is the default
164 // global object of the context. A variable declared in the global 164 // global object of the context. A variable declared in the global
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
283 blink::Platform::current()->histogramCustomCounts(histogramName, contextCrea tionDurationInMilliseconds, 0, 10000, 50); 283 blink::Platform::current()->histogramCustomCounts(histogramName, contextCrea tionDurationInMilliseconds, 0, 10000, 50);
284 } 284 }
285 285
286 static v8::Handle<v8::Object> toInnerGlobalObject(v8::Handle<v8::Context> contex t) 286 static v8::Handle<v8::Object> toInnerGlobalObject(v8::Handle<v8::Context> contex t)
287 { 287 {
288 return v8::Handle<v8::Object>::Cast(context->Global()->GetPrototype()); 288 return v8::Handle<v8::Object>::Cast(context->Global()->GetPrototype());
289 } 289 }
290 290
291 bool V8WindowShell::installDOMWindow() 291 bool V8WindowShell::installDOMWindow()
292 { 292 {
293 DOMWindow* window = m_frame->domWindow(); 293 LocalDOMWindow* window = m_frame->domWindow();
294 v8::Local<v8::Object> windowWrapper = V8ObjectConstructor::newInstance(m_iso late, m_scriptState->perContextData()->constructorForType(&V8Window::wrapperType Info)); 294 v8::Local<v8::Object> windowWrapper = V8ObjectConstructor::newInstance(m_iso late, m_scriptState->perContextData()->constructorForType(&V8Window::wrapperType Info));
295 if (windowWrapper.IsEmpty()) 295 if (windowWrapper.IsEmpty())
296 return false; 296 return false;
297 297
298 V8Window::installPerContextEnabledProperties(windowWrapper, window, m_isolat e); 298 V8Window::installPerContextEnabledProperties(windowWrapper, window, m_isolat e);
299 299
300 V8DOMWrapper::setNativeInfoForHiddenWrapper(v8::Handle<v8::Object>::Cast(win dowWrapper->GetPrototype()), &V8Window::wrapperTypeInfo, window); 300 V8DOMWrapper::setNativeInfoForHiddenWrapper(v8::Handle<v8::Object>::Cast(win dowWrapper->GetPrototype()), &V8Window::wrapperTypeInfo, window);
301 301
302 // Install the windowWrapper as the prototype of the innerGlobalObject. 302 // Install the windowWrapper as the prototype of the innerGlobalObject.
303 // The full structure of the global object is as follows: 303 // The full structure of the global object is as follows:
304 // 304 //
305 // outerGlobalObject (Empty object, remains after navigation) 305 // outerGlobalObject (Empty object, remains after navigation)
306 // -- has prototype --> innerGlobalObject (Holds global variables, changes during navigation) 306 // -- has prototype --> innerGlobalObject (Holds global variables, changes during navigation)
307 // -- has prototype --> DOMWindow instance 307 // -- has prototype --> LocalDOMWindow instance
308 // -- has prototype --> Window.prototype 308 // -- has prototype --> Window.prototype
309 // -- has prototype --> Object.prototype 309 // -- has prototype --> Object.prototype
310 // 310 //
311 // Note: Much of this prototype structure is hidden from web content. The 311 // Note: Much of this prototype structure is hidden from web content. The
312 // outer, inner, and DOMWindow instance all appear to be the same 312 // outer, inner, and LocalDOMWindow instance all appear to be the same
313 // JavaScript object. 313 // JavaScript object.
314 // 314 //
315 // Note: With Oilpan, the DOMWindow object is garbage collected. 315 // Note: With Oilpan, the LocalDOMWindow object is garbage collected.
316 // Persistent references to this inner global object view of the DOMWi ndow 316 // Persistent references to this inner global object view of the Local DOMWindow
317 // aren't kept, as that would prevent the global object from ever bein g released. 317 // aren't kept, as that would prevent the global object from ever bein g released.
318 // It is safe not to do so, as the wrapper for the DOMWindow being ins talled here 318 // It is safe not to do so, as the wrapper for the LocalDOMWindow bein g installed here
319 // already keeps a persistent reference, and it along with the inner g lobal object 319 // already keeps a persistent reference, and it along with the inner g lobal object
320 // views of the DOMWindow will die together once that wrapper clears t he persistent 320 // views of the LocalDOMWindow will die together once that wrapper cle ars the persistent
321 // reference. 321 // reference.
322 v8::Handle<v8::Object> innerGlobalObject = toInnerGlobalObject(m_scriptState ->context()); 322 v8::Handle<v8::Object> innerGlobalObject = toInnerGlobalObject(m_scriptState ->context());
323 V8DOMWrapper::setNativeInfoForHiddenWrapper(innerGlobalObject, &V8Window::wr apperTypeInfo, window); 323 V8DOMWrapper::setNativeInfoForHiddenWrapper(innerGlobalObject, &V8Window::wr apperTypeInfo, window);
324 innerGlobalObject->SetPrototype(windowWrapper); 324 innerGlobalObject->SetPrototype(windowWrapper);
325 V8DOMWrapper::associateObjectWithWrapper<V8Window>(PassRefPtrWillBeRawPtr<DO MWindow>(window), &V8Window::wrapperTypeInfo, windowWrapper, m_isolate, WrapperC onfiguration::Dependent); 325 V8DOMWrapper::associateObjectWithWrapper<V8Window>(PassRefPtrWillBeRawPtr<Lo calDOMWindow>(window), &V8Window::wrapperTypeInfo, windowWrapper, m_isolate, Wra pperConfiguration::Dependent);
326 return true; 326 return true;
327 } 327 }
328 328
329 void V8WindowShell::updateDocumentWrapper(v8::Handle<v8::Object> wrapper) 329 void V8WindowShell::updateDocumentWrapper(v8::Handle<v8::Object> wrapper)
330 { 330 {
331 ASSERT(m_world->isMainWorld()); 331 ASSERT(m_world->isMainWorld());
332 m_document.set(m_isolate, wrapper); 332 m_document.set(m_isolate, wrapper);
333 } 333 }
334 334
335 void V8WindowShell::updateDocumentProperty() 335 void V8WindowShell::updateDocumentProperty()
336 { 336 {
337 if (!m_world->isMainWorld()) 337 if (!m_world->isMainWorld())
338 return; 338 return;
339 339
340 ScriptState::Scope scope(m_scriptState.get()); 340 ScriptState::Scope scope(m_scriptState.get());
341 v8::Handle<v8::Context> context = m_scriptState->context(); 341 v8::Handle<v8::Context> context = m_scriptState->context();
342 v8::Handle<v8::Value> documentWrapper = toV8(m_frame->document(), context->G lobal(), context->GetIsolate()); 342 v8::Handle<v8::Value> documentWrapper = toV8(m_frame->document(), context->G lobal(), context->GetIsolate());
343 ASSERT(documentWrapper == m_document.newLocal(m_isolate) || m_document.isEmp ty()); 343 ASSERT(documentWrapper == m_document.newLocal(m_isolate) || m_document.isEmp ty());
344 if (m_document.isEmpty()) 344 if (m_document.isEmpty())
345 updateDocumentWrapper(v8::Handle<v8::Object>::Cast(documentWrapper)); 345 updateDocumentWrapper(v8::Handle<v8::Object>::Cast(documentWrapper));
346 checkDocumentWrapper(m_document.newLocal(m_isolate), m_frame->document()); 346 checkDocumentWrapper(m_document.newLocal(m_isolate), m_frame->document());
347 347
348 // If instantiation of the document wrapper fails, clear the cache 348 // If instantiation of the document wrapper fails, clear the cache
349 // and let the DOMWindow accessor handle access to the document. 349 // and let the LocalDOMWindow accessor handle access to the document.
350 if (documentWrapper.IsEmpty()) { 350 if (documentWrapper.IsEmpty()) {
351 clearDocumentProperty(); 351 clearDocumentProperty();
352 return; 352 return;
353 } 353 }
354 ASSERT(documentWrapper->IsObject()); 354 ASSERT(documentWrapper->IsObject());
355 context->Global()->ForceSet(v8AtomicString(m_isolate, "document"), documentW rapper, static_cast<v8::PropertyAttribute>(v8::ReadOnly | v8::DontDelete)); 355 context->Global()->ForceSet(v8AtomicString(m_isolate, "document"), documentW rapper, static_cast<v8::PropertyAttribute>(v8::ReadOnly | v8::DontDelete));
356 356
357 // We also stash a reference to the document on the inner global object so t hat 357 // We also stash a reference to the document on the inner global object so t hat
358 // DOMWindow objects we obtain from JavaScript references are guaranteed to have 358 // LocalDOMWindow objects we obtain from JavaScript references are guarantee d to have
359 // live Document objects. 359 // live Document objects.
360 V8HiddenValue::setHiddenValue(m_isolate, toInnerGlobalObject(context), V8Hid denValue::document(m_isolate), documentWrapper); 360 V8HiddenValue::setHiddenValue(m_isolate, toInnerGlobalObject(context), V8Hid denValue::document(m_isolate), documentWrapper);
361 } 361 }
362 362
363 void V8WindowShell::clearDocumentProperty() 363 void V8WindowShell::clearDocumentProperty()
364 { 364 {
365 ASSERT(isContextInitialized()); 365 ASSERT(isContextInitialized());
366 if (!m_world->isMainWorld()) 366 if (!m_world->isMainWorld())
367 return; 367 return;
368 v8::HandleScope handleScope(m_isolate); 368 v8::HandleScope handleScope(m_isolate);
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
492 492
493 void V8WindowShell::updateSecurityOrigin(SecurityOrigin* origin) 493 void V8WindowShell::updateSecurityOrigin(SecurityOrigin* origin)
494 { 494 {
495 ASSERT(m_world->isMainWorld()); 495 ASSERT(m_world->isMainWorld());
496 if (!isContextInitialized()) 496 if (!isContextInitialized())
497 return; 497 return;
498 setSecurityToken(origin); 498 setSecurityToken(origin);
499 } 499 }
500 500
501 } // WebCore 501 } // WebCore
OLDNEW
« no previous file with comments | « Source/bindings/v8/V8WindowShell.h ('k') | Source/bindings/v8/custom/V8CustomXPathNSResolver.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698