Chromium Code Reviews| 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 1572 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1626 UserMetricsRecordAction("SelectAll"); | 1627 UserMetricsRecordAction("SelectAll"); |
| 1627 } | 1628 } |
| 1628 | 1629 |
| 1629 void RenderView::OnSetInitialFocus(bool reverse) { | 1630 void RenderView::OnSetInitialFocus(bool reverse) { |
| 1630 if (!webview()) | 1631 if (!webview()) |
| 1631 return; | 1632 return; |
| 1632 webview()->setInitialFocus(reverse); | 1633 webview()->setInitialFocus(reverse); |
| 1633 } | 1634 } |
| 1634 | 1635 |
| 1635 void RenderView::OnScrollFocusedEditableNodeIntoView() { | 1636 void RenderView::OnScrollFocusedEditableNodeIntoView() { |
| 1636 if (!webview()) | 1637 WebNode node; |
| 1637 return; | 1638 if (GetFocusedNode(node)) { |
| 1638 WebFrame* focused_frame = webview()->focusedFrame(); | 1639 if (IsEditableNode(node)) |
| 1639 if (focused_frame) { | 1640 // TODO(varunjain): Change webkit API to scroll a particular node into |
| 1640 WebDocument doc = focused_frame->document(); | 1641 // view and use that API here instead. |
| 1641 if (!doc.isNull()) { | 1642 webview()->scrollFocusedNodeIntoView(); |
| 1642 WebNode node = doc.focusedNode(); | |
| 1643 if (IsEditableNode(node)) | |
| 1644 // TODO(varunjain): Change webkit API to scroll a particular node into | |
| 1645 // view and use that API here instead. | |
| 1646 webview()->scrollFocusedNodeIntoView(); | |
| 1647 } | |
| 1648 } | 1643 } |
| 1649 } | 1644 } |
| 1650 | 1645 |
| 1651 /////////////////////////////////////////////////////////////////////////////// | 1646 /////////////////////////////////////////////////////////////////////////////// |
| 1652 | 1647 |
| 1653 void RenderView::SetContentSettings(const ContentSettings& settings) { | 1648 void RenderView::SetContentSettings(const ContentSettings& settings) { |
| 1654 current_content_settings_ = settings; | 1649 current_content_settings_ = settings; |
| 1655 } | 1650 } |
| 1656 | 1651 |
| 1657 // Tell the embedding application that the URL of the active page has changed | 1652 // 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... | |
| 2407 | 2402 |
| 2408 bool RenderView::isShowingSpellingUI() { | 2403 bool RenderView::isShowingSpellingUI() { |
| 2409 return spelling_panel_visible_; | 2404 return spelling_panel_visible_; |
| 2410 } | 2405 } |
| 2411 | 2406 |
| 2412 void RenderView::updateSpellingUIWithMisspelledWord(const WebString& word) { | 2407 void RenderView::updateSpellingUIWithMisspelledWord(const WebString& word) { |
| 2413 Send(new ViewHostMsg_UpdateSpellingPanelWithMisspelledWord(routing_id_, | 2408 Send(new ViewHostMsg_UpdateSpellingPanelWithMisspelledWord(routing_id_, |
| 2414 word)); | 2409 word)); |
| 2415 } | 2410 } |
| 2416 | 2411 |
| 2412 void RenderView::continuousSpellCheckingEnabledStateChanged() { | |
| 2413 UpdateToggleSpellCheckCommandState(); | |
| 2414 } | |
| 2415 | |
| 2417 bool RenderView::runFileChooser( | 2416 bool RenderView::runFileChooser( |
| 2418 const WebKit::WebFileChooserParams& params, | 2417 const WebKit::WebFileChooserParams& params, |
| 2419 WebFileChooserCompletion* chooser_completion) { | 2418 WebFileChooserCompletion* chooser_completion) { |
| 2420 // Do not open the file dialog in a hidden RenderView. | 2419 // Do not open the file dialog in a hidden RenderView. |
| 2421 if (is_hidden()) | 2420 if (is_hidden()) |
| 2422 return false; | 2421 return false; |
| 2423 ViewHostMsg_RunFileChooser_Params ipc_params; | 2422 ViewHostMsg_RunFileChooser_Params ipc_params; |
| 2424 if (params.directory) | 2423 if (params.directory) |
| 2425 ipc_params.mode = ViewHostMsg_RunFileChooser_Params::OpenFolder; | 2424 ipc_params.mode = ViewHostMsg_RunFileChooser_Params::OpenFolder; |
| 2426 else if (params.multiSelect) | 2425 else if (params.multiSelect) |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2533 // any existing pending sends. | 2532 // any existing pending sends. |
| 2534 pending_target_url_ = latest_url; | 2533 pending_target_url_ = latest_url; |
| 2535 target_url_status_ = TARGET_PENDING; | 2534 target_url_status_ = TARGET_PENDING; |
| 2536 } else { | 2535 } else { |
| 2537 Send(new ViewHostMsg_UpdateTargetURL(routing_id_, page_id_, latest_url)); | 2536 Send(new ViewHostMsg_UpdateTargetURL(routing_id_, page_id_, latest_url)); |
| 2538 target_url_ = latest_url; | 2537 target_url_ = latest_url; |
| 2539 target_url_status_ = TARGET_INFLIGHT; | 2538 target_url_status_ = TARGET_INFLIGHT; |
| 2540 } | 2539 } |
| 2541 } | 2540 } |
| 2542 | 2541 |
| 2542 void RenderView::UpdateToggleSpellCheckCommandState() { | |
| 2543 bool is_enabled = false; | |
| 2544 WebNode node; | |
| 2545 if (GetFocusedNode(node)) | |
| 2546 is_enabled = IsEditableNode(node); | |
| 2547 | |
| 2548 CommandCheckedState checked_state = COMMAND_CHECKED_STATE_UNCHECKED; | |
| 2549 if (is_enabled && webview()) { | |
| 2550 WebFrame* frame = webview()->focusedFrame(); | |
| 2551 if (frame->isContinuousSpellCheckingEnabled()) { | |
|
brettw
2011/01/13 05:59:55
Use {} for single-line conditionals consistently.
sail
2011/01/13 23:38:15
Done.
| |
| 2552 checked_state = COMMAND_CHECKED_STATE_CHECKED; | |
| 2553 } | |
| 2554 } | |
| 2555 | |
| 2556 Send(new ViewHostMsg_CommandStateChanged( | |
| 2557 routing_id_, | |
| 2558 RENDER_VIEW_COMMAND_TOGGLE_SPELL_CHECK, | |
| 2559 is_enabled, | |
| 2560 checked_state)); | |
| 2561 } | |
| 2562 | |
| 2543 void RenderView::StartNavStateSyncTimerIfNecessary() { | 2563 void RenderView::StartNavStateSyncTimerIfNecessary() { |
| 2544 int delay; | 2564 int delay; |
| 2545 if (send_content_state_immediately_) | 2565 if (send_content_state_immediately_) |
| 2546 delay = 0; | 2566 delay = 0; |
| 2547 else if (is_hidden()) | 2567 else if (is_hidden()) |
| 2548 delay = kDelaySecondsForContentStateSyncHidden; | 2568 delay = kDelaySecondsForContentStateSyncHidden; |
| 2549 else | 2569 else |
| 2550 delay = kDelaySecondsForContentStateSync; | 2570 delay = kDelaySecondsForContentStateSync; |
| 2551 | 2571 |
| 2552 if (nav_state_sync_timer_.IsRunning()) { | 2572 if (nav_state_sync_timer_.IsRunning()) { |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2609 void RenderView::focusedNodeChanged(const WebNode& node) { | 2629 void RenderView::focusedNodeChanged(const WebNode& node) { |
| 2610 Send(new ViewHostMsg_FocusedNodeChanged(routing_id_, IsEditableNode(node))); | 2630 Send(new ViewHostMsg_FocusedNodeChanged(routing_id_, IsEditableNode(node))); |
| 2611 | 2631 |
| 2612 if (WebAccessibilityCache::accessibilityEnabled() && node.isNull()) { | 2632 if (WebAccessibilityCache::accessibilityEnabled() && node.isNull()) { |
| 2613 // TODO(ctguil): Make WebKit send this notification. | 2633 // TODO(ctguil): Make WebKit send this notification. |
| 2614 // When focus is cleared notify accessibility that the document is focused. | 2634 // When focus is cleared notify accessibility that the document is focused. |
| 2615 postAccessibilityNotification( | 2635 postAccessibilityNotification( |
| 2616 webview()->accessibilityObject(), | 2636 webview()->accessibilityObject(), |
| 2617 WebKit::WebAccessibilityNotificationFocusedUIElementChanged); | 2637 WebKit::WebAccessibilityNotificationFocusedUIElementChanged); |
| 2618 } | 2638 } |
| 2639 | |
| 2640 UpdateToggleSpellCheckCommandState(); | |
| 2619 } | 2641 } |
| 2620 | 2642 |
| 2621 void RenderView::navigateBackForwardSoon(int offset) { | 2643 void RenderView::navigateBackForwardSoon(int offset) { |
| 2622 Send(new ViewHostMsg_GoToEntryAtOffset(routing_id_, offset)); | 2644 Send(new ViewHostMsg_GoToEntryAtOffset(routing_id_, offset)); |
| 2623 } | 2645 } |
| 2624 | 2646 |
| 2625 int RenderView::historyBackListCount() { | 2647 int RenderView::historyBackListCount() { |
| 2626 return history_list_offset_ < 0 ? 0 : history_list_offset_; | 2648 return history_list_offset_ < 0 ? 0 : history_list_offset_; |
| 2627 } | 2649 } |
| 2628 | 2650 |
| (...skipping 1952 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 4581 xpath_remaining.erase(0, delim_pos + 1); | 4603 xpath_remaining.erase(0, delim_pos + 1); |
| 4582 } else { | 4604 } else { |
| 4583 xpath_remaining.swap(xpath_child); | 4605 xpath_remaining.swap(xpath_child); |
| 4584 } | 4606 } |
| 4585 frame = frame->findChildByExpression(WideToUTF16Hack(xpath_child)); | 4607 frame = frame->findChildByExpression(WideToUTF16Hack(xpath_child)); |
| 4586 } | 4608 } |
| 4587 | 4609 |
| 4588 return frame; | 4610 return frame; |
| 4589 } | 4611 } |
| 4590 | 4612 |
| 4613 bool RenderView::GetFocusedNode(WebNode& node) const { | |
| 4614 if (!webview()) | |
| 4615 return false; | |
| 4616 WebFrame* focused_frame = webview()->focusedFrame(); | |
| 4617 if (focused_frame) { | |
| 4618 WebDocument doc = focused_frame->document(); | |
| 4619 if (!doc.isNull()) { | |
| 4620 node = doc.focusedNode(); | |
| 4621 return true; | |
| 4622 } | |
| 4623 } | |
| 4624 | |
| 4625 return false; | |
| 4626 } | |
| 4627 | |
| 4591 void RenderView::SetSuggestions(const std::vector<std::string>& suggestions) { | 4628 void RenderView::SetSuggestions(const std::vector<std::string>& suggestions) { |
| 4592 // Explicitly allow empty vector to be sent to the browser. | 4629 // Explicitly allow empty vector to be sent to the browser. |
| 4593 Send(new ViewHostMsg_SetSuggestions(routing_id_, page_id_, suggestions)); | 4630 Send(new ViewHostMsg_SetSuggestions(routing_id_, page_id_, suggestions)); |
| 4594 } | 4631 } |
| 4595 | 4632 |
| 4596 void RenderView::EvaluateScript(const string16& frame_xpath, | 4633 void RenderView::EvaluateScript(const string16& frame_xpath, |
| 4597 const string16& script, | 4634 const string16& script, |
| 4598 int id, | 4635 int id, |
| 4599 bool notify_result) { | 4636 bool notify_result) { |
| 4600 v8::Handle<v8::Value> result; | 4637 v8::Handle<v8::Value> result; |
| (...skipping 1186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 5787 } | 5824 } |
| 5788 #endif | 5825 #endif |
| 5789 | 5826 |
| 5790 void RenderView::OnJavaScriptStressTestControl(int cmd, int param) { | 5827 void RenderView::OnJavaScriptStressTestControl(int cmd, int param) { |
| 5791 if (cmd == kJavaScriptStressTestSetStressRunType) { | 5828 if (cmd == kJavaScriptStressTestSetStressRunType) { |
| 5792 v8::Testing::SetStressRunType(static_cast<v8::Testing::StressType>(param)); | 5829 v8::Testing::SetStressRunType(static_cast<v8::Testing::StressType>(param)); |
| 5793 } else if (cmd == kJavaScriptStressTestPrepareStressRun) { | 5830 } else if (cmd == kJavaScriptStressTestPrepareStressRun) { |
| 5794 v8::Testing::PrepareStressRun(param); | 5831 v8::Testing::PrepareStressRun(param); |
| 5795 } | 5832 } |
| 5796 } | 5833 } |
| OLD | NEW |