OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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_frame_impl.h" | 5 #include "content/renderer/render_frame_impl.h" |
6 | 6 |
7 #include <map> | 7 #include <map> |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/auto_reset.h" | 10 #include "base/auto_reset.h" |
(...skipping 1073 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1084 base::TrimWhitespace(selection_text.substr(start, length), base::TRIM_ALL, | 1084 base::TrimWhitespace(selection_text.substr(start, length), base::TRIM_ALL, |
1085 &trimmed_selection_text); | 1085 &trimmed_selection_text); |
1086 } | 1086 } |
1087 } | 1087 } |
1088 base::string16 trimmed_params_text; | 1088 base::string16 trimmed_params_text; |
1089 base::TrimWhitespace(params.selection_text, base::TRIM_ALL, | 1089 base::TrimWhitespace(params.selection_text, base::TRIM_ALL, |
1090 &trimmed_params_text); | 1090 &trimmed_params_text); |
1091 return trimmed_params_text != trimmed_selection_text; | 1091 return trimmed_params_text != trimmed_selection_text; |
1092 } | 1092 } |
1093 | 1093 |
| 1094 bool RenderFrameImpl::RunJavaScriptMessage(JavaScriptMessageType type, |
| 1095 const base::string16& message, |
| 1096 const base::string16& default_value, |
| 1097 const GURL& frame_url, |
| 1098 base::string16* result) { |
| 1099 // Don't allow further dialogs if we are waiting to swap out, since the |
| 1100 // PageGroupLoadDeferrer in our stack prevents it. |
| 1101 if (render_view()->suppress_dialogs_until_swap_out_) |
| 1102 return false; |
| 1103 |
| 1104 bool success = false; |
| 1105 base::string16 result_temp; |
| 1106 if (!result) |
| 1107 result = &result_temp; |
| 1108 |
| 1109 render_view()->SendAndRunNestedMessageLoop( |
| 1110 new FrameHostMsg_RunJavaScriptMessage( |
| 1111 routing_id_, message, default_value, frame_url, type, &success, |
| 1112 result)); |
| 1113 return success; |
| 1114 } |
| 1115 |
1094 void RenderFrameImpl::DidCommitCompositorFrame() { | 1116 void RenderFrameImpl::DidCommitCompositorFrame() { |
1095 if (compositing_helper_) | 1117 if (compositing_helper_) |
1096 compositing_helper_->DidCommitCompositorFrame(); | 1118 compositing_helper_->DidCommitCompositorFrame(); |
1097 } | 1119 } |
1098 | 1120 |
1099 RenderView* RenderFrameImpl::GetRenderView() { | 1121 RenderView* RenderFrameImpl::GetRenderView() { |
1100 return render_view_.get(); | 1122 return render_view_.get(); |
1101 } | 1123 } |
1102 | 1124 |
1103 int RenderFrameImpl::GetRoutingID() { | 1125 int RenderFrameImpl::GetRoutingID() { |
(...skipping 905 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2009 // was changed, and SyncSelectionIfRequired may send SelectionChanged | 2031 // was changed, and SyncSelectionIfRequired may send SelectionChanged |
2010 // to notify the selection was changed. Focus change should be notified | 2032 // to notify the selection was changed. Focus change should be notified |
2011 // before selection change. | 2033 // before selection change. |
2012 GetRenderWidget()->UpdateTextInputType(); | 2034 GetRenderWidget()->UpdateTextInputType(); |
2013 SyncSelectionIfRequired(); | 2035 SyncSelectionIfRequired(); |
2014 #if defined(OS_ANDROID) | 2036 #if defined(OS_ANDROID) |
2015 GetRenderWidget()->UpdateTextInputState(false, true); | 2037 GetRenderWidget()->UpdateTextInputState(false, true); |
2016 #endif | 2038 #endif |
2017 } | 2039 } |
2018 | 2040 |
| 2041 void RenderFrameImpl::runModalAlertDialog(const blink::WebString& message) { |
| 2042 RunJavaScriptMessage(JAVASCRIPT_MESSAGE_TYPE_ALERT, |
| 2043 message, |
| 2044 base::string16(), |
| 2045 frame_->document().url(), |
| 2046 NULL); |
| 2047 } |
| 2048 |
| 2049 bool RenderFrameImpl::runModalConfirmDialog(const blink::WebString& message) { |
| 2050 return RunJavaScriptMessage(JAVASCRIPT_MESSAGE_TYPE_CONFIRM, |
| 2051 message, |
| 2052 base::string16(), |
| 2053 frame_->document().url(), |
| 2054 NULL); |
| 2055 } |
| 2056 |
| 2057 bool RenderFrameImpl::runModalPromptDialog( |
| 2058 const blink::WebString& message, |
| 2059 const blink::WebString& default_value, |
| 2060 blink::WebString* actual_value) { |
| 2061 base::string16 result; |
| 2062 bool ok = RunJavaScriptMessage(JAVASCRIPT_MESSAGE_TYPE_PROMPT, |
| 2063 message, |
| 2064 default_value, |
| 2065 frame_->document().url(), |
| 2066 &result); |
| 2067 if (ok) |
| 2068 actual_value->assign(result); |
| 2069 return ok; |
| 2070 } |
| 2071 |
| 2072 bool RenderFrameImpl::runModalBeforeUnloadDialog( |
| 2073 bool is_reload, |
| 2074 const blink::WebString& message) { |
| 2075 // If we are swapping out, we have already run the beforeunload handler. |
| 2076 // TODO(creis): Fix OnSwapOut to clear the frame without running beforeunload |
| 2077 // at all, to avoid running it twice. |
| 2078 if (render_view()->is_swapped_out_) |
| 2079 return true; |
| 2080 |
| 2081 // Don't allow further dialogs if we are waiting to swap out, since the |
| 2082 // PageGroupLoadDeferrer in our stack prevents it. |
| 2083 if (render_view()->suppress_dialogs_until_swap_out_) |
| 2084 return false; |
| 2085 |
| 2086 bool success = false; |
| 2087 // This is an ignored return value, but is included so we can accept the same |
| 2088 // response as RunJavaScriptMessage. |
| 2089 base::string16 ignored_result; |
| 2090 render_view()->SendAndRunNestedMessageLoop( |
| 2091 new FrameHostMsg_RunBeforeUnloadConfirm( |
| 2092 routing_id_, frame_->document().url(), message, is_reload, |
| 2093 &success, &ignored_result)); |
| 2094 return success; |
| 2095 } |
| 2096 |
2019 void RenderFrameImpl::showContextMenu(const blink::WebContextMenuData& data) { | 2097 void RenderFrameImpl::showContextMenu(const blink::WebContextMenuData& data) { |
2020 ContextMenuParams params = ContextMenuParamsBuilder::Build(data); | 2098 ContextMenuParams params = ContextMenuParamsBuilder::Build(data); |
2021 params.source_type = GetRenderWidget()->context_menu_source_type(); | 2099 params.source_type = GetRenderWidget()->context_menu_source_type(); |
2022 if (params.source_type == ui::MENU_SOURCE_TOUCH_EDIT_MENU) { | 2100 if (params.source_type == ui::MENU_SOURCE_TOUCH_EDIT_MENU) { |
2023 params.x = GetRenderWidget()->touch_editing_context_menu_location().x(); | 2101 params.x = GetRenderWidget()->touch_editing_context_menu_location().x(); |
2024 params.y = GetRenderWidget()->touch_editing_context_menu_location().y(); | 2102 params.y = GetRenderWidget()->touch_editing_context_menu_location().y(); |
2025 } | 2103 } |
2026 GetRenderWidget()->OnShowHostContextMenu(¶ms); | 2104 GetRenderWidget()->OnShowHostContextMenu(¶ms); |
2027 | 2105 |
2028 // Plugins, e.g. PDF, don't currently update the render view when their | 2106 // Plugins, e.g. PDF, don't currently update the render view when their |
(...skipping 1049 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3078 selection_text_offset_ = offset; | 3156 selection_text_offset_ = offset; |
3079 selection_range_ = range; | 3157 selection_range_ = range; |
3080 // This IPC is dispatched by RenderWidetHost, so use its routing ID. | 3158 // This IPC is dispatched by RenderWidetHost, so use its routing ID. |
3081 Send(new ViewHostMsg_SelectionChanged( | 3159 Send(new ViewHostMsg_SelectionChanged( |
3082 GetRenderWidget()->routing_id(), text, offset, range)); | 3160 GetRenderWidget()->routing_id(), text, offset, range)); |
3083 } | 3161 } |
3084 GetRenderWidget()->UpdateSelectionBounds(); | 3162 GetRenderWidget()->UpdateSelectionBounds(); |
3085 } | 3163 } |
3086 | 3164 |
3087 } // namespace content | 3165 } // namespace content |
OLD | NEW |