| 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 447 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|   458       *type = ViewHostMsg_AccessibilityNotification_Params:: |   458       *type = ViewHostMsg_AccessibilityNotification_Params:: | 
|   459           NOTIFICATION_TYPE_SELECTED_TEXT_CHANGED; |   459           NOTIFICATION_TYPE_SELECTED_TEXT_CHANGED; | 
|   460       break; |   460       break; | 
|   461     default: |   461     default: | 
|   462       // TODO(ctguil): Support additional webkit notifications. |   462       // TODO(ctguil): Support additional webkit notifications. | 
|   463       return false; |   463       return false; | 
|   464   } |   464   } | 
|   465   return true; |   465   return true; | 
|   466 } |   466 } | 
|   467  |   467  | 
 |   468 // Conversion for the incoming value.  The map isn't perfect; v8 has Uint32, | 
 |   469 // and int64 which don't fit as Value::TYPE_INTEGER, so we let them fall into | 
 |   470 // being TYPE_REALs.  Dates are converted to a string (which can then be parsed | 
 |   471 // into a base::Time), as are regexps.  Arrays are converted into lists, | 
 |   472 // recursively.  We don't deal with binary objects or functions - they become | 
 |   473 // null values. | 
 |   474 static Value* ConvertV8Value(const v8::Handle<v8::Value>& v8value) { | 
 |   475   if (v8value->IsBoolean()) { | 
 |   476     return Value::CreateBooleanValue(v8value->BooleanValue()); | 
 |   477   } else if (v8value->IsInt32()) { | 
 |   478     return Value::CreateIntegerValue(v8value->Int32Value()); | 
 |   479   } else if (v8value->IsNumber()) { | 
 |   480     return Value::CreateRealValue(v8value->NumberValue()); | 
 |   481   } else if (v8value->IsString()) { | 
 |   482     return Value::CreateStringValue(*v8::String::Utf8Value(v8value)); | 
 |   483   } else if (v8value->IsDate()) { | 
 |   484     v8::Date* date = v8::Date::Cast(*v8value); | 
 |   485     return Value::CreateRealValue(date->NumberValue() / 1000.0); | 
 |   486   } else if (v8value->IsRegExp()) { | 
 |   487     return Value::CreateStringValue( | 
 |   488         *v8::String::Utf8Value(v8value->ToString())); | 
 |   489   } else if (v8value->IsArray()) { | 
 |   490     v8::Array* array = v8::Array::Cast(*v8value); | 
 |   491     uint32_t length = array->Length(); | 
 |   492     scoped_ptr<ListValue> list(new ListValue); | 
 |   493     for (uint32_t i = 0 ; i < length ; ++i) { | 
 |   494       list->Set(i, ConvertV8Value(array->Get(i))); | 
 |   495     } | 
 |   496     return list.release(); | 
 |   497   } | 
 |   498   return Value::CreateNullValue(); | 
 |   499 } | 
 |   500  | 
|   468 /////////////////////////////////////////////////////////////////////////////// |   501 /////////////////////////////////////////////////////////////////////////////// | 
|   469  |   502  | 
|   470 int32 RenderView::next_page_id_ = 1; |   503 int32 RenderView::next_page_id_ = 1; | 
|   471  |   504  | 
|   472 struct RenderView::PendingFileChooser { |   505 struct RenderView::PendingFileChooser { | 
|   473   PendingFileChooser(const ViewHostMsg_RunFileChooser_Params& p, |   506   PendingFileChooser(const ViewHostMsg_RunFileChooser_Params& p, | 
|   474                      WebFileChooserCompletion* c) |   507                      WebFileChooserCompletion* c) | 
|   475       : params(p), |   508       : params(p), | 
|   476         completion(c) { |   509         completion(c) { | 
|   477   } |   510   } | 
| (...skipping 4056 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  4534  |  4567  | 
|  4535 void RenderView::EvaluateScript(const string16& frame_xpath, |  4568 void RenderView::EvaluateScript(const string16& frame_xpath, | 
|  4536                                 const string16& script, |  4569                                 const string16& script, | 
|  4537                                 int id, |  4570                                 int id, | 
|  4538                                 bool notify_result) { |  4571                                 bool notify_result) { | 
|  4539   v8::Handle<v8::Value> result; |  4572   v8::Handle<v8::Value> result; | 
|  4540   WebFrame* web_frame = GetChildFrame(UTF16ToWideHack(frame_xpath)); |  4573   WebFrame* web_frame = GetChildFrame(UTF16ToWideHack(frame_xpath)); | 
|  4541   if (web_frame) |  4574   if (web_frame) | 
|  4542     result = web_frame->executeScriptAndReturnValue(WebScriptSource(script)); |  4575     result = web_frame->executeScriptAndReturnValue(WebScriptSource(script)); | 
|  4543   if (notify_result) { |  4576   if (notify_result) { | 
|  4544     bool bool_result = !result.IsEmpty() && result->IsBoolean() ? |  4577     ListValue list; | 
|  4545         result->BooleanValue() : false; |  4578     if (web_frame) { | 
|  4546     Send(new ViewHostMsg_ScriptEvalResponse(routing_id_, id, bool_result)); |  4579       v8::HandleScope handle_scope; | 
 |  4580       v8::Local<v8::Context> context = web_frame->mainWorldScriptContext(); | 
 |  4581       v8::Context::Scope context_scope(context); | 
 |  4582       list.Set(0, ConvertV8Value(result)); | 
 |  4583     } else { | 
 |  4584       list.Set(0, Value::CreateNullValue()); | 
 |  4585     } | 
 |  4586     Send(new ViewHostMsg_ScriptEvalResponse(routing_id_, id, list)); | 
|  4547   } |  4587   } | 
|  4548 } |  4588 } | 
|  4549  |  4589  | 
|  4550 void RenderView::InsertCSS(const std::wstring& frame_xpath, |  4590 void RenderView::InsertCSS(const std::wstring& frame_xpath, | 
|  4551                            const std::string& css, |  4591                            const std::string& css, | 
|  4552                            const std::string& id) { |  4592                            const std::string& id) { | 
|  4553   WebFrame* web_frame = GetChildFrame(frame_xpath); |  4593   WebFrame* web_frame = GetChildFrame(frame_xpath); | 
|  4554   if (!web_frame) |  4594   if (!web_frame) | 
|  4555     return; |  4595     return; | 
|  4556  |  4596  | 
| (...skipping 1128 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  5685   external_popup_menu_.reset(); |  5725   external_popup_menu_.reset(); | 
|  5686 } |  5726 } | 
|  5687 #endif |  5727 #endif | 
|  5688  |  5728  | 
|  5689 void RenderView::AddErrorToRootConsole(const string16& message) { |  5729 void RenderView::AddErrorToRootConsole(const string16& message) { | 
|  5690   if (webview() && webview()->mainFrame()) { |  5730   if (webview() && webview()->mainFrame()) { | 
|  5691     webview()->mainFrame()->addMessageToConsole( |  5731     webview()->mainFrame()->addMessageToConsole( | 
|  5692         WebConsoleMessage(WebConsoleMessage::LevelError, message)); |  5732         WebConsoleMessage(WebConsoleMessage::LevelError, message)); | 
|  5693   } |  5733   } | 
|  5694 } |  5734 } | 
| OLD | NEW |