Skip to content

Commit

Permalink
Remove CefFrame::LoadString method (fixes issue chromiumembedded#2586)
Browse files Browse the repository at this point in the history
This method has not behaved as expected for some time.
  • Loading branch information
magreenblatt committed Oct 15, 2019
1 parent d28efe8 commit 737ff18
Show file tree
Hide file tree
Showing 11 changed files with 107 additions and 122 deletions.
11 changes: 1 addition & 10 deletions include/capi/cef_frame_capi.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
// by hand. See the translator.README.txt file in the tools directory for
// more information.
//
// $hash=5f3cb132c1116a36c746c246ebeded195c917718$
// $hash=69e96203a1f5a71808125a25e511d99b599b7915$
//

#ifndef CEF_INCLUDE_CAPI_CEF_FRAME_CAPI_H_
Expand Down Expand Up @@ -145,15 +145,6 @@ typedef struct _cef_frame_t {
void(CEF_CALLBACK* load_url)(struct _cef_frame_t* self,
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|
// parameter is the URL where the script in question can be found, if any. The
Expand Down
10 changes: 5 additions & 5 deletions include/cef_api_hash.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
// implementations. See the translator.README.txt file in the tools directory
// for more information.
//
// $hash=42f531d8211496faa76ffa838a2cf0b9cfa45c56$
// $hash=714707190282ccff4cfc40f0f17b88c24f27236a$
//

#ifndef CEF_INCLUDE_API_HASH_H_
Expand All @@ -47,13 +47,13 @@
// way that may cause binary incompatibility with other builds. The universal
// hash value will change if any platform is affected whereas the platform hash
// 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)
#define CEF_API_HASH_PLATFORM "f691a75408d8ea7742a14db07fc1df73555320a3"
#define CEF_API_HASH_PLATFORM "fdc417626039e5cb7122cd531fcc82d3845354f4"
#elif defined(OS_MACOSX)
#define CEF_API_HASH_PLATFORM "1c2b7de4554429cfb71302d465cb55e6da45788d"
#define CEF_API_HASH_PLATFORM "184c18fff7d61c248062eb43092c8f6f94f051b0"
#elif defined(OS_LINUX)
#define CEF_API_HASH_PLATFORM "698c65121d173f8a72997e91783166a930c2efca"
#define CEF_API_HASH_PLATFORM "acc3cea452fa30b32d76d09282744a5dc30b9530"
#endif

#ifdef __cplusplus
Expand Down
9 changes: 0 additions & 9 deletions include/cef_frame.h
Original file line number Diff line number Diff line change
Expand Up @@ -145,15 +145,6 @@ class CefFrame : public virtual CefBaseRefCounted {
/*--cef()--*/
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|
// parameter is the URL where the script in question can be found, if any.
Expand Down
19 changes: 0 additions & 19 deletions libcef/browser/frame_host_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -168,25 +168,6 @@ void CefFrameHostImpl::LoadURL(const CefString& url) {
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,
const CefString& scriptUrl,
int startLine) {
Expand Down
1 change: 0 additions & 1 deletion libcef/browser/frame_host_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ class CefFrameHostImpl : public CefFrame {
void GetText(CefRefPtr<CefStringVisitor> visitor) override;
void LoadRequest(CefRefPtr<CefRequest> request) override;
void LoadURL(const CefString& url) override;
void LoadString(const CefString& string, const CefString& url) override;
void ExecuteJavaScript(const CefString& jsCode,
const CefString& scriptUrl,
int startLine) override;
Expand Down
22 changes: 0 additions & 22 deletions libcef/renderer/frame_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -153,17 +153,6 @@ void CefFrameImpl::LoadURL(const CefString& url) {
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,
const CefString& scriptUrl,
int startLine) {
Expand Down Expand Up @@ -481,17 +470,6 @@ void CefFrameImpl::OnRequest(const Cef_Request_Params& params) {
} else if (frame_->ExecuteCommand(blink::WebString::FromUTF8(command))) {
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 {
// Invalid request.
NOTREACHED();
Expand Down
1 change: 0 additions & 1 deletion libcef/renderer/frame_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ class CefFrameImpl : public CefFrame {
void GetText(CefRefPtr<CefStringVisitor> visitor) override;
void LoadRequest(CefRefPtr<CefRequest> request) override;
void LoadURL(const CefString& url) override;
void LoadString(const CefString& string, const CefString& url) override;
void ExecuteJavaScript(const CefString& jsCode,
const CefString& scriptUrl,
int startLine) override;
Expand Down
26 changes: 1 addition & 25 deletions libcef_dll/cpptoc/frame_cpptoc.cc
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
// implementations. See the translator.README.txt file in the tools directory
// for more information.
//
// $hash=49a9d7412f4d9b8d5d7e15ce9f6f62e1b03ea248$
// $hash=ecb9362194093a89170324347f61c27c31c46685$
//

#include "libcef_dll/cpptoc/frame_cpptoc.h"
Expand Down Expand Up @@ -219,29 +219,6 @@ void CEF_CALLBACK frame_load_url(struct _cef_frame_t* self,
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,
const cef_string_t* code,
const cef_string_t* script_url,
Expand Down Expand Up @@ -480,7 +457,6 @@ CefFrameCppToC::CefFrameCppToC() {
GetStruct()->get_text = frame_get_text;
GetStruct()->load_request = frame_load_request;
GetStruct()->load_url = frame_load_url;
GetStruct()->load_string = frame_load_string;
GetStruct()->execute_java_script = frame_execute_java_script;
GetStruct()->is_main = frame_is_main;
GetStruct()->is_focused = frame_is_focused;
Expand Down
26 changes: 1 addition & 25 deletions libcef_dll/ctocpp/frame_ctocpp.cc
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
// implementations. See the translator.README.txt file in the tools directory
// for more information.
//
// $hash=957f55c65387757a411f9b898827bdef95531c45$
// $hash=99d10924d2ed2a233bd9d33314a627aa574cf89e$
//

#include "libcef_dll/ctocpp/frame_ctocpp.h"
Expand Down Expand Up @@ -220,30 +220,6 @@ NO_SANITIZE("cfi-icall") void CefFrameCToCpp::LoadURL(const CefString& url) {
_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")
void CefFrameCToCpp::ExecuteJavaScript(const CefString& code,
const CefString& script_url,
Expand Down
3 changes: 1 addition & 2 deletions libcef_dll/ctocpp/frame_ctocpp.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
// implementations. See the translator.README.txt file in the tools directory
// for more information.
//
// $hash=1f9305ea3945990271795caf303c11ae09f662a4$
// $hash=016b054a1d376b7e66fa5bfc377be2d1da080631$
//

#ifndef CEF_LIBCEF_DLL_CTOCPP_FRAME_CTOCPP_H_
Expand Down Expand Up @@ -52,7 +52,6 @@ class CefFrameCToCpp
void GetText(CefRefPtr<CefStringVisitor> visitor) OVERRIDE;
void LoadRequest(CefRefPtr<CefRequest> request) OVERRIDE;
void LoadURL(const CefString& url) OVERRIDE;
void LoadString(const CefString& string_val, const CefString& url) OVERRIDE;
void ExecuteJavaScript(const CefString& code,
const CefString& script_url,
int start_line) OVERRIDE;
Expand Down
101 changes: 98 additions & 3 deletions tests/cefclient/browser/test_runner.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

#include "tests/cefclient/browser/test_runner.h"

#include <map>
#include <set>
#include <sstream>

#include "include/base/cef_bind.h"
Expand Down Expand Up @@ -36,6 +38,35 @@ const char kTestHost[] = "tests";
const char kLocalHost[] = "localhost";
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|.
std::string StringReplace(const std::string& str,
const std::string& from,
Expand Down Expand Up @@ -64,7 +95,7 @@ void RunGetSourceTest(CefRefPtr<CefBrowser> browser) {
std::stringstream ss;
ss << "<html><body bgcolor=\"white\">Source:<pre>" << source
<< "</pre></body></html>";
browser_->GetMainFrame()->LoadString(ss.str(), "http://tests/getsource");
LoadStringResourcePage(browser_, kTestGetSourcePage, ss.str());
}

private:
Expand All @@ -85,7 +116,7 @@ void RunGetTextTest(CefRefPtr<CefBrowser> browser) {
std::stringstream ss;
ss << "<html><body bgcolor=\"white\">Text:<pre>" << text
<< "</pre></body></html>";
browser_->GetMainFrame()->LoadString(ss.str(), "http://tests/gettext");
LoadStringResourcePage(browser_, kTestGetTextPage, ss.str());
}

private:
Expand Down Expand Up @@ -156,7 +187,7 @@ void RunPluginInfoTest(CefRefPtr<CefBrowser> browser) {
html_ += "\n</body></html>";

// Load the html in the browser.
browser_->GetMainFrame()->LoadString(html_, "http://tests/plugin_info");
LoadStringResourcePage(browser_, kTestPluginInfoPage, html_);
}

virtual bool Visit(CefRefPtr<CefWebPluginInfo> info,
Expand Down Expand Up @@ -465,6 +496,60 @@ class RequestDumpResourceProvider : public CefResourceManager::Provider {
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.
std::string RequestUrlFilter(const std::string& url) {
if (url.find(kTestOrigin) != 0U) {
Expand Down Expand Up @@ -742,6 +827,16 @@ void SetupResourceManager(CefRefPtr<CefResourceManager> resource_manager) {
new RequestDumpResourceProvider(test_origin + "request.html"), 0,
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.
#if defined(OS_WIN)
// Read resources from the binary.
Expand Down

0 comments on commit 737ff18

Please sign in to comment.