Chromium Code Reviews| 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" | |
| 11 #include "base/json/json_writer.h" | |
| 10 #include "base/memory/scoped_ptr.h" | 12 #include "base/memory/scoped_ptr.h" |
| 11 #include "base/string_util.h" | 13 #include "base/string_util.h" |
| 12 #include "base/strings/string_piece.h" | 14 #include "base/strings/string_piece.h" |
| 13 #include "base/strings/string_split.h" | 15 #include "base/strings/string_split.h" |
| 14 #include "chrome/common/child_process_logging.h" | 16 #include "chrome/common/child_process_logging.h" |
| 15 #include "chrome/common/chrome_switches.h" | 17 #include "chrome/common/chrome_switches.h" |
| 16 #include "chrome/common/chrome_version_info.h" | 18 #include "chrome/common/chrome_version_info.h" |
| 17 #include "chrome/common/extensions/api/extension_api.h" | 19 #include "chrome/common/extensions/api/extension_api.h" |
| 18 #include "chrome/common/extensions/background_info.h" | 20 #include "chrome/common/extensions/background_info.h" |
| 19 #include "chrome/common/extensions/extension.h" | 21 #include "chrome/common/extensions/extension.h" |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 58 #include "chrome/renderer/extensions/tab_finder.h" | 60 #include "chrome/renderer/extensions/tab_finder.h" |
| 59 #include "chrome/renderer/extensions/tabs_custom_bindings.h" | 61 #include "chrome/renderer/extensions/tabs_custom_bindings.h" |
| 60 #include "chrome/renderer/extensions/tts_custom_bindings.h" | 62 #include "chrome/renderer/extensions/tts_custom_bindings.h" |
| 61 #include "chrome/renderer/extensions/user_script_slave.h" | 63 #include "chrome/renderer/extensions/user_script_slave.h" |
| 62 #include "chrome/renderer/extensions/web_request_custom_bindings.h" | 64 #include "chrome/renderer/extensions/web_request_custom_bindings.h" |
| 63 #include "chrome/renderer/extensions/webstore_bindings.h" | 65 #include "chrome/renderer/extensions/webstore_bindings.h" |
| 64 #include "chrome/renderer/resource_bundle_source_map.h" | 66 #include "chrome/renderer/resource_bundle_source_map.h" |
| 65 #include "content/public/renderer/render_thread.h" | 67 #include "content/public/renderer/render_thread.h" |
| 66 #include "content/public/renderer/render_view.h" | 68 #include "content/public/renderer/render_view.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 // Read the JSON and write it back out to remove comments. | |
| 131 base::Value* value = base::JSONReader::Read( | |
| 132 ResourceBundle::GetSharedInstance().GetRawDataResource( | |
| 133 IDR_EXTENSION_API_FEATURES).as_string()); | |
|
not at google - send to devlin
2013/05/03 04:58:14
do you need to write it back to a string again? yo
cduvall
2013/05/07 23:44:29
Done.
| |
| 134 std::string json_str; | |
| 135 base::JSONWriter::Write(value, &json_str); | |
| 136 return v8::String::New(json_str.c_str()); | |
| 137 } | |
| 138 }; | |
| 139 | |
| 116 class SchemaRegistryNativeHandler : public ObjectBackedNativeHandler { | 140 class SchemaRegistryNativeHandler : public ObjectBackedNativeHandler { |
| 117 public: | 141 public: |
| 118 SchemaRegistryNativeHandler(V8SchemaRegistry* registry, | 142 SchemaRegistryNativeHandler(V8SchemaRegistry* registry, |
| 119 v8::Handle<v8::Context> context) | 143 v8::Handle<v8::Context> context) |
| 120 : ObjectBackedNativeHandler(context), | 144 : ObjectBackedNativeHandler(context), |
| 121 registry_(registry) { | 145 registry_(registry) { |
| 122 RouteFunction("GetSchema", | 146 RouteFunction("GetSchema", |
| 123 base::Bind(&SchemaRegistryNativeHandler::GetSchema, | 147 base::Bind(&SchemaRegistryNativeHandler::GetSchema, |
| 124 base::Unretained(this))); | 148 base::Unretained(this))); |
| 125 } | 149 } |
| (...skipping 566 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 692 } | 716 } |
| 693 | 717 |
| 694 void Dispatcher::RegisterSchemaGeneratedBindings( | 718 void Dispatcher::RegisterSchemaGeneratedBindings( |
| 695 ModuleSystem* module_system, | 719 ModuleSystem* module_system, |
| 696 ChromeV8Context* context) { | 720 ChromeV8Context* context) { |
| 697 std::set<std::string> apis = | 721 std::set<std::string> apis = |
| 698 ExtensionAPI::GetSharedInstance()->GetAllAPINames(); | 722 ExtensionAPI::GetSharedInstance()->GetAllAPINames(); |
| 699 for (std::set<std::string>::iterator it = apis.begin(); | 723 for (std::set<std::string>::iterator it = apis.begin(); |
| 700 it != apis.end(); ++it) { | 724 it != apis.end(); ++it) { |
| 701 const std::string& api_name = *it; | 725 const std::string& api_name = *it; |
| 702 if (!context->GetAvailabilityForContext(api_name).is_available()) | 726 if (!context->IsAnyFeatureAvailableToContext(api_name)) |
| 703 continue; | 727 continue; |
| 704 | 728 |
| 705 Feature* feature = | 729 Feature* feature = |
| 706 BaseFeatureProvider::GetByName("api")->GetFeature(api_name); | 730 BaseFeatureProvider::GetByName("api")->GetFeature(api_name); |
| 707 if (feature && feature->IsInternal()) | 731 if (feature && feature->IsInternal()) |
| 708 continue; | 732 continue; |
| 709 | 733 |
| 710 std::vector<std::string> split; | 734 std::vector<std::string> split; |
| 711 base::SplitString(api_name, '.', &split); | 735 base::SplitString(api_name, '.', &split); |
| 712 | 736 |
| (...skipping 294 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1007 module_system->RegisterNativeHandler("lazy_background_page", | 1031 module_system->RegisterNativeHandler("lazy_background_page", |
| 1008 scoped_ptr<NativeHandler>( | 1032 scoped_ptr<NativeHandler>( |
| 1009 new LazyBackgroundPageNativeHandler(this, v8_context))); | 1033 new LazyBackgroundPageNativeHandler(this, v8_context))); |
| 1010 module_system->RegisterNativeHandler("logging", | 1034 module_system->RegisterNativeHandler("logging", |
| 1011 scoped_ptr<NativeHandler>(new LoggingNativeHandler(v8_context))); | 1035 scoped_ptr<NativeHandler>(new LoggingNativeHandler(v8_context))); |
| 1012 module_system->RegisterNativeHandler("schema_registry", | 1036 module_system->RegisterNativeHandler("schema_registry", |
| 1013 scoped_ptr<NativeHandler>( | 1037 scoped_ptr<NativeHandler>( |
| 1014 new SchemaRegistryNativeHandler(v8_schema_registry(), v8_context))); | 1038 new SchemaRegistryNativeHandler(v8_schema_registry(), v8_context))); |
| 1015 module_system->RegisterNativeHandler("v8_context", | 1039 module_system->RegisterNativeHandler("v8_context", |
| 1016 scoped_ptr<NativeHandler>(new V8ContextNativeHandler(context, this))); | 1040 scoped_ptr<NativeHandler>(new V8ContextNativeHandler(context, this))); |
| 1041 module_system->RegisterNativeHandler("test_features", | |
| 1042 scoped_ptr<NativeHandler>(new TestFeaturesNativeHandler(v8_context))); | |
| 1017 | 1043 |
| 1018 int manifest_version = extension ? extension->manifest_version() : 1; | 1044 int manifest_version = extension ? extension->manifest_version() : 1; |
| 1019 bool send_request_disabled = | 1045 bool send_request_disabled = |
| 1020 (extension && Manifest::IsUnpackedLocation(extension->location()) && | 1046 (extension && Manifest::IsUnpackedLocation(extension->location()) && |
| 1021 BackgroundInfo::HasLazyBackgroundPage(extension)); | 1047 BackgroundInfo::HasLazyBackgroundPage(extension)); |
| 1022 module_system->RegisterNativeHandler("process", | 1048 module_system->RegisterNativeHandler("process", |
| 1023 scoped_ptr<NativeHandler>(new ProcessInfoNativeHandler( | 1049 scoped_ptr<NativeHandler>(new ProcessInfoNativeHandler( |
| 1024 this, v8_context, context->GetExtensionID(), | 1050 this, v8_context, context->GetExtensionID(), |
| 1025 context->GetContextTypeDescription(), | 1051 context->GetContextTypeDescription(), |
| 1026 ChromeRenderProcessObserver::is_incognito_process(), | 1052 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()); | 1452 std::string error_msg = base::StringPrintf(kMessage, function_name.c_str()); |
| 1427 v8::ThrowException( | 1453 v8::ThrowException( |
| 1428 v8::Exception::Error(v8::String::New(error_msg.c_str()))); | 1454 v8::Exception::Error(v8::String::New(error_msg.c_str()))); |
| 1429 return false; | 1455 return false; |
| 1430 } | 1456 } |
| 1431 | 1457 |
| 1432 return true; | 1458 return true; |
| 1433 } | 1459 } |
| 1434 | 1460 |
| 1435 } // namespace extensions | 1461 } // namespace extensions |
| OLD | NEW |