1 // Copyright 2021 The Chromium Embedded Framework Authors. Portions copyright 2 // 2011 The Chromium Authors. All rights reserved. Use of this source code is 3 // governed by a BSD-style license that can be found in the LICENSE file. 4 5 #ifndef CEF_LIBCEF_COMMON_STRING_UTIL_H_ 6 #define CEF_LIBCEF_COMMON_STRING_UTIL_H_ 7 #pragma once 8 9 #include "include/cef_base.h" 10 11 #include "base/callback.h" 12 #include "base/memory/scoped_refptr.h" 13 14 namespace base { 15 class ReadOnlySharedMemoryRegion; 16 class RefCountedMemory; 17 } // namespace base 18 19 namespace blink { 20 class WebString; 21 } 22 23 namespace string_util { 24 25 // Convert |source| to |cef_string|, avoiding UTF conversions if possible. 26 void GetCefString(const blink::WebString& source, CefString& cef_string); 27 void GetCefString(scoped_refptr<base::RefCountedMemory> source, 28 CefString& cef_string); 29 30 // Read |source| into shared memory, avoiding UTF conversions if possible. 31 // Use ExecuteWithScopedCefString() to retrieve the value on the receiving end 32 // with zero UTF conversions and zero copies if possible. 33 base::ReadOnlySharedMemoryRegion CreateSharedMemoryRegion( 34 const blink::WebString& source); 35 36 using ScopedCefStringCallback = base::OnceCallback<void(const CefString&)>; 37 38 // Helper for executing |callback| with |region| as a scoped CefString. 39 void ExecuteWithScopedCefString(base::ReadOnlySharedMemoryRegion region, 40 ScopedCefStringCallback callback); 41 42 } // namespace string_util 43 44 #endif // CEF_LIBCEF_COMMON_STRING_UTIL_H_ 45