void AsinbowAPI::executeCommandWork(const std::string& command, const FB::JSObjectPtr& callback) { char buf[4096]; FILE* pipe = popen( #ifdef _WIN32 utf8_to_ansi(command).c_str(), #else command.c_str(), #endif "r"); if (!pipe) { callback->Invoke("", FB::variant_list_of(true)("popen failed!")); return; } std::string result; int c; while ((c = fgetc(pipe)) != EOF) { result += (char)c; if (c=='\n') { #ifdef _WIN32 result = ansi_to_utf8(result); #endif callback->Invoke("", FB::variant_list_of(false)(result)); result = ""; } } pclose(pipe); callback->Invoke("", FB::variant_list_of(true)); }
int FB::BrowserHost::delayedInvoke(const int delayms, const FB::JSObjectPtr& func, const FB::VariantList& args, const std::string& fname) { assertMainThread(); FB::JSObjectPtr delegate = getDelayedInvokeDelegate(); assert(delegate); if (fname.empty()) return delegate->Invoke("", FB::variant_list_of(delayms)(func)(args)).convert_cast<int>(); else return delegate->Invoke("", FB::variant_list_of(delayms)(func)(args)(fname)).convert_cast<int>(); }
int FB::BrowserHost::delayedInvoke(const int delayms, const FB::JSObjectPtr& func, const FB::VariantList& args, const std::string& fname) { assertMainThread(); FB::JSObjectPtr delegate = getDelayedInvokeDelegate(); if (!delegate) return -1; // this is wrong (the return is meant to be the result of setTimeout) if (fname.empty()) return delegate->Invoke("", FB::variant_list_of(delayms)(func)(args)).convert_cast<int>(); else return delegate->Invoke("", FB::variant_list_of(delayms)(func)(args)(fname)).convert_cast<int>(); }
bool OfficeDriveAPI::callbackTest(FB::JSObjectPtr callback) { callback->Invoke("", FB::variant_list_of("")); m_host->htmlLog("callbackTest success"); return true; }
void OfficeDriveAPI::cupdateDaemon(FB::JSObjectPtr callback) { /*FB::PluginEventSinkPtr eventSinkPtr; boost::optional<std::string> codeBase = getPlugin()->getParam("codeBase"); std::string codeBaseUrl = "None"; if (codeBase) { codeBaseUrl = *codeBase; } */ intptr_t ret = -1; char exePath[512]; memset(&exePath, 0, sizeof(exePath)); char * appData; #ifdef FB_WIN appData = getenv("LOCALAPPDATA"); sprintf(exePath, "%s\\OfficeDrive\\dist\Update.exe", appData); const char *localName[] = {exePath}; char* const localArgs[] = {exePath, NULL}; ret = _spawnv(_P_WAIT, localName[0], localArgs); #endif callback->Invoke("",FB::variant_list_of(ret)); }
void FB::BrowserHost::AsyncHtmlLog(void *logReq) { FB::AsyncLogRequest *req = (FB::AsyncLogRequest*)logReq; try { FB::DOM::WindowPtr window = req->m_host->getDOMWindow(); if (window->getJSObject()->HasProperty("console")) { FB::JSObjectPtr obj = window->getProperty<FB::JSObjectPtr>("console"); printf("Logging: %s\n", req->m_msg.c_str()); obj->Invoke("log", FB::variant_list_of(req->m_msg)); } } catch (const std::exception &) { // printf("Exception: %s\n", e.what()); // Fail silently; logging should not require success. FBLOG_TRACE("BrowserHost", "Logging to browser console failed"); return; } delete req; }
std::string Convert::stringify(const FB::BrowserHostPtr& host, const FB::JSObjectPtr& object) { if(host == NULL) throw DatabaseException("Browser host was null.", DatabaseException::NOT_FOUND_ERR); else if(!host->getDOMWindow()->getProperty<FB::variant>("JSON").is_of_type<FB::JSObjectPtr>()) throw DatabaseException("Could not cast window.JSON to type object.", DatabaseException::UNKNOWN_ERR); FB::JSObjectPtr json = host->getDOMWindow()->getProperty<FB::JSObjectPtr>("JSON"); if(json == NULL) throw DatabaseException("window.JSON support not available.", DatabaseException::NOT_FOUND_ERR); else if(json->HasMethod("stringify")) { FB::VariantList arguments(1, object); FB::variant result = json->Invoke("stringify", arguments); if(result.empty()) throw DatabaseException("JSON Stringification failed.", DatabaseException::RECOVERABLE_ERR); else return result.cast<std::string>(); } else throw DatabaseException("window.JSON missing method stringify().", DatabaseException::NOT_FOUND_ERR); }
void OfficeDriveAPI::updateDaemonCallback(const FB::JSObjectPtr& callback, bool success, const FB::HeaderMap& headers, const boost::shared_array<uint8_t>& data, const size_t size) { int ret = -1; if (success) { std::string dstr(reinterpret_cast<const char*>(data.get()), size); // m_host->htmlLog(std::string(headers)); m_host->htmlLog("Downloading new OfficeDriveClient.jar"); char jarFile[512]; memset(&jarFile, 0, sizeof(jarFile)); char * appData; #ifdef FB_WIN appData = getenv("LOCALAPPDATA"); sprintf(jarFile, "%s\\OfficeDrive\\OfficeDriveClient.jar", appData); #endif #ifdef FB_MACOSX appData = getenv("HOME"); sprintf(jarFile, "%s/LocalAppData/OfficeDrive/OfficeDriveClient.jar", appData); /* char launchAgent[512]; char launchAgent_src[512]; memset(&launchAgent, 0, sizeof(launchAgent)); memset(&launchAgent, 0, sizeof(launchAgent_src)); sprintf(launchAgent, "%s/Library/LaunchAgents/net.officedrive.agent.plist", appData); sprintf(launchAgent, "%s/LocalAppData/OfficeDrive/net.officedrive.agent.plist", appData); boost::filesystem::fstream xml_file_in(launchAgent_src ,std::ios::in); boost::filesystem::fstream xml_file_out(launchAgent ,std::ios::out); xml_file_out.write(reinterpret_cast<const char*>(xml_file_in.get()), sizeof(xml_file_in)); xml_file_out.close(); xml_file_in.close(); */ #endif boost::filesystem::fstream binary_file(jarFile ,std::ios::out|std::ios::binary); binary_file.write(reinterpret_cast<const char*>(data.get()), size); binary_file.close(); m_host->htmlLog("Finished downloading: " + std::string(jarFile)); ret = size; callback->Invoke("",FB::variant_list_of(ret)); //#ifdef FB_MACOSX // <key>LimitLoadToSessionType</key> // <string>Aqua</string> // <key>ProgramArguments</key> // <array> // <string>/usr/bin/java</string> // <string>-jar</string> // <string>LocalAppData/OfficeDrive/OfficeDriveClient.jar</string> // </array> // <key>RunAtLoad</key> // <true/> // <key>StartInterval</key> // <integer>1337</integer> // <key>StandardErrorPath</key> // <string>OfficeDriveClient.stderr.log</string> // <key>StandardOutPath</key> // <string>OfficeDriveClient.stdout.log</string> //</dict> //</plist> //#endif // } else { callback->Invoke("",FB::variant_list_of(ret)); // The request could not be completed } }
void OfficeDriveAPI::fileSelectCallback(const std::string &path, FB::JSObjectPtr callback) { callback->Invoke("",FB::variant_list_of(path)); selectedPath = path; m_host->htmlLog(selectedPath); }