| 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/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "base/macros.h" | 9 #include "base/macros.h" |
| 10 #include "base/strings/string_split.h" | 10 #include "base/strings/string_split.h" |
| (...skipping 15 matching lines...) Expand all Loading... |
| 26 #include "extensions/renderer/v8_helpers.h" | 26 #include "extensions/renderer/v8_helpers.h" |
| 27 #include "gin/per_context_data.h" | 27 #include "gin/per_context_data.h" |
| 28 #include "third_party/WebKit/public/platform/WebSecurityOrigin.h" | 28 #include "third_party/WebKit/public/platform/WebSecurityOrigin.h" |
| 29 #include "third_party/WebKit/public/platform/WebURLRequest.h" | 29 #include "third_party/WebKit/public/platform/WebURLRequest.h" |
| 30 #include "third_party/WebKit/public/web/WebDataSource.h" | 30 #include "third_party/WebKit/public/web/WebDataSource.h" |
| 31 #include "third_party/WebKit/public/web/WebDocument.h" | 31 #include "third_party/WebKit/public/web/WebDocument.h" |
| 32 #include "third_party/WebKit/public/web/WebLocalFrame.h" | 32 #include "third_party/WebKit/public/web/WebLocalFrame.h" |
| 33 #include "third_party/WebKit/public/web/WebView.h" | 33 #include "third_party/WebKit/public/web/WebView.h" |
| 34 #include "v8/include/v8.h" | 34 #include "v8/include/v8.h" |
| 35 | 35 |
| 36 using content::V8ValueConverter; | |
| 37 | |
| 38 namespace extensions { | 36 namespace extensions { |
| 39 | 37 |
| 40 namespace { | 38 namespace { |
| 41 | 39 |
| 42 std::string GetContextTypeDescriptionString(Feature::Context context_type) { | 40 std::string GetContextTypeDescriptionString(Feature::Context context_type) { |
| 43 switch (context_type) { | 41 switch (context_type) { |
| 44 case Feature::UNSPECIFIED_CONTEXT: | 42 case Feature::UNSPECIFIED_CONTEXT: |
| 45 return "UNSPECIFIED"; | 43 return "UNSPECIFIED"; |
| 46 case Feature::BLESSED_EXTENSION_CONTEXT: | 44 case Feature::BLESSED_EXTENSION_CONTEXT: |
| 47 return "BLESSED_EXTENSION"; | 45 return "BLESSED_EXTENSION"; |
| (...skipping 317 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 365 } | 363 } |
| 366 | 364 |
| 367 void ScriptContext::OnResponseReceived(const std::string& name, | 365 void ScriptContext::OnResponseReceived(const std::string& name, |
| 368 int request_id, | 366 int request_id, |
| 369 bool success, | 367 bool success, |
| 370 const base::ListValue& response, | 368 const base::ListValue& response, |
| 371 const std::string& error) { | 369 const std::string& error) { |
| 372 DCHECK(thread_checker_.CalledOnValidThread()); | 370 DCHECK(thread_checker_.CalledOnValidThread()); |
| 373 v8::HandleScope handle_scope(isolate()); | 371 v8::HandleScope handle_scope(isolate()); |
| 374 | 372 |
| 375 std::unique_ptr<V8ValueConverter> converter(V8ValueConverter::create()); | |
| 376 v8::Local<v8::Value> argv[] = { | 373 v8::Local<v8::Value> argv[] = { |
| 377 v8::Integer::New(isolate(), request_id), | 374 v8::Integer::New(isolate(), request_id), |
| 378 v8::String::NewFromUtf8(isolate(), name.c_str()), | 375 v8::String::NewFromUtf8(isolate(), name.c_str()), |
| 379 v8::Boolean::New(isolate(), success), | 376 v8::Boolean::New(isolate(), success), |
| 380 converter->ToV8Value(&response, | 377 content::V8ValueConverter::Create()->ToV8Value( |
| 381 v8::Local<v8::Context>::New(isolate(), v8_context_)), | 378 &response, v8::Local<v8::Context>::New(isolate(), v8_context_)), |
| 382 v8::String::NewFromUtf8(isolate(), error.c_str())}; | 379 v8::String::NewFromUtf8(isolate(), error.c_str())}; |
| 383 | 380 |
| 384 module_system()->CallModuleMethodSafe("sendRequest", "handleResponse", | 381 module_system()->CallModuleMethodSafe("sendRequest", "handleResponse", |
| 385 arraysize(argv), argv); | 382 arraysize(argv), argv); |
| 386 } | 383 } |
| 387 | 384 |
| 388 bool ScriptContext::HasAPIPermission(APIPermission::ID permission) const { | 385 bool ScriptContext::HasAPIPermission(APIPermission::ID permission) const { |
| 389 DCHECK(thread_checker_.CalledOnValidThread()); | 386 DCHECK(thread_checker_.CalledOnValidThread()); |
| 390 if (effective_extension_.get()) { | 387 if (effective_extension_.get()) { |
| 391 return effective_extension_->permissions_data()->HasAPIPermission( | 388 return effective_extension_->permissions_data()->HasAPIPermission( |
| (...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 524 v8::Local<v8::Value> argv[]) { | 521 v8::Local<v8::Value> argv[]) { |
| 525 return context_->CallFunction(function, argc, argv); | 522 return context_->CallFunction(function, argc, argv); |
| 526 } | 523 } |
| 527 | 524 |
| 528 gin::ContextHolder* ScriptContext::Runner::GetContextHolder() { | 525 gin::ContextHolder* ScriptContext::Runner::GetContextHolder() { |
| 529 v8::HandleScope handle_scope(context_->isolate()); | 526 v8::HandleScope handle_scope(context_->isolate()); |
| 530 return gin::PerContextData::From(context_->v8_context())->context_holder(); | 527 return gin::PerContextData::From(context_->v8_context())->context_holder(); |
| 531 } | 528 } |
| 532 | 529 |
| 533 } // namespace extensions | 530 } // namespace extensions |
| OLD | NEW |