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

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

Issue 2412783002: Only inject mojo builtins to contexts with the mojoPrivate API feature. (Closed)
Patch Set: Created 4 years, 2 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 | « no previous file | 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/module_system.h" 5 #include "extensions/renderer/module_system.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/command_line.h" 8 #include "base/command_line.h"
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/macros.h" 10 #include "base/macros.h"
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
104 v8::Local<v8::Object> obj = args.This(); 104 v8::Local<v8::Object> obj = args.This();
105 CHECK_EQ(2, args.Length()); 105 CHECK_EQ(2, args.Length());
106 CHECK(args[0]->IsString()); 106 CHECK(args[0]->IsString());
107 v8::Maybe<bool> result = 107 v8::Maybe<bool> result =
108 obj->DefineOwnProperty(args.GetIsolate()->GetCurrentContext(), 108 obj->DefineOwnProperty(args.GetIsolate()->GetCurrentContext(),
109 args[0]->ToString(), args[1], v8::ReadOnly); 109 args[0]->ToString(), args[1], v8::ReadOnly);
110 if (!result.FromMaybe(false)) 110 if (!result.FromMaybe(false))
111 LOG(ERROR) << "Failed to set private property on the export."; 111 LOG(ERROR) << "Failed to set private property on the export.";
112 } 112 }
113 113
114 bool ContextNeedsMojoBindings(ScriptContext* context) {
115 // Mojo is only used from JS by some APIs so a context only needs the mojo
116 // bindings at least one is available.
Devlin 2016/10/13 14:44:14 nit: "if at least one is available"? (missing "if"
Sam McNally 2016/10/13 22:24:50 Done.
117 //
118 // Prefer to use Mojo from C++ if possible rather than adding to this list.
119 static const char* const kMojoUsingApis[] = {
Devlin 2016/10/13 14:44:14 nitty nit: since variable names can't express the
Sam McNally 2016/10/13 22:24:50 Done.
120 "mimeHandlerPrivate", "mojoPrivate",
121 };
122
123 for (const auto* api : kMojoUsingApis) {
124 if (context->GetAvailability(api).is_available())
125 return true;
126 }
127 return false;
128 }
129
114 } // namespace 130 } // namespace
115 131
116 std::string ModuleSystem::ExceptionHandler::CreateExceptionString( 132 std::string ModuleSystem::ExceptionHandler::CreateExceptionString(
117 const v8::TryCatch& try_catch) { 133 const v8::TryCatch& try_catch) {
118 v8::Local<v8::Message> message(try_catch.Message()); 134 v8::Local<v8::Message> message(try_catch.Message());
119 if (message.IsEmpty()) { 135 if (message.IsEmpty()) {
120 return "try_catch has no message"; 136 return "try_catch has no message";
121 } 137 }
122 138
123 std::string resource_name = "<unknown resource>"; 139 std::string resource_name = "<unknown resource>";
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
162 base::Bind(&ModuleSystem::RequireAsync, base::Unretained(this))); 178 base::Bind(&ModuleSystem::RequireAsync, base::Unretained(this)));
163 RouteFunction("privates", 179 RouteFunction("privates",
164 base::Bind(&ModuleSystem::Private, base::Unretained(this))); 180 base::Bind(&ModuleSystem::Private, base::Unretained(this)));
165 181
166 v8::Local<v8::Object> global(context->v8_context()->Global()); 182 v8::Local<v8::Object> global(context->v8_context()->Global());
167 v8::Isolate* isolate = context->isolate(); 183 v8::Isolate* isolate = context->isolate();
168 SetPrivate(global, kModulesField, v8::Object::New(isolate)); 184 SetPrivate(global, kModulesField, v8::Object::New(isolate));
169 SetPrivate(global, kModuleSystem, v8::External::New(isolate, this)); 185 SetPrivate(global, kModuleSystem, v8::External::New(isolate, this));
170 186
171 gin::ModuleRegistry::From(context->v8_context())->AddObserver(this); 187 gin::ModuleRegistry::From(context->v8_context())->AddObserver(this);
172 // TODO(devlin): We really shouldn't be injecting mojo into every blessed
173 // extension context - it's wasteful. But it's better than injecting into
174 // every frame (previous behavior) so start with this while we investigate
175 // further. See crbug.com/636655.
176 if (context_->GetRenderFrame() && 188 if (context_->GetRenderFrame() &&
177 context_->context_type() == Feature::BLESSED_EXTENSION_CONTEXT) { 189 context_->context_type() == Feature::BLESSED_EXTENSION_CONTEXT &&
190 ContextNeedsMojoBindings(context_)) {
178 context_->GetRenderFrame()->EnsureMojoBuiltinsAreAvailable( 191 context_->GetRenderFrame()->EnsureMojoBuiltinsAreAvailable(
179 context->isolate(), context->v8_context()); 192 context->isolate(), context->v8_context());
180 } 193 }
181 } 194 }
182 195
183 ModuleSystem::~ModuleSystem() { 196 ModuleSystem::~ModuleSystem() {
184 } 197 }
185 198
186 void ModuleSystem::Invalidate() { 199 void ModuleSystem::Invalidate() {
187 // Clear the module system properties from the global context. It's polite, 200 // Clear the module system properties from the global context. It's polite,
(...skipping 574 matching lines...) Expand 10 before | Expand all | Expand 10 after
762 775
763 void ModuleSystem::ClobberExistingNativeHandler(const std::string& name) { 776 void ModuleSystem::ClobberExistingNativeHandler(const std::string& name) {
764 NativeHandlerMap::iterator existing_handler = native_handler_map_.find(name); 777 NativeHandlerMap::iterator existing_handler = native_handler_map_.find(name);
765 if (existing_handler != native_handler_map_.end()) { 778 if (existing_handler != native_handler_map_.end()) {
766 clobbered_native_handlers_.push_back(std::move(existing_handler->second)); 779 clobbered_native_handlers_.push_back(std::move(existing_handler->second));
767 native_handler_map_.erase(existing_handler); 780 native_handler_map_.erase(existing_handler);
768 } 781 }
769 } 782 }
770 783
771 } // namespace extensions 784 } // namespace extensions
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698