From ca9abe98a9a6e0c34f906941674b2cfa9cd6ca0c Mon Sep 17 00:00:00 2001 From: Marshall Greenblatt Date: Fri, 5 May 2017 15:34:20 -0400 Subject: [PATCH] Fix DCHECK during Find (issue #2050) --- include/capi/cef_browser_capi.h | 15 +++++++++------ include/cef_browser.h | 15 +++++++++------ libcef/browser/browser_host_impl.cc | 8 ++++++++ libcef/browser/browser_host_impl.h | 3 +++ 4 files changed, 29 insertions(+), 12 deletions(-) diff --git a/include/capi/cef_browser_capi.h b/include/capi/cef_browser_capi.h index 9e1362f6c..9485dd534 100644 --- a/include/capi/cef_browser_capi.h +++ b/include/capi/cef_browser_capi.h @@ -430,12 +430,15 @@ typedef struct _cef_browser_host_t { struct _cef_pdf_print_callback_t* callback); /// - // Search for |searchText|. |identifier| can be used to have multiple searches - // running simultaniously. |forward| indicates whether to search forward or - // backward within the page. |matchCase| indicates whether the search should - // be case-sensitive. |findNext| indicates whether this is the first request - // or a follow-up. The cef_find_handler_t instance, if any, returned via - // cef_client_t::GetFindHandler will be called to report find results. + // Search for |searchText|. |identifier| must be a unique ID and these IDs + // must strictly increase so that newer requests always have greater IDs than + // older requests. If |identifier| is zero or less than the previous ID value + // then it will be automatically assigned a new valid ID. |forward| indicates + // whether to search forward or backward within the page. |matchCase| + // indicates whether the search should be case-sensitive. |findNext| indicates + // whether this is the first request or a follow-up. The cef_find_handler_t + // instance, if any, returned via cef_client_t::GetFindHandler will be called + // to report find results. /// void (CEF_CALLBACK *find)(struct _cef_browser_host_t* self, int identifier, const cef_string_t* searchText, int forward, int matchCase, diff --git a/include/cef_browser.h b/include/cef_browser.h index 3b4ed1617..f12facb9a 100644 --- a/include/cef_browser.h +++ b/include/cef_browser.h @@ -472,12 +472,15 @@ class CefBrowserHost : public virtual CefBaseRefCounted { CefRefPtr callback) =0; /// - // Search for |searchText|. |identifier| can be used to have multiple searches - // running simultaniously. |forward| indicates whether to search forward or - // backward within the page. |matchCase| indicates whether the search should - // be case-sensitive. |findNext| indicates whether this is the first request - // or a follow-up. The CefFindHandler instance, if any, returned via - // CefClient::GetFindHandler will be called to report find results. + // Search for |searchText|. |identifier| must be a unique ID and these IDs + // must strictly increase so that newer requests always have greater IDs than + // older requests. If |identifier| is zero or less than the previous ID value + // then it will be automatically assigned a new valid ID. |forward| indicates + // whether to search forward or backward within the page. |matchCase| + // indicates whether the search should be case-sensitive. |findNext| indicates + // whether this is the first request or a follow-up. The CefFindHandler + // instance, if any, returned via CefClient::GetFindHandler will be called to + // report find results. /// /*--cef()--*/ virtual void Find(int identifier, const CefString& searchText, diff --git a/libcef/browser/browser_host_impl.cc b/libcef/browser/browser_host_impl.cc index 14df2b671..096ec108a 100644 --- a/libcef/browser/browser_host_impl.cc +++ b/libcef/browser/browser_host_impl.cc @@ -784,6 +784,14 @@ void CefBrowserHostImpl::Find(int identifier, const CefString& searchText, if (!web_contents_) return; + // Every find request must have a unique ID and these IDs must strictly + // increase so that newer requests always have greater IDs than older + // requests. + if (identifier <= find_request_id_counter_) + identifier = ++find_request_id_counter_; + else + find_request_id_counter_ = identifier; + blink::WebFindOptions options; options.forward = forward; options.match_case = matchCase; diff --git a/libcef/browser/browser_host_impl.h b/libcef/browser/browser_host_impl.h index 6f4328eb0..0000eb545 100644 --- a/libcef/browser/browser_host_impl.h +++ b/libcef/browser/browser_host_impl.h @@ -637,6 +637,9 @@ class CefBrowserHostImpl : public CefBrowserHost, // Observers that want to be notified of changes to this object. base::ObserverList observers_; + // Used to provide unique incremental IDs for each find request. + int find_request_id_counter_ = 0; + IMPLEMENT_REFCOUNTING(CefBrowserHostImpl); DISALLOW_COPY_AND_ASSIGN(CefBrowserHostImpl); };