Remove CefFrame::LoadString method (fixes issue #2586)

This method has not behaved as expected for some time.
This commit is contained in:
Marshall Greenblatt 2019-10-15 17:34:13 +02:00
parent d28efe8797
commit 737ff18498
11 changed files with 107 additions and 122 deletions

View File

@ -33,7 +33,7 @@
// by hand. See the translator.README.txt file in the tools directory for // by hand. See the translator.README.txt file in the tools directory for
// more information. // more information.
// //
// $hash=5f3cb132c1116a36c746c246ebeded195c917718$ // $hash=69e96203a1f5a71808125a25e511d99b599b7915$
// //
#ifndef CEF_INCLUDE_CAPI_CEF_FRAME_CAPI_H_ #ifndef CEF_INCLUDE_CAPI_CEF_FRAME_CAPI_H_
@ -145,15 +145,6 @@ typedef struct _cef_frame_t {
void(CEF_CALLBACK* load_url)(struct _cef_frame_t* self, void(CEF_CALLBACK* load_url)(struct _cef_frame_t* self,
const cef_string_t* url); const cef_string_t* url);
///
// Load the contents of |string_val| with the specified dummy |url|. |url|
// should have a standard scheme (for example, http scheme) or behaviors like
// link clicks and web security restrictions may not behave as expected.
///
void(CEF_CALLBACK* load_string)(struct _cef_frame_t* self,
const cef_string_t* string_val,
const cef_string_t* url);
/// ///
// Execute a string of JavaScript code in this frame. The |script_url| // Execute a string of JavaScript code in this frame. The |script_url|
// parameter is the URL where the script in question can be found, if any. The // parameter is the URL where the script in question can be found, if any. The

View File

@ -34,7 +34,7 @@
// implementations. See the translator.README.txt file in the tools directory // implementations. See the translator.README.txt file in the tools directory
// for more information. // for more information.
// //
// $hash=42f531d8211496faa76ffa838a2cf0b9cfa45c56$ // $hash=714707190282ccff4cfc40f0f17b88c24f27236a$
// //
#ifndef CEF_INCLUDE_API_HASH_H_ #ifndef CEF_INCLUDE_API_HASH_H_
@ -47,13 +47,13 @@
// way that may cause binary incompatibility with other builds. The universal // way that may cause binary incompatibility with other builds. The universal
// hash value will change if any platform is affected whereas the platform hash // hash value will change if any platform is affected whereas the platform hash
// values will change only if that particular platform is affected. // values will change only if that particular platform is affected.
#define CEF_API_HASH_UNIVERSAL "842f5e9a25404c0d6d6408d361c760f1f107b129" #define CEF_API_HASH_UNIVERSAL "2b148bd47ce42d97377baaa92039bf1bb04d631e"
#if defined(OS_WIN) #if defined(OS_WIN)
#define CEF_API_HASH_PLATFORM "f691a75408d8ea7742a14db07fc1df73555320a3" #define CEF_API_HASH_PLATFORM "fdc417626039e5cb7122cd531fcc82d3845354f4"
#elif defined(OS_MACOSX) #elif defined(OS_MACOSX)
#define CEF_API_HASH_PLATFORM "1c2b7de4554429cfb71302d465cb55e6da45788d" #define CEF_API_HASH_PLATFORM "184c18fff7d61c248062eb43092c8f6f94f051b0"
#elif defined(OS_LINUX) #elif defined(OS_LINUX)
#define CEF_API_HASH_PLATFORM "698c65121d173f8a72997e91783166a930c2efca" #define CEF_API_HASH_PLATFORM "acc3cea452fa30b32d76d09282744a5dc30b9530"
#endif #endif
#ifdef __cplusplus #ifdef __cplusplus

View File

@ -145,15 +145,6 @@ class CefFrame : public virtual CefBaseRefCounted {
/*--cef()--*/ /*--cef()--*/
virtual void LoadURL(const CefString& url) = 0; virtual void LoadURL(const CefString& url) = 0;
///
// Load the contents of |string_val| with the specified dummy |url|. |url|
// should have a standard scheme (for example, http scheme) or behaviors like
// link clicks and web security restrictions may not behave as expected.
///
/*--cef()--*/
virtual void LoadString(const CefString& string_val,
const CefString& url) = 0;
/// ///
// Execute a string of JavaScript code in this frame. The |script_url| // Execute a string of JavaScript code in this frame. The |script_url|
// parameter is the URL where the script in question can be found, if any. // parameter is the URL where the script in question can be found, if any.

View File

@ -168,25 +168,6 @@ void CefFrameHostImpl::LoadURL(const CefString& url) {
std::string()); std::string());
} }
void CefFrameHostImpl::LoadString(const CefString& string,
const CefString& url) {
// Only known frame ids or kMainFrameId are supported.
const auto frame_id = GetFrameId();
if (frame_id < CefFrameHostImpl::kMainFrameId)
return;
Cef_Request_Params params;
params.name = "load-string";
params.user_initiated = false;
params.request_id = -1;
params.expect_response = false;
params.arguments.AppendString(string);
params.arguments.AppendString(url);
Send(new CefMsg_Request(MSG_ROUTING_NONE, params));
}
void CefFrameHostImpl::ExecuteJavaScript(const CefString& jsCode, void CefFrameHostImpl::ExecuteJavaScript(const CefString& jsCode,
const CefString& scriptUrl, const CefString& scriptUrl,
int startLine) { int startLine) {

View File

@ -66,7 +66,6 @@ class CefFrameHostImpl : public CefFrame {
void GetText(CefRefPtr<CefStringVisitor> visitor) override; void GetText(CefRefPtr<CefStringVisitor> visitor) override;
void LoadRequest(CefRefPtr<CefRequest> request) override; void LoadRequest(CefRefPtr<CefRequest> request) override;
void LoadURL(const CefString& url) override; void LoadURL(const CefString& url) override;
void LoadString(const CefString& string, const CefString& url) override;
void ExecuteJavaScript(const CefString& jsCode, void ExecuteJavaScript(const CefString& jsCode,
const CefString& scriptUrl, const CefString& scriptUrl,
int startLine) override; int startLine) override;

View File

@ -153,17 +153,6 @@ void CefFrameImpl::LoadURL(const CefString& url) {
OnLoadRequest(params); OnLoadRequest(params);
} }
void CefFrameImpl::LoadString(const CefString& string, const CefString& url) {
CEF_REQUIRE_RT_RETURN_VOID();
if (frame_) {
GURL gurl = GURL(url.ToString());
content::RenderFrame::FromWebFrame(frame_)->LoadHTMLString(
string.ToString(), gurl, "UTF-8", GURL(),
false /* replace_current_item */);
}
}
void CefFrameImpl::ExecuteJavaScript(const CefString& jsCode, void CefFrameImpl::ExecuteJavaScript(const CefString& jsCode,
const CefString& scriptUrl, const CefString& scriptUrl,
int startLine) { int startLine) {
@ -481,17 +470,6 @@ void CefFrameImpl::OnRequest(const Cef_Request_Params& params) {
} else if (frame_->ExecuteCommand(blink::WebString::FromUTF8(command))) { } else if (frame_->ExecuteCommand(blink::WebString::FromUTF8(command))) {
success = true; success = true;
} }
} else if (params.name == "load-string") {
// Load a string.
DCHECK_EQ(params.arguments.GetSize(), (size_t)2);
std::string string, url;
params.arguments.GetString(0, &string);
params.arguments.GetString(1, &url);
content::RenderFrame::FromWebFrame(frame_)->LoadHTMLString(
string, GURL(url), "UTF-8", GURL(), false /* replace_current_item */);
} else { } else {
// Invalid request. // Invalid request.
NOTREACHED(); NOTREACHED();

View File

@ -55,7 +55,6 @@ class CefFrameImpl : public CefFrame {
void GetText(CefRefPtr<CefStringVisitor> visitor) override; void GetText(CefRefPtr<CefStringVisitor> visitor) override;
void LoadRequest(CefRefPtr<CefRequest> request) override; void LoadRequest(CefRefPtr<CefRequest> request) override;
void LoadURL(const CefString& url) override; void LoadURL(const CefString& url) override;
void LoadString(const CefString& string, const CefString& url) override;
void ExecuteJavaScript(const CefString& jsCode, void ExecuteJavaScript(const CefString& jsCode,
const CefString& scriptUrl, const CefString& scriptUrl,
int startLine) override; int startLine) override;

View File

@ -9,7 +9,7 @@
// implementations. See the translator.README.txt file in the tools directory // implementations. See the translator.README.txt file in the tools directory
// for more information. // for more information.
// //
// $hash=49a9d7412f4d9b8d5d7e15ce9f6f62e1b03ea248$ // $hash=ecb9362194093a89170324347f61c27c31c46685$
// //
#include "libcef_dll/cpptoc/frame_cpptoc.h" #include "libcef_dll/cpptoc/frame_cpptoc.h"
@ -219,29 +219,6 @@ void CEF_CALLBACK frame_load_url(struct _cef_frame_t* self,
CefFrameCppToC::Get(self)->LoadURL(CefString(url)); CefFrameCppToC::Get(self)->LoadURL(CefString(url));
} }
void CEF_CALLBACK frame_load_string(struct _cef_frame_t* self,
const cef_string_t* string_val,
const cef_string_t* url) {
shutdown_checker::AssertNotShutdown();
// AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING
DCHECK(self);
if (!self)
return;
// Verify param: string_val; type: string_byref_const
DCHECK(string_val);
if (!string_val)
return;
// Verify param: url; type: string_byref_const
DCHECK(url);
if (!url)
return;
// Execute
CefFrameCppToC::Get(self)->LoadString(CefString(string_val), CefString(url));
}
void CEF_CALLBACK frame_execute_java_script(struct _cef_frame_t* self, void CEF_CALLBACK frame_execute_java_script(struct _cef_frame_t* self,
const cef_string_t* code, const cef_string_t* code,
const cef_string_t* script_url, const cef_string_t* script_url,
@ -480,7 +457,6 @@ CefFrameCppToC::CefFrameCppToC() {
GetStruct()->get_text = frame_get_text; GetStruct()->get_text = frame_get_text;
GetStruct()->load_request = frame_load_request; GetStruct()->load_request = frame_load_request;
GetStruct()->load_url = frame_load_url; GetStruct()->load_url = frame_load_url;
GetStruct()->load_string = frame_load_string;
GetStruct()->execute_java_script = frame_execute_java_script; GetStruct()->execute_java_script = frame_execute_java_script;
GetStruct()->is_main = frame_is_main; GetStruct()->is_main = frame_is_main;
GetStruct()->is_focused = frame_is_focused; GetStruct()->is_focused = frame_is_focused;

View File

@ -9,7 +9,7 @@
// implementations. See the translator.README.txt file in the tools directory // implementations. See the translator.README.txt file in the tools directory
// for more information. // for more information.
// //
// $hash=957f55c65387757a411f9b898827bdef95531c45$ // $hash=99d10924d2ed2a233bd9d33314a627aa574cf89e$
// //
#include "libcef_dll/ctocpp/frame_ctocpp.h" #include "libcef_dll/ctocpp/frame_ctocpp.h"
@ -220,30 +220,6 @@ NO_SANITIZE("cfi-icall") void CefFrameCToCpp::LoadURL(const CefString& url) {
_struct->load_url(_struct, url.GetStruct()); _struct->load_url(_struct, url.GetStruct());
} }
NO_SANITIZE("cfi-icall")
void CefFrameCToCpp::LoadString(const CefString& string_val,
const CefString& url) {
shutdown_checker::AssertNotShutdown();
cef_frame_t* _struct = GetStruct();
if (CEF_MEMBER_MISSING(_struct, load_string))
return;
// AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING
// Verify param: string_val; type: string_byref_const
DCHECK(!string_val.empty());
if (string_val.empty())
return;
// Verify param: url; type: string_byref_const
DCHECK(!url.empty());
if (url.empty())
return;
// Execute
_struct->load_string(_struct, string_val.GetStruct(), url.GetStruct());
}
NO_SANITIZE("cfi-icall") NO_SANITIZE("cfi-icall")
void CefFrameCToCpp::ExecuteJavaScript(const CefString& code, void CefFrameCToCpp::ExecuteJavaScript(const CefString& code,
const CefString& script_url, const CefString& script_url,

View File

@ -9,7 +9,7 @@
// implementations. See the translator.README.txt file in the tools directory // implementations. See the translator.README.txt file in the tools directory
// for more information. // for more information.
// //
// $hash=1f9305ea3945990271795caf303c11ae09f662a4$ // $hash=016b054a1d376b7e66fa5bfc377be2d1da080631$
// //
#ifndef CEF_LIBCEF_DLL_CTOCPP_FRAME_CTOCPP_H_ #ifndef CEF_LIBCEF_DLL_CTOCPP_FRAME_CTOCPP_H_
@ -52,7 +52,6 @@ class CefFrameCToCpp
void GetText(CefRefPtr<CefStringVisitor> visitor) OVERRIDE; void GetText(CefRefPtr<CefStringVisitor> visitor) OVERRIDE;
void LoadRequest(CefRefPtr<CefRequest> request) OVERRIDE; void LoadRequest(CefRefPtr<CefRequest> request) OVERRIDE;
void LoadURL(const CefString& url) OVERRIDE; void LoadURL(const CefString& url) OVERRIDE;
void LoadString(const CefString& string_val, const CefString& url) OVERRIDE;
void ExecuteJavaScript(const CefString& code, void ExecuteJavaScript(const CefString& code,
const CefString& script_url, const CefString& script_url,
int start_line) OVERRIDE; int start_line) OVERRIDE;

View File

@ -4,6 +4,8 @@
#include "tests/cefclient/browser/test_runner.h" #include "tests/cefclient/browser/test_runner.h"
#include <map>
#include <set>
#include <sstream> #include <sstream>
#include "include/base/cef_bind.h" #include "include/base/cef_bind.h"
@ -36,6 +38,35 @@ const char kTestHost[] = "tests";
const char kLocalHost[] = "localhost"; const char kLocalHost[] = "localhost";
const char kTestOrigin[] = "http://tests/"; const char kTestOrigin[] = "http://tests/";
// Pages handled via StringResourceProvider.
const char kTestGetSourcePage[] = "get_source.html";
const char kTestGetTextPage[] = "get_text.html";
const char kTestPluginInfoPage[] = "plugin_info.html";
// Map of page name to data.
typedef std::map<std::string, std::string> StringResourceMap;
StringResourceMap* g_string_resource_map = NULL;
void SetStringResource(const std::string& page, const std::string& data) {
if (!CefCurrentlyOn(TID_IO)) {
CefPostTask(TID_IO, base::Bind(SetStringResource, page, data));
return;
}
if (g_string_resource_map) {
(*g_string_resource_map)[page] = data;
}
}
// Set page data and navigate the browser. Used in combination with
// StringResourceProvider.
void LoadStringResourcePage(CefRefPtr<CefBrowser> browser,
const std::string& page,
const std::string& data) {
SetStringResource(page, data);
browser->GetMainFrame()->LoadURL(kTestOrigin + page);
}
// Replace all instances of |from| with |to| in |str|. // Replace all instances of |from| with |to| in |str|.
std::string StringReplace(const std::string& str, std::string StringReplace(const std::string& str,
const std::string& from, const std::string& from,
@ -64,7 +95,7 @@ void RunGetSourceTest(CefRefPtr<CefBrowser> browser) {
std::stringstream ss; std::stringstream ss;
ss << "<html><body bgcolor=\"white\">Source:<pre>" << source ss << "<html><body bgcolor=\"white\">Source:<pre>" << source
<< "</pre></body></html>"; << "</pre></body></html>";
browser_->GetMainFrame()->LoadString(ss.str(), "http://tests/getsource"); LoadStringResourcePage(browser_, kTestGetSourcePage, ss.str());
} }
private: private:
@ -85,7 +116,7 @@ void RunGetTextTest(CefRefPtr<CefBrowser> browser) {
std::stringstream ss; std::stringstream ss;
ss << "<html><body bgcolor=\"white\">Text:<pre>" << text ss << "<html><body bgcolor=\"white\">Text:<pre>" << text
<< "</pre></body></html>"; << "</pre></body></html>";
browser_->GetMainFrame()->LoadString(ss.str(), "http://tests/gettext"); LoadStringResourcePage(browser_, kTestGetTextPage, ss.str());
} }
private: private:
@ -156,7 +187,7 @@ void RunPluginInfoTest(CefRefPtr<CefBrowser> browser) {
html_ += "\n</body></html>"; html_ += "\n</body></html>";
// Load the html in the browser. // Load the html in the browser.
browser_->GetMainFrame()->LoadString(html_, "http://tests/plugin_info"); LoadStringResourcePage(browser_, kTestPluginInfoPage, html_);
} }
virtual bool Visit(CefRefPtr<CefWebPluginInfo> info, virtual bool Visit(CefRefPtr<CefWebPluginInfo> info,
@ -465,6 +496,60 @@ class RequestDumpResourceProvider : public CefResourceManager::Provider {
DISALLOW_COPY_AND_ASSIGN(RequestDumpResourceProvider); DISALLOW_COPY_AND_ASSIGN(RequestDumpResourceProvider);
}; };
// Provider that returns string data for specific pages. Used in combination
// with LoadStringResourcePage().
class StringResourceProvider : public CefResourceManager::Provider {
public:
explicit StringResourceProvider(const std::set<std::string>& pages)
: pages_(pages) {
DCHECK(!pages.empty());
DCHECK(!g_string_resource_map);
g_string_resource_map = &resource_map_;
}
virtual ~StringResourceProvider() { g_string_resource_map = NULL; }
bool OnRequest(scoped_refptr<CefResourceManager::Request> request) OVERRIDE {
CEF_REQUIRE_IO_THREAD();
const std::string& url = request->url();
if (url.find(kTestOrigin) != 0U) {
// Not handled by this provider.
return false;
}
const std::string& page = url.substr(strlen(kTestOrigin));
if (pages_.find(page) == pages_.end()) {
// Not handled by this provider.
return false;
}
std::string value;
StringResourceMap::const_iterator it = resource_map_.find(page);
if (it != resource_map_.end()) {
value = it->second;
} else {
value = "<html><body>No data available</body></html>";
}
CefRefPtr<CefStreamReader> response = CefStreamReader::CreateForData(
static_cast<void*>(const_cast<char*>(value.c_str())), value.size());
request->Continue(new CefStreamResourceHandler(
200, "OK", "text/html", CefResponse::HeaderMap(), response));
return true;
}
private:
const std::set<std::string> pages_;
// Only accessed on the IO thread.
StringResourceMap resource_map_;
DISALLOW_COPY_AND_ASSIGN(StringResourceProvider);
};
// Add a file extension to |url| if none is currently specified. // Add a file extension to |url| if none is currently specified.
std::string RequestUrlFilter(const std::string& url) { std::string RequestUrlFilter(const std::string& url) {
if (url.find(kTestOrigin) != 0U) { if (url.find(kTestOrigin) != 0U) {
@ -742,6 +827,16 @@ void SetupResourceManager(CefRefPtr<CefResourceManager> resource_manager) {
new RequestDumpResourceProvider(test_origin + "request.html"), 0, new RequestDumpResourceProvider(test_origin + "request.html"), 0,
std::string()); std::string());
// Set of supported string pages.
std::set<std::string> string_pages;
string_pages.insert(kTestGetSourcePage);
string_pages.insert(kTestGetTextPage);
string_pages.insert(kTestPluginInfoPage);
// Add provider for string resources.
resource_manager->AddProvider(new StringResourceProvider(string_pages), 0,
std::string());
// Add provider for bundled resource files. // Add provider for bundled resource files.
#if defined(OS_WIN) #if defined(OS_WIN)
// Read resources from the binary. // Read resources from the binary.