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

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

Issue 2254383002: Signal extension API schema corruption to the browser process. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address comments 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
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"
14 #include "extensions/common/extension_api.h" 15 #include "extensions/common/extension_api.h"
16 #include "extensions/common/extension_messages.h"
15 #include "extensions/renderer/object_backed_native_handler.h" 17 #include "extensions/renderer/object_backed_native_handler.h"
16 #include "extensions/renderer/script_context.h" 18 #include "extensions/renderer/script_context.h"
17 #include "extensions/renderer/v8_helpers.h" 19 #include "extensions/renderer/v8_helpers.h"
18 20
19 using content::V8ValueConverter; 21 using content::V8ValueConverter;
20 22
21 namespace extensions { 23 namespace extensions {
22 24
23 namespace { 25 namespace {
24 26
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
124 126
125 // Slow path: Need to build schema first. 127 // Slow path: Need to build schema first.
126 128
127 v8::Isolate* isolate = v8::Isolate::GetCurrent(); 129 v8::Isolate* isolate = v8::Isolate::GetCurrent();
128 v8::EscapableHandleScope handle_scope(isolate); 130 v8::EscapableHandleScope handle_scope(isolate);
129 v8::Local<v8::Context> context = GetOrCreateContext(isolate); 131 v8::Local<v8::Context> context = GetOrCreateContext(isolate);
130 v8::Context::Scope context_scope(context); 132 v8::Context::Scope context_scope(context);
131 133
132 const base::DictionaryValue* schema = 134 const base::DictionaryValue* schema =
133 ExtensionAPI::GetSharedInstance()->GetSchema(api); 135 ExtensionAPI::GetSharedInstance()->GetSchema(api);
134 CHECK(schema) << api; 136
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
135 std::unique_ptr<V8ValueConverter> v8_value_converter( 146 std::unique_ptr<V8ValueConverter> v8_value_converter(
136 V8ValueConverter::create()); 147 V8ValueConverter::create());
137 v8::Local<v8::Value> value = v8_value_converter->ToV8Value(schema, context); 148 v8::Local<v8::Value> value = v8_value_converter->ToV8Value(schema, context);
138 CHECK(!value.IsEmpty()); 149 CHECK(!value.IsEmpty());
139 150
140 v8::Local<v8::Object> v8_schema(v8::Local<v8::Object>::Cast(value)); 151 v8::Local<v8::Object> v8_schema(v8::Local<v8::Object>::Cast(value));
141 DeepFreeze(v8_schema, context); 152 DeepFreeze(v8_schema, context);
142 schema_cache_->Set(api, v8_schema); 153 schema_cache_->Set(api, v8_schema);
143 154
144 return handle_scope.Escape(v8_schema); 155 return handle_scope.Escape(v8_schema);
145 } 156 }
146 157
147 v8::Local<v8::Context> V8SchemaRegistry::GetOrCreateContext( 158 v8::Local<v8::Context> V8SchemaRegistry::GetOrCreateContext(
148 v8::Isolate* isolate) { 159 v8::Isolate* isolate) {
149 // It's ok to create local handles in this function, since this is only called 160 // It's ok to create local handles in this function, since this is only called
150 // when we have a HandleScope. 161 // when we have a HandleScope.
151 if (!context_holder_) { 162 if (!context_holder_) {
152 context_holder_.reset(new gin::ContextHolder(isolate)); 163 context_holder_.reset(new gin::ContextHolder(isolate));
153 context_holder_->SetContext(v8::Context::New(isolate)); 164 context_holder_->SetContext(v8::Context::New(isolate));
154 schema_cache_.reset(new SchemaCache(isolate)); 165 schema_cache_.reset(new SchemaCache(isolate));
155 return context_holder_->context(); 166 return context_holder_->context();
156 } 167 }
157 return context_holder_->context(); 168 return context_holder_->context();
158 } 169 }
159 170
160 } // namespace extensions 171 } // namespace extensions
OLDNEW
« extensions/browser/extension_message_filter.cc ('K') | « extensions/common/extension_messages.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698