diff --git a/appshell/appshell_extensions_gtk.cpp b/appshell/appshell_extensions_gtk.cpp new file mode 100644 index 000000000..9ca468051 --- /dev/null +++ b/appshell/appshell_extensions_gtk.cpp @@ -0,0 +1,819 @@ +/* + * Copyright (c) 2012 Chhatoi Pritam Baral . All rights reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + * + */ + +#include "appshell_extensions.h" +#include "client_handler.h" + +#include +#include +#include + +#define CLOSING_PROP L"CLOSING" + + +/////////////////////////////////////////////////////////////////////////////// +// LiveBrowserMgrLin + +class LiveBrowserMgrLin +{ +public: + static LiveBrowserMgrLin* GetInstance(); + static void Shutdown(); + + bool IsChromeWindow(Window hwnd); + bool IsAnyChromeWindowsRunning(); + void CloseLiveBrowserKillTimers(); + void CloseLiveBrowserFireCallback(int valToSend); + + CefRefPtr GetCloseCallback() { return m_closeLiveBrowserCallback; } + int GetCloseHeartbeatTimerId() { return m_closeLiveBrowserHeartbeatTimerId; } + int GetCloseTimeoutTimerId() { return m_closeLiveBrowserTimeoutTimerId; } + + void SetCloseCallback(CefRefPtr closeLiveBrowserCallback) + { m_closeLiveBrowserCallback = closeLiveBrowserCallback; } + void SetBrowser(CefRefPtr browser) + { m_browser = browser; } + void SetCloseHeartbeatTimerId(int closeLiveBrowserHeartbeatTimerId) + { m_closeLiveBrowserHeartbeatTimerId = closeLiveBrowserHeartbeatTimerId; } + void SetCloseTimeoutTimerId(int closeLiveBrowserTimeoutTimerId) + { m_closeLiveBrowserTimeoutTimerId = closeLiveBrowserTimeoutTimerId; } + +private: + // private so this class cannot be instantiated externally + LiveBrowserMgrLin(); + virtual ~LiveBrowserMgrLin(); + + int m_closeLiveBrowserHeartbeatTimerId; + int m_closeLiveBrowserTimeoutTimerId; + CefRefPtr m_closeLiveBrowserCallback; + CefRefPtr m_browser; + + static LiveBrowserMgrLin* s_instance; +}; + +LiveBrowserMgrLin::LiveBrowserMgrLin() + : m_closeLiveBrowserHeartbeatTimerId(0) + , m_closeLiveBrowserTimeoutTimerId(0) +{ +} + +LiveBrowserMgrLin::~LiveBrowserMgrLin() +{ +} + +LiveBrowserMgrLin* LiveBrowserMgrLin::GetInstance() +{ + if (!s_instance) + s_instance = new LiveBrowserMgrLin(); + return s_instance; +} + +void LiveBrowserMgrLin::Shutdown() +{ + delete s_instance; + s_instance = NULL; +} + +bool LiveBrowserMgrLin::IsChromeWindow(Window hwnd) +{ + if( !hwnd ) { + return false; + } + + //TODO be!! + return true; +} + +struct EnumChromeWindowsCallbackData +{ + bool closeWindow; + int numberOfFoundWindows; +}; + +// bool CALLBACK LiveBrowserMgrLin::EnumChromeWindowsCallback(Window hwnd, long userParam) +// { +// if( !hwnd || !s_instance) { +// return FALSE; +// } + +// EnumChromeWindowsCallbackData* cbData = reinterpret_cast(userParam); +// if(!cbData) { +// return FALSE; +// } + +// if (!s_instance->IsChromeWindow(hwnd)) { +// return TRUE; +// } + +// cbData->numberOfFoundWindows++; +// //This window belongs to the instance of the browser we're interested in, tell it to close +// if( cbData->closeWindow ) { +// ::SendMessageCallback(hwnd, WM_CLOSE, NULL, NULL, CloseLiveBrowserAsyncCallback, NULL); +// } + +// return TRUE; +// } + +bool LiveBrowserMgrLin::IsAnyChromeWindowsRunning() +{ + return false; +} + +void LiveBrowserMgrLin::CloseLiveBrowserKillTimers() +{ + if (m_closeLiveBrowserHeartbeatTimerId) { + m_closeLiveBrowserHeartbeatTimerId = 0; + } + + if (m_closeLiveBrowserTimeoutTimerId) { + m_closeLiveBrowserTimeoutTimerId = 0; + } +} + +void LiveBrowserMgrLin::CloseLiveBrowserFireCallback(int valToSend) +{ + CefRefPtr responseArgs = m_closeLiveBrowserCallback->GetArgumentList(); + + // kill the timers + CloseLiveBrowserKillTimers(); + + // Set common response args (callbackId and error) + responseArgs->SetInt(1, valToSend); + + // Send response + m_browser->SendProcessMessage(PID_RENDERER, m_closeLiveBrowserCallback); + + // Clear state + m_closeLiveBrowserCallback = NULL; + m_browser = NULL; +} + +// void CALLBACK LiveBrowserMgrLin::CloseLiveBrowserTimerCallback( Window hwnd, int uMsg, int idEvent, int dwTime) +// { +// if( !s_instance ) { +// ::KillTimer(NULL, idEvent); +// return; +// } + +// int retVal = NO_ERROR; +// if( s_instance->IsAnyChromeWindowsRunning() ) +// { +// retVal = ERR_UNKNOWN; +// //if this is the heartbeat timer, wait for another beat +// if (idEvent == s_instance->m_closeLiveBrowserHeartbeatTimerId) { +// return; +// } +// } + +// //notify back to the app +// s_instance->CloseLiveBrowserFireCallback(retVal); +// } + +// void CALLBACK LiveBrowserMgrLin::CloseLiveBrowserAsyncCallback( Window hwnd, int uMsg, ULONG_PTR dwData, LRESULT lResult ) +// { +// if( !s_instance ) { +// return; +// } + +// //If there are no more versions of chrome, then fire the callback +// if( !s_instance->IsAnyChromeWindowsRunning() ) { +// s_instance->CloseLiveBrowserFireCallback(NO_ERROR); +// } +// else if(s_instance->m_closeLiveBrowserHeartbeatTimerId == 0){ +// //start a heartbeat timer to see if it closes after the message returned +// s_instance->m_closeLiveBrowserHeartbeatTimerId = ::SetTimer(NULL, 0, 30, CloseLiveBrowserTimerCallback); +// } +// } + +LiveBrowserMgrLin* LiveBrowserMgrLin::s_instance = NULL; + + +// static int CALLBACK SetInitialPathCallback(Window hWnd, int uMsg, long lParam, long lpData) +// { +// if (BFFM_INITIALIZED == uMsg && NULL != lpData) +// { +// SendMessage(hWnd, BFFM_SETSELECTION, TRUE, lpData); +// } + +// return 0; +// } + +// static std::wstring GetPathToLiveBrowser() +// { +// HKEY hKey; + +// // First, look at the "App Paths" registry key for a "chrome.exe" entry. This only +// // checks for installs for all users. If Chrome is only installed for the current user, +// // we fall back to the code below. +// if (ERROR_SUCCESS == RegOpenKeyEx( +// HKEY_LOCAL_MACHINE, +// L"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\App Paths\\chrome.exe", +// 0, KEY_READ, &hKey)) { +// wchar_t wpath[MAX_PATH] = {0}; + +// int length = MAX_PATH; +// RegQueryValueEx(hKey, NULL, NULL, NULL, (LPBYTE)wpath, &length); +// RegCloseKey(hKey); + +// return std::wstring(wpath); +// } + +// // We didn't get an "App Paths" entry. This could be because Chrome was only installed for +// // the current user, or because Chrome isn't installed at all. +// // Look for Chrome.exe at C:\Users\{USERNAME}\AppData\Local\Google\Chrome\Application\chrome.exe +// TCHAR localAppPath[MAX_PATH] = {0}; +// SHGetFolderPath(NULL, CSIDL_LOCAL_APPDATA, NULL, SHGFP_TYPE_CURRENT, localAppPath); +// std::wstring appPath(localAppPath); +// appPath += L"\\Google\\Chrome\\Application\\chrome.exe"; + +// return appPath; +// } + +// static bool ConvertToShortPathName(std::wstring & path) +// { +// int shortPathBufSize = _MAX_PATH+1; +// WCHAR shortPathBuf[_MAX_PATH+1]; +// int finalShortPathSize = ::GetShortPathName(path.c_str(), shortPathBuf, shortPathBufSize); +// if( finalShortPathSize == 0 ) { +// return false; +// } + +// path.assign(shortPathBuf, finalShortPathSize); +// return true; +// } + +int32 OpenLiveBrowser(ExtensionString argURL, bool enableRemoteDebugging) +{ + + //#TODO Duh! + return NO_ERROR; +} + +// int32 OpenLiveBrowser(ExtensionString argURL, bool enableRemoteDebugging) +// { +// std::wstring appPath = GetPathToLiveBrowser(); +// std::wstring args = appPath; + +// if (enableRemoteDebugging) +// args += L" --remote-debugging-port=9222 --allow-file-access-from-files "; +// else +// args += L" "; +// args += argURL; + +// // Args must be mutable +// int argsBufSize = args.length() +1; +// std::auto_ptr argsBuf( new WCHAR[argsBufSize]); +// wcscpy(argsBuf.get(), args.c_str()); + +// STARTUPINFO si = {0}; +// si.cb = sizeof(si); +// PROCESS_INFORMATION pi = {0}; + +// //Send the whole command in through the args param. Windows will parse the first token up to a space +// //as the processes and feed the rest in as the argument string. +// if (!CreateProcess(NULL, argsBuf.get(), NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi)) { +// return ConvertWinErrorCode(GetLastError()); +// } + +// CloseHandle(pi.hProcess); +// CloseHandle(pi.hThread); + +// return NO_ERROR; +// } + +void CloseLiveBrowser(CefRefPtr browser, CefRefPtr response) +{ + //#TODO Duh, +} + +// void CloseLiveBrowser(CefRefPtr browser, CefRefPtr response) +// { +// LiveBrowserMgrLin* liveBrowserMgr = LiveBrowserMgrLin::GetInstance(); + +// if (liveBrowserMgr->GetCloseCallback() != NULL) { +// // We can only handle a single async callback at a time. If there is already one that hasn't fired then +// // we kill it now and get ready for the next. +// liveBrowserMgr->CloseLiveBrowserFireCallback(ERR_UNKNOWN); +// } + +// liveBrowserMgr->SetCloseCallback(response); +// liveBrowserMgr->SetBrowser(browser); + +// EnumChromeWindowsCallbackData cbData = {0}; + +// cbData.numberOfFoundWindows = 0; +// cbData.closeWindow = true; +// ::EnumWindows(LiveBrowserMgrLin::EnumChromeWindowsCallback, (long)&cbData); + +// if (cbData.numberOfFoundWindows == 0) { +// liveBrowserMgr->CloseLiveBrowserFireCallback(NO_ERROR); +// } else if (liveBrowserMgr->GetCloseCallback()) { +// // set a timeout for up to 3 minutes to close the browser +// liveBrowserMgr->SetCloseTimeoutTimerId( ::SetTimer(NULL, 0, 3 * 60 * 1000, LiveBrowserMgrLin::CloseLiveBrowserTimerCallback) ); +// } +// } + +int32 OpenURLInDefaultBrowser(ExtensionString url) +{ + return NO_ERROR; +} + +// int32 OpenURLInDefaultBrowser(ExtensionString url) +// { +// int result = (int)ShellExecute(NULL, L"open", url.c_str(), NULL, NULL, SW_SHOWNORMAL); + +// // If the result > 32, the function suceeded. If the result is <= 32, it is an +// // error code. +// if (result <= 32) +// return ConvertWinErrorCode(result); + +// return NO_ERROR; +// } + +int32 ShowOpenDialog(bool allowMultipleSelection, + bool chooseDirectory, + ExtensionString title, + ExtensionString initialDirectory, + ExtensionString fileTypes, + CefRefPtr& selectedFiles) +{ + return NO_ERROR; +} + +// int32 ShowOpenDialog(bool allowMultipleSelection, +// bool chooseDirectory, +// ExtensionString title, +// ExtensionString initialDirectory, +// ExtensionString fileTypes, +// CefRefPtr& selectedFiles) +// { +// wchar_t szFile[MAX_PATH]; +// szFile[0] = 0; + +// // TODO (issue #64) - This method should be using IFileDialog instead of the +// /* outdated SHGetPathFromIDList and GetOpenFileName. + +// Useful function to parse fileTypesStr: +// template +// int inline findAndReplaceString(T& source, const T& find, const T& replace) +// { +// int num=0; +// int fLen = find.size(); +// int rLen = replace.size(); +// for (int pos=0; (pos=source.find(find, pos))!=T::npos; pos+=rLen) +// { +// num++; +// source.replace(pos, fLen, replace); +// } +// return num; +// } +// */ + +// // SHBrowseForFolder can handle Windows path only, not Unix path. +// // ofn.lpstrInitialDir also needs Windows path on XP and not Unix path. +// ConvertToNativePath(initialDirectory); + +// if (chooseDirectory) { +// BROWSEINFO bi = {0}; +// bi.hwndOwner = GetActiveWindow(); +// bi.lpszTitle = title.c_str(); +// bi.ulFlags = BIF_NEWDIALOGSTYLE; +// bi.lpfn = SetInitialPathCallback; +// bi.lParam = (long)initialDirectory.c_str(); + +// LPITEMIDLIST pidl = SHBrowseForFolder(&bi); +// if (pidl != 0) { +// if (SHGetPathFromIDList(pidl, szFile)) { +// // Add directory path to the result +// ExtensionString pathName(szFile); +// ConvertToUnixPath(pathName); +// selectedFiles->SetString(0, pathName); +// } +// IMalloc* pMalloc = NULL; +// SHGetMalloc(&pMalloc); +// if (pMalloc) { +// pMalloc->Free(pidl); +// pMalloc->Release(); +// } +// } +// } else { +// OPENFILENAME ofn; + +// ZeroMemory(&ofn, sizeof(ofn)); +// ofn.hwndOwner = GetActiveWindow(); +// ofn.lStructSize = sizeof(ofn); +// ofn.lpstrFile = szFile; +// ofn.nMaxFile = MAX_PATH; + +// // TODO (issue #65) - Use passed in file types. Note, when fileTypesStr is null, all files should be shown +// /* findAndReplaceString( fileTypesStr, std::string(" "), std::string(";*.")); +// LPCWSTR allFilesFilter = L"All Files\0*.*\0\0";*/ + +// ofn.lpstrFilter = L"All Files\0*.*\0Web Files\0*.js;*.css;*.htm;*.html\0\0"; + +// ofn.lpstrInitialDir = initialDirectory.c_str(); +// ofn.Flags = OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST | OFN_NOCHANGEDIR | OFN_EXPLORER; +// if (allowMultipleSelection) +// ofn.Flags |= OFN_ALLOWMULTISELECT; + +// if (GetOpenFileName(&ofn)) { +// if (allowMultipleSelection) { +// // Multiple selection encodes the files differently + +// // If multiple files are selected, the first null terminator +// // signals end of directory that the files are all in +// std::wstring dir(szFile); + +// // Check for two null terminators, which signal that only one file +// // was selected +// if (szFile[dir.length() + 1] == '\0') { +// ExtensionString filePath(dir); +// ConvertToUnixPath(filePath); +// selectedFiles->SetString(0, filePath); +// } else { +// // Multiple files are selected +// wchar_t fullPath[MAX_PATH]; +// for (int i = (dir.length() + 1), fileIndex = 0; ; fileIndex++) { +// // Get the next file name +// std::wstring file(&szFile[i]); + +// // Two adjacent null characters signal the end of the files +// if (file.length() == 0) +// break; + +// // The filename is relative to the directory that was specified as +// // the first string +// if (PathCombine(fullPath, dir.c_str(), file.c_str()) != NULL) { +// ExtensionString filePath(fullPath); +// ConvertToUnixPath(filePath); +// selectedFiles->SetString(fileIndex, filePath); +// } + +// // Go to the start of the next file name +// i += file.length() + 1; +// } +// } + +// } else { +// // If multiple files are not allowed, add the single file +// selectedFiles->SetString(0, szFile); +// } +// } +// } + +// return NO_ERROR; +// } + +int32 ReadDir(ExtensionString path, CefRefPtr& directoryContents) +{ + return NO_ERROR; +} + +// int32 ReadDir(ExtensionString path, CefRefPtr& directoryContents) +// { +// if (path.length() && path[path.length() - 1] != '/') +// path += '/'; + +// path += '*'; + +// WIN32_FIND_DATA ffd; +// HANDLE hFind = FindFirstFile(path.c_str(), &ffd); + +// std::vector resultFiles; +// std::vector resultDirs; + +// if (hFind != INVALID_HANDLE_VALUE) { +// do { +// // Ignore '.' and '..' +// if (!wcscmp(ffd.cFileName, L".") || !wcscmp(ffd.cFileName, L"..")) +// continue; + +// // Collect file and directory names separately +// if (ffd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) { +// resultDirs.push_back(ExtensionString(ffd.cFileName)); +// } else { +// resultFiles.push_back(ExtensionString(ffd.cFileName)); +// } +// } +// while (FindNextFile(hFind, &ffd) != 0); + +// FindClose(hFind); +// } +// else { +// return ConvertWinErrorCode(GetLastError()); +// } + +// // On Windows, list directories first, then files +// size_t i, total = 0; +// for (i = 0; i < resultDirs.size(); i++) +// directoryContents->SetString(total++, resultDirs[i]); +// for (i = 0; i < resultFiles.size(); i++) +// directoryContents->SetString(total++, resultFiles[i]); + +// return NO_ERROR; +// } + +int MakeDir(ExtensionString path, int mode) +{ + return NO_ERROR; +} + +// int32 MakeDir(ExtensionString path, int32 mode) +// { +// // TODO (issue #1759): honor mode +// ConvertToNativePath(path); +// int err = SHCreateDirectoryEx(NULL, path.c_str(), NULL); + +// return ConvertWinErrorCode(err); +// } + +int Rename(ExtensionString oldName, ExtensionString newName) +{ + return NO_ERROR; +} + +// int32 Rename(ExtensionString oldName, ExtensionString newName) +// { +// if (!MoveFile(oldName.c_str(), newName.c_str())) +// return ConvertWinErrorCode(GetLastError()); + +// return NO_ERROR; +// } + +int GetFileModificationTime(ExtensionString filename, uint32& modtime, bool& isDir) +{ + return NO_ERROR; +} + +// int32 GetFileModificationTime(ExtensionString filename, uint32& modtime, bool& isDir) +// { +// int dwAttr = GetFileAttributes(filename.c_str()); + +// if (dwAttr == INVALID_FILE_ATTRIBUTES) { +// return ConvertWinErrorCode(GetLastError()); +// } + +// isDir = ((dwAttr & FILE_ATTRIBUTE_DIRECTORY) != 0); + +// WIN32_FILE_ATTRIBUTE_DATA fad; +// if (!GetFileAttributesEx(filename.c_str(), GetFileExInfoStandard, &fad)) { +// return ConvertWinErrorCode(GetLastError()); +// } + +// modtime = FiletimeToTime(fad.ftLastWriteTime); + +// return NO_ERROR; +// } + +int ReadFile(ExtensionString filename, ExtensionString encoding, std::string& contents) +{ + return NO_ERROR; +} + +// int32 ReadFile(ExtensionString filename, ExtensionString encoding, std::string& contents) +// { +// if (encoding != L"utf8") +// return ERR_UNSUPPORTED_ENCODING; + +// int dwAttr; +// dwAttr = GetFileAttributes(filename.c_str()); +// if (INVALID_FILE_ATTRIBUTES == dwAttr) +// return ConvertWinErrorCode(GetLastError()); + +// if (dwAttr & FILE_ATTRIBUTE_DIRECTORY) +// return ERR_CANT_READ; + +// HANDLE hFile = CreateFile(filename.c_str(), GENERIC_READ, +// 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); +// int32 error = NO_ERROR; + +// if (INVALID_HANDLE_VALUE == hFile) +// return ConvertWinErrorCode(GetLastError()); + +// int dwFileSize = GetFileSize(hFile, NULL); +// int dwBytesRead; +// char* buffer = (char*)malloc(dwFileSize); +// if (buffer && ReadFile(hFile, buffer, dwFileSize, &dwBytesRead, NULL)) { +// contents = std::string(buffer, dwFileSize); +// } +// else { +// if (!buffer) +// error = ERR_UNKNOWN; +// else +// error = ConvertWinErrorCode(GetLastError()); +// } +// CloseHandle(hFile); +// if (buffer) +// free(buffer); + +// return error; +// } + +int32 WriteFile(ExtensionString filename, std::string contents, ExtensionString encoding) +{ + return NO_ERROR; +} + +// int32 WriteFile(ExtensionString filename, std::string contents, ExtensionString encoding) +// { +// if (encoding != L"utf8") +// return ERR_UNSUPPORTED_ENCODING; + +// HANDLE hFile = CreateFile(filename.c_str(), GENERIC_WRITE, +// 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL); +// int dwBytesWritten; +// int error = NO_ERROR; + +// if (INVALID_HANDLE_VALUE == hFile) +// return ConvertWinErrorCode(GetLastError(), false); + +// // TODO (issue 67) - Should write to temp file and handle encoding +// if (!WriteFile(hFile, contents.c_str(), contents.length(), &dwBytesWritten, NULL)) { +// error = ConvertWinErrorCode(GetLastError(), false); +// } + +// CloseHandle(hFile); +// return error; +// } + +int SetPosixPermissions(ExtensionString filename, int32 mode) +{ + return NO_ERROR; +} + +// int32 SetPosixPermissions(ExtensionString filename, int32 mode) +// { +// int dwAttr = GetFileAttributes(filename.c_str()); + +// if (dwAttr == INVALID_FILE_ATTRIBUTES) +// return ERR_NOT_FOUND; + +// if ((dwAttr & FILE_ATTRIBUTE_DIRECTORY) != 0) +// return NO_ERROR; + +// bool write = (mode & 0200) != 0; +// bool read = (mode & 0400) != 0; +// int mask = (write ? _S_IWRITE : 0) | (read ? _S_IREAD : 0); + +// if (_wchmod(filename.c_str(), mask) == -1) { +// return ConvertErrnoCode(errno); +// } + +// return NO_ERROR; +// } + +int DeleteFileOrDirectory(ExtensionString filename) +{ + return NO_ERROR; +} +// int32 DeleteFileOrDirectory(ExtensionString filename) +// { +// int dwAttr = GetFileAttributes(filename.c_str()); + +// if (dwAttr == INVALID_FILE_ATTRIBUTES) +// return ERR_NOT_FOUND; + +// if ((dwAttr & FILE_ATTRIBUTE_DIRECTORY) != 0) +// return ERR_NOT_FILE; + +// if (!DeleteFile(filename.c_str())) +// return ConvertWinErrorCode(GetLastError()); + +// return NO_ERROR; +// } + + +// void OnBeforeShutdown() +// { +// LiveBrowserMgrLin::Shutdown(); +// } + +void CloseWindow(CefRefPtr browser) +{ + +} + +// void CloseWindow(CefRefPtr browser) +// { +// if (browser.get()) { +// Window browserHwnd = browser->GetHost()->GetWindowHandle(); +// SetProp(browserHwnd, CLOSING_PROP, (HANDLE)1); +// browser->GetHost()->CloseBrowser(); +// } +// } + +void BringBrowserWindowToFront(CefRefPtr browser) +{ + +} + +// void BringBrowserWindowToFront(CefRefPtr browser) +// { +// if (browser.get()) { +// Window hwnd = browser->GetHost()->GetWindowHandle(); +// // if (hwnd) +// // ::BringWindowToTop(hwnd); +// // TODO +// } +// } + +// void ConvertToNativePath(ExtensionString& filename) +// { +// // Convert '/' to '\' +// replace(filename.begin(), filename.end(), '/', '\\'); +// } + +// void ConvertToUnixPath(ExtensionString& filename) +// { +// // Convert '\\' to '/' +// replace(filename.begin(), filename.end(), '\\', '/'); +// } + +// // Maps errors from errno.h to the brackets error codes +// // found in brackets_extensions.js +// int ConvertErrnoCode(int errorCode, bool isReading) +// { +// switch (errorCode) { +// case NO_ERROR: +// return NO_ERROR; +// case EINVAL: +// return ERR_INVALID_PARAMS; +// case ENOENT: +// return ERR_NOT_FOUND; +// default: +// return ERR_UNKNOWN; +// } +// } + +// // Maps errors from WinError.h to the brackets error codes +// // found in brackets_extensions.js +// int ConvertWinErrorCode(int errorCode, bool isReading) +// { +// switch (errorCode) { +// case NO_ERROR: +// return NO_ERROR; +// case ERROR_PATH_NOT_FOUND: +// case ERROR_FILE_NOT_FOUND: +// return ERR_NOT_FOUND; +// case ERROR_ACCESS_DENIED: +// return isReading ? ERR_CANT_READ : ERR_CANT_WRITE; +// case ERROR_WRITE_PROTECT: +// return ERR_CANT_WRITE; +// case ERROR_HANDLE_DISK_FULL: +// return ERR_OUT_OF_SPACE; +// case ERROR_ALREADY_EXISTS: +// return ERR_FILE_EXISTS; +// default: +// return ERR_UNKNOWN; +// } +// } + +// /** +// * Convert a FILETIME (number of 100 nanosecond intervals since Jan 1 1601) +// * to time_t (number of seconds since Jan 1 1970) +// */ +// time_t FiletimeToTime(FILETIME const& ft) { +// ULARGE_INTEGER ull; +// ull.LowPart = ft.dwLowDateTime; +// ull.HighPart = ft.dwHighDateTime; + +// // Convert the FILETIME from 100 nanosecond intervals into seconds +// // and then subtract the number of seconds between +// // Jan 1 1601 and Jan 1 1970 + +// const int64 NANOSECOND_INTERVALS = 10000000ULL; +// const int64 SECONDS_FROM_JAN_1_1601_TO_JAN_1_1970 = 11644473600ULL; + +// return ull.QuadPart / NANOSECOND_INTERVALS - SECONDS_FROM_JAN_1_1601_TO_JAN_1_1970; +// } + +int ShowFolderInOSWindow(ExtensionString pathname) +{ + return NO_ERROR; +} + +// int32 ShowFolderInOSWindow(ExtensionString pathname) { +// ShellExecute(NULL, L"open", pathname.c_str(), NULL, NULL, SW_SHOWDEFAULT); +// return NO_ERROR; +// } + diff --git a/appshell/cefclient_gtk.cpp b/appshell/cefclient_gtk.cpp index 0cb4d3940..06888f391 100644 --- a/appshell/cefclient_gtk.cpp +++ b/appshell/cefclient_gtk.cpp @@ -6,22 +6,22 @@ #include #include #include -#include "cefclient/cefclient.h" +#include "cefclient.h" #include "include/cef_app.h" #include "include/cef_browser.h" #include "include/cef_frame.h" #include "include/cef_runnable.h" -#include "cefclient/binding_test.h" -#include "cefclient/client_handler.h" -#include "cefclient/dom_test.h" -#include "cefclient/scheme_test.h" -#include "cefclient/string_util.h" +#include "client_handler.h" +//#include "string_util.h" char szWorkingDir[512]; // The current working directory // The global ClientHandler reference. extern CefRefPtr g_handler; +//Application startup time +time_t g_appStartupTime; + void destroy(void) { CefQuitMessageLoop(); } @@ -30,125 +30,125 @@ void TerminationSignalHandler(int signatl) { destroy(); } -// Callback for Debug > Get Source... menu item. -gboolean GetSourceActivated(GtkWidget* widget) { - if (g_handler.get() && g_handler->GetBrowserId()) - RunGetSourceTest(g_handler->GetBrowser()); +// // Callback for Debug > Get Source... menu item. +// gboolean GetSourceActivated(GtkWidget* widget) { +// if (g_handler.get() && g_handler->GetBrowserId()) +// RunGetSourceTest(g_handler->GetBrowser()); - return FALSE; // Don't stop this message. -} +// return FALSE; // Don't stop this message. +// } -// Callback for Debug > Get Source... menu item. -gboolean GetTextActivated(GtkWidget* widget) { - if (g_handler.get() && g_handler->GetBrowserId()) - RunGetTextTest(g_handler->GetBrowser()); +// // Callback for Debug > Get Source... menu item. +// gboolean GetTextActivated(GtkWidget* widget) { +// if (g_handler.get() && g_handler->GetBrowserId()) +// RunGetTextTest(g_handler->GetBrowser()); - return FALSE; // Don't stop this message. -} +// return FALSE; // Don't stop this message. +// } -// Callback for Debug > Request... menu item. -gboolean RequestActivated(GtkWidget* widget) { - if (g_handler.get() && g_handler->GetBrowserId()) - RunRequestTest(g_handler->GetBrowser()); +// // Callback for Debug > Request... menu item. +// gboolean RequestActivated(GtkWidget* widget) { +// if (g_handler.get() && g_handler->GetBrowserId()) +// RunRequestTest(g_handler->GetBrowser()); - return FALSE; // Don't stop this message. -} +// return FALSE; // Don't stop this message. +// } -// Callback for Debug > Local Storage... menu item. -gboolean LocalStorageActivated(GtkWidget* widget) { - if (g_handler.get() && g_handler->GetBrowserId()) - RunLocalStorageTest(g_handler->GetBrowser()); +// // Callback for Debug > Local Storage... menu item. +// gboolean LocalStorageActivated(GtkWidget* widget) { +// if (g_handler.get() && g_handler->GetBrowserId()) +// RunLocalStorageTest(g_handler->GetBrowser()); - return FALSE; // Don't stop this message. -} +// return FALSE; // Don't stop this message. +// } -// Callback for Debug > XMLHttpRequest... menu item. -gboolean XMLHttpRequestActivated(GtkWidget* widget) { - if (g_handler.get() && g_handler->GetBrowserId()) - RunXMLHTTPRequestTest(g_handler->GetBrowser()); +// // Callback for Debug > XMLHttpRequest... menu item. +// gboolean XMLHttpRequestActivated(GtkWidget* widget) { +// if (g_handler.get() && g_handler->GetBrowserId()) +// RunXMLHTTPRequestTest(g_handler->GetBrowser()); - return FALSE; // Don't stop this message. -} +// return FALSE; // Don't stop this message. +// } -// Callback for Debug > Scheme Handler... menu item. -gboolean SchemeHandlerActivated(GtkWidget* widget) { - if (g_handler.get() && g_handler->GetBrowserId()) - scheme_test::RunTest(g_handler->GetBrowser()); +// // Callback for Debug > Scheme Handler... menu item. +// gboolean SchemeHandlerActivated(GtkWidget* widget) { +// if (g_handler.get() && g_handler->GetBrowserId()) +// scheme_test::RunTest(g_handler->GetBrowser()); - return FALSE; // Don't stop this message. -} +// return FALSE; // Don't stop this message. +// } -// Callback for Debug > JavaScript Binding... menu item. -gboolean BindingActivated(GtkWidget* widget) { - if (g_handler.get() && g_handler->GetBrowserId()) - binding_test::RunTest(g_handler->GetBrowser()); +// // Callback for Debug > JavaScript Binding... menu item. +// gboolean BindingActivated(GtkWidget* widget) { +// if (g_handler.get() && g_handler->GetBrowserId()) +// binding_test::RunTest(g_handler->GetBrowser()); - return FALSE; // Don't stop this message. -} +// return FALSE; // Don't stop this message. +// } -// Callback for Debug > Plugin Info... menu item. -gboolean PluginInfoActivated(GtkWidget* widget) { - if (g_handler.get() && g_handler->GetBrowserId()) - RunPluginInfoTest(g_handler->GetBrowser()); +// // Callback for Debug > Plugin Info... menu item. +// gboolean PluginInfoActivated(GtkWidget* widget) { +// if (g_handler.get() && g_handler->GetBrowserId()) +// RunPluginInfoTest(g_handler->GetBrowser()); - return FALSE; // Don't stop this message. -} +// return FALSE; // Don't stop this message. +// } -// Callback for Debug > DOM Access... menu item. -gboolean DOMAccessActivated(GtkWidget* widget) { - if (g_handler.get() && g_handler->GetBrowserId()) - dom_test::RunTest(g_handler->GetBrowser()); +// // Callback for Debug > DOM Access... menu item. +// gboolean DOMAccessActivated(GtkWidget* widget) { +// if (g_handler.get() && g_handler->GetBrowserId()) +// dom_test::RunTest(g_handler->GetBrowser()); - return FALSE; // Don't stop this message. -} +// return FALSE; // Don't stop this message. +// } -// Callback for Debug > Popup Window... menu item. -gboolean PopupWindowActivated(GtkWidget* widget) { - if (g_handler.get() && g_handler->GetBrowserId()) - RunPopupTest(g_handler->GetBrowser()); +// // Callback for Debug > Popup Window... menu item. +// gboolean PopupWindowActivated(GtkWidget* widget) { +// if (g_handler.get() && g_handler->GetBrowserId()) +// RunPopupTest(g_handler->GetBrowser()); - return FALSE; // Don't stop this message. -} +// return FALSE; // Don't stop this message. +// } -// Callback for Debug > Accelerated 2D Canvas... menu item. -gboolean Accelerated2DCanvasActivated(GtkWidget* widget) { - if (g_handler.get() && g_handler->GetBrowserId()) - RunAccelerated2DCanvasTest(g_handler->GetBrowser()); +// // Callback for Debug > Accelerated 2D Canvas... menu item. +// gboolean Accelerated2DCanvasActivated(GtkWidget* widget) { +// if (g_handler.get() && g_handler->GetBrowserId()) +// RunAccelerated2DCanvasTest(g_handler->GetBrowser()); - return FALSE; // Don't stop this message. -} +// return FALSE; // Don't stop this message. +// } -// Callback for Debug > Accelerated Layers... menu item. -gboolean AcceleratedLayersActivated(GtkWidget* widget) { - if (g_handler.get() && g_handler->GetBrowserId()) - RunAcceleratedLayersTest(g_handler->GetBrowser()); +// // Callback for Debug > Accelerated Layers... menu item. +// gboolean AcceleratedLayersActivated(GtkWidget* widget) { +// if (g_handler.get() && g_handler->GetBrowserId()) +// RunAcceleratedLayersTest(g_handler->GetBrowser()); - return FALSE; // Don't stop this message. -} +// return FALSE; // Don't stop this message. +// } -// Callback for Debug > WebGL... menu item. -gboolean WebGLActivated(GtkWidget* widget) { - if (g_handler.get() && g_handler->GetBrowserId()) - RunWebGLTest(g_handler->GetBrowser()); +// // Callback for Debug > WebGL... menu item. +// gboolean WebGLActivated(GtkWidget* widget) { +// if (g_handler.get() && g_handler->GetBrowserId()) +// RunWebGLTest(g_handler->GetBrowser()); - return FALSE; // Don't stop this message. -} +// return FALSE; // Don't stop this message. +// } -// Callback for Debug > HTML5 Video... menu item. -gboolean HTML5VideoActivated(GtkWidget* widget) { - if (g_handler.get() && g_handler->GetBrowserId()) - RunHTML5VideoTest(g_handler->GetBrowser()); +// // Callback for Debug > HTML5 Video... menu item. +// gboolean HTML5VideoActivated(GtkWidget* widget) { +// if (g_handler.get() && g_handler->GetBrowserId()) +// RunHTML5VideoTest(g_handler->GetBrowser()); - return FALSE; // Don't stop this message. -} +// return FALSE; // Don't stop this message. +// } -// Callback for Debug > HTML5 Drag & Drop... menu item. -gboolean HTML5DragDropActivated(GtkWidget* widget) { - if (g_handler.get() && g_handler->GetBrowserId()) - RunDragDropTest(g_handler->GetBrowser()); +// // Callback for Debug > HTML5 Drag & Drop... menu item. +// gboolean HTML5DragDropActivated(GtkWidget* widget) { +// if (g_handler.get() && g_handler->GetBrowserId()) +// RunDragDropTest(g_handler->GetBrowser()); - return FALSE; // Don't stop this message. -} +// return FALSE; // Don't stop this message. +// } // Callback for when you click the back button. void BackButtonClicked(GtkButton* button) { @@ -205,36 +205,6 @@ GtkWidget* CreateMenuBar() { GtkWidget* menu_bar = gtk_menu_bar_new(); GtkWidget* debug_menu = CreateMenu(menu_bar, "Tests"); - AddMenuEntry(debug_menu, "Get Source", - G_CALLBACK(GetSourceActivated)); - AddMenuEntry(debug_menu, "Get Text", - G_CALLBACK(GetTextActivated)); - AddMenuEntry(debug_menu, "Request", - G_CALLBACK(RequestActivated)); - AddMenuEntry(debug_menu, "Local Storage", - G_CALLBACK(LocalStorageActivated)); - AddMenuEntry(debug_menu, "XMLHttpRequest", - G_CALLBACK(XMLHttpRequestActivated)); - AddMenuEntry(debug_menu, "Scheme Handler", - G_CALLBACK(SchemeHandlerActivated)); - AddMenuEntry(debug_menu, "JavaScript Binding", - G_CALLBACK(BindingActivated)); - AddMenuEntry(debug_menu, "Plugin Info", - G_CALLBACK(PluginInfoActivated)); - AddMenuEntry(debug_menu, "DOM Access", - G_CALLBACK(DOMAccessActivated)); - AddMenuEntry(debug_menu, "Popup Window", - G_CALLBACK(PopupWindowActivated)); - AddMenuEntry(debug_menu, "Accelerated 2D Canvas", - G_CALLBACK(Accelerated2DCanvasActivated)); - AddMenuEntry(debug_menu, "Accelerated Layers", - G_CALLBACK(AcceleratedLayersActivated)); - AddMenuEntry(debug_menu, "WebGL", - G_CALLBACK(WebGLActivated)); - AddMenuEntry(debug_menu, "HTML5 Video", - G_CALLBACK(HTML5VideoActivated)); - AddMenuEntry(debug_menu, "HTML5 Drag & Drop", - G_CALLBACK(HTML5DragDropActivated)); return menu_bar; } @@ -251,6 +221,9 @@ static gboolean HandleFocus(GtkWidget* widget, int main(int argc, char* argv[]) { CefMainArgs main_args(argc, argv); + + g_appStartupTime = time(NULL); + CefRefPtr app(new ClientApp); // Execute the secondary process, if any. @@ -258,6 +231,7 @@ int main(int argc, char* argv[]) { if (exit_code >= 0) return exit_code; + //Retrieve the current working directory if (!getcwd(szWorkingDir, sizeof (szWorkingDir))) return -1; @@ -273,12 +247,14 @@ int main(int argc, char* argv[]) { // Populate the settings based on command line arguments. AppGetSettings(settings, app); + // Check cache_path setting + if (CefString(&settings.cache_path).length() == 0) { + CefString(&settings.cache_path) = AppGetCachePath(); + } + // Initialize CEF. CefInitialize(main_args, settings, app.get()); - // Register the scheme handler. - scheme_test::InitTest(); - window = gtk_window_new(GTK_WINDOW_TOPLEVEL); gtk_window_set_default_size(GTK_WINDOW(window), 800, 600); @@ -370,3 +346,10 @@ int main(int argc, char* argv[]) { std::string AppGetWorkingDirectory() { return szWorkingDir; } + +CefString AppGetCachePath() { + std::string cachePath = ClientApp::AppGetSupportDirectory(); + cachePath.append("/cef_data"); + + return CefString(cachePath); +} \ No newline at end of file diff --git a/appshell/client_app_gtk.cpp b/appshell/client_app_gtk.cpp new file mode 100644 index 000000000..87e36c698 --- /dev/null +++ b/appshell/client_app_gtk.cpp @@ -0,0 +1,73 @@ +/* + * Copyright (c) 2012 Adobe Systems Incorporated. All rights reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + * + */ + +#include "client_app.h" +#include "resource.h" +#include "include/cef_base.h" +#include "config.h" + +#include +//#include +//#include +#include + +extern time_t g_appStartupTime; + +CefString ClientApp::GetCurrentLanguage() +{ + //TODO proper locale in GTK + printf("in GetCurrentLanguage\n"); + return CefString("en"); +} + +std::string ClientApp::GetExtensionJSSource() +{ + //Another bloody TODO here. + printf("in GetExtensionJSSource\n"); + FILE* file = fopen("appshell_extensions.js","r"); + if(file == NULL) + { + return ""; + } + + fseek(file, 0, SEEK_END); + long int size = ftell(file); + rewind(file); + + char* content = (char*)calloc(size + 1, 1); + + fread(content,1,size,file); + + return content; +} + +double ClientApp::GetElapsedMilliseconds() +{ + return (time(NULL) - g_appStartupTime); +} + +CefString ClientApp::AppGetSupportDirectory() +{ + return CefString("/"); +} + diff --git a/appshell/client_handler_gtk.cpp b/appshell/client_handler_gtk.cpp index 2b0036f77..c4f64de54 100644 --- a/appshell/client_handler_gtk.cpp +++ b/appshell/client_handler_gtk.cpp @@ -3,11 +3,15 @@ // can be found in the LICENSE file. #include +#include #include -#include "cefclient/client_handler.h" +#include "client_handler.h" #include "include/cef_browser.h" #include "include/cef_frame.h" +// The global ClientHandler reference. +extern CefRefPtr g_handler; + // ClientHandler::ClientLifeSpanHandler implementation bool ClientHandler::OnBeforePopup(CefRefPtr parentBrowser, const CefPopupFeatures& popupFeatures, @@ -67,9 +71,18 @@ void ClientHandler::SetNavState(bool canGoBack, bool canGoForward) { } void ClientHandler::CloseMainWindow() { - // TODO(port): Close main window. + // TODO(port): Check if this is enough + gtk_main_quit(); +} + +void ClientHandler::PopupCreated(CefRefPtr browser) +{ + // TODO Finish this thing + browser->GetHost()->SetFocus(true); } +//#TODO Implement window handling, e.g.: CloseWindowCallback + bool ClientHandler::CanCloseBrowser(CefRefPtr browser) { return true; } diff --git a/appshell/resource_util_linux.cpp b/appshell/resource_util_linux.cpp index 66b46267d..2d55e62b3 100644 --- a/appshell/resource_util_linux.cpp +++ b/appshell/resource_util_linux.cpp @@ -3,11 +3,11 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include "cefclient/resource_util.h" +#include "resource_util.h" #include #include #include "include/cef_stream.h" -#include "cefclient/util.h" +#include "util.h" bool GetResourceDir(std::string& dir) { char buff[1024];