| 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), |
| 89 safe_builtins_(this), | 93 safe_builtins_(this), |
| 90 isolate_(v8_context->GetIsolate()), | 94 isolate_(v8_context->GetIsolate()), |
| 91 url_(web_frame_ ? GetDataSourceURLForFrame(web_frame_) : GURL()), | 95 url_(web_frame_ ? GetDataSourceURLForFrame(web_frame_) : GURL()), |
| 92 runner_(new Runner(this)) { | 96 runner_(new Runner(this)) { |
| 93 VLOG(1) << "Created context:\n" | 97 VLOG(1) << "Created context:\n" |
| 94 << " extension id: " << GetExtensionID() << "\n" | 98 << " extension id: " << GetExtensionID() << "\n" |
| 95 << " frame: " << web_frame_ << "\n" | 99 << " frame: " << web_frame_ << "\n" |
| 96 << " URL: " << GetURL() << "\n" | 100 << " URL: " << GetURL() << "\n" |
| 97 << " context type: " << GetContextTypeDescription() << "\n" | 101 << " context type: " << GetContextTypeDescription() << "\n" |
| 98 << " effective extension id: " | 102 << " effective extension id: " |
| 99 << (effective_extension_.get() ? effective_extension_->id() : "") | 103 << (effective_extension_.get() ? effective_extension_->id() : "") |
| 100 << " effective context type: " | 104 << " effective context type: " |
| 101 << GetEffectiveContextTypeDescription(); | 105 << GetEffectiveContextTypeDescription(); |
| 102 gin::PerContextData::From(v8_context)->set_runner(runner_.get()); | 106 gin::PerContextData* gin_data = gin::PerContextData::From(v8_context); |
| 107 CHECK(gin_data); // may fail if the v8::Context hasn't been registered yet |
| 108 gin_data->set_runner(runner_.get()); |
| 103 } | 109 } |
| 104 | 110 |
| 105 ScriptContext::~ScriptContext() { | 111 ScriptContext::~ScriptContext() { |
| 106 VLOG(1) << "Destroyed context for extension\n" | 112 VLOG(1) << "Destroyed context for extension\n" |
| 107 << " extension id: " << GetExtensionID() << "\n" | 113 << " extension id: " << GetExtensionID() << "\n" |
| 108 << " effective extension id: " | 114 << " effective extension id: " |
| 109 << (effective_extension_.get() ? effective_extension_->id() : ""); | 115 << (effective_extension_.get() ? effective_extension_->id() : ""); |
| 110 Invalidate(); | 116 Invalidate(); |
| 111 } | 117 } |
| 112 | 118 |
| 119 // static |
| 120 bool ScriptContext::IsSandboxedPage(const ExtensionSet& extensions, |
| 121 const GURL& url) { |
| 122 // TODO(kalman): This is checking for the wrong thing, it should be checking |
| 123 // if the frame's security origin is unique. The extension sandbox directive |
| 124 // is checked for in extensions/common/manifest_handlers/csp_info.cc. |
| 125 if (url.SchemeIs(kExtensionScheme)) { |
| 126 const Extension* extension = extensions.GetByID(url.host()); |
| 127 if (extension) { |
| 128 return SandboxedPageInfo::IsSandboxedPage(extension, url.path()); |
| 129 } |
| 130 } |
| 131 return false; |
| 132 } |
| 133 |
| 113 void ScriptContext::Invalidate() { | 134 void ScriptContext::Invalidate() { |
| 114 if (!is_valid()) | 135 if (!is_valid()) |
| 115 return; | 136 return; |
| 116 if (module_system_) | 137 if (module_system_) |
| 117 module_system_->Invalidate(); | 138 module_system_->Invalidate(); |
| 118 web_frame_ = NULL; | 139 web_frame_ = NULL; |
| 119 v8_context_.Reset(); | 140 v8_context_.Reset(); |
| 120 runner_.reset(); | 141 runner_.reset(); |
| 121 } | 142 } |
| 122 | 143 |
| (...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 311 v8::Handle<v8::Value> argv[]) { | 332 v8::Handle<v8::Value> argv[]) { |
| 312 return context_->CallFunction(function, argc, argv); | 333 return context_->CallFunction(function, argc, argv); |
| 313 } | 334 } |
| 314 | 335 |
| 315 gin::ContextHolder* ScriptContext::Runner::GetContextHolder() { | 336 gin::ContextHolder* ScriptContext::Runner::GetContextHolder() { |
| 316 v8::HandleScope handle_scope(context_->isolate()); | 337 v8::HandleScope handle_scope(context_->isolate()); |
| 317 return gin::PerContextData::From(context_->v8_context())->context_holder(); | 338 return gin::PerContextData::From(context_->v8_context())->context_holder(); |
| 318 } | 339 } |
| 319 | 340 |
| 320 } // namespace extensions | 341 } // namespace extensions |
| OLD | NEW |