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

Side by Side Diff: extensions/renderer/v8_schema_registry.cc

Issue 2275813002: Revert of Signal extension API schema corruption to the browser process. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 4 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
« no previous file with comments | « extensions/common/extension_messages.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "extensions/renderer/v8_schema_registry.h" 5 #include "extensions/renderer/v8_schema_registry.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <utility> 9 #include <utility>
10 10
11 #include "base/logging.h" 11 #include "base/logging.h"
12 #include "base/values.h" 12 #include "base/values.h"
13 #include "content/public/child/v8_value_converter.h" 13 #include "content/public/child/v8_value_converter.h"
14 #include "content/public/renderer/render_thread.h"
15 #include "extensions/common/extension_api.h" 14 #include "extensions/common/extension_api.h"
16 #include "extensions/common/extension_messages.h"
17 #include "extensions/renderer/object_backed_native_handler.h" 15 #include "extensions/renderer/object_backed_native_handler.h"
18 #include "extensions/renderer/script_context.h" 16 #include "extensions/renderer/script_context.h"
19 #include "extensions/renderer/v8_helpers.h" 17 #include "extensions/renderer/v8_helpers.h"
20 18
21 using content::V8ValueConverter; 19 using content::V8ValueConverter;
22 20
23 namespace extensions { 21 namespace extensions {
24 22
25 namespace { 23 namespace {
26 24
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
126 124
127 // Slow path: Need to build schema first. 125 // Slow path: Need to build schema first.
128 126
129 v8::Isolate* isolate = v8::Isolate::GetCurrent(); 127 v8::Isolate* isolate = v8::Isolate::GetCurrent();
130 v8::EscapableHandleScope handle_scope(isolate); 128 v8::EscapableHandleScope handle_scope(isolate);
131 v8::Local<v8::Context> context = GetOrCreateContext(isolate); 129 v8::Local<v8::Context> context = GetOrCreateContext(isolate);
132 v8::Context::Scope context_scope(context); 130 v8::Context::Scope context_scope(context);
133 131
134 const base::DictionaryValue* schema = 132 const base::DictionaryValue* schema =
135 ExtensionAPI::GetSharedInstance()->GetSchema(api); 133 ExtensionAPI::GetSharedInstance()->GetSchema(api);
136 134 CHECK(schema) << api;
137 // If the schema for |api| cannot be loaded then return an empty object, but
138 // also notify the browser so that it can take appropriate action.
139 // See http://crbug.com/121424.
140 if (!schema) {
141 content::RenderThread::Get()->Send(
142 new ExtensionHostMsg_NotifyBadExtensionApiSchema(api));
143 return v8::Local<v8::Object>();
144 }
145
146 std::unique_ptr<V8ValueConverter> v8_value_converter( 135 std::unique_ptr<V8ValueConverter> v8_value_converter(
147 V8ValueConverter::create()); 136 V8ValueConverter::create());
148 v8::Local<v8::Value> value = v8_value_converter->ToV8Value(schema, context); 137 v8::Local<v8::Value> value = v8_value_converter->ToV8Value(schema, context);
149 CHECK(!value.IsEmpty()); 138 CHECK(!value.IsEmpty());
150 139
151 v8::Local<v8::Object> v8_schema(v8::Local<v8::Object>::Cast(value)); 140 v8::Local<v8::Object> v8_schema(v8::Local<v8::Object>::Cast(value));
152 DeepFreeze(v8_schema, context); 141 DeepFreeze(v8_schema, context);
153 schema_cache_->Set(api, v8_schema); 142 schema_cache_->Set(api, v8_schema);
154 143
155 return handle_scope.Escape(v8_schema); 144 return handle_scope.Escape(v8_schema);
156 } 145 }
157 146
158 v8::Local<v8::Context> V8SchemaRegistry::GetOrCreateContext( 147 v8::Local<v8::Context> V8SchemaRegistry::GetOrCreateContext(
159 v8::Isolate* isolate) { 148 v8::Isolate* isolate) {
160 // It's ok to create local handles in this function, since this is only called 149 // It's ok to create local handles in this function, since this is only called
161 // when we have a HandleScope. 150 // when we have a HandleScope.
162 if (!context_holder_) { 151 if (!context_holder_) {
163 context_holder_.reset(new gin::ContextHolder(isolate)); 152 context_holder_.reset(new gin::ContextHolder(isolate));
164 context_holder_->SetContext(v8::Context::New(isolate)); 153 context_holder_->SetContext(v8::Context::New(isolate));
165 schema_cache_.reset(new SchemaCache(isolate)); 154 schema_cache_.reset(new SchemaCache(isolate));
166 return context_holder_->context(); 155 return context_holder_->context();
167 } 156 }
168 return context_holder_->context(); 157 return context_holder_->context();
169 } 158 }
170 159
171 } // namespace extensions 160 } // namespace extensions
OLDNEW
« no previous file with comments | « extensions/common/extension_messages.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698