Chromium Code Reviews| Index: content/renderer/render_view_impl.cc |
| diff --git a/content/renderer/render_view_impl.cc b/content/renderer/render_view_impl.cc |
| index 224cb16f4c42e163a00131e049cb9bfa46244295..e2d06b9469c07bbc2e3fcaabd0dd00c47fbaf150 100644 |
| --- a/content/renderer/render_view_impl.cc |
| +++ b/content/renderer/render_view_impl.cc |
| @@ -612,6 +612,7 @@ RenderViewImpl::RenderViewImpl( |
| mouse_lock_dispatcher_(NULL), |
| #if defined(OS_ANDROID) |
| expected_content_intent_id_(0), |
| + synchronous_find_active_match_ordinal_(-1), |
| #endif |
| session_storage_namespace_id_(session_storage_namespace_id), |
| handling_select_range_(false), |
| @@ -939,9 +940,6 @@ bool RenderViewImpl::OnMessageReceived(const IPC::Message& message) { |
| IPC_MESSAGE_HANDLER(ViewMsg_Redo, OnRedo) |
| IPC_MESSAGE_HANDLER(ViewMsg_Cut, OnCut) |
| IPC_MESSAGE_HANDLER(ViewMsg_Copy, OnCopy) |
| -#if defined(OS_MACOSX) |
| - IPC_MESSAGE_HANDLER(ViewMsg_CopyToFindPboard, OnCopyToFindPboard) |
| -#endif |
| IPC_MESSAGE_HANDLER(ViewMsg_Paste, OnPaste) |
| IPC_MESSAGE_HANDLER(ViewMsg_PasteAndMatchStyle, OnPasteAndMatchStyle) |
| IPC_MESSAGE_HANDLER(ViewMsg_Replace, OnReplace) |
| @@ -960,12 +958,6 @@ bool RenderViewImpl::OnMessageReceived(const IPC::Message& message) { |
| IPC_MESSAGE_HANDLER(ViewMsg_ExecuteEditCommand, OnExecuteEditCommand) |
| IPC_MESSAGE_HANDLER(ViewMsg_Find, OnFind) |
| IPC_MESSAGE_HANDLER(ViewMsg_StopFinding, OnStopFinding) |
| -#if defined(OS_ANDROID) |
| - IPC_MESSAGE_HANDLER(ViewMsg_ActivateNearestFindResult, |
| - OnActivateNearestFindResult) |
| - IPC_MESSAGE_HANDLER(ViewMsg_FindMatchRects, |
| - OnFindMatchRects) |
| -#endif |
| IPC_MESSAGE_HANDLER(ViewMsg_Zoom, OnZoom) |
| IPC_MESSAGE_HANDLER(ViewMsg_SetZoomLevel, OnSetZoomLevel) |
| IPC_MESSAGE_HANDLER(ViewMsg_ZoomFactor, OnZoomFactor) |
| @@ -1018,12 +1010,6 @@ bool RenderViewImpl::OnMessageReceived(const IPC::Message& message) { |
| IPC_MESSAGE_HANDLER(ViewMsg_SetActive, OnSetActive) |
| IPC_MESSAGE_HANDLER(ViewMsg_SetNavigationStartTime, |
| OnSetNavigationStartTime) |
| -#if defined(OS_MACOSX) |
| - IPC_MESSAGE_HANDLER(ViewMsg_SetWindowVisibility, OnSetWindowVisibility) |
| - IPC_MESSAGE_HANDLER(ViewMsg_WindowFrameChanged, OnWindowFrameChanged) |
| - IPC_MESSAGE_HANDLER(ViewMsg_PluginImeCompositionCompleted, |
| - OnPluginImeCompositionCompleted) |
| -#endif |
| IPC_MESSAGE_HANDLER(ViewMsg_SetEditCommandsForNextKeyEvent, |
| OnSetEditCommandsForNextKeyEvent) |
| IPC_MESSAGE_HANDLER(ViewMsg_CustomContextMenuAction, |
| @@ -1038,22 +1024,29 @@ bool RenderViewImpl::OnMessageReceived(const IPC::Message& message) { |
| IPC_MESSAGE_HANDLER( |
| ViewMsg_GetSerializedHtmlDataForCurrentPageWithLocalLinks, |
| OnGetSerializedHtmlDataForCurrentPageWithLocalLinks) |
| -#if defined(OS_MACOSX) |
| - IPC_MESSAGE_HANDLER(ViewMsg_SelectPopupMenuItem, OnSelectPopupMenuItem) |
| -#elif defined(OS_ANDROID) |
| - IPC_MESSAGE_HANDLER(ViewMsg_SelectPopupMenuItems, OnSelectPopupMenuItems) |
| -#endif |
| IPC_MESSAGE_HANDLER(ViewMsg_ContextMenuClosed, OnContextMenuClosed) |
| // TODO(viettrungluu): Move to a separate message filter. |
| -#if defined(OS_MACOSX) |
| - IPC_MESSAGE_HANDLER(ViewMsg_SetInLiveResize, OnSetInLiveResize) |
| -#endif |
| IPC_MESSAGE_HANDLER(ViewMsg_SetHistoryLengthAndPrune, |
| OnSetHistoryLengthAndPrune) |
| IPC_MESSAGE_HANDLER(ViewMsg_EnableViewSourceMode, OnEnableViewSourceMode) |
| IPC_MESSAGE_HANDLER(JavaBridgeMsg_Init, OnJavaBridgeInit) |
| IPC_MESSAGE_HANDLER(ViewMsg_SetAccessibilityMode, OnSetAccessibilityMode) |
| IPC_MESSAGE_HANDLER(ViewMsg_UpdateFrameTree, OnUpdatedFrameTree) |
| +#if defined(OS_ANDROID) |
| + IPC_MESSAGE_HANDLER(ViewMsg_ActivateNearestFindResult, |
| + OnActivateNearestFindResult) |
| + IPC_MESSAGE_HANDLER(ViewMsg_FindMatchRects, OnFindMatchRects) |
| + IPC_MESSAGE_HANDLER(ViewMsg_SelectPopupMenuItems, OnSelectPopupMenuItems) |
| + IPC_MESSAGE_HANDLER_DELAY_REPLY(ViewMsg_SynchronousFind, OnSynchronousFind) |
| +#elif defined(OS_MACOSX) |
| + IPC_MESSAGE_HANDLER(ViewMsg_CopyToFindPboard, OnCopyToFindPboard) |
| + IPC_MESSAGE_HANDLER(ViewMsg_PluginImeCompositionCompleted, |
| + OnPluginImeCompositionCompleted) |
| + IPC_MESSAGE_HANDLER(ViewMsg_SelectPopupMenuItem, OnSelectPopupMenuItem) |
| + IPC_MESSAGE_HANDLER(ViewMsg_SetInLiveResize, OnSetInLiveResize) |
| + IPC_MESSAGE_HANDLER(ViewMsg_SetWindowVisibility, OnSetWindowVisibility) |
| + IPC_MESSAGE_HANDLER(ViewMsg_WindowFrameChanged, OnWindowFrameChanged) |
| +#endif |
| // Have the super handle all other messages. |
| IPC_MESSAGE_UNHANDLED(handled = RenderWidget::OnMessageReceived(message)) |
| @@ -3894,30 +3887,66 @@ void RenderViewImpl::hasTouchEventHandlers(bool has_handlers) { |
| Send(new ViewHostMsg_HasTouchEventHandlers(routing_id_, has_handlers)); |
| } |
| -void RenderViewImpl::reportFindInPageMatchCount(int request_id, int count, |
| +void RenderViewImpl::SendFindReply(int request_id, |
| + int match_count, |
| + int ordinal, |
| + const WebRect& selection_rect, |
| + bool final_status_update) { |
| +#if defined(OS_ANDROID) |
| + // Check if this is a synchronous find request. |
|
jam
2012/09/19 19:37:56
nit: this comment and the one below are not very u
Leandro Graciá Gil
2012/09/20 16:05:06
Done.
|
| + if (synchronous_find_reply_message_.get()) { |
| + if (final_status_update) { |
| + ViewMsg_SynchronousFind::WriteReplyParams( |
| + synchronous_find_reply_message_.get(), |
| + match_count, |
| + match_count ? synchronous_find_active_match_ordinal_ : 0); |
| + Send(synchronous_find_reply_message_.release()); |
| + } |
| + return; |
| + } |
| +#endif |
| + |
| + // Send the search result over to the browser process. |
| + Send(new ViewHostMsg_Find_Reply(routing_id_, |
| + request_id, |
| + match_count, |
| + selection_rect, |
| + ordinal, |
| + final_status_update)); |
| +} |
| + |
| +void RenderViewImpl::reportFindInPageMatchCount(int request_id, |
| + int count, |
| bool final_update) { |
| int active_match_ordinal = -1; // -1 = don't update active match ordinal |
| if (!count) |
| active_match_ordinal = 0; |
| - Send(new ViewHostMsg_Find_Reply(routing_id_, |
| - request_id, |
| - count, |
| - gfx::Rect(), |
| - active_match_ordinal, |
| - final_update)); |
| + // Send the search result over to the browser process. |
| + SendFindReply(request_id, |
| + count, |
| + active_match_ordinal, |
| + gfx::Rect(), |
| + final_update); |
| } |
| void RenderViewImpl::reportFindInPageSelection(int request_id, |
| int active_match_ordinal, |
| const WebRect& selection_rect) { |
| - // Send the search result over to the browser process. |
| - Send(new ViewHostMsg_Find_Reply(routing_id_, |
| - request_id, |
| - -1, |
| - selection_rect, |
| - active_match_ordinal, |
| - false)); |
| +#if defined(OS_ANDROID) |
| + // If this was a SynchronousFind request, we need to remember the ordinal |
| + // value here for replying when reportFindInPageMatchCount is called. |
| + if (synchronous_find_reply_message_.get()) { |
| + synchronous_find_active_match_ordinal_ = active_match_ordinal; |
| + return; |
| + } |
| +#endif |
| + |
| + SendFindReply(request_id, |
| + -1, /* number_of_matches */ |
|
jam
2012/09/19 19:37:56
nit: can you skip the comments here? if someone wa
Leandro Graciá Gil
2012/09/20 16:05:06
Done.
|
| + active_match_ordinal, |
| + selection_rect, |
| + false /* final_update */); |
| } |
| void RenderViewImpl::openFileSystem( |
| @@ -4525,8 +4554,22 @@ WebKit::WebPlugin* RenderViewImpl::GetWebPluginFromPluginDocument() { |
| return webview()->mainFrame()->document().to<WebPluginDocument>().plugin(); |
| } |
| -void RenderViewImpl::OnFind(int request_id, const string16& search_text, |
| +void RenderViewImpl::OnFind(int request_id, |
| + const string16& search_text, |
| const WebFindOptions& options) { |
| +#if defined(OS_ANDROID) |
| + // Make sure any asynchronous messages do not disrupt an ongoing synchronous |
| + // find request as it might lead to deadlocks. Also, these should be safe to |
| + // ignore since they would belong to a previous find request. |
| + if (synchronous_find_reply_message_.get()) |
| + return; |
| +#endif |
| + Find(request_id, search_text, options); |
| +} |
| + |
| +void RenderViewImpl::Find(int request_id, |
| + const string16& search_text, |
| + const WebFindOptions& options) { |
| WebFrame* main_frame = webview()->mainFrame(); |
| // Check if the plugin still exists in the document. |
| @@ -4536,16 +4579,10 @@ void RenderViewImpl::OnFind(int request_id, const string16& search_text, |
| // Just navigate back/forward. |
| GetWebPluginFromPluginDocument()->selectFindResult(options.forward); |
| } else { |
| - if (GetWebPluginFromPluginDocument()->startFind( |
| + if (!GetWebPluginFromPluginDocument()->startFind( |
| search_text, options.matchCase, request_id)) { |
| - } else { |
| // Send "no results". |
| - Send(new ViewHostMsg_Find_Reply(routing_id_, |
| - request_id, |
| - 0, |
| - gfx::Rect(), |
| - 0, |
| - true)); |
| + SendFindReply(request_id, 0, 0, gfx::Rect(), true); |
| } |
| } |
| return; |
| @@ -4618,13 +4655,8 @@ void RenderViewImpl::OnFind(int request_id, const string16& search_text, |
| // Otherwise the scoping effort will send more results. |
| bool final_status_update = !result; |
| - // Send the search result over to the browser process. |
| - Send(new ViewHostMsg_Find_Reply(routing_id_, |
| - request_id, |
| - match_count, |
| - selection_rect, |
| - ordinal, |
| - final_status_update)); |
| + SendFindReply(request_id, match_count, ordinal, selection_rect, |
| + final_status_update); |
| // Scoping effort begins, starting with the mainframe. |
| search_frame = main_frame; |
| @@ -4654,6 +4686,18 @@ void RenderViewImpl::OnFind(int request_id, const string16& search_text, |
| } |
| void RenderViewImpl::OnStopFinding(content::StopFindAction action) { |
| +#if defined(OS_ANDROID) |
| + // Make sure any asynchronous messages do not disrupt an ongoing synchronous |
| + // find request as it might lead to deadlocks. Also, these should be safe to |
| + // ignore since they would belong to a previous find request. |
| + if (synchronous_find_reply_message_.get()) |
| + return; |
| +#endif |
| + |
| + StopFinding(action); |
| +} |
| + |
| +void RenderViewImpl::StopFinding(content::StopFindAction action) { |
| WebView* view = webview(); |
| if (!view) |
| return; |
| @@ -4688,6 +4732,23 @@ void RenderViewImpl::OnStopFinding(content::StopFindAction action) { |
| } |
| #if defined(OS_ANDROID) |
| +void RenderViewImpl::OnSynchronousFind(int request_id, |
| + const string16& search_string, |
| + const WebFindOptions& options, |
| + IPC::Message* reply_msg) { |
| + // It is impossible for simultaneous blocking finds to occur. |
| + CHECK(!synchronous_find_reply_message_.get()); |
| + synchronous_find_reply_message_.reset(reply_msg); |
| + |
| + // Find next should be asynchronous in order to minimize blocking |
| + // the UI thread as much as possible. |
| + DCHECK(!options.findNext); |
| + StopFinding(content::STOP_FIND_ACTION_KEEP_SELECTION); |
| + synchronous_find_active_match_ordinal_ = -1; |
| + |
| + Find(request_id, search_string, options); |
| +} |
| + |
| void RenderViewImpl::OnActivateNearestFindResult(int request_id, |
| float x, float y) { |
| if (!webview()) |
| @@ -4705,12 +4766,11 @@ void RenderViewImpl::OnActivateNearestFindResult(int request_id, |
| return; |
| } |
| - Send(new ViewHostMsg_Find_Reply(routing_id_, |
| - request_id, |
| - -1 /* number_of_matches */, |
| - selection_rect, |
| - ordinal, |
| - true /* final_update */)); |
| + SendFindReply(request_id, |
| + -1 /* number_of_matches */, |
| + ordinal, |
| + selection_rect, |
| + true /* final_update */); |
| } |
| void RenderViewImpl::OnFindMatchRects(int current_version) { |