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

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

Issue 404883002: Allow extension APIs to be called from WebUI. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 5 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 | Annotate | Revision Log
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/dispatcher.h" 5 #include "extensions/renderer/dispatcher.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/callback.h" 8 #include "base/callback.h"
9 #include "base/command_line.h" 9 #include "base/command_line.h"
10 #include "base/debug/alias.h" 10 #include "base/debug/alias.h"
(...skipping 347 matching lines...) Expand 10 before | Expand all | Expand 10 after
358 } 358 }
359 359
360 bool Dispatcher::CheckContextAccessToExtensionAPI( 360 bool Dispatcher::CheckContextAccessToExtensionAPI(
361 const std::string& function_name, 361 const std::string& function_name,
362 ScriptContext* context) const { 362 ScriptContext* context) const {
363 if (!context) { 363 if (!context) {
364 DLOG(ERROR) << "Not in a v8::Context"; 364 DLOG(ERROR) << "Not in a v8::Context";
365 return false; 365 return false;
366 } 366 }
367 367
368 if (!context->extension()) {
369 context->isolate()->ThrowException(v8::Exception::Error(
370 v8::String::NewFromUtf8(context->isolate(), "Not in an extension.")));
371 return false;
372 }
373
374 // Theoretically we could end up with bindings being injected into sandboxed 368 // Theoretically we could end up with bindings being injected into sandboxed
375 // frames, for example content scripts. Don't let them execute API functions. 369 // frames, for example content scripts. Don't let them execute API functions.
376 blink::WebFrame* frame = context->web_frame(); 370 blink::WebFrame* frame = context->web_frame();
377 if (IsSandboxedPage(ScriptContext::GetDataSourceURLForFrame(frame))) { 371 if (IsSandboxedPage(ScriptContext::GetDataSourceURLForFrame(frame))) {
378 static const char kMessage[] = 372 static const char kMessage[] =
379 "%s cannot be used within a sandboxed frame."; 373 "%s cannot be used within a sandboxed frame.";
380 std::string error_msg = base::StringPrintf(kMessage, function_name.c_str()); 374 std::string error_msg = base::StringPrintf(kMessage, function_name.c_str());
381 context->isolate()->ThrowException(v8::Exception::Error( 375 context->isolate()->ThrowException(v8::Exception::Error(
382 v8::String::NewFromUtf8(context->isolate(), error_msg.c_str()))); 376 v8::String::NewFromUtf8(context->isolate(), error_msg.c_str())));
383 return false; 377 return false;
(...skipping 456 matching lines...) Expand 10 before | Expand all | Expand 10 after
840 break; 834 break;
841 } 835 }
842 } 836 }
843 if (runtime_is_available) 837 if (runtime_is_available)
844 RegisterBinding("runtime", context); 838 RegisterBinding("runtime", context);
845 break; 839 break;
846 } 840 }
847 841
848 case Feature::BLESSED_EXTENSION_CONTEXT: 842 case Feature::BLESSED_EXTENSION_CONTEXT:
849 case Feature::UNBLESSED_EXTENSION_CONTEXT: 843 case Feature::UNBLESSED_EXTENSION_CONTEXT:
850 case Feature::CONTENT_SCRIPT_CONTEXT: { 844 case Feature::CONTENT_SCRIPT_CONTEXT:
845 case Feature::WEBUI_CONTEXT: {
851 // Extension context; iterate through all the APIs and bind the available 846 // Extension context; iterate through all the APIs and bind the available
852 // ones. 847 // ones.
853 const FeatureProvider* api_feature_provider = 848 const FeatureProvider* api_feature_provider =
854 FeatureProvider::GetAPIFeatures(); 849 FeatureProvider::GetAPIFeatures();
855 const std::vector<std::string>& apis = 850 const std::vector<std::string>& apis =
856 api_feature_provider->GetAllFeatureNames(); 851 api_feature_provider->GetAllFeatureNames();
857 for (std::vector<std::string>::const_iterator it = apis.begin(); 852 for (std::vector<std::string>::const_iterator it = apis.begin();
858 it != apis.end(); 853 it != apis.end();
859 ++it) { 854 ++it) {
860 const std::string& api_name = *it; 855 const std::string& api_name = *it;
(...skipping 257 matching lines...) Expand 10 before | Expand all | Expand 10 after
1118 1113
1119 // TODO(kalman): This isUnique() check is wrong, it should be performed as 1114 // TODO(kalman): This isUnique() check is wrong, it should be performed as
1120 // part of IsSandboxedPage(). 1115 // part of IsSandboxedPage().
1121 if (!origin.isUnique() && extensions_.ExtensionBindingsAllowed(url)) { 1116 if (!origin.isUnique() && extensions_.ExtensionBindingsAllowed(url)) {
1122 if (!extension) // TODO(kalman): when does this happen? 1117 if (!extension) // TODO(kalman): when does this happen?
1123 return Feature::UNSPECIFIED_CONTEXT; 1118 return Feature::UNSPECIFIED_CONTEXT;
1124 return extension->is_hosted_app() ? Feature::BLESSED_WEB_PAGE_CONTEXT 1119 return extension->is_hosted_app() ? Feature::BLESSED_WEB_PAGE_CONTEXT
1125 : Feature::UNBLESSED_EXTENSION_CONTEXT; 1120 : Feature::UNBLESSED_EXTENSION_CONTEXT;
1126 } 1121 }
1127 1122
1128 if (url.is_valid()) 1123 if (!url.is_valid())
1129 return Feature::WEB_PAGE_CONTEXT; 1124 return Feature::UNSPECIFIED_CONTEXT;
1130 1125
1131 return Feature::UNSPECIFIED_CONTEXT; 1126 if (url.SchemeIs(content::kChromeUIScheme))
1127 return Feature::WEBUI_CONTEXT;
1128
1129 return Feature::WEB_PAGE_CONTEXT;
1132 } 1130 }
1133 1131
1134 v8::Handle<v8::Object> Dispatcher::GetOrCreateObject( 1132 v8::Handle<v8::Object> Dispatcher::GetOrCreateObject(
1135 const v8::Handle<v8::Object>& object, 1133 const v8::Handle<v8::Object>& object,
1136 const std::string& field, 1134 const std::string& field,
1137 v8::Isolate* isolate) { 1135 v8::Isolate* isolate) {
1138 v8::Handle<v8::String> key = v8::String::NewFromUtf8(isolate, field.c_str()); 1136 v8::Handle<v8::String> key = v8::String::NewFromUtf8(isolate, field.c_str());
1139 // If the object has a callback property, it is assumed it is an unavailable 1137 // If the object has a callback property, it is assumed it is an unavailable
1140 // API, so it is safe to delete. This is checked before GetOrCreateObject is 1138 // API, so it is safe to delete. This is checked before GetOrCreateObject is
1141 // called. 1139 // called.
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
1197 return v8::Handle<v8::Object>(); 1195 return v8::Handle<v8::Object>();
1198 1196
1199 if (bind_name) 1197 if (bind_name)
1200 *bind_name = split.back(); 1198 *bind_name = split.back();
1201 1199
1202 return bind_object.IsEmpty() ? AsObjectOrEmpty(GetOrCreateChrome(context)) 1200 return bind_object.IsEmpty() ? AsObjectOrEmpty(GetOrCreateChrome(context))
1203 : bind_object; 1201 : bind_object;
1204 } 1202 }
1205 1203
1206 } // namespace extensions 1204 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698