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" | 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, context()->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(context()->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(context()->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) { |
| 264 ChromeV8Context* context = | 264 ChromeV8Context* context = GetContext(); |
|
not at google - send to devlin
2013/05/29 17:41:55
could inline this as context() too, etc below.
marja
2013/05/31 10:06:44
Done.
| |
| 265 dispatcher()->v8_context_set().GetByV8Context(v8_context()); | |
| 266 if (!context) | 265 if (!context) |
| 267 return v8::Undefined(); | 266 return v8::Undefined(); |
| 268 RenderView* render_view = context->GetRenderView(); | 267 RenderView* render_view = context->GetRenderView(); |
| 269 if (IsContextLazyBackgroundPage(render_view, context->extension())) { | 268 if (IsContextLazyBackgroundPage(render_view, context->extension())) { |
| 270 render_view->Send(new ExtensionHostMsg_IncrementLazyKeepaliveCount( | 269 render_view->Send(new ExtensionHostMsg_IncrementLazyKeepaliveCount( |
| 271 render_view->GetRoutingID())); | 270 render_view->GetRoutingID())); |
| 272 } | 271 } |
| 273 return v8::Undefined(); | 272 return v8::Undefined(); |
| 274 } | 273 } |
| 275 | 274 |
| 276 v8::Handle<v8::Value> DecrementKeepaliveCount(const v8::Arguments& args) { | 275 v8::Handle<v8::Value> DecrementKeepaliveCount(const v8::Arguments& args) { |
| 277 ChromeV8Context* context = | 276 ChromeV8Context* context = GetContext(); |
| 278 dispatcher()->v8_context_set().GetByV8Context(v8_context()); | |
| 279 if (!context) | 277 if (!context) |
| 280 return v8::Undefined(); | 278 return v8::Undefined(); |
| 281 RenderView* render_view = context->GetRenderView(); | 279 RenderView* render_view = context->GetRenderView(); |
| 282 if (IsContextLazyBackgroundPage(render_view, context->extension())) { | 280 if (IsContextLazyBackgroundPage(render_view, context->extension())) { |
| 283 render_view->Send(new ExtensionHostMsg_DecrementLazyKeepaliveCount( | 281 render_view->Send(new ExtensionHostMsg_DecrementLazyKeepaliveCount( |
| 284 render_view->GetRoutingID())); | 282 render_view->GetRoutingID())); |
| 285 } | 283 } |
| 286 return v8::Undefined(); | 284 return v8::Undefined(); |
| 287 } | 285 } |
| 288 | 286 |
| 289 private: | 287 private: |
| 290 bool IsContextLazyBackgroundPage(RenderView* render_view, | 288 bool IsContextLazyBackgroundPage(RenderView* render_view, |
| 291 const Extension* extension) { | 289 const Extension* extension) { |
| 292 if (!render_view) | 290 if (!render_view) |
| 293 return false; | 291 return false; |
| 294 | 292 |
| 295 ExtensionHelper* helper = ExtensionHelper::Get(render_view); | 293 ExtensionHelper* helper = ExtensionHelper::Get(render_view); |
| 296 return (extension && BackgroundInfo::HasLazyBackgroundPage(extension) && | 294 return (extension && BackgroundInfo::HasLazyBackgroundPage(extension) && |
| 297 helper->view_type() == VIEW_TYPE_EXTENSION_BACKGROUND_PAGE); | 295 helper->view_type() == VIEW_TYPE_EXTENSION_BACKGROUND_PAGE); |
| 298 } | 296 } |
| 299 }; | 297 }; |
| 300 | 298 |
| 301 class ProcessInfoNativeHandler : public ChromeV8Extension { | 299 class ProcessInfoNativeHandler : public ChromeV8Extension { |
| 302 public: | 300 public: |
| 303 ProcessInfoNativeHandler(Dispatcher* dispatcher, | 301 ProcessInfoNativeHandler(Dispatcher* dispatcher, |
| 304 v8::Handle<v8::Context> context, | 302 ChromeV8Context* context, |
| 305 const std::string& extension_id, | 303 const std::string& extension_id, |
| 306 const std::string& context_type, | 304 const std::string& context_type, |
| 307 bool is_incognito_context, | 305 bool is_incognito_context, |
| 308 int manifest_version, | 306 int manifest_version, |
| 309 bool send_request_disabled) | 307 bool send_request_disabled) |
| 310 : ChromeV8Extension(dispatcher, context), | 308 : ChromeV8Extension(dispatcher, context), |
| 311 extension_id_(extension_id), | 309 extension_id_(extension_id), |
| 312 context_type_(context_type), | 310 context_type_(context_type), |
| 313 is_incognito_context_(is_incognito_context), | 311 is_incognito_context_(is_incognito_context), |
| 314 manifest_version_(manifest_version), | 312 manifest_version_(manifest_version), |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 358 private: | 356 private: |
| 359 std::string extension_id_; | 357 std::string extension_id_; |
| 360 std::string context_type_; | 358 std::string context_type_; |
| 361 bool is_incognito_context_; | 359 bool is_incognito_context_; |
| 362 int manifest_version_; | 360 int manifest_version_; |
| 363 bool send_request_disabled_; | 361 bool send_request_disabled_; |
| 364 }; | 362 }; |
| 365 | 363 |
| 366 class LoggingNativeHandler : public ObjectBackedNativeHandler { | 364 class LoggingNativeHandler : public ObjectBackedNativeHandler { |
| 367 public: | 365 public: |
| 368 explicit LoggingNativeHandler(v8::Handle<v8::Context> context) | 366 explicit LoggingNativeHandler(ChromeV8Context* context) |
| 369 : ObjectBackedNativeHandler(context) { | 367 : ObjectBackedNativeHandler(context) { |
| 370 RouteFunction("DCHECK", | 368 RouteFunction("DCHECK", |
| 371 base::Bind(&LoggingNativeHandler::Dcheck, base::Unretained(this))); | 369 base::Bind(&LoggingNativeHandler::Dcheck, base::Unretained(this))); |
| 372 RouteFunction("CHECK", | 370 RouteFunction("CHECK", |
| 373 base::Bind(&LoggingNativeHandler::Check, base::Unretained(this))); | 371 base::Bind(&LoggingNativeHandler::Check, base::Unretained(this))); |
| 374 } | 372 } |
| 375 | 373 |
| 376 v8::Handle<v8::Value> Check(const v8::Arguments& args) { | 374 v8::Handle<v8::Value> Check(const v8::Arguments& args) { |
| 377 bool check_value; | 375 bool check_value; |
| 378 std::string error_message; | 376 std::string error_message; |
| (...skipping 381 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 760 !context->GetAvailability(api_name).is_available()) { | 758 !context->GetAvailability(api_name).is_available()) { |
| 761 only_ancestor_available = true; | 759 only_ancestor_available = true; |
| 762 break; | 760 break; |
| 763 } | 761 } |
| 764 bind_object = GetOrCreateObject(bind_object, split[i]); | 762 bind_object = GetOrCreateObject(bind_object, split[i]); |
| 765 } | 763 } |
| 766 if (only_ancestor_available) | 764 if (only_ancestor_available) |
| 767 continue; | 765 continue; |
| 768 | 766 |
| 769 if (lazy_bindings_map_.find(api_name) != lazy_bindings_map_.end()) { | 767 if (lazy_bindings_map_.find(api_name) != lazy_bindings_map_.end()) { |
| 770 InstallBindings(module_system, context->v8_context(), api_name); | 768 InstallBindings( |
| 769 module_system, context->v8_context(), api_name); | |
| 771 } else if (!source_map_.Contains(api_name)) { | 770 } else if (!source_map_.Contains(api_name)) { |
| 772 module_system->RegisterNativeHandler( | 771 module_system->RegisterNativeHandler( |
| 773 api_name, | 772 api_name, |
| 774 scoped_ptr<NativeHandler>(new BindingGeneratingNativeHandler( | 773 scoped_ptr<NativeHandler>(new BindingGeneratingNativeHandler( |
| 775 module_system, | 774 module_system, |
| 776 api_name, | 775 api_name, |
| 777 "binding"))); | 776 "binding"))); |
| 778 module_system->SetNativeLazyField(bind_object, | 777 module_system->SetNativeLazyField(bind_object, |
| 779 split.back(), | 778 split.back(), |
| 780 api_name, | 779 api_name, |
| 781 "binding"); | 780 "binding"); |
| 782 } else { | 781 } else { |
| 783 module_system->SetLazyField(bind_object, | 782 module_system->SetLazyField(bind_object, |
| 784 split.back(), | 783 split.back(), |
| 785 api_name, | 784 api_name, |
| 786 "binding"); | 785 "binding"); |
| 787 } | 786 } |
| 788 } | 787 } |
| 789 } | 788 } |
| 790 | 789 |
| 791 void Dispatcher::RegisterNativeHandlers(ModuleSystem* module_system, | 790 void Dispatcher::RegisterNativeHandlers(ModuleSystem* module_system, |
| 792 ChromeV8Context* context) { | 791 ChromeV8Context* context) { |
| 793 v8::Handle<v8::Context> v8_context = context->v8_context(); | |
| 794 | |
| 795 module_system->RegisterNativeHandler("event_bindings", | 792 module_system->RegisterNativeHandler("event_bindings", |
| 796 scoped_ptr<NativeHandler>(EventBindings::Create(this, v8_context))); | 793 scoped_ptr<NativeHandler>(EventBindings::Create(this, context))); |
| 797 module_system->RegisterNativeHandler("miscellaneous_bindings", | 794 module_system->RegisterNativeHandler("miscellaneous_bindings", |
| 798 scoped_ptr<NativeHandler>(MiscellaneousBindings::Get(this, v8_context))); | 795 scoped_ptr<NativeHandler>(MiscellaneousBindings::Get(this, context))); |
| 799 module_system->RegisterNativeHandler("apiDefinitions", | 796 module_system->RegisterNativeHandler("apiDefinitions", |
| 800 scoped_ptr<NativeHandler>(new ApiDefinitionsNatives(this, context))); | 797 scoped_ptr<NativeHandler>(new ApiDefinitionsNatives(this, context))); |
| 801 module_system->RegisterNativeHandler("sendRequest", | 798 module_system->RegisterNativeHandler("sendRequest", |
| 802 scoped_ptr<NativeHandler>( | 799 scoped_ptr<NativeHandler>( |
| 803 new SendRequestNatives(this, request_sender_.get(), context))); | 800 new SendRequestNatives(this, request_sender_.get(), context))); |
| 804 module_system->RegisterNativeHandler("setIcon", | 801 module_system->RegisterNativeHandler("setIcon", |
| 805 scoped_ptr<NativeHandler>( | 802 scoped_ptr<NativeHandler>( |
| 806 new SetIconNatives(this, request_sender_.get(), context))); | 803 new SetIconNatives(this, request_sender_.get(), context))); |
| 807 module_system->RegisterNativeHandler( | 804 module_system->RegisterNativeHandler( |
| 808 "contentWatcherNative", | 805 "contentWatcherNative", |
| 809 content_watcher_->MakeNatives(v8_context)); | 806 content_watcher_->MakeNatives(context)); |
| 810 module_system->RegisterNativeHandler("activityLogger", | 807 module_system->RegisterNativeHandler("activityLogger", |
| 811 scoped_ptr<NativeHandler>(new APIActivityLogger(this, v8_context))); | 808 scoped_ptr<NativeHandler>(new APIActivityLogger(this, context))); |
| 812 | 809 |
| 813 // Natives used by multiple APIs. | 810 // Natives used by multiple APIs. |
| 814 module_system->RegisterNativeHandler("file_system_natives", | 811 module_system->RegisterNativeHandler("file_system_natives", |
| 815 scoped_ptr<NativeHandler>(new FileSystemNatives(v8_context))); | 812 scoped_ptr<NativeHandler>(new FileSystemNatives(context))); |
| 816 | 813 |
| 817 // Custom bindings. | 814 // Custom bindings. |
| 818 module_system->RegisterNativeHandler("app", | 815 module_system->RegisterNativeHandler("app", |
| 819 scoped_ptr<NativeHandler>(new AppBindings(this, context))); | 816 scoped_ptr<NativeHandler>(new AppBindings(this, context))); |
| 820 module_system->RegisterNativeHandler("app_runtime", | 817 module_system->RegisterNativeHandler("app_runtime", |
| 821 scoped_ptr<NativeHandler>( | 818 scoped_ptr<NativeHandler>( |
| 822 new AppRuntimeCustomBindings(this, v8_context))); | 819 new AppRuntimeCustomBindings(this, context))); |
| 823 module_system->RegisterNativeHandler("app_window", | 820 module_system->RegisterNativeHandler("app_window", |
| 824 scoped_ptr<NativeHandler>( | 821 scoped_ptr<NativeHandler>( |
| 825 new AppWindowCustomBindings(this, v8_context))); | 822 new AppWindowCustomBindings(this, context))); |
| 826 module_system->RegisterNativeHandler("context_menus", | 823 module_system->RegisterNativeHandler("context_menus", |
| 827 scoped_ptr<NativeHandler>( | 824 scoped_ptr<NativeHandler>( |
| 828 new ContextMenusCustomBindings(this, v8_context))); | 825 new ContextMenusCustomBindings(this, context))); |
| 829 module_system->RegisterNativeHandler("extension", | 826 module_system->RegisterNativeHandler("extension", |
| 830 scoped_ptr<NativeHandler>( | 827 scoped_ptr<NativeHandler>( |
| 831 new ExtensionCustomBindings(this, v8_context))); | 828 new ExtensionCustomBindings(this, context))); |
| 832 module_system->RegisterNativeHandler("sync_file_system", | 829 module_system->RegisterNativeHandler("sync_file_system", |
| 833 scoped_ptr<NativeHandler>( | 830 scoped_ptr<NativeHandler>( |
| 834 new SyncFileSystemCustomBindings(this, v8_context))); | 831 new SyncFileSystemCustomBindings(this, context))); |
| 835 module_system->RegisterNativeHandler("file_browser_handler", | 832 module_system->RegisterNativeHandler("file_browser_handler", |
| 836 scoped_ptr<NativeHandler>(new FileBrowserHandlerCustomBindings( | 833 scoped_ptr<NativeHandler>(new FileBrowserHandlerCustomBindings( |
| 837 this, v8_context))); | 834 this, context))); |
| 838 module_system->RegisterNativeHandler("file_browser_private", | 835 module_system->RegisterNativeHandler("file_browser_private", |
| 839 scoped_ptr<NativeHandler>(new FileBrowserPrivateCustomBindings( | 836 scoped_ptr<NativeHandler>(new FileBrowserPrivateCustomBindings( |
| 840 this, v8_context))); | 837 this, context))); |
| 841 module_system->RegisterNativeHandler("i18n", | 838 module_system->RegisterNativeHandler("i18n", |
| 842 scoped_ptr<NativeHandler>( | 839 scoped_ptr<NativeHandler>( |
| 843 new I18NCustomBindings(this, v8_context))); | 840 new I18NCustomBindings(this, context))); |
| 844 module_system->RegisterNativeHandler("mediaGalleries", | 841 module_system->RegisterNativeHandler("mediaGalleries", |
| 845 scoped_ptr<NativeHandler>( | 842 scoped_ptr<NativeHandler>( |
| 846 new MediaGalleriesCustomBindings(this, v8_context))); | 843 new MediaGalleriesCustomBindings(this, context))); |
| 847 module_system->RegisterNativeHandler("page_actions", | 844 module_system->RegisterNativeHandler("page_actions", |
| 848 scoped_ptr<NativeHandler>( | 845 scoped_ptr<NativeHandler>( |
| 849 new PageActionsCustomBindings(this, v8_context))); | 846 new PageActionsCustomBindings(this, context))); |
| 850 module_system->RegisterNativeHandler("page_capture", | 847 module_system->RegisterNativeHandler("page_capture", |
| 851 scoped_ptr<NativeHandler>( | 848 scoped_ptr<NativeHandler>( |
| 852 new PageCaptureCustomBindings(this, v8_context))); | 849 new PageCaptureCustomBindings(this, context))); |
| 853 module_system->RegisterNativeHandler("runtime", | 850 module_system->RegisterNativeHandler("runtime", |
| 854 scoped_ptr<NativeHandler>(new RuntimeCustomBindings(this, context))); | 851 scoped_ptr<NativeHandler>(new RuntimeCustomBindings(this, context))); |
| 855 module_system->RegisterNativeHandler("tabs", | 852 module_system->RegisterNativeHandler("tabs", |
| 856 scoped_ptr<NativeHandler>(new TabsCustomBindings(this, v8_context))); | 853 scoped_ptr<NativeHandler>(new TabsCustomBindings(this, context))); |
| 857 module_system->RegisterNativeHandler("tts", | 854 module_system->RegisterNativeHandler("tts", |
| 858 scoped_ptr<NativeHandler>(new TTSCustomBindings(this, v8_context))); | 855 scoped_ptr<NativeHandler>(new TTSCustomBindings(this, context))); |
| 859 module_system->RegisterNativeHandler("web_request", | 856 module_system->RegisterNativeHandler("web_request", |
| 860 scoped_ptr<NativeHandler>( | 857 scoped_ptr<NativeHandler>( |
| 861 new WebRequestCustomBindings(this, v8_context))); | 858 new WebRequestCustomBindings(this, context))); |
| 862 module_system->RegisterNativeHandler("webstore", | 859 module_system->RegisterNativeHandler("webstore", |
| 863 scoped_ptr<NativeHandler>(new WebstoreBindings(this, context))); | 860 scoped_ptr<NativeHandler>(new WebstoreBindings(this, context))); |
| 864 } | 861 } |
| 865 | 862 |
| 866 void Dispatcher::PopulateSourceMap() { | 863 void Dispatcher::PopulateSourceMap() { |
| 867 source_map_.RegisterSource("event_bindings", IDR_EVENT_BINDINGS_JS); | 864 source_map_.RegisterSource("event_bindings", IDR_EVENT_BINDINGS_JS); |
| 868 source_map_.RegisterSource("miscellaneous_bindings", | 865 source_map_.RegisterSource("miscellaneous_bindings", |
| 869 IDR_MISCELLANEOUS_BINDINGS_JS); | 866 IDR_MISCELLANEOUS_BINDINGS_JS); |
| 870 source_map_.RegisterSource("json", IDR_JSON_JS); | 867 source_map_.RegisterSource("json", IDR_JSON_JS); |
| 871 source_map_.RegisterSource("json_schema", IDR_JSON_SCHEMA_JS); | 868 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(), | 1009 ExtensionURLInfo url_info(frame->document().securityOrigin(), |
| 1013 UserScriptSlave::GetDataSourceURLForFrame(frame)); | 1010 UserScriptSlave::GetDataSourceURLForFrame(frame)); |
| 1014 | 1011 |
| 1015 Feature::Context context_type = | 1012 Feature::Context context_type = |
| 1016 ClassifyJavaScriptContext(extension_id, extension_group, url_info); | 1013 ClassifyJavaScriptContext(extension_id, extension_group, url_info); |
| 1017 | 1014 |
| 1018 ChromeV8Context* context = | 1015 ChromeV8Context* context = |
| 1019 new ChromeV8Context(v8_context, frame, extension, context_type); | 1016 new ChromeV8Context(v8_context, frame, extension, context_type); |
| 1020 v8_context_set_.Add(context); | 1017 v8_context_set_.Add(context); |
| 1021 | 1018 |
| 1022 scoped_ptr<ModuleSystem> module_system(new ModuleSystem(v8_context, | 1019 scoped_ptr<ModuleSystem> module_system(new ModuleSystem(context, |
| 1023 &source_map_)); | 1020 &source_map_)); |
| 1024 // Enable natives in startup. | 1021 // Enable natives in startup. |
| 1025 ModuleSystem::NativesEnabledScope natives_enabled_scope(module_system.get()); | 1022 ModuleSystem::NativesEnabledScope natives_enabled_scope(module_system.get()); |
| 1026 | 1023 |
| 1027 RegisterNativeHandlers(module_system.get(), context); | 1024 RegisterNativeHandlers(module_system.get(), context); |
| 1028 | 1025 |
| 1029 module_system->RegisterNativeHandler("chrome", | 1026 module_system->RegisterNativeHandler("chrome", |
| 1030 scoped_ptr<NativeHandler>(new ChromeNativeHandler(v8_context))); | 1027 scoped_ptr<NativeHandler>(new ChromeNativeHandler(context))); |
| 1031 module_system->RegisterNativeHandler("chrome_hidden", | 1028 module_system->RegisterNativeHandler("chrome_hidden", |
| 1032 scoped_ptr<NativeHandler>(new ChromeHiddenNativeHandler(v8_context))); | 1029 scoped_ptr<NativeHandler>(new ChromeHiddenNativeHandler(context))); |
| 1033 module_system->RegisterNativeHandler("print", | 1030 module_system->RegisterNativeHandler("print", |
| 1034 scoped_ptr<NativeHandler>(new PrintNativeHandler(v8_context))); | 1031 scoped_ptr<NativeHandler>(new PrintNativeHandler(context))); |
| 1035 module_system->RegisterNativeHandler("lazy_background_page", | 1032 module_system->RegisterNativeHandler("lazy_background_page", |
| 1036 scoped_ptr<NativeHandler>( | 1033 scoped_ptr<NativeHandler>( |
| 1037 new LazyBackgroundPageNativeHandler(this, v8_context))); | 1034 new LazyBackgroundPageNativeHandler(this, context))); |
| 1038 module_system->RegisterNativeHandler("logging", | 1035 module_system->RegisterNativeHandler("logging", |
| 1039 scoped_ptr<NativeHandler>(new LoggingNativeHandler(v8_context))); | 1036 scoped_ptr<NativeHandler>(new LoggingNativeHandler(context))); |
| 1040 module_system->RegisterNativeHandler("schema_registry", | 1037 module_system->RegisterNativeHandler("schema_registry", |
| 1041 scoped_ptr<NativeHandler>( | 1038 scoped_ptr<NativeHandler>( |
| 1042 new SchemaRegistryNativeHandler(v8_schema_registry(), v8_context))); | 1039 new SchemaRegistryNativeHandler(v8_schema_registry(), context))); |
| 1043 module_system->RegisterNativeHandler("v8_context", | 1040 module_system->RegisterNativeHandler("v8_context", |
| 1044 scoped_ptr<NativeHandler>(new V8ContextNativeHandler(context, this))); | 1041 scoped_ptr<NativeHandler>(new V8ContextNativeHandler(context, this))); |
| 1045 module_system->RegisterNativeHandler("test_features", | 1042 module_system->RegisterNativeHandler("test_features", |
| 1046 scoped_ptr<NativeHandler>(new TestFeaturesNativeHandler(v8_context))); | 1043 scoped_ptr<NativeHandler>(new TestFeaturesNativeHandler(context))); |
| 1047 | 1044 |
| 1048 int manifest_version = extension ? extension->manifest_version() : 1; | 1045 int manifest_version = extension ? extension->manifest_version() : 1; |
| 1049 bool send_request_disabled = | 1046 bool send_request_disabled = |
| 1050 (extension && Manifest::IsUnpackedLocation(extension->location()) && | 1047 (extension && Manifest::IsUnpackedLocation(extension->location()) && |
| 1051 BackgroundInfo::HasLazyBackgroundPage(extension)); | 1048 BackgroundInfo::HasLazyBackgroundPage(extension)); |
| 1052 module_system->RegisterNativeHandler("process", | 1049 module_system->RegisterNativeHandler("process", |
| 1053 scoped_ptr<NativeHandler>(new ProcessInfoNativeHandler( | 1050 scoped_ptr<NativeHandler>(new ProcessInfoNativeHandler( |
| 1054 this, v8_context, context->GetExtensionID(), | 1051 this, context, context->GetExtensionID(), |
| 1055 context->GetContextTypeDescription(), | 1052 context->GetContextTypeDescription(), |
| 1056 ChromeRenderProcessObserver::is_incognito_process(), | 1053 ChromeRenderProcessObserver::is_incognito_process(), |
| 1057 manifest_version, send_request_disabled))); | 1054 manifest_version, send_request_disabled))); |
| 1058 | 1055 |
| 1059 GetOrCreateChrome(v8_context); | 1056 GetOrCreateChrome(v8_context); |
| 1060 | 1057 |
| 1061 // Loading JavaScript is expensive, so only run the full API bindings | 1058 // Loading JavaScript is expensive, so only run the full API bindings |
| 1062 // generation mechanisms in extension pages (NOT all web pages). | 1059 // generation mechanisms in extension pages (NOT all web pages). |
| 1063 switch (context_type) { | 1060 switch (context_type) { |
| 1064 case Feature::UNSPECIFIED_CONTEXT: | 1061 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()); | 1456 std::string error_msg = base::StringPrintf(kMessage, function_name.c_str()); |
| 1460 v8::ThrowException( | 1457 v8::ThrowException( |
| 1461 v8::Exception::Error(v8::String::New(error_msg.c_str()))); | 1458 v8::Exception::Error(v8::String::New(error_msg.c_str()))); |
| 1462 return false; | 1459 return false; |
| 1463 } | 1460 } |
| 1464 | 1461 |
| 1465 return true; | 1462 return true; |
| 1466 } | 1463 } |
| 1467 | 1464 |
| 1468 } // namespace extensions | 1465 } // namespace extensions |
| OLD | NEW |