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 200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
211 // via window.window, window.self, window.parent, etc. The outer window | 211 // via window.window, window.self, window.parent, etc. The outer window |
212 // has a security token which is the domain. The outer window cannot | 212 // has a security token which is the domain. The outer window cannot |
213 // have its own properties. window.foo = 'x' is delegated to the | 213 // have its own properties. window.foo = 'x' is delegated to the |
214 // inner window. | 214 // inner window. |
215 // | 215 // |
216 // When a frame navigates to a new page, the inner window is cut off | 216 // When a frame navigates to a new page, the inner window is cut off |
217 // the outer window, and the outer window identify is preserved for | 217 // the outer window, and the outer window identify is preserved for |
218 // the frame. However, a new inner window is created for the new page. | 218 // the frame. However, a new inner window is created for the new page. |
219 // If there are JS code holds a closure to the old inner window, | 219 // If there are JS code holds a closure to the old inner window, |
220 // it won't be able to reach the outer window via its global object. | 220 // it won't be able to reach the outer window via its global object. |
221 bool WindowProxy::initializeIfNeeded() { | 221 void WindowProxy::initializeIfNeeded() { |
222 if (isContextInitialized()) | 222 if (isContextInitialized()) |
223 return true; | 223 return; |
224 | 224 initialize(); |
225 return initialize(); | |
226 } | 225 } |
227 | 226 |
228 bool WindowProxy::initialize() { | 227 void WindowProxy::initialize() { |
229 TRACE_EVENT1("v8", "WindowProxy::initialize", "isMainWindow", | 228 TRACE_EVENT1("v8", "WindowProxy::initialize", "isMainWindow", |
230 m_frame->isMainFrame()); | 229 m_frame->isMainFrame()); |
231 SCOPED_BLINK_UMA_HISTOGRAM_TIMER( | 230 SCOPED_BLINK_UMA_HISTOGRAM_TIMER( |
232 m_frame->isMainFrame() ? "Blink.Binding.InitializeMainWindowProxy" | 231 m_frame->isMainFrame() ? "Blink.Binding.InitializeMainWindowProxy" |
233 : "Blink.Binding.InitializeNonMainWindowProxy"); | 232 : "Blink.Binding.InitializeNonMainWindowProxy"); |
234 | 233 |
235 ScriptForbiddenScope::AllowUserAgentScript allowScript; | 234 ScriptForbiddenScope::AllowUserAgentScript allowScript; |
236 | 235 |
237 v8::HandleScope handleScope(m_isolate); | 236 v8::HandleScope handleScope(m_isolate); |
238 | 237 |
239 createContext(); | 238 createContext(); |
240 | 239 CHECK(isContextInitialized()); |
haraken
2016/12/27 15:15:40
isContextInitialized() should return true here bec
| |
241 if (!isContextInitialized()) | |
242 return false; | |
243 | 240 |
244 ScriptState::Scope scope(m_scriptState.get()); | 241 ScriptState::Scope scope(m_scriptState.get()); |
245 v8::Local<v8::Context> context = m_scriptState->context(); | 242 v8::Local<v8::Context> context = m_scriptState->context(); |
246 if (m_globalProxy.isEmpty()) { | 243 if (m_globalProxy.isEmpty()) { |
247 m_globalProxy.set(m_isolate, context->Global()); | 244 m_globalProxy.set(m_isolate, context->Global()); |
248 if (m_globalProxy.isEmpty()) { | 245 CHECK(!m_globalProxy.isEmpty()); |
haraken
2016/12/27 15:15:40
Unless V8 hits OOM or stack-overflow, m_globalProx
| |
249 disposeContext(DoNotDetachGlobal); | |
250 return false; | |
251 } | |
252 } | 246 } |
253 | 247 |
254 if (!setupWindowPrototypeChain()) { | 248 setupWindowPrototypeChain(); |
haraken
2016/12/27 15:15:40
setupWindowPrototypeChain() never returns false.
| |
255 disposeContext(DoNotDetachGlobal); | |
256 return false; | |
257 } | |
258 | 249 |
259 SecurityOrigin* origin = 0; | 250 SecurityOrigin* origin = 0; |
260 if (m_world->isMainWorld()) { | 251 if (m_world->isMainWorld()) { |
261 // ActivityLogger for main world is updated within updateDocument(). | 252 // ActivityLogger for main world is updated within updateDocument(). |
262 updateDocument(); | 253 updateDocument(); |
263 origin = m_frame->securityContext()->getSecurityOrigin(); | 254 origin = m_frame->securityContext()->getSecurityOrigin(); |
264 // FIXME: Can this be removed when CSP moves to browser? | 255 // FIXME: Can this be removed when CSP moves to browser? |
265 ContentSecurityPolicy* csp = | 256 ContentSecurityPolicy* csp = |
266 m_frame->securityContext()->contentSecurityPolicy(); | 257 m_frame->securityContext()->contentSecurityPolicy(); |
267 context->AllowCodeGenerationFromStrings( | 258 context->AllowCodeGenerationFromStrings( |
(...skipping 11 matching lines...) Expand all Loading... | |
279 MainThreadDebugger::instance()->contextCreated(m_scriptState.get(), frame, | 270 MainThreadDebugger::instance()->contextCreated(m_scriptState.get(), frame, |
280 origin); | 271 origin); |
281 frame->loader().client()->didCreateScriptContext( | 272 frame->loader().client()->didCreateScriptContext( |
282 context, m_world->extensionGroup(), m_world->worldId()); | 273 context, m_world->extensionGroup(), m_world->worldId()); |
283 } | 274 } |
284 // If conditional features for window have been queued before the V8 context | 275 // If conditional features for window have been queued before the V8 context |
285 // was ready, then inject them into the context now | 276 // was ready, then inject them into the context now |
286 if (m_world->isMainWorld()) { | 277 if (m_world->isMainWorld()) { |
287 installPendingConditionalFeaturesOnWindow(m_scriptState.get()); | 278 installPendingConditionalFeaturesOnWindow(m_scriptState.get()); |
288 } | 279 } |
289 | |
290 return true; | |
291 } | 280 } |
292 | 281 |
293 void WindowProxy::createContext() { | 282 void WindowProxy::createContext() { |
294 // Create a new v8::Context with the window object as the global object | 283 // Create a new v8::Context with the window object as the global object |
295 // (aka the inner global). Reuse the global proxy object (aka the outer | 284 // (aka the inner global). Reuse the global proxy object (aka the outer |
296 // global) if it already exists. See the comments in | 285 // global) if it already exists. See the comments in |
297 // setupWindowPrototypeChain for the structure of the prototype chain of | 286 // setupWindowPrototypeChain for the structure of the prototype chain of |
298 // the global object. | 287 // the global object. |
299 v8::Local<v8::ObjectTemplate> globalTemplate = | 288 v8::Local<v8::ObjectTemplate> globalTemplate = |
300 V8Window::domTemplate(m_isolate, *m_world)->InstanceTemplate(); | 289 V8Window::domTemplate(m_isolate, *m_world)->InstanceTemplate(); |
(...skipping 27 matching lines...) Expand all Loading... | |
328 V8PerIsolateData::from(m_isolate)); | 317 V8PerIsolateData::from(m_isolate)); |
329 context = | 318 context = |
330 v8::Context::New(m_isolate, &extensionConfiguration, globalTemplate, | 319 v8::Context::New(m_isolate, &extensionConfiguration, globalTemplate, |
331 m_globalProxy.newLocal(m_isolate)); | 320 m_globalProxy.newLocal(m_isolate)); |
332 } | 321 } |
333 CHECK(!context.IsEmpty()); | 322 CHECK(!context.IsEmpty()); |
334 | 323 |
335 m_scriptState = ScriptState::create(context, m_world); | 324 m_scriptState = ScriptState::create(context, m_world); |
336 } | 325 } |
337 | 326 |
338 bool WindowProxy::setupWindowPrototypeChain() { | 327 void WindowProxy::setupWindowPrototypeChain() { |
339 // Associate the window wrapper object and its prototype chain with the | 328 // Associate the window wrapper object and its prototype chain with the |
340 // corresponding native DOMWindow object. | 329 // corresponding native DOMWindow object. |
341 // The full structure of the global object's prototype chain is as follows: | 330 // The full structure of the global object's prototype chain is as follows: |
342 // | 331 // |
343 // global proxy object [1] | 332 // global proxy object [1] |
344 // -- has prototype --> global object (window wrapper object) [2] | 333 // -- has prototype --> global object (window wrapper object) [2] |
345 // -- has prototype --> Window.prototype | 334 // -- has prototype --> Window.prototype |
346 // -- has prototype --> WindowProperties [3] | 335 // -- has prototype --> WindowProperties [3] |
347 // -- has prototype --> EventTarget.prototype | 336 // -- has prototype --> EventTarget.prototype |
348 // -- has prototype --> Object.prototype | 337 // -- has prototype --> Object.prototype |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
393 v8::Local<v8::Object> windowProperties = | 382 v8::Local<v8::Object> windowProperties = |
394 windowPrototype->GetPrototype().As<v8::Object>(); | 383 windowPrototype->GetPrototype().As<v8::Object>(); |
395 CHECK(!windowProperties.IsEmpty()); | 384 CHECK(!windowProperties.IsEmpty()); |
396 V8DOMWrapper::setNativeInfo(m_isolate, windowProperties, wrapperTypeInfo, | 385 V8DOMWrapper::setNativeInfo(m_isolate, windowProperties, wrapperTypeInfo, |
397 window); | 386 window); |
398 | 387 |
399 // TODO(keishi): Remove installPagePopupController and implement | 388 // TODO(keishi): Remove installPagePopupController and implement |
400 // PagePopupController in another way. | 389 // PagePopupController in another way. |
401 V8PagePopupControllerBinding::installPagePopupController(context, | 390 V8PagePopupControllerBinding::installPagePopupController(context, |
402 windowWrapper); | 391 windowWrapper); |
403 return true; | |
404 } | 392 } |
405 | 393 |
406 void WindowProxy::updateDocumentProperty() { | 394 void WindowProxy::updateDocumentProperty() { |
407 DCHECK(m_world->isMainWorld()); | 395 DCHECK(m_world->isMainWorld()); |
408 | 396 |
409 if (m_frame->isRemoteFrame()) | 397 if (m_frame->isRemoteFrame()) |
410 return; | 398 return; |
411 | 399 |
412 ScriptState::Scope scope(m_scriptState.get()); | 400 ScriptState::Scope scope(m_scriptState.get()); |
413 v8::Local<v8::Context> context = m_scriptState->context(); | 401 v8::Local<v8::Context> context = m_scriptState->context(); |
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
571 .ToChecked(); | 559 .ToChecked(); |
572 } | 560 } |
573 | 561 |
574 void WindowProxy::updateSecurityOrigin(SecurityOrigin* origin) { | 562 void WindowProxy::updateSecurityOrigin(SecurityOrigin* origin) { |
575 if (!isContextInitialized()) | 563 if (!isContextInitialized()) |
576 return; | 564 return; |
577 setSecurityToken(origin); | 565 setSecurityToken(origin); |
578 } | 566 } |
579 | 567 |
580 } // namespace blink | 568 } // namespace blink |
OLD | NEW |