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