| 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/json/json_reader.h" |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 112 v8::Handle<v8::Object> chrome_object(v8::Object::New()); | 112 v8::Handle<v8::Object> chrome_object(v8::Object::New()); |
| 113 global->Set(chrome_string, chrome_object); | 113 global->Set(chrome_string, chrome_object); |
| 114 return chrome_object; | 114 return chrome_object; |
| 115 } | 115 } |
| 116 CHECK(chrome->IsObject()); | 116 CHECK(chrome->IsObject()); |
| 117 return chrome->ToObject(); | 117 return chrome->ToObject(); |
| 118 } | 118 } |
| 119 | 119 |
| 120 class TestFeaturesNativeHandler : public ObjectBackedNativeHandler { | 120 class TestFeaturesNativeHandler : public ObjectBackedNativeHandler { |
| 121 public: | 121 public: |
| 122 explicit TestFeaturesNativeHandler(v8::Handle<v8::Context> context) | 122 explicit TestFeaturesNativeHandler(ChromeV8Context* context) |
| 123 : ObjectBackedNativeHandler(context) { | 123 : ObjectBackedNativeHandler(context) { |
| 124 RouteFunction("GetAPIFeatures", | 124 RouteFunction("GetAPIFeatures", |
| 125 base::Bind(&TestFeaturesNativeHandler::GetAPIFeatures, | 125 base::Bind(&TestFeaturesNativeHandler::GetAPIFeatures, |
| 126 base::Unretained(this))); | 126 base::Unretained(this))); |
| 127 } | 127 } |
| 128 | 128 |
| 129 private: | 129 private: |
| 130 v8::Handle<v8::Value> GetAPIFeatures(const v8::Arguments& args) { | 130 v8::Handle<v8::Value> GetAPIFeatures(const v8::Arguments& args) { |
| 131 base::Value* value = base::JSONReader::Read( | 131 base::Value* value = base::JSONReader::Read( |
| 132 ResourceBundle::GetSharedInstance().GetRawDataResource( | 132 ResourceBundle::GetSharedInstance().GetRawDataResource( |
| 133 IDR_EXTENSION_API_FEATURES).as_string()); | 133 IDR_EXTENSION_API_FEATURES).as_string()); |
| 134 scoped_ptr<content::V8ValueConverter> converter( | 134 scoped_ptr<content::V8ValueConverter> converter( |
| 135 content::V8ValueConverter::create()); | 135 content::V8ValueConverter::create()); |
| 136 return converter->ToV8Value(value, v8_context()); | 136 return converter->ToV8Value(value, v8_context()); |
| 137 } | 137 } |
| 138 }; | 138 }; |
| 139 | 139 |
| 140 class SchemaRegistryNativeHandler : public ObjectBackedNativeHandler { | 140 class SchemaRegistryNativeHandler : public ObjectBackedNativeHandler { |
| 141 public: | 141 public: |
| 142 SchemaRegistryNativeHandler(V8SchemaRegistry* registry, | 142 SchemaRegistryNativeHandler(V8SchemaRegistry* registry, |
| 143 v8::Handle<v8::Context> context) | 143 ChromeV8Context* context) |
| 144 : ObjectBackedNativeHandler(context), | 144 : ObjectBackedNativeHandler(context), |
| 145 registry_(registry) { | 145 registry_(registry) { |
| 146 RouteFunction("GetSchema", | 146 RouteFunction("GetSchema", |
| 147 base::Bind(&SchemaRegistryNativeHandler::GetSchema, | 147 base::Bind(&SchemaRegistryNativeHandler::GetSchema, |
| 148 base::Unretained(this))); | 148 base::Unretained(this))); |
| 149 } | 149 } |
| 150 | 150 |
| 151 private: | 151 private: |
| 152 v8::Handle<v8::Value> GetSchema(const v8::Arguments& args) { | 152 v8::Handle<v8::Value> GetSchema(const v8::Arguments& args) { |
| 153 return registry_->GetSchema(*v8::String::AsciiValue(args[0])); | 153 return registry_->GetSchema(*v8::String::AsciiValue(args[0])); |
| 154 } | 154 } |
| 155 | 155 |
| 156 V8SchemaRegistry* registry_; | 156 V8SchemaRegistry* registry_; |
| 157 }; | 157 }; |
| 158 | 158 |
| 159 class V8ContextNativeHandler : public ObjectBackedNativeHandler { | 159 class V8ContextNativeHandler : public ObjectBackedNativeHandler { |
| 160 public: | 160 public: |
| 161 V8ContextNativeHandler(ChromeV8Context* context, Dispatcher* dispatcher) | 161 V8ContextNativeHandler(ChromeV8Context* context, Dispatcher* dispatcher) |
| 162 : ObjectBackedNativeHandler(context->v8_context()), | 162 : ObjectBackedNativeHandler(context), |
| 163 context_(context), | 163 context_(context), |
| 164 dispatcher_(dispatcher) { | 164 dispatcher_(dispatcher) { |
| 165 RouteFunction("GetAvailability", | 165 RouteFunction("GetAvailability", |
| 166 base::Bind(&V8ContextNativeHandler::GetAvailability, | 166 base::Bind(&V8ContextNativeHandler::GetAvailability, |
| 167 base::Unretained(this))); | 167 base::Unretained(this))); |
| 168 RouteFunction("GetModuleSystem", | 168 RouteFunction("GetModuleSystem", |
| 169 base::Bind(&V8ContextNativeHandler::GetModuleSystem, | 169 base::Bind(&V8ContextNativeHandler::GetModuleSystem, |
| 170 base::Unretained(this))); | 170 base::Unretained(this))); |
| 171 } | 171 } |
| 172 | 172 |
| (...skipping 20 matching lines...) Expand all Loading... |
| 193 v8_context); | 193 v8_context); |
| 194 return context->module_system()->NewInstance(); | 194 return context->module_system()->NewInstance(); |
| 195 } | 195 } |
| 196 | 196 |
| 197 ChromeV8Context* context_; | 197 ChromeV8Context* context_; |
| 198 Dispatcher* dispatcher_; | 198 Dispatcher* dispatcher_; |
| 199 }; | 199 }; |
| 200 | 200 |
| 201 class ChromeHiddenNativeHandler : public ObjectBackedNativeHandler { | 201 class ChromeHiddenNativeHandler : public ObjectBackedNativeHandler { |
| 202 public: | 202 public: |
| 203 explicit ChromeHiddenNativeHandler(v8::Handle<v8::Context> context) | 203 explicit ChromeHiddenNativeHandler(ChromeV8Context* context) |
| 204 : ObjectBackedNativeHandler(context) { | 204 : ObjectBackedNativeHandler(context) { |
| 205 RouteFunction("GetChromeHidden", | 205 RouteFunction("GetChromeHidden", |
| 206 base::Bind(&ChromeHiddenNativeHandler::GetChromeHidden, | 206 base::Bind(&ChromeHiddenNativeHandler::GetChromeHidden, |
| 207 base::Unretained(this))); | 207 base::Unretained(this))); |
| 208 } | 208 } |
| 209 | 209 |
| 210 v8::Handle<v8::Value> GetChromeHidden(const v8::Arguments& args) { | 210 v8::Handle<v8::Value> GetChromeHidden(const v8::Arguments& args) { |
| 211 return ChromeV8Context::GetOrCreateChromeHidden(v8_context()); | 211 return ChromeV8Context::GetOrCreateChromeHidden(v8_context()); |
| 212 } | 212 } |
| 213 }; | 213 }; |
| 214 | 214 |
| 215 class ChromeNativeHandler : public ObjectBackedNativeHandler { | 215 class ChromeNativeHandler : public ObjectBackedNativeHandler { |
| 216 public: | 216 public: |
| 217 explicit ChromeNativeHandler(v8::Handle<v8::Context> context) | 217 explicit ChromeNativeHandler(ChromeV8Context* context) |
| 218 : ObjectBackedNativeHandler(context) { | 218 : ObjectBackedNativeHandler(context) { |
| 219 RouteFunction("GetChrome", | 219 RouteFunction("GetChrome", |
| 220 base::Bind(&ChromeNativeHandler::GetChrome, base::Unretained(this))); | 220 base::Bind(&ChromeNativeHandler::GetChrome, base::Unretained(this))); |
| 221 } | 221 } |
| 222 | 222 |
| 223 v8::Handle<v8::Value> GetChrome(const v8::Arguments& args) { | 223 v8::Handle<v8::Value> GetChrome(const v8::Arguments& args) { |
| 224 return GetOrCreateChrome(v8_context()); | 224 return GetOrCreateChrome(v8_context()); |
| 225 } | 225 } |
| 226 }; | 226 }; |
| 227 | 227 |
| 228 class PrintNativeHandler : public ObjectBackedNativeHandler { | 228 class PrintNativeHandler : public ObjectBackedNativeHandler { |
| 229 public: | 229 public: |
| 230 explicit PrintNativeHandler(v8::Handle<v8::Context> context) | 230 explicit PrintNativeHandler(ChromeV8Context* context) |
| 231 : ObjectBackedNativeHandler(context) { | 231 : ObjectBackedNativeHandler(context) { |
| 232 RouteFunction("Print", | 232 RouteFunction("Print", |
| 233 base::Bind(&PrintNativeHandler::Print, | 233 base::Bind(&PrintNativeHandler::Print, |
| 234 base::Unretained(this))); | 234 base::Unretained(this))); |
| 235 } | 235 } |
| 236 | 236 |
| 237 v8::Handle<v8::Value> Print(const v8::Arguments& args) { | 237 v8::Handle<v8::Value> Print(const v8::Arguments& args) { |
| 238 if (args.Length() < 1) | 238 if (args.Length() < 1) |
| 239 return v8::Undefined(); | 239 return v8::Undefined(); |
| 240 | 240 |
| 241 std::vector<std::string> components; | 241 std::vector<std::string> components; |
| 242 for (int i = 0; i < args.Length(); ++i) | 242 for (int i = 0; i < args.Length(); ++i) |
| 243 components.push_back(*v8::String::Utf8Value(args[i]->ToString())); | 243 components.push_back(*v8::String::Utf8Value(args[i]->ToString())); |
| 244 | 244 |
| 245 LOG(ERROR) << JoinString(components, ','); | 245 LOG(ERROR) << JoinString(components, ','); |
| 246 return v8::Undefined(); | 246 return v8::Undefined(); |
| 247 } | 247 } |
| 248 }; | 248 }; |
| 249 | 249 |
| 250 class LazyBackgroundPageNativeHandler : public ChromeV8Extension { | 250 class LazyBackgroundPageNativeHandler : public ChromeV8Extension { |
| 251 public: | 251 public: |
| 252 LazyBackgroundPageNativeHandler(Dispatcher* dispatcher, | 252 LazyBackgroundPageNativeHandler(Dispatcher* dispatcher, |
| 253 v8::Handle<v8::Context> context) | 253 ChromeV8Context* context) |
| 254 : ChromeV8Extension(dispatcher, context) { | 254 : ChromeV8Extension(dispatcher, context) { |
| 255 RouteFunction("IncrementKeepaliveCount", | 255 RouteFunction("IncrementKeepaliveCount", |
| 256 base::Bind(&LazyBackgroundPageNativeHandler::IncrementKeepaliveCount, | 256 base::Bind(&LazyBackgroundPageNativeHandler::IncrementKeepaliveCount, |
| 257 base::Unretained(this))); | 257 base::Unretained(this))); |
| 258 RouteFunction("DecrementKeepaliveCount", | 258 RouteFunction("DecrementKeepaliveCount", |
| 259 base::Bind(&LazyBackgroundPageNativeHandler::DecrementKeepaliveCount, | 259 base::Bind(&LazyBackgroundPageNativeHandler::DecrementKeepaliveCount, |
| 260 base::Unretained(this))); | 260 base::Unretained(this))); |
| 261 } | 261 } |
| 262 | 262 |
| 263 v8::Handle<v8::Value> IncrementKeepaliveCount(const v8::Arguments& args) { | 263 v8::Handle<v8::Value> IncrementKeepaliveCount(const v8::Arguments& args) { |
| (...skipping 30 matching lines...) Expand all Loading... |
| 294 | 294 |
| 295 ExtensionHelper* helper = ExtensionHelper::Get(render_view); | 295 ExtensionHelper* helper = ExtensionHelper::Get(render_view); |
| 296 return (extension && BackgroundInfo::HasLazyBackgroundPage(extension) && | 296 return (extension && BackgroundInfo::HasLazyBackgroundPage(extension) && |
| 297 helper->view_type() == VIEW_TYPE_EXTENSION_BACKGROUND_PAGE); | 297 helper->view_type() == VIEW_TYPE_EXTENSION_BACKGROUND_PAGE); |
| 298 } | 298 } |
| 299 }; | 299 }; |
| 300 | 300 |
| 301 class ProcessInfoNativeHandler : public ChromeV8Extension { | 301 class ProcessInfoNativeHandler : public ChromeV8Extension { |
| 302 public: | 302 public: |
| 303 ProcessInfoNativeHandler(Dispatcher* dispatcher, | 303 ProcessInfoNativeHandler(Dispatcher* dispatcher, |
| 304 v8::Handle<v8::Context> context, | 304 ChromeV8Context* context, |
| 305 const std::string& extension_id, | 305 const std::string& extension_id, |
| 306 const std::string& context_type, | 306 const std::string& context_type, |
| 307 bool is_incognito_context, | 307 bool is_incognito_context, |
| 308 int manifest_version, | 308 int manifest_version, |
| 309 bool send_request_disabled) | 309 bool send_request_disabled) |
| 310 : ChromeV8Extension(dispatcher, context), | 310 : ChromeV8Extension(dispatcher, context), |
| 311 extension_id_(extension_id), | 311 extension_id_(extension_id), |
| 312 context_type_(context_type), | 312 context_type_(context_type), |
| 313 is_incognito_context_(is_incognito_context), | 313 is_incognito_context_(is_incognito_context), |
| 314 manifest_version_(manifest_version), | 314 manifest_version_(manifest_version), |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 358 private: | 358 private: |
| 359 std::string extension_id_; | 359 std::string extension_id_; |
| 360 std::string context_type_; | 360 std::string context_type_; |
| 361 bool is_incognito_context_; | 361 bool is_incognito_context_; |
| 362 int manifest_version_; | 362 int manifest_version_; |
| 363 bool send_request_disabled_; | 363 bool send_request_disabled_; |
| 364 }; | 364 }; |
| 365 | 365 |
| 366 class LoggingNativeHandler : public ObjectBackedNativeHandler { | 366 class LoggingNativeHandler : public ObjectBackedNativeHandler { |
| 367 public: | 367 public: |
| 368 explicit LoggingNativeHandler(v8::Handle<v8::Context> context) | 368 explicit LoggingNativeHandler(ChromeV8Context* context) |
| 369 : ObjectBackedNativeHandler(context) { | 369 : ObjectBackedNativeHandler(context) { |
| 370 RouteFunction("DCHECK", | 370 RouteFunction("DCHECK", |
| 371 base::Bind(&LoggingNativeHandler::Dcheck, base::Unretained(this))); | 371 base::Bind(&LoggingNativeHandler::Dcheck, base::Unretained(this))); |
| 372 RouteFunction("CHECK", | 372 RouteFunction("CHECK", |
| 373 base::Bind(&LoggingNativeHandler::Check, base::Unretained(this))); | 373 base::Bind(&LoggingNativeHandler::Check, base::Unretained(this))); |
| 374 } | 374 } |
| 375 | 375 |
| 376 v8::Handle<v8::Value> Check(const v8::Arguments& args) { | 376 v8::Handle<v8::Value> Check(const v8::Arguments& args) { |
| 377 bool check_value; | 377 bool check_value; |
| 378 std::string error_message; | 378 std::string error_message; |
| (...skipping 404 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 783 module_system->SetLazyField(bind_object, | 783 module_system->SetLazyField(bind_object, |
| 784 split.back(), | 784 split.back(), |
| 785 api_name, | 785 api_name, |
| 786 "binding"); | 786 "binding"); |
| 787 } | 787 } |
| 788 } | 788 } |
| 789 } | 789 } |
| 790 | 790 |
| 791 void Dispatcher::RegisterNativeHandlers(ModuleSystem* module_system, | 791 void Dispatcher::RegisterNativeHandlers(ModuleSystem* module_system, |
| 792 ChromeV8Context* context) { | 792 ChromeV8Context* context) { |
| 793 v8::Handle<v8::Context> v8_context = context->v8_context(); | |
| 794 | |
| 795 module_system->RegisterNativeHandler("event_bindings", | 793 module_system->RegisterNativeHandler("event_bindings", |
| 796 scoped_ptr<NativeHandler>(EventBindings::Create(this, v8_context))); | 794 scoped_ptr<NativeHandler>(EventBindings::Create(this, context))); |
| 797 module_system->RegisterNativeHandler("miscellaneous_bindings", | 795 module_system->RegisterNativeHandler("miscellaneous_bindings", |
| 798 scoped_ptr<NativeHandler>(MiscellaneousBindings::Get(this, v8_context))); | 796 scoped_ptr<NativeHandler>(MiscellaneousBindings::Get(this, context))); |
| 799 module_system->RegisterNativeHandler("apiDefinitions", | 797 module_system->RegisterNativeHandler("apiDefinitions", |
| 800 scoped_ptr<NativeHandler>(new ApiDefinitionsNatives(this, context))); | 798 scoped_ptr<NativeHandler>(new ApiDefinitionsNatives(this, context))); |
| 801 module_system->RegisterNativeHandler("sendRequest", | 799 module_system->RegisterNativeHandler("sendRequest", |
| 802 scoped_ptr<NativeHandler>( | 800 scoped_ptr<NativeHandler>( |
| 803 new SendRequestNatives(this, request_sender_.get(), context))); | 801 new SendRequestNatives(this, request_sender_.get(), context))); |
| 804 module_system->RegisterNativeHandler("setIcon", | 802 module_system->RegisterNativeHandler("setIcon", |
| 805 scoped_ptr<NativeHandler>( | 803 scoped_ptr<NativeHandler>( |
| 806 new SetIconNatives(this, request_sender_.get(), context))); | 804 new SetIconNatives(this, request_sender_.get(), context))); |
| 807 module_system->RegisterNativeHandler( | 805 module_system->RegisterNativeHandler( |
| 808 "contentWatcherNative", | 806 "contentWatcherNative", |
| 809 content_watcher_->MakeNatives(v8_context)); | 807 content_watcher_->MakeNatives(context)); |
| 810 module_system->RegisterNativeHandler("activityLogger", | 808 module_system->RegisterNativeHandler("activityLogger", |
| 811 scoped_ptr<NativeHandler>(new APIActivityLogger(this, v8_context))); | 809 scoped_ptr<NativeHandler>(new APIActivityLogger(this, context))); |
| 812 | 810 |
| 813 // Natives used by multiple APIs. | 811 // Natives used by multiple APIs. |
| 814 module_system->RegisterNativeHandler("file_system_natives", | 812 module_system->RegisterNativeHandler("file_system_natives", |
| 815 scoped_ptr<NativeHandler>(new FileSystemNatives(v8_context))); | 813 scoped_ptr<NativeHandler>(new FileSystemNatives(context))); |
| 816 | 814 |
| 817 // Custom bindings. | 815 // Custom bindings. |
| 818 module_system->RegisterNativeHandler("app", | 816 module_system->RegisterNativeHandler("app", |
| 819 scoped_ptr<NativeHandler>(new AppBindings(this, context))); | 817 scoped_ptr<NativeHandler>(new AppBindings(this, context))); |
| 820 module_system->RegisterNativeHandler("app_runtime", | 818 module_system->RegisterNativeHandler("app_runtime", |
| 821 scoped_ptr<NativeHandler>( | 819 scoped_ptr<NativeHandler>( |
| 822 new AppRuntimeCustomBindings(this, v8_context))); | 820 new AppRuntimeCustomBindings(this, context))); |
| 823 module_system->RegisterNativeHandler("app_window", | 821 module_system->RegisterNativeHandler("app_window", |
| 824 scoped_ptr<NativeHandler>( | 822 scoped_ptr<NativeHandler>( |
| 825 new AppWindowCustomBindings(this, v8_context))); | 823 new AppWindowCustomBindings(this, context))); |
| 826 module_system->RegisterNativeHandler("context_menus", | 824 module_system->RegisterNativeHandler("context_menus", |
| 827 scoped_ptr<NativeHandler>( | 825 scoped_ptr<NativeHandler>( |
| 828 new ContextMenusCustomBindings(this, v8_context))); | 826 new ContextMenusCustomBindings(this, context))); |
| 829 module_system->RegisterNativeHandler("extension", | 827 module_system->RegisterNativeHandler("extension", |
| 830 scoped_ptr<NativeHandler>( | 828 scoped_ptr<NativeHandler>( |
| 831 new ExtensionCustomBindings(this, v8_context))); | 829 new ExtensionCustomBindings(this, context))); |
| 832 module_system->RegisterNativeHandler("sync_file_system", | 830 module_system->RegisterNativeHandler("sync_file_system", |
| 833 scoped_ptr<NativeHandler>( | 831 scoped_ptr<NativeHandler>( |
| 834 new SyncFileSystemCustomBindings(this, v8_context))); | 832 new SyncFileSystemCustomBindings(this, context))); |
| 835 module_system->RegisterNativeHandler("file_browser_handler", | 833 module_system->RegisterNativeHandler("file_browser_handler", |
| 836 scoped_ptr<NativeHandler>(new FileBrowserHandlerCustomBindings( | 834 scoped_ptr<NativeHandler>(new FileBrowserHandlerCustomBindings( |
| 837 this, v8_context))); | 835 this, context))); |
| 838 module_system->RegisterNativeHandler("file_browser_private", | 836 module_system->RegisterNativeHandler("file_browser_private", |
| 839 scoped_ptr<NativeHandler>(new FileBrowserPrivateCustomBindings( | 837 scoped_ptr<NativeHandler>(new FileBrowserPrivateCustomBindings( |
| 840 this, v8_context))); | 838 this, context))); |
| 841 module_system->RegisterNativeHandler("i18n", | 839 module_system->RegisterNativeHandler("i18n", |
| 842 scoped_ptr<NativeHandler>( | 840 scoped_ptr<NativeHandler>( |
| 843 new I18NCustomBindings(this, v8_context))); | 841 new I18NCustomBindings(this, context))); |
| 844 module_system->RegisterNativeHandler("mediaGalleries", | 842 module_system->RegisterNativeHandler("mediaGalleries", |
| 845 scoped_ptr<NativeHandler>( | 843 scoped_ptr<NativeHandler>( |
| 846 new MediaGalleriesCustomBindings(this, v8_context))); | 844 new MediaGalleriesCustomBindings(this, context))); |
| 847 module_system->RegisterNativeHandler("page_actions", | 845 module_system->RegisterNativeHandler("page_actions", |
| 848 scoped_ptr<NativeHandler>( | 846 scoped_ptr<NativeHandler>( |
| 849 new PageActionsCustomBindings(this, v8_context))); | 847 new PageActionsCustomBindings(this, context))); |
| 850 module_system->RegisterNativeHandler("page_capture", | 848 module_system->RegisterNativeHandler("page_capture", |
| 851 scoped_ptr<NativeHandler>( | 849 scoped_ptr<NativeHandler>( |
| 852 new PageCaptureCustomBindings(this, v8_context))); | 850 new PageCaptureCustomBindings(this, context))); |
| 853 module_system->RegisterNativeHandler("runtime", | 851 module_system->RegisterNativeHandler("runtime", |
| 854 scoped_ptr<NativeHandler>(new RuntimeCustomBindings(this, context))); | 852 scoped_ptr<NativeHandler>(new RuntimeCustomBindings(this, context))); |
| 855 module_system->RegisterNativeHandler("tabs", | 853 module_system->RegisterNativeHandler("tabs", |
| 856 scoped_ptr<NativeHandler>(new TabsCustomBindings(this, v8_context))); | 854 scoped_ptr<NativeHandler>(new TabsCustomBindings(this, context))); |
| 857 module_system->RegisterNativeHandler("tts", | 855 module_system->RegisterNativeHandler("tts", |
| 858 scoped_ptr<NativeHandler>(new TTSCustomBindings(this, v8_context))); | 856 scoped_ptr<NativeHandler>(new TTSCustomBindings(this, context))); |
| 859 module_system->RegisterNativeHandler("web_request", | 857 module_system->RegisterNativeHandler("web_request", |
| 860 scoped_ptr<NativeHandler>( | 858 scoped_ptr<NativeHandler>( |
| 861 new WebRequestCustomBindings(this, v8_context))); | 859 new WebRequestCustomBindings(this, context))); |
| 862 module_system->RegisterNativeHandler("webstore", | 860 module_system->RegisterNativeHandler("webstore", |
| 863 scoped_ptr<NativeHandler>(new WebstoreBindings(this, context))); | 861 scoped_ptr<NativeHandler>(new WebstoreBindings(this, context))); |
| 864 } | 862 } |
| 865 | 863 |
| 866 void Dispatcher::PopulateSourceMap() { | 864 void Dispatcher::PopulateSourceMap() { |
| 867 source_map_.RegisterSource("event_bindings", IDR_EVENT_BINDINGS_JS); | 865 source_map_.RegisterSource("event_bindings", IDR_EVENT_BINDINGS_JS); |
| 868 source_map_.RegisterSource("miscellaneous_bindings", | 866 source_map_.RegisterSource("miscellaneous_bindings", |
| 869 IDR_MISCELLANEOUS_BINDINGS_JS); | 867 IDR_MISCELLANEOUS_BINDINGS_JS); |
| 870 source_map_.RegisterSource("json", IDR_JSON_JS); | 868 source_map_.RegisterSource("json", IDR_JSON_JS); |
| 871 source_map_.RegisterSource("json_schema", IDR_JSON_SCHEMA_JS); | 869 source_map_.RegisterSource("json_schema", IDR_JSON_SCHEMA_JS); |
| (...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1012 ExtensionURLInfo url_info(frame->document().securityOrigin(), | 1010 ExtensionURLInfo url_info(frame->document().securityOrigin(), |
| 1013 UserScriptSlave::GetDataSourceURLForFrame(frame)); | 1011 UserScriptSlave::GetDataSourceURLForFrame(frame)); |
| 1014 | 1012 |
| 1015 Feature::Context context_type = | 1013 Feature::Context context_type = |
| 1016 ClassifyJavaScriptContext(extension_id, extension_group, url_info); | 1014 ClassifyJavaScriptContext(extension_id, extension_group, url_info); |
| 1017 | 1015 |
| 1018 ChromeV8Context* context = | 1016 ChromeV8Context* context = |
| 1019 new ChromeV8Context(v8_context, frame, extension, context_type); | 1017 new ChromeV8Context(v8_context, frame, extension, context_type); |
| 1020 v8_context_set_.Add(context); | 1018 v8_context_set_.Add(context); |
| 1021 | 1019 |
| 1022 scoped_ptr<ModuleSystem> module_system(new ModuleSystem(v8_context, | 1020 scoped_ptr<ModuleSystem> module_system(new ModuleSystem(context, |
| 1023 &source_map_)); | 1021 &source_map_)); |
| 1024 // Enable natives in startup. | 1022 // Enable natives in startup. |
| 1025 ModuleSystem::NativesEnabledScope natives_enabled_scope(module_system.get()); | 1023 ModuleSystem::NativesEnabledScope natives_enabled_scope(module_system.get()); |
| 1026 | 1024 |
| 1027 RegisterNativeHandlers(module_system.get(), context); | 1025 RegisterNativeHandlers(module_system.get(), context); |
| 1028 | 1026 |
| 1029 module_system->RegisterNativeHandler("chrome", | 1027 module_system->RegisterNativeHandler("chrome", |
| 1030 scoped_ptr<NativeHandler>(new ChromeNativeHandler(v8_context))); | 1028 scoped_ptr<NativeHandler>(new ChromeNativeHandler(context))); |
| 1031 module_system->RegisterNativeHandler("chrome_hidden", | 1029 module_system->RegisterNativeHandler("chrome_hidden", |
| 1032 scoped_ptr<NativeHandler>(new ChromeHiddenNativeHandler(v8_context))); | 1030 scoped_ptr<NativeHandler>(new ChromeHiddenNativeHandler(context))); |
| 1033 module_system->RegisterNativeHandler("print", | 1031 module_system->RegisterNativeHandler("print", |
| 1034 scoped_ptr<NativeHandler>(new PrintNativeHandler(v8_context))); | 1032 scoped_ptr<NativeHandler>(new PrintNativeHandler(context))); |
| 1035 module_system->RegisterNativeHandler("lazy_background_page", | 1033 module_system->RegisterNativeHandler("lazy_background_page", |
| 1036 scoped_ptr<NativeHandler>( | 1034 scoped_ptr<NativeHandler>( |
| 1037 new LazyBackgroundPageNativeHandler(this, v8_context))); | 1035 new LazyBackgroundPageNativeHandler(this, context))); |
| 1038 module_system->RegisterNativeHandler("logging", | 1036 module_system->RegisterNativeHandler("logging", |
| 1039 scoped_ptr<NativeHandler>(new LoggingNativeHandler(v8_context))); | 1037 scoped_ptr<NativeHandler>(new LoggingNativeHandler(context))); |
| 1040 module_system->RegisterNativeHandler("schema_registry", | 1038 module_system->RegisterNativeHandler("schema_registry", |
| 1041 scoped_ptr<NativeHandler>( | 1039 scoped_ptr<NativeHandler>( |
| 1042 new SchemaRegistryNativeHandler(v8_schema_registry(), v8_context))); | 1040 new SchemaRegistryNativeHandler(v8_schema_registry(), context))); |
| 1043 module_system->RegisterNativeHandler("v8_context", | 1041 module_system->RegisterNativeHandler("v8_context", |
| 1044 scoped_ptr<NativeHandler>(new V8ContextNativeHandler(context, this))); | 1042 scoped_ptr<NativeHandler>(new V8ContextNativeHandler(context, this))); |
| 1045 module_system->RegisterNativeHandler("test_features", | 1043 module_system->RegisterNativeHandler("test_features", |
| 1046 scoped_ptr<NativeHandler>(new TestFeaturesNativeHandler(v8_context))); | 1044 scoped_ptr<NativeHandler>(new TestFeaturesNativeHandler(context))); |
| 1047 | 1045 |
| 1048 int manifest_version = extension ? extension->manifest_version() : 1; | 1046 int manifest_version = extension ? extension->manifest_version() : 1; |
| 1049 bool send_request_disabled = | 1047 bool send_request_disabled = |
| 1050 (extension && Manifest::IsUnpackedLocation(extension->location()) && | 1048 (extension && Manifest::IsUnpackedLocation(extension->location()) && |
| 1051 BackgroundInfo::HasLazyBackgroundPage(extension)); | 1049 BackgroundInfo::HasLazyBackgroundPage(extension)); |
| 1052 module_system->RegisterNativeHandler("process", | 1050 module_system->RegisterNativeHandler("process", |
| 1053 scoped_ptr<NativeHandler>(new ProcessInfoNativeHandler( | 1051 scoped_ptr<NativeHandler>(new ProcessInfoNativeHandler( |
| 1054 this, v8_context, context->GetExtensionID(), | 1052 this, context, context->GetExtensionID(), |
| 1055 context->GetContextTypeDescription(), | 1053 context->GetContextTypeDescription(), |
| 1056 ChromeRenderProcessObserver::is_incognito_process(), | 1054 ChromeRenderProcessObserver::is_incognito_process(), |
| 1057 manifest_version, send_request_disabled))); | 1055 manifest_version, send_request_disabled))); |
| 1058 | 1056 |
| 1059 GetOrCreateChrome(v8_context); | 1057 GetOrCreateChrome(v8_context); |
| 1060 | 1058 |
| 1061 // Loading JavaScript is expensive, so only run the full API bindings | 1059 // Loading JavaScript is expensive, so only run the full API bindings |
| 1062 // generation mechanisms in extension pages (NOT all web pages). | 1060 // generation mechanisms in extension pages (NOT all web pages). |
| 1063 switch (context_type) { | 1061 switch (context_type) { |
| 1064 case Feature::UNSPECIFIED_CONTEXT: | 1062 case Feature::UNSPECIFIED_CONTEXT: |
| (...skipping 394 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1459 std::string error_msg = base::StringPrintf(kMessage, function_name.c_str()); | 1457 std::string error_msg = base::StringPrintf(kMessage, function_name.c_str()); |
| 1460 v8::ThrowException( | 1458 v8::ThrowException( |
| 1461 v8::Exception::Error(v8::String::New(error_msg.c_str()))); | 1459 v8::Exception::Error(v8::String::New(error_msg.c_str()))); |
| 1462 return false; | 1460 return false; |
| 1463 } | 1461 } |
| 1464 | 1462 |
| 1465 return true; | 1463 return true; |
| 1466 } | 1464 } |
| 1467 | 1465 |
| 1468 } // namespace extensions | 1466 } // namespace extensions |
| OLD | NEW |