| 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/child/v8_value_converter.h" | 12 #include "content/public/child/v8_value_converter.h" |
| 13 #include "content/public/common/url_constants.h" | 13 #include "content/public/common/url_constants.h" |
| 14 #include "content/public/renderer/render_frame.h" | 14 #include "content/public/renderer/render_frame.h" |
| 15 #include "content/public/renderer/render_view.h" | 15 #include "content/public/renderer/render_view.h" |
| 16 #include "extensions/common/constants.h" |
| 16 #include "extensions/common/extension.h" | 17 #include "extensions/common/extension.h" |
| 17 #include "extensions/common/extension_api.h" | 18 #include "extensions/common/extension_api.h" |
| 19 #include "extensions/common/extension_set.h" |
| 18 #include "extensions/common/extension_urls.h" | 20 #include "extensions/common/extension_urls.h" |
| 19 #include "extensions/common/features/base_feature_provider.h" | 21 #include "extensions/common/features/base_feature_provider.h" |
| 22 #include "extensions/common/manifest_handlers/sandboxed_page_info.h" |
| 20 #include "extensions/common/permissions/permissions_data.h" | 23 #include "extensions/common/permissions/permissions_data.h" |
| 21 #include "gin/per_context_data.h" | 24 #include "gin/per_context_data.h" |
| 22 #include "third_party/WebKit/public/web/WebDataSource.h" | 25 #include "third_party/WebKit/public/web/WebDataSource.h" |
| 23 #include "third_party/WebKit/public/web/WebDocument.h" | 26 #include "third_party/WebKit/public/web/WebDocument.h" |
| 24 #include "third_party/WebKit/public/web/WebFrame.h" | 27 #include "third_party/WebKit/public/web/WebFrame.h" |
| 28 #include "third_party/WebKit/public/web/WebLocalFrame.h" |
| 25 #include "third_party/WebKit/public/web/WebScopedMicrotaskSuppression.h" | 29 #include "third_party/WebKit/public/web/WebScopedMicrotaskSuppression.h" |
| 26 #include "third_party/WebKit/public/web/WebSecurityOrigin.h" | 30 #include "third_party/WebKit/public/web/WebSecurityOrigin.h" |
| 27 #include "third_party/WebKit/public/web/WebView.h" | 31 #include "third_party/WebKit/public/web/WebView.h" |
| 28 #include "v8/include/v8.h" | 32 #include "v8/include/v8.h" |
| 29 | 33 |
| 30 using content::V8ValueConverter; | 34 using content::V8ValueConverter; |
| 31 | 35 |
| 32 namespace extensions { | 36 namespace extensions { |
| 33 | 37 |
| 34 namespace { | 38 namespace { |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 68 v8::Handle<v8::Value> receiver, | 72 v8::Handle<v8::Value> receiver, |
| 69 int argc, | 73 int argc, |
| 70 v8::Handle<v8::Value> argv[]) override; | 74 v8::Handle<v8::Value> argv[]) override; |
| 71 gin::ContextHolder* GetContextHolder() override; | 75 gin::ContextHolder* GetContextHolder() override; |
| 72 | 76 |
| 73 private: | 77 private: |
| 74 ScriptContext* context_; | 78 ScriptContext* context_; |
| 75 }; | 79 }; |
| 76 | 80 |
| 77 ScriptContext::ScriptContext(const v8::Handle<v8::Context>& v8_context, | 81 ScriptContext::ScriptContext(const v8::Handle<v8::Context>& v8_context, |
| 78 blink::WebFrame* web_frame, | 82 blink::WebLocalFrame* web_frame, |
| 79 const Extension* extension, | 83 const Extension* extension, |
| 80 Feature::Context context_type, | 84 Feature::Context context_type, |
| 81 const Extension* effective_extension, | 85 const Extension* effective_extension, |
| 82 Feature::Context effective_context_type) | 86 Feature::Context effective_context_type) |
| 83 : v8_context_(v8_context->GetIsolate(), v8_context), | 87 : v8_context_(v8_context->GetIsolate(), v8_context), |
| 84 web_frame_(web_frame), | 88 web_frame_(web_frame), |
| 85 extension_(extension), | 89 extension_(extension), |
| 86 context_type_(context_type), | 90 context_type_(context_type), |
| 87 effective_extension_(effective_extension), | 91 effective_extension_(effective_extension), |
| 88 effective_context_type_(effective_context_type), | 92 effective_context_type_(effective_context_type), |
| (...skipping 14 matching lines...) Expand all Loading... |
| 103 } | 107 } |
| 104 | 108 |
| 105 ScriptContext::~ScriptContext() { | 109 ScriptContext::~ScriptContext() { |
| 106 VLOG(1) << "Destroyed context for extension\n" | 110 VLOG(1) << "Destroyed context for extension\n" |
| 107 << " extension id: " << GetExtensionID() << "\n" | 111 << " extension id: " << GetExtensionID() << "\n" |
| 108 << " effective extension id: " | 112 << " effective extension id: " |
| 109 << (effective_extension_.get() ? effective_extension_->id() : ""); | 113 << (effective_extension_.get() ? effective_extension_->id() : ""); |
| 110 Invalidate(); | 114 Invalidate(); |
| 111 } | 115 } |
| 112 | 116 |
| 117 // static |
| 118 bool ScriptContext::IsSandboxedPage(const ExtensionSet& extensions, |
| 119 const GURL& url) { |
| 120 // TODO(kalman): This is checking for the wrong thing, it should be checking |
| 121 // if the frame's security origin is unique. The extension sandbox directive |
| 122 // is checked for in extensions/common/manifest_handlers/csp_info.cc. |
| 123 if (url.SchemeIs(kExtensionScheme)) { |
| 124 const Extension* extension = extensions.GetByID(url.host()); |
| 125 if (extension) { |
| 126 return SandboxedPageInfo::IsSandboxedPage(extension, url.path()); |
| 127 } |
| 128 } |
| 129 return false; |
| 130 } |
| 131 |
| 113 void ScriptContext::Invalidate() { | 132 void ScriptContext::Invalidate() { |
| 114 if (!is_valid()) | 133 if (!is_valid()) |
| 115 return; | 134 return; |
| 116 if (module_system_) | 135 if (module_system_) |
| 117 module_system_->Invalidate(); | 136 module_system_->Invalidate(); |
| 118 web_frame_ = NULL; | 137 web_frame_ = NULL; |
| 119 v8_context_.Reset(); | 138 v8_context_.Reset(); |
| 120 runner_.reset(); | 139 runner_.reset(); |
| 121 } | 140 } |
| 122 | 141 |
| (...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 311 v8::Handle<v8::Value> argv[]) { | 330 v8::Handle<v8::Value> argv[]) { |
| 312 return context_->CallFunction(function, argc, argv); | 331 return context_->CallFunction(function, argc, argv); |
| 313 } | 332 } |
| 314 | 333 |
| 315 gin::ContextHolder* ScriptContext::Runner::GetContextHolder() { | 334 gin::ContextHolder* ScriptContext::Runner::GetContextHolder() { |
| 316 v8::HandleScope handle_scope(context_->isolate()); | 335 v8::HandleScope handle_scope(context_->isolate()); |
| 317 return gin::PerContextData::From(context_->v8_context())->context_holder(); | 336 return gin::PerContextData::From(context_->v8_context())->context_holder(); |
| 318 } | 337 } |
| 319 | 338 |
| 320 } // namespace extensions | 339 } // namespace extensions |
| OLD | NEW |