| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "content/renderer/render_view.h" | 5 #include "content/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> |
| 11 | 11 |
| 12 #include "base/callback.h" | 12 #include "base/callback.h" |
| 13 #include "base/command_line.h" | 13 #include "base/command_line.h" |
| 14 #include "base/compiler_specific.h" | 14 #include "base/compiler_specific.h" |
| 15 #include "base/json/json_writer.h" | 15 #include "base/json/json_writer.h" |
| 16 #include "base/lazy_instance.h" | 16 #include "base/lazy_instance.h" |
| 17 #include "base/metrics/histogram.h" | 17 #include "base/metrics/histogram.h" |
| 18 #include "base/path_service.h" | 18 #include "base/path_service.h" |
| 19 #include "base/process_util.h" | 19 #include "base/process_util.h" |
| 20 #include "base/string_piece.h" | 20 #include "base/string_piece.h" |
| 21 #include "base/string_split.h" |
| 21 #include "base/string_util.h" | 22 #include "base/string_util.h" |
| 22 #include "base/sys_string_conversions.h" | 23 #include "base/sys_string_conversions.h" |
| 23 #include "base/time.h" | 24 #include "base/time.h" |
| 24 #include "base/utf_string_conversions.h" | 25 #include "base/utf_string_conversions.h" |
| 25 #include "content/common/appcache/appcache_dispatcher.h" | 26 #include "content/common/appcache/appcache_dispatcher.h" |
| 26 #include "content/common/bindings_policy.h" | 27 #include "content/common/bindings_policy.h" |
| 27 #include "content/common/clipboard_messages.h" | 28 #include "content/common/clipboard_messages.h" |
| 28 #include "content/common/content_constants.h" | 29 #include "content/common/content_constants.h" |
| 29 #include "content/common/content_switches.h" | 30 #include "content/common/content_switches.h" |
| 30 #include "content/common/database_messages.h" | 31 #include "content/common/database_messages.h" |
| (...skipping 3283 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3314 | 3315 |
| 3315 void RenderView::OnSetPageEncoding(const std::string& encoding_name) { | 3316 void RenderView::OnSetPageEncoding(const std::string& encoding_name) { |
| 3316 webview()->setPageEncoding(WebString::fromUTF8(encoding_name)); | 3317 webview()->setPageEncoding(WebString::fromUTF8(encoding_name)); |
| 3317 } | 3318 } |
| 3318 | 3319 |
| 3319 void RenderView::OnResetPageEncodingToDefault() { | 3320 void RenderView::OnResetPageEncodingToDefault() { |
| 3320 WebString no_encoding; | 3321 WebString no_encoding; |
| 3321 webview()->setPageEncoding(no_encoding); | 3322 webview()->setPageEncoding(no_encoding); |
| 3322 } | 3323 } |
| 3323 | 3324 |
| 3324 WebFrame* RenderView::GetChildFrame(const std::wstring& xpath) const { | 3325 WebFrame* RenderView::GetChildFrame(const string16& xpath) const { |
| 3325 if (xpath.empty()) | 3326 if (xpath.empty()) |
| 3326 return webview()->mainFrame(); | 3327 return webview()->mainFrame(); |
| 3327 | 3328 |
| 3328 // xpath string can represent a frame deep down the tree (across multiple | 3329 // xpath string can represent a frame deep down the tree (across multiple |
| 3329 // frame DOMs). | 3330 // frame DOMs). |
| 3330 // Example, /html/body/table/tbody/tr/td/iframe\n/frameset/frame[0] | 3331 // Example, /html/body/table/tbody/tr/td/iframe\n/frameset/frame[0] |
| 3331 // should break into 2 xpaths | 3332 // should break into 2 xpaths |
| 3332 // /html/body/table/tbody/tr/td/iframe & /frameset/frame[0] | 3333 // /html/body/table/tbody/tr/td/iframe & /frameset/frame[0] |
| 3334 std::vector<string16> xpaths; |
| 3335 SplitString(xpath, '\n', &xpaths); |
| 3333 | 3336 |
| 3334 WebFrame* frame = webview()->mainFrame(); | 3337 WebFrame* frame = webview()->mainFrame(); |
| 3335 | 3338 for (std::vector<string16>::const_iterator i = xpaths.begin(); |
| 3336 std::wstring xpath_remaining = xpath; | 3339 frame && i != xpaths.end(); ++i) { |
| 3337 while (!xpath_remaining.empty()) { | 3340 frame = frame->findChildByExpression(*i); |
| 3338 std::wstring::size_type delim_pos = xpath_remaining.find_first_of(L'\n'); | |
| 3339 std::wstring xpath_child; | |
| 3340 if (delim_pos != std::wstring::npos) { | |
| 3341 xpath_child = xpath_remaining.substr(0, delim_pos); | |
| 3342 xpath_remaining.erase(0, delim_pos + 1); | |
| 3343 } else { | |
| 3344 xpath_remaining.swap(xpath_child); | |
| 3345 } | |
| 3346 frame = frame->findChildByExpression(WideToUTF16Hack(xpath_child)); | |
| 3347 } | 3341 } |
| 3348 | 3342 |
| 3349 return frame; | 3343 return frame; |
| 3350 } | 3344 } |
| 3351 | 3345 |
| 3352 WebNode RenderView::GetFocusedNode() const { | 3346 WebNode RenderView::GetFocusedNode() const { |
| 3353 if (!webview()) | 3347 if (!webview()) |
| 3354 return WebNode(); | 3348 return WebNode(); |
| 3355 WebFrame* focused_frame = webview()->focusedFrame(); | 3349 WebFrame* focused_frame = webview()->focusedFrame(); |
| 3356 if (focused_frame) { | 3350 if (focused_frame) { |
| (...skipping 16 matching lines...) Expand all Loading... |
| 3373 } | 3367 } |
| 3374 } | 3368 } |
| 3375 return is_editable_node; | 3369 return is_editable_node; |
| 3376 } | 3370 } |
| 3377 | 3371 |
| 3378 void RenderView::EvaluateScript(const string16& frame_xpath, | 3372 void RenderView::EvaluateScript(const string16& frame_xpath, |
| 3379 const string16& script, | 3373 const string16& script, |
| 3380 int id, | 3374 int id, |
| 3381 bool notify_result) { | 3375 bool notify_result) { |
| 3382 v8::Handle<v8::Value> result; | 3376 v8::Handle<v8::Value> result; |
| 3383 WebFrame* web_frame = GetChildFrame(UTF16ToWideHack(frame_xpath)); | 3377 WebFrame* web_frame = GetChildFrame(frame_xpath); |
| 3384 if (web_frame) | 3378 if (web_frame) |
| 3385 result = web_frame->executeScriptAndReturnValue(WebScriptSource(script)); | 3379 result = web_frame->executeScriptAndReturnValue(WebScriptSource(script)); |
| 3386 if (notify_result) { | 3380 if (notify_result) { |
| 3387 ListValue list; | 3381 ListValue list; |
| 3388 if (!result.IsEmpty() && web_frame) { | 3382 if (!result.IsEmpty() && web_frame) { |
| 3389 v8::HandleScope handle_scope; | 3383 v8::HandleScope handle_scope; |
| 3390 v8::Local<v8::Context> context = web_frame->mainWorldScriptContext(); | 3384 v8::Local<v8::Context> context = web_frame->mainWorldScriptContext(); |
| 3391 v8::Context::Scope context_scope(context); | 3385 v8::Context::Scope context_scope(context); |
| 3392 V8ValueConverter converter; | 3386 V8ValueConverter converter; |
| 3393 converter.set_allow_date(true); | 3387 converter.set_allow_date(true); |
| 3394 converter.set_allow_regexp(true); | 3388 converter.set_allow_regexp(true); |
| 3395 list.Set(0, converter.FromV8Value(result, context)); | 3389 list.Set(0, converter.FromV8Value(result, context)); |
| 3396 } else { | 3390 } else { |
| 3397 list.Set(0, Value::CreateNullValue()); | 3391 list.Set(0, Value::CreateNullValue()); |
| 3398 } | 3392 } |
| 3399 Send(new ViewHostMsg_ScriptEvalResponse(routing_id_, id, list)); | 3393 Send(new ViewHostMsg_ScriptEvalResponse(routing_id_, id, list)); |
| 3400 } | 3394 } |
| 3401 } | 3395 } |
| 3402 | 3396 |
| 3403 void RenderView::OnScriptEvalRequest(const string16& frame_xpath, | 3397 void RenderView::OnScriptEvalRequest(const string16& frame_xpath, |
| 3404 const string16& jscript, | 3398 const string16& jscript, |
| 3405 int id, | 3399 int id, |
| 3406 bool notify_result) { | 3400 bool notify_result) { |
| 3407 EvaluateScript(frame_xpath, jscript, id, notify_result); | 3401 EvaluateScript(frame_xpath, jscript, id, notify_result); |
| 3408 } | 3402 } |
| 3409 | 3403 |
| 3410 void RenderView::OnCSSInsertRequest(const std::wstring& frame_xpath, | 3404 void RenderView::OnCSSInsertRequest(const string16& frame_xpath, |
| 3411 const std::string& css) { | 3405 const std::string& css) { |
| 3412 WebFrame* frame = GetChildFrame(frame_xpath); | 3406 WebFrame* frame = GetChildFrame(frame_xpath); |
| 3413 if (!frame) | 3407 if (!frame) |
| 3414 return; | 3408 return; |
| 3415 | 3409 |
| 3416 frame->document().insertUserStyleSheet( | 3410 frame->document().insertUserStyleSheet( |
| 3417 WebString::fromUTF8(css), | 3411 WebString::fromUTF8(css), |
| 3418 WebDocument::UserStyleAuthorLevel); | 3412 WebDocument::UserStyleAuthorLevel); |
| 3419 } | 3413 } |
| 3420 | 3414 |
| (...skipping 1012 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4433 } | 4427 } |
| 4434 #endif | 4428 #endif |
| 4435 | 4429 |
| 4436 void RenderView::OnContextMenuClosed( | 4430 void RenderView::OnContextMenuClosed( |
| 4437 const webkit_glue::CustomContextMenuContext& custom_context) { | 4431 const webkit_glue::CustomContextMenuContext& custom_context) { |
| 4438 if (custom_context.is_pepper_menu) | 4432 if (custom_context.is_pepper_menu) |
| 4439 pepper_delegate_.OnContextMenuClosed(custom_context); | 4433 pepper_delegate_.OnContextMenuClosed(custom_context); |
| 4440 else | 4434 else |
| 4441 context_menu_node_.reset(); | 4435 context_menu_node_.reset(); |
| 4442 } | 4436 } |
| OLD | NEW |