| 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 1359 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1370 #if defined(OS_MACOSX) || defined(USE_AURA) | 1370 #if defined(OS_MACOSX) || defined(USE_AURA) |
| 1371 GetRenderWidget()->UpdateCompositionInfo( | 1371 GetRenderWidget()->UpdateCompositionInfo( |
| 1372 false /* not an immediate request */); | 1372 false /* not an immediate request */); |
| 1373 #endif | 1373 #endif |
| 1374 } | 1374 } |
| 1375 | 1375 |
| 1376 void RenderFrameImpl::PepperSelectionChanged( | 1376 void RenderFrameImpl::PepperSelectionChanged( |
| 1377 PepperPluginInstanceImpl* instance) { | 1377 PepperPluginInstanceImpl* instance) { |
| 1378 if (instance != focused_pepper_plugin_) | 1378 if (instance != focused_pepper_plugin_) |
| 1379 return; | 1379 return; |
| 1380 SyncSelectionIfRequired(); | 1380 // Keep the original behavior for pepper plugins and handle all selection |
| 1381 // change as user initiated. |
| 1382 SyncSelectionIfRequired(true); |
| 1381 } | 1383 } |
| 1382 | 1384 |
| 1383 RenderWidgetFullscreenPepper* RenderFrameImpl::CreatePepperFullscreenContainer( | 1385 RenderWidgetFullscreenPepper* RenderFrameImpl::CreatePepperFullscreenContainer( |
| 1384 PepperPluginInstanceImpl* plugin) { | 1386 PepperPluginInstanceImpl* plugin) { |
| 1385 GURL active_url; | 1387 GURL active_url; |
| 1386 if (render_view()->webview()) | 1388 if (render_view()->webview()) |
| 1387 active_url = render_view()->GetURLForGraphicsContext3D(); | 1389 active_url = render_view()->GetURLForGraphicsContext3D(); |
| 1388 | 1390 |
| 1389 // Synchronous IPC to obtain a routing id for the fullscreen widget. | 1391 // Synchronous IPC to obtain a routing id for the fullscreen widget. |
| 1390 int32_t fullscreen_widget_routing_id = MSG_ROUTING_NONE; | 1392 int32_t fullscreen_widget_routing_id = MSG_ROUTING_NONE; |
| (...skipping 563 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1954 base::AutoReset<bool> handling_select_range(&handling_select_range_, true); | 1956 base::AutoReset<bool> handling_select_range(&handling_select_range_, true); |
| 1955 frame_->MoveRangeSelectionExtent( | 1957 frame_->MoveRangeSelectionExtent( |
| 1956 render_view_->ConvertWindowPointToViewport(point)); | 1958 render_view_->ConvertWindowPointToViewport(point)); |
| 1957 } | 1959 } |
| 1958 | 1960 |
| 1959 void RenderFrameImpl::OnReplace(const base::string16& text) { | 1961 void RenderFrameImpl::OnReplace(const base::string16& text) { |
| 1960 if (!frame_->HasSelection()) | 1962 if (!frame_->HasSelection()) |
| 1961 frame_->SelectWordAroundCaret(); | 1963 frame_->SelectWordAroundCaret(); |
| 1962 | 1964 |
| 1963 frame_->ReplaceSelection(WebString::FromUTF16(text)); | 1965 frame_->ReplaceSelection(WebString::FromUTF16(text)); |
| 1964 SyncSelectionIfRequired(); | 1966 // Handle this selection change as user initiated since typically triggered |
| 1967 // from context menu. |
| 1968 SyncSelectionIfRequired(true); |
| 1965 } | 1969 } |
| 1966 | 1970 |
| 1967 void RenderFrameImpl::OnReplaceMisspelling(const base::string16& text) { | 1971 void RenderFrameImpl::OnReplaceMisspelling(const base::string16& text) { |
| 1968 if (!frame_->HasSelection()) | 1972 if (!frame_->HasSelection()) |
| 1969 return; | 1973 return; |
| 1970 | 1974 |
| 1971 frame_->ReplaceMisspelledRange(WebString::FromUTF16(text)); | 1975 frame_->ReplaceMisspelledRange(WebString::FromUTF16(text)); |
| 1972 } | 1976 } |
| 1973 | 1977 |
| 1974 void RenderFrameImpl::OnCopyImageAt(int x, int y) { | 1978 void RenderFrameImpl::OnCopyImageAt(int x, int y) { |
| (...skipping 658 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2633 void RenderFrameImpl::AttachGuest(int element_instance_id) { | 2637 void RenderFrameImpl::AttachGuest(int element_instance_id) { |
| 2634 BrowserPluginManager::Get()->Attach(element_instance_id); | 2638 BrowserPluginManager::Get()->Attach(element_instance_id); |
| 2635 } | 2639 } |
| 2636 | 2640 |
| 2637 void RenderFrameImpl::DetachGuest(int element_instance_id) { | 2641 void RenderFrameImpl::DetachGuest(int element_instance_id) { |
| 2638 BrowserPluginManager::Get()->Detach(element_instance_id); | 2642 BrowserPluginManager::Get()->Detach(element_instance_id); |
| 2639 } | 2643 } |
| 2640 | 2644 |
| 2641 void RenderFrameImpl::SetSelectedText(const base::string16& selection_text, | 2645 void RenderFrameImpl::SetSelectedText(const base::string16& selection_text, |
| 2642 size_t offset, | 2646 size_t offset, |
| 2643 const gfx::Range& range) { | 2647 const gfx::Range& range, |
| 2648 bool user_initiated) { |
| 2644 Send(new FrameHostMsg_SelectionChanged(routing_id_, selection_text, | 2649 Send(new FrameHostMsg_SelectionChanged(routing_id_, selection_text, |
| 2645 static_cast<uint32_t>(offset), range)); | 2650 static_cast<uint32_t>(offset), range, |
| 2651 user_initiated)); |
| 2646 } | 2652 } |
| 2647 | 2653 |
| 2648 void RenderFrameImpl::EnsureMojoBuiltinsAreAvailable( | 2654 void RenderFrameImpl::EnsureMojoBuiltinsAreAvailable( |
| 2649 v8::Isolate* isolate, | 2655 v8::Isolate* isolate, |
| 2650 v8::Local<v8::Context> context) { | 2656 v8::Local<v8::Context> context) { |
| 2651 gin::ModuleRegistry* registry = gin::ModuleRegistry::From(context); | 2657 gin::ModuleRegistry* registry = gin::ModuleRegistry::From(context); |
| 2652 if (registry->available_modules().count(mojo::edk::js::Core::kModuleName)) | 2658 if (registry->available_modules().count(mojo::edk::js::Core::kModuleName)) |
| 2653 return; | 2659 return; |
| 2654 | 2660 |
| 2655 v8::HandleScope handle_scope(isolate); | 2661 v8::HandleScope handle_scope(isolate); |
| (...skipping 1510 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4166 if (previews_state_ & SERVER_LOFI_ON) | 4172 if (previews_state_ & SERVER_LOFI_ON) |
| 4167 return request.Url().ProtocolIs("https"); | 4173 return request.Url().ProtocolIs("https"); |
| 4168 return true; | 4174 return true; |
| 4169 } | 4175 } |
| 4170 | 4176 |
| 4171 void RenderFrameImpl::AbortClientNavigation() { | 4177 void RenderFrameImpl::AbortClientNavigation() { |
| 4172 Send(new FrameHostMsg_AbortNavigation(routing_id_)); | 4178 Send(new FrameHostMsg_AbortNavigation(routing_id_)); |
| 4173 } | 4179 } |
| 4174 | 4180 |
| 4175 void RenderFrameImpl::DidChangeSelection(bool is_empty_selection) { | 4181 void RenderFrameImpl::DidChangeSelection(bool is_empty_selection) { |
| 4176 if (!GetRenderWidget()->input_handler().handling_input_event() && | 4182 bool user_initiated = |
| 4177 !handling_select_range_) | 4183 GetRenderWidget()->input_handler().handling_input_event() || |
| 4178 return; | 4184 handling_select_range_; |
| 4179 | 4185 |
| 4180 if (is_empty_selection) | 4186 if (is_empty_selection) |
| 4181 selection_text_.clear(); | 4187 selection_text_.clear(); |
| 4182 | 4188 |
| 4183 // UpdateTextInputState should be called before SyncSelectionIfRequired. | 4189 // UpdateTextInputState should be called before SyncSelectionIfRequired. |
| 4184 // UpdateTextInputState may send TextInputStateChanged to notify the focus | 4190 // UpdateTextInputState may send TextInputStateChanged to notify the focus |
| 4185 // was changed, and SyncSelectionIfRequired may send SelectionChanged | 4191 // was changed, and SyncSelectionIfRequired may send SelectionChanged |
| 4186 // to notify the selection was changed. Focus change should be notified | 4192 // to notify the selection was changed. Focus change should be notified |
| 4187 // before selection change. | 4193 // before selection change. |
| 4188 GetRenderWidget()->UpdateTextInputState(); | 4194 GetRenderWidget()->UpdateTextInputState(); |
| 4189 SyncSelectionIfRequired(); | 4195 SyncSelectionIfRequired(user_initiated); |
| 4190 } | 4196 } |
| 4191 | 4197 |
| 4192 bool RenderFrameImpl::HandleCurrentKeyboardEvent() { | 4198 bool RenderFrameImpl::HandleCurrentKeyboardEvent() { |
| 4193 bool did_execute_command = false; | 4199 bool did_execute_command = false; |
| 4194 for (auto command : GetRenderWidget()->edit_commands()) { | 4200 for (auto command : GetRenderWidget()->edit_commands()) { |
| 4195 // In gtk and cocoa, it's possible to bind multiple edit commands to one | 4201 // In gtk and cocoa, it's possible to bind multiple edit commands to one |
| 4196 // key (but it's the exception). Once one edit command is not executed, it | 4202 // key (but it's the exception). Once one edit command is not executed, it |
| 4197 // seems safest to not execute the rest. | 4203 // seems safest to not execute the rest. |
| 4198 if (!frame_->ExecuteCommand(blink::WebString::FromUTF8(command.name), | 4204 if (!frame_->ExecuteCommand(blink::WebString::FromUTF8(command.name), |
| 4199 blink::WebString::FromUTF8(command.value))) | 4205 blink::WebString::FromUTF8(command.value))) |
| (...skipping 2070 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6270 } | 6276 } |
| 6271 } | 6277 } |
| 6272 | 6278 |
| 6273 void RenderFrameImpl::UpdateEncoding(WebFrame* frame, | 6279 void RenderFrameImpl::UpdateEncoding(WebFrame* frame, |
| 6274 const std::string& encoding_name) { | 6280 const std::string& encoding_name) { |
| 6275 // Only update main frame's encoding_name. | 6281 // Only update main frame's encoding_name. |
| 6276 if (!frame->Parent()) | 6282 if (!frame->Parent()) |
| 6277 Send(new FrameHostMsg_UpdateEncoding(routing_id_, encoding_name)); | 6283 Send(new FrameHostMsg_UpdateEncoding(routing_id_, encoding_name)); |
| 6278 } | 6284 } |
| 6279 | 6285 |
| 6280 void RenderFrameImpl::SyncSelectionIfRequired() { | 6286 void RenderFrameImpl::SyncSelectionIfRequired(bool user_initiated) { |
| 6281 base::string16 text; | 6287 base::string16 text; |
| 6282 size_t offset; | 6288 size_t offset = 0; |
| 6283 gfx::Range range; | 6289 gfx::Range range = gfx::Range::InvalidRange(); |
| 6284 #if BUILDFLAG(ENABLE_PLUGINS) | 6290 #if BUILDFLAG(ENABLE_PLUGINS) |
| 6285 if (focused_pepper_plugin_) { | 6291 if (focused_pepper_plugin_) { |
| 6286 focused_pepper_plugin_->GetSurroundingText(&text, &range); | 6292 focused_pepper_plugin_->GetSurroundingText(&text, &range); |
| 6287 offset = 0; // Pepper API does not support offset reporting. | 6293 offset = 0; // Pepper API does not support offset reporting. |
| 6288 // TODO(kinaba): cut as needed. | 6294 // TODO(kinaba): cut as needed. |
| 6289 } else | 6295 } else |
| 6290 #endif | 6296 #endif |
| 6291 { | 6297 { |
| 6292 WebRange selection = | 6298 WebRange selection = |
| 6293 GetRenderWidget()->GetWebWidget()->CaretOrSelectionRange(); | 6299 GetRenderWidget()->GetWebWidget()->CaretOrSelectionRange(); |
| 6294 if (selection.IsNull()) | 6300 |
| 6301 // When clearing text selection from JavaScript the selection range |
| 6302 // might be null but the selected text still have to be updated. |
| 6303 // Do not cancel sync selection if the clear was not user initiated. |
| 6304 if (!selection.IsNull()) { |
| 6305 range = gfx::Range(selection.StartOffset(), selection.EndOffset()); |
| 6306 |
| 6307 if (frame_->GetInputMethodController()->TextInputType() != |
| 6308 blink::kWebTextInputTypeNone) { |
| 6309 // If current focused element is editable, we will send 100 more chars |
| 6310 // before and after selection. It is for input method surrounding text |
| 6311 // feature. |
| 6312 if (selection.StartOffset() > kExtraCharsBeforeAndAfterSelection) |
| 6313 offset = selection.StartOffset() - kExtraCharsBeforeAndAfterSelection; |
| 6314 else |
| 6315 offset = 0; |
| 6316 size_t length = |
| 6317 selection.EndOffset() - offset + kExtraCharsBeforeAndAfterSelection; |
| 6318 text = frame_->RangeAsText(WebRange(offset, length)).Utf16(); |
| 6319 } else { |
| 6320 offset = selection.StartOffset(); |
| 6321 text = frame_->SelectionAsText().Utf16(); |
| 6322 // http://crbug.com/101435 |
| 6323 // In some case, frame->selectionAsText() returned text's length is not |
| 6324 // equal to the length returned from |
| 6325 // GetWebWidget()->caretOrSelectionRange(). |
| 6326 // So we have to set the range according to text.length(). |
| 6327 range.set_end(range.start() + text.length()); |
| 6328 } |
| 6329 } else if (user_initiated) { |
| 6295 return; | 6330 return; |
| 6296 | |
| 6297 range = gfx::Range(selection.StartOffset(), selection.EndOffset()); | |
| 6298 | |
| 6299 if (frame_->GetInputMethodController()->TextInputType() != | |
| 6300 blink::kWebTextInputTypeNone) { | |
| 6301 // If current focused element is editable, we will send 100 more chars | |
| 6302 // before and after selection. It is for input method surrounding text | |
| 6303 // feature. | |
| 6304 if (selection.StartOffset() > kExtraCharsBeforeAndAfterSelection) | |
| 6305 offset = selection.StartOffset() - kExtraCharsBeforeAndAfterSelection; | |
| 6306 else | |
| 6307 offset = 0; | |
| 6308 size_t length = | |
| 6309 selection.EndOffset() - offset + kExtraCharsBeforeAndAfterSelection; | |
| 6310 text = frame_->RangeAsText(WebRange(offset, length)).Utf16(); | |
| 6311 } else { | |
| 6312 offset = selection.StartOffset(); | |
| 6313 text = frame_->SelectionAsText().Utf16(); | |
| 6314 // http://crbug.com/101435 | |
| 6315 // In some case, frame->selectionAsText() returned text's length is not | |
| 6316 // equal to the length returned from | |
| 6317 // GetWebWidget()->caretOrSelectionRange(). | |
| 6318 // So we have to set the range according to text.length(). | |
| 6319 range.set_end(range.start() + text.length()); | |
| 6320 } | 6331 } |
| 6321 } | 6332 } |
| 6322 | 6333 |
| 6323 // TODO(dglazkov): Investigate if and why this would be happening, | 6334 // TODO(dglazkov): Investigate if and why this would be happening, |
| 6324 // and resolve this. We shouldn't be carrying selection text here. | 6335 // and resolve this. We shouldn't be carrying selection text here. |
| 6325 // http://crbug.com/632920. | 6336 // http://crbug.com/632920. |
| 6326 // Sometimes we get repeated didChangeSelection calls from webkit when | 6337 // Sometimes we get repeated didChangeSelection calls from webkit when |
| 6327 // the selection hasn't actually changed. We don't want to report these | 6338 // the selection hasn't actually changed. We don't want to report these |
| 6328 // because it will cause us to continually claim the X clipboard. | 6339 // because it will cause us to continually claim the X clipboard. |
| 6329 if (selection_text_offset_ != offset || | 6340 if (selection_text_offset_ != offset || |
| 6330 selection_range_ != range || | 6341 selection_range_ != range || |
| 6331 selection_text_ != text) { | 6342 selection_text_ != text) { |
| 6332 selection_text_ = text; | 6343 selection_text_ = text; |
| 6333 selection_text_offset_ = offset; | 6344 selection_text_offset_ = offset; |
| 6334 selection_range_ = range; | 6345 selection_range_ = range; |
| 6335 SetSelectedText(text, offset, range); | 6346 SetSelectedText(text, offset, range, user_initiated); |
| 6336 } | 6347 } |
| 6337 GetRenderWidget()->UpdateSelectionBounds(); | 6348 GetRenderWidget()->UpdateSelectionBounds(); |
| 6338 } | 6349 } |
| 6339 | 6350 |
| 6340 void RenderFrameImpl::InitializeUserMediaClient() { | 6351 void RenderFrameImpl::InitializeUserMediaClient() { |
| 6341 RenderThreadImpl* render_thread = RenderThreadImpl::current(); | 6352 RenderThreadImpl* render_thread = RenderThreadImpl::current(); |
| 6342 if (!render_thread) // Will be NULL during unit tests. | 6353 if (!render_thread) // Will be NULL during unit tests. |
| 6343 return; | 6354 return; |
| 6344 | 6355 |
| 6345 #if BUILDFLAG(ENABLE_WEBRTC) | 6356 #if BUILDFLAG(ENABLE_WEBRTC) |
| (...skipping 709 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 7055 policy(info.default_policy), | 7066 policy(info.default_policy), |
| 7056 replaces_current_history_item(info.replaces_current_history_item), | 7067 replaces_current_history_item(info.replaces_current_history_item), |
| 7057 history_navigation_in_new_child_frame( | 7068 history_navigation_in_new_child_frame( |
| 7058 info.is_history_navigation_in_new_child_frame), | 7069 info.is_history_navigation_in_new_child_frame), |
| 7059 client_redirect(info.is_client_redirect), | 7070 client_redirect(info.is_client_redirect), |
| 7060 cache_disabled(info.is_cache_disabled), | 7071 cache_disabled(info.is_cache_disabled), |
| 7061 form(info.form), | 7072 form(info.form), |
| 7062 source_location(info.source_location) {} | 7073 source_location(info.source_location) {} |
| 7063 | 7074 |
| 7064 } // namespace content | 7075 } // namespace content |
| OLD | NEW |