| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "chrome/renderer/extensions/dispatcher.h" | 5 #include "chrome/renderer/extensions/dispatcher.h" |
| 6 | 6 |
| 7 #include "base/callback.h" | 7 #include "base/callback.h" |
| 8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
| 9 #include "base/debug/alias.h" | 9 #include "base/debug/alias.h" |
| 10 #include "base/json/json_reader.h" |
| 10 #include "base/memory/scoped_ptr.h" | 11 #include "base/memory/scoped_ptr.h" |
| 11 #include "base/string_util.h" | 12 #include "base/string_util.h" |
| 12 #include "base/strings/string_piece.h" | 13 #include "base/strings/string_piece.h" |
| 13 #include "base/strings/string_split.h" | 14 #include "base/strings/string_split.h" |
| 14 #include "chrome/common/child_process_logging.h" | 15 #include "chrome/common/child_process_logging.h" |
| 15 #include "chrome/common/chrome_switches.h" | 16 #include "chrome/common/chrome_switches.h" |
| 16 #include "chrome/common/chrome_version_info.h" | 17 #include "chrome/common/chrome_version_info.h" |
| 17 #include "chrome/common/extensions/api/extension_api.h" | 18 #include "chrome/common/extensions/api/extension_api.h" |
| 18 #include "chrome/common/extensions/background_info.h" | 19 #include "chrome/common/extensions/background_info.h" |
| 19 #include "chrome/common/extensions/extension.h" | 20 #include "chrome/common/extensions/extension.h" |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 57 #include "chrome/renderer/extensions/sync_file_system_custom_bindings.h" | 58 #include "chrome/renderer/extensions/sync_file_system_custom_bindings.h" |
| 58 #include "chrome/renderer/extensions/tab_finder.h" | 59 #include "chrome/renderer/extensions/tab_finder.h" |
| 59 #include "chrome/renderer/extensions/tabs_custom_bindings.h" | 60 #include "chrome/renderer/extensions/tabs_custom_bindings.h" |
| 60 #include "chrome/renderer/extensions/tts_custom_bindings.h" | 61 #include "chrome/renderer/extensions/tts_custom_bindings.h" |
| 61 #include "chrome/renderer/extensions/user_script_slave.h" | 62 #include "chrome/renderer/extensions/user_script_slave.h" |
| 62 #include "chrome/renderer/extensions/web_request_custom_bindings.h" | 63 #include "chrome/renderer/extensions/web_request_custom_bindings.h" |
| 63 #include "chrome/renderer/extensions/webstore_bindings.h" | 64 #include "chrome/renderer/extensions/webstore_bindings.h" |
| 64 #include "chrome/renderer/resource_bundle_source_map.h" | 65 #include "chrome/renderer/resource_bundle_source_map.h" |
| 65 #include "content/public/renderer/render_thread.h" | 66 #include "content/public/renderer/render_thread.h" |
| 66 #include "content/public/renderer/render_view.h" | 67 #include "content/public/renderer/render_view.h" |
| 68 #include "content/public/renderer/v8_value_converter.h" |
| 67 #include "extensions/common/view_type.h" | 69 #include "extensions/common/view_type.h" |
| 70 #include "grit/common_resources.h" |
| 68 #include "grit/renderer_resources.h" | 71 #include "grit/renderer_resources.h" |
| 69 #include "third_party/WebKit/Source/Platform/chromium/public/WebString.h" | 72 #include "third_party/WebKit/Source/Platform/chromium/public/WebString.h" |
| 70 #include "third_party/WebKit/Source/Platform/chromium/public/WebURLRequest.h" | 73 #include "third_party/WebKit/Source/Platform/chromium/public/WebURLRequest.h" |
| 71 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDataSource.h" | 74 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDataSource.h" |
| 72 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDocument.h" | 75 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDocument.h" |
| 73 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" | 76 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" |
| 74 #include "third_party/WebKit/Source/WebKit/chromium/public/WebScopedUserGesture.
h" | 77 #include "third_party/WebKit/Source/WebKit/chromium/public/WebScopedUserGesture.
h" |
| 75 #include "third_party/WebKit/Source/WebKit/chromium/public/WebSecurityPolicy.h" | 78 #include "third_party/WebKit/Source/WebKit/chromium/public/WebSecurityPolicy.h" |
| 76 #include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h" | 79 #include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h" |
| 77 #include "ui/base/layout.h" | 80 #include "ui/base/layout.h" |
| (...skipping 28 matching lines...) Expand all Loading... |
| 106 v8::Handle<v8::Value> chrome(global->Get(chrome_string)); | 109 v8::Handle<v8::Value> chrome(global->Get(chrome_string)); |
| 107 if (chrome.IsEmpty() || chrome->IsUndefined()) { | 110 if (chrome.IsEmpty() || chrome->IsUndefined()) { |
| 108 v8::Handle<v8::Object> chrome_object(v8::Object::New()); | 111 v8::Handle<v8::Object> chrome_object(v8::Object::New()); |
| 109 global->Set(chrome_string, chrome_object); | 112 global->Set(chrome_string, chrome_object); |
| 110 return chrome_object; | 113 return chrome_object; |
| 111 } | 114 } |
| 112 CHECK(chrome->IsObject()); | 115 CHECK(chrome->IsObject()); |
| 113 return chrome->ToObject(); | 116 return chrome->ToObject(); |
| 114 } | 117 } |
| 115 | 118 |
| 119 class TestFeaturesNativeHandler : public ObjectBackedNativeHandler { |
| 120 public: |
| 121 explicit TestFeaturesNativeHandler(v8::Handle<v8::Context> context) |
| 122 : ObjectBackedNativeHandler(context) { |
| 123 RouteFunction("GetAPIFeatures", |
| 124 base::Bind(&TestFeaturesNativeHandler::GetAPIFeatures, |
| 125 base::Unretained(this))); |
| 126 } |
| 127 |
| 128 private: |
| 129 v8::Handle<v8::Value> GetAPIFeatures(const v8::Arguments& args) { |
| 130 base::Value* value = base::JSONReader::Read( |
| 131 ResourceBundle::GetSharedInstance().GetRawDataResource( |
| 132 IDR_EXTENSION_API_FEATURES).as_string()); |
| 133 scoped_ptr<content::V8ValueConverter> converter( |
| 134 content::V8ValueConverter::create()); |
| 135 return converter->ToV8Value(value, v8_context()); |
| 136 } |
| 137 }; |
| 138 |
| 116 class SchemaRegistryNativeHandler : public ObjectBackedNativeHandler { | 139 class SchemaRegistryNativeHandler : public ObjectBackedNativeHandler { |
| 117 public: | 140 public: |
| 118 SchemaRegistryNativeHandler(V8SchemaRegistry* registry, | 141 SchemaRegistryNativeHandler(V8SchemaRegistry* registry, |
| 119 v8::Handle<v8::Context> context) | 142 v8::Handle<v8::Context> context) |
| 120 : ObjectBackedNativeHandler(context), | 143 : ObjectBackedNativeHandler(context), |
| 121 registry_(registry) { | 144 registry_(registry) { |
| 122 RouteFunction("GetSchema", | 145 RouteFunction("GetSchema", |
| 123 base::Bind(&SchemaRegistryNativeHandler::GetSchema, | 146 base::Bind(&SchemaRegistryNativeHandler::GetSchema, |
| 124 base::Unretained(this))); | 147 base::Unretained(this))); |
| 125 } | 148 } |
| (...skipping 566 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 692 } | 715 } |
| 693 | 716 |
| 694 void Dispatcher::RegisterSchemaGeneratedBindings( | 717 void Dispatcher::RegisterSchemaGeneratedBindings( |
| 695 ModuleSystem* module_system, | 718 ModuleSystem* module_system, |
| 696 ChromeV8Context* context) { | 719 ChromeV8Context* context) { |
| 697 std::set<std::string> apis = | 720 std::set<std::string> apis = |
| 698 ExtensionAPI::GetSharedInstance()->GetAllAPINames(); | 721 ExtensionAPI::GetSharedInstance()->GetAllAPINames(); |
| 699 for (std::set<std::string>::iterator it = apis.begin(); | 722 for (std::set<std::string>::iterator it = apis.begin(); |
| 700 it != apis.end(); ++it) { | 723 it != apis.end(); ++it) { |
| 701 const std::string& api_name = *it; | 724 const std::string& api_name = *it; |
| 702 if (!context->GetAvailabilityForContext(api_name).is_available()) | 725 if (!context->IsAnyFeatureAvailableToContext(api_name)) |
| 703 continue; | 726 continue; |
| 704 | 727 |
| 705 Feature* feature = | 728 Feature* feature = |
| 706 BaseFeatureProvider::GetByName("api")->GetFeature(api_name); | 729 BaseFeatureProvider::GetByName("api")->GetFeature(api_name); |
| 707 if (feature && feature->IsInternal()) | 730 if (feature && feature->IsInternal()) |
| 708 continue; | 731 continue; |
| 709 | 732 |
| 710 std::vector<std::string> split; | 733 std::vector<std::string> split; |
| 711 base::SplitString(api_name, '.', &split); | 734 base::SplitString(api_name, '.', &split); |
| 712 | 735 |
| (...skipping 294 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1007 module_system->RegisterNativeHandler("lazy_background_page", | 1030 module_system->RegisterNativeHandler("lazy_background_page", |
| 1008 scoped_ptr<NativeHandler>( | 1031 scoped_ptr<NativeHandler>( |
| 1009 new LazyBackgroundPageNativeHandler(this, v8_context))); | 1032 new LazyBackgroundPageNativeHandler(this, v8_context))); |
| 1010 module_system->RegisterNativeHandler("logging", | 1033 module_system->RegisterNativeHandler("logging", |
| 1011 scoped_ptr<NativeHandler>(new LoggingNativeHandler(v8_context))); | 1034 scoped_ptr<NativeHandler>(new LoggingNativeHandler(v8_context))); |
| 1012 module_system->RegisterNativeHandler("schema_registry", | 1035 module_system->RegisterNativeHandler("schema_registry", |
| 1013 scoped_ptr<NativeHandler>( | 1036 scoped_ptr<NativeHandler>( |
| 1014 new SchemaRegistryNativeHandler(v8_schema_registry(), v8_context))); | 1037 new SchemaRegistryNativeHandler(v8_schema_registry(), v8_context))); |
| 1015 module_system->RegisterNativeHandler("v8_context", | 1038 module_system->RegisterNativeHandler("v8_context", |
| 1016 scoped_ptr<NativeHandler>(new V8ContextNativeHandler(context, this))); | 1039 scoped_ptr<NativeHandler>(new V8ContextNativeHandler(context, this))); |
| 1040 module_system->RegisterNativeHandler("test_features", |
| 1041 scoped_ptr<NativeHandler>(new TestFeaturesNativeHandler(v8_context))); |
| 1017 | 1042 |
| 1018 int manifest_version = extension ? extension->manifest_version() : 1; | 1043 int manifest_version = extension ? extension->manifest_version() : 1; |
| 1019 bool send_request_disabled = | 1044 bool send_request_disabled = |
| 1020 (extension && Manifest::IsUnpackedLocation(extension->location()) && | 1045 (extension && Manifest::IsUnpackedLocation(extension->location()) && |
| 1021 BackgroundInfo::HasLazyBackgroundPage(extension)); | 1046 BackgroundInfo::HasLazyBackgroundPage(extension)); |
| 1022 module_system->RegisterNativeHandler("process", | 1047 module_system->RegisterNativeHandler("process", |
| 1023 scoped_ptr<NativeHandler>(new ProcessInfoNativeHandler( | 1048 scoped_ptr<NativeHandler>(new ProcessInfoNativeHandler( |
| 1024 this, v8_context, context->GetExtensionID(), | 1049 this, v8_context, context->GetExtensionID(), |
| 1025 context->GetContextTypeDescription(), | 1050 context->GetContextTypeDescription(), |
| 1026 ChromeRenderProcessObserver::is_incognito_process(), | 1051 ChromeRenderProcessObserver::is_incognito_process(), |
| (...skipping 399 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1426 std::string error_msg = base::StringPrintf(kMessage, function_name.c_str()); | 1451 std::string error_msg = base::StringPrintf(kMessage, function_name.c_str()); |
| 1427 v8::ThrowException( | 1452 v8::ThrowException( |
| 1428 v8::Exception::Error(v8::String::New(error_msg.c_str()))); | 1453 v8::Exception::Error(v8::String::New(error_msg.c_str()))); |
| 1429 return false; | 1454 return false; |
| 1430 } | 1455 } |
| 1431 | 1456 |
| 1432 return true; | 1457 return true; |
| 1433 } | 1458 } |
| 1434 | 1459 |
| 1435 } // namespace extensions | 1460 } // namespace extensions |
| OLD | NEW |