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 23 matching lines...) Expand all Loading... | |
34 #include "chrome/common/database_messages.h" | 34 #include "chrome/common/database_messages.h" |
35 #include "chrome/common/extensions/extension.h" | 35 #include "chrome/common/extensions/extension.h" |
36 #include "chrome/common/file_system/file_system_dispatcher.h" | 36 #include "chrome/common/file_system/file_system_dispatcher.h" |
37 #include "chrome/common/file_system/webfilesystem_callback_dispatcher.h" | 37 #include "chrome/common/file_system/webfilesystem_callback_dispatcher.h" |
38 #include "chrome/common/json_value_serializer.h" | 38 #include "chrome/common/json_value_serializer.h" |
39 #include "chrome/common/jstemplate_builder.h" | 39 #include "chrome/common/jstemplate_builder.h" |
40 #include "chrome/common/notification_service.h" | 40 #include "chrome/common/notification_service.h" |
41 #include "chrome/common/page_zoom.h" | 41 #include "chrome/common/page_zoom.h" |
42 #include "chrome/common/pepper_plugin_registry.h" | 42 #include "chrome/common/pepper_plugin_registry.h" |
43 #include "chrome/common/render_messages.h" | 43 #include "chrome/common/render_messages.h" |
44 #include "chrome/common/render_view_commands.h" | |
44 #include "chrome/common/renderer_preferences.h" | 45 #include "chrome/common/renderer_preferences.h" |
45 #include "chrome/common/thumbnail_score.h" | 46 #include "chrome/common/thumbnail_score.h" |
46 #include "chrome/common/url_constants.h" | 47 #include "chrome/common/url_constants.h" |
47 #include "chrome/common/web_apps.h" | 48 #include "chrome/common/web_apps.h" |
48 #include "chrome/common/window_container_type.h" | 49 #include "chrome/common/window_container_type.h" |
49 #include "chrome/renderer/about_handler.h" | 50 #include "chrome/renderer/about_handler.h" |
50 #include "chrome/renderer/audio_message_filter.h" | 51 #include "chrome/renderer/audio_message_filter.h" |
51 #include "chrome/renderer/autofill_helper.h" | 52 #include "chrome/renderer/autofill_helper.h" |
52 #include "chrome/renderer/automation/dom_automation_controller.h" | 53 #include "chrome/renderer/automation/dom_automation_controller.h" |
53 #include "chrome/renderer/blocked_plugin.h" | 54 #include "chrome/renderer/blocked_plugin.h" |
(...skipping 1580 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1634 UserMetricsRecordAction("SelectAll"); | 1635 UserMetricsRecordAction("SelectAll"); |
1635 } | 1636 } |
1636 | 1637 |
1637 void RenderView::OnSetInitialFocus(bool reverse) { | 1638 void RenderView::OnSetInitialFocus(bool reverse) { |
1638 if (!webview()) | 1639 if (!webview()) |
1639 return; | 1640 return; |
1640 webview()->setInitialFocus(reverse); | 1641 webview()->setInitialFocus(reverse); |
1641 } | 1642 } |
1642 | 1643 |
1643 void RenderView::OnScrollFocusedEditableNodeIntoView() { | 1644 void RenderView::OnScrollFocusedEditableNodeIntoView() { |
1644 if (!webview()) | 1645 linked_ptr<WebKit::WebNode> node = GetFocusedNode(); |
1645 return; | 1646 if (node != NULL) { |
1646 WebFrame* focused_frame = webview()->focusedFrame(); | 1647 if (IsEditableNode(*node)) |
1647 if (focused_frame) { | 1648 // TODO(varunjain): Change webkit API to scroll a particular node into |
1648 WebDocument doc = focused_frame->document(); | 1649 // view and use that API here instead. |
1649 if (!doc.isNull()) { | 1650 webview()->scrollFocusedNodeIntoView(); |
1650 WebNode node = doc.focusedNode(); | |
1651 if (IsEditableNode(node)) | |
1652 // TODO(varunjain): Change webkit API to scroll a particular node into | |
1653 // view and use that API here instead. | |
1654 webview()->scrollFocusedNodeIntoView(); | |
1655 } | |
1656 } | 1651 } |
1657 } | 1652 } |
1658 | 1653 |
1659 /////////////////////////////////////////////////////////////////////////////// | 1654 /////////////////////////////////////////////////////////////////////////////// |
1660 | 1655 |
1661 void RenderView::SetContentSettings(const ContentSettings& settings) { | 1656 void RenderView::SetContentSettings(const ContentSettings& settings) { |
1662 current_content_settings_ = settings; | 1657 current_content_settings_ = settings; |
1663 } | 1658 } |
1664 | 1659 |
1665 // Tell the embedding application that the URL of the active page has changed | 1660 // Tell the embedding application that the URL of the active page has changed |
(...skipping 749 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2415 | 2410 |
2416 bool RenderView::isShowingSpellingUI() { | 2411 bool RenderView::isShowingSpellingUI() { |
2417 return spelling_panel_visible_; | 2412 return spelling_panel_visible_; |
2418 } | 2413 } |
2419 | 2414 |
2420 void RenderView::updateSpellingUIWithMisspelledWord(const WebString& word) { | 2415 void RenderView::updateSpellingUIWithMisspelledWord(const WebString& word) { |
2421 Send(new ViewHostMsg_UpdateSpellingPanelWithMisspelledWord(routing_id_, | 2416 Send(new ViewHostMsg_UpdateSpellingPanelWithMisspelledWord(routing_id_, |
2422 word)); | 2417 word)); |
2423 } | 2418 } |
2424 | 2419 |
2420 void RenderView::continuousSpellCheckingEnabledStateChanged() { | |
2421 UpdateToggleSpellCheckCommandState(); | |
2422 } | |
2423 | |
2425 bool RenderView::runFileChooser( | 2424 bool RenderView::runFileChooser( |
2426 const WebKit::WebFileChooserParams& params, | 2425 const WebKit::WebFileChooserParams& params, |
2427 WebFileChooserCompletion* chooser_completion) { | 2426 WebFileChooserCompletion* chooser_completion) { |
2428 // Do not open the file dialog in a hidden RenderView. | 2427 // Do not open the file dialog in a hidden RenderView. |
2429 if (is_hidden()) | 2428 if (is_hidden()) |
2430 return false; | 2429 return false; |
2431 ViewHostMsg_RunFileChooser_Params ipc_params; | 2430 ViewHostMsg_RunFileChooser_Params ipc_params; |
2432 if (params.directory) | 2431 if (params.directory) |
2433 ipc_params.mode = ViewHostMsg_RunFileChooser_Params::OpenFolder; | 2432 ipc_params.mode = ViewHostMsg_RunFileChooser_Params::OpenFolder; |
2434 else if (params.multiSelect) | 2433 else if (params.multiSelect) |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2541 // any existing pending sends. | 2540 // any existing pending sends. |
2542 pending_target_url_ = latest_url; | 2541 pending_target_url_ = latest_url; |
2543 target_url_status_ = TARGET_PENDING; | 2542 target_url_status_ = TARGET_PENDING; |
2544 } else { | 2543 } else { |
2545 Send(new ViewHostMsg_UpdateTargetURL(routing_id_, page_id_, latest_url)); | 2544 Send(new ViewHostMsg_UpdateTargetURL(routing_id_, page_id_, latest_url)); |
2546 target_url_ = latest_url; | 2545 target_url_ = latest_url; |
2547 target_url_status_ = TARGET_INFLIGHT; | 2546 target_url_status_ = TARGET_INFLIGHT; |
2548 } | 2547 } |
2549 } | 2548 } |
2550 | 2549 |
2550 void RenderView::UpdateToggleSpellCheckCommandState() { | |
2551 bool is_enabled = false; | |
2552 linked_ptr<WebKit::WebNode> node = GetFocusedNode(); | |
2553 if (node != NULL) | |
2554 is_enabled = IsEditableNode(*node); | |
2555 | |
2556 RenderViewCommandCheckedState checked_state = | |
2557 RENDER_VIEW_COMMAND_CHECKED_STATE_UNCHECKED; | |
2558 if (is_enabled && webview()) { | |
2559 WebFrame* frame = webview()->focusedFrame(); | |
2560 if (frame->isContinuousSpellCheckingEnabled()) | |
2561 checked_state = RENDER_VIEW_COMMAND_CHECKED_STATE_CHECKED; | |
2562 } | |
2563 | |
2564 Send(new ViewHostMsg_CommandStateChanged( | |
2565 routing_id_, | |
2566 RENDER_VIEW_COMMAND_TOGGLE_SPELL_CHECK, | |
2567 is_enabled, | |
2568 checked_state)); | |
2569 } | |
2570 | |
2551 void RenderView::StartNavStateSyncTimerIfNecessary() { | 2571 void RenderView::StartNavStateSyncTimerIfNecessary() { |
2552 int delay; | 2572 int delay; |
2553 if (send_content_state_immediately_) | 2573 if (send_content_state_immediately_) |
2554 delay = 0; | 2574 delay = 0; |
2555 else if (is_hidden()) | 2575 else if (is_hidden()) |
2556 delay = kDelaySecondsForContentStateSyncHidden; | 2576 delay = kDelaySecondsForContentStateSyncHidden; |
2557 else | 2577 else |
2558 delay = kDelaySecondsForContentStateSync; | 2578 delay = kDelaySecondsForContentStateSync; |
2559 | 2579 |
2560 if (nav_state_sync_timer_.IsRunning()) { | 2580 if (nav_state_sync_timer_.IsRunning()) { |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2617 void RenderView::focusedNodeChanged(const WebNode& node) { | 2637 void RenderView::focusedNodeChanged(const WebNode& node) { |
2618 Send(new ViewHostMsg_FocusedNodeChanged(routing_id_, IsEditableNode(node))); | 2638 Send(new ViewHostMsg_FocusedNodeChanged(routing_id_, IsEditableNode(node))); |
2619 | 2639 |
2620 if (WebAccessibilityCache::accessibilityEnabled() && node.isNull()) { | 2640 if (WebAccessibilityCache::accessibilityEnabled() && node.isNull()) { |
2621 // TODO(ctguil): Make WebKit send this notification. | 2641 // TODO(ctguil): Make WebKit send this notification. |
2622 // When focus is cleared notify accessibility that the document is focused. | 2642 // When focus is cleared notify accessibility that the document is focused. |
2623 postAccessibilityNotification( | 2643 postAccessibilityNotification( |
2624 webview()->accessibilityObject(), | 2644 webview()->accessibilityObject(), |
2625 WebKit::WebAccessibilityNotificationFocusedUIElementChanged); | 2645 WebKit::WebAccessibilityNotificationFocusedUIElementChanged); |
2626 } | 2646 } |
2647 | |
2648 UpdateToggleSpellCheckCommandState(); | |
2627 } | 2649 } |
2628 | 2650 |
2629 void RenderView::navigateBackForwardSoon(int offset) { | 2651 void RenderView::navigateBackForwardSoon(int offset) { |
2630 Send(new ViewHostMsg_GoToEntryAtOffset(routing_id_, offset)); | 2652 Send(new ViewHostMsg_GoToEntryAtOffset(routing_id_, offset)); |
2631 } | 2653 } |
2632 | 2654 |
2633 int RenderView::historyBackListCount() { | 2655 int RenderView::historyBackListCount() { |
2634 return history_list_offset_ < 0 ? 0 : history_list_offset_; | 2656 return history_list_offset_ < 0 ? 0 : history_list_offset_; |
2635 } | 2657 } |
2636 | 2658 |
(...skipping 1952 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
4589 xpath_remaining.erase(0, delim_pos + 1); | 4611 xpath_remaining.erase(0, delim_pos + 1); |
4590 } else { | 4612 } else { |
4591 xpath_remaining.swap(xpath_child); | 4613 xpath_remaining.swap(xpath_child); |
4592 } | 4614 } |
4593 frame = frame->findChildByExpression(WideToUTF16Hack(xpath_child)); | 4615 frame = frame->findChildByExpression(WideToUTF16Hack(xpath_child)); |
4594 } | 4616 } |
4595 | 4617 |
4596 return frame; | 4618 return frame; |
4597 } | 4619 } |
4598 | 4620 |
4621 linked_ptr<WebNode> RenderView::GetFocusedNode() const { | |
brettw
2011/01/18 18:25:43
I've never seen us use linked_ptr in this context.
sail
2011/01/18 18:41:13
Hm.. but then I wouldn't be able to indicate that
brettw
2011/01/18 18:44:17
It has an IsNull function and you can make isNull
sail
2011/01/18 19:09:17
Ahh, that's awesome. I should have seen that earli
| |
4622 if (!webview()) | |
4623 return linked_ptr<WebNode>(); | |
4624 WebFrame* focused_frame = webview()->focusedFrame(); | |
4625 if (focused_frame) { | |
4626 WebDocument doc = focused_frame->document(); | |
4627 if (!doc.isNull()) { | |
4628 return linked_ptr<WebNode>(new WebNode(doc.focusedNode())); | |
4629 } | |
4630 } | |
4631 | |
4632 return linked_ptr<WebNode>(); | |
4633 } | |
4634 | |
4599 void RenderView::SetSuggestions(const std::vector<std::string>& suggestions) { | 4635 void RenderView::SetSuggestions(const std::vector<std::string>& suggestions) { |
4600 // Explicitly allow empty vector to be sent to the browser. | 4636 // Explicitly allow empty vector to be sent to the browser. |
4601 Send(new ViewHostMsg_SetSuggestions(routing_id_, page_id_, suggestions)); | 4637 Send(new ViewHostMsg_SetSuggestions(routing_id_, page_id_, suggestions)); |
4602 } | 4638 } |
4603 | 4639 |
4604 void RenderView::EvaluateScript(const string16& frame_xpath, | 4640 void RenderView::EvaluateScript(const string16& frame_xpath, |
4605 const string16& script, | 4641 const string16& script, |
4606 int id, | 4642 int id, |
4607 bool notify_result) { | 4643 bool notify_result) { |
4608 v8::Handle<v8::Value> result; | 4644 v8::Handle<v8::Value> result; |
(...skipping 1183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
5792 } | 5828 } |
5793 #endif | 5829 #endif |
5794 | 5830 |
5795 void RenderView::OnJavaScriptStressTestControl(int cmd, int param) { | 5831 void RenderView::OnJavaScriptStressTestControl(int cmd, int param) { |
5796 if (cmd == kJavaScriptStressTestSetStressRunType) { | 5832 if (cmd == kJavaScriptStressTestSetStressRunType) { |
5797 v8::Testing::SetStressRunType(static_cast<v8::Testing::StressType>(param)); | 5833 v8::Testing::SetStressRunType(static_cast<v8::Testing::StressType>(param)); |
5798 } else if (cmd == kJavaScriptStressTestPrepareStressRun) { | 5834 } else if (cmd == kJavaScriptStressTestPrepareStressRun) { |
5799 v8::Testing::PrepareStressRun(param); | 5835 v8::Testing::PrepareStressRun(param); |
5800 } | 5836 } |
5801 } | 5837 } |
OLD | NEW |