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

Unified Diff: third_party/WebKit/Source/bindings/core/v8/LocalWindowProxy.cpp

Issue 2841443005: [Bindings] Create and use V8 context snapshots (Closed)
Patch Set: Work for some comments Created 3 years, 7 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 side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/Source/bindings/core/v8/LocalWindowProxy.cpp
diff --git a/third_party/WebKit/Source/bindings/core/v8/LocalWindowProxy.cpp b/third_party/WebKit/Source/bindings/core/v8/LocalWindowProxy.cpp
index 3b33bb890be160e9c7ee7d28faaae173b2a5a685..1faecaa91cd5714d845fa9920431ef05ec55807c 100644
--- a/third_party/WebKit/Source/bindings/core/v8/LocalWindowProxy.cpp
+++ b/third_party/WebKit/Source/bindings/core/v8/LocalWindowProxy.cpp
@@ -39,6 +39,7 @@
#include "bindings/core/v8/V8HTMLDocument.h"
#include "bindings/core/v8/V8Initializer.h"
#include "bindings/core/v8/V8PagePopupControllerBinding.h"
+#include "bindings/core/v8/V8SnapshotCreator.h"
#include "bindings/core/v8/V8Window.h"
#include "core/dom/Modulator.h"
#include "core/frame/LocalFrame.h"
@@ -157,26 +158,27 @@ void LocalWindowProxy::Initialize() {
SetSecurityToken(origin);
}
- MainThreadDebugger::Instance()->ContextCreated(script_state_.Get(),
- GetFrame(), origin);
- GetFrame()->Loader().Client()->DidCreateScriptContext(context,
- world_->GetWorldId());
- // If conditional features for window have been queued before the V8 context
- // was ready, then inject them into the context now
- if (world_->IsMainWorld()) {
- InstallConditionalFeaturesOnWindow(script_state_.Get());
+ {
+ TRACE_EVENT1("v8", "notification", "isMainWindow",
+ GetFrame()->IsMainFrame());
+ MainThreadDebugger::Instance()->ContextCreated(script_state_.Get(),
+ GetFrame(), origin);
+ GetFrame()->Loader().Client()->DidCreateScriptContext(context,
+ world_->GetWorldId());
+ // If conditional features for window have been queued before the V8 context
+ // was ready, then inject them into the context now
+ if (world_->IsMainWorld()) {
+ InstallConditionalFeaturesOnWindow(script_state_.Get());
+ GetFrame()->Loader().DispatchDidClearWindowObjectInMainWorld();
+ }
}
-
- if (world_->IsMainWorld())
- GetFrame()->Loader().DispatchDidClearWindowObjectInMainWorld();
}
void LocalWindowProxy::CreateContext() {
- // Create a new v8::Context with the window object as the global object
- // (aka the inner global). Reuse the outer global proxy if it already exists.
- v8::Local<v8::ObjectTemplate> global_template =
- V8Window::domTemplate(GetIsolate(), *world_)->InstanceTemplate();
- CHECK(!global_template.IsEmpty());
+ TRACE_EVENT1("v8", "LocalWindowProxy::CreateContext", "isMainWindow",
+ GetFrame()->IsMainFrame());
+
+ V8SnapshotCreator::EnsureInterfaceTemplates(GetIsolate(), World());
Vector<const char*> extension_names;
// Dynamically tell v8 about our extensions now.
@@ -193,9 +195,21 @@ void LocalWindowProxy::CreateContext() {
{
V8PerIsolateData::UseCounterDisabledScope use_counter_disabled(
V8PerIsolateData::From(GetIsolate()));
- context =
- v8::Context::New(GetIsolate(), &extension_configuration,
- global_template, global_proxy_.NewLocal(GetIsolate()));
+ TRACE_EVENT1("v8", "contextCreation", "isMainWindow",
+ GetFrame()->IsMainFrame());
+
+ v8::Local<v8::Object> global_proxy = global_proxy_.NewLocal(GetIsolate());
+ context = V8SnapshotCreator::CreateContext(
+ GetIsolate(), World(), &extension_configuration, global_proxy,
+ GetFrame()->GetDocument());
+
+ if (context.IsEmpty()) {
+ v8::Local<v8::ObjectTemplate> global_template =
+ V8Window::domTemplate(GetIsolate(), *world_)->InstanceTemplate();
+ CHECK(!global_template.IsEmpty());
+ context = v8::Context::New(GetIsolate(), &extension_configuration,
+ global_template, global_proxy);
+ }
}
CHECK(!context.IsEmpty());
@@ -212,6 +226,9 @@ void LocalWindowProxy::CreateContext() {
}
void LocalWindowProxy::SetupWindowPrototypeChain() {
+ TRACE_EVENT1("v8", "LocalWindowProxy::setupWindowPrototypeChain",
+ "isMainWindow", GetFrame()->IsMainFrame());
+
// Associate the window wrapper object and its prototype chain with the
// corresponding native DOMWindow object.
DOMWindow* window = GetFrame()->DomWindow();
@@ -248,6 +265,9 @@ void LocalWindowProxy::SetupWindowPrototypeChain() {
V8DOMWrapper::SetNativeInfo(GetIsolate(), window_properties,
wrapper_type_info, window);
+ V8SnapshotCreator::InstallRuntimeEnabledFeaturesOnGlobal(script_state_.Get(),
+ window_wrapper);
+
// TODO(keishi): Remove installPagePopupController and implement
// PagePopupController in another way.
V8PagePopupControllerBinding::InstallPagePopupController(context,
@@ -256,12 +276,18 @@ void LocalWindowProxy::SetupWindowPrototypeChain() {
void LocalWindowProxy::UpdateDocumentProperty() {
DCHECK(world_->IsMainWorld());
+ TRACE_EVENT1("v8", "LocalWindowProxy::updateDocumentProperty", "isMainWindow",
+ GetFrame()->IsMainFrame());
ScriptState::Scope scope(script_state_.Get());
v8::Local<v8::Context> context = script_state_->GetContext();
v8::Local<v8::Value> document_wrapper =
ToV8(GetFrame()->GetDocument(), context->Global(), GetIsolate());
DCHECK(document_wrapper->IsObject());
+
+ V8SnapshotCreator::InstallRuntimeEnabledFeaturesOnDocument(
+ script_state_.Get(), document_wrapper.As<v8::Object>());
haraken 2017/05/20 19:10:02 UpdateDocumentProperty() is called every time wind
peria 2017/05/30 08:25:44 Agree. will do in the next update.
+
// Update the cached accessor for window.document.
CHECK(V8PrivateProperty::GetWindowDocumentCachedAccessor(GetIsolate())
.Set(context->Global(), document_wrapper));
@@ -323,8 +349,8 @@ void LocalWindowProxy::SetSecurityToken(SecurityOrigin* origin) {
String frame_security_token = frame_security_origin->ToString();
// We need to check the return value of domainWasSetInDOM() on the
// frame's SecurityOrigin because, if that's the case, only
- // SecurityOrigin::m_domain would have been modified.
- // m_domain is not used by SecurityOrigin::toString(), so we would end
+ // SecurityOrigin::domain_ would have been modified.
+ // domain_ is not used by SecurityOrigin::toString(), so we would end
// up generating the same token that was already set.
if (frame_security_origin->DomainWasSetInDOM() ||
frame_security_token.IsEmpty() || frame_security_token == "null") {

Powered by Google App Engine
This is Rietveld 408576698