OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/render_view.h" | 5 #include "chrome/renderer/render_view.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <cmath> | 8 #include <cmath> |
9 #include <string> | 9 #include <string> |
10 #include <vector> | 10 #include <vector> |
(...skipping 448 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
459 *type = ViewHostMsg_AccessibilityNotification_Params:: | 459 *type = ViewHostMsg_AccessibilityNotification_Params:: |
460 NOTIFICATION_TYPE_SELECTED_TEXT_CHANGED; | 460 NOTIFICATION_TYPE_SELECTED_TEXT_CHANGED; |
461 break; | 461 break; |
462 default: | 462 default: |
463 // TODO(ctguil): Support additional webkit notifications. | 463 // TODO(ctguil): Support additional webkit notifications. |
464 return false; | 464 return false; |
465 } | 465 } |
466 return true; | 466 return true; |
467 } | 467 } |
468 | 468 |
| 469 // Conversion for the incoming value. The map isn't perfect; v8 has Uint32, |
| 470 // and int64 which don't fit as Value::TYPE_INTEGER, so we let them fall into |
| 471 // being TYPE_REALs. Dates are converted to a string (which can then be parsed |
| 472 // into a base::Time), as are regexps. Arrays are converted into lists, |
| 473 // recursively. We don't deal with binary objects or functions - they become |
| 474 // null values. |
| 475 static Value* ConvertV8Value(const v8::Handle<v8::Value>& v8value) { |
| 476 if (v8value->IsBoolean()) { |
| 477 return Value::CreateBooleanValue(v8value->BooleanValue()); |
| 478 } else if (v8value->IsInt32()) { |
| 479 return Value::CreateIntegerValue(v8value->Int32Value()); |
| 480 } else if (v8value->IsNumber()) { |
| 481 return Value::CreateRealValue(v8value->NumberValue()); |
| 482 } else if (v8value->IsString()) { |
| 483 return Value::CreateStringValue(*v8::String::Utf8Value(v8value)); |
| 484 } else if (v8value->IsDate()) { |
| 485 v8::Date* date = v8::Date::Cast(*v8value); |
| 486 return Value::CreateRealValue(date->NumberValue() / 1000.0); |
| 487 } else if (v8value->IsRegExp()) { |
| 488 return Value::CreateStringValue( |
| 489 *v8::String::Utf8Value(v8value->ToString())); |
| 490 } else if (v8value->IsArray()) { |
| 491 v8::Array* array = v8::Array::Cast(*v8value); |
| 492 uint32_t length = array->Length(); |
| 493 scoped_ptr<ListValue> list(new ListValue); |
| 494 for (uint32_t i = 0 ; i < length ; ++i) { |
| 495 list->Set(i, ConvertV8Value(array->Get(i))); |
| 496 } |
| 497 return list.release(); |
| 498 } |
| 499 return Value::CreateNullValue(); |
| 500 } |
| 501 |
469 /////////////////////////////////////////////////////////////////////////////// | 502 /////////////////////////////////////////////////////////////////////////////// |
470 | 503 |
471 int32 RenderView::next_page_id_ = 1; | 504 int32 RenderView::next_page_id_ = 1; |
472 | 505 |
473 struct RenderView::PendingFileChooser { | 506 struct RenderView::PendingFileChooser { |
474 PendingFileChooser(const ViewHostMsg_RunFileChooser_Params& p, | 507 PendingFileChooser(const ViewHostMsg_RunFileChooser_Params& p, |
475 WebFileChooserCompletion* c) | 508 WebFileChooserCompletion* c) |
476 : params(p), | 509 : params(p), |
477 completion(c) { | 510 completion(c) { |
478 } | 511 } |
(...skipping 4036 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4515 | 4548 |
4516 void RenderView::EvaluateScript(const string16& frame_xpath, | 4549 void RenderView::EvaluateScript(const string16& frame_xpath, |
4517 const string16& script, | 4550 const string16& script, |
4518 int id, | 4551 int id, |
4519 bool notify_result) { | 4552 bool notify_result) { |
4520 v8::Handle<v8::Value> result; | 4553 v8::Handle<v8::Value> result; |
4521 WebFrame* web_frame = GetChildFrame(UTF16ToWideHack(frame_xpath)); | 4554 WebFrame* web_frame = GetChildFrame(UTF16ToWideHack(frame_xpath)); |
4522 if (web_frame) | 4555 if (web_frame) |
4523 result = web_frame->executeScriptAndReturnValue(WebScriptSource(script)); | 4556 result = web_frame->executeScriptAndReturnValue(WebScriptSource(script)); |
4524 if (notify_result) { | 4557 if (notify_result) { |
4525 bool bool_result = !result.IsEmpty() && result->IsBoolean() ? | 4558 ListValue list; |
4526 result->BooleanValue() : false; | 4559 if (web_frame) { |
4527 Send(new ViewHostMsg_ScriptEvalResponse(routing_id_, id, bool_result)); | 4560 v8::HandleScope handle_scope; |
| 4561 v8::Local<v8::Context> context = web_frame->mainWorldScriptContext(); |
| 4562 v8::Context::Scope context_scope(context); |
| 4563 list.Set(0, ConvertV8Value(result)); |
| 4564 } else { |
| 4565 list.Set(0, Value::CreateNullValue()); |
| 4566 } |
| 4567 Send(new ViewHostMsg_ScriptEvalResponse(routing_id_, id, list)); |
4528 } | 4568 } |
4529 } | 4569 } |
4530 | 4570 |
4531 void RenderView::InsertCSS(const std::wstring& frame_xpath, | 4571 void RenderView::InsertCSS(const std::wstring& frame_xpath, |
4532 const std::string& css, | 4572 const std::string& css, |
4533 const std::string& id) { | 4573 const std::string& id) { |
4534 WebFrame* web_frame = GetChildFrame(frame_xpath); | 4574 WebFrame* web_frame = GetChildFrame(frame_xpath); |
4535 if (!web_frame) | 4575 if (!web_frame) |
4536 return; | 4576 return; |
4537 | 4577 |
(...skipping 1137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5675 external_popup_menu_.reset(); | 5715 external_popup_menu_.reset(); |
5676 } | 5716 } |
5677 #endif | 5717 #endif |
5678 | 5718 |
5679 void RenderView::AddErrorToRootConsole(const string16& message) { | 5719 void RenderView::AddErrorToRootConsole(const string16& message) { |
5680 if (webview() && webview()->mainFrame()) { | 5720 if (webview() && webview()->mainFrame()) { |
5681 webview()->mainFrame()->addMessageToConsole( | 5721 webview()->mainFrame()->addMessageToConsole( |
5682 WebConsoleMessage(WebConsoleMessage::LevelError, message)); | 5722 WebConsoleMessage(WebConsoleMessage::LevelError, message)); |
5683 } | 5723 } |
5684 } | 5724 } |
OLD | NEW |