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 #include <utility> | 9 #include <utility> |
10 #include <vector> | 10 #include <vector> |
(...skipping 1363 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1374 #if defined(OS_MACOSX) || defined(USE_AURA) | 1374 #if defined(OS_MACOSX) || defined(USE_AURA) |
1375 GetRenderWidget()->UpdateCompositionInfo( | 1375 GetRenderWidget()->UpdateCompositionInfo( |
1376 false /* not an immediate request */); | 1376 false /* not an immediate request */); |
1377 #endif | 1377 #endif |
1378 } | 1378 } |
1379 | 1379 |
1380 void RenderFrameImpl::PepperSelectionChanged( | 1380 void RenderFrameImpl::PepperSelectionChanged( |
1381 PepperPluginInstanceImpl* instance) { | 1381 PepperPluginInstanceImpl* instance) { |
1382 if (instance != focused_pepper_plugin_) | 1382 if (instance != focused_pepper_plugin_) |
1383 return; | 1383 return; |
1384 SyncSelectionIfRequired(); | 1384 // Keep the original behavior for pepper plugins and handle all selection |
| 1385 // change as user initiated. |
| 1386 SyncSelectionIfRequired(true); |
1385 } | 1387 } |
1386 | 1388 |
1387 RenderWidgetFullscreenPepper* RenderFrameImpl::CreatePepperFullscreenContainer( | 1389 RenderWidgetFullscreenPepper* RenderFrameImpl::CreatePepperFullscreenContainer( |
1388 PepperPluginInstanceImpl* plugin) { | 1390 PepperPluginInstanceImpl* plugin) { |
1389 GURL active_url; | 1391 GURL active_url; |
1390 if (render_view()->webview()) | 1392 if (render_view()->webview()) |
1391 active_url = render_view()->GetURLForGraphicsContext3D(); | 1393 active_url = render_view()->GetURLForGraphicsContext3D(); |
1392 | 1394 |
1393 // Synchronous IPC to obtain a routing id for the fullscreen widget. | 1395 // Synchronous IPC to obtain a routing id for the fullscreen widget. |
1394 int32_t fullscreen_widget_routing_id = MSG_ROUTING_NONE; | 1396 int32_t fullscreen_widget_routing_id = MSG_ROUTING_NONE; |
(...skipping 569 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1964 base::AutoReset<bool> handling_select_range(&handling_select_range_, true); | 1966 base::AutoReset<bool> handling_select_range(&handling_select_range_, true); |
1965 frame_->MoveRangeSelectionExtent( | 1967 frame_->MoveRangeSelectionExtent( |
1966 render_view_->ConvertWindowPointToViewport(point)); | 1968 render_view_->ConvertWindowPointToViewport(point)); |
1967 } | 1969 } |
1968 | 1970 |
1969 void RenderFrameImpl::OnReplace(const base::string16& text) { | 1971 void RenderFrameImpl::OnReplace(const base::string16& text) { |
1970 if (!frame_->HasSelection()) | 1972 if (!frame_->HasSelection()) |
1971 frame_->SelectWordAroundCaret(); | 1973 frame_->SelectWordAroundCaret(); |
1972 | 1974 |
1973 frame_->ReplaceSelection(WebString::FromUTF16(text)); | 1975 frame_->ReplaceSelection(WebString::FromUTF16(text)); |
1974 SyncSelectionIfRequired(); | 1976 // Handle this selection change as user initiated since typically triggered |
| 1977 // from context menu. |
| 1978 SyncSelectionIfRequired(true); |
1975 } | 1979 } |
1976 | 1980 |
1977 void RenderFrameImpl::OnReplaceMisspelling(const base::string16& text) { | 1981 void RenderFrameImpl::OnReplaceMisspelling(const base::string16& text) { |
1978 if (!frame_->HasSelection()) | 1982 if (!frame_->HasSelection()) |
1979 return; | 1983 return; |
1980 | 1984 |
1981 frame_->ReplaceMisspelledRange(WebString::FromUTF16(text)); | 1985 frame_->ReplaceMisspelledRange(WebString::FromUTF16(text)); |
1982 } | 1986 } |
1983 | 1987 |
1984 void RenderFrameImpl::OnCopyImageAt(int x, int y) { | 1988 void RenderFrameImpl::OnCopyImageAt(int x, int y) { |
(...skipping 660 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2645 void RenderFrameImpl::AttachGuest(int element_instance_id) { | 2649 void RenderFrameImpl::AttachGuest(int element_instance_id) { |
2646 BrowserPluginManager::Get()->Attach(element_instance_id); | 2650 BrowserPluginManager::Get()->Attach(element_instance_id); |
2647 } | 2651 } |
2648 | 2652 |
2649 void RenderFrameImpl::DetachGuest(int element_instance_id) { | 2653 void RenderFrameImpl::DetachGuest(int element_instance_id) { |
2650 BrowserPluginManager::Get()->Detach(element_instance_id); | 2654 BrowserPluginManager::Get()->Detach(element_instance_id); |
2651 } | 2655 } |
2652 | 2656 |
2653 void RenderFrameImpl::SetSelectedText(const base::string16& selection_text, | 2657 void RenderFrameImpl::SetSelectedText(const base::string16& selection_text, |
2654 size_t offset, | 2658 size_t offset, |
2655 const gfx::Range& range) { | 2659 const gfx::Range& range, |
| 2660 bool user_initiated) { |
2656 Send(new FrameHostMsg_SelectionChanged(routing_id_, selection_text, | 2661 Send(new FrameHostMsg_SelectionChanged(routing_id_, selection_text, |
2657 static_cast<uint32_t>(offset), range)); | 2662 static_cast<uint32_t>(offset), range, |
| 2663 user_initiated)); |
2658 } | 2664 } |
2659 | 2665 |
2660 void RenderFrameImpl::EnsureMojoBuiltinsAreAvailable( | 2666 void RenderFrameImpl::EnsureMojoBuiltinsAreAvailable( |
2661 v8::Isolate* isolate, | 2667 v8::Isolate* isolate, |
2662 v8::Local<v8::Context> context) { | 2668 v8::Local<v8::Context> context) { |
2663 gin::ModuleRegistry* registry = gin::ModuleRegistry::From(context); | 2669 gin::ModuleRegistry* registry = gin::ModuleRegistry::From(context); |
2664 if (registry->available_modules().count(mojo::edk::js::Core::kModuleName)) | 2670 if (registry->available_modules().count(mojo::edk::js::Core::kModuleName)) |
2665 return; | 2671 return; |
2666 | 2672 |
2667 v8::HandleScope handle_scope(isolate); | 2673 v8::HandleScope handle_scope(isolate); |
(...skipping 1504 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4172 blink::WebEffectiveConnectionType | 4178 blink::WebEffectiveConnectionType |
4173 RenderFrameImpl::GetEffectiveConnectionType() { | 4179 RenderFrameImpl::GetEffectiveConnectionType() { |
4174 return effective_connection_type_; | 4180 return effective_connection_type_; |
4175 } | 4181 } |
4176 | 4182 |
4177 void RenderFrameImpl::AbortClientNavigation() { | 4183 void RenderFrameImpl::AbortClientNavigation() { |
4178 Send(new FrameHostMsg_AbortNavigation(routing_id_)); | 4184 Send(new FrameHostMsg_AbortNavigation(routing_id_)); |
4179 } | 4185 } |
4180 | 4186 |
4181 void RenderFrameImpl::DidChangeSelection(bool is_empty_selection) { | 4187 void RenderFrameImpl::DidChangeSelection(bool is_empty_selection) { |
4182 if (!GetRenderWidget()->input_handler().handling_input_event() && | 4188 bool user_initiated = |
4183 !handling_select_range_) | 4189 GetRenderWidget()->input_handler().handling_input_event() || |
4184 return; | 4190 handling_select_range_; |
4185 | 4191 |
4186 if (is_empty_selection) | 4192 if (is_empty_selection) |
4187 selection_text_.clear(); | 4193 selection_text_.clear(); |
4188 | 4194 |
4189 // UpdateTextInputState should be called before SyncSelectionIfRequired. | 4195 // UpdateTextInputState should be called before SyncSelectionIfRequired. |
4190 // UpdateTextInputState may send TextInputStateChanged to notify the focus | 4196 // UpdateTextInputState may send TextInputStateChanged to notify the focus |
4191 // was changed, and SyncSelectionIfRequired may send SelectionChanged | 4197 // was changed, and SyncSelectionIfRequired may send SelectionChanged |
4192 // to notify the selection was changed. Focus change should be notified | 4198 // to notify the selection was changed. Focus change should be notified |
4193 // before selection change. | 4199 // before selection change. |
4194 GetRenderWidget()->UpdateTextInputState(); | 4200 GetRenderWidget()->UpdateTextInputState(); |
4195 SyncSelectionIfRequired(); | 4201 SyncSelectionIfRequired(user_initiated); |
4196 } | 4202 } |
4197 | 4203 |
4198 bool RenderFrameImpl::HandleCurrentKeyboardEvent() { | 4204 bool RenderFrameImpl::HandleCurrentKeyboardEvent() { |
4199 bool did_execute_command = false; | 4205 bool did_execute_command = false; |
4200 for (auto command : GetRenderWidget()->edit_commands()) { | 4206 for (auto command : GetRenderWidget()->edit_commands()) { |
4201 // In gtk and cocoa, it's possible to bind multiple edit commands to one | 4207 // In gtk and cocoa, it's possible to bind multiple edit commands to one |
4202 // key (but it's the exception). Once one edit command is not executed, it | 4208 // key (but it's the exception). Once one edit command is not executed, it |
4203 // seems safest to not execute the rest. | 4209 // seems safest to not execute the rest. |
4204 if (!frame_->ExecuteCommand(blink::WebString::FromUTF8(command.name), | 4210 if (!frame_->ExecuteCommand(blink::WebString::FromUTF8(command.name), |
4205 blink::WebString::FromUTF8(command.value))) | 4211 blink::WebString::FromUTF8(command.value))) |
(...skipping 2078 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6284 } | 6290 } |
6285 } | 6291 } |
6286 | 6292 |
6287 void RenderFrameImpl::UpdateEncoding(WebFrame* frame, | 6293 void RenderFrameImpl::UpdateEncoding(WebFrame* frame, |
6288 const std::string& encoding_name) { | 6294 const std::string& encoding_name) { |
6289 // Only update main frame's encoding_name. | 6295 // Only update main frame's encoding_name. |
6290 if (!frame->Parent()) | 6296 if (!frame->Parent()) |
6291 Send(new FrameHostMsg_UpdateEncoding(routing_id_, encoding_name)); | 6297 Send(new FrameHostMsg_UpdateEncoding(routing_id_, encoding_name)); |
6292 } | 6298 } |
6293 | 6299 |
6294 void RenderFrameImpl::SyncSelectionIfRequired() { | 6300 void RenderFrameImpl::SyncSelectionIfRequired(bool user_initiated) { |
6295 base::string16 text; | 6301 base::string16 text; |
6296 size_t offset; | 6302 size_t offset = 0; |
6297 gfx::Range range; | 6303 gfx::Range range = gfx::Range::InvalidRange(); |
6298 #if BUILDFLAG(ENABLE_PLUGINS) | 6304 #if BUILDFLAG(ENABLE_PLUGINS) |
6299 if (focused_pepper_plugin_) { | 6305 if (focused_pepper_plugin_) { |
6300 focused_pepper_plugin_->GetSurroundingText(&text, &range); | 6306 focused_pepper_plugin_->GetSurroundingText(&text, &range); |
6301 offset = 0; // Pepper API does not support offset reporting. | 6307 offset = 0; // Pepper API does not support offset reporting. |
6302 // TODO(kinaba): cut as needed. | 6308 // TODO(kinaba): cut as needed. |
6303 } else | 6309 } else |
6304 #endif | 6310 #endif |
6305 { | 6311 { |
6306 WebRange selection = | 6312 WebRange selection = |
6307 GetRenderWidget()->GetWebWidget()->CaretOrSelectionRange(); | 6313 GetRenderWidget()->GetWebWidget()->CaretOrSelectionRange(); |
6308 if (selection.IsNull()) | 6314 |
| 6315 // When clearing text selection from JavaScript the selection range |
| 6316 // might be null but the selected text still have to be updated. |
| 6317 // Do not cancel sync selection if the clear was not user initiated. |
| 6318 if (!selection.IsNull()) { |
| 6319 range = gfx::Range(selection.StartOffset(), selection.EndOffset()); |
| 6320 |
| 6321 if (frame_->GetInputMethodController()->TextInputType() != |
| 6322 blink::kWebTextInputTypeNone) { |
| 6323 // If current focused element is editable, we will send 100 more chars |
| 6324 // before and after selection. It is for input method surrounding text |
| 6325 // feature. |
| 6326 if (selection.StartOffset() > kExtraCharsBeforeAndAfterSelection) |
| 6327 offset = selection.StartOffset() - kExtraCharsBeforeAndAfterSelection; |
| 6328 else |
| 6329 offset = 0; |
| 6330 size_t length = |
| 6331 selection.EndOffset() - offset + kExtraCharsBeforeAndAfterSelection; |
| 6332 text = frame_->RangeAsText(WebRange(offset, length)).Utf16(); |
| 6333 } else { |
| 6334 offset = selection.StartOffset(); |
| 6335 text = frame_->SelectionAsText().Utf16(); |
| 6336 // http://crbug.com/101435 |
| 6337 // In some case, frame->selectionAsText() returned text's length is not |
| 6338 // equal to the length returned from |
| 6339 // GetWebWidget()->caretOrSelectionRange(). |
| 6340 // So we have to set the range according to text.length(). |
| 6341 range.set_end(range.start() + text.length()); |
| 6342 } |
| 6343 } else if (user_initiated) { |
6309 return; | 6344 return; |
6310 | |
6311 range = gfx::Range(selection.StartOffset(), selection.EndOffset()); | |
6312 | |
6313 if (frame_->GetInputMethodController()->TextInputType() != | |
6314 blink::kWebTextInputTypeNone) { | |
6315 // If current focused element is editable, we will send 100 more chars | |
6316 // before and after selection. It is for input method surrounding text | |
6317 // feature. | |
6318 if (selection.StartOffset() > kExtraCharsBeforeAndAfterSelection) | |
6319 offset = selection.StartOffset() - kExtraCharsBeforeAndAfterSelection; | |
6320 else | |
6321 offset = 0; | |
6322 size_t length = | |
6323 selection.EndOffset() - offset + kExtraCharsBeforeAndAfterSelection; | |
6324 text = frame_->RangeAsText(WebRange(offset, length)).Utf16(); | |
6325 } else { | |
6326 offset = selection.StartOffset(); | |
6327 text = frame_->SelectionAsText().Utf16(); | |
6328 // http://crbug.com/101435 | |
6329 // In some case, frame->selectionAsText() returned text's length is not | |
6330 // equal to the length returned from | |
6331 // GetWebWidget()->caretOrSelectionRange(). | |
6332 // So we have to set the range according to text.length(). | |
6333 range.set_end(range.start() + text.length()); | |
6334 } | 6345 } |
6335 } | 6346 } |
6336 | 6347 |
6337 // TODO(dglazkov): Investigate if and why this would be happening, | 6348 // TODO(dglazkov): Investigate if and why this would be happening, |
6338 // and resolve this. We shouldn't be carrying selection text here. | 6349 // and resolve this. We shouldn't be carrying selection text here. |
6339 // http://crbug.com/632920. | 6350 // http://crbug.com/632920. |
6340 // Sometimes we get repeated didChangeSelection calls from webkit when | 6351 // Sometimes we get repeated didChangeSelection calls from webkit when |
6341 // the selection hasn't actually changed. We don't want to report these | 6352 // the selection hasn't actually changed. We don't want to report these |
6342 // because it will cause us to continually claim the X clipboard. | 6353 // because it will cause us to continually claim the X clipboard. |
6343 if (selection_text_offset_ != offset || | 6354 if (selection_text_offset_ != offset || |
6344 selection_range_ != range || | 6355 selection_range_ != range || |
6345 selection_text_ != text) { | 6356 selection_text_ != text) { |
6346 selection_text_ = text; | 6357 selection_text_ = text; |
6347 selection_text_offset_ = offset; | 6358 selection_text_offset_ = offset; |
6348 selection_range_ = range; | 6359 selection_range_ = range; |
6349 SetSelectedText(text, offset, range); | 6360 SetSelectedText(text, offset, range, user_initiated); |
6350 } | 6361 } |
6351 GetRenderWidget()->UpdateSelectionBounds(); | 6362 GetRenderWidget()->UpdateSelectionBounds(); |
6352 } | 6363 } |
6353 | 6364 |
6354 void RenderFrameImpl::InitializeUserMediaClient() { | 6365 void RenderFrameImpl::InitializeUserMediaClient() { |
6355 RenderThreadImpl* render_thread = RenderThreadImpl::current(); | 6366 RenderThreadImpl* render_thread = RenderThreadImpl::current(); |
6356 if (!render_thread) // Will be NULL during unit tests. | 6367 if (!render_thread) // Will be NULL during unit tests. |
6357 return; | 6368 return; |
6358 | 6369 |
6359 #if BUILDFLAG(ENABLE_WEBRTC) | 6370 #if BUILDFLAG(ENABLE_WEBRTC) |
(...skipping 709 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7069 policy(info.default_policy), | 7080 policy(info.default_policy), |
7070 replaces_current_history_item(info.replaces_current_history_item), | 7081 replaces_current_history_item(info.replaces_current_history_item), |
7071 history_navigation_in_new_child_frame( | 7082 history_navigation_in_new_child_frame( |
7072 info.is_history_navigation_in_new_child_frame), | 7083 info.is_history_navigation_in_new_child_frame), |
7073 client_redirect(info.is_client_redirect), | 7084 client_redirect(info.is_client_redirect), |
7074 cache_disabled(info.is_cache_disabled), | 7085 cache_disabled(info.is_cache_disabled), |
7075 form(info.form), | 7086 form(info.form), |
7076 source_location(info.source_location) {} | 7087 source_location(info.source_location) {} |
7077 | 7088 |
7078 } // namespace content | 7089 } // namespace content |
OLD | NEW |