From 383168173ad8d786c1b695d97c521ac1c0d7ab9e Mon Sep 17 00:00:00 2001 From: Marshall Greenblatt Date: Sun, 10 Oct 2010 00:16:24 +0000 Subject: [PATCH] Fix various Mac compile errors. git-svn-id: https://chromiumembedded.googlecode.com/svn/trunk@115 5089003a-bbd8-11dd-ad1f-f1f9622dbc98 --- libcef/browser_impl.cc | 58 ++++++++++++++---------- libcef/browser_navigation_controller.cc | 4 +- libcef/browser_resource_loader_bridge.cc | 8 ++-- libcef/browser_webkit_glue.cc | 8 ++++ libcef/browser_webkit_glue.h | 4 ++ libcef/browser_webview_delegate.cc | 4 +- libcef/cef_context.cc | 5 ++ libcef/cef_process.cc | 4 ++ libcef/cef_process_io_thread.cc | 9 +++- libcef/cef_string.c | 6 +++ libcef/request_impl.cc | 15 ++++-- libcef/scheme_impl.cc | 6 +-- libcef/stream_impl.cc | 13 +++++- libcef_dll/cpptoc/cpptoc.h | 20 ++++---- 14 files changed, 108 insertions(+), 56 deletions(-) diff --git a/libcef/browser_impl.cc b/libcef/browser_impl.cc index 04f0f7546..bf4ce3181 100644 --- a/libcef/browser_impl.cc +++ b/libcef/browser_impl.cc @@ -41,14 +41,16 @@ 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(CefWindowInfo& windowInfo, bool popup, CefRefPtr handler) : window_info_(windowInfo), is_popup_(popup), is_modal_(false), - handler_(handler), webviewhost_(NULL), popuphost_(NULL), unique_id_(0), - frame_main_(NULL) + handler_(handler), webviewhost_(NULL), popuphost_(NULL), + frame_main_(NULL), unique_id_(0) { delegate_.reset(new BrowserWebViewDelegate(this)); popup_delegate_.reset(new BrowserWebViewDelegate(this)); @@ -190,7 +192,7 @@ CefRefPtr CefBrowserImpl::GetFrame(const std::wstring& name) if (!view) return NULL; - WebFrame* frame = view->findFrameByName(name); + WebFrame* frame = view->findFrameByName(StdWStringToWebString(name)); if(frame) return GetCefFrame(frame); return NULL; @@ -285,7 +287,7 @@ WebFrame* CefBrowserImpl::GetWebFrame(CefRefPtr frame) std::wstring name = frame->GetName(); if(name.empty()) return view ->mainFrame(); - return view ->findFrameByName(name); + return view ->findFrameByName(StdWStringToWebString(name)); } void CefBrowserImpl::Undo(CefRefPtr frame) @@ -578,11 +580,12 @@ void CefBrowserImpl::UIT_LoadURLForRequest(CefFrame* frame, if (url.empty()) return; - GURL gurl(url); + GURL gurl(StdWStringToWebString(url)); if (!gurl.is_valid() && !gurl.has_scheme()) { // Try to add "http://" at the beginning - gurl = GURL(std::wstring(L"http://") + url); + std::wstring new_url = std::wstring(L"http://") + url; + gurl = GURL(StdWStringToWebString(new_url)); if (!gurl.is_valid()) return; } @@ -600,11 +603,12 @@ void CefBrowserImpl::UIT_LoadHTML(CefFrame* frame, { REQUIRE_UIT(); - GURL gurl(url); + GURL gurl(StdWStringToWebString(url)); if (!gurl.is_valid() && !gurl.has_scheme()) { // Try to add "http://" at the beginning - gurl = GURL(std::wstring(L"http://") + url); + std::wstring new_url = std::wstring(L"http://") + url; + gurl = GURL(StdWStringToWebString(new_url)); if (!gurl.is_valid()) return; } @@ -622,11 +626,12 @@ void CefBrowserImpl::UIT_LoadHTMLForStreamRef(CefFrame* frame, { REQUIRE_UIT(); - GURL gurl(url); + GURL gurl(StdWStringToWebString(url)); if (!gurl.is_valid() && !gurl.has_scheme()) { // Try to add "http://" at the beginning - gurl = GURL(std::wstring(L"http://") + url); + std::wstring new_url = std::wstring(L"http://") + url; + gurl = GURL(StdWStringToWebString(new_url)); if (!gurl.is_valid()) return; } @@ -662,8 +667,9 @@ void CefBrowserImpl::UIT_ExecuteJavaScript(CefFrame* frame, WebFrame* web_frame = GetWebFrame(frame); if(web_frame) { web_frame->executeScript( - WebScriptSource(WebString(js_code), WebURL(GURL(script_url)), - start_line)); + WebScriptSource(StdWStringToWebString(js_code), + WebURL(GURL(StdWStringToWebString(script_url))), + start_line)); } frame->Release(); @@ -693,10 +699,13 @@ bool CefBrowserImpl::UIT_Navigate(const BrowserNavigationEntry& entry, // Get the right target frame for the entry. WebFrame* frame; - if (!entry.GetTargetFrame().empty()) - frame = view->findFrameByName(entry.GetTargetFrame()); - else + if (!entry.GetTargetFrame().empty()) { + frame = view->findFrameByName( + StdWStringToWebString(entry.GetTargetFrame())); + } else { frame = view->mainFrame(); + } + // TODO(mpcomplete): should we clear the target frame, or should // back/forward navigations maintain the target frame? @@ -720,10 +729,8 @@ bool CefBrowserImpl::UIT_Navigate(const BrowserNavigationEntry& entry, DCHECK(entry.GetPageID() == -1); WebURLRequest request(entry.GetURL()); - if(entry.GetMethod().size() > 0) { - request.setHTTPMethod( - StdStringToWebString(WideToUTF8(entry.GetMethod()))); - } + if(entry.GetMethod().size() > 0) + request.setHTTPMethod(StdWStringToWebString(entry.GetMethod())); if(entry.GetHeaders().size() > 0) CefRequestImpl::SetHeaderMap(entry.GetHeaders(), request); @@ -955,8 +962,8 @@ void CefBrowserImpl::UIT_Find(int identifier, const std::wstring& search_text, // Just navigate back/forward. delegate->SelectFindResult(options.forward); } else { - if (delegate->StartFind(search_text.c_str(), options.matchCase, - identifier)) { + if (delegate->StartFind(StdWStringToWebString(search_text), + options.matchCase, identifier)) { } else { // No find results. UIT_NotifyFindStatus(identifier, 0, gfx::Rect(), 0, true); @@ -983,8 +990,8 @@ void CefBrowserImpl::UIT_Find(int identifier, const std::wstring& search_text, WebRange current_selection = focused_frame->selectionRange(); do { - result = search_frame->find( - identifier, search_text, options, wrap_within_frame, &selection_rect); + result = search_frame->find(identifier, StdWStringToWebString(search_text), + options, wrap_within_frame, &selection_rect); if (!result) { // don't leave text selected as you move to the next frame. @@ -1010,7 +1017,8 @@ 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, search_text, options, true, // Force wrapping. + identifier, StdWStringToWebString(search_text), + options, true, // Force wrapping. &selection_rect); } } @@ -1051,7 +1059,7 @@ void CefBrowserImpl::UIT_Find(int identifier, const std::wstring& search_text, // Start new scoping request. If the scoping function determines that it // needs to scope, it will defer until later. search_frame->scopeStringMatches(identifier, - search_text, + StdWStringToWebString(search_text), options, true); // reset the tickmarks } diff --git a/libcef/browser_navigation_controller.cc b/libcef/browser_navigation_controller.cc index c594c7006..4362c64a4 100644 --- a/libcef/browser_navigation_controller.cc +++ b/libcef/browser_navigation_controller.cc @@ -26,9 +26,9 @@ BrowserNavigationEntry::BrowserNavigationEntry(int page_id, : page_id_(page_id), url_(url), title_(title), - target_frame_(target_frame), method_(method), - headers_(headers) { + headers_(headers), + target_frame_(target_frame) { if(!upload.isNull()) upload_ = upload; } diff --git a/libcef/browser_resource_loader_bridge.cc b/libcef/browser_resource_loader_bridge.cc index 9c7de2294..089a97afb 100644 --- a/libcef/browser_resource_loader_bridge.cc +++ b/libcef/browser_resource_loader_bridge.cc @@ -107,9 +107,9 @@ class RequestProxy : public URLRequest::Delegate, public: // Takes ownership of the params. RequestProxy(CefRefPtr browser) - : browser_(browser), - download_to_file_(false), + : download_to_file_(false), buf_(new net::IOBuffer(kDataSize)), + browser_(browser), last_upload_position_(0) { } @@ -814,9 +814,9 @@ namespace webkit_glue { // Factory function. ResourceLoaderBridge* ResourceLoaderBridge::Create( const webkit_glue::ResourceLoaderBridge::RequestInfo& request_info) { - CefRefPtr browser = + CefRefPtr browser = _Context->GetBrowserByID(request_info.routing_id); - return new ResourceLoaderBridgeImpl(browser, request_info); + return new ResourceLoaderBridgeImpl(browser.get(), request_info); } // Issue the proxy resolve request on the io thread, and wait diff --git a/libcef/browser_webkit_glue.cc b/libcef/browser_webkit_glue.cc index 42de8e79e..a0b9d494a 100644 --- a/libcef/browser_webkit_glue.cc +++ b/libcef/browser_webkit_glue.cc @@ -113,6 +113,14 @@ std::string WebStringToStdString(const WebKit::WebString& str) { 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() { return std::string("Chrome/7.0.517.0"); } diff --git a/libcef/browser_webkit_glue.h b/libcef/browser_webkit_glue.h index 2b128647c..7ba641a28 100644 --- a/libcef/browser_webkit_glue.h +++ b/libcef/browser_webkit_glue.h @@ -43,4 +43,8 @@ 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); + } // namespace webkit_glue diff --git a/libcef/browser_webview_delegate.cc b/libcef/browser_webview_delegate.cc index 1079e2703..8daa5a081 100644 --- a/libcef/browser_webview_delegate.cc +++ b/libcef/browser_webview_delegate.cc @@ -21,8 +21,6 @@ #include "base/string_util.h" #include "base/trace_event.h" #include "base/utf_string_conversions.h" -#include "gfx/gdi_util.h" -#include "gfx/native_widget_types.h" #include "gfx/point.h" #include "media/filters/audio_renderer_impl.h" #include "net/base/net_errors.h" @@ -296,6 +294,8 @@ bool BrowserWebViewDelegate::handleCurrentKeyboardEvent() { KEYEVENT_CHAR, event.windowsKeyCode, event.modifiers, event.isSystemKey?true:false); break; + default: + break; } } } diff --git a/libcef/cef_context.cc b/libcef/cef_context.cc index 4f00ed052..a19a425e1 100644 --- a/libcef/cef_context.cc +++ b/libcef/cef_context.cc @@ -13,6 +13,7 @@ #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" #include "webkit/glue/webpreferences.h" @@ -61,7 +62,11 @@ static void UIT_RegisterPlugin(struct CefPluginInfo* plugin_info) NPAPI::PluginVersionInfo info; +#if defined(OS_WIN) info.path = FilePath(plugin_info->unique_name); +#else + info.path = FilePath(WideToUTF8(plugin_info->unique_name)); +#endif info.product_name = plugin_info->display_name; info.file_description = plugin_info->description; info.file_version =plugin_info->version; diff --git a/libcef/cef_process.cc b/libcef/cef_process.cc index a68dbbb61..01a002987 100644 --- a/libcef/cef_process.cc +++ b/libcef/cef_process.cc @@ -37,7 +37,11 @@ public: } void DoMessageLoopIteration() { +#if defined(OS_MACOSX) + Run(); +#else Run(NULL); +#endif } private: diff --git a/libcef/cef_process_io_thread.cc b/libcef/cef_process_io_thread.cc index b4212d6bb..ebbda7add 100644 --- a/libcef/cef_process_io_thread.cc +++ b/libcef/cef_process_io_thread.cc @@ -10,6 +10,7 @@ #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) @@ -33,8 +34,14 @@ void CefProcessIOThread::Init() { // Initializes the COM library on the current thread. CoInitialize(NULL); #endif + +#if defined(OS_WIN) + FilePath cache_path(_Context->cache_path()); +#else + FilePath cache_path(WideToUTF8(_Context->cache_path())); +#endif - request_context_ = new BrowserRequestContext(FilePath(_Context->cache_path()), + request_context_ = new BrowserRequestContext(cache_path, net::HttpCache::NORMAL, false); _Context->set_request_context(request_context_); diff --git a/libcef/cef_string.c b/libcef/cef_string.c index c5d39aff0..565226755 100644 --- a/libcef/cef_string.c +++ b/libcef/cef_string.c @@ -3,8 +3,14 @@ // can be found in the LICENSE file. #include "include/cef_string.h" +#include "build/build_config.h" + #include +#if defined(OS_MACOSX) +#include +#else #include +#endif #include typedef unsigned long dword_t; diff --git a/libcef/request_impl.cc b/libcef/request_impl.cc index 7eeea485c..2e1469453 100644 --- a/libcef/request_impl.cc +++ b/libcef/request_impl.cc @@ -156,8 +156,8 @@ void CefRequestImpl::SetHeaderMap(const HeaderMap& map, HeaderMap::const_iterator it = map.begin(); for(; it != map.end(); ++it) { request.setHTTPHeaderField( - webkit_glue::StdStringToWebString(WideToUTF8(it->first.c_str())), - webkit_glue::StdStringToWebString(WideToUTF8(it->second.c_str()))); + webkit_glue::StdWStringToWebString(it->first.c_str()), + webkit_glue::StdWStringToWebString(it->second.c_str())); } } @@ -465,7 +465,11 @@ void CefPostDataElementImpl::Set(const net::UploadData::Element& element) std::string(element.bytes().begin(), element.bytes().end()).c_str())); } else if (element.type() == net::UploadData::TYPE_FILE) { +#if defined(OS_WIN) SetToFile(element.file_path().value()); +#else + SetToFile(UTF8ToWide(element.file_path().value())); +#endif } else { NOTREACHED(); } @@ -480,7 +484,11 @@ void CefPostDataElementImpl::Get(net::UploadData::Element& element) if(type_ == PDE_TYPE_BYTES) { element.SetToBytes(static_cast(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 } else { NOTREACHED(); } @@ -514,8 +522,7 @@ void CefPostDataElementImpl::Get(WebKit::WebHTTPBody::Element& element) static_cast(data_.bytes.bytes), data_.bytes.size); } else if(type_ == PDE_TYPE_FILE) { element.type = WebKit::WebHTTPBody::Element::TypeFile; - element.filePath.assign( - webkit_glue::StdStringToWebString(WideToUTF8(data_.filename))); + element.filePath.assign(webkit_glue::StdWStringToWebString(data_.filename)); } else { NOTREACHED(); } diff --git a/libcef/scheme_impl.cc b/libcef/scheme_impl.cc index c6c2a15aa..8b46785f5 100644 --- a/libcef/scheme_impl.cc +++ b/libcef/scheme_impl.cc @@ -42,10 +42,6 @@ static void TrackAdd(CefTrackObject* object) g_scheme_tracker.Pointer()->Add(object); } -static void TrackDelete(CefTrackObject* object) -{ - g_scheme_tracker.Pointer()->Delete(object); -} // URLRequestJob implementation. @@ -54,9 +50,9 @@ class CefUrlRequestJob : public URLRequestJob { public: CefUrlRequestJob(URLRequest* request, CefRefPtr handler) : URLRequestJob(request), - url_(request->url()), handler_(handler), response_length_(0), + url_(request->url()), remaining_bytes_(0) { } virtual ~CefUrlRequestJob(){} diff --git a/libcef/stream_impl.cc b/libcef/stream_impl.cc index c5da5d12a..1e093d281 100644 --- a/libcef/stream_impl.cc +++ b/libcef/stream_impl.cc @@ -5,6 +5,7 @@ #include "stream_impl.h" #include "base/logging.h" +#include "base/utf_string_conversions.h" // Static functions @@ -13,7 +14,11 @@ CefRefPtr CefStreamReader::CreateForFile( const std::wstring& fileName) { CefRefPtr 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); return reader; @@ -45,7 +50,11 @@ CefRefPtr CefStreamWriter::CreateForFile( { DCHECK(!fileName.empty()); CefRefPtr writer; +#if defined(OS_WIN) FILE* file = _wfopen(fileName.c_str(), L"wb"); +#else + FILE* file = fopen(WideToUTF8(fileName).c_str(), "wb"); +#endif if(file) writer = new CefFileWriter(file, true); return writer; @@ -65,7 +74,7 @@ CefRefPtr CefStreamWriter::CreateForHandler( // CefFileReader CefFileReader::CefFileReader(FILE* file, bool close) - : file_(file), close_(close) + : close_(close), file_(file) { } @@ -255,7 +264,7 @@ void CefBytesReader::SetData(void* data, long datasize, bool copy) // CefBytesWriter CefBytesWriter::CefBytesWriter(size_t grow) - : grow_(grow), offset_(0), datasize_(grow) + : grow_(grow), datasize_(grow), offset_(0) { DCHECK(grow > 0); data_ = malloc(grow); diff --git a/libcef_dll/cpptoc/cpptoc.h b/libcef_dll/cpptoc/cpptoc.h index 536645ea9..c08cc46dc 100644 --- a/libcef_dll/cpptoc/cpptoc.h +++ b/libcef_dll/cpptoc/cpptoc.h @@ -17,6 +17,13 @@ template class CefCppToC : public CefThreadSafeBase { public: + // Structure representation with pointer to the C++ class. + struct Struct + { + StructName struct_; + CefCppToC* class_; + }; + // Use this method to retrieve the underlying class instance from our // own structure when the structure is passed as the required first // parameter of a C API function call. No explicit reference counting @@ -24,8 +31,7 @@ public: static CefRefPtr Get(StructName* s) { // Cast our structure to the wrapper structure type. - ClassName::Struct* wrapperStruct = - reinterpret_cast(s); + Struct* wrapperStruct = reinterpret_cast(s); // Return the underlying object instance. return wrapperStruct->class_->GetClass(); } @@ -48,8 +54,7 @@ public: static CefRefPtr Unwrap(StructName* s) { // Cast our structure to the wrapper structure type. - ClassName::Struct* wrapperStruct = - reinterpret_cast(s); + Struct* wrapperStruct = reinterpret_cast(s); // Add the underlying object instance to a smart pointer. CefRefPtr objectPtr(wrapperStruct->class_->GetClass()); // Release the reference to our wrapper object that was added before the @@ -59,13 +64,6 @@ public: return objectPtr; } - // Structure representation with pointer to the C++ class. - struct Struct - { - StructName struct_; - CefCppToC* class_; - }; - CefCppToC(BaseName* cls) : class_(cls) {