| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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 <map> | 5 #include <map> |
| 6 #include <set> | 6 #include <set> |
| 7 #include <string> | 7 #include <string> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "chrome/renderer/extensions/extension_process_bindings.h" | 10 #include "chrome/renderer/extensions/extension_process_bindings.h" |
| 11 | 11 |
| 12 #include "base/json_reader.h" |
| 12 #include "base/singleton.h" | 13 #include "base/singleton.h" |
| 13 #include "chrome/common/extensions/extension.h" | 14 #include "chrome/common/extensions/extension.h" |
| 14 #include "chrome/common/extensions/extension_message_bundle.h" | 15 #include "chrome/common/extensions/extension_message_bundle.h" |
| 15 #include "chrome/common/extensions/url_pattern.h" | 16 #include "chrome/common/extensions/url_pattern.h" |
| 16 #include "chrome/common/render_messages.h" | 17 #include "chrome/common/render_messages.h" |
| 17 #include "chrome/common/url_constants.h" | 18 #include "chrome/common/url_constants.h" |
| 18 #include "chrome/renderer/extensions/bindings_utils.h" | 19 #include "chrome/renderer/extensions/bindings_utils.h" |
| 19 #include "chrome/renderer/extensions/event_bindings.h" | 20 #include "chrome/renderer/extensions/event_bindings.h" |
| 20 #include "chrome/renderer/extensions/js_only_v8_extensions.h" | 21 #include "chrome/renderer/extensions/js_only_v8_extensions.h" |
| 21 #include "chrome/renderer/extensions/renderer_extension_bindings.h" | 22 #include "chrome/renderer/extensions/renderer_extension_bindings.h" |
| (...skipping 323 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 345 std::string name = *v8::String::AsciiValue(args[0]); | 346 std::string name = *v8::String::AsciiValue(args[0]); |
| 346 if (GetFunctionNameSet()->find(name) == GetFunctionNameSet()->end()) { | 347 if (GetFunctionNameSet()->find(name) == GetFunctionNameSet()->end()) { |
| 347 NOTREACHED() << "Unexpected function " << name; | 348 NOTREACHED() << "Unexpected function " << name; |
| 348 return v8::Undefined(); | 349 return v8::Undefined(); |
| 349 } | 350 } |
| 350 | 351 |
| 351 if (!ExtensionProcessBindings::CurrentContextHasPermission(name)) { | 352 if (!ExtensionProcessBindings::CurrentContextHasPermission(name)) { |
| 352 return ExtensionProcessBindings::ThrowPermissionDeniedException(name); | 353 return ExtensionProcessBindings::ThrowPermissionDeniedException(name); |
| 353 } | 354 } |
| 354 | 355 |
| 355 std::string json_args = *v8::String::Utf8Value(args[1]); | 356 std::string str_args = *v8::String::Utf8Value(args[1]); |
| 356 int request_id = args[2]->Int32Value(); | 357 int request_id = args[2]->Int32Value(); |
| 357 bool has_callback = args[3]->BooleanValue(); | 358 bool has_callback = args[3]->BooleanValue(); |
| 358 | 359 |
| 360 ListValue args_holder; |
| 361 JSONReader reader; |
| 362 Value* json_args = reader.JsonToValue(str_args, false, false); |
| 363 |
| 364 // Since we do the serialization in the v8 extension, we should always get |
| 365 // valid JSON. |
| 366 if (!json_args) { |
| 367 NOTREACHED() << "Invalid JSON passed to StartRequest."; |
| 368 return v8::Undefined(); |
| 369 } |
| 370 |
| 371 // Put the args in a 1-element list for easier serialization. Maybe all |
| 372 // requests should have a list of args? |
| 373 args_holder.Append(json_args); |
| 374 |
| 359 v8::Persistent<v8::Context> current_context = | 375 v8::Persistent<v8::Context> current_context = |
| 360 v8::Persistent<v8::Context>::New(v8::Context::GetCurrent()); | 376 v8::Persistent<v8::Context>::New(v8::Context::GetCurrent()); |
| 361 DCHECK(!current_context.IsEmpty()); | 377 DCHECK(!current_context.IsEmpty()); |
| 362 GetPendingRequestMap()[request_id].reset(new PendingRequest( | 378 GetPendingRequestMap()[request_id].reset(new PendingRequest( |
| 363 current_context, name)); | 379 current_context, name)); |
| 364 | 380 |
| 365 renderview->SendExtensionRequest(name, json_args, request_id, has_callback); | 381 renderview->SendExtensionRequest(name, args_holder, |
| 382 request_id, has_callback); |
| 366 | 383 |
| 367 return v8::Undefined(); | 384 return v8::Undefined(); |
| 368 } | 385 } |
| 369 | 386 |
| 370 static v8::Handle<v8::Value> GetRenderViewId(const v8::Arguments& args) { | 387 static v8::Handle<v8::Value> GetRenderViewId(const v8::Arguments& args) { |
| 371 RenderView* renderview = bindings_utils::GetRenderViewForCurrentContext(); | 388 RenderView* renderview = bindings_utils::GetRenderViewForCurrentContext(); |
| 372 if (!renderview) | 389 if (!renderview) |
| 373 return v8::Undefined(); | 390 return v8::Undefined(); |
| 374 return v8::Integer::New(renderview->routing_id()); | 391 return v8::Integer::New(renderview->routing_id()); |
| 375 } | 392 } |
| (...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 516 return; | 533 return; |
| 517 | 534 |
| 518 v8::HandleScope handle_scope; | 535 v8::HandleScope handle_scope; |
| 519 WebFrame* frame = view->mainFrame(); | 536 WebFrame* frame = view->mainFrame(); |
| 520 v8::Local<v8::Context> context = frame->mainWorldScriptContext(); | 537 v8::Local<v8::Context> context = frame->mainWorldScriptContext(); |
| 521 v8::Handle<v8::Value> argv[1]; | 538 v8::Handle<v8::Value> argv[1]; |
| 522 argv[0] = v8::String::New(type_str); | 539 argv[0] = v8::String::New(type_str); |
| 523 bindings_utils::CallFunctionInContext(context, "setViewType", | 540 bindings_utils::CallFunctionInContext(context, "setViewType", |
| 524 arraysize(argv), argv); | 541 arraysize(argv), argv); |
| 525 } | 542 } |
| OLD | NEW |