From 293e4ff69202cfb440f8b1bbb4e030f40b15193b Mon Sep 17 00:00:00 2001 From: "Oleg.Korshul" Date: Wed, 2 Sep 2015 16:12:40 +0000 Subject: [PATCH] git-svn-id: svn://fileserver/activex/AVS/Sources/TeamlabOffice/trunk/ServerComponents@64487 954022d7-b5bf-4e40-9824-e11837661b57 --- .../app/test/src/ASCDocumentEditor.pro | 46 ++++++++- .../app/test/src/ASCDocumentEditor_mac.pro | 19 ++-- .../app/test/src/AscDocumentEditor.pri | 10 ++ .../ChromiumBasedEditors 2/lib/include/base.h | 2 +- .../cefclient/browser/client_app_browser.h | 2 +- .../mac/cefclient/browser/client_handler.h | 2 +- .../cef/mac/cefclient/process_helper_mac.cc | 6 +- .../cefclient/renderer/client_app_renderer.h | 2 +- .../lib/src/cefapplication.cpp | 8 +- .../lib/src/cefview.cpp | 32 ++++++- .../cefwrapper/client_renderer_wrapper.cpp | 38 ++++---- .../lib/src/filedownloader.h | 94 ++++++++++++++++++- 12 files changed, 221 insertions(+), 40 deletions(-) diff --git a/DesktopEditor/ChromiumBasedEditors 2/app/test/src/ASCDocumentEditor.pro b/DesktopEditor/ChromiumBasedEditors 2/app/test/src/ASCDocumentEditor.pro index 67c0015da8..bb93c41077 100644 --- a/DesktopEditor/ChromiumBasedEditors 2/app/test/src/ASCDocumentEditor.pro +++ b/DesktopEditor/ChromiumBasedEditors 2/app/test/src/ASCDocumentEditor.pro @@ -24,6 +24,11 @@ linux-g++:!contains(QMAKE_HOST.arch, x86_64):{ message(linux32) } +mac { + PLATFORM_BUILD = mac + message(mac) +} + CONFIG(debug, debug|release) { PLATFORM_BUILD2 = $$PLATFORM_BUILD/debug DESTDIR = $$PWD/build/$$PLATFORM_BUILD/Debug @@ -41,8 +46,47 @@ SOURCES += \ win32 { LIBS += -L$$PWD/../../cefbuilds/$$PLATFORM_BUILD -llibcef -} else { +} + +linux { LIBS += -L$$PWD/../../cefbuilds/$$PLATFORM_BUILD -lcef } +mac { + +DEFINES += _MAC + +#PROJECT_PATH = $$PWD +PROJECT_PATH = .. + +QMAKE_LFLAGS += -F$${PROJECT_PATH}/../../cefbuilds/mac +LIBS += -framework "Chromium Embedded Framework" + +BUNDLE_TARGET = $${PROJECT_PATH}/build/mac/Debug/$${TARGET}.app + +QMAKE_POST_LINK += mkdir -p $${BUNDLE_TARGET}/Contents/Frameworks; +QMAKE_POST_LINK += cp -R $${PROJECT_PATH}/../../cefbuilds/mac/ASCDocumentEditor\ Helper.app $${BUNDLE_TARGET}/Contents/Frameworks; +QMAKE_POST_LINK += cp -R $${PROJECT_PATH}/../../cefbuilds/mac/Chromium\ Embedded\ Framework.framework $${BUNDLE_TARGET}/Contents/Frameworks; +QMAKE_POST_LINK += cp -R $${PROJECT_PATH}/../../corebuilds/mac/debug/libascdocumentscore.dylib $${BUNDLE_TARGET}/Contents/Frameworks; + +QMAKE_POST_LINK += install_name_tool \ +-change \ +@executable_path/Chromium\ Embedded\ Framework \ +@executable_path/../Frameworks/Chromium\ Embedded\ Framework.framework/Chromium\ Embedded\ Framework \ +$${BUNDLE_TARGET}/Contents/MacOS/ASCDocumentEditor; + +QMAKE_POST_LINK += install_name_tool \ +-change \ +libascdocumentscore.dylib \ +@executable_path/../Frameworks/libascdocumentscore.dylib \ +$${BUNDLE_TARGET}/Contents/MacOS/ASCDocumentEditor; + +QMAKE_POST_LINK += install_name_tool \ +-change \ +@executable_path/Chromium\ Embedded\ Framework \ +@executable_path/../Frameworks/Chromium\ Embedded\ Framework.framework/Chromium\ Embedded\ Framework \ +$${BUNDLE_TARGET}/Contents/Frameworks/libascdocumentscore.dylib + +} + LIBS += -L$$PWD/../../corebuilds/$$PLATFORM_BUILD2 -lascdocumentscore diff --git a/DesktopEditor/ChromiumBasedEditors 2/app/test/src/ASCDocumentEditor_mac.pro b/DesktopEditor/ChromiumBasedEditors 2/app/test/src/ASCDocumentEditor_mac.pro index 718a08ce4c..1feead3238 100644 --- a/DesktopEditor/ChromiumBasedEditors 2/app/test/src/ASCDocumentEditor_mac.pro +++ b/DesktopEditor/ChromiumBasedEditors 2/app/test/src/ASCDocumentEditor_mac.pro @@ -7,14 +7,18 @@ QT -= core QT -= gui -TARGET = ASCDocumentEditor +TARGET = $$quote(ASCDocumentEditor Helper) TEMPLATE = app #CONFIG += console CONFIG += app_bundle +CONFIG += c++11 + INCLUDEPATH += \ $$PWD/../../../lib/src/cef/mac +LIBS += -L../../../../../../SDK/lib/mac_64 -lgraphics + DEFINES += \ "V8_DEPRECATION_WARNINGS" \ "PSAPI_VERSION=1" \ @@ -72,7 +76,6 @@ DEFINES += \ "NVALGRIND" \ "DYNAMIC_ANNOTATIONS_ENABLED=0" -#PROJECT_PATH = /Users/Oleg/Desktop/activex/AVS/Sources/TeamlabOffice/trunk/ServerComponents/DesktopEditor/ChromiumBasedEditors\ 2/app/test/src PROJECT_PATH = ../ QMAKE_LFLAGS += -F$${PROJECT_PATH}/../../cefbuilds/mac @@ -228,7 +231,10 @@ SOURCES += \ ../../../lib/src/cef/mac/libcef_dll/wrapper/cef_zip_archive.cc \ ../../../lib/src/cef/mac/libcef_dll/wrapper/libcef_dll_wrapper.cc \ ../../../lib/src/cef/mac/libcef_dll/wrapper/libcef_dll_wrapper2.cc \ - ../../../lib/src/cef/mac/libcef_dll/transfer_util.cc + ../../../lib/src/cef/mac/libcef_dll/transfer_util.cc \ + ../../../lib/src/cef/mac/cefclient/process_helper_mac.cc \ + ../../../lib/src/cefwrapper/client_renderer_wrapper.cpp \ + ../../../lib/src/cefwrapper/client_scheme_wrapper.cpp HEADERS += \ ../../../lib/src/cef/mac/cefclient/browser/binding_test.h \ @@ -544,8 +550,7 @@ OBJECTIVE_SOURCES += \ ../../../lib/src/cef/mac/cefclient/browser/resource_util_mac.mm \ ../../../lib/src/cef/mac/cefclient/browser/root_window_mac.mm \ ../../../lib/src/cef/mac/cefclient/browser/temp_window_mac.mm \ - ../../../lib/src/cef/mac/cefclient/browser/window_test_mac.mm \ - ../../../lib/src/cef/mac/cefclient/cefclient_mac.mm + ../../../lib/src/cef/mac/cefclient/browser/window_test_mac.mm BUNDLE_TARGET = $${PROJECT_PATH}/mac_Debug/$${TARGET}.app @@ -555,5 +560,5 @@ cp -R $${PROJECT_PATH}/../../cefbuilds/mac/Chromium\ Embedded\ Framework.framewo install_name_tool \ -change \ @executable_path/Chromium\ Embedded\ Framework \ -@executable_path/../Frameworks/Chromium\ Embedded\ Framework.framework/Chromium\ Embedded\ Framework \ -ASCDocumentEditor.app/Contents/MacOS/ASCDocumentEditor +@executable_path/../../../../Frameworks/Chromium\ Embedded\ Framework.framework/Chromium\ Embedded\ Framework \ +ASCDocumentEditor\ Helper.app/Contents/MacOS/ASCDocumentEditor\ Helper diff --git a/DesktopEditor/ChromiumBasedEditors 2/app/test/src/AscDocumentEditor.pri b/DesktopEditor/ChromiumBasedEditors 2/app/test/src/AscDocumentEditor.pri index 86898ae599..a075168e79 100644 --- a/DesktopEditor/ChromiumBasedEditors 2/app/test/src/AscDocumentEditor.pri +++ b/DesktopEditor/ChromiumBasedEditors 2/app/test/src/AscDocumentEditor.pri @@ -60,3 +60,13 @@ linux-g++ { CONFIG += link_pkgconfig PKGCONFIG += glib-2.0 gdk-2.0 gtkglext-1.0 atk cairo gtk+-unix-print-2.0 } + +mac { + DEFINES += \ + MAC \ + _MAC \ + _LINUX + + LIBS += -framework AppKit + LIBS += -framework OpenGl +} diff --git a/DesktopEditor/ChromiumBasedEditors 2/lib/include/base.h b/DesktopEditor/ChromiumBasedEditors 2/lib/include/base.h index 425b8531ac..d308d2d455 100644 --- a/DesktopEditor/ChromiumBasedEditors 2/lib/include/base.h +++ b/DesktopEditor/ChromiumBasedEditors 2/lib/include/base.h @@ -21,7 +21,7 @@ #ifdef _MAC -#define WindowHandleId XID +#define WindowHandleId void* #endif diff --git a/DesktopEditor/ChromiumBasedEditors 2/lib/src/cef/mac/cefclient/browser/client_app_browser.h b/DesktopEditor/ChromiumBasedEditors 2/lib/src/cef/mac/cefclient/browser/client_app_browser.h index 18a4041a17..61a57a20a0 100644 --- a/DesktopEditor/ChromiumBasedEditors 2/lib/src/cef/mac/cefclient/browser/client_app_browser.h +++ b/DesktopEditor/ChromiumBasedEditors 2/lib/src/cef/mac/cefclient/browser/client_app_browser.h @@ -36,7 +36,7 @@ class ClientAppBrowser : public ClientApp, ClientAppBrowser(); - private: + protected: // Creates all of the Delegate objects. Implemented by cefclient in // client_app_delegates_browser.cc static void CreateDelegates(DelegateSet& delegates); diff --git a/DesktopEditor/ChromiumBasedEditors 2/lib/src/cef/mac/cefclient/browser/client_handler.h b/DesktopEditor/ChromiumBasedEditors 2/lib/src/cef/mac/cefclient/browser/client_handler.h index 82191f1e4b..8919d614ef 100644 --- a/DesktopEditor/ChromiumBasedEditors 2/lib/src/cef/mac/cefclient/browser/client_handler.h +++ b/DesktopEditor/ChromiumBasedEditors 2/lib/src/cef/mac/cefclient/browser/client_handler.h @@ -260,7 +260,7 @@ class ClientHandler : public CefClient, // Returns true if this handler uses off-screen rendering. bool is_osr() const { return is_osr_; } - private: + protected: // Create a new popup window using the specified information. |is_devtools| // will be true if the window will be used for DevTools. Return true to // proceed with popup browser creation or false to cancel the popup browser. diff --git a/DesktopEditor/ChromiumBasedEditors 2/lib/src/cef/mac/cefclient/process_helper_mac.cc b/DesktopEditor/ChromiumBasedEditors 2/lib/src/cef/mac/cefclient/process_helper_mac.cc index 43c0c2cce3..2f13862326 100644 --- a/DesktopEditor/ChromiumBasedEditors 2/lib/src/cef/mac/cefclient/process_helper_mac.cc +++ b/DesktopEditor/ChromiumBasedEditors 2/lib/src/cef/mac/cefclient/process_helper_mac.cc @@ -7,6 +7,8 @@ #include "cefclient/common/client_app_other.h" #include "cefclient/renderer/client_app_renderer.h" +#include "../../../cefwrapper/client_app.h" + namespace client { int RunMain(int argc, char* argv[]) { @@ -20,9 +22,9 @@ int RunMain(int argc, char* argv[]) { CefRefPtr app; ClientApp::ProcessType process_type = ClientApp::GetProcessType(command_line); if (process_type == ClientApp::RendererProcess) - app = new ClientAppRenderer(); + app = new CAscClientAppRenderer(); else if (process_type == ClientApp::OtherProcess) - app = new ClientAppOther(); + app = new CAscClientAppOther(); // Execute the secondary process. return CefExecuteProcess(main_args, app, NULL); diff --git a/DesktopEditor/ChromiumBasedEditors 2/lib/src/cef/mac/cefclient/renderer/client_app_renderer.h b/DesktopEditor/ChromiumBasedEditors 2/lib/src/cef/mac/cefclient/renderer/client_app_renderer.h index 49223639a1..e3aff7e516 100644 --- a/DesktopEditor/ChromiumBasedEditors 2/lib/src/cef/mac/cefclient/renderer/client_app_renderer.h +++ b/DesktopEditor/ChromiumBasedEditors 2/lib/src/cef/mac/cefclient/renderer/client_app_renderer.h @@ -125,7 +125,7 @@ class ClientAppRenderer : public ClientApp, CefProcessId source_process, CefRefPtr message) OVERRIDE; - private: + protected: // Set of supported Delegates. DelegateSet delegates_; diff --git a/DesktopEditor/ChromiumBasedEditors 2/lib/src/cefapplication.cpp b/DesktopEditor/ChromiumBasedEditors 2/lib/src/cefapplication.cpp index da9b40abc7..64cd393409 100644 --- a/DesktopEditor/ChromiumBasedEditors 2/lib/src/cefapplication.cpp +++ b/DesktopEditor/ChromiumBasedEditors 2/lib/src/cefapplication.cpp @@ -201,7 +201,7 @@ void CApplicationCEF::Init_CEF(CAscApplicationManager* pManager, int argc, char* settings.cache_path = _cache; // Initialize CEF. -#if defined(_LINUX) && !defined(_MAC) +#if defined(_LINUX) bool bInit = m_pInternal->context->Initialize(main_args, settings, m_pInternal->m_app.get(), sandbox_info); #else bool bInit = CefInitialize(main_args, settings, m_pInternal->m_app.get(), sandbox_info); @@ -230,7 +230,7 @@ void CApplicationCEF::Close() { if (NULL != m_pInternal) { -#if defined(_LINUX) && !defined(_MAC) +#if defined(_LINUX) m_pInternal->context->Shutdown(); #else // Shut down CEF. @@ -243,7 +243,7 @@ void CApplicationCEF::Close() int CApplicationCEF::RunMessageLoop(bool& is_runned) { -#if defined(_LINUX) && !defined(_MAC) +#if defined(_LINUX) is_runned = true; return m_pInternal->message_loop->Run(); #else @@ -259,7 +259,7 @@ void CApplicationCEF::DoMessageLoopEvent() bool CApplicationCEF::ExitMessageLoop() { -#if defined(_LINUX) && !defined(_MAC) +#if defined(_LINUX) m_pInternal->message_loop->Quit(); return true; #else diff --git a/DesktopEditor/ChromiumBasedEditors 2/lib/src/cefview.cpp b/DesktopEditor/ChromiumBasedEditors 2/lib/src/cefview.cpp index 0d0763715b..60a576164c 100644 --- a/DesktopEditor/ChromiumBasedEditors 2/lib/src/cefview.cpp +++ b/DesktopEditor/ChromiumBasedEditors 2/lib/src/cefview.cpp @@ -48,6 +48,10 @@ LRESULT CALLBACK MyMouseHook(int nCode, WPARAM wp, LPARAM lp) #include #endif +#ifdef _MAC +#include "mac_common.h" +#endif + class CPagePrintData { public: @@ -619,15 +623,21 @@ void CCefFileDownloader::DownloadFile(CAscApplicationManager* pManager, const st rect.top = 0; rect.right = 10; rect.bottom = 10; -#else + info.SetAsChild(hWnd, rect); +#endif + +#if defined(_LINUX) && !defined(_MAC) CefRect rect; rect.x = 0; rect.y = 0; rect.width = 10; rect.height = 10; + info.SetAsChild(hWnd, rect); #endif - info.SetAsChild(hWnd, rect); +#ifdef _MAC + info.SetAsChild(hWnd, 0, 0, 10, 10); +#endif // Creat the new child browser window CefBrowserHost::CreateBrowser(info, m_pInternal, "ascdesktop://emptydownload.html", _settings, NULL); @@ -1822,15 +1832,23 @@ void CCefView::load(const std::wstring& url) rect.top = 0; rect.right = m_pInternal->m_pWidgetImpl->parent_width() - 1; rect.bottom = m_pInternal->m_pWidgetImpl->parent_height() - 1; -#else + info.SetAsChild(hWnd, rect); +#endif + +#if defined(_LINUX) && !defined(_MAC) CefRect rect; rect.x = 0; rect.y = 0; rect.width = m_pInternal->m_pWidgetImpl->parent_width(); rect.height = m_pInternal->m_pWidgetImpl->parent_height(); + info.SetAsChild(hWnd, rect); #endif - info.SetAsChild(hWnd, rect); +#ifdef _MAC + info.SetAsChild(hWnd, 0, 0, + m_pInternal->m_pWidgetImpl->parent_width(), + m_pInternal->m_pWidgetImpl->parent_height()); +#endif CefString sUrl = url; @@ -1969,6 +1987,12 @@ void CCefView::resizeEvent(int width, int height) XConfigureWindow(xdisplay, xwindow, CWHeight | CWWidth | CWY, &changes); #endif +#ifdef _MAC + MAC_COMMON_set_window_handle_sizes(hwnd, 0, 0, + (0 == width) ? (m_pInternal->m_pWidgetImpl->parent_width()) : width, + (0 == height) ? (m_pInternal->m_pWidgetImpl->parent_height()) : height); +#endif + focus(); } diff --git a/DesktopEditor/ChromiumBasedEditors 2/lib/src/cefwrapper/client_renderer_wrapper.cpp b/DesktopEditor/ChromiumBasedEditors 2/lib/src/cefwrapper/client_renderer_wrapper.cpp index d5ecc03df1..9dd7eeb9f3 100644 --- a/DesktopEditor/ChromiumBasedEditors 2/lib/src/cefwrapper/client_renderer_wrapper.cpp +++ b/DesktopEditor/ChromiumBasedEditors 2/lib/src/cefwrapper/client_renderer_wrapper.cpp @@ -10,7 +10,6 @@ #include "../../../../common/File.h" #include "../../../../common/Directory.h" #include "../../../../graphics/BaseThread.h" -#include "../../src/filedownloader.h" #include "../../../../raster/ImageFileFormatChecker.h" namespace asc_client_renderer @@ -63,7 +62,7 @@ public: const CefV8ValueList& arguments, CefRefPtr& retval, CefString& exception) OVERRIDE - { + { if (name == "Copy") { CefV8Context::GetCurrentContext()->GetFrame()->Copy(); @@ -795,10 +794,29 @@ public: return false; } + bool IsNeedDownload(const std::wstring& FilePath) + { + int n1 = FilePath.find(L"www."); + int n2 = FilePath.find(L"http://"); + int n3 = FilePath.find(L"ftp://"); + int n4 = FilePath.find(L"https://"); + + if (n1 != std::wstring::npos && n1 < 10) + return true; + if (n2 != std::wstring::npos && n2 < 10) + return true; + if (n3 != std::wstring::npos && n3 < 10) + return true; + if (n4 != std::wstring::npos && n4 < 10) + return true; + + return false; + } + std::wstring GetFullUrl(const std::wstring& sUrl, const std::wstring& sBaseUrl) { std::wstring sUrlSrc = L""; - if (CFileDownloader::IsNeedDownload(sUrl)) + if (IsNeedDownload(sUrl)) { sUrlSrc = sUrl; } @@ -841,20 +859,6 @@ public: return sUrlSrc; } - bool DownloadFile(const std::wstring& sUrl, const std::wstring& sDst, const std::wstring& sBaseUrl) - { - std::wstring sUrlSrc = GetFullUrl(sUrl, sBaseUrl); - - CFileDownloader oDownloader(sUrlSrc, false); - oDownloader.SetFilePath(sDst); - oDownloader.Start( 0 ); - while ( oDownloader.IsRunned() ) - { - NSThreads::Sleep(10); - } - return oDownloader.IsFileDownloaded(); - } - // Provide the reference counting implementation for this class. IMPLEMENT_REFCOUNTING(CAscEditorNativeV8Handler); }; diff --git a/DesktopEditor/ChromiumBasedEditors 2/lib/src/filedownloader.h b/DesktopEditor/ChromiumBasedEditors 2/lib/src/filedownloader.h index dfd5e5b366..523cbdb8ce 100644 --- a/DesktopEditor/ChromiumBasedEditors 2/lib/src/filedownloader.h +++ b/DesktopEditor/ChromiumBasedEditors 2/lib/src/filedownloader.h @@ -376,7 +376,9 @@ protected : bool m_bDelete; // Удалять ли файл в деструкторе }; -#else +#endif + +#if defined(LINUX) && !defined(MAC) #include #include @@ -530,6 +532,96 @@ protected : }; +#endif + +#ifdef MAC + +class CFileDownloader : public NSThreads::CBaseThread +{ +public : + CFileDownloader(std::wstring sFileUrl, bool bDelete = true) : NSThreads::CBaseThread() + { + m_sFilePath = L""; + m_sFileUrl = sFileUrl; + m_bComplete = false; + m_bDelete = bDelete; + } + ~CFileDownloader () + { + if ( m_sFilePath.length() > 0 && m_bDelete ) + { + NSFile::CFileBinary::Remove(m_sFilePath); + m_sFilePath = L""; + } + } + + void SetFilePath(const std::wstring& sPath) + { + m_sFilePath = sPath; + } + + std::wstring GetFilePath() + { + return m_sFilePath; + } + bool IsFileDownloaded() + { + return m_bComplete; + } +protected : + + virtual DWORD ThreadProc () + { + m_bComplete = false; + + if ( true ) + { + int hrResultAll = DownloadFileAll(m_sFileUrl); + + if (0 != hrResultAll) + { + m_bRunThread = FALSE; + return 0; + } + } + + m_bComplete = true; + m_bRunThread = FALSE; + return 0; + } + + int DownloadFileAll(std::wstring sFileURL); + +public: + static bool IsNeedDownload(const std::wstring& FilePath) + { + int n1 = FilePath.find(L"www."); + int n2 = FilePath.find(L"http://"); + int n3 = FilePath.find(L"ftp://"); + int n4 = FilePath.find(L"https://"); + + if (n1 != std::wstring::npos && n1 < 10) + return true; + if (n2 != std::wstring::npos && n2 < 10) + return true; + if (n3 != std::wstring::npos && n3 < 10) + return true; + if (n4 != std::wstring::npos && n4 < 10) + return true; + + return false; + } + +protected : + + std::wstring m_sFilePath; // Путь к сохраненному файлу на диске + std::wstring m_sFileUrl; // Ссылка на скачивание файла + + bool m_bComplete; // Закачался файл или нет + bool m_bDelete; // Удалять ли файл в деструкторе + +}; + #endif #endif // CEF_FILE_DOWNLOADER