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 "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 21 matching lines...) Expand all Loading... |
32 #include "chrome/common/extensions/extension.h" | 32 #include "chrome/common/extensions/extension.h" |
33 #include "chrome/common/file_system/file_system_dispatcher.h" | 33 #include "chrome/common/file_system/file_system_dispatcher.h" |
34 #include "chrome/common/file_system/webfilesystem_callback_dispatcher.h" | 34 #include "chrome/common/file_system/webfilesystem_callback_dispatcher.h" |
35 #include "chrome/common/json_value_serializer.h" | 35 #include "chrome/common/json_value_serializer.h" |
36 #include "chrome/common/jstemplate_builder.h" | 36 #include "chrome/common/jstemplate_builder.h" |
37 #include "chrome/common/notification_service.h" | 37 #include "chrome/common/notification_service.h" |
38 #include "chrome/common/page_zoom.h" | 38 #include "chrome/common/page_zoom.h" |
39 #include "chrome/common/pepper_messages.h" | 39 #include "chrome/common/pepper_messages.h" |
40 #include "chrome/common/pepper_plugin_registry.h" | 40 #include "chrome/common/pepper_plugin_registry.h" |
41 #include "chrome/common/render_messages.h" | 41 #include "chrome/common/render_messages.h" |
42 #include "chrome/common/render_view_commands.h" | |
43 #include "chrome/common/renderer_preferences.h" | 42 #include "chrome/common/renderer_preferences.h" |
44 #include "chrome/common/thumbnail_score.h" | 43 #include "chrome/common/thumbnail_score.h" |
45 #include "chrome/common/url_constants.h" | 44 #include "chrome/common/url_constants.h" |
46 #include "chrome/common/web_apps.h" | 45 #include "chrome/common/web_apps.h" |
47 #include "chrome/common/window_container_type.h" | 46 #include "chrome/common/window_container_type.h" |
48 #include "chrome/renderer/about_handler.h" | 47 #include "chrome/renderer/about_handler.h" |
49 #include "chrome/renderer/audio_message_filter.h" | 48 #include "chrome/renderer/audio_message_filter.h" |
50 #include "chrome/renderer/autofill_helper.h" | 49 #include "chrome/renderer/autofill_helper.h" |
51 #include "chrome/renderer/automation/dom_automation_controller.h" | 50 #include "chrome/renderer/automation/dom_automation_controller.h" |
52 #include "chrome/renderer/blocked_plugin.h" | 51 #include "chrome/renderer/blocked_plugin.h" |
(...skipping 1567 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1620 UserMetricsRecordAction("SelectAll"); | 1619 UserMetricsRecordAction("SelectAll"); |
1621 } | 1620 } |
1622 | 1621 |
1623 void RenderView::OnSetInitialFocus(bool reverse) { | 1622 void RenderView::OnSetInitialFocus(bool reverse) { |
1624 if (!webview()) | 1623 if (!webview()) |
1625 return; | 1624 return; |
1626 webview()->setInitialFocus(reverse); | 1625 webview()->setInitialFocus(reverse); |
1627 } | 1626 } |
1628 | 1627 |
1629 void RenderView::OnScrollFocusedEditableNodeIntoView() { | 1628 void RenderView::OnScrollFocusedEditableNodeIntoView() { |
1630 WebKit::WebNode node = GetFocusedNode(); | 1629 if (!webview()) |
1631 if (!node.isNull()) { | 1630 return; |
1632 if (IsEditableNode(node)) | 1631 WebFrame* focused_frame = webview()->focusedFrame(); |
1633 // TODO(varunjain): Change webkit API to scroll a particular node into | 1632 if (focused_frame) { |
1634 // view and use that API here instead. | 1633 WebDocument doc = focused_frame->document(); |
1635 webview()->scrollFocusedNodeIntoView(); | 1634 if (!doc.isNull()) { |
| 1635 WebNode node = doc.focusedNode(); |
| 1636 if (IsEditableNode(node)) |
| 1637 // TODO(varunjain): Change webkit API to scroll a particular node into |
| 1638 // view and use that API here instead. |
| 1639 webview()->scrollFocusedNodeIntoView(); |
| 1640 } |
1636 } | 1641 } |
1637 } | 1642 } |
1638 | 1643 |
1639 /////////////////////////////////////////////////////////////////////////////// | 1644 /////////////////////////////////////////////////////////////////////////////// |
1640 | 1645 |
1641 void RenderView::SetContentSettings(const ContentSettings& settings) { | 1646 void RenderView::SetContentSettings(const ContentSettings& settings) { |
1642 current_content_settings_ = settings; | 1647 current_content_settings_ = settings; |
1643 } | 1648 } |
1644 | 1649 |
1645 // Tell the embedding application that the URL of the active page has changed | 1650 // Tell the embedding application that the URL of the active page has changed |
(...skipping 710 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2356 | 2361 |
2357 bool RenderView::isShowingSpellingUI() { | 2362 bool RenderView::isShowingSpellingUI() { |
2358 return spelling_panel_visible_; | 2363 return spelling_panel_visible_; |
2359 } | 2364 } |
2360 | 2365 |
2361 void RenderView::updateSpellingUIWithMisspelledWord(const WebString& word) { | 2366 void RenderView::updateSpellingUIWithMisspelledWord(const WebString& word) { |
2362 Send(new ViewHostMsg_UpdateSpellingPanelWithMisspelledWord(routing_id_, | 2367 Send(new ViewHostMsg_UpdateSpellingPanelWithMisspelledWord(routing_id_, |
2363 word)); | 2368 word)); |
2364 } | 2369 } |
2365 | 2370 |
2366 void RenderView::continuousSpellCheckingEnabledStateChanged() { | |
2367 UpdateToggleSpellCheckCommandState(); | |
2368 } | |
2369 | |
2370 bool RenderView::runFileChooser( | 2371 bool RenderView::runFileChooser( |
2371 const WebKit::WebFileChooserParams& params, | 2372 const WebKit::WebFileChooserParams& params, |
2372 WebFileChooserCompletion* chooser_completion) { | 2373 WebFileChooserCompletion* chooser_completion) { |
2373 // Do not open the file dialog in a hidden RenderView. | 2374 // Do not open the file dialog in a hidden RenderView. |
2374 if (is_hidden()) | 2375 if (is_hidden()) |
2375 return false; | 2376 return false; |
2376 ViewHostMsg_RunFileChooser_Params ipc_params; | 2377 ViewHostMsg_RunFileChooser_Params ipc_params; |
2377 if (params.directory) | 2378 if (params.directory) |
2378 ipc_params.mode = ViewHostMsg_RunFileChooser_Params::OpenFolder; | 2379 ipc_params.mode = ViewHostMsg_RunFileChooser_Params::OpenFolder; |
2379 else if (params.multiSelect) | 2380 else if (params.multiSelect) |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2486 // any existing pending sends. | 2487 // any existing pending sends. |
2487 pending_target_url_ = latest_url; | 2488 pending_target_url_ = latest_url; |
2488 target_url_status_ = TARGET_PENDING; | 2489 target_url_status_ = TARGET_PENDING; |
2489 } else { | 2490 } else { |
2490 Send(new ViewHostMsg_UpdateTargetURL(routing_id_, page_id_, latest_url)); | 2491 Send(new ViewHostMsg_UpdateTargetURL(routing_id_, page_id_, latest_url)); |
2491 target_url_ = latest_url; | 2492 target_url_ = latest_url; |
2492 target_url_status_ = TARGET_INFLIGHT; | 2493 target_url_status_ = TARGET_INFLIGHT; |
2493 } | 2494 } |
2494 } | 2495 } |
2495 | 2496 |
2496 void RenderView::UpdateToggleSpellCheckCommandState() { | |
2497 bool is_enabled = false; | |
2498 WebKit::WebNode node = GetFocusedNode(); | |
2499 if (!node.isNull()) | |
2500 is_enabled = IsEditableNode(node); | |
2501 | |
2502 RenderViewCommandCheckedState checked_state = | |
2503 RENDER_VIEW_COMMAND_CHECKED_STATE_UNCHECKED; | |
2504 if (is_enabled && webview()) { | |
2505 WebFrame* frame = webview()->focusedFrame(); | |
2506 if (frame->isContinuousSpellCheckingEnabled()) | |
2507 checked_state = RENDER_VIEW_COMMAND_CHECKED_STATE_CHECKED; | |
2508 } | |
2509 | |
2510 Send(new ViewHostMsg_CommandStateChanged( | |
2511 routing_id_, | |
2512 RENDER_VIEW_COMMAND_TOGGLE_SPELL_CHECK, | |
2513 is_enabled, | |
2514 checked_state)); | |
2515 } | |
2516 | |
2517 void RenderView::StartNavStateSyncTimerIfNecessary() { | 2497 void RenderView::StartNavStateSyncTimerIfNecessary() { |
2518 int delay; | 2498 int delay; |
2519 if (send_content_state_immediately_) | 2499 if (send_content_state_immediately_) |
2520 delay = 0; | 2500 delay = 0; |
2521 else if (is_hidden()) | 2501 else if (is_hidden()) |
2522 delay = kDelaySecondsForContentStateSyncHidden; | 2502 delay = kDelaySecondsForContentStateSyncHidden; |
2523 else | 2503 else |
2524 delay = kDelaySecondsForContentStateSync; | 2504 delay = kDelaySecondsForContentStateSync; |
2525 | 2505 |
2526 if (nav_state_sync_timer_.IsRunning()) { | 2506 if (nav_state_sync_timer_.IsRunning()) { |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2583 void RenderView::focusedNodeChanged(const WebNode& node) { | 2563 void RenderView::focusedNodeChanged(const WebNode& node) { |
2584 Send(new ViewHostMsg_FocusedNodeChanged(routing_id_, IsEditableNode(node))); | 2564 Send(new ViewHostMsg_FocusedNodeChanged(routing_id_, IsEditableNode(node))); |
2585 | 2565 |
2586 if (WebAccessibilityCache::accessibilityEnabled() && node.isNull()) { | 2566 if (WebAccessibilityCache::accessibilityEnabled() && node.isNull()) { |
2587 // TODO(ctguil): Make WebKit send this notification. | 2567 // TODO(ctguil): Make WebKit send this notification. |
2588 // When focus is cleared notify accessibility that the document is focused. | 2568 // When focus is cleared notify accessibility that the document is focused. |
2589 postAccessibilityNotification( | 2569 postAccessibilityNotification( |
2590 webview()->accessibilityObject(), | 2570 webview()->accessibilityObject(), |
2591 WebKit::WebAccessibilityNotificationFocusedUIElementChanged); | 2571 WebKit::WebAccessibilityNotificationFocusedUIElementChanged); |
2592 } | 2572 } |
2593 | |
2594 UpdateToggleSpellCheckCommandState(); | |
2595 } | 2573 } |
2596 | 2574 |
2597 void RenderView::navigateBackForwardSoon(int offset) { | 2575 void RenderView::navigateBackForwardSoon(int offset) { |
2598 Send(new ViewHostMsg_GoToEntryAtOffset(routing_id_, offset)); | 2576 Send(new ViewHostMsg_GoToEntryAtOffset(routing_id_, offset)); |
2599 } | 2577 } |
2600 | 2578 |
2601 int RenderView::historyBackListCount() { | 2579 int RenderView::historyBackListCount() { |
2602 return history_list_offset_ < 0 ? 0 : history_list_offset_; | 2580 return history_list_offset_ < 0 ? 0 : history_list_offset_; |
2603 } | 2581 } |
2604 | 2582 |
(...skipping 1935 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4540 xpath_remaining.erase(0, delim_pos + 1); | 4518 xpath_remaining.erase(0, delim_pos + 1); |
4541 } else { | 4519 } else { |
4542 xpath_remaining.swap(xpath_child); | 4520 xpath_remaining.swap(xpath_child); |
4543 } | 4521 } |
4544 frame = frame->findChildByExpression(WideToUTF16Hack(xpath_child)); | 4522 frame = frame->findChildByExpression(WideToUTF16Hack(xpath_child)); |
4545 } | 4523 } |
4546 | 4524 |
4547 return frame; | 4525 return frame; |
4548 } | 4526 } |
4549 | 4527 |
4550 WebNode RenderView::GetFocusedNode() const { | |
4551 if (!webview()) | |
4552 return WebNode(); | |
4553 WebFrame* focused_frame = webview()->focusedFrame(); | |
4554 if (focused_frame) { | |
4555 WebDocument doc = focused_frame->document(); | |
4556 if (!doc.isNull()) | |
4557 return doc.focusedNode(); | |
4558 } | |
4559 | |
4560 return WebNode(); | |
4561 } | |
4562 | |
4563 void RenderView::SetSuggestions(const std::vector<std::string>& suggestions) { | 4528 void RenderView::SetSuggestions(const std::vector<std::string>& suggestions) { |
4564 // Explicitly allow empty vector to be sent to the browser. | 4529 // Explicitly allow empty vector to be sent to the browser. |
4565 Send(new ViewHostMsg_SetSuggestions(routing_id_, page_id_, suggestions)); | 4530 Send(new ViewHostMsg_SetSuggestions(routing_id_, page_id_, suggestions)); |
4566 } | 4531 } |
4567 | 4532 |
4568 void RenderView::EvaluateScript(const string16& frame_xpath, | 4533 void RenderView::EvaluateScript(const string16& frame_xpath, |
4569 const string16& script, | 4534 const string16& script, |
4570 int id, | 4535 int id, |
4571 bool notify_result) { | 4536 bool notify_result) { |
4572 v8::Handle<v8::Value> result; | 4537 v8::Handle<v8::Value> result; |
(...skipping 1212 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5785 if (cmd == kJavaScriptStressTestSetStressRunType) { | 5750 if (cmd == kJavaScriptStressTestSetStressRunType) { |
5786 v8::Testing::SetStressRunType(static_cast<v8::Testing::StressType>(param)); | 5751 v8::Testing::SetStressRunType(static_cast<v8::Testing::StressType>(param)); |
5787 } else if (cmd == kJavaScriptStressTestPrepareStressRun) { | 5752 } else if (cmd == kJavaScriptStressTestPrepareStressRun) { |
5788 v8::Testing::PrepareStressRun(param); | 5753 v8::Testing::PrepareStressRun(param); |
5789 } | 5754 } |
5790 } | 5755 } |
5791 | 5756 |
5792 void RenderView::OnContextMenuClosed() { | 5757 void RenderView::OnContextMenuClosed() { |
5793 context_menu_node_.reset(); | 5758 context_menu_node_.reset(); |
5794 } | 5759 } |
OLD | NEW |