OLD | NEW |
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/script_context.h" | 5 #include "extensions/renderer/script_context.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
9 #include "base/strings/string_split.h" | 9 #include "base/strings/string_split.h" |
10 #include "base/strings/string_util.h" | 10 #include "base/strings/string_util.h" |
11 #include "base/values.h" | 11 #include "base/values.h" |
12 #include "content/public/common/url_constants.h" | 12 #include "content/public/common/url_constants.h" |
13 #include "content/public/renderer/render_frame.h" | 13 #include "content/public/renderer/render_frame.h" |
14 #include "content/public/renderer/render_view.h" | 14 #include "content/public/renderer/render_view.h" |
15 #include "content/public/renderer/v8_value_converter.h" | 15 #include "content/public/renderer/v8_value_converter.h" |
16 #include "extensions/common/extension.h" | 16 #include "extensions/common/extension.h" |
17 #include "extensions/common/extension_api.h" | 17 #include "extensions/common/extension_api.h" |
18 #include "extensions/common/extension_urls.h" | 18 #include "extensions/common/extension_urls.h" |
19 #include "extensions/common/features/base_feature_provider.h" | 19 #include "extensions/common/features/base_feature_provider.h" |
| 20 #include "extensions/common/permissions/permissions_data.h" |
20 #include "gin/per_context_data.h" | 21 #include "gin/per_context_data.h" |
21 #include "third_party/WebKit/public/web/WebDataSource.h" | 22 #include "third_party/WebKit/public/web/WebDataSource.h" |
22 #include "third_party/WebKit/public/web/WebDocument.h" | 23 #include "third_party/WebKit/public/web/WebDocument.h" |
23 #include "third_party/WebKit/public/web/WebFrame.h" | 24 #include "third_party/WebKit/public/web/WebFrame.h" |
24 #include "third_party/WebKit/public/web/WebScopedMicrotaskSuppression.h" | 25 #include "third_party/WebKit/public/web/WebScopedMicrotaskSuppression.h" |
25 #include "third_party/WebKit/public/web/WebSecurityOrigin.h" | 26 #include "third_party/WebKit/public/web/WebSecurityOrigin.h" |
26 #include "third_party/WebKit/public/web/WebView.h" | 27 #include "third_party/WebKit/public/web/WebView.h" |
27 #include "v8/include/v8.h" | 28 #include "v8/include/v8.h" |
28 | 29 |
29 using content::V8ValueConverter; | 30 using content::V8ValueConverter; |
(...skipping 236 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
266 int argc, | 267 int argc, |
267 v8::Handle<v8::Value> argv[]) { | 268 v8::Handle<v8::Value> argv[]) { |
268 return CallFunction(function, argc, argv); | 269 return CallFunction(function, argc, argv); |
269 } | 270 } |
270 | 271 |
271 gin::ContextHolder* ScriptContext::GetContextHolder() { | 272 gin::ContextHolder* ScriptContext::GetContextHolder() { |
272 v8::HandleScope handle_scope(isolate()); | 273 v8::HandleScope handle_scope(isolate()); |
273 return gin::PerContextData::From(v8_context())->context_holder(); | 274 return gin::PerContextData::From(v8_context())->context_holder(); |
274 } | 275 } |
275 | 276 |
| 277 void ScriptContext::SetContentCapabilities( |
| 278 const APIPermissionSet& permissions) { |
| 279 content_capabilities_ = permissions; |
| 280 } |
| 281 |
| 282 bool ScriptContext::HasAPIPermission(APIPermission::ID permission) const { |
| 283 if (effective_extension_.get()) { |
| 284 return effective_extension_->permissions_data()->HasAPIPermission( |
| 285 permission); |
| 286 } else if (context_type() == Feature::WEB_PAGE_CONTEXT) { |
| 287 // Only web page contexts may be granted content capabilities. Other |
| 288 // contexts are either privileged WebUI or extensions with their own set of |
| 289 // permissions. |
| 290 if (content_capabilities_.find(permission) != content_capabilities_.end()) |
| 291 return true; |
| 292 } |
| 293 return false; |
| 294 } |
| 295 |
276 } // namespace extensions | 296 } // namespace extensions |
OLD | NEW |