Introduce CefString and cef_string_t implementations that support string type conversions and customization of the API string type (issue #146).

git-svn-id: https://chromiumembedded.googlecode.com/svn/trunk@145 5089003a-bbd8-11dd-ad1f-f1f9622dbc98
This commit is contained in:
Marshall Greenblatt
2010-11-22 17:49:46 +00:00
parent 1e1c2ad8d7
commit 7d60642638
121 changed files with 2598 additions and 3209 deletions

View File

@ -40,11 +40,6 @@ using WebKit::WebString;
using WebKit::WebURL;
using WebKit::WebURLRequest;
using WebKit::WebView;
using webkit_glue::StdStringToWebString;
using webkit_glue::StdWStringToWebString;
using webkit_glue::WebStringToStdString;
using webkit_glue::WebStringToStdWString;
CefBrowserImpl::CefBrowserImpl(const CefWindowInfo& windowInfo,
const CefBrowserSettings& settings, bool popup,
@ -187,19 +182,19 @@ CefRefPtr<CefFrame> CefBrowserImpl::GetFocusedFrame()
return GetWebView() ? GetCefFrame(GetWebView()->focusedFrame()) : NULL;
}
CefRefPtr<CefFrame> CefBrowserImpl::GetFrame(const std::wstring& name)
CefRefPtr<CefFrame> CefBrowserImpl::GetFrame(const CefString& name)
{
WebView* view = GetWebView();
if (!view)
return NULL;
WebFrame* frame = view->findFrameByName(StdWStringToWebString(name));
WebFrame* frame = view->findFrameByName(string16(name));
if(frame)
return GetCefFrame(frame);
return NULL;
}
void CefBrowserImpl::GetFrameNames(std::vector<std::wstring>& names)
void CefBrowserImpl::GetFrameNames(std::vector<CefString>& names)
{
WebView* view = GetWebView();
if (!view)
@ -208,13 +203,15 @@ void CefBrowserImpl::GetFrameNames(std::vector<std::wstring>& names)
WebFrame* main_frame = view->mainFrame();
WebFrame* it = main_frame;
do {
if(it != main_frame)
names.push_back(UTF16ToWideHack(it->name()));
if(it != main_frame) {
string16 str = it->name();
names.push_back(str);
}
it = it->traverseNext(true);
} while (it != main_frame);
}
void CefBrowserImpl::Find(int identifier, const std::wstring& searchText,
void CefBrowserImpl::Find(int identifier, const CefString& searchText,
bool forward, bool matchCase, bool findNext)
{
WebKit::WebFindOptions options;
@ -244,11 +241,11 @@ CefRefPtr<CefFrame> CefBrowserImpl::GetCefFrame(WebFrame* frame)
if(frame == view->mainFrame()) {
// Use or create the single main frame reference.
if(frame_main_ == NULL)
frame_main_ = new CefFrameImpl(this, std::wstring());
frame_main_ = new CefFrameImpl(this, CefString());
cef_frame = frame_main_;
} else {
// Locate or create the appropriate named reference.
std::wstring name = UTF16ToWideHack(frame->name());
CefString name = frame->name();
DCHECK(!name.empty());
FrameMap::const_iterator it = frames_.find(name);
if(it != frames_.end())
@ -264,7 +261,7 @@ CefRefPtr<CefFrame> CefBrowserImpl::GetCefFrame(WebFrame* frame)
return cef_frame;
}
void CefBrowserImpl::RemoveCefFrame(const std::wstring& name)
void CefBrowserImpl::RemoveCefFrame(const CefString& name)
{
Lock();
@ -285,10 +282,10 @@ WebFrame* CefBrowserImpl::GetWebFrame(CefRefPtr<CefFrame> frame)
if (!view)
return NULL;
std::wstring name = frame->GetName();
CefString name = frame->GetName();
if(name.empty())
return view ->mainFrame();
return view ->findFrameByName(StdWStringToWebString(name));
return view ->findFrameByName(string16(name));
}
void CefBrowserImpl::Undo(CefRefPtr<CefFrame> frame)
@ -355,7 +352,7 @@ void CefBrowserImpl::ViewSource(CefRefPtr<CefFrame> frame)
&CefBrowserImpl::UIT_HandleAction, MENU_ID_VIEWSOURCE, frame.get()));
}
std::wstring CefBrowserImpl::GetSource(CefRefPtr<CefFrame> frame)
CefString CefBrowserImpl::GetSource(CefRefPtr<CefFrame> frame)
{
if(!CefThread::CurrentlyOn(CefThread::UI))
{
@ -377,22 +374,19 @@ std::wstring CefBrowserImpl::GetSource(CefRefPtr<CefFrame> frame)
// Wait for the UI thread callback to tell us that the data is available
event.Wait();
return UTF8ToWide(
static_cast<CefBytesWriter*>(stream.get())->GetDataString());
return static_cast<CefBytesWriter*>(stream.get())->GetDataString();
}
else
{
// Retrieve the document string directly
WebKit::WebFrame* web_frame = GetWebFrame(frame);
if(web_frame) {
std::string markup = web_frame->contentAsMarkup().utf8();
return UTF8ToWide(markup);
}
return std::wstring();
if(web_frame)
return web_frame->contentAsMarkup();
return CefString();
}
}
std::wstring CefBrowserImpl::GetText(CefRefPtr<CefFrame> frame)
CefString CefBrowserImpl::GetText(CefRefPtr<CefFrame> frame)
{
if(!CefThread::CurrentlyOn(CefThread::UI))
{
@ -414,8 +408,7 @@ std::wstring CefBrowserImpl::GetText(CefRefPtr<CefFrame> frame)
// Wait for the UI thread callback to tell us that the data is available
event.Wait();
return UTF8ToWide(
static_cast<CefBytesWriter*>(stream.get())->GetDataString());
return static_cast<CefBytesWriter*>(stream.get())->GetDataString();
}
else
{
@ -423,7 +416,7 @@ std::wstring CefBrowserImpl::GetText(CefRefPtr<CefFrame> frame)
WebKit::WebFrame* web_frame = GetWebFrame(frame);
if(web_frame)
return webkit_glue::DumpDocumentText(web_frame);
return std::wstring();
return CefString();
}
}
@ -438,7 +431,7 @@ void CefBrowserImpl::LoadRequest(CefRefPtr<CefFrame> frame,
}
void CefBrowserImpl::LoadURL(CefRefPtr<CefFrame> frame,
const std::wstring& url)
const CefString& url)
{
frame->AddRef();
CefThread::PostTask(CefThread::UI, FROM_HERE, NewRunnableMethod(this,
@ -446,8 +439,8 @@ void CefBrowserImpl::LoadURL(CefRefPtr<CefFrame> frame,
}
void CefBrowserImpl::LoadString(CefRefPtr<CefFrame> frame,
const std::wstring& string,
const std::wstring& url)
const CefString& string,
const CefString& url)
{
frame->AddRef();
CefThread::PostTask(CefThread::UI, FROM_HERE, NewRunnableMethod(this,
@ -456,7 +449,7 @@ void CefBrowserImpl::LoadString(CefRefPtr<CefFrame> frame,
void CefBrowserImpl::LoadStream(CefRefPtr<CefFrame> frame,
CefRefPtr<CefStreamReader> stream,
const std::wstring& url)
const CefString& url)
{
DCHECK(stream.get() != NULL);
frame->AddRef();
@ -467,8 +460,8 @@ void CefBrowserImpl::LoadStream(CefRefPtr<CefFrame> frame,
}
void CefBrowserImpl::ExecuteJavaScript(CefRefPtr<CefFrame> frame,
const std::wstring& jsCode,
const std::wstring& scriptUrl,
const CefString& jsCode,
const CefString& scriptUrl,
int startLine)
{
frame->AddRef();
@ -477,25 +470,23 @@ void CefBrowserImpl::ExecuteJavaScript(CefRefPtr<CefFrame> frame,
startLine));
}
std::wstring CefBrowserImpl::GetURL(CefRefPtr<CefFrame> frame)
CefString CefBrowserImpl::GetURL(CefRefPtr<CefFrame> frame)
{
WebFrame* web_frame = GetWebFrame(frame);
if(web_frame) {
std::string spec = web_frame->url().spec();
return UTF8ToWide(spec);
}
return std::wstring();
if(web_frame)
return web_frame->url().spec();
return CefString();
}
// static
bool CefBrowser::CreateBrowser(CefWindowInfo& windowInfo, bool popup,
CefRefPtr<CefHandler> handler,
const std::wstring& url)
const CefString& url)
{
if(!_Context.get())
return false;
std::wstring newUrl = url;
CefString newUrl = url;
CefBrowserSettings settings(_Context->browser_defaults());
if(handler.get())
@ -517,12 +508,12 @@ bool CefBrowser::CreateBrowser(CefWindowInfo& windowInfo, bool popup,
// static
CefRefPtr<CefBrowser> CefBrowser::CreateBrowserSync(CefWindowInfo& windowInfo,
bool popup, CefRefPtr<CefHandler> handler, const std::wstring& url)
bool popup, CefRefPtr<CefHandler> handler, const CefString& url)
{
if(!_Context.get() || !CefThread::CurrentlyOn(CefThread::UI))
return NULL;
std::wstring newUrl = url;
CefString newUrl = url;
CefRefPtr<CefBrowser> alternateBrowser;
CefBrowserSettings settings(_Context->browser_defaults());
@ -563,17 +554,17 @@ void CefBrowserImpl::UIT_DestroyBrowser()
}
void CefBrowserImpl::UIT_LoadURL(CefFrame* frame,
const std::wstring& url)
const CefString& url)
{
UIT_LoadURLForRequest(frame, url, std::wstring(), WebHTTPBody(),
UIT_LoadURLForRequest(frame, url, CefString(), WebHTTPBody(),
CefRequest::HeaderMap());
}
void CefBrowserImpl::UIT_LoadURLForRequestRef(CefFrame* frame,
CefRequest* request)
{
std::wstring url = request->GetURL();
std::wstring method = request->GetMethod();
CefString url = request->GetURL();
CefString method = request->GetMethod();
CefRequestImpl *impl = static_cast<CefRequestImpl*>(request);
@ -593,8 +584,8 @@ void CefBrowserImpl::UIT_LoadURLForRequestRef(CefFrame* frame,
}
void CefBrowserImpl::UIT_LoadURLForRequest(CefFrame* frame,
const std::wstring& url,
const std::wstring& method,
const CefString& url,
const CefString& method,
const WebKit::WebHTTPBody& upload_data,
const CefRequest::HeaderMap& headers)
{
@ -603,58 +594,61 @@ void CefBrowserImpl::UIT_LoadURLForRequest(CefFrame* frame,
if (url.empty())
return;
GURL gurl(StdWStringToWebString(url));
std::string urlStr(url);
GURL gurl = GURL(urlStr);
if (!gurl.is_valid() && !gurl.has_scheme()) {
// Try to add "http://" at the beginning
std::wstring new_url = std::wstring(L"http://") + url;
gurl = GURL(StdWStringToWebString(new_url));
std::string new_url = std::string("http://") + urlStr;
gurl = GURL(new_url);
if (!gurl.is_valid())
return;
}
nav_controller_->LoadEntry(
new BrowserNavigationEntry(-1, gurl, std::wstring(), frame->GetName(),
new BrowserNavigationEntry(-1, gurl, CefString(), frame->GetName(),
method, upload_data, headers));
frame->Release();
}
void CefBrowserImpl::UIT_LoadHTML(CefFrame* frame,
const std::wstring& html,
const std::wstring& url)
const CefString& html,
const CefString& url)
{
REQUIRE_UIT();
GURL gurl(StdWStringToWebString(url));
std::string urlStr(url);
GURL gurl = GURL(urlStr);
if (!gurl.is_valid() && !gurl.has_scheme()) {
// Try to add "http://" at the beginning
std::wstring new_url = std::wstring(L"http://") + url;
gurl = GURL(StdWStringToWebString(new_url));
std::string new_url = std::string("http://") + urlStr;
gurl = GURL(new_url);
if (!gurl.is_valid())
return;
}
WebFrame* web_frame = GetWebFrame(frame);
if(web_frame)
web_frame->loadHTMLString(WideToUTF8(html), gurl);
web_frame->loadHTMLString(std::string(html), gurl);
frame->Release();
}
void CefBrowserImpl::UIT_LoadHTMLForStreamRef(CefFrame* frame,
CefStreamReader* stream,
const std::wstring& url)
const CefString& url)
{
REQUIRE_UIT();
GURL gurl(StdWStringToWebString(url));
std::string urlStr(url);
GURL gurl = GURL(urlStr);
if (!gurl.is_valid() && !gurl.has_scheme()) {
// Try to add "http://" at the beginning
std::wstring new_url = std::wstring(L"http://") + url;
gurl = GURL(StdWStringToWebString(new_url));
std::string new_url = std::string("http://") + urlStr;
gurl = GURL(new_url);
if (!gurl.is_valid())
return;
}
@ -681,18 +675,16 @@ void CefBrowserImpl::UIT_LoadHTMLForStreamRef(CefFrame* frame,
}
void CefBrowserImpl::UIT_ExecuteJavaScript(CefFrame* frame,
const std::wstring& js_code,
const std::wstring& script_url,
const CefString& js_code,
const CefString& script_url,
int start_line)
{
REQUIRE_UIT();
WebFrame* web_frame = GetWebFrame(frame);
if(web_frame) {
web_frame->executeScript(
WebScriptSource(StdWStringToWebString(js_code),
WebURL(GURL(StdWStringToWebString(script_url))),
start_line));
web_frame->executeScript(WebScriptSource(string16(js_code),
WebURL(GURL(std::string(script_url))), start_line));
}
frame->Release();
@ -722,12 +714,10 @@ bool CefBrowserImpl::UIT_Navigate(const BrowserNavigationEntry& entry,
// Get the right target frame for the entry.
WebFrame* frame;
if (!entry.GetTargetFrame().empty()) {
frame = view->findFrameByName(
StdWStringToWebString(entry.GetTargetFrame()));
} else {
if (!entry.GetTargetFrame().empty())
frame = view->findFrameByName(string16(entry.GetTargetFrame()));
else
frame = view->mainFrame();
}
// TODO(mpcomplete): should we clear the target frame, or should
// back/forward navigations maintain the target frame?
@ -752,23 +742,22 @@ bool CefBrowserImpl::UIT_Navigate(const BrowserNavigationEntry& entry,
DCHECK(entry.GetPageID() == -1);
WebURLRequest request(entry.GetURL());
if(entry.GetMethod().size() > 0)
request.setHTTPMethod(StdWStringToWebString(entry.GetMethod()));
if(entry.GetMethod().length() > 0)
request.setHTTPMethod(string16(entry.GetMethod()));
if(entry.GetHeaders().size() > 0)
CefRequestImpl::SetHeaderMap(entry.GetHeaders(), request);
if(!entry.GetUploadData().isNull())
{
std::string method = WebStringToStdString(request.httpMethod());
if(method == "GET" || method == "HEAD") {
request.setHTTPMethod(StdStringToWebString("POST"));
}
if(request.httpHeaderField(StdStringToWebString("Content-Type")).length()
== 0) {
string16 method = request.httpMethod();
if(method == ASCIIToUTF16("GET") || method == ASCIIToUTF16("HEAD"))
request.setHTTPMethod(ASCIIToUTF16("POST"));
if(request.httpHeaderField(ASCIIToUTF16("Content-Type")).length() == 0) {
request.setHTTPHeaderField(
StdStringToWebString("Content-Type"),
StdStringToWebString("application/x-www-form-urlencoded"));
ASCIIToUTF16("Content-Type"),
ASCIIToUTF16("application/x-www-form-urlencoded"));
}
request.setHTTPBody(entry.GetUploadData());
}
@ -797,16 +786,16 @@ bool CefBrowserImpl::UIT_Navigate(const BrowserNavigationEntry& entry,
}
CefRefPtr<CefBrowserImpl> CefBrowserImpl::UIT_CreatePopupWindow(
const std::wstring& url, const CefPopupFeatures& features)
const CefString& url, const CefPopupFeatures& features)
{
REQUIRE_UIT();
CefWindowInfo info;
#if defined(OS_WIN)
info.SetAsPopup(NULL, url.c_str());
info.SetAsPopup(NULL, CefString());
#endif
CefRefPtr<CefHandler> handler = handler_;
std::wstring newUrl = url;
CefString newUrl = url;
// Start with the current browser window's settings.
CefBrowserSettings settings(settings_);
@ -938,10 +927,11 @@ void CefBrowserImpl::UIT_GetDocumentTextNotify(CefFrame* frame,
WebKit::WebFrame* web_frame = GetWebFrame(frame);
if(web_frame) {
// Retrieve the document string
std::wstring str = webkit_glue::DumpDocumentText(web_frame);
std::string cstr = WideToUTF8(str);
std::wstring wstr = webkit_glue::DumpDocumentText(web_frame);
std::string str;
WideToUTF8(wstr.c_str(), wstr.length(), &str);
// Write the document string to the stream
writer->Write(cstr.c_str(), cstr.size(), 1);
writer->Write(str.c_str(), str.size(), 1);
}
// Notify the calling thread that the data is now available
@ -973,7 +963,7 @@ void CefBrowserImpl::UIT_CanGoForwardNotify(bool *retVal,
event->Signal();
}
void CefBrowserImpl::UIT_Find(int identifier, const std::wstring& search_text,
void CefBrowserImpl::UIT_Find(int identifier, const CefString& search_text,
const WebKit::WebFindOptions& options)
{
WebView* view = GetWebView();
@ -981,6 +971,7 @@ void CefBrowserImpl::UIT_Find(int identifier, const std::wstring& search_text,
return;
WebFrame* main_frame = view->mainFrame();
string16 searchText(search_text);
if (main_frame->document().isPluginDocument()) {
WebPlugin* plugin = main_frame->document().to<WebPluginDocument>().plugin();
@ -990,8 +981,7 @@ void CefBrowserImpl::UIT_Find(int identifier, const std::wstring& search_text,
// Just navigate back/forward.
delegate->SelectFindResult(options.forward);
} else {
if (delegate->StartFind(StdWStringToWebString(search_text),
options.matchCase, identifier)) {
if (delegate->StartFind(searchText, options.matchCase, identifier)) {
} else {
// No find results.
UIT_NotifyFindStatus(identifier, 0, gfx::Rect(), 0, true);
@ -1018,8 +1008,8 @@ void CefBrowserImpl::UIT_Find(int identifier, const std::wstring& search_text,
WebRange current_selection = focused_frame->selectionRange();
do {
result = search_frame->find(identifier, StdWStringToWebString(search_text),
options, wrap_within_frame, &selection_rect);
result = search_frame->find(identifier, searchText, options,
wrap_within_frame, &selection_rect);
if (!result) {
// don't leave text selected as you move to the next frame.
@ -1045,7 +1035,7 @@ void CefBrowserImpl::UIT_Find(int identifier, const std::wstring& search_text,
// match for the search word(s).
if (multi_frame && search_frame == focused_frame) {
result = search_frame->find(
identifier, StdWStringToWebString(search_text),
identifier, searchText,
options, true, // Force wrapping.
&selection_rect);
}
@ -1086,9 +1076,7 @@ void CefBrowserImpl::UIT_Find(int identifier, const std::wstring& search_text,
if (result) {
// Start new scoping request. If the scoping function determines that it
// needs to scope, it will defer until later.
search_frame->scopeStringMatches(identifier,
StdWStringToWebString(search_text),
options,
search_frame->scopeStringMatches(identifier, searchText, options,
true); // reset the tickmarks
}

View File

@ -58,9 +58,9 @@ public:
virtual CefRefPtr<CefHandler> GetHandler();
virtual CefRefPtr<CefFrame> GetMainFrame();
virtual CefRefPtr<CefFrame> GetFocusedFrame();
virtual CefRefPtr<CefFrame> GetFrame(const std::wstring& name);
virtual void GetFrameNames(std::vector<std::wstring>& names);
virtual void Find(int identifier, const std::wstring& searchText,
virtual CefRefPtr<CefFrame> GetFrame(const CefString& name);
virtual void GetFrameNames(std::vector<CefString>& names);
virtual void Find(int identifier, const CefString& searchText,
bool forward, bool matchCase, bool findNext);
virtual void StopFinding(bool clearSelection);
@ -70,7 +70,7 @@ public:
// guarantee that the same CefFrame object will be returned across different
// calls to this function.
CefRefPtr<CefFrame> GetCefFrame(WebKit::WebFrame* frame);
void RemoveCefFrame(const std::wstring& name);
void RemoveCefFrame(const CefString& name);
// Return the WebFrame object associated with the specified CefFrame. This
// may return NULL if no WebFrame with the CefFrame's name exists.
@ -86,23 +86,23 @@ public:
void SelectAll(CefRefPtr<CefFrame> frame);
void Print(CefRefPtr<CefFrame> frame);
void ViewSource(CefRefPtr<CefFrame> frame);
std::wstring GetSource(CefRefPtr<CefFrame> frame);
std::wstring GetText(CefRefPtr<CefFrame> frame);
CefString GetSource(CefRefPtr<CefFrame> frame);
CefString GetText(CefRefPtr<CefFrame> frame);
void LoadRequest(CefRefPtr<CefFrame> frame,
CefRefPtr<CefRequest> request);
void LoadURL(CefRefPtr<CefFrame> frame,
const std::wstring& url);
const CefString& url);
void LoadString(CefRefPtr<CefFrame> frame,
const std::wstring& string,
const std::wstring& url);
const CefString& string,
const CefString& url);
void LoadStream(CefRefPtr<CefFrame> frame,
CefRefPtr<CefStreamReader> stream,
const std::wstring& url);
const CefString& url);
void ExecuteJavaScript(CefRefPtr<CefFrame> frame,
const std::wstring& jsCode,
const std::wstring& scriptUrl,
const CefString& jsCode,
const CefString& scriptUrl,
int startLine);
std::wstring GetURL(CefRefPtr<CefFrame> frame);
CefString GetURL(CefRefPtr<CefFrame> frame);
WebKit::WebView* GetWebView() const {
return webviewhost_.get() ? webviewhost_->webview() : NULL;
@ -151,36 +151,36 @@ public:
is_modal_ = val;
}
void UIT_SetTitle(const std::wstring& title) {
void UIT_SetTitle(const CefString& title) {
REQUIRE_UIT();
title_ = title;
}
std::wstring UIT_GetTitle() {
CefString UIT_GetTitle() {
REQUIRE_UIT();
return title_;
}
void UIT_CreateBrowser(const std::wstring& url);
void UIT_CreateBrowser(const CefString& url);
void UIT_DestroyBrowser();
void UIT_LoadURL(CefFrame* frame,
const std::wstring& url);
const CefString& url);
void UIT_LoadURLForRequest(CefFrame* frame,
const std::wstring& url,
const std::wstring& method,
const CefString& url,
const CefString& method,
const WebKit::WebHTTPBody& upload_data,
const CefRequest::HeaderMap& headers);
void UIT_LoadURLForRequestRef(CefFrame* frame,
CefRequest* request);
void UIT_LoadHTML(CefFrame* frame,
const std::wstring& html,
const std::wstring& url);
const CefString& html,
const CefString& url);
void UIT_LoadHTMLForStreamRef(CefFrame* frame,
CefStreamReader* stream,
const std::wstring& url);
const CefString& url);
void UIT_ExecuteJavaScript(CefFrame* frame,
const std::wstring& js_code,
const std::wstring& script_url,
const CefString& js_code,
const CefString& script_url,
int start_line);
void UIT_GoBackOrForward(int offset);
void UIT_Reload(bool ignoreCache);
@ -189,7 +189,7 @@ public:
bool ignoreCahce);
void UIT_SetFocus(WebWidgetHost* host, bool enable);
CefRefPtr<CefBrowserImpl> UIT_CreatePopupWindow(const std::wstring& url,
CefRefPtr<CefBrowserImpl> UIT_CreatePopupWindow(const CefString& url,
const CefPopupFeatures& features);
WebKit::WebWidget* UIT_CreatePopupWidget();
void UIT_ClosePopupWidget();
@ -223,7 +223,7 @@ public:
void UIT_SetUniqueID(int id) { unique_id_ = id; }
int UIT_GetUniqueID() { return unique_id_; }
void UIT_Find(int identifier, const std::wstring& search_text,
void UIT_Find(int identifier, const CefString& search_text,
const WebKit::WebFindOptions& options);
void UIT_StopFinding(bool clear_selection);
void UIT_NotifyFindStatus(int identifier, int count,
@ -247,14 +247,14 @@ protected:
scoped_ptr<BrowserWebViewDelegate> popup_delegate_;
scoped_ptr<BrowserNavigationController> nav_controller_;
std::wstring title_;
CefString title_;
#if defined(OS_WIN)
// Context object used to manage printing.
printing::PrintingContext print_context_;
#endif
typedef std::map<std::wstring, CefFrame*> FrameMap;
typedef std::map<CefString, CefFrame*> FrameMap;
FrameMap frames_;
CefFrame* frame_main_;
@ -270,7 +270,7 @@ protected:
class CefFrameImpl : public CefThreadSafeBase<CefFrame>
{
public:
CefFrameImpl(CefBrowserImpl* browser, const std::wstring& name)
CefFrameImpl(CefBrowserImpl* browser, const CefString& name)
: browser_(browser), name_(name) {}
virtual ~CefFrameImpl() { browser_->RemoveCefFrame(name_); }
@ -284,30 +284,30 @@ public:
virtual void SelectAll() { browser_->SelectAll(this); }
virtual void Print() { browser_->Print(this); }
virtual void ViewSource() { browser_->ViewSource(this); }
virtual std::wstring GetSource() { return browser_->GetSource(this); }
virtual std::wstring GetText() { return browser_->GetText(this); }
virtual CefString GetSource() { return browser_->GetSource(this); }
virtual CefString GetText() { return browser_->GetText(this); }
virtual void LoadRequest(CefRefPtr<CefRequest> request)
{ return browser_->LoadRequest(this, request); }
virtual void LoadURL(const std::wstring& url)
virtual void LoadURL(const CefString& url)
{ return browser_->LoadURL(this, url); }
virtual void LoadString(const std::wstring& string,
const std::wstring& url)
virtual void LoadString(const CefString& string,
const CefString& url)
{ return browser_->LoadString(this, string, url); }
virtual void LoadStream(CefRefPtr<CefStreamReader> stream,
const std::wstring& url)
const CefString& url)
{ return browser_->LoadStream(this, stream, url); }
virtual void ExecuteJavaScript(const std::wstring& jsCode,
const std::wstring& scriptUrl,
virtual void ExecuteJavaScript(const CefString& jsCode,
const CefString& scriptUrl,
int startLine)
{ return browser_->ExecuteJavaScript(this, jsCode, scriptUrl, startLine); }
virtual bool IsMain() { return name_.empty(); }
virtual bool IsFocused();
virtual std::wstring GetName() { return name_; }
virtual std::wstring GetURL() { return browser_->GetURL(this); }
virtual CefString GetName() { return name_; }
virtual CefString GetURL() { return browser_->GetURL(this); }
private:
CefRefPtr<CefBrowserImpl> browser_;
std::wstring name_;
CefString name_;
};
#endif // _BROWSER_IMPL_H

View File

@ -10,7 +10,6 @@
#import <Cocoa/Cocoa.h>
#include "base/utf_string_conversions.h"
#include "third_party/WebKit/WebKit/chromium/public/WebFrame.h"
#include "third_party/WebKit/WebKit/chromium/public/WebRect.h"
#include "third_party/WebKit/WebKit/chromium/public/WebSize.h"
@ -32,7 +31,7 @@ gfx::NativeWindow CefBrowserImpl::GetMainWndHandle() const {
return (NSWindow*)window_info_.m_View;
}
void CefBrowserImpl::UIT_CreateBrowser(const std::wstring& url)
void CefBrowserImpl::UIT_CreateBrowser(const CefString& url)
{
REQUIRE_UIT();
@ -67,7 +66,7 @@ void CefBrowserImpl::UIT_CreateBrowser(const std::wstring& url)
if(url.size() > 0) {
CefRefPtr<CefFrame> frame = GetMainFrame();
frame->AddRef();
UIT_LoadURL(frame, url.c_str());
UIT_LoadURL(frame, url);
}
}

View File

@ -8,7 +8,6 @@
#include "browser_settings.h"
#include "printing/units.h"
#include "base/utf_string_conversions.h"
#include "base/win_util.h"
#include "skia/ext/vector_canvas.h"
#include "third_party/WebKit/WebKit/chromium/public/WebFrame.h"
@ -96,13 +95,15 @@ gfx::NativeWindow CefBrowserImpl::GetMainWndHandle() const {
return window_info_.m_hWnd;
}
void CefBrowserImpl::UIT_CreateBrowser(const std::wstring& url)
void CefBrowserImpl::UIT_CreateBrowser(const CefString& url)
{
REQUIRE_UIT();
std::wstring windowName(CefString(&window_info_.m_windowName));
// Create the new browser window
window_info_.m_hWnd = CreateWindowEx(window_info_.m_dwExStyle, GetWndClass(),
window_info_.m_windowName, window_info_.m_dwStyle,
windowName.c_str(), window_info_.m_dwStyle,
window_info_.m_x, window_info_.m_y, window_info_.m_nWidth,
window_info_.m_nHeight, window_info_.m_hWndParent, window_info_.m_hMenu,
::GetModuleHandle(NULL), NULL);
@ -140,10 +141,10 @@ void CefBrowserImpl::UIT_CreateBrowser(const std::wstring& url)
handler_->HandleAfterCreated(this);
}
if(url.size() > 0) {
if(url.length() > 0) {
CefRefPtr<CefFrame> frame = GetMainFrame();
frame->AddRef();
UIT_LoadURL(frame, url.c_str());
UIT_LoadURL(frame, url);
}
}
@ -307,12 +308,11 @@ void CefBrowserImpl::UIT_PrintPage(int page_number, int total_pages,
printInfo.m_Rect = rect;
printInfo.m_Scale = scale;
std::string spec = frame->url().spec();
std::wstring url = UTF8ToWide(spec);
std::wstring title = title_;
CefString url(frame->url().spec());
CefString title = title_;
std::wstring topLeft, topCenter, topRight;
std::wstring bottomLeft, bottomCenter, bottomRight;
CefString topLeft, topCenter, topRight;
CefString bottomLeft, bottomCenter, bottomRight;
// allow the handler to format print header and/or footer
CefHandler::RetVal rv = handler_->HandlePrintHeaderFooter(this,
@ -333,33 +333,39 @@ void CefBrowserImpl::UIT_PrintPage(int page_number, int total_pages,
// TODO(cef): Keep the header strings inside a reasonable bounding box
// so that they don't overlap each other.
if(topLeft.size() > 0) {
DrawText(hDC, topLeft.c_str(), topLeft.size(), &rect,
if(topLeft.length() > 0) {
std::wstring topLeftStr(topLeft);
DrawText(hDC, topLeftStr.c_str(), topLeftStr.length(), &rect,
DT_LEFT | DT_TOP | DT_SINGLELINE | DT_END_ELLIPSIS
| DT_EXPANDTABS | DT_NOPREFIX);
}
if(topCenter.size() > 0) {
DrawText(hDC, topCenter.c_str(), topCenter.size(), &rect,
if(topCenter.length() > 0) {
std::wstring topCenterStr(topCenter);
DrawText(hDC, topCenterStr.c_str(), topCenterStr.length(), &rect,
DT_CENTER | DT_TOP | DT_SINGLELINE | DT_END_ELLIPSIS
| DT_EXPANDTABS | DT_NOPREFIX);
}
if(topRight.size() > 0) {
DrawText(hDC, topRight.c_str(), topRight.size(), &rect,
if(topRight.length() > 0) {
std::wstring topRightStr(topRight);
DrawText(hDC, topRightStr.c_str(), topRightStr.length(), &rect,
DT_RIGHT | DT_TOP | DT_SINGLELINE | DT_END_ELLIPSIS
| DT_EXPANDTABS | DT_NOPREFIX);
}
if(bottomLeft.size() > 0) {
DrawText(hDC, bottomLeft.c_str(), bottomLeft.size(), &rect,
if(bottomLeft.length() > 0) {
std::wstring bottomLeftStr(bottomLeft);
DrawText(hDC, bottomLeftStr.c_str(), bottomLeftStr.length(), &rect,
DT_LEFT | DT_BOTTOM | DT_SINGLELINE | DT_END_ELLIPSIS
| DT_EXPANDTABS | DT_NOPREFIX);
}
if(bottomCenter.size() > 0) {
DrawText(hDC, bottomCenter.c_str(), bottomCenter.size(), &rect,
if(bottomCenter.length() > 0) {
std::wstring bottomCenterStr(bottomCenter);
DrawText(hDC, bottomCenterStr.c_str(), bottomCenterStr.length(), &rect,
DT_CENTER | DT_BOTTOM | DT_SINGLELINE | DT_END_ELLIPSIS
| DT_EXPANDTABS | DT_NOPREFIX);
}
if(bottomRight.size() > 0) {
DrawText(hDC, bottomRight.c_str(), bottomRight.size(), &rect,
if(bottomRight.length() > 0) {
std::wstring bottomRightStr(bottomRight);
DrawText(hDC, bottomRightStr.c_str(), bottomRightStr.length(), &rect,
DT_RIGHT | DT_BOTTOM | DT_SINGLELINE | DT_END_ELLIPSIS
| DT_EXPANDTABS | DT_NOPREFIX);
}

View File

@ -18,9 +18,9 @@ BrowserNavigationEntry::BrowserNavigationEntry()
BrowserNavigationEntry::BrowserNavigationEntry(int page_id,
const GURL& url,
const std::wstring& title,
const std::wstring& target_frame,
const std::wstring& method,
const CefString& title,
const CefString& target_frame,
const CefString& method,
const WebKit::WebHTTPBody& upload,
const CefRequest::HeaderMap& headers)
: page_id_(page_id),

View File

@ -43,9 +43,9 @@ class BrowserNavigationEntry {
BrowserNavigationEntry();
BrowserNavigationEntry(int page_id,
const GURL& url,
const std::wstring& title,
const std::wstring& target_frame,
const std::wstring& method,
const CefString& title,
const CefString& target_frame,
const CefString& method,
const WebKit::WebHTTPBody& upload,
const CefRequest::HeaderMap& headers);
~BrowserNavigationEntry();
@ -55,8 +55,8 @@ class BrowserNavigationEntry {
const GURL& GetURL() const { return url_; }
// Set / Get the title
void SetTitle(const std::wstring& a_title) { title_ = a_title; }
const std::wstring& GetTitle() const { return title_; }
void SetTitle(const CefString& a_title) { title_ = a_title; }
const CefString& GetTitle() const { return title_; }
// Set / Get opaque state.
// WARNING: This state is saved to the database and used to restore previous
@ -70,9 +70,9 @@ class BrowserNavigationEntry {
void SetPageID(int page_id) { page_id_ = page_id; }
int32 GetPageID() const { return page_id_; }
const std::wstring& GetTargetFrame() const { return target_frame_; }
const CefString& GetTargetFrame() const { return target_frame_; }
const std::wstring& GetMethod() const { return method_; }
const CefString& GetMethod() const { return method_; }
const WebKit::WebHTTPBody& GetUploadData() const { return upload_; }
const CefRequest::HeaderMap& GetHeaders() const { return headers_; }
@ -82,13 +82,13 @@ private:
int32 page_id_;
GURL url_;
std::wstring title_;
CefString title_;
std::string state_;
std::wstring method_;
CefString method_;
WebKit::WebHTTPBody upload_;
CefRequest::HeaderMap headers_;
std::wstring target_frame_;
CefString target_frame_;
DISALLOW_COPY_AND_ASSIGN(BrowserNavigationEntry);
};

View File

@ -53,7 +53,6 @@
#include "base/time.h"
#include "base/timer.h"
#include "base/thread.h"
#include "base/utf_string_conversions.h"
#include "base/waitable_event.h"
#include "net/base/cookie_store.h"
#include "net/base/file_stream.h"
@ -178,8 +177,7 @@ class RequestProxy : public URLRequest::Delegate,
CefRefPtr<CefHandler> handler = browser_->GetHandler();
if (handler.get()) {
CefRefPtr<CefDownloadHandler> dl_handler;
if (handler->HandleDownloadResponse(browser_,
UTF8ToWide(info.mime_type), UTF8ToWide(filename),
if (handler->HandleDownloadResponse(browser_, info.mime_type, filename,
info.content_length, dl_handler) == RV_CONTINUE) {
download_handler_ = dl_handler;
}
@ -263,15 +261,14 @@ class RequestProxy : public URLRequest::Delegate,
CefRefPtr<CefRequest> request(new CefRequestImpl());
CefRequestImpl* requestimpl = static_cast<CefRequestImpl*>(request.get());
const std::wstring originalUrl = UTF8ToWide(params->url.spec());
std::string originalUrl(params->url.spec());
requestimpl->SetURL(originalUrl);
requestimpl->SetMethod(UTF8ToWide(params->method));
requestimpl->SetMethod(params->method);
// Transfer request headers
CefRequest::HeaderMap headerMap;
CefRequestImpl::ParseHeaders(params->headers, headerMap);
headerMap.insert(
std::make_pair(L"Referrer", UTF8ToWide(params->referrer.spec())));
headerMap.insert(std::make_pair("Referrer", params->referrer.spec()));
requestimpl->SetHeaderMap(headerMap);
// Transfer post data, if any
@ -285,30 +282,33 @@ class RequestProxy : public URLRequest::Delegate,
int loadFlags = params->load_flags;
// Handler output will be returned in these variables
std::wstring redirectUrl;
CefString redirectUrl;
CefRefPtr<CefStreamReader> resourceStream;
std::wstring mimeType;
CefString mimeType;
CefHandler::RetVal rv = handler->HandleBeforeResourceLoad(
browser_, request, redirectUrl, resourceStream, mimeType, loadFlags);
browser_, request, redirectUrl, resourceStream, mimeType,
loadFlags);
// Observe URL from request.
const std::wstring requestUrl = request->GetURL();
const std::string requestUrl(request->GetURL());
if(requestUrl != originalUrl) {
params->url = GURL(WideToUTF8(requestUrl));
params->url = GURL(requestUrl);
redirectUrl.clear(); // Request URL trumps redirect URL
}
// Observe method from request.
params->method = WideToUTF8(request->GetMethod());
params->method = request->GetMethod();
// Observe headers from request.
request->GetHeaderMap(headerMap);
CefRequest::HeaderMap::iterator referrer = headerMap.find(L"Referrer");
CefString referrerStr;
referrerStr.FromASCII("Referrer");
CefRequest::HeaderMap::iterator referrer = headerMap.find(referrerStr);
if(referrer == headerMap.end()) {
params->referrer = GURL();
} else {
params->referrer = GURL(WideToUTF8(referrer->second));
params->referrer = GURL(std::string(referrer->second));
headerMap.erase(referrer);
}
params->headers = CefRequestImpl::GenerateHeaders(headerMap);
@ -328,7 +328,7 @@ class RequestProxy : public URLRequest::Delegate,
std::string(), base::Time());
} else if(!redirectUrl.empty()) {
// redirect to the specified URL
params->url = GURL(WideToUTF8(redirectUrl));
params->url = GURL(std::string(redirectUrl));
ResourceResponseInfo info;
bool defer_redirect;
OnReceivedRedirect(params->url, info, &defer_redirect);
@ -345,7 +345,7 @@ class RequestProxy : public URLRequest::Delegate,
ResourceResponseInfo info;
info.content_length = static_cast<int64>(offset);
if(!mimeType.empty())
info.mime_type = WideToUTF8(mimeType);
info.mime_type = mimeType;
OnReceivedResponse(info, false);
AsyncReadData();
}

View File

@ -3,44 +3,43 @@
// be found in the LICENSE file.
#include "../include/cef.h"
#include "base/utf_string_conversions.h"
#include "webkit/glue/webpreferences.h"
void BrowserToWebSettings(const CefBrowserSettings& cef, WebPreferences& web)
{
if (cef.standard_font_family)
web.standard_font_family = cef.standard_font_family;
void BrowserToWebSettings(const CefBrowserSettings& cef, WebPreferences& web)
{
if (cef.standard_font_family.length > 0)
web.standard_font_family = CefString(&cef.standard_font_family);
else
web.standard_font_family = L"Times";
if (cef.fixed_font_family)
web.fixed_font_family = cef.fixed_font_family;
if (cef.fixed_font_family.length > 0)
web.fixed_font_family = CefString(&cef.fixed_font_family);
else
web.fixed_font_family = L"Courier";
if (cef.serif_font_family)
web.serif_font_family = cef.serif_font_family;
if (cef.serif_font_family.length > 0)
web.serif_font_family = CefString(&cef.serif_font_family);
else
web.serif_font_family = L"Times";
if (cef.sans_serif_font_family)
web.sans_serif_font_family = cef.sans_serif_font_family;
if (cef.sans_serif_font_family.length > 0)
web.sans_serif_font_family = CefString(&cef.sans_serif_font_family);
else
web.sans_serif_font_family = L"Helvetica";
// These two fonts below are picked from the intersection of
// Win XP font list and Vista font list :
// http://www.microsoft.com/typography/fonts/winxp.htm
// http://blogs.msdn.com/michkap/archive/2006/04/04/567881.aspx
// Some of them are installed only with CJK and complex script
// support enabled on Windows XP and are out of consideration here.
// (although we enabled both on our buildbots.)
// They (especially Impact for fantasy) are not typical cursive
// and fantasy fonts, but it should not matter for layout tests
// These two fonts below are picked from the intersection of
// Win XP font list and Vista font list :
// http://www.microsoft.com/typography/fonts/winxp.htm
// http://blogs.msdn.com/michkap/archive/2006/04/04/567881.aspx
// Some of them are installed only with CJK and complex script
// support enabled on Windows XP and are out of consideration here.
// (although we enabled both on our buildbots.)
// They (especially Impact for fantasy) are not typical cursive
// and fantasy fonts, but it should not matter for layout tests
// as long as they're available.
if (cef.cursive_font_family) {
web.cursive_font_family = cef.cursive_font_family;
if (cef.cursive_font_family.length > 0) {
web.cursive_font_family = CefString(&cef.cursive_font_family);
} else {
#if defined(OS_MACOSX)
web.cursive_font_family = L"Apple Chancery";
@ -49,8 +48,8 @@ void BrowserToWebSettings(const CefBrowserSettings& cef, WebPreferences& web)
#endif
}
if (cef.fantasy_font_family) {
web.fantasy_font_family = cef.fantasy_font_family;
if (cef.fantasy_font_family.length > 0) {
web.fantasy_font_family = CefString(&cef.fantasy_font_family);
} else {
#if defined(OS_MACOSX)
web.fantasy_font_family = L"Papyrus";
@ -79,8 +78,8 @@ void BrowserToWebSettings(const CefBrowserSettings& cef, WebPreferences& web)
else
web.minimum_logical_font_size = 9;
if (cef.default_encoding)
web.default_encoding = WideToUTF8(cef.default_encoding);
if (cef.default_encoding.length > 0)
web.default_encoding = CefString(&cef.default_encoding);
else
web.default_encoding = "ISO-8859-1";
@ -113,9 +112,9 @@ void BrowserToWebSettings(const CefBrowserSettings& cef, WebPreferences& web)
web.user_style_sheet_enabled = cef.user_style_sheet_enabled;
if (cef.user_style_sheet_location) {
if (cef.user_style_sheet_location.length > 0) {
web.user_style_sheet_location =
GURL(WideToUTF8(cef.user_style_sheet_location));
GURL(std::string(CefString(&cef.user_style_sheet_location)));
}
web.author_and_user_styles_enabled = !cef.author_and_user_styles_disabled;
@ -126,89 +125,5 @@ void BrowserToWebSettings(const CefBrowserSettings& cef, WebPreferences& web)
web.show_composited_layer_borders = false;
web.accelerated_compositing_enabled = !cef.accelerated_compositing_disabled;
web.accelerated_2d_canvas_enabled = !cef.accelerated_2d_canvas_disabled;
web.memory_info_enabled = false;
}
void WebToBrowserSettings(const WebPreferences& web, CefBrowserSettings& cef)
{
cef.Reset();
if (!web.standard_font_family.empty()) {
cef.standard_font_family =
cef_string_alloc(web.standard_font_family.c_str());
}
if (!web.fixed_font_family.empty()) {
cef.fixed_font_family =
cef_string_alloc(web.fixed_font_family.c_str());
}
if (!web.serif_font_family.empty()) {
cef.serif_font_family =
cef_string_alloc(web.serif_font_family.c_str());
}
if (!web.cursive_font_family.empty()) {
cef.cursive_font_family =
cef_string_alloc(web.cursive_font_family.c_str());
}
if (!web.fantasy_font_family.empty()) {
cef.fantasy_font_family =
cef_string_alloc(web.fantasy_font_family.c_str());
}
cef.default_font_size = web.default_font_size;
cef.default_fixed_font_size = web.default_fixed_font_size;
cef.minimum_font_size = web.minimum_font_size;
cef.minimum_logical_font_size = web.minimum_logical_font_size;
cef.remote_fonts_disabled = !web.remote_fonts_enabled;
if (!web.default_encoding.empty()) {
std::wstring wstr;
UTF8ToWide(web.default_encoding.c_str(), web.default_encoding.length(),
&wstr);
cef.default_encoding = cef_string_alloc(wstr.c_str());
}
cef.encoding_detector_enabled = web.uses_universal_detector;
cef.javascript_disabled = !web.java_enabled;
cef.javascript_open_windows_disallowed =
!web.javascript_can_open_windows_automatically;
cef.javascript_close_windows_disallowed =
!web.allow_scripts_to_close_windows;
cef.javascript_access_clipboard_disallowed =
!web.javascript_can_access_clipboard;
cef.dom_paste_disabled = !web.dom_paste_enabled;
cef.caret_browsing_enabled = web.caret_browsing_enabled;
cef.java_disabled = !web.java_enabled;
cef.plugins_disabled = !web.plugins_enabled;
cef.universal_access_from_file_urls_allowed =
web.allow_universal_access_from_file_urls;
cef.file_access_from_file_urls_allowed = web.allow_file_access_from_file_urls;
cef.web_security_disabled = !web.web_security_enabled;
cef.xss_auditor_enabled = web.xss_auditor_enabled;
cef.image_load_disabled = !web.loads_images_automatically;
cef.shrink_standalone_images_to_fit = web.shrinks_standalone_images_to_fit;
cef.site_specific_quirks_disabled = !web.site_specific_quirks_enabled;
cef.text_area_resize_disabled = !web.text_areas_are_resizable;
cef.page_cache_disabled = !web.uses_page_cache;
cef.tab_to_links_disabled = !web.tabs_to_links;
cef.hyperlink_auditing_disabled = !web.hyperlink_auditing_enabled;
cef.user_style_sheet_enabled = web.user_style_sheet_enabled;
if (!web.user_style_sheet_location.is_empty()) {
std::string str = web.user_style_sheet_location.spec();
std::wstring wstr;
UTF8ToWide(str.c_str(), str.length(), &wstr);
cef.user_style_sheet_location = cef_string_alloc(wstr.c_str());
}
cef.author_and_user_styles_disabled = !web.author_and_user_styles_enabled;
cef.local_storage_disabled = !web.local_storage_enabled;
cef.databases_disabled = !web.databases_enabled;
cef.application_cache_disabled = !web.application_cache_enabled;
cef.experimental_webgl_enabled = web.experimental_webgl_enabled;
cef.accelerated_compositing_disabled = !web.accelerated_compositing_enabled;
cef.accelerated_2d_canvas_disabled = !web.accelerated_2d_canvas_enabled;
}
web.memory_info_enabled = false;
}

View File

@ -9,6 +9,5 @@ class CefBrowserSettings;
struct WebPreferences;
void BrowserToWebSettings(const CefBrowserSettings& cef, WebPreferences& web);
void WebToBrowserSettings(const WebPreferences& web, CefBrowserSettings& cef);
#endif // _CEF_BROWSER_SETTINGS_H

View File

@ -22,7 +22,6 @@ MSVC_POP_WARNING();
#include "base/path_service.h"
#include "base/scoped_ptr.h"
#include "base/string16.h"
#include "base/utf_string_conversions.h"
#include "net/base/mime_util.h"
#include "third_party/WebKit/WebKit/chromium/public/WebFrame.h"
#include "third_party/WebKit/WebKit/chromium/public/WebString.h"
@ -73,8 +72,8 @@ bool IsProtocolSupportedForMedia(const GURL& url) {
std::string GetWebKitLocale() {
const CefSettings& settings = _Context->settings();
if (settings.locale)
return WideToUTF8(settings.locale);
if (settings.locale.length > 0)
return CefString(&settings.locale);
return "en-US";
}
@ -104,29 +103,11 @@ void ClearCache()
WebCore::cache()->setDisabled(false);
}
WebKit::WebString StdStringToWebString(const std::string& str) {
return WebKit::WebString::fromUTF8(str.data(), str.size());
}
std::string WebStringToStdString(const WebKit::WebString& str) {
std::string ret;
if (!str.isNull())
UTF16ToUTF8(str.data(), str.length(), &ret);
return ret;
}
WebKit::WebString StdWStringToWebString(const std::wstring& str) {
return StdStringToWebString(WideToUTF8(str));
}
std::wstring WebStringToStdWString(const WebKit::WebString& str) {
return UTF8ToWide(WebStringToStdString(str));
}
std::string GetProductVersion() {
const CefSettings& settings = _Context->settings();
if (settings.product_version)
return WideToUTF8(settings.product_version);
if (settings.product_version.length > 0) {
return CefString(&settings.product_version);
}
return "Chrome/7.0.517.0";
}

View File

@ -12,7 +12,6 @@
namespace WebKit {
class WebFrame;
class WebString;
class WebView;
}
@ -43,14 +42,6 @@ v8::Handle<v8::Context> GetV8Context(WebKit::WebFrame* frame);
// Clear all cached data.
void ClearCache();
WebKit::WebString StdStringToWebString(const std::string& str);
std::string WebStringToStdString(const WebKit::WebString& str);
WebKit::WebString StdWStringToWebString(const std::wstring& str);
std::wstring WebStringToStdWString(const WebKit::WebString& str);
// Returns true if the specified 'Content-Disposition' header value represents
// an attachment download. Also returns the file name.
bool IsContentDispositionAttachment(const std::string& cd_header,

View File

@ -21,7 +21,6 @@
#include "base/message_loop.h"
#include "base/process_util.h"
#include "base/string_util.h"
#include "base/utf_string_conversions.h"
#include "gfx/point.h"
#include "media/filters/audio_renderer_impl.h"
#include "net/base/net_errors.h"
@ -152,10 +151,10 @@ void TranslatePopupFeatures(const WebWindowFeatures& webKitFeatures,
if (webKitFeatures.additionalFeatures.size() > 0)
features.additionalFeatures = cef_string_list_alloc();
CefString str;
for(unsigned int i = 0; i < webKitFeatures.additionalFeatures.size(); ++i) {
cef_string_list_append(features.additionalFeatures,
webkit_glue::WebStringToStdWString(
webKitFeatures.additionalFeatures[i]).c_str());
str = string16(webKitFeatures.additionalFeatures[i]);
cef_string_list_append(features.additionalFeatures, str.GetStruct());
}
}
@ -191,21 +190,21 @@ WebStorageNamespace* BrowserWebViewDelegate::createSessionStorageNamespace(
void BrowserWebViewDelegate::didAddMessageToConsole(
const WebConsoleMessage& message, const WebString& source_name,
unsigned source_line) {
std::wstring wmessage = UTF16ToWideHack(message.text);
std::wstring wsource = UTF16ToWideHack(source_name);
std::string messageStr = message.text.utf8();
std::string sourceStr = source_name.utf8();
CefHandler::RetVal rv = RV_CONTINUE;
CefRefPtr<CefHandler> handler = browser_->GetHandler();
if(handler.get()) {
rv = handler->HandleConsoleMessage(browser_, wmessage, wsource,
source_line);
rv = handler->HandleConsoleMessage(browser_, messageStr, sourceStr,
source_line);
}
if(rv == RV_CONTINUE) {
logging::LogMessage("CONSOLE", 0).stream() << "\""
<< message.text.utf8().data()
<< messageStr
<< ",\" source: "
<< source_name.utf8().data()
<< sourceStr
<< "("
<< source_line
<< ")";
@ -357,8 +356,8 @@ bool BrowserWebViewDelegate::runFileChooser(
void BrowserWebViewDelegate::runModalAlertDialog(
WebFrame* frame, const WebString& message) {
std::wstring messageStr = UTF16ToWideHack(message);
CefHandler::RetVal rv = RV_CONTINUE;
CefString messageStr = string16(message);
CefRefPtr<CefHandler> handler = browser_->GetHandler();
if(handler.get()) {
rv = handler->HandleJSAlert(browser_, browser_->GetCefFrame(frame),
@ -370,8 +369,8 @@ void BrowserWebViewDelegate::runModalAlertDialog(
bool BrowserWebViewDelegate::runModalConfirmDialog(
WebFrame* frame, const WebString& message) {
std::wstring messageStr = UTF16ToWideHack(message);
CefHandler::RetVal rv = RV_CONTINUE;
CefString messageStr = string16(message);
bool retval = false;
CefRefPtr<CefHandler> handler = browser_->GetHandler();
if(handler.get()) {
@ -386,26 +385,26 @@ bool BrowserWebViewDelegate::runModalConfirmDialog(
bool BrowserWebViewDelegate::runModalPromptDialog(
WebFrame* frame, const WebString& message, const WebString& default_value,
WebString* actual_value) {
std::wstring wmessage = UTF16ToWideHack(message);
std::wstring wdefault = UTF16ToWideHack(default_value);
std::wstring wresult;
CefString messageStr = string16(message);
CefString defaultValueStr = string16(default_value);
CefString actualValueStr;
if(actual_value)
wresult = UTF16ToWideHack(*actual_value);
actualValueStr = string16(*actual_value);
CefHandler::RetVal rv = RV_CONTINUE;
bool retval = false;
CefRefPtr<CefHandler> handler = browser_->GetHandler();
if(handler.get()) {
rv = handler->HandleJSPrompt(browser_, browser_->GetCefFrame(frame),
wmessage, wdefault, retval, wresult);
messageStr, defaultValueStr, retval, actualValueStr);
}
if(rv != RV_HANDLED)
retval = ShowJavaScriptPrompt(frame, wmessage, wdefault, &wresult);
if(actual_value && !wresult.empty())
*actual_value = WideToUTF16Hack(wresult);
if(rv != RV_HANDLED) {
retval = ShowJavaScriptPrompt(frame, messageStr, defaultValueStr,
&actualValueStr);
}
if (actual_value)
*actual_value = string16(actualValueStr);
return retval;
}
@ -426,12 +425,11 @@ void BrowserWebViewDelegate::setKeyboardFocusURL(const WebKit::WebURL& url) {
void BrowserWebViewDelegate::setToolTipText(
const WebString& text, WebTextDirection hint)
{
std::wstring tooltipText(UTF8ToWide(webkit_glue::WebStringToStdString(text)));
CefString tooltipStr = string16(text);
CefRefPtr<CefHandler> handler = browser_->GetHandler();
if(handler.get() && handler->HandleTooltip(browser_, tooltipText)
if(handler.get() && handler->HandleTooltip(browser_, tooltipStr)
== RV_CONTINUE){
GetWidgetHost()->SetTooltipText(tooltipText);
GetWidgetHost()->SetTooltipText(tooltipStr);
}
}
@ -601,7 +599,7 @@ void BrowserWebViewDelegate::loadURLExternally(
WebFrame* frame, const WebURLRequest& request,
WebNavigationPolicy policy) {
DCHECK_NE(policy, WebKit::WebNavigationPolicyCurrentTab);
browser_->UIT_CreatePopupWindow(UTF8ToWide(request.url().spec().data()),
browser_->UIT_CreatePopupWindow(std::string(request.url().spec().data()),
CefPopupFeatures());
}
@ -618,9 +616,8 @@ WebNavigationPolicy BrowserWebViewDelegate::decidePolicyForNavigation(
if (!request_url.is_valid())
return WebKit::WebNavigationPolicyIgnore;
req->SetURL(UTF8ToWide(request_url.spec()));
req->SetMethod(
UTF8ToWide(webkit_glue::WebStringToStdString(request.httpMethod())));
req->SetURL(request_url.spec());
req->SetMethod(string16(request.httpMethod()));
const WebKit::WebHTTPBody& httpBody = request.httpBody();
if(!httpBody.isNull()) {
@ -717,13 +714,13 @@ void BrowserWebViewDelegate::didFailProvisionalLoad(
CefRefPtr<CefHandler> handler = browser_->GetHandler();
if(handler.get()) {
// give the handler an opportunity to generate a custom error message
std::wstring error_str;
CefString errorStr;
CefHandler::RetVal rv = handler->HandleLoadError(browser_,
browser_->GetCefFrame(frame),
static_cast<CefHandler::ErrorCode>(error.reason),
UTF8ToWide(failed_ds->request().url().spec().data()), error_str);
if(rv == RV_HANDLED && !error_str.empty())
error_text = WideToUTF8(error_str);
std::string(failed_ds->request().url().spec().data()), errorStr);
if(rv == RV_HANDLED && !errorStr.empty())
error_text = errorStr;
} else {
error_text = StringPrintf("Error %d when loading url %s",
error.reason, failed_ds->request().url().spec().data());
@ -767,13 +764,12 @@ void BrowserWebViewDelegate::didClearWindowObject(WebFrame* frame) {
void BrowserWebViewDelegate::didReceiveTitle(
WebFrame* frame, const WebString& title) {
std::wstring wtitle = UTF16ToWideHack(title);
browser_->UIT_SetTitle(wtitle);
CefString titleStr = string16(title);
browser_->UIT_SetTitle(titleStr);
CefRefPtr<CefHandler> handler = browser_->GetHandler();
if(handler.get()) {
// Notify the handler of a page title change
handler->HandleTitleChange(browser_, wtitle);
handler->HandleTitleChange(browser_, titleStr);
}
}
@ -971,7 +967,7 @@ void BrowserWebViewDelegate::UpdateURL(WebFrame* frame) {
entry->SetURL(request.url());
}
std::wstring url = UTF8ToWide(entry->GetURL().spec().c_str());
std::string url = std::string(entry->GetURL().spec().c_str());
CefRefPtr<CefHandler> handler = browser_->GetHandler();
if(handler.get()) {

View File

@ -251,13 +251,13 @@ class BrowserWebViewDelegate : public WebKit::WebViewClient,
// Default handling of JavaScript messages.
void ShowJavaScriptAlert(WebKit::WebFrame* webframe,
const std::wstring& message);
const CefString& message);
bool ShowJavaScriptConfirm(WebKit::WebFrame* webframe,
const std::wstring& message);
const CefString& message);
bool ShowJavaScriptPrompt(WebKit::WebFrame* webframe,
const std::wstring& message,
const std::wstring& default_value,
std::wstring* result);
const CefString& message,
const CefString& default_value,
CefString* result);
// Called to show the file chooser dialog.
bool ShowFileChooser(std::vector<FilePath>& file_names,

View File

@ -8,7 +8,6 @@
#import <Cocoa/Cocoa.h>
#include "base/sys_string_conversions.h"
#include "base/utf_string_conversions.h"
#include "third_party/WebKit/WebKit/chromium/public/WebCursorInfo.h"
#include "third_party/WebKit/WebKit/chromium/public/WebPopupMenu.h"
#include "third_party/WebKit/WebKit/chromium/public/WebView.h"
@ -198,7 +197,7 @@ void BrowserWebViewDelegate::DidMovePlugin(
void BrowserWebViewDelegate::ShowJavaScriptAlert(
WebKit::WebFrame* webframe, const std::wstring& message) {
NSString *text =
[NSString stringWithUTF8String:WideToUTF8(message).c_str()];
[NSString stringWithUTF8String:(std::string(message).c_str())];
NSAlert *alert = [NSAlert alertWithMessageText:@"JavaScript Alert"
defaultButton:@"OK"
alternateButton:nil
@ -234,7 +233,7 @@ bool BrowserWebViewDelegate::ShowFileChooser(std::vector<FilePath>& file_names,
/*
void BrowserWebViewDelegate::SetPageTitle(const std::wstring& title) {
[[browser_->GetWebViewHost()->view_handle() window]
setTitle:[NSString stringWithUTF8String:WideToUTF8(title).c_str()]];
setTitle:[NSString stringWithUTF8String:(std::string(title).c_str())]];
}
void BrowserWebViewDelegate::SetAddressBarURL(const GURL& url) {

View File

@ -20,7 +20,6 @@
#include "base/message_loop.h"
#include "base/string_util.h"
#include "base/utf_string_conversions.h"
#include "gfx/gdi_util.h"
#include "gfx/native_widget_types.h"
#include "gfx/point.h"
@ -205,7 +204,7 @@ static void AddMenuItem(CefRefPtr<CefBrowser> browser, HMENU menu, int index,
CefHandler::MenuId id, const wchar_t* label,
bool enabled, std::list<std::wstring>& label_list)
{
std::wstring actual_label = label;
CefString actual_label(label);
CefRefPtr<CefHandler> handler = browser->GetHandler();
if(handler.get()) {
// Let the handler change the label if desired
@ -284,28 +283,30 @@ void BrowserWebViewDelegate::showContextMenu(
if(handler.get()) {
// Gather menu information
CefHandler::MenuInfo menuInfo;
std::wstring linkStr, imageStr, pageStr, frameStr;
std::wstring selectedTextStr, misspelledWordStr, securityInfoStr;
linkStr = UTF16ToWideHack(data.linkURL.spec().utf16());
imageStr = UTF16ToWideHack(data.srcURL.spec().utf16());
pageStr = UTF16ToWideHack(data.pageURL.spec().utf16());
frameStr = UTF16ToWideHack(data.frameURL.spec().utf16());
selectedTextStr = UTF16ToWideHack(data.selectedText);
misspelledWordStr = UTF16ToWideHack(data.misspelledWord);
securityInfoStr = UTF16ToWideHack(data.securityInfo.utf16());
CefString linkStr(std::string(data.linkURL.spec()));
CefString imageStr(std::string(data.srcURL.spec()));
CefString pageStr(std::string(data.pageURL.spec()));
CefString frameStr(std::string(data.frameURL.spec()));
CefString selectedTextStr(string16(data.selectedText));
CefString misspelledWordStr(string16(data.misspelledWord));
CefString securityInfoStr(std::string(data.securityInfo));
menuInfo.typeFlags = type_flags;
menuInfo.x = screen_pt.x;
menuInfo.y = screen_pt.y;
menuInfo.linkUrl = linkStr.c_str();
menuInfo.imageUrl = imageStr.c_str();
menuInfo.pageUrl = pageStr.c_str();
menuInfo.frameUrl = frameStr.c_str();
menuInfo.selectionText = selectedTextStr.c_str();
menuInfo.misspelledWord = misspelledWordStr.c_str();
cef_string_set(linkStr.c_str(), linkStr.length(), &menuInfo.linkUrl, false);
cef_string_set(imageStr.c_str(), imageStr.length(), &menuInfo.imageUrl,
false);
cef_string_set(pageStr.c_str(), pageStr.length(), &menuInfo.pageUrl, false);
cef_string_set(frameStr.c_str(), frameStr.length(), &menuInfo.frameUrl,
false);
cef_string_set(selectedTextStr.c_str(), selectedTextStr.length(),
&menuInfo.selectionText, false);
cef_string_set(misspelledWordStr.c_str(), misspelledWordStr.length(),
&menuInfo.misspelledWord, false);
menuInfo.editFlags = edit_flags;
menuInfo.securityInfo = securityInfoStr.c_str();
cef_string_set(securityInfoStr.c_str(), securityInfoStr.length(),
&menuInfo.securityInfo, false);
// Notify the handler that a context menu is requested
CefHandler::RetVal rv = handler->HandleBeforeMenu(browser_, menuInfo);
@ -383,27 +384,30 @@ end:
// Private methods ------------------------------------------------------------
void BrowserWebViewDelegate::ShowJavaScriptAlert(WebFrame* webframe,
const std::wstring& message)
const CefString& message)
{
// TODO(cef): Think about what we should be showing as the prompt caption
MessageBox(browser_->GetMainWndHandle(), message.c_str(),
browser_->UIT_GetTitle().c_str(), MB_OK | MB_ICONWARNING);
std::wstring messageStr = message;
std::wstring titleStr = browser_->UIT_GetTitle();
MessageBox(browser_->GetMainWndHandle(), messageStr.c_str(), titleStr.c_str(),
MB_OK | MB_ICONWARNING);
}
bool BrowserWebViewDelegate::ShowJavaScriptConfirm(WebFrame* webframe,
const std::wstring& message)
const CefString& message)
{
// TODO(cef): Think about what we should be showing as the prompt caption
int rv = MessageBox(browser_->GetMainWndHandle(), message.c_str(),
browser_->UIT_GetTitle().c_str(),
MB_YESNO | MB_ICONQUESTION);
std::wstring messageStr = message;
std::wstring titleStr = browser_->UIT_GetTitle();
int rv = MessageBox(browser_->GetMainWndHandle(), messageStr.c_str(),
titleStr.c_str(), MB_YESNO | MB_ICONQUESTION);
return (rv == IDYES);
}
bool BrowserWebViewDelegate::ShowJavaScriptPrompt(WebFrame* webframe,
const std::wstring& message,
const std::wstring& default_value,
std::wstring* result)
const CefString& message,
const CefString& default_value,
CefString* result)
{
// TODO(cef): Implement a default prompt dialog
return false;
@ -414,10 +418,7 @@ namespace
// from chrome/browser/views/shell_dialogs_win.cc
bool RunOpenFileDialog(
const std::wstring& filter,
HWND owner,
FilePath* path)
bool RunOpenFileDialog(const std::wstring& filter, HWND owner, FilePath* path)
{
OPENFILENAME ofn;
@ -446,10 +447,8 @@ bool RunOpenFileDialog(
return success;
}
bool RunOpenMultiFileDialog(
const std::wstring& filter,
HWND owner,
std::vector<FilePath>* paths)
bool RunOpenMultiFileDialog(const std::wstring& filter, HWND owner,
std::vector<FilePath>* paths)
{
OPENFILENAME ofn;
@ -509,12 +508,10 @@ bool BrowserWebViewDelegate::ShowFileChooser(std::vector<FilePath>& file_names,
{
bool result = false;
if (multi_select)
{
result = RunOpenMultiFileDialog(L"", browser_->GetMainWndHandle(), &file_names);
}
else
{
if (multi_select) {
result = RunOpenMultiFileDialog(L"", browser_->GetMainWndHandle(),
&file_names);
} else {
FilePath file_name;
result = RunOpenFileDialog(L"", browser_->GetMainWndHandle(), &file_name);
if (result)

View File

@ -11,7 +11,6 @@
#include "webwidget_host.h"
#include "base/scoped_ptr.h"
#include "base/utf_string_conversions.h"
#include "gfx/rect.h"
#include "third_party/WebKit/WebKit/chromium/public/WebFrame.h"
#include "third_party/WebKit/WebKit/chromium/public/WebView.h"

View File

@ -13,7 +13,6 @@
#if defined(OS_MACOSX) || defined(OS_WIN)
#include "base/nss_util.h"
#endif
#include "base/utf_string_conversions.h"
#include "webkit/glue/plugins/plugin_list.h"
// Global CefContext pointer
@ -193,14 +192,7 @@ bool CefContext::Initialize(const CefSettings& settings,
settings_ = settings;
browser_defaults_ = browser_defaults;
std::wstring cachePathStr;
if(settings.cache_path)
cachePathStr = settings.cache_path;
#if defined(OS_WIN)
cache_path_ = FilePath(cachePathStr);
#else
cache_path_ = FilePath(WideToUTF8(cachePathStr));
#endif
cache_path_ = FilePath(CefString(&settings.cache_path));
#if defined(OS_MACOSX) || defined(OS_WIN)
// We want to be sure to init NSPR on the main thread.

View File

@ -11,7 +11,6 @@
#include "browser_socket_stream_bridge.h"
#include "browser_webblobregistry_impl.h"
#include "base/utf_string_conversions.h"
#include "build/build_config.h"
#if defined(OS_WIN)

View File

@ -125,20 +125,17 @@ void CefProcessUIThread::Init() {
const CefSettings& settings = _Context->settings();
if (settings.user_agent)
webkit_glue::SetUserAgent(WideToUTF8(settings.user_agent));
if (settings.user_agent.length > 0)
webkit_glue::SetUserAgent(CefString(&settings.user_agent));
if (settings.extra_plugin_paths) {
cef_string_t str;
FilePath path;
int size = cef_string_list_size(settings.extra_plugin_paths);
for(int i = 0; i < size; ++i) {
str = cef_string_list_value(settings.extra_plugin_paths, i);
#if defined(OS_WIN)
path = FilePath(str);
#else
path = FilePath(WideToUTF8(str));
#endif
if (!cef_string_list_value(settings.extra_plugin_paths, i, &str))
continue;
path = FilePath(CefString(&str));
NPAPI::PluginList::Singleton()->AddExtraPluginPath(path);
}
}

View File

@ -1,169 +0,0 @@
// Copyright (c) 2009 The Chromium Embedded Framework Authors. All rights
// reserved. Use of this source code is governed by a BSD-style license that
// can be found in the LICENSE file.
#include "include/cef_string.h"
#include "build/build_config.h"
#include <limits.h>
#if defined(OS_MACOSX)
#include <stdlib.h>
#else
#include <malloc.h>
#endif
#include <string.h>
typedef unsigned long dword_t;
CEF_EXPORT size_t cef_string_length(cef_string_t str)
{
dword_t* ptr;
if(!str)
return 0;
// The string length, in bytes, is placed in a dword_t immediately proceeding
// the string value.
ptr = (dword_t*)str;
ptr--;
return (size_t)(*ptr / sizeof(wchar_t));
}
CEF_EXPORT cef_string_t cef_string_alloc(const wchar_t* str)
{
if(!str)
return NULL;
return cef_string_alloc_length(str, wcslen(str));
}
CEF_EXPORT cef_string_t cef_string_alloc_length(const wchar_t* str,
size_t len)
{
dword_t size, *ptr;
wchar_t* newstr;
// Check that the size can fit in a dword_t.
if(len >= (UINT_MAX - sizeof(wchar_t) - sizeof(dword_t)) / sizeof(wchar_t))
return NULL;
// Get the size of the string in bytes.
size = sizeof(wchar_t) * len;
// Allocate the new buffer including space for the proceeding dword_t size
// value and the terminating nul.
ptr = (dword_t*)malloc(sizeof(dword_t) + size + sizeof(wchar_t));
if(!ptr)
return NULL;
// Set the size as the first value in the newly allocated memory and
// increment to the string location.
*ptr = size;
ptr++;
if(str != NULL)
{
// Copy the string to the buffer.
memcpy(ptr, str, size);
}
else
{
// Initialize the string to zeros.
memset(ptr, 0, size);
}
newstr = (wchar_t*)ptr;
// Nul-terminate the string.
newstr[len] = '\0';
return (cef_string_t)newstr;
}
CEF_EXPORT int cef_string_realloc(cef_string_t* oldstr, const wchar_t* newstr)
{
if(!oldstr)
return 0;
// Free the old string.
cef_string_free(*oldstr);
// Copy the new string.
*oldstr = cef_string_alloc(newstr);
return 1;
}
CEF_EXPORT int cef_string_realloc_length(cef_string_t* oldstr,
const wchar_t* newstr,
size_t len)
{
if(!oldstr)
return 0;
// Check that the size can fit in a dword_t.
if(len >= (UINT_MAX - sizeof(wchar_t) - sizeof(dword_t)) / sizeof(wchar_t))
return 0;
if(*oldstr)
{
dword_t newsize, *oldptr, *newptr;
// Get the new size of the string in bytes.
newsize = sizeof(wchar_t) * len;
// Adjust the pointer to account for the dword_t immediately proceeding the
// string value.
oldptr = (dword_t*)*oldstr;
oldptr--;
// Re-allocate the buffer including space for the proceeding dword_t size
// value and the terminating nul.
newptr = (dword_t*)realloc(
oldptr, sizeof(dword_t) + newsize + sizeof(wchar_t));
if(!newptr)
return 0;
// Set the size as the first value in the newly allocated memory and
// increment to the string location.
*newptr = newsize;
newptr++;
// Set the string pointer to the beginning on the string in the newly
// allocated memory.
*oldstr = (cef_string_t)newptr;
if(newstr)
{
// Copy the new string value. Use of memmove() ensures that any
// overlapping region in the old string will be copied before being
// overwritten.
memmove(*oldstr, newstr, newsize);
// Nul-terminate the string.
*oldstr[len] = '\0';
}
}
else
{
// Allocate the string.
*oldstr = cef_string_alloc_length(newstr, len);
}
return 1;
}
CEF_EXPORT void cef_string_free(cef_string_t str)
{
dword_t* ptr;
if(!str)
return;
// The size is placed in a dword_t immediately proceeding the string value.
ptr = (dword_t*)str;
ptr--;
free(ptr);
}

View File

@ -7,7 +7,7 @@
#include <vector>
typedef std::vector<std::wstring> StringList;
typedef std::vector<CefString> StringList;
CEF_EXPORT cef_string_list_t cef_string_list_alloc()
{
@ -21,24 +21,26 @@ CEF_EXPORT int cef_string_list_size(cef_string_list_t list)
return impl->size();
}
CEF_EXPORT cef_string_t cef_string_list_value(cef_string_list_t list, int index)
CEF_EXPORT int cef_string_list_value(cef_string_list_t list, int index,
cef_string_t* value)
{
DCHECK(list);
DCHECK(value);
StringList* impl = (StringList*)list;
DCHECK(index >= 0 && index < (int)impl->size());
if(index < 0 || index >= (int)impl->size())
return NULL;
return cef_string_alloc((*impl)[index].c_str());
return false;
const CefString& str = (*impl)[index];
return cef_string_copy(str.c_str(), str.length(), value);
}
CEF_EXPORT void cef_string_list_append(cef_string_list_t list, const wchar_t* value)
CEF_EXPORT void cef_string_list_append(cef_string_list_t list,
const cef_string_t* value)
{
DCHECK(list);
DCHECK(value);
StringList* impl = (StringList*)list;
std::wstring valstr;
if(value)
valstr = value;
impl->push_back(valstr);
impl->push_back(CefString(value));
}
CEF_EXPORT void cef_string_list_clear(cef_string_list_t list)

View File

@ -7,7 +7,7 @@
#include <map>
typedef std::map<std::wstring, std::wstring> StringMap;
typedef std::map<CefString, CefString> StringMap;
CEF_EXPORT cef_string_map_t cef_string_map_alloc()
{
@ -21,23 +21,25 @@ CEF_EXPORT int cef_string_map_size(cef_string_map_t map)
return impl->size();
}
CEF_EXPORT cef_string_t cef_string_map_find(cef_string_map_t map,
const wchar_t* key)
CEF_EXPORT int cef_string_map_find(cef_string_map_t map,
const cef_string_t* key,
cef_string_t* value)
{
DCHECK(map);
DCHECK(value);
StringMap* impl = (StringMap*)map;
std::wstring keystr;
if(key)
keystr = key;
StringMap::const_iterator it = impl->find(keystr);
StringMap::const_iterator it = impl->find(CefString(key));
if(it == impl->end())
return NULL;
return cef_string_alloc(it->second.c_str());
const CefString& val = it->second;
return cef_string_set(val.c_str(), val.length(), value, true);
}
CEF_EXPORT cef_string_t cef_string_map_key(cef_string_map_t map, int index)
CEF_EXPORT int cef_string_map_key(cef_string_map_t map, int index,
cef_string_t* key)
{
DCHECK(map);
DCHECK(key);
StringMap* impl = (StringMap*)map;
DCHECK(index >= 0 && index < (int)impl->size());
if(index < 0 || index >= (int)impl->size())
@ -45,37 +47,38 @@ CEF_EXPORT cef_string_t cef_string_map_key(cef_string_map_t map, int index)
StringMap::const_iterator it = impl->begin();
for(int ct = 0; it != impl->end(); ++it, ct++) {
if(ct == index)
return cef_string_alloc(it->first.c_str());
return cef_string_set(it->first.c_str(), it->first.length(), key, true);
}
return NULL;
return 0;
}
CEF_EXPORT cef_string_t cef_string_map_value(cef_string_map_t map, int index)
CEF_EXPORT int cef_string_map_value(cef_string_map_t map, int index,
cef_string_t* value)
{
DCHECK(map);
DCHECK(value);
StringMap* impl = (StringMap*)map;
DCHECK(index >= 0 && index < (int)impl->size());
if(index < 0 || index >= (int)impl->size())
return NULL;
StringMap::const_iterator it = impl->begin();
for(int ct = 0; it != impl->end(); ++it, ct++) {
if(ct == index)
return cef_string_alloc(it->second.c_str());
if(ct == index) {
return cef_string_set(it->second.c_str(), it->second.length(), value,
true);
}
}
return NULL;
return 0;
}
CEF_EXPORT void cef_string_map_append(cef_string_map_t map, const wchar_t* key,
const wchar_t* value)
CEF_EXPORT int cef_string_map_append(cef_string_map_t map,
const cef_string_t* key,
const cef_string_t* value)
{
DCHECK(map);
StringMap* impl = (StringMap*)map;
std::wstring keystr, valstr;
if(key)
keystr = key;
if(value)
valstr = value;
impl->insert(std::pair<std::wstring, std::wstring>(keystr, valstr));
impl->insert(std::make_pair(CefString(key), CefString(value)));
return 1;
}
CEF_EXPORT void cef_string_map_clear(cef_string_map_t map)

294
libcef/cef_string_types.cc Normal file
View File

@ -0,0 +1,294 @@
// Copyright (c) 2010 The Chromium Embedded Framework Authors. All rights
// reserved. Use of this source code is governed by a BSD-style license that
// can be found in the LICENSE file.
#include "include/cef_string_types.h"
#include "base/logging.h"
#include "base/string16.h"
#include "base/utf_string_conversions.h"
namespace {
void string_wide_dtor(wchar_t* str)
{
delete [] str;
}
void string_utf8_dtor(char* str)
{
delete [] str;
}
void string_utf16_dtor(char16_t* str)
{
delete [] str;
}
} // namespace
CEF_EXPORT int cef_string_wide_set(const wchar_t* src, size_t src_len,
cef_string_wide_t* output, int copy)
{
cef_string_wide_clear(output);
if (copy) {
if (src && src_len > 0) {
output->str = new wchar_t[src_len+1];
if (!output->str)
return 0;
memcpy(output->str, src, src_len * sizeof(wchar_t));
output->str[src_len] = 0;
output->length = src_len;
output->dtor = string_wide_dtor;
}
} else {
output->str = const_cast<wchar_t*>(src);
output->length = src_len;
output->dtor = NULL;
}
return 1;
}
CEF_EXPORT int cef_string_utf8_set(const char* src, size_t src_len,
cef_string_utf8_t* output, int copy)
{
cef_string_utf8_clear(output);
if (copy) {
if (src && src_len > 0) {
output->str = new char[src_len+1];
if (!output->str)
return 0;
memcpy(output->str, src, src_len * sizeof(char));
output->str[src_len] = 0;
output->length = src_len;
output->dtor = string_utf8_dtor;
}
} else {
output->str = const_cast<char*>(src);
output->length = src_len;
output->dtor = NULL;
}
return 1;
}
CEF_EXPORT int cef_string_utf16_set(const char16_t* src, size_t src_len,
cef_string_utf16_t* output, int copy)
{
cef_string_utf16_clear(output);
if (copy) {
if (src && src_len > 0) {
output->str = new char16_t[src_len+1];
if (!output->str)
return 0;
memcpy(output->str, src, src_len * sizeof(char16_t));
output->str[src_len] = 0;
output->length = src_len;
output->dtor = string_utf16_dtor;
}
} else {
output->str = const_cast<char16_t*>(src);
output->length = src_len;
output->dtor = NULL;
}
return 1;
}
CEF_EXPORT void cef_string_wide_clear(cef_string_wide_t* str)
{
DCHECK(str != NULL);
if (str->dtor && str->str)
str->dtor(str->str);
str->str = NULL;
str->length = 0;
str->dtor = NULL;
}
CEF_EXPORT void cef_string_utf8_clear(cef_string_utf8_t* str)
{
DCHECK(str != NULL);
if (str->dtor && str->str)
str->dtor(str->str);
str->str = NULL;
str->length = 0;
str->dtor = NULL;
}
CEF_EXPORT void cef_string_utf16_clear(cef_string_utf16_t* str)
{
DCHECK(str != NULL);
if (str->dtor && str->str)
str->dtor(str->str);
str->str = NULL;
str->length = 0;
str->dtor = NULL;
}
CEF_EXPORT int cef_string_wide_cmp(const cef_string_wide_t* str1,
const cef_string_wide_t* str2)
{
if (str1->length == 0 && str2->length == 0)
return 0;
int r = wcsncmp(str1->str, str2->str, std::min(str1->length, str2->length));
if (r == 0) {
if (str1->length > str2->length)
return 1;
else if (str1->length < str2->length)
return -1;
}
return r;
}
CEF_EXPORT int cef_string_utf8_cmp(const cef_string_utf8_t* str1,
const cef_string_utf8_t* str2)
{
if (str1->length == 0 && str2->length == 0)
return 0;
int r = strncmp(str1->str, str2->str, std::min(str1->length, str2->length));
if (r == 0) {
if (str1->length > str2->length)
return 1;
else if (str1->length < str2->length)
return -1;
}
return r;
}
CEF_EXPORT int cef_string_utf16_cmp(const cef_string_utf16_t* str1,
const cef_string_utf16_t* str2)
{
if (str1->length == 0 && str2->length == 0)
return 0;
#if defined(WCHAR_T_IS_UTF32)
int r = c16memcmp(str1->str, str2->str, std::min(str1->length, str2->length));
#else
int r = wcsncmp(str1->str, str2->str, std::min(str1->length, str2->length));
#endif
if (r == 0) {
if (str1->length > str2->length)
return 1;
else if (str1->length < str2->length)
return -1;
}
return r;
}
CEF_EXPORT int cef_string_wide_to_utf8(const wchar_t* src, size_t src_len,
cef_string_utf8_t* output)
{
std::string str;
bool ret = WideToUTF8(src, src_len, &str);
if (!cef_string_utf8_set(str.c_str(), str.length(), output, true))
return false;
return ret;
}
CEF_EXPORT int cef_string_utf8_to_wide(const char* src, size_t src_len,
cef_string_wide_t* output)
{
std::wstring str;
bool ret = UTF8ToWide(src, src_len, &str);
if (!cef_string_wide_set(str.c_str(), str.length(), output, true))
return false;
return ret;
}
CEF_EXPORT int cef_string_wide_to_utf16(const wchar_t* src, size_t src_len,
cef_string_utf16_t* output)
{
string16 str;
bool ret = WideToUTF16(src, src_len, &str);
if (!cef_string_utf16_set(str.c_str(), str.length(), output, true))
return false;
return ret;
}
CEF_EXPORT int cef_string_utf16_to_wide(const char16_t* src, size_t src_len,
cef_string_wide_t* output)
{
std::wstring str;
bool ret = UTF16ToWide(src, src_len, &str);
if (!cef_string_wide_set(str.c_str(), str.length(), output, true))
return false;
return ret;
}
CEF_EXPORT int cef_string_utf8_to_utf16(const char* src, size_t src_len,
cef_string_utf16_t* output)
{
string16 str;
bool ret = UTF8ToUTF16(src, src_len, &str);
if (!cef_string_utf16_set(str.c_str(), str.length(), output, true))
return false;
return ret;
}
CEF_EXPORT int cef_string_utf16_to_utf8(const char16_t* src, size_t src_len,
cef_string_utf8_t* output)
{
std::string str;
bool ret = UTF16ToUTF8(src, src_len, &str);
if (!cef_string_utf8_set(str.c_str(), str.length(), output, true))
return false;
return ret;
}
CEF_EXPORT int cef_string_ascii_to_wide(const char* src, size_t src_len,
cef_string_wide_t* output)
{
std::wstring str = ASCIIToWide(std::string(src, src_len));
return cef_string_wide_set(str.c_str(), str.length(), output, true);
}
CEF_EXPORT int cef_string_ascii_to_utf16(const char* src, size_t src_len,
cef_string_utf16_t* output)
{
string16 str = ASCIIToUTF16(std::string(src, src_len));
return cef_string_utf16_set(str.c_str(), str.length(), output, true);
}
CEF_EXPORT cef_string_userfree_wide_t cef_string_userfree_wide_alloc()
{
cef_string_wide_t* s = new cef_string_wide_t;
memset(s, 0, sizeof(cef_string_wide_t));
return s;
}
CEF_EXPORT cef_string_userfree_utf8_t cef_string_userfree_utf8_alloc()
{
cef_string_utf8_t* s = new cef_string_utf8_t;
memset(s, 0, sizeof(cef_string_utf8_t));
return s;
}
CEF_EXPORT cef_string_userfree_utf16_t cef_string_userfree_utf16_alloc()
{
cef_string_utf16_t* s = new cef_string_utf16_t;
memset(s, 0, sizeof(cef_string_utf16_t));
return s;
}
CEF_EXPORT void cef_string_userfree_wide_free(cef_string_userfree_wide_t str)
{
cef_string_wide_clear(str);
delete str;
}
CEF_EXPORT void cef_string_userfree_utf8_free(cef_string_userfree_utf8_t str)
{
cef_string_utf8_clear(str);
delete str;
}
CEF_EXPORT void cef_string_userfree_utf16_free(cef_string_userfree_utf16_t str)
{
cef_string_utf16_clear(str);
delete str;
}

View File

@ -75,11 +75,11 @@ void PrintSettings::ResetRequestedPageMargins() {
void PrintSettings::Init(HDC hdc,
const DEVMODE& dev_mode,
const PageRanges& new_ranges,
const std::wstring& new_device_name,
const CefString& new_device_name,
bool print_selection_only,
bool print_to_file) {
DCHECK(hdc);
printer_name_ = dev_mode.dmDeviceName;
printer_name_ = std::wstring(dev_mode.dmDeviceName);
device_name_ = new_device_name;
ranges = new_ranges;
landscape = dev_mode.dmOrientation == DMORIENT_LANDSCAPE;

View File

@ -84,7 +84,7 @@ class PrintSettings {
void Init(HDC hdc,
const DEVMODE& dev_mode,
const PageRanges& new_ranges,
const std::wstring& new_device_name,
const CefString& new_device_name,
bool selection_only,
bool to_file);
#endif
@ -102,11 +102,11 @@ class PrintSettings {
// output.
bool Equals(const PrintSettings& rhs) const;
const std::wstring& printer_name() const { return printer_name_; }
void set_device_name(const std::wstring& device_name) {
const CefString& printer_name() const { return printer_name_; }
void set_device_name(const CefString& device_name) {
device_name_ = device_name;
}
const std::wstring& device_name() const { return device_name_; }
const CefString& device_name() const { return device_name_; }
int dpi() const { return dpi_; }
const PageSetup& page_setup_pixels() const { return page_setup_pixels_; }
@ -160,10 +160,10 @@ class PrintSettings {
// Settings that can't be changed without side-effects.
// Printer name as shown to the user.
std::wstring printer_name_;
CefString printer_name_;
// Printer device name as opened by the OS.
std::wstring device_name_;
CefString device_name_;
// Page setup in pixel units, dpi adjusted.
PageSetup page_setup_pixels_;

View File

@ -176,7 +176,7 @@ PrintingContext::Result PrintingContext::Init() {
TCHAR printername[512];
DWORD size = sizeof(printername)-1;
if(GetDefaultPrinter(printername, &size)) {
return Init(std::wstring(printername), false);
return Init(CefString(printername), false);
}
return FAILED;
}
@ -186,13 +186,14 @@ PrintingContext::Result PrintingContext::InitWithSettings(
DCHECK(!in_print_job_);
settings_ = settings;
return Init(settings_.device_name().c_str(), true);
return Init(settings_.device_name(), true);
}
PrintingContext::Result PrintingContext::Init(const std::wstring& device_name,
PrintingContext::Result PrintingContext::Init(const CefString& device_name,
bool adjust_dev_mode) {
HANDLE printer;
if (!OpenPrinter(const_cast<wchar_t*>(device_name.c_str()),
std::wstring deviceNameStr = device_name;
if (!OpenPrinter(const_cast<wchar_t*>(deviceNameStr.c_str()),
&printer,
NULL))
return FAILED;
@ -224,7 +225,7 @@ void PrintingContext::ResetSettings() {
}
PrintingContext::Result PrintingContext::NewDocument(
const std::wstring& document_name) {
const CefString& document_name) {
DCHECK(!in_print_job_);
if (!hdc_)
return OnError();
@ -239,7 +240,8 @@ PrintingContext::Result PrintingContext::NewDocument(
return OnError();
DOCINFO di = { sizeof(DOCINFO) };
di.lpszDocName = document_name.c_str();
std::wstring documentNameStr = document_name;
di.lpszDocName = documentNameStr.c_str();
wchar_t szFileName[MAX_PATH] = L"";
if (settings_.to_file) {
@ -343,7 +345,7 @@ BOOL PrintingContext::AbortProc(HDC hdc, int nCode) {
}
bool PrintingContext::InitializeSettings(const DEVMODE& dev_mode,
const std::wstring& new_device_name,
const CefString& new_device_name,
const PRINTPAGERANGE* ranges,
int number_ranges,
bool selection_only,
@ -389,7 +391,7 @@ bool PrintingContext::InitializeSettings(const DEVMODE& dev_mode,
}
bool PrintingContext::GetPrinterSettings(HANDLE printer,
const std::wstring& device_name,
const CefString& device_name,
bool adjust_dev_mode) {
DCHECK(!in_print_job_);
scoped_array<uint8> buffer;
@ -451,9 +453,10 @@ bool PrintingContext::GetPrinterSettings(HANDLE printer,
return false;
}
bool PrintingContext::AllocateContext(const std::wstring& printer_name,
bool PrintingContext::AllocateContext(const CefString& printer_name,
const DEVMODE* dev_mode) {
hdc_ = CreateDC(L"WINSPOOL", printer_name.c_str(), NULL, dev_mode);
std::wstring printerNameStr = printer_name;
hdc_ = CreateDC(L"WINSPOOL", printerNameStr.c_str(), NULL, dev_mode);
DCHECK(hdc_);
return hdc_ != NULL;
}

View File

@ -53,7 +53,7 @@ class PrintingContext {
// like IPC message processing! Some printers have side-effects on this call
// like virtual printers that ask the user for the path of the saved document;
// for example a PDF printer.
Result NewDocument(const std::wstring& document_name);
Result NewDocument(const CefString& document_name);
// Starts a new page.
Result NewPage();
@ -94,7 +94,7 @@ class PrintingContext {
// Reads the settings from the selected device context. Updates settings_ and
// its margins.
bool InitializeSettings(const DEVMODE& dev_mode,
const std::wstring& new_device_name,
const CefString& new_device_name,
const PRINTPAGERANGE* ranges,
int number_ranges,
bool selection_only,
@ -103,18 +103,18 @@ class PrintingContext {
// Retrieves the printer's default low-level settings. hdc_ is allocated with
// this call.
bool GetPrinterSettings(HANDLE printer,
const std::wstring& device_name,
const CefString& device_name,
bool adjust_dev_mode);
// Allocates the HDC for a specific DEVMODE.
bool AllocateContext(const std::wstring& printer_name,
bool AllocateContext(const CefString& printer_name,
const DEVMODE* dev_mode);
// Updates printer dev_mode with settings_
void PrintingContext::AdjustDevMode(DEVMODE& dev_mode);
// Initializes the hdc_ either with setting_ or with just printer defaults.
Result Init(const std::wstring& device_name, bool adjust_dev_mode);
Result Init(const CefString& device_name, bool adjust_dev_mode);
// Parses the result of a PRINTDLGEX result.
Result ParseDialogResultEx(const PRINTDLGEX& dialog_options);

View File

@ -6,7 +6,6 @@
#include "browser_webkit_glue.h"
#include "base/logging.h"
#include "base/utf_string_conversions.h"
#include "net/http/http_response_headers.h"
#include "net/http/http_util.h"
#include "net/url_request/url_request.h"
@ -25,30 +24,30 @@ CefRequestImpl::CefRequestImpl()
{
}
std::wstring CefRequestImpl::GetURL()
CefString CefRequestImpl::GetURL()
{
Lock();
std::wstring url = url_;
CefString url = url_;
Unlock();
return url;
}
void CefRequestImpl::SetURL(const std::wstring& url)
void CefRequestImpl::SetURL(const CefString& url)
{
Lock();
url_ = url;
Unlock();
}
std::wstring CefRequestImpl::GetMethod()
CefString CefRequestImpl::GetMethod()
{
Lock();
std::wstring method = method_;
CefString method = method_;
Unlock();
return method;
}
void CefRequestImpl::SetMethod(const std::wstring& method)
void CefRequestImpl::SetMethod(const CefString& method)
{
Lock();
method_ = method;
@ -84,8 +83,8 @@ void CefRequestImpl::SetHeaderMap(const HeaderMap& headerMap)
Unlock();
}
void CefRequestImpl::Set(const std::wstring& url,
const std::wstring& method,
void CefRequestImpl::Set(const CefString& url,
const CefString& method,
CefRefPtr<CefPostData> postData,
const HeaderMap& headerMap)
{
@ -99,14 +98,13 @@ void CefRequestImpl::Set(const std::wstring& url,
void CefRequestImpl::Set(URLRequest* request)
{
SetURL(UTF8ToWide(request->url().spec()));
SetMethod(UTF8ToWide(request->method()));
SetURL(request->url().spec());
SetMethod(request->method());
// Transfer request headers
HeaderMap headerMap;
GetHeaderMap(request->extra_request_headers(), headerMap);
headerMap.insert(
std::make_pair(L"Referrer", UTF8ToWide(request->referrer())));
headerMap.insert(std::make_pair(L"Referrer", request->referrer()));
SetHeaderMap(headerMap);
// Transfer post data, if any
@ -123,7 +121,7 @@ void CefRequestImpl::GetHeaderMap(const net::HttpRequestHeaders& headers, Header
{
net::HttpRequestHeaders::Iterator it(headers);
do {
map[UTF8ToWide(it.name())] = UTF8ToWide(it.value());
map[it.name()] = it.value();
} while (it.GetNext());
}
@ -136,10 +134,7 @@ void CefRequestImpl::GetHeaderMap(const WebKit::WebURLRequest& request,
virtual void visitHeader(const WebKit::WebString& name,
const WebKit::WebString& value) {
map_->insert(
std::make_pair(
UTF8ToWide(webkit_glue::WebStringToStdString(name)),
UTF8ToWide(webkit_glue::WebStringToStdString(value))));
map_->insert(std::make_pair(string16(name), string16(value)));
}
private:
@ -154,11 +149,8 @@ void CefRequestImpl::SetHeaderMap(const HeaderMap& map,
WebKit::WebURLRequest& request)
{
HeaderMap::const_iterator it = map.begin();
for(; it != map.end(); ++it) {
request.setHTTPHeaderField(
webkit_glue::StdWStringToWebString(it->first.c_str()),
webkit_glue::StdWStringToWebString(it->second.c_str()));
}
for(; it != map.end(); ++it)
request.setHTTPHeaderField(string16(it->first), string16(it->second));
}
std::string CefRequestImpl::GenerateHeaders(const HeaderMap& map)
@ -168,15 +160,15 @@ std::string CefRequestImpl::GenerateHeaders(const HeaderMap& map)
for(HeaderMap::const_iterator header = map.begin();
header != map.end();
++header) {
const std::wstring& key = header->first;
const std::wstring& value = header->second;
const CefString& key = header->first;
const CefString& value = header->second;
if(!key.empty()) {
// Delimit with "\r\n".
if(!headers.empty())
headers += "\r\n";
headers += WideToUTF8(key) + ": " + WideToUTF8(value);
headers += std::string(key) + ": " + std::string(value);
}
}
@ -194,7 +186,7 @@ void CefRequestImpl::ParseHeaders(const std::string& header_str, HeaderMap& map)
void* iter = NULL;
std::string name, value;
while(headers->EnumerateHeaderLines(&iter, &name, &value))
map.insert(std::make_pair(UTF8ToWide(name), UTF8ToWide(value)));
map.insert(std::make_pair(name, value));
}
CefRefPtr<CefPostData> CefPostData::CreatePostData()
@ -351,6 +343,7 @@ CefRefPtr<CefPostDataElement> CefPostDataElement::CreatePostDataElement()
CefPostDataElementImpl::CefPostDataElementImpl()
{
type_ = PDE_TYPE_EMPTY;
memset(&data_, 0, sizeof(data_));
}
CefPostDataElementImpl::~CefPostDataElementImpl()
@ -364,31 +357,21 @@ void CefPostDataElementImpl::SetToEmpty()
if(type_ == PDE_TYPE_BYTES)
free(data_.bytes.bytes);
else if(type_ == PDE_TYPE_FILE)
free(data_.filename);
cef_string_clear(&data_.filename);
type_ = PDE_TYPE_EMPTY;
memset(&data_, 0, sizeof(data_));
Unlock();
}
void CefPostDataElementImpl::SetToFile(const std::wstring& fileName)
void CefPostDataElementImpl::SetToFile(const CefString& fileName)
{
Lock();
// Clear any data currently in the element
SetToEmpty();
// Assign the new file name
size_t size = fileName.size();
wchar_t* data = static_cast<wchar_t*>(malloc((size + 1) * sizeof(wchar_t)));
DCHECK(data != NULL);
if(data == NULL)
return;
memcpy(static_cast<void*>(data), static_cast<const void*>(fileName.c_str()),
size * sizeof(wchar_t));
data[size] = 0;
// Assign the new data
type_ = PDE_TYPE_FILE;
data_.filename = data;
cef_string_copy(fileName.c_str(), fileName.length(), &data_.filename);
Unlock();
}
@ -420,13 +403,13 @@ CefPostDataElement::Type CefPostDataElementImpl::GetType()
return type;
}
std::wstring CefPostDataElementImpl::GetFile()
CefString CefPostDataElementImpl::GetFile()
{
Lock();
DCHECK(type_ == PDE_TYPE_FILE);
std::wstring filename;
CefString filename;
if(type_ == PDE_TYPE_FILE)
filename = data_.filename;
filename.FromString(data_.filename.str, data_.filename.length, false);
Unlock();
return filename;
}
@ -484,11 +467,8 @@ void CefPostDataElementImpl::Get(net::UploadData::Element& element)
if(type_ == PDE_TYPE_BYTES) {
element.SetToBytes(static_cast<char*>(data_.bytes.bytes), data_.bytes.size);
} else if(type_ == PDE_TYPE_FILE) {
#if defined(OS_WIN)
element.SetToFilePath(FilePath(data_.filename));
#else
element.SetToFilePath(FilePath(WideToUTF8(data_.filename)));
#endif
FilePath path = FilePath(CefString(&data_.filename));
element.SetToFilePath(path);
} else {
NOTREACHED();
}
@ -504,7 +484,7 @@ void CefPostDataElementImpl::Set(const WebKit::WebHTTPBody::Element& element)
SetToBytes(element.data.size(),
static_cast<const void*>(element.data.data()));
} else if(element.type == WebKit::WebHTTPBody::Element::TypeFile) {
SetToFile(UTF8ToWide(webkit_glue::WebStringToStdString(element.filePath)));
SetToFile(string16(element.filePath));
} else {
NOTREACHED();
}
@ -522,7 +502,7 @@ void CefPostDataElementImpl::Get(WebKit::WebHTTPBody::Element& element)
static_cast<char*>(data_.bytes.bytes), data_.bytes.size);
} else if(type_ == PDE_TYPE_FILE) {
element.type = WebKit::WebHTTPBody::Element::TypeFile;
element.filePath.assign(webkit_glue::StdWStringToWebString(data_.filename));
element.filePath.assign(string16(CefString(&data_.filename)));
} else {
NOTREACHED();
}

View File

@ -20,16 +20,16 @@ public:
CefRequestImpl();
~CefRequestImpl() {}
virtual std::wstring GetURL();
virtual void SetURL(const std::wstring& url);
virtual std::wstring GetMethod();
virtual void SetMethod(const std::wstring& method);
virtual CefString GetURL();
virtual void SetURL(const CefString& url);
virtual CefString GetMethod();
virtual void SetMethod(const CefString& method);
virtual CefRefPtr<CefPostData> GetPostData();
virtual void SetPostData(CefRefPtr<CefPostData> postData);
virtual void GetHeaderMap(HeaderMap& headerMap);
virtual void SetHeaderMap(const HeaderMap& headerMap);
virtual void Set(const std::wstring& url,
const std::wstring& method,
virtual void Set(const CefString& url,
const CefString& method,
CefRefPtr<CefPostData> postData,
const HeaderMap& headerMap);
@ -46,8 +46,8 @@ public:
static void ParseHeaders(const std::string& header_str, HeaderMap& map);
protected:
std::wstring url_;
std::wstring method_;
CefString url_;
CefString method_;
CefRefPtr<CefPostData> postdata_;
HeaderMap headermap_;
};
@ -82,10 +82,10 @@ public:
~CefPostDataElementImpl();
virtual void SetToEmpty();
virtual void SetToFile(const std::wstring& fileName);
virtual void SetToFile(const CefString& fileName);
virtual void SetToBytes(size_t size, const void* bytes);
virtual Type GetType();
virtual std::wstring GetFile();
virtual CefString GetFile();
virtual size_t GetBytesCount();
virtual size_t GetBytes(size_t size, void* bytes);
@ -103,7 +103,7 @@ protected:
void* bytes;
size_t size;
} bytes;
wchar_t* filename;
cef_string_t filename;
} data_;
};

View File

@ -6,7 +6,6 @@
#include "base/lazy_instance.h"
#include "base/logging.h"
#include "base/message_loop.h"
#include "base/utf_string_conversions.h"
#include "googleurl/src/url_util.h"
#include "net/base/completion_callback.h"
#include "net/base/io_buffer.h"
@ -187,13 +186,13 @@ private:
static_cast<CefRequestImpl*>(req.get())->Set(owner_->request());
owner_->handler_->Cancel();
std::wstring mime_type;
CefString mime_type;
int response_length = 0;
// handler should complete content generation in ProcessRequest
bool res = owner_->handler_->ProcessRequest(req, mime_type,
&response_length);
if (res) {
owner_->mime_type_ = WideToUTF8(mime_type);
owner_->mime_type_ = mime_type;
owner_->response_length_ = response_length;
}
//////////////////////////////////////////////////////////////////////////
@ -390,8 +389,8 @@ private:
std::string host_name_;
};
bool CefRegisterScheme(const std::wstring& scheme_name,
const std::wstring& host_name,
bool CefRegisterScheme(const CefString& scheme_name,
const CefString& host_name,
CefRefPtr<CefSchemeHandlerFactory> factory)
{
// Verify that the context is already initialized
@ -403,8 +402,7 @@ bool CefRegisterScheme(const std::wstring& scheme_name,
// will call AddRef() and Release() on the object in debug mode, resulting in
// the object being deleted if it doesn't already have a reference.
CefRefPtr<SchemeRequestJobWrapper> wrapper(
new SchemeRequestJobWrapper(WideToUTF8(scheme_name),
WideToUTF8(host_name), factory));
new SchemeRequestJobWrapper(scheme_name, host_name, factory));
CefThread::PostTask(CefThread::UI, FROM_HERE, NewRunnableMethod(wrapper.get(),
&SchemeRequestJobWrapper::RegisterScheme));

View File

@ -3,24 +3,18 @@
// can be found in the LICENSE file.
#include "stream_impl.h"
#include "base/logging.h"
#include "base/utf_string_conversions.h"
// Static functions
CefRefPtr<CefStreamReader> CefStreamReader::CreateForFile(
const std::wstring& fileName)
const CefString& fileName)
{
CefRefPtr<CefStreamReader> reader;
#if defined(OS_WIN)
FILE *f = _wfopen(fileName.c_str(), L"rb");
#else
FILE *f = fopen(WideToUTF8(fileName).c_str(), "rb");
#endif
if(f)
reader = new CefFileReader(f, true);
std::string fileNameStr = fileName;
FILE *file = fopen(fileNameStr.c_str(), "rb");
if(file)
reader = new CefFileReader(file, true);
return reader;
}
@ -46,15 +40,12 @@ CefRefPtr<CefStreamReader> CefStreamReader::CreateForHandler(
}
CefRefPtr<CefStreamWriter> CefStreamWriter::CreateForFile(
const std::wstring& fileName)
const CefString& fileName)
{
DCHECK(!fileName.empty());
CefRefPtr<CefStreamWriter> writer;
#if defined(OS_WIN)
FILE* file = _wfopen(fileName.c_str(), L"wb");
#else
FILE* file = fopen(WideToUTF8(fileName).c_str(), "wb");
#endif
std::string fileNameStr = fileName;
FILE *file = fopen(fileNameStr.c_str(), "wb");
if(file)
writer = new CefFileWriter(file, true);
return writer;

View File

@ -6,7 +6,6 @@
#include "cef_context.h"
#include "tracker.h"
#include "base/lazy_instance.h"
#include "base/utf_string_conversions.h"
#include "third_party/WebKit/WebKit/chromium/public/WebKit.h"
#include "third_party/WebKit/WebKit/chromium/public/WebScriptController.h"
@ -56,26 +55,24 @@ static void TrackDestructor(v8::Persistent<v8::Value> object,
// Convert a wide string to a V8 string.
static v8::Handle<v8::String> GetV8String(const std::wstring& str)
static v8::Handle<v8::String> GetV8String(const CefString& str)
{
std::string tmpStr = WideToUTF8(str);
std::string tmpStr = str;
return v8::String::New(tmpStr.c_str(), tmpStr.length());
}
// Convert a V8 string to a wide string.
static std::wstring GetWString(v8::Handle<v8::String> str)
// Convert a V8 string to a UTF8 string.
static std::string GetString(v8::Handle<v8::String> str)
{
// Allocate enough space for a worst-case conversion.
size_t len = str->Length()*4;
char* buf = new char[len];
int newlen = str->WriteUtf8(buf, len);
std::wstring value;
UTF8ToWide(buf, newlen, &value);
int len = str->Utf8Length();
char* buf = new char[len+1];
str->WriteUtf8(buf, len+1);
std::string ret(buf, len);
delete [] buf;
return value;
return ret;
}
// V8 function callback
static v8::Handle<v8::Value> FunctionCallbackImpl(const v8::Arguments& args)
{
@ -87,11 +84,11 @@ static v8::Handle<v8::Value> FunctionCallbackImpl(const v8::Arguments& args)
for(int i = 0; i < args.Length(); i++)
params.push_back(new CefV8ValueImpl(args[i]));
std::wstring func_name =
GetWString(v8::Handle<v8::String>::Cast(args.Callee()->GetName()));
CefString func_name =
GetString(v8::Handle<v8::String>::Cast(args.Callee()->GetName()));
CefRefPtr<CefV8Value> object = new CefV8ValueImpl(args.This());
CefRefPtr<CefV8Value> retval;
std::wstring exception;
CefString exception;
v8::Handle<v8::Value> value = v8::Null();
if(handler->Execute(func_name, object, params, retval, exception)) {
@ -142,8 +139,8 @@ private:
CefV8Handler* handler_;
};
bool CefRegisterExtension(const std::wstring& extension_name,
const std::wstring& javascript_code,
bool CefRegisterExtension(const CefString& extension_name,
const CefString& javascript_code,
CefRefPtr<CefV8Handler> handler)
{
// Verify that the context is already initialized
@ -153,9 +150,9 @@ bool CefRegisterExtension(const std::wstring& extension_name,
if(!handler.get())
return false;
TrackString* name = new TrackString(WideToUTF8(extension_name));
TrackString* name = new TrackString(extension_name);
TrackAdd(name);
TrackString* code = new TrackString(WideToUTF8(javascript_code));
TrackString* code = new TrackString(javascript_code);
TrackAdd(name);
ExtensionWrapper* wrapper = new ExtensionWrapper(name->GetString(),
@ -205,7 +202,7 @@ CefRefPtr<CefV8Value> CefV8Value::CreateDouble(double value)
}
// static
CefRefPtr<CefV8Value> CefV8Value::CreateString(const std::wstring& value)
CefRefPtr<CefV8Value> CefV8Value::CreateString(const CefString& value)
{
v8::HandleScope handle_scope;
return new CefV8ValueImpl(GetV8String(value));
@ -244,7 +241,7 @@ CefRefPtr<CefV8Value> CefV8Value::CreateArray()
}
// static
CefRefPtr<CefV8Value> CefV8Value::CreateFunction(const std::wstring& name,
CefRefPtr<CefV8Value> CefV8Value::CreateFunction(const CefString& name,
CefRefPtr<CefV8Handler> handler)
{
v8::HandleScope handle_scope;
@ -324,9 +321,10 @@ v8::Handle<v8::Value> CefV8ValueImpl::GetValue()
return rv;
}
bool CefV8ValueImpl::IsReservedKey(const std::wstring& key)
bool CefV8ValueImpl::IsReservedKey(const CefString& key)
{
return (key.find(L"Cef::") == 0 || key.find(L"v8::") == 0);
std::string str = key;
return (str.find("Cef::") == 0 || str.find("v8::") == 0);
}
bool CefV8ValueImpl::IsUndefined()
@ -441,17 +439,17 @@ double CefV8ValueImpl::GetDoubleValue()
return rv;
}
std::wstring CefV8ValueImpl::GetStringValue()
CefString CefV8ValueImpl::GetStringValue()
{
std::wstring rv;
CefString rv;
Lock();
v8::HandleScope handle_scope;
rv = GetWString(v8_value_->ToString());
rv = GetString(v8_value_->ToString());
Unlock();
return rv;
}
bool CefV8ValueImpl::HasValue(const std::wstring& key)
bool CefV8ValueImpl::HasValue(const CefString& key)
{
if(IsReservedKey(key))
return false;
@ -480,7 +478,7 @@ bool CefV8ValueImpl::HasValue(int index)
return rv;
}
bool CefV8ValueImpl::DeleteValue(const std::wstring& key)
bool CefV8ValueImpl::DeleteValue(const CefString& key)
{
if(IsReservedKey(key))
return false;
@ -509,7 +507,7 @@ bool CefV8ValueImpl::DeleteValue(int index)
return rv;
}
CefRefPtr<CefV8Value> CefV8ValueImpl::GetValue(const std::wstring& key)
CefRefPtr<CefV8Value> CefV8ValueImpl::GetValue(const CefString& key)
{
if(IsReservedKey(key))
return false;
@ -538,7 +536,7 @@ CefRefPtr<CefV8Value> CefV8ValueImpl::GetValue(int index)
return rv;
}
bool CefV8ValueImpl::SetValue(const std::wstring& key,
bool CefV8ValueImpl::SetValue(const CefString& key,
CefRefPtr<CefV8Value> value)
{
if(IsReservedKey(key))
@ -574,7 +572,7 @@ bool CefV8ValueImpl::SetValue(int index, CefRefPtr<CefV8Value> value)
return rv;
}
bool CefV8ValueImpl::GetKeys(std::vector<std::wstring>& keys)
bool CefV8ValueImpl::GetKeys(std::vector<CefString>& keys)
{
bool rv = false;
Lock();
@ -585,7 +583,7 @@ bool CefV8ValueImpl::GetKeys(std::vector<std::wstring>& keys)
uint32_t len = arr_keys->Length();
for(uint32_t i = 0; i < len; ++i) {
v8::Local<v8::Value> value = arr_keys->Get(v8::Integer::New(i));
std::wstring str = GetWString(value->ToString());
CefString str = GetString(value->ToString());
if(!IsReservedKey(str))
keys.push_back(str);
}
@ -624,15 +622,15 @@ int CefV8ValueImpl::GetArrayLength()
return rv;
}
std::wstring CefV8ValueImpl::GetFunctionName()
CefString CefV8ValueImpl::GetFunctionName()
{
std::wstring rv;
CefString rv;
Lock();
if(v8_value_->IsFunction()) {
v8::HandleScope handle_scope;
v8::Local<v8::Object> obj = v8_value_->ToObject();
v8::Local<v8::Function> func = v8::Local<v8::Function>::Cast(obj);
rv = GetWString(v8::Handle<v8::String>::Cast(func->GetName()));
rv = GetString(v8::Handle<v8::String>::Cast(func->GetName()));
}
Unlock();
return rv;
@ -656,7 +654,7 @@ CefRefPtr<CefV8Handler> CefV8ValueImpl::GetFunctionHandler()
bool CefV8ValueImpl::ExecuteFunction(CefRefPtr<CefV8Value> object,
const CefV8ValueList& arguments,
CefRefPtr<CefV8Value>& retval,
std::wstring& exception)
CefString& exception)
{
bool rv = false;
Lock();
@ -682,7 +680,7 @@ bool CefV8ValueImpl::ExecuteFunction(CefRefPtr<CefV8Value> object,
v8::TryCatch try_catch;
v8::Local<v8::Value> func_rv = func->Call(recv, argc, argv);
if (try_catch.HasCaught())
exception = GetWString(try_catch.Message()->Get());
exception = GetString(try_catch.Message()->Get());
else
retval = new CefV8ValueImpl(func_rv);

View File

@ -20,7 +20,7 @@ public:
bool Attach(v8::Handle<v8::Value> value, CefTrackObject* tracker = NULL);
void Detach();
v8::Handle<v8::Value> GetValue();
bool IsReservedKey(const std::wstring& key);
bool IsReservedKey(const CefString& key);
virtual bool IsUndefined();
virtual bool IsNull();
@ -34,24 +34,24 @@ public:
virtual bool GetBoolValue();
virtual int GetIntValue();
virtual double GetDoubleValue();
virtual std::wstring GetStringValue();
virtual bool HasValue(const std::wstring& key);
virtual CefString GetStringValue();
virtual bool HasValue(const CefString& key);
virtual bool HasValue(int index);
virtual bool DeleteValue(const std::wstring& key);
virtual bool DeleteValue(const CefString& key);
virtual bool DeleteValue(int index);
virtual CefRefPtr<CefV8Value> GetValue(const std::wstring& key);
virtual CefRefPtr<CefV8Value> GetValue(const CefString& key);
virtual CefRefPtr<CefV8Value> GetValue(int index);
virtual bool SetValue(const std::wstring& key, CefRefPtr<CefV8Value> value);
virtual bool SetValue(const CefString& key, CefRefPtr<CefV8Value> value);
virtual bool SetValue(int index, CefRefPtr<CefV8Value> value);
virtual bool GetKeys(std::vector<std::wstring>& keys);
virtual bool GetKeys(std::vector<CefString>& keys);
virtual CefRefPtr<CefBase> GetUserData();
virtual int GetArrayLength();
virtual std::wstring GetFunctionName();
virtual CefString GetFunctionName();
virtual CefRefPtr<CefV8Handler> GetFunctionHandler();
virtual bool ExecuteFunction(CefRefPtr<CefV8Value> object,
const CefV8ValueList& arguments,
CefRefPtr<CefV8Value>& retval,
std::wstring& exception);
CefString& exception);
protected:
v8::Persistent<v8::Value> v8_value_;

View File

@ -5,13 +5,13 @@
#ifndef _WEBWIDGET_HOST_H
#define _WEBWIDGET_HOST_H
#include "include/cef_string.h"
#include "base/basictypes.h"
#include "base/scoped_ptr.h"
#include "gfx/native_widget_types.h"
#include "gfx/rect.h"
#include "skia/ext/platform_canvas.h"
#include "third_party/WebKit/WebKit/chromium/public/WebInputEvent.h"
#include <string>
namespace gfx {
class Rect;
@ -70,7 +70,7 @@ class WebWidgetHost {
void PaintRect(const gfx::Rect& rect);
void SetTooltipText(const std::wstring& tooltip_text);
void SetTooltipText(const CefString& tooltip_text);
protected:
WebWidgetHost();
@ -144,6 +144,7 @@ class WebWidgetHost {
#if defined(OS_WIN)
bool track_mouse_leave_;
std::wstring tooltip_text_;
#endif
#if defined(TOOLKIT_USES_GTK)
@ -154,7 +155,6 @@ class WebWidgetHost {
WebKit::WebKeyboardEvent last_key_event_;
gfx::NativeView tooltip_view_;
std::wstring tooltip_text_;
bool tooltip_showing_;
#ifndef NDEBUG

View File

@ -214,7 +214,7 @@ void WebWidgetHost::Paint() {
}
}
void WebWidgetHost::SetTooltipText(const std::wstring& tooltip_text) {
void WebWidgetHost::SetTooltipText(const std::string& tooltip_text) {
// TODO(port): Implement this method.
}

View File

@ -372,7 +372,8 @@ void WebWidgetHost::OnNotify(WPARAM wparam, NMHDR* header) {
}
}
void WebWidgetHost::SetTooltipText(const std::wstring& new_tooltip_text) {
void WebWidgetHost::SetTooltipText(const CefString& tooltip_text) {
std::wstring new_tooltip_text(tooltip_text);
if (new_tooltip_text != tooltip_text_) {
tooltip_text_ = new_tooltip_text;

View File

@ -4,14 +4,13 @@
#include "xml_reader_impl.h"
#include "base/logging.h"
#include "base/utf_string_conversions.h"
// Static functions
//static
CefRefPtr<CefXmlReader> CefXmlReader::Create(CefRefPtr<CefStreamReader> stream,
EncodingType encodingType,
const std::wstring& URI)
const CefString& URI)
{
CefRefPtr<CefXmlReaderImpl> impl(new CefXmlReaderImpl());
if (!impl->Initialize(stream, encodingType, URI))
@ -55,14 +54,12 @@ void XMLCALL xml_error_callback(void *arg, const char *msg,
if (!msg)
return;
std::wstring error_str;
UTF8ToWide(msg, strlen(msg), &error_str);
std::string error_str(msg);
if (!error_str.empty() && error_str[error_str.length()-1] == '\n')
error_str.resize(error_str.length()-1);
std::wstringstream ss;
ss << error_str << L", line " << xmlTextReaderLocatorLineNumber(locator);
std::stringstream ss;
ss << error_str << ", line " << xmlTextReaderLocatorLineNumber(locator);
LOG(INFO) << ss.str();
@ -83,14 +80,12 @@ void XMLCALL xml_structured_error_callback(void *userData, xmlErrorPtr error)
if (!error->message)
return;
std::wstring error_str;
UTF8ToWide(error->message, strlen(error->message), &error_str);
std::string error_str(error->message);
if (!error_str.empty() && error_str[error_str.length()-1] == '\n')
error_str.resize(error_str.length()-1);
std::wstringstream ss;
ss << error_str << L", line " << error->line;
std::stringstream ss;
ss << error_str << ", line " << error->line;
LOG(INFO) << ss.str();
@ -98,14 +93,13 @@ void XMLCALL xml_structured_error_callback(void *userData, xmlErrorPtr error)
impl->AppendError(ss.str());
}
std::wstring xmlCharToWString(const xmlChar* xmlStr, bool free)
CefString xmlCharToString(const xmlChar* xmlStr, bool free)
{
if (!xmlStr)
return std::wstring();
return CefString();
const char* str = reinterpret_cast<const char*>(xmlStr);
std::wstring wstr;
UTF8ToWide(str, strlen(str), &wstr);
CefString wstr = std::string(str);
if (free)
xmlFree(const_cast<xmlChar*>(xmlStr));
@ -135,7 +129,7 @@ CefXmlReaderImpl::~CefXmlReaderImpl()
bool CefXmlReaderImpl::Initialize(CefRefPtr<CefStreamReader> stream,
EncodingType encodingType,
const std::wstring& URI)
const CefString& URI)
{
xmlCharEncoding enc = XML_CHAR_ENCODING_NONE;
switch (encodingType) {
@ -164,7 +158,8 @@ bool CefXmlReaderImpl::Initialize(CefRefPtr<CefStreamReader> stream,
input_buffer->readcallback = xml_read_callback;
// Create the text reader.
reader_ = xmlNewTextReader(input_buffer, WideToUTF8(URI).c_str());
std::string uriStr = URI;
reader_ = xmlNewTextReader(input_buffer, uriStr.c_str());
if (!reader_) {
// Free the input buffer.
xmlFreeParserInputBuffer(input_buffer);
@ -209,10 +204,10 @@ bool CefXmlReaderImpl::HasError()
return !error_buf_.str().empty();
}
std::wstring CefXmlReaderImpl::GetError()
CefString CefXmlReaderImpl::GetError()
{
if (!VerifyContext())
return std::wstring();
return CefString();
return error_buf_.str();
}
@ -259,52 +254,52 @@ int CefXmlReaderImpl::GetDepth()
return xmlTextReaderDepth(reader_);
}
std::wstring CefXmlReaderImpl::GetLocalName()
CefString CefXmlReaderImpl::GetLocalName()
{
if (!VerifyContext())
return std::wstring();
return CefString();
return xmlCharToWString(xmlTextReaderConstLocalName(reader_), false);
return xmlCharToString(xmlTextReaderConstLocalName(reader_), false);
}
std::wstring CefXmlReaderImpl::GetPrefix()
CefString CefXmlReaderImpl::GetPrefix()
{
if (!VerifyContext())
return std::wstring();
return CefString();
return xmlCharToWString(xmlTextReaderConstPrefix(reader_), false);
return xmlCharToString(xmlTextReaderConstPrefix(reader_), false);
}
std::wstring CefXmlReaderImpl::GetQualifiedName()
CefString CefXmlReaderImpl::GetQualifiedName()
{
if (!VerifyContext())
return std::wstring();
return CefString();
return xmlCharToWString(xmlTextReaderConstName(reader_), false);
return xmlCharToString(xmlTextReaderConstName(reader_), false);
}
std::wstring CefXmlReaderImpl::GetNamespaceURI()
CefString CefXmlReaderImpl::GetNamespaceURI()
{
if (!VerifyContext())
return std::wstring();
return CefString();
return xmlCharToWString(xmlTextReaderConstNamespaceUri(reader_), false);
return xmlCharToString(xmlTextReaderConstNamespaceUri(reader_), false);
}
std::wstring CefXmlReaderImpl::GetBaseURI()
CefString CefXmlReaderImpl::GetBaseURI()
{
if (!VerifyContext())
return std::wstring();
return CefString();
return xmlCharToWString(xmlTextReaderConstBaseUri(reader_), false);
return xmlCharToString(xmlTextReaderConstBaseUri(reader_), false);
}
std::wstring CefXmlReaderImpl::GetXmlLang()
CefString CefXmlReaderImpl::GetXmlLang()
{
if (!VerifyContext())
return std::wstring();
return CefString();
return xmlCharToWString(xmlTextReaderConstXmlLang(reader_), false);
return xmlCharToString(xmlTextReaderConstXmlLang(reader_), false);
}
bool CefXmlReaderImpl::IsEmptyElement()
@ -328,19 +323,19 @@ bool CefXmlReaderImpl::HasValue()
}
}
std::wstring CefXmlReaderImpl::GetValue()
CefString CefXmlReaderImpl::GetValue()
{
if (!VerifyContext())
return std::wstring();
return CefString();
if (xmlTextReaderNodeType(reader_) == XML_READER_TYPE_ENTITY_REFERENCE) {
// Provide special handling to return entity reference values.
xmlNodePtr node = xmlTextReaderCurrentNode(reader_);
if (node->content != NULL)
return xmlCharToWString(node->content, false);
return NULL;
return xmlCharToString(node->content, false);
return CefString();
} else {
return xmlCharToWString(xmlTextReaderConstValue(reader_), false);
return xmlCharToString(xmlTextReaderConstValue(reader_), false);
}
}
@ -360,50 +355,50 @@ size_t CefXmlReaderImpl::GetAttributeCount()
return xmlTextReaderAttributeCount(reader_);
}
std::wstring CefXmlReaderImpl::GetAttribute(int index)
CefString CefXmlReaderImpl::GetAttribute(int index)
{
if (!VerifyContext())
return std::wstring();
return CefString();
return xmlCharToWString(xmlTextReaderGetAttributeNo(reader_, index), true);
return xmlCharToString(xmlTextReaderGetAttributeNo(reader_, index), true);
}
std::wstring CefXmlReaderImpl::GetAttribute(const std::wstring& qualifiedName)
CefString CefXmlReaderImpl::GetAttribute(const CefString& qualifiedName)
{
if (!VerifyContext())
return std::wstring();
return CefString();
std::string qualifiedNameStr = WideToUTF8(qualifiedName);
return xmlCharToWString(xmlTextReaderGetAttribute(reader_,
std::string qualifiedNameStr = qualifiedName;
return xmlCharToString(xmlTextReaderGetAttribute(reader_,
BAD_CAST qualifiedNameStr.c_str()), true);
}
std::wstring CefXmlReaderImpl::GetAttribute(const std::wstring& localName,
const std::wstring& namespaceURI)
CefString CefXmlReaderImpl::GetAttribute(const CefString& localName,
const CefString& namespaceURI)
{
if (!VerifyContext())
return std::wstring();
return CefString();
std::string localNameStr = WideToUTF8(localName);
std::string namespaceURIStr = WideToUTF8(namespaceURI);
return xmlCharToWString(xmlTextReaderGetAttributeNs(reader_,
std::string localNameStr = localName;
std::string namespaceURIStr = namespaceURI;
return xmlCharToString(xmlTextReaderGetAttributeNs(reader_,
BAD_CAST localNameStr.c_str(), BAD_CAST namespaceURIStr.c_str()), true);
}
std::wstring CefXmlReaderImpl::GetInnerXml()
CefString CefXmlReaderImpl::GetInnerXml()
{
if (!VerifyContext())
return std::wstring();
return CefString();
return xmlCharToWString(xmlTextReaderReadInnerXml(reader_), true);
return xmlCharToString(xmlTextReaderReadInnerXml(reader_), true);
}
std::wstring CefXmlReaderImpl::GetOuterXml()
CefString CefXmlReaderImpl::GetOuterXml()
{
if (!VerifyContext())
return std::wstring();
return CefString();
return xmlCharToWString(xmlTextReaderReadOuterXml(reader_), true);
return xmlCharToString(xmlTextReaderReadOuterXml(reader_), true);
}
int CefXmlReaderImpl::GetLineNumber()
@ -422,24 +417,24 @@ bool CefXmlReaderImpl::MoveToAttribute(int index)
return xmlTextReaderMoveToAttributeNo(reader_, index) == 1 ? true : false;
}
bool CefXmlReaderImpl::MoveToAttribute(const std::wstring& qualifiedName)
bool CefXmlReaderImpl::MoveToAttribute(const CefString& qualifiedName)
{
if (!VerifyContext())
return false;
std::string qualifiedNameStr = WideToUTF8(qualifiedName);
std::string qualifiedNameStr = qualifiedName;
return xmlTextReaderMoveToAttribute(reader_,
BAD_CAST qualifiedNameStr.c_str()) == 1 ? true : false;
}
bool CefXmlReaderImpl::MoveToAttribute(const std::wstring& localName,
const std::wstring& namespaceURI)
bool CefXmlReaderImpl::MoveToAttribute(const CefString& localName,
const CefString& namespaceURI)
{
if (!VerifyContext())
return false;
std::string localNameStr = WideToUTF8(localName);
std::string namespaceURIStr = WideToUTF8(namespaceURI);
std::string localNameStr = localName;
std::string namespaceURIStr = namespaceURI;
return xmlTextReaderMoveToAttributeNs(reader_,
BAD_CAST localNameStr.c_str(), BAD_CAST namespaceURIStr.c_str()) == 1 ?
true : false;
@ -469,7 +464,7 @@ bool CefXmlReaderImpl::MoveToCarryingElement()
return xmlTextReaderMoveToElement(reader_) == 1 ? true : false;
}
void CefXmlReaderImpl::AppendError(const std::wstring& error_str)
void CefXmlReaderImpl::AppendError(const CefString& error_str)
{
if (!error_buf_.str().empty())
error_buf_ << L"\n";

View File

@ -19,42 +19,42 @@ public:
// Initialize the reader context.
bool Initialize(CefRefPtr<CefStreamReader> stream,
EncodingType encodingType, const std::wstring& URI);
EncodingType encodingType, const CefString& URI);
virtual bool MoveToNextNode();
virtual bool Close();
virtual bool HasError();
virtual std::wstring GetError();
virtual CefString GetError();
virtual NodeType GetType();
virtual int GetDepth();
virtual std::wstring GetLocalName();
virtual std::wstring GetPrefix();
virtual std::wstring GetQualifiedName();
virtual std::wstring GetNamespaceURI();
virtual std::wstring GetBaseURI();
virtual std::wstring GetXmlLang();
virtual CefString GetLocalName();
virtual CefString GetPrefix();
virtual CefString GetQualifiedName();
virtual CefString GetNamespaceURI();
virtual CefString GetBaseURI();
virtual CefString GetXmlLang();
virtual bool IsEmptyElement();
virtual bool HasValue();
virtual std::wstring GetValue();
virtual CefString GetValue();
virtual bool HasAttributes();
virtual size_t GetAttributeCount();
virtual std::wstring GetAttribute(int index);
virtual std::wstring GetAttribute(const std::wstring& qualifiedName);
virtual std::wstring GetAttribute(const std::wstring& localName,
const std::wstring& namespaceURI);
virtual std::wstring GetInnerXml();
virtual std::wstring GetOuterXml();
virtual CefString GetAttribute(int index);
virtual CefString GetAttribute(const CefString& qualifiedName);
virtual CefString GetAttribute(const CefString& localName,
const CefString& namespaceURI);
virtual CefString GetInnerXml();
virtual CefString GetOuterXml();
virtual int GetLineNumber();
virtual bool MoveToAttribute(int index);
virtual bool MoveToAttribute(const std::wstring& qualifiedName);
virtual bool MoveToAttribute(const std::wstring& localName,
const std::wstring& namespaceURI);
virtual bool MoveToAttribute(const CefString& qualifiedName);
virtual bool MoveToAttribute(const CefString& localName,
const CefString& namespaceURI);
virtual bool MoveToFirstAttribute();
virtual bool MoveToNextAttribute();
virtual bool MoveToCarryingElement();
// Add another line to the error string.
void AppendError(const std::wstring& error_str);
void AppendError(const CefString& error_str);
// Verify that the reader exists and is being accessed from the correct
// thread.
@ -64,7 +64,7 @@ protected:
PlatformThreadId supported_thread_id_;
CefRefPtr<CefStreamReader> stream_;
xmlTextReaderPtr reader_;
std::wstringstream error_buf_;
std::stringstream error_buf_;
};
#endif // _XML_READER_IMPL_H

View File

@ -4,7 +4,6 @@
#include "zip_reader_impl.h"
#include "base/logging.h"
#include "base/utf_string_conversions.h"
#include <time.h>
// Static functions
@ -146,7 +145,7 @@ bool CefZipReaderImpl::MoveToNextFile()
return (unzGoToNextFile(reader_) == UNZ_OK);
}
bool CefZipReaderImpl::MoveToFile(const std::wstring& fileName, bool caseSensitive)
bool CefZipReaderImpl::MoveToFile(const CefString& fileName, bool caseSensitive)
{
if (!VerifyContext())
return false;
@ -156,7 +155,7 @@ bool CefZipReaderImpl::MoveToFile(const std::wstring& fileName, bool caseSensiti
has_fileinfo_ = false;
std::string fileNameStr = WideToUTF8(fileName);
std::string fileNameStr = fileName;
return (unzLocateFile(reader_, fileNameStr.c_str(),
(caseSensitive ? 1 : 2)) == UNZ_OK);
}
@ -174,10 +173,10 @@ bool CefZipReaderImpl::Close()
return (result == UNZ_OK);
}
std::wstring CefZipReaderImpl::GetFileName()
CefString CefZipReaderImpl::GetFileName()
{
if (!VerifyContext() || !GetFileInfo())
return std::wstring();
return CefString();
return filename_;
}
@ -198,7 +197,7 @@ time_t CefZipReaderImpl::GetFileLastModified()
return filemodified_;
}
bool CefZipReaderImpl::OpenFile(const std::wstring& password)
bool CefZipReaderImpl::OpenFile(const CefString& password)
{
if (!VerifyContext())
return false;
@ -211,7 +210,7 @@ bool CefZipReaderImpl::OpenFile(const std::wstring& password)
if (password.empty()) {
ret = (unzOpenCurrentFile(reader_) == UNZ_OK);
} else {
std::string passwordStr = WideToUTF8(password);
std::string passwordStr = password;
ret = (unzOpenCurrentFilePassword(reader_, passwordStr.c_str()) == UNZ_OK);
}
@ -270,7 +269,7 @@ bool CefZipReaderImpl::GetFileInfo()
}
has_fileinfo_ = true;
UTF8ToWide(file_name, strlen(file_name), &filename_);
filename_ = std::string(file_name);
filesize_ = file_info.uncompressed_size;
struct tm time;

View File

@ -22,12 +22,12 @@ public:
virtual bool MoveToFirstFile();
virtual bool MoveToNextFile();
virtual bool MoveToFile(const std::wstring& fileName, bool caseSensitive);
virtual bool MoveToFile(const CefString& fileName, bool caseSensitive);
virtual bool Close();
virtual std::wstring GetFileName();
virtual CefString GetFileName();
virtual long GetFileSize();
virtual time_t GetFileLastModified();
virtual bool OpenFile(const std::wstring& password);
virtual bool OpenFile(const CefString& password);
virtual bool CloseFile();
virtual int ReadFile(void* buffer, size_t bufferSize);
virtual long Tell();
@ -44,7 +44,7 @@ protected:
unzFile reader_;
bool has_fileopen_;
bool has_fileinfo_;
std::wstring filename_;
CefString filename_;
long filesize_;
time_t filemodified_;
};