| 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 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 57 #include "platform/ScriptForbiddenScope.h" | 57 #include "platform/ScriptForbiddenScope.h" |
| 58 #include "platform/heap/Handle.h" | 58 #include "platform/heap/Handle.h" |
| 59 #include "platform/instrumentation/tracing/TraceEvent.h" | 59 #include "platform/instrumentation/tracing/TraceEvent.h" |
| 60 #include "platform/weborigin/SecurityOrigin.h" | 60 #include "platform/weborigin/SecurityOrigin.h" |
| 61 #include "platform/weborigin/SecurityViolationReportingPolicy.h" | 61 #include "platform/weborigin/SecurityViolationReportingPolicy.h" |
| 62 #include "platform/wtf/Assertions.h" | 62 #include "platform/wtf/Assertions.h" |
| 63 #include "v8/include/v8.h" | 63 #include "v8/include/v8.h" |
| 64 | 64 |
| 65 namespace blink { | 65 namespace blink { |
| 66 | 66 |
| 67 void LocalWindowProxy::DisposeContext(GlobalDetachmentBehavior behavior) { | 67 void LocalWindowProxy::DisposeContext(Lifecycle next_status) { |
| 68 DCHECK(next_status == Lifecycle::kGlobalObjectIsDetached || |
| 69 next_status == Lifecycle::kFrameIsDetached); |
| 70 |
| 68 if (lifecycle_ != Lifecycle::kContextIsInitialized) | 71 if (lifecycle_ != Lifecycle::kContextIsInitialized) |
| 69 return; | 72 return; |
| 70 | 73 |
| 71 ScriptState::Scope scope(script_state_.Get()); | 74 ScriptState::Scope scope(script_state_.Get()); |
| 72 v8::Local<v8::Context> context = script_state_->GetContext(); | 75 v8::Local<v8::Context> context = script_state_->GetContext(); |
| 73 // The embedder could run arbitrary code in response to the | 76 // The embedder could run arbitrary code in response to the |
| 74 // willReleaseScriptContext callback, so all disposing should happen after | 77 // willReleaseScriptContext callback, so all disposing should happen after |
| 75 // it returns. | 78 // it returns. |
| 76 GetFrame()->Loader().Client()->WillReleaseScriptContext(context, | 79 GetFrame()->Loader().Client()->WillReleaseScriptContext(context, |
| 77 world_->GetWorldId()); | 80 world_->GetWorldId()); |
| 78 MainThreadDebugger::Instance()->ContextWillBeDestroyed(script_state_.Get()); | 81 MainThreadDebugger::Instance()->ContextWillBeDestroyed(script_state_.Get()); |
| 79 | 82 |
| 80 if (behavior == kDetachGlobal) { | 83 if (next_status == Lifecycle::kGlobalObjectIsDetached) { |
| 81 v8::Local<v8::Context> context = script_state_->GetContext(); | 84 v8::Local<v8::Context> context = script_state_->GetContext(); |
| 82 // Clean up state on the global proxy, which will be reused. | 85 // Clean up state on the global proxy, which will be reused. |
| 83 if (!global_proxy_.IsEmpty()) { | 86 if (!global_proxy_.IsEmpty()) { |
| 84 CHECK(global_proxy_ == context->Global()); | 87 CHECK(global_proxy_ == context->Global()); |
| 85 CHECK_EQ(ToScriptWrappable(context->Global()), | 88 CHECK_EQ(ToScriptWrappable(context->Global()), |
| 86 ToScriptWrappable( | 89 ToScriptWrappable( |
| 87 context->Global()->GetPrototype().As<v8::Object>())); | 90 context->Global()->GetPrototype().As<v8::Object>())); |
| 88 global_proxy_.Get().SetWrapperClassId(0); | 91 global_proxy_.Get().SetWrapperClassId(0); |
| 89 } | 92 } |
| 90 V8DOMWrapper::ClearNativeInfo(GetIsolate(), context->Global()); | 93 V8DOMWrapper::ClearNativeInfo(GetIsolate(), context->Global()); |
| 91 script_state_->DetachGlobalObject(); | 94 script_state_->DetachGlobalObject(); |
| 92 | 95 |
| 93 #if DCHECK_IS_ON() | 96 #if DCHECK_IS_ON() |
| 94 DidDetachGlobalObject(); | 97 DidDetachGlobalObject(); |
| 95 #endif | 98 #endif |
| 96 } | 99 } |
| 97 | 100 |
| 98 script_state_->DisposePerContextData(); | 101 script_state_->DisposePerContextData(); |
| 99 | 102 |
| 100 // It's likely that disposing the context has created a lot of | 103 // It's likely that disposing the context has created a lot of |
| 101 // garbage. Notify V8 about this so it'll have a chance of cleaning | 104 // garbage. Notify V8 about this so it'll have a chance of cleaning |
| 102 // it up when idle. | 105 // it up when idle. |
| 103 V8GCForContextDispose::Instance().NotifyContextDisposed( | 106 V8GCForContextDispose::Instance().NotifyContextDisposed( |
| 104 GetFrame()->IsMainFrame()); | 107 GetFrame()->IsMainFrame()); |
| 105 | 108 |
| 106 DCHECK_EQ(lifecycle_, Lifecycle::kContextIsInitialized); | 109 DCHECK_EQ(lifecycle_, Lifecycle::kContextIsInitialized); |
| 107 lifecycle_ = behavior == kDetachGlobal ? Lifecycle::kGlobalObjectIsDetached | 110 lifecycle_ = next_status; |
| 108 : Lifecycle::kFrameIsDetached; | |
| 109 } | 111 } |
| 110 | 112 |
| 111 void LocalWindowProxy::Initialize() { | 113 void LocalWindowProxy::Initialize() { |
| 112 TRACE_EVENT1("v8", "LocalWindowProxy::initialize", "isMainWindow", | 114 TRACE_EVENT1("v8", "LocalWindowProxy::initialize", "isMainWindow", |
| 113 GetFrame()->IsMainFrame()); | 115 GetFrame()->IsMainFrame()); |
| 114 SCOPED_BLINK_UMA_HISTOGRAM_TIMER( | 116 SCOPED_BLINK_UMA_HISTOGRAM_TIMER( |
| 115 GetFrame()->IsMainFrame() | 117 GetFrame()->IsMainFrame() |
| 116 ? "Blink.Binding.InitializeMainLocalWindowProxy" | 118 ? "Blink.Binding.InitializeMainLocalWindowProxy" |
| 117 : "Blink.Binding.InitializeNonMainLocalWindowProxy"); | 119 : "Blink.Binding.InitializeNonMainLocalWindowProxy"); |
| 118 | 120 |
| (...skipping 322 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 441 | 443 |
| 442 SetSecurityToken(origin); | 444 SetSecurityToken(origin); |
| 443 } | 445 } |
| 444 | 446 |
| 445 LocalWindowProxy::LocalWindowProxy(v8::Isolate* isolate, | 447 LocalWindowProxy::LocalWindowProxy(v8::Isolate* isolate, |
| 446 LocalFrame& frame, | 448 LocalFrame& frame, |
| 447 RefPtr<DOMWrapperWorld> world) | 449 RefPtr<DOMWrapperWorld> world) |
| 448 : WindowProxy(isolate, frame, std::move(world)) {} | 450 : WindowProxy(isolate, frame, std::move(world)) {} |
| 449 | 451 |
| 450 } // namespace blink | 452 } // namespace blink |
| OLD | NEW |