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/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
10 #include "base/string_piece.h" | 10 #include "base/string_piece.h" |
11 #include "base/string_split.h" | |
11 #include "chrome/common/child_process_logging.h" | 12 #include "chrome/common/child_process_logging.h" |
12 #include "chrome/common/chrome_switches.h" | 13 #include "chrome/common/chrome_switches.h" |
13 #include "chrome/common/chrome_version_info.h" | 14 #include "chrome/common/chrome_version_info.h" |
14 #include "chrome/common/extensions/api/extension_api.h" | 15 #include "chrome/common/extensions/api/extension_api.h" |
15 #include "chrome/common/extensions/extension.h" | 16 #include "chrome/common/extensions/extension.h" |
16 #include "chrome/common/extensions/extension_messages.h" | 17 #include "chrome/common/extensions/extension_messages.h" |
18 #include "chrome/common/extensions/features/feature.h" | |
17 #include "chrome/common/extensions/manifest.h" | 19 #include "chrome/common/extensions/manifest.h" |
18 #include "chrome/common/extensions/permissions/permission_set.h" | 20 #include "chrome/common/extensions/permissions/permission_set.h" |
19 #include "chrome/common/url_constants.h" | 21 #include "chrome/common/url_constants.h" |
20 #include "chrome/common/view_type.h" | 22 #include "chrome/common/view_type.h" |
21 #include "chrome/renderer/chrome_render_process_observer.h" | 23 #include "chrome/renderer/chrome_render_process_observer.h" |
22 #include "chrome/renderer/extensions/api_definitions_natives.h" | 24 #include "chrome/renderer/extensions/api_definitions_natives.h" |
23 #include "chrome/renderer/extensions/app_bindings.h" | 25 #include "chrome/renderer/extensions/app_bindings.h" |
24 #include "chrome/renderer/extensions/app_runtime_custom_bindings.h" | 26 #include "chrome/renderer/extensions/app_runtime_custom_bindings.h" |
25 #include "chrome/renderer/extensions/app_window_custom_bindings.h" | 27 #include "chrome/renderer/extensions/app_window_custom_bindings.h" |
28 #include "chrome/renderer/extensions/binding_generating_native_handler.h" | |
26 #include "chrome/renderer/extensions/chrome_v8_context.h" | 29 #include "chrome/renderer/extensions/chrome_v8_context.h" |
27 #include "chrome/renderer/extensions/chrome_v8_extension.h" | 30 #include "chrome/renderer/extensions/chrome_v8_extension.h" |
28 #include "chrome/renderer/extensions/content_watcher.h" | 31 #include "chrome/renderer/extensions/content_watcher.h" |
29 #include "chrome/renderer/extensions/context_menus_custom_bindings.h" | 32 #include "chrome/renderer/extensions/context_menus_custom_bindings.h" |
30 #include "chrome/renderer/extensions/event_bindings.h" | 33 #include "chrome/renderer/extensions/event_bindings.h" |
31 #include "chrome/renderer/extensions/extension_custom_bindings.h" | 34 #include "chrome/renderer/extensions/extension_custom_bindings.h" |
32 #include "chrome/renderer/extensions/extension_groups.h" | 35 #include "chrome/renderer/extensions/extension_groups.h" |
33 #include "chrome/renderer/extensions/extension_helper.h" | 36 #include "chrome/renderer/extensions/extension_helper.h" |
34 #include "chrome/renderer/extensions/file_browser_handler_custom_bindings.h" | 37 #include "chrome/renderer/extensions/file_browser_handler_custom_bindings.h" |
35 #include "chrome/renderer/extensions/file_browser_private_custom_bindings.h" | 38 #include "chrome/renderer/extensions/file_browser_private_custom_bindings.h" |
36 #include "chrome/renderer/extensions/file_system_natives.h" | 39 #include "chrome/renderer/extensions/file_system_natives.h" |
37 #include "chrome/renderer/extensions/i18n_custom_bindings.h" | 40 #include "chrome/renderer/extensions/i18n_custom_bindings.h" |
38 #include "chrome/renderer/extensions/media_galleries_custom_bindings.h" | 41 #include "chrome/renderer/extensions/media_galleries_custom_bindings.h" |
39 #include "chrome/renderer/extensions/miscellaneous_bindings.h" | 42 #include "chrome/renderer/extensions/miscellaneous_bindings.h" |
40 #include "chrome/renderer/extensions/module_system.h" | 43 #include "chrome/renderer/extensions/module_system.h" |
41 #include "chrome/renderer/extensions/native_handler.h" | 44 #include "chrome/renderer/extensions/object_backed_native_handler.h" |
42 #include "chrome/renderer/extensions/page_actions_custom_bindings.h" | 45 #include "chrome/renderer/extensions/page_actions_custom_bindings.h" |
43 #include "chrome/renderer/extensions/page_capture_custom_bindings.h" | 46 #include "chrome/renderer/extensions/page_capture_custom_bindings.h" |
44 #include "chrome/renderer/extensions/request_sender.h" | 47 #include "chrome/renderer/extensions/request_sender.h" |
45 #include "chrome/renderer/extensions/runtime_custom_bindings.h" | 48 #include "chrome/renderer/extensions/runtime_custom_bindings.h" |
46 #include "chrome/renderer/extensions/send_request_natives.h" | 49 #include "chrome/renderer/extensions/send_request_natives.h" |
47 #include "chrome/renderer/extensions/set_icon_natives.h" | 50 #include "chrome/renderer/extensions/set_icon_natives.h" |
48 #include "chrome/renderer/extensions/sync_file_system_custom_bindings.h" | 51 #include "chrome/renderer/extensions/sync_file_system_custom_bindings.h" |
49 #include "chrome/renderer/extensions/tab_finder.h" | 52 #include "chrome/renderer/extensions/tab_finder.h" |
50 #include "chrome/renderer/extensions/tabs_custom_bindings.h" | 53 #include "chrome/renderer/extensions/tabs_custom_bindings.h" |
51 #include "chrome/renderer/extensions/tts_custom_bindings.h" | 54 #include "chrome/renderer/extensions/tts_custom_bindings.h" |
(...skipping 30 matching lines...) Expand all Loading... | |
82 namespace extensions { | 85 namespace extensions { |
83 | 86 |
84 namespace { | 87 namespace { |
85 | 88 |
86 static const int64 kInitialExtensionIdleHandlerDelayMs = 5*1000; | 89 static const int64 kInitialExtensionIdleHandlerDelayMs = 5*1000; |
87 static const int64 kMaxExtensionIdleHandlerDelayMs = 5*60*1000; | 90 static const int64 kMaxExtensionIdleHandlerDelayMs = 5*60*1000; |
88 static const char kEventDispatchFunction[] = "Event.dispatchEvent"; | 91 static const char kEventDispatchFunction[] = "Event.dispatchEvent"; |
89 static const char kOnSuspendEvent[] = "runtime.onSuspend"; | 92 static const char kOnSuspendEvent[] = "runtime.onSuspend"; |
90 static const char kOnSuspendCanceledEvent[] = "runtime.onSuspendCanceled"; | 93 static const char kOnSuspendCanceledEvent[] = "runtime.onSuspendCanceled"; |
91 | 94 |
92 class ChromeHiddenNativeHandler : public NativeHandler { | 95 static v8::Handle<v8::Object> GetOrCreateChrome( |
96 v8::Handle<v8::Context> context) { | |
97 v8::Handle<v8::String> chrome_string(v8::String::New("chrome")); | |
98 v8::Handle<v8::Object> global(context->Global()); | |
99 v8::Handle<v8::Value> chrome(global->Get(chrome_string)); | |
100 if (chrome.IsEmpty() || chrome->IsUndefined()) { | |
101 v8::Handle<v8::Object> chrome_object(v8::Object::New()); | |
102 global->Set(chrome_string, chrome_object); | |
103 return chrome_object; | |
104 } | |
105 CHECK(chrome->IsObject()); | |
106 return chrome->ToObject(); | |
107 } | |
108 | |
109 class SchemaRegistryNativeHandler : public ObjectBackedNativeHandler { | |
93 public: | 110 public: |
94 explicit ChromeHiddenNativeHandler(v8::Isolate* isolate) | 111 SchemaRegistryNativeHandler(V8SchemaRegistry* registry, |
95 : NativeHandler(isolate) { | 112 v8::Handle<v8::Context> context) |
113 : ObjectBackedNativeHandler(context), | |
114 registry_(registry) { | |
115 RouteFunction("GetSchema", | |
116 base::Bind(&SchemaRegistryNativeHandler::GetSchema, | |
117 base::Unretained(this))); | |
118 } | |
119 | |
120 private: | |
121 v8::Handle<v8::Value> GetSchema(const v8::Arguments& args) { | |
122 return registry_->GetSchema(*v8::String::AsciiValue(args[0])); | |
123 } | |
124 | |
125 V8SchemaRegistry* registry_; | |
126 }; | |
127 | |
128 class V8ContextNativeHandler : public ObjectBackedNativeHandler { | |
129 public: | |
130 explicit V8ContextNativeHandler(ChromeV8Context* context) | |
131 : ObjectBackedNativeHandler(context->v8_context()), | |
132 context_(context) { | |
133 RouteFunction("GetAvailability", | |
134 base::Bind(&V8ContextNativeHandler::GetAvailability, | |
135 base::Unretained(this))); | |
136 } | |
137 | |
138 private: | |
139 v8::Handle<v8::Value> GetAvailability(const v8::Arguments& args) { | |
140 CHECK_EQ(args.Length(), 1); | |
141 std::string api_name = *v8::String::AsciiValue(args[0]->ToString()); | |
142 Feature::Availability availability = context_->GetAvailability(api_name); | |
143 | |
144 v8::Handle<v8::Object> ret = v8::Object::New(); | |
145 ret->Set(v8::String::New("is_available"), | |
146 v8::Boolean::New(availability.is_available())); | |
147 ret->Set(v8::String::New("message"), | |
148 v8::String::New(availability.message().c_str())); | |
149 return ret; | |
150 } | |
151 | |
152 ChromeV8Context* context_; | |
153 }; | |
154 | |
155 class ChromeHiddenNativeHandler : public ObjectBackedNativeHandler { | |
156 public: | |
157 explicit ChromeHiddenNativeHandler(v8::Handle<v8::Context> context) | |
158 : ObjectBackedNativeHandler(context) { | |
96 RouteFunction("GetChromeHidden", | 159 RouteFunction("GetChromeHidden", |
97 base::Bind(&ChromeHiddenNativeHandler::GetChromeHidden, | 160 base::Bind(&ChromeHiddenNativeHandler::GetChromeHidden, |
98 base::Unretained(this))); | 161 base::Unretained(this))); |
99 } | 162 } |
100 | 163 |
101 v8::Handle<v8::Value> GetChromeHidden(const v8::Arguments& args) { | 164 v8::Handle<v8::Value> GetChromeHidden(const v8::Arguments& args) { |
102 return ChromeV8Context::GetOrCreateChromeHidden(v8::Context::GetCurrent()); | 165 return ChromeV8Context::GetOrCreateChromeHidden(v8_context()); |
103 } | 166 } |
104 }; | 167 }; |
105 | 168 |
106 class PrintNativeHandler : public NativeHandler { | 169 class ChromeNativeHandler : public ObjectBackedNativeHandler { |
107 public: | 170 public: |
108 explicit PrintNativeHandler(v8::Isolate* isolate) | 171 explicit ChromeNativeHandler(v8::Handle<v8::Context> context) |
109 : NativeHandler(isolate) { | 172 : ObjectBackedNativeHandler(context) { |
173 RouteFunction("GetChrome", | |
174 base::Bind(&ChromeNativeHandler::GetChrome, base::Unretained(this))); | |
175 } | |
176 | |
177 v8::Handle<v8::Value> GetChrome(const v8::Arguments& args) { | |
178 return GetOrCreateChrome(v8_context()); | |
179 } | |
180 }; | |
181 | |
182 class PrintNativeHandler : public ObjectBackedNativeHandler { | |
183 public: | |
184 explicit PrintNativeHandler(v8::Handle<v8::Context> context) | |
185 : ObjectBackedNativeHandler(context) { | |
110 RouteFunction("Print", | 186 RouteFunction("Print", |
111 base::Bind(&PrintNativeHandler::Print, | 187 base::Bind(&PrintNativeHandler::Print, |
112 base::Unretained(this))); | 188 base::Unretained(this))); |
113 } | 189 } |
114 | 190 |
115 v8::Handle<v8::Value> Print(const v8::Arguments& args) { | 191 v8::Handle<v8::Value> Print(const v8::Arguments& args) { |
116 if (args.Length() < 1) | 192 if (args.Length() < 1) |
117 return v8::Undefined(); | 193 return v8::Undefined(); |
118 | 194 |
119 std::vector<std::string> components; | 195 std::vector<std::string> components; |
(...skipping 11 matching lines...) Expand all Loading... | |
131 : ChromeV8Extension(dispatcher) { | 207 : ChromeV8Extension(dispatcher) { |
132 RouteFunction("IncrementKeepaliveCount", | 208 RouteFunction("IncrementKeepaliveCount", |
133 base::Bind(&LazyBackgroundPageNativeHandler::IncrementKeepaliveCount, | 209 base::Bind(&LazyBackgroundPageNativeHandler::IncrementKeepaliveCount, |
134 base::Unretained(this))); | 210 base::Unretained(this))); |
135 RouteFunction("DecrementKeepaliveCount", | 211 RouteFunction("DecrementKeepaliveCount", |
136 base::Bind(&LazyBackgroundPageNativeHandler::DecrementKeepaliveCount, | 212 base::Bind(&LazyBackgroundPageNativeHandler::DecrementKeepaliveCount, |
137 base::Unretained(this))); | 213 base::Unretained(this))); |
138 } | 214 } |
139 | 215 |
140 v8::Handle<v8::Value> IncrementKeepaliveCount(const v8::Arguments& args) { | 216 v8::Handle<v8::Value> IncrementKeepaliveCount(const v8::Arguments& args) { |
141 ChromeV8Context* context = dispatcher()->v8_context_set().GetCurrent(); | 217 ChromeV8Context* context = |
218 dispatcher()->v8_context_set().GetByV8Context(v8_context()); | |
142 if (!context) | 219 if (!context) |
143 return v8::Undefined(); | 220 return v8::Undefined(); |
144 RenderView* render_view = context->GetRenderView(); | 221 RenderView* render_view = context->GetRenderView(); |
145 if (IsContextLazyBackgroundPage(render_view, context->extension())) { | 222 if (IsContextLazyBackgroundPage(render_view, context->extension())) { |
146 render_view->Send(new ExtensionHostMsg_IncrementLazyKeepaliveCount( | 223 render_view->Send(new ExtensionHostMsg_IncrementLazyKeepaliveCount( |
147 render_view->GetRoutingID())); | 224 render_view->GetRoutingID())); |
148 } | 225 } |
149 return v8::Undefined(); | 226 return v8::Undefined(); |
150 } | 227 } |
151 | 228 |
152 v8::Handle<v8::Value> DecrementKeepaliveCount(const v8::Arguments& args) { | 229 v8::Handle<v8::Value> DecrementKeepaliveCount(const v8::Arguments& args) { |
153 ChromeV8Context* context = dispatcher()->v8_context_set().GetCurrent(); | 230 ChromeV8Context* context = |
231 dispatcher()->v8_context_set().GetByV8Context(v8_context()); | |
154 if (!context) | 232 if (!context) |
155 return v8::Undefined(); | 233 return v8::Undefined(); |
156 RenderView* render_view = context->GetRenderView(); | 234 RenderView* render_view = context->GetRenderView(); |
157 if (IsContextLazyBackgroundPage(render_view, context->extension())) { | 235 if (IsContextLazyBackgroundPage(render_view, context->extension())) { |
158 render_view->Send(new ExtensionHostMsg_DecrementLazyKeepaliveCount( | 236 render_view->Send(new ExtensionHostMsg_DecrementLazyKeepaliveCount( |
159 render_view->GetRoutingID())); | 237 render_view->GetRoutingID())); |
160 } | 238 } |
161 return v8::Undefined(); | 239 return v8::Undefined(); |
162 } | 240 } |
163 | 241 |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
231 } | 309 } |
232 | 310 |
233 private: | 311 private: |
234 std::string extension_id_; | 312 std::string extension_id_; |
235 std::string context_type_; | 313 std::string context_type_; |
236 bool is_incognito_context_; | 314 bool is_incognito_context_; |
237 int manifest_version_; | 315 int manifest_version_; |
238 bool send_request_disabled_; | 316 bool send_request_disabled_; |
239 }; | 317 }; |
240 | 318 |
241 class LoggingNativeHandler : public NativeHandler { | 319 class LoggingNativeHandler : public ObjectBackedNativeHandler { |
242 public: | 320 public: |
243 explicit LoggingNativeHandler(v8::Isolate* isolate) | 321 explicit LoggingNativeHandler(v8::Handle<v8::Context> context) |
244 : NativeHandler(isolate) { | 322 : ObjectBackedNativeHandler(context) { |
245 RouteFunction("DCHECK", | 323 RouteFunction("DCHECK", |
246 base::Bind(&LoggingNativeHandler::Dcheck, | 324 base::Bind(&LoggingNativeHandler::Dcheck, base::Unretained(this))); |
247 base::Unretained(this))); | |
248 } | 325 } |
249 | 326 |
250 v8::Handle<v8::Value> Dcheck(const v8::Arguments& args) { | 327 v8::Handle<v8::Value> Dcheck(const v8::Arguments& args) { |
251 CHECK_LE(args.Length(), 2); | 328 CHECK_LE(args.Length(), 2); |
252 bool check_value = args[0]->BooleanValue(); | 329 bool check_value = args[0]->BooleanValue(); |
253 std::string error_message; | 330 std::string error_message; |
254 if (args.Length() == 2) | 331 if (args.Length() == 2) |
255 error_message = "Error: " + std::string(*v8::String::AsciiValue(args[1])); | 332 error_message = "Error: " + std::string(*v8::String::AsciiValue(args[1])); |
256 | 333 |
257 v8::Handle<v8::StackTrace> stack_trace = | 334 v8::Handle<v8::StackTrace> stack_trace = |
258 v8::StackTrace::CurrentStackTrace(10); | 335 v8::StackTrace::CurrentStackTrace(10); |
259 if (stack_trace.IsEmpty() || stack_trace->GetFrameCount() <= 0) { | 336 if (stack_trace.IsEmpty() || stack_trace->GetFrameCount() <= 0) { |
260 error_message += "\n <no stack trace>"; | 337 error_message += "\n <no stack trace>"; |
261 } else { | 338 } else { |
262 for (size_t i = 0; i < (size_t) stack_trace->GetFrameCount(); ++i) { | 339 for (size_t i = 0; i < (size_t) stack_trace->GetFrameCount(); ++i) { |
263 v8::Handle<v8::StackFrame> frame = stack_trace->GetFrame(i); | 340 v8::Handle<v8::StackFrame> frame = stack_trace->GetFrame(i); |
264 CHECK(!frame.IsEmpty()); | 341 CHECK(!frame.IsEmpty()); |
265 error_message += base::StringPrintf("\n at %s (%s:%d:%d)", | 342 error_message += base::StringPrintf("\n at %s (%s:%d:%d)", |
266 ToStringOrDefault(frame->GetFunctionName(), "<anonymous>").c_str(), | 343 ToStringOrDefault(frame->GetFunctionName(), "<anonymous>").c_str(), |
267 ToStringOrDefault(frame->GetScriptName(), "<anonymous>").c_str(), | 344 ToStringOrDefault(frame->GetScriptName(), "<anonymous>").c_str(), |
268 frame->GetLineNumber(), | 345 frame->GetLineNumber(), |
269 frame->GetColumn()); | 346 frame->GetColumn()); |
270 } | 347 } |
271 } | 348 } |
272 DCHECK(check_value) << error_message; | 349 DCHECK(check_value) << error_message; |
273 LOG(WARNING) << error_message; | |
274 return v8::Undefined(); | 350 return v8::Undefined(); |
275 } | 351 } |
276 | 352 |
277 private: | 353 private: |
278 std::string ToStringOrDefault(const v8::Handle<v8::String>& v8_string, | 354 std::string ToStringOrDefault(const v8::Handle<v8::String>& v8_string, |
279 const std::string& dflt) { | 355 const std::string& dflt) { |
280 if (v8_string.IsEmpty()) | 356 if (v8_string.IsEmpty()) |
281 return dflt; | 357 return dflt; |
282 std::string ascii_value = *v8::String::AsciiValue(v8_string); | 358 std::string ascii_value = *v8::String::AsciiValue(v8_string); |
283 return ascii_value.empty() ? dflt : ascii_value; | 359 return ascii_value.empty() ? dflt : ascii_value; |
(...skipping 11 matching lines...) Expand all Loading... | |
295 } | 371 } |
296 | 372 |
297 void InstallWebstoreBindings(ModuleSystem* module_system, | 373 void InstallWebstoreBindings(ModuleSystem* module_system, |
298 v8::Handle<v8::Object> chrome, | 374 v8::Handle<v8::Object> chrome, |
299 v8::Handle<v8::Object> chrome_hidden) { | 375 v8::Handle<v8::Object> chrome_hidden) { |
300 module_system->SetLazyField(chrome, "webstore", "webstore", "chromeWebstore"); | 376 module_system->SetLazyField(chrome, "webstore", "webstore", "chromeWebstore"); |
301 module_system->SetLazyField(chrome_hidden, "webstore", "webstore", | 377 module_system->SetLazyField(chrome_hidden, "webstore", "webstore", |
302 "chromeHiddenWebstore"); | 378 "chromeHiddenWebstore"); |
303 } | 379 } |
304 | 380 |
305 static v8::Handle<v8::Object> GetOrCreateChrome( | |
306 v8::Handle<v8::Context> context) { | |
307 v8::Handle<v8::String> chrome_string(v8::String::New("chrome")); | |
308 v8::Handle<v8::Object> global(context->Global()); | |
309 v8::Handle<v8::Value> chrome(global->Get(chrome_string)); | |
310 if (chrome.IsEmpty() || chrome->IsUndefined()) { | |
311 v8::Handle<v8::Object> chrome_object(v8::Object::New()); | |
312 global->Set(chrome_string, chrome_object); | |
313 return chrome_object; | |
314 } | |
315 CHECK(chrome->IsObject()); | |
316 return chrome->ToObject(); | |
317 } | |
318 | |
319 } // namespace | 381 } // namespace |
320 | 382 |
321 Dispatcher::Dispatcher() | 383 Dispatcher::Dispatcher() |
322 : content_watcher_(new ContentWatcher(this)), | 384 : content_watcher_(new ContentWatcher(this)), |
323 is_webkit_initialized_(false), | 385 is_webkit_initialized_(false), |
324 webrequest_adblock_(false), | 386 webrequest_adblock_(false), |
325 webrequest_adblock_plus_(false), | 387 webrequest_adblock_plus_(false), |
326 webrequest_other_(false), | 388 webrequest_other_(false), |
327 source_map_(&ResourceBundle::GetSharedInstance()) { | 389 source_map_(&ResourceBundle::GetSharedInstance()) { |
328 const CommandLine& command_line = *(CommandLine::ForCurrentProcess()); | 390 const CommandLine& command_line = *(CommandLine::ForCurrentProcess()); |
329 is_extension_process_ = | 391 is_extension_process_ = |
330 command_line.HasSwitch(switches::kExtensionProcess) || | 392 command_line.HasSwitch(switches::kExtensionProcess) || |
331 command_line.HasSwitch(switches::kSingleProcess); | 393 command_line.HasSwitch(switches::kSingleProcess); |
332 | 394 |
333 if (is_extension_process_) { | 395 if (is_extension_process_) { |
334 RenderThread::Get()->SetIdleNotificationDelayInMs( | 396 RenderThread::Get()->SetIdleNotificationDelayInMs( |
335 kInitialExtensionIdleHandlerDelayMs); | 397 kInitialExtensionIdleHandlerDelayMs); |
336 } | 398 } |
337 | 399 |
338 user_script_slave_.reset(new UserScriptSlave(&extensions_)); | 400 user_script_slave_.reset(new UserScriptSlave(&extensions_)); |
339 request_sender_.reset(new RequestSender(this, &v8_context_set_)); | 401 request_sender_.reset(new RequestSender(this)); |
340 PopulateSourceMap(); | 402 PopulateSourceMap(); |
341 PopulateLazyBindingsMap(); | 403 PopulateLazyBindingsMap(); |
342 } | 404 } |
343 | 405 |
344 Dispatcher::~Dispatcher() { | 406 Dispatcher::~Dispatcher() { |
345 } | 407 } |
346 | 408 |
347 bool Dispatcher::OnControlMessageReceived(const IPC::Message& message) { | 409 bool Dispatcher::OnControlMessageReceived(const IPC::Message& message) { |
348 bool handled = true; | 410 bool handled = true; |
349 IPC_BEGIN_MESSAGE_MAP(Dispatcher, message) | 411 IPC_BEGIN_MESSAGE_MAP(Dispatcher, message) |
(...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
553 } // namespace | 615 } // namespace |
554 | 616 |
555 bool Dispatcher::AllowScriptExtension(WebFrame* frame, | 617 bool Dispatcher::AllowScriptExtension(WebFrame* frame, |
556 const std::string& v8_extension_name, | 618 const std::string& v8_extension_name, |
557 int extension_group, | 619 int extension_group, |
558 int world_id) { | 620 int world_id) { |
559 g_hack_extension_group = extension_group; | 621 g_hack_extension_group = extension_group; |
560 return true; | 622 return true; |
561 } | 623 } |
562 | 624 |
625 v8::Handle<v8::Object> Dispatcher::GetOrCreateObject( | |
626 v8::Handle<v8::Object> object, | |
627 const std::string& field) { | |
628 v8::HandleScope handle_scope; | |
629 v8::Handle<v8::String> key = v8::String::New(field.c_str()); | |
630 // This little dance is for APIs that may be unavailable but have available | |
631 // children. For example, chrome.app can be unavailable, while | |
632 // chrome.app.runtime is available. The lazy getter for chrome.app must be | |
633 // deleted, so that there isn't an error when accessing chrome.app.runtime. | |
634 if (object->Has(key)) { | |
635 v8::Handle<v8::Value> value = object->Get(key); | |
636 if (!value->IsUndefined() && value->IsObject()) | |
not at google - send to devlin
2013/03/01 00:36:06
I think that IsObject implies !undefined so the fi
cduvall
2013/03/01 00:43:52
Done.
| |
637 return handle_scope.Close(v8::Handle<v8::Object>::Cast(value)); | |
638 else | |
639 object->Delete(key); | |
640 } | |
641 | |
642 v8::Handle<v8::Object> new_object = v8::Object::New(); | |
643 object->Set(key, new_object); | |
644 return handle_scope.Close(new_object); | |
645 } | |
646 | |
647 void Dispatcher::RegisterSchemaGeneratedBindings( | |
648 ModuleSystem* module_system, | |
649 ChromeV8Context* context, | |
650 v8::Handle<v8::Context> v8_context) { | |
651 std::set<std::string> apis = | |
652 ExtensionAPI::GetSharedInstance()->GetAllAPINames(); | |
653 for (std::set<std::string>::iterator it = apis.begin(); | |
654 it != apis.end(); ++it) { | |
655 const std::string& api_name = *it; | |
656 | |
657 std::vector<std::string> split; | |
658 base::SplitString(api_name, '.', &split); | |
659 | |
660 v8::Handle<v8::Object> bind_object = GetOrCreateChrome(v8_context); | |
661 for (size_t i = 0; i < split.size() - 1; ++i) | |
662 bind_object = GetOrCreateObject(bind_object, split[i]); | |
663 | |
664 if (lazy_bindings_map_.find(api_name) != lazy_bindings_map_.end()) { | |
665 InstallBindings(module_system, v8_context, api_name); | |
666 } else if (!source_map_.Contains(api_name)) { | |
667 module_system->RegisterNativeHandler( | |
668 api_name, | |
669 scoped_ptr<NativeHandler>(new BindingGeneratingNativeHandler( | |
670 module_system, | |
671 api_name, | |
672 "binding"))); | |
673 module_system->SetNativeLazyField(bind_object, | |
674 split.back(), | |
675 api_name, | |
676 "binding"); | |
677 } else { | |
678 module_system->SetLazyField(bind_object, | |
679 split.back(), | |
680 api_name, | |
681 "binding"); | |
682 } | |
683 } | |
684 } | |
685 | |
563 void Dispatcher::RegisterNativeHandlers(ModuleSystem* module_system, | 686 void Dispatcher::RegisterNativeHandlers(ModuleSystem* module_system, |
564 ChromeV8Context* context) { | 687 ChromeV8Context* context) { |
565 module_system->RegisterNativeHandler("event_bindings", | 688 module_system->RegisterNativeHandler("event_bindings", |
566 scoped_ptr<NativeHandler>(EventBindings::Get(this))); | 689 scoped_ptr<NativeHandler>( |
690 EventBindings::Create(this, context->v8_context()))); | |
567 module_system->RegisterNativeHandler("miscellaneous_bindings", | 691 module_system->RegisterNativeHandler("miscellaneous_bindings", |
568 scoped_ptr<NativeHandler>(MiscellaneousBindings::Get(this))); | 692 scoped_ptr<NativeHandler>( |
693 MiscellaneousBindings::Get(this, context->v8_context()))); | |
569 module_system->RegisterNativeHandler("apiDefinitions", | 694 module_system->RegisterNativeHandler("apiDefinitions", |
570 scoped_ptr<NativeHandler>(new ApiDefinitionsNatives(this))); | 695 scoped_ptr<NativeHandler>(new ApiDefinitionsNatives(this, context))); |
571 module_system->RegisterNativeHandler("sendRequest", | 696 module_system->RegisterNativeHandler("sendRequest", |
572 scoped_ptr<NativeHandler>( | 697 scoped_ptr<NativeHandler>( |
573 new SendRequestNatives(this, request_sender_.get()))); | 698 new SendRequestNatives(this, request_sender_.get(), context))); |
574 module_system->RegisterNativeHandler("setIcon", | 699 module_system->RegisterNativeHandler("setIcon", |
575 scoped_ptr<NativeHandler>( | 700 scoped_ptr<NativeHandler>( |
576 new SetIconNatives(this, request_sender_.get()))); | 701 new SetIconNatives(this, request_sender_.get(), context))); |
577 module_system->RegisterNativeHandler("contentWatcherNative", | 702 module_system->RegisterNativeHandler("contentWatcherNative", |
578 content_watcher_->MakeNatives()); | 703 content_watcher_->MakeNatives()); |
579 | 704 |
580 // Natives used by multiple APIs. | 705 // Natives used by multiple APIs. |
581 module_system->RegisterNativeHandler("file_system_natives", | 706 module_system->RegisterNativeHandler("file_system_natives", |
582 scoped_ptr<NativeHandler>(new FileSystemNatives())); | 707 scoped_ptr<NativeHandler>(new FileSystemNatives(context->v8_context()))); |
583 | 708 |
584 // Custom bindings. | 709 // Custom bindings. |
585 module_system->RegisterNativeHandler("app", | 710 module_system->RegisterNativeHandler("app", |
586 scoped_ptr<NativeHandler>(new AppBindings(this, context))); | 711 scoped_ptr<NativeHandler>(new AppBindings(this, context))); |
587 module_system->RegisterNativeHandler("app_runtime", | 712 module_system->RegisterNativeHandler("app_runtime", |
588 scoped_ptr<NativeHandler>(new AppRuntimeCustomBindings())); | 713 scoped_ptr<NativeHandler>( |
714 new AppRuntimeCustomBindings(this, context->v8_context()))); | |
589 module_system->RegisterNativeHandler("app_window", | 715 module_system->RegisterNativeHandler("app_window", |
590 scoped_ptr<NativeHandler>(new AppWindowCustomBindings(this))); | 716 scoped_ptr<NativeHandler>( |
717 new AppWindowCustomBindings(this, context->v8_context()))); | |
591 module_system->RegisterNativeHandler("context_menus", | 718 module_system->RegisterNativeHandler("context_menus", |
592 scoped_ptr<NativeHandler>(new ContextMenusCustomBindings())); | 719 scoped_ptr<NativeHandler>(new ContextMenusCustomBindings())); |
593 module_system->RegisterNativeHandler("extension", | 720 module_system->RegisterNativeHandler("extension", |
594 scoped_ptr<NativeHandler>( | 721 scoped_ptr<NativeHandler>( |
595 new ExtensionCustomBindings(this))); | 722 new ExtensionCustomBindings(this, context->v8_context()))); |
596 module_system->RegisterNativeHandler("sync_file_system", | 723 module_system->RegisterNativeHandler("sync_file_system", |
597 scoped_ptr<NativeHandler>(new SyncFileSystemCustomBindings())); | 724 scoped_ptr<NativeHandler>(new SyncFileSystemCustomBindings())); |
598 module_system->RegisterNativeHandler("file_browser_handler", | 725 module_system->RegisterNativeHandler("file_browser_handler", |
599 scoped_ptr<NativeHandler>(new FileBrowserHandlerCustomBindings())); | 726 scoped_ptr<NativeHandler>(new FileBrowserHandlerCustomBindings( |
727 context->v8_context()))); | |
600 module_system->RegisterNativeHandler("file_browser_private", | 728 module_system->RegisterNativeHandler("file_browser_private", |
601 scoped_ptr<NativeHandler>(new FileBrowserPrivateCustomBindings())); | 729 scoped_ptr<NativeHandler>(new FileBrowserPrivateCustomBindings( |
730 context->v8_context()))); | |
602 module_system->RegisterNativeHandler("i18n", | 731 module_system->RegisterNativeHandler("i18n", |
603 scoped_ptr<NativeHandler>(new I18NCustomBindings())); | 732 scoped_ptr<NativeHandler>( |
733 new I18NCustomBindings(this, context->v8_context()))); | |
604 module_system->RegisterNativeHandler("mediaGalleries", | 734 module_system->RegisterNativeHandler("mediaGalleries", |
605 scoped_ptr<NativeHandler>(new MediaGalleriesCustomBindings())); | 735 scoped_ptr<NativeHandler>(new MediaGalleriesCustomBindings())); |
606 module_system->RegisterNativeHandler("page_actions", | 736 module_system->RegisterNativeHandler("page_actions", |
607 scoped_ptr<NativeHandler>( | 737 scoped_ptr<NativeHandler>( |
608 new PageActionsCustomBindings(this))); | 738 new PageActionsCustomBindings(this))); |
609 module_system->RegisterNativeHandler("page_capture", | 739 module_system->RegisterNativeHandler("page_capture", |
610 scoped_ptr<NativeHandler>(new PageCaptureCustomBindings())); | 740 scoped_ptr<NativeHandler>( |
741 new PageCaptureCustomBindings(this, context->v8_context()))); | |
611 module_system->RegisterNativeHandler("runtime", | 742 module_system->RegisterNativeHandler("runtime", |
612 scoped_ptr<NativeHandler>(new RuntimeCustomBindings(context))); | 743 scoped_ptr<NativeHandler>(new RuntimeCustomBindings(this, context))); |
613 module_system->RegisterNativeHandler("tabs", | 744 module_system->RegisterNativeHandler("tabs", |
614 scoped_ptr<NativeHandler>(new TabsCustomBindings())); | 745 scoped_ptr<NativeHandler>( |
746 new TabsCustomBindings(this, context->v8_context()))); | |
615 module_system->RegisterNativeHandler("tts", | 747 module_system->RegisterNativeHandler("tts", |
616 scoped_ptr<NativeHandler>(new TTSCustomBindings())); | 748 scoped_ptr<NativeHandler>(new TTSCustomBindings())); |
617 module_system->RegisterNativeHandler("web_request", | 749 module_system->RegisterNativeHandler("web_request", |
618 scoped_ptr<NativeHandler>(new WebRequestCustomBindings())); | 750 scoped_ptr<NativeHandler>(new WebRequestCustomBindings())); |
619 module_system->RegisterNativeHandler("webstore", | 751 module_system->RegisterNativeHandler("webstore", |
620 scoped_ptr<NativeHandler>(new WebstoreBindings(this, context))); | 752 scoped_ptr<NativeHandler>(new WebstoreBindings(this, context))); |
621 } | 753 } |
622 | 754 |
623 void Dispatcher::PopulateSourceMap() { | 755 void Dispatcher::PopulateSourceMap() { |
624 source_map_.RegisterSource("event_bindings", IDR_EVENT_BINDINGS_JS); | 756 source_map_.RegisterSource("event_bindings", IDR_EVENT_BINDINGS_JS); |
625 source_map_.RegisterSource("miscellaneous_bindings", | 757 source_map_.RegisterSource("miscellaneous_bindings", |
626 IDR_MISCELLANEOUS_BINDINGS_JS); | 758 IDR_MISCELLANEOUS_BINDINGS_JS); |
627 source_map_.RegisterSource("schema_generated_bindings", | |
628 IDR_SCHEMA_GENERATED_BINDINGS_JS); | |
629 source_map_.RegisterSource("json", IDR_JSON_JS); | 759 source_map_.RegisterSource("json", IDR_JSON_JS); |
630 source_map_.RegisterSource("json_schema", IDR_JSON_SCHEMA_JS); | 760 source_map_.RegisterSource("json_schema", IDR_JSON_SCHEMA_JS); |
631 source_map_.RegisterSource("apitest", IDR_EXTENSION_APITEST_JS); | 761 source_map_.RegisterSource("test", IDR_TEST_CUSTOM_BINDINGS_JS); |
632 | 762 |
633 // Libraries. | 763 // Libraries. |
634 source_map_.RegisterSource("contentWatcher", IDR_CONTENT_WATCHER_JS); | 764 source_map_.RegisterSource("contentWatcher", IDR_CONTENT_WATCHER_JS); |
635 source_map_.RegisterSource("imageUtil", IDR_IMAGE_UTIL_JS); | 765 source_map_.RegisterSource("imageUtil", IDR_IMAGE_UTIL_JS); |
636 source_map_.RegisterSource("lastError", IDR_LAST_ERROR_JS); | 766 source_map_.RegisterSource("lastError", IDR_LAST_ERROR_JS); |
637 source_map_.RegisterSource("schemaUtils", IDR_SCHEMA_UTILS_JS); | 767 source_map_.RegisterSource("schemaUtils", IDR_SCHEMA_UTILS_JS); |
638 source_map_.RegisterSource("sendRequest", IDR_SEND_REQUEST_JS); | 768 source_map_.RegisterSource("sendRequest", IDR_SEND_REQUEST_JS); |
639 source_map_.RegisterSource("setIcon", IDR_SET_ICON_JS); | 769 source_map_.RegisterSource("setIcon", IDR_SET_ICON_JS); |
640 source_map_.RegisterSource("utils", IDR_UTILS_JS); | 770 source_map_.RegisterSource("utils", IDR_UTILS_JS); |
641 source_map_.RegisterSource("entryIdManager", IDR_ENTRY_ID_MANAGER); | 771 source_map_.RegisterSource("entryIdManager", IDR_ENTRY_ID_MANAGER); |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
688 IDR_SYSTEM_INDICATOR_CUSTOM_BINDINGS_JS); | 818 IDR_SYSTEM_INDICATOR_CUSTOM_BINDINGS_JS); |
689 source_map_.RegisterSource("tabCapture", IDR_TAB_CAPTURE_CUSTOM_BINDINGS_JS); | 819 source_map_.RegisterSource("tabCapture", IDR_TAB_CAPTURE_CUSTOM_BINDINGS_JS); |
690 source_map_.RegisterSource("tabs", IDR_TABS_CUSTOM_BINDINGS_JS); | 820 source_map_.RegisterSource("tabs", IDR_TABS_CUSTOM_BINDINGS_JS); |
691 source_map_.RegisterSource("tts", IDR_TTS_CUSTOM_BINDINGS_JS); | 821 source_map_.RegisterSource("tts", IDR_TTS_CUSTOM_BINDINGS_JS); |
692 source_map_.RegisterSource("ttsEngine", IDR_TTS_ENGINE_CUSTOM_BINDINGS_JS); | 822 source_map_.RegisterSource("ttsEngine", IDR_TTS_ENGINE_CUSTOM_BINDINGS_JS); |
693 source_map_.RegisterSource("types", IDR_TYPES_CUSTOM_BINDINGS_JS); | 823 source_map_.RegisterSource("types", IDR_TYPES_CUSTOM_BINDINGS_JS); |
694 source_map_.RegisterSource("webRequest", IDR_WEB_REQUEST_CUSTOM_BINDINGS_JS); | 824 source_map_.RegisterSource("webRequest", IDR_WEB_REQUEST_CUSTOM_BINDINGS_JS); |
695 source_map_.RegisterSource("webRequestInternal", | 825 source_map_.RegisterSource("webRequestInternal", |
696 IDR_WEB_REQUEST_INTERNAL_CUSTOM_BINDINGS_JS); | 826 IDR_WEB_REQUEST_INTERNAL_CUSTOM_BINDINGS_JS); |
697 source_map_.RegisterSource("webstore", IDR_WEBSTORE_CUSTOM_BINDINGS_JS); | 827 source_map_.RegisterSource("webstore", IDR_WEBSTORE_CUSTOM_BINDINGS_JS); |
828 source_map_.RegisterSource("binding", IDR_BINDING_JS); | |
698 | 829 |
699 // Platform app sources that are not API-specific.. | 830 // Platform app sources that are not API-specific.. |
700 source_map_.RegisterSource("tagWatcher", IDR_TAG_WATCHER_JS); | 831 source_map_.RegisterSource("tagWatcher", IDR_TAG_WATCHER_JS); |
701 source_map_.RegisterSource("webview", IDR_WEB_VIEW_JS); | 832 source_map_.RegisterSource("web_view", IDR_WEB_VIEW_JS); |
702 source_map_.RegisterSource("denyWebview", IDR_WEB_VIEW_DENY_JS); | 833 source_map_.RegisterSource("denyWebview", IDR_WEB_VIEW_DENY_JS); |
703 source_map_.RegisterSource("platformApp", IDR_PLATFORM_APP_JS); | 834 source_map_.RegisterSource("platformApp", IDR_PLATFORM_APP_JS); |
704 source_map_.RegisterSource("injectAppTitlebar", IDR_INJECT_APP_TITLEBAR_JS); | 835 source_map_.RegisterSource("injectAppTitlebar", IDR_INJECT_APP_TITLEBAR_JS); |
705 } | 836 } |
706 | 837 |
707 void Dispatcher::PopulateLazyBindingsMap() { | 838 void Dispatcher::PopulateLazyBindingsMap() { |
708 lazy_bindings_map_["app"] = InstallAppBindings; | 839 lazy_bindings_map_["app"] = InstallAppBindings; |
709 lazy_bindings_map_["webstore"] = InstallWebstoreBindings; | 840 lazy_bindings_map_["webstore"] = InstallWebstoreBindings; |
710 } | 841 } |
711 | 842 |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
764 new ChromeV8Context(v8_context, frame, extension, context_type); | 895 new ChromeV8Context(v8_context, frame, extension, context_type); |
765 v8_context_set_.Add(context); | 896 v8_context_set_.Add(context); |
766 | 897 |
767 scoped_ptr<ModuleSystem> module_system(new ModuleSystem(v8_context, | 898 scoped_ptr<ModuleSystem> module_system(new ModuleSystem(v8_context, |
768 &source_map_)); | 899 &source_map_)); |
769 // Enable natives in startup. | 900 // Enable natives in startup. |
770 ModuleSystem::NativesEnabledScope natives_enabled_scope(module_system.get()); | 901 ModuleSystem::NativesEnabledScope natives_enabled_scope(module_system.get()); |
771 | 902 |
772 RegisterNativeHandlers(module_system.get(), context); | 903 RegisterNativeHandlers(module_system.get(), context); |
773 | 904 |
774 v8::Isolate* isolate = v8_context->GetIsolate(); | 905 module_system->RegisterNativeHandler("chrome", |
906 scoped_ptr<NativeHandler>(new ChromeNativeHandler(v8_context))); | |
775 module_system->RegisterNativeHandler("chrome_hidden", | 907 module_system->RegisterNativeHandler("chrome_hidden", |
776 scoped_ptr<NativeHandler>(new ChromeHiddenNativeHandler(isolate))); | 908 scoped_ptr<NativeHandler>(new ChromeHiddenNativeHandler(v8_context))); |
777 module_system->RegisterNativeHandler("print", | 909 module_system->RegisterNativeHandler("print", |
778 scoped_ptr<NativeHandler>(new PrintNativeHandler(isolate))); | 910 scoped_ptr<NativeHandler>(new PrintNativeHandler(v8_context))); |
779 module_system->RegisterNativeHandler("lazy_background_page", | 911 module_system->RegisterNativeHandler("lazy_background_page", |
780 scoped_ptr<NativeHandler>(new LazyBackgroundPageNativeHandler(this))); | 912 scoped_ptr<NativeHandler>(new LazyBackgroundPageNativeHandler(this))); |
781 module_system->RegisterNativeHandler("logging", | 913 module_system->RegisterNativeHandler("logging", |
782 scoped_ptr<NativeHandler>(new LoggingNativeHandler(isolate))); | 914 scoped_ptr<NativeHandler>(new LoggingNativeHandler(v8_context))); |
915 module_system->RegisterNativeHandler("schema_registry", | |
916 scoped_ptr<NativeHandler>( | |
917 new SchemaRegistryNativeHandler(v8_schema_registry(), v8_context))); | |
918 module_system->RegisterNativeHandler("v8_context", | |
919 scoped_ptr<NativeHandler>(new V8ContextNativeHandler(context))); | |
783 | 920 |
784 int manifest_version = extension ? extension->manifest_version() : 1; | 921 int manifest_version = extension ? extension->manifest_version() : 1; |
785 bool send_request_disabled = | 922 bool send_request_disabled = |
786 (extension && Manifest::IsUnpackedLocation(extension->location()) && | 923 (extension && Manifest::IsUnpackedLocation(extension->location()) && |
787 extension->has_lazy_background_page()); | 924 extension->has_lazy_background_page()); |
788 module_system->RegisterNativeHandler("process", | 925 module_system->RegisterNativeHandler("process", |
789 scoped_ptr<NativeHandler>(new ProcessInfoNativeHandler( | 926 scoped_ptr<NativeHandler>(new ProcessInfoNativeHandler( |
790 this, context->GetExtensionID(), | 927 this, context->GetExtensionID(), |
791 context->GetContextTypeDescription(), | 928 context->GetContextTypeDescription(), |
792 ChromeRenderProcessObserver::is_incognito_process(), | 929 ChromeRenderProcessObserver::is_incognito_process(), |
793 manifest_version, send_request_disabled))); | 930 manifest_version, send_request_disabled))); |
794 | 931 |
795 GetOrCreateChrome(v8_context); | 932 GetOrCreateChrome(v8_context); |
796 | 933 |
797 // Loading JavaScript is expensive, so only run the full API bindings | 934 // Loading JavaScript is expensive, so only run the full API bindings |
798 // generation mechanisms in extension pages (NOT all web pages). | 935 // generation mechanisms in extension pages (NOT all web pages). |
799 switch (context_type) { | 936 switch (context_type) { |
800 case Feature::UNSPECIFIED_CONTEXT: | 937 case Feature::UNSPECIFIED_CONTEXT: |
801 case Feature::WEB_PAGE_CONTEXT: | 938 case Feature::WEB_PAGE_CONTEXT: |
802 // TODO(kalman): see comment below about ExtensionAPI. | 939 // TODO(kalman): see comment below about ExtensionAPI. |
803 InstallBindings(module_system.get(), v8_context, "app"); | 940 InstallBindings(module_system.get(), v8_context, "app"); |
804 InstallBindings(module_system.get(), v8_context, "webstore"); | 941 InstallBindings(module_system.get(), v8_context, "webstore"); |
805 break; | 942 break; |
806 | |
807 case Feature::BLESSED_EXTENSION_CONTEXT: | 943 case Feature::BLESSED_EXTENSION_CONTEXT: |
808 case Feature::UNBLESSED_EXTENSION_CONTEXT: | 944 case Feature::UNBLESSED_EXTENSION_CONTEXT: |
809 case Feature::CONTENT_SCRIPT_CONTEXT: { | 945 case Feature::CONTENT_SCRIPT_CONTEXT: { |
946 if (extension && !extension->is_platform_app()) | |
947 module_system->Require("miscellaneous_bindings"); | |
810 module_system->Require("json"); // see paranoid comment in json.js | 948 module_system->Require("json"); // see paranoid comment in json.js |
811 module_system->Require("miscellaneous_bindings"); | |
812 module_system->Require("schema_generated_bindings"); | |
813 module_system->Require("apitest"); | |
814 | 949 |
815 // TODO(kalman): move this code back out of the switch and execute it | 950 // TODO(kalman): move this code back out of the switch and execute it |
816 // regardless of |context_type|. ExtensionAPI knows how to return the | 951 // regardless of |context_type|. ExtensionAPI knows how to return the |
817 // correct APIs, however, until it doesn't have a 2MB overhead we can't | 952 // correct APIs, however, until it doesn't have a 2MB overhead we can't |
818 // load it in every process. | 953 // load it in every process. |
819 const std::set<std::string>& apis = context->GetAvailableExtensionAPIs(); | 954 RegisterSchemaGeneratedBindings(module_system.get(), |
820 for (std::set<std::string>::const_iterator i = apis.begin(); | 955 context, |
821 i != apis.end(); ++i) { | 956 v8_context); |
822 InstallBindings(module_system.get(), v8_context, *i); | |
823 } | |
824 | |
825 break; | 957 break; |
826 } | 958 } |
827 } | 959 } |
828 | 960 |
829 // Inject custom JS into the platform app context. | 961 // Inject custom JS into the platform app context. |
830 if (IsWithinPlatformApp(frame)) | 962 if (IsWithinPlatformApp(frame)) |
831 module_system->Require("platformApp"); | 963 module_system->Require("platformApp"); |
832 | 964 |
833 if (context_type == Feature::BLESSED_EXTENSION_CONTEXT) { | 965 if (context_type == Feature::BLESSED_EXTENSION_CONTEXT) { |
834 bool has_permission = extension->HasAPIPermission(APIPermission::kWebView); | 966 bool has_permission = extension->HasAPIPermission(APIPermission::kWebView); |
835 module_system->Require(has_permission ? "webview" : "denyWebview"); | 967 module_system->Require(has_permission ? "web_view" : "denyWebview"); |
836 } | 968 } |
837 | 969 |
838 context->set_module_system(module_system.Pass()); | 970 context->set_module_system(module_system.Pass()); |
839 | 971 |
840 context->DispatchOnLoadEvent( | 972 context->DispatchOnLoadEvent( |
841 ChromeRenderProcessObserver::is_incognito_process(), | 973 ChromeRenderProcessObserver::is_incognito_process(), |
842 manifest_version); | 974 manifest_version); |
843 | 975 |
844 VLOG(1) << "Num tracked contexts: " << v8_context_set_.size(); | 976 VLOG(1) << "Num tracked contexts: " << v8_context_set_.size(); |
845 } | 977 } |
(...skipping 20 matching lines...) Expand all Loading... | |
866 return extension && extension->is_platform_app(); | 998 return extension && extension->is_platform_app(); |
867 } | 999 } |
868 | 1000 |
869 void Dispatcher::WillReleaseScriptContext( | 1001 void Dispatcher::WillReleaseScriptContext( |
870 WebFrame* frame, v8::Handle<v8::Context> v8_context, int world_id) { | 1002 WebFrame* frame, v8::Handle<v8::Context> v8_context, int world_id) { |
871 ChromeV8Context* context = v8_context_set_.GetByV8Context(v8_context); | 1003 ChromeV8Context* context = v8_context_set_.GetByV8Context(v8_context); |
872 if (!context) | 1004 if (!context) |
873 return; | 1005 return; |
874 | 1006 |
875 context->DispatchOnUnloadEvent(); | 1007 context->DispatchOnUnloadEvent(); |
1008 // TODO(kalman): add an invalidation observer interface to ChromeV8Context. | |
1009 request_sender_->InvalidateContext(context); | |
876 | 1010 |
877 v8_context_set_.Remove(context); | 1011 v8_context_set_.Remove(context); |
878 VLOG(1) << "Num tracked contexts: " << v8_context_set_.size(); | 1012 VLOG(1) << "Num tracked contexts: " << v8_context_set_.size(); |
879 } | 1013 } |
880 | 1014 |
881 void Dispatcher::DidCreateDocumentElement(WebKit::WebFrame* frame) { | 1015 void Dispatcher::DidCreateDocumentElement(WebKit::WebFrame* frame) { |
882 if (IsWithinPlatformApp(frame)) { | 1016 if (IsWithinPlatformApp(frame)) { |
883 // WebKit doesn't let us define an additional user agent stylesheet, so we | 1017 // WebKit doesn't let us define an additional user agent stylesheet, so we |
884 // insert the default platform app stylesheet into all documents that are | 1018 // insert the default platform app stylesheet into all documents that are |
885 // loaded in each app. | 1019 // loaded in each app. |
(...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1102 return Feature::UNSPECIFIED_CONTEXT; | 1236 return Feature::UNSPECIFIED_CONTEXT; |
1103 } | 1237 } |
1104 | 1238 |
1105 void Dispatcher::OnExtensionResponse(int request_id, | 1239 void Dispatcher::OnExtensionResponse(int request_id, |
1106 bool success, | 1240 bool success, |
1107 const base::ListValue& response, | 1241 const base::ListValue& response, |
1108 const std::string& error) { | 1242 const std::string& error) { |
1109 request_sender_->HandleResponse(request_id, success, response, error); | 1243 request_sender_->HandleResponse(request_id, success, response, error); |
1110 } | 1244 } |
1111 | 1245 |
1112 bool Dispatcher::CheckCurrentContextAccessToExtensionAPI( | 1246 bool Dispatcher::CheckContextAccessToExtensionAPI( |
1113 const std::string& function_name) const { | 1247 const std::string& function_name, ChromeV8Context* context) const { |
1114 ChromeV8Context* context = v8_context_set().GetCurrent(); | |
1115 if (!context) { | 1248 if (!context) { |
1116 DLOG(ERROR) << "Not in a v8::Context"; | 1249 DLOG(ERROR) << "Not in a v8::Context"; |
1117 return false; | 1250 return false; |
1118 } | 1251 } |
1119 | 1252 |
1120 if (!context->extension()) { | 1253 if (!context->extension()) { |
1121 v8::ThrowException( | 1254 v8::ThrowException( |
1122 v8::Exception::Error(v8::String::New("Not in an extension."))); | 1255 v8::Exception::Error(v8::String::New("Not in an extension."))); |
1123 return false; | 1256 return false; |
1124 } | 1257 } |
(...skipping 29 matching lines...) Expand all Loading... | |
1154 std::string error_msg = base::StringPrintf(kMessage, function_name.c_str()); | 1287 std::string error_msg = base::StringPrintf(kMessage, function_name.c_str()); |
1155 v8::ThrowException( | 1288 v8::ThrowException( |
1156 v8::Exception::Error(v8::String::New(error_msg.c_str()))); | 1289 v8::Exception::Error(v8::String::New(error_msg.c_str()))); |
1157 return false; | 1290 return false; |
1158 } | 1291 } |
1159 | 1292 |
1160 return true; | 1293 return true; |
1161 } | 1294 } |
1162 | 1295 |
1163 } // namespace extensions | 1296 } // namespace extensions |
OLD | NEW |