diff --git a/appshell/appshell_extension_handler.h b/appshell/appshell_extension_handler.h index f36c9e6d6..588f42bbf 100644 --- a/appshell/appshell_extension_handler.h +++ b/appshell/appshell_extension_handler.h @@ -25,6 +25,8 @@ #include "include/cef_process_message.h" #include "include/cef_v8.h" +#include "appshell/appshell_helpers.h" + namespace appshell { // Forward declarations. @@ -161,13 +163,13 @@ class AppShellExtensionHandler : public CefV8Handler { // GetCurrentLanguage(), GetApplicationSupportDirectory(), and GetRemoteDebuggingPort(). // All other messages are passed to the browser process. if (name == "GetElapsedMilliseconds") { - retval = CefV8Value::CreateDouble(client_app_->GetElapsedMilliseconds()); + retval = CefV8Value::CreateDouble(GetElapsedMilliseconds()); } else if (name == "GetCurrentLanguage") { - retval = CefV8Value::CreateString(client_app_->GetCurrentLanguage()); + retval = CefV8Value::CreateString(GetCurrentLanguage()); } else if (name == "GetApplicationSupportDirectory") { - retval = CefV8Value::CreateString(ClientApp::AppGetSupportDirectory()); + retval = CefV8Value::CreateString(AppGetSupportDirectory()); } else if (name == "GetUserDocumentsDirectory") { - retval = CefV8Value::CreateString(ClientApp::AppGetDocumentsDirectory()); + retval = CefV8Value::CreateString(AppGetDocumentsDirectory()); } else if (name == "GetRemoteDebuggingPort") { retval = CefV8Value::CreateInt(REMOTE_DEBUGGING_PORT); } else { diff --git a/appshell/appshell_extensions_gtk.cpp b/appshell/appshell_extensions_gtk.cpp index 904e2d5ca..b1a162c68 100644 --- a/appshell/appshell_extensions_gtk.cpp +++ b/appshell/appshell_extensions_gtk.cpp @@ -23,7 +23,8 @@ #include "appshell_extensions_platform.h" -#include "client_app.h" +#include "appshell/appshell_helpers.h" + #include #include #include @@ -70,7 +71,7 @@ int32 OpenLiveBrowser(ExtensionString argURL, bool enableRemoteDebugging) GError *gerror = NULL; if (enableRemoteDebugging) { - CefString appSupportDirectory = ClientApp::AppGetSupportDirectory(); + CefString appSupportDirectory = appshell::AppGetSupportDirectory(); // TODO: (INGO) to better understand to string conversion issue, I need a consultant // here. Getting the char* from CefString I had to call ToString().c_str() diff --git a/appshell/appshell_extensions_mac.mm b/appshell/appshell_extensions_mac.mm index 62b460762..c1ffb3b88 100644 --- a/appshell/appshell_extensions_mac.mm +++ b/appshell/appshell_extensions_mac.mm @@ -23,7 +23,7 @@ #include "appshell_extensions_platform.h" -#include "client_app.h" +#include "appshell/appshell_helpers.h" #include "native_menu_model.h" #include "GoogleChrome.h" @@ -50,7 +50,7 @@ - (void)timeoutTimer:(NSTimer*)timer; // Live Development browser debug paramaters int const debugPort = 9222; NSString* debugPortCommandlineArguments = [NSString stringWithFormat:@"--remote-debugging-port=%d", debugPort]; -NSString* debugProfilePath = [NSString stringWithFormat:@"--user-data-dir=%s/live-dev-profile", ClientApp::AppGetSupportDirectory().ToString().c_str()]; +NSString* debugProfilePath = [NSString stringWithFormat:@"--user-data-dir=%s/live-dev-profile", appshell::AppGetSupportDirectory().ToString().c_str()]; /////////////////////////////////////////////////////////////////////////////// // LiveBrowserMgrMac diff --git a/appshell/appshell_extensions_win.cpp b/appshell/appshell_extensions_win.cpp index 7bfe616dd..64f4a97c0 100644 --- a/appshell/appshell_extensions_win.cpp +++ b/appshell/appshell_extensions_win.cpp @@ -23,9 +23,8 @@ #include "appshell_extensions_platform.h" -#include "client_app.h" +#include "appshell/appshell_helpers.h" #include "native_menu_model.h" -#include "client_handler.h" #include #include @@ -339,7 +338,7 @@ int32 OpenLiveBrowser(ExtensionString argURL, bool enableRemoteDebugging) std::wstring args = appPath; if (enableRemoteDebugging) { - std::wstring profilePath(ClientApp::AppGetSupportDirectory()); + std::wstring profilePath(appshell::AppGetSupportDirectory()); profilePath += L"\\live-dev-profile"; args += L" --user-data-dir=\""; args += profilePath; diff --git a/appshell/appshell_helpers.h b/appshell/appshell_helpers.h new file mode 100644 index 000000000..1ade3019f --- /dev/null +++ b/appshell/appshell_helpers.h @@ -0,0 +1,48 @@ +/* + * Copyright (c) 2016 - present 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. + */ + +#pragma once + +#include + +#include "include/internal/cef_string.h" + +#include "config.h" + +namespace appshell { + +double GetElapsedMilliseconds(); +CefString GetCurrentLanguage(); +std::string GetExtensionJSSource(); +CefString AppGetSupportDirectory(); +CefString AppGetDocumentsDirectory(); + +// Returns the default CEF cache location +CefString AppGetCachePath(); + +// Returns a string containing the product and version (e.g. "Brackets/0.19.0.0") +CefString AppGetProductVersionString(); + +// Returns a string containing "Chrome/" appends with its version (e.g. "Chrome/29.0.1547.65") +CefString AppGetChromiumVersionString(); + +} // namespace appshell diff --git a/appshell/client_app_gtk.cpp b/appshell/appshell_helpers_gtk.cpp similarity index 83% rename from appshell/client_app_gtk.cpp rename to appshell/appshell_helpers_gtk.cpp index 381504021..06856b8e0 100644 --- a/appshell/client_app_gtk.cpp +++ b/appshell/appshell_helpers_gtk.cpp @@ -21,24 +21,25 @@ * */ -#include "client_app.h" +#include "appshell/appshell_helpers.h" #include "appshell/browser/resource.h" #include "include/cef_base.h" -#include "config.h" +#include "include/cef_version.h" #include #include #include //#include //#include -#include #include extern time_t g_appStartupTime; extern char _binary_appshell_appshell_extensions_js_start; -CefString ClientApp::GetCurrentLanguage() +namespace appshell { + +CefString GetCurrentLanguage() { const char* locconst = pango_language_to_string( gtk_get_default_language() ); //Rado: for me it prints "en-us", so I have to strip everything after the "-" @@ -51,7 +52,7 @@ CefString ClientApp::GetCurrentLanguage() return CefString(loc); } -std::string ClientApp::GetExtensionJSSource() +std::string GetExtensionJSSource() { //# We objcopy the appshell/appshell_extensions.js file, and link it directly into the binary. //# See http://www.linuxjournal.com/content/embedding-file-executable-aka-hello-world-version-5967 @@ -76,21 +77,21 @@ std::string ClientApp::GetExtensionJSSource() return content; } -double ClientApp::GetElapsedMilliseconds() +double GetElapsedMilliseconds() { return (time(NULL) - g_appStartupTime); } -CefString ClientApp::AppGetSupportDirectory() +CefString AppGetSupportDirectory() { gchar *supportDir = g_strdup_printf("%s/%s", g_get_user_config_dir(), APP_NAME); CefString result = CefString(supportDir); g_free(supportDir); - + return result; } -CefString ClientApp::AppGetDocumentsDirectory() +CefString AppGetDocumentsDirectory() { const char *dir = g_get_user_special_dir(G_USER_DIRECTORY_DOCUMENTS); if (dir == NULL) { @@ -98,4 +99,22 @@ CefString ClientApp::AppGetDocumentsDirectory() } else { return CefString(dir); } -} \ No newline at end of file +} + +CefString AppGetCachePath() { + std::string cachePath = std::string(AppGetSupportDirectory()) + "/cef_data"; + + return CefString(cachePath); +} + +CefString AppGetProductVersionString() { + // TODO + return CefString(""); +} + +CefString AppGetChromiumVersionString() { + // TODO + return CefString(""); +} + +} // namespace appshell diff --git a/appshell/client_app_mac.mm b/appshell/appshell_helpers_mac.mm similarity index 66% rename from appshell/client_app_mac.mm rename to appshell/appshell_helpers_mac.mm index 427e041d2..b47a1b1dd 100644 --- a/appshell/client_app_mac.mm +++ b/appshell/appshell_helpers_mac.mm @@ -21,24 +21,25 @@ * */ -#include "client_app.h" +#include "appshell/appshell_helpers.h" #include "include/cef_base.h" +#include "include/cef_version.h" #include "config.h" #include -#include - extern CFTimeInterval g_appStartupTime; -double ClientApp::GetElapsedMilliseconds() +namespace appshell { + +double GetElapsedMilliseconds() { CFAbsoluteTime elapsed = CFAbsoluteTimeGetCurrent() - g_appStartupTime; - + return round(elapsed * 1000); } -CefString ClientApp::GetCurrentLanguage() +CefString GetCurrentLanguage() { // Do not confuse preferredLanguages with currentLocale. // preferredLanguages specifies to UI language. currentLocale @@ -49,24 +50,24 @@ // default on US systems. // NSLog(@"localeIdentifier: %@", [[NSLocale currentLocale] localeIdentifier]); // NSLog(@"%@", language); - + NSString* language = [[NSLocale preferredLanguages] objectAtIndex:0]; - + CefString result = [language UTF8String]; return result; } -std::string ClientApp::GetExtensionJSSource() +std::string GetExtensionJSSource() { std::string result; - + // This is a hack to grab the extension file from the main app resource bundle. // This code may be run in a sub process in an app that is bundled inside the main app. #if 1 NSString* bundlePath = [[NSBundle mainBundle] bundlePath]; NSString* sourcePath; NSRange range = [bundlePath rangeOfString: @"/Frameworks/"]; - + if (range.location == NSNotFound) { sourcePath = [[NSBundle mainBundle] pathForResource: @"appshell_extensions" ofType: @"js"]; } else { @@ -76,23 +77,51 @@ #else NSString* sourcePath = [[NSBundle mainBundle] pathForResource: @"appshell_extensions" ofType: @"js"]; #endif - + NSString* jsSource = [[NSString alloc] initWithContentsOfFile:sourcePath encoding:NSUTF8StringEncoding error:nil]; result = [jsSource UTF8String]; [jsSource release]; - + return result; } +CefString AppGetSupportDirectory() { + NSString *libraryDirectory = [NSSearchPathForDirectoriesInDomains(NSApplicationSupportDirectory, NSUserDomainMask, YES) objectAtIndex:0]; + NSString *supportDirectory = [NSString stringWithFormat:@"%@/%@%@", libraryDirectory, GROUP_NAME, APP_NAME]; -CefString ClientApp::AppGetSupportDirectory() { - NSString *libraryDirectory = [NSSearchPathForDirectoriesInDomains(NSApplicationSupportDirectory, NSUserDomainMask, YES) objectAtIndex:0]; - NSString *supportDirectory = [NSString stringWithFormat:@"%@/%@%@", libraryDirectory, GROUP_NAME, APP_NAME]; - - return CefString([supportDirectory UTF8String]); + return CefString([supportDirectory UTF8String]); } -CefString ClientApp::AppGetDocumentsDirectory() { +CefString AppGetDocumentsDirectory() { NSString *documentsDirectory = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0]; return CefString([documentsDirectory UTF8String]); } + +CefString AppGetCachePath() { + std::string cachePath = std::string(AppGetSupportDirectory()) + "/cef_data"; + + return CefString(cachePath); +} + +CefString AppGetProductVersionString() { + NSMutableString *s = [NSMutableString stringWithString:APP_NAME]; + [s replaceOccurrencesOfString:@" " + withString:@"" + options:NSLiteralSearch + range:NSMakeRange(0, [s length])]; + [s appendString:@"/"]; + [s appendString:(NSString*)[[NSBundle mainBundle] + objectForInfoDictionaryKey:(NSString *)kCFBundleVersionKey]]; + CefString result = CefString([s UTF8String]); + return result; +} + +CefString AppGetChromiumVersionString() { + NSMutableString *s = [NSMutableString stringWithFormat:@"Chrome/%d.%d.%d.%d", + cef_version_info(2), cef_version_info(3), + cef_version_info(4), cef_version_info(5)]; + CefString result = CefString([s UTF8String]); + return result; +} + +} // namespace appshell diff --git a/appshell/appshell_helpers_win.cpp b/appshell/appshell_helpers_win.cpp new file mode 100644 index 000000000..e916faef7 --- /dev/null +++ b/appshell/appshell_helpers_win.cpp @@ -0,0 +1,189 @@ +/* + * Copyright (c) 2012 - present 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 "appshell/appshell_helpers.h" + +#include "appshell/browser/resource.h" +#include "include/cef_base.h" +#include "include/cef_version.h" + +#include +#include +#include + +extern DWORD g_appStartupTime; +extern HINSTANCE hInst; + +namespace appshell { + +CefString GetCurrentLanguage() +{ + // Get the user's selected language + // Defaults to the system installed language if not using MUI. + LANGID langID = GetUserDefaultUILanguage(); + + // Convert LANGID to a RFC 4646 language tag (per navigator.language) + int langSize = GetLocaleInfo(langID, LOCALE_SISO639LANGNAME, NULL, 0); + int countrySize = GetLocaleInfo(langID, LOCALE_SISO3166CTRYNAME, NULL, 0); + + wchar_t *lang = new wchar_t[langSize + countrySize + 1]; + wchar_t *country = new wchar_t[countrySize]; + + GetLocaleInfo(langID, LOCALE_SISO639LANGNAME, lang, langSize); + GetLocaleInfo(langID, LOCALE_SISO3166CTRYNAME, country, countrySize); + + // add hyphen + wcscat(wcscat(lang, L"-"), country); + std::wstring locale(lang); + + delete [] lang; + delete [] country; + + return CefString(locale); +} + +std::string GetExtensionJSSource() +{ + HRSRC hRes = FindResource(hInst, MAKEINTRESOURCE(IDS_APPSHELL_EXTENSIONS), MAKEINTRESOURCE(256)); + DWORD dwSize; + LPBYTE pBytes = NULL; + + if(hRes) + { + HGLOBAL hGlob = LoadResource(hInst, hRes); + if(hGlob) + { + dwSize = SizeofResource(hInst, hRes); + pBytes = (LPBYTE)LockResource(hGlob); + } + } + + if (pBytes) { + std::string result((const char *)pBytes, dwSize); + return result; + } + + return ""; +} + +double GetElapsedMilliseconds() +{ + return (timeGetTime() - g_appStartupTime); +} + +CefString AppGetSupportDirectory() +{ + wchar_t dataPath[MAX_UNC_PATH]; + SHGetFolderPath(NULL, CSIDL_APPDATA, NULL, SHGFP_TYPE_CURRENT, dataPath); + + std::wstring appSupportPath = dataPath; + appSupportPath += L"\\" GROUP_NAME APP_NAME; + + // Convert '\\' to '/' + replace(appSupportPath.begin(), appSupportPath.end(), '\\', '/'); + + return CefString(appSupportPath); +} + +CefString AppGetDocumentsDirectory() +{ + wchar_t dataPath[MAX_UNC_PATH] = {0}; + SHGetFolderPath(NULL, CSIDL_MYDOCUMENTS, NULL, SHGFP_TYPE_CURRENT, dataPath); + std::wstring appUserDocuments = dataPath; + + // Convert '\\' to '/' + replace(appUserDocuments.begin(), appUserDocuments.end(), '\\', '/'); + + return CefString(appUserDocuments); +} + +CefString AppGetCachePath() { + std::wstring cachePath = AppGetSupportDirectory(); + cachePath += L"/cef_data"; + + return CefString(cachePath); +} +// Helper function for AppGetProductVersionString. Reads version info from +// VERSIONINFO and writes it into the passed in std::wstring. +void GetFileVersionString(std::wstring &retVersion) { + DWORD dwSize = 0; + BYTE *pVersionInfo = NULL; + VS_FIXEDFILEINFO *pFileInfo = NULL; + UINT pLenFileInfo = 0; + + HMODULE module = GetModuleHandle(NULL); + TCHAR executablePath[MAX_UNC_PATH]; + GetModuleFileName(module, executablePath, MAX_UNC_PATH); + + dwSize = GetFileVersionInfoSize(executablePath, NULL); + if (dwSize == 0) { + return; + } + + pVersionInfo = new BYTE[dwSize]; + + if (!GetFileVersionInfo(executablePath, 0, dwSize, pVersionInfo)) { + delete[] pVersionInfo; + return; + } + + if (!VerQueryValue(pVersionInfo, TEXT("\\"), (LPVOID*) &pFileInfo, &pLenFileInfo)) { + delete[] pVersionInfo; + return; + } + + int major = (pFileInfo->dwFileVersionMS >> 16) & 0xffff ; + int minor = (pFileInfo->dwFileVersionMS) & 0xffff; + int hotfix = (pFileInfo->dwFileVersionLS >> 16) & 0xffff; + int other = (pFileInfo->dwFileVersionLS) & 0xffff; + + delete[] pVersionInfo; + + std::wostringstream versionStream(L""); + versionStream << major << L"." << minor << L"." << hotfix << L"." << other; + retVersion = versionStream.str(); +} + +CefString AppGetProductVersionString() { + std::wstring s(APP_NAME); + size_t i = s.find(L" "); + while (i != std::wstring::npos) { + s.erase(i, 1); + i = s.find(L" "); + } + std::wstring version(L""); + GetFileVersionString(version); + s.append(L"/"); + s.append(version); + return CefString(s); +} + +CefString AppGetChromiumVersionString() { + std::wostringstream versionStream(L""); + versionStream << L"Chrome/" << cef_version_info(2) << L"." << cef_version_info(3) + << L"." << cef_version_info(4) << L"." << cef_version_info(5); + + return CefString(versionStream.str()); +} + +} // namespace appshell diff --git a/appshell/cefclient.cpp b/appshell/cefclient.cpp index 42c55ceee..3127fb77d 100644 --- a/appshell/cefclient.cpp +++ b/appshell/cefclient.cpp @@ -16,6 +16,7 @@ #include "include/base/cef_logging.h" #include "client_handler.h" #include "appshell/common/client_switches.h" +#include "appshell/appshell_helpers.h" #include "config.h" CefRefPtr g_handler; @@ -87,7 +88,7 @@ void AppGetSettings(CefSettings& settings, CefRefPtr app) { // Don't update the settings.locale with the locale that we detected from the OS. // Otherwise, CEF will use it to find the resources and when it fails in finding resources // for some locales that are not available in resources, it crashes. - //CefString(&settings.locale) = app->GetCurrentLanguage( ); + //CefString(&settings.locale) = appshell::GetCurrentLanguage( ); CefString(&settings.javascript_flags) = g_command_line->GetSwitchValue(client::switches::kJavascriptFlags); @@ -95,14 +96,14 @@ void AppGetSettings(CefSettings& settings, CefRefPtr app) { // Enable dev tools settings.remote_debugging_port = REMOTE_DEBUGGING_PORT; - std::wstring versionStr = AppGetProductVersionString(); + std::wstring versionStr = appshell::AppGetProductVersionString(); if (!versionStr.empty()) { // Explicitly append the Chromium version to our own product version string // since assigning product version always replaces the Chromium version in // the User Agent string. versionStr.append(L" "); - versionStr.append(AppGetChromiumVersionString()); + versionStr.append(appshell::AppGetChromiumVersionString()); // Set product version, which gets added to the User Agent string CefString(&settings.product_version) = versionStr; diff --git a/appshell/cefclient.h b/appshell/cefclient.h index 67120d066..5cf80477c 100644 --- a/appshell/cefclient.h +++ b/appshell/cefclient.h @@ -26,16 +26,6 @@ std::string AppGetWorkingDirectory(); // Returns the starting URL CefString AppGetInitialURL(); - -// Returns the default CEF cache location -CefString AppGetCachePath(); - -// Returns a string containing the product and version (e.g. "Brackets/0.19.0.0") -CefString AppGetProductVersionString(); - -// Returns a string containing "Chrome/" appends with its version (e.g. "Chrome/29.0.1547.65") -CefString AppGetChromiumVersionString(); - // Initialize the application command line. void AppInitCommandLine(int argc, const char* const* argv); diff --git a/appshell/cefclient_gtk.cc b/appshell/cefclient_gtk.cc index 3ea5a1470..16510956d 100644 --- a/appshell/cefclient_gtk.cc +++ b/appshell/cefclient_gtk.cc @@ -16,6 +16,7 @@ #include "include/cef_runnable.h" #include "client_handler.h" #include "appshell/common/client_switches.h" +#include "appshell/appshell_helpers.h" #include "appshell_node_process.h" static std::string APPICONS[] = {"appshell32.png","appshell48.png","appshell128.png","appshell256.png"}; @@ -111,12 +112,6 @@ std::string AppGetRunningDirectory() { } } -CefString AppGetCachePath() { - std::string cachePath = std::string(ClientApp::AppGetSupportDirectory()) + "/cef_data"; - - return CefString(cachePath); -} - GtkWidget* AddMenuEntry(GtkWidget* menu_widget, const char* text, GCallback callback) { GtkWidget* entry = gtk_menu_item_new_with_label(text); @@ -169,7 +164,7 @@ int main(int argc, char* argv[]) { // Check cache_path setting if (CefString(&settings.cache_path).length() == 0) { - CefString(&settings.cache_path) = AppGetCachePath(); + CefString(&settings.cache_path) = appshell::AppGetCachePath(); } CefRefPtr cmdLine = AppGetCommandLine(); @@ -271,13 +266,3 @@ int main(int argc, char* argv[]) { return 0; } - -CefString AppGetProductVersionString() { - // TODO - return CefString(""); -} - -CefString AppGetChromiumVersionString() { - // TODO - return CefString(""); -} diff --git a/appshell/cefclient_mac.mm b/appshell/cefclient_mac.mm index 3d8ae5f30..43797cc1b 100644 --- a/appshell/cefclient_mac.mm +++ b/appshell/cefclient_mac.mm @@ -18,6 +18,7 @@ #include "config.h" #include "command_callbacks.h" #include "appshell/common/client_switches.h" +#include "appshell/appshell_helpers.h" #include "native_menu_model.h" #include "appshell_node_process.h" @@ -840,7 +841,7 @@ int main(int argc, char* argv[]) { // Check command if (CefString(&settings.cache_path).length() == 0) { - CefString(&settings.cache_path) = AppGetCachePath(); + CefString(&settings.cache_path) = appshell::AppGetCachePath(); } // Initialize CEF. @@ -919,30 +920,3 @@ int main(int argc, char* argv[]) { std::string AppGetWorkingDirectory() { return szWorkingDir; } - -CefString AppGetCachePath() { - std::string cachePath = std::string(ClientApp::AppGetSupportDirectory()) + "/cef_data"; - - return CefString(cachePath); -} - -CefString AppGetProductVersionString() { - NSMutableString *s = [NSMutableString stringWithString:APP_NAME]; - [s replaceOccurrencesOfString:@" " - withString:@"" - options:NSLiteralSearch - range:NSMakeRange(0, [s length])]; - [s appendString:@"/"]; - [s appendString:(NSString*)[[NSBundle mainBundle] - objectForInfoDictionaryKey:(NSString *)kCFBundleVersionKey]]; - CefString result = CefString([s UTF8String]); - return result; -} - -CefString AppGetChromiumVersionString() { - NSMutableString *s = [NSMutableString stringWithFormat:@"Chrome/%d.%d.%d.%d", - cef_version_info(2), cef_version_info(3), - cef_version_info(4), cef_version_info(5)]; - CefString result = CefString([s UTF8String]); - return result; -} diff --git a/appshell/cefclient_win.cpp b/appshell/cefclient_win.cpp index 2df5fe01b..b3ee4b988 100644 --- a/appshell/cefclient_win.cpp +++ b/appshell/cefclient_win.cpp @@ -18,6 +18,7 @@ #include "config.h" #include "appshell/browser/resource.h" #include "appshell/common/client_switches.h" +#include "appshell/appshell_helpers.h" #include "native_menu_model.h" #include "appshell_node_process.h" @@ -232,7 +233,7 @@ int APIENTRY wWinMain(HINSTANCE hInstance, // Check command if (CefString(&settings.cache_path).length() == 0) { - CefString(&settings.cache_path) = AppGetCachePath(); + CefString(&settings.cache_path) = appshell::AppGetCachePath(); } // Initialize CEF. @@ -354,76 +355,6 @@ std::string AppGetWorkingDirectory() { return szWorkingDir; } -CefString AppGetCachePath() { - std::wstring cachePath = ClientApp::AppGetSupportDirectory(); - cachePath += L"/cef_data"; - - return CefString(cachePath); -} - CefString AppGetInitialURL() { return szInitialUrl; } - -// Helper function for AppGetProductVersionString. Reads version info from -// VERSIONINFO and writes it into the passed in std::wstring. -void GetFileVersionString(std::wstring &retVersion) { - DWORD dwSize = 0; - BYTE *pVersionInfo = NULL; - VS_FIXEDFILEINFO *pFileInfo = NULL; - UINT pLenFileInfo = 0; - - HMODULE module = GetModuleHandle(NULL); - TCHAR executablePath[MAX_UNC_PATH]; - GetModuleFileName(module, executablePath, MAX_UNC_PATH); - - dwSize = GetFileVersionInfoSize(executablePath, NULL); - if (dwSize == 0) { - return; - } - - pVersionInfo = new BYTE[dwSize]; - - if (!GetFileVersionInfo(executablePath, 0, dwSize, pVersionInfo)) { - delete[] pVersionInfo; - return; - } - - if (!VerQueryValue(pVersionInfo, TEXT("\\"), (LPVOID*) &pFileInfo, &pLenFileInfo)) { - delete[] pVersionInfo; - return; - } - - int major = (pFileInfo->dwFileVersionMS >> 16) & 0xffff ; - int minor = (pFileInfo->dwFileVersionMS) & 0xffff; - int hotfix = (pFileInfo->dwFileVersionLS >> 16) & 0xffff; - int other = (pFileInfo->dwFileVersionLS) & 0xffff; - - delete[] pVersionInfo; - - std::wostringstream versionStream(L""); - versionStream << major << L"." << minor << L"." << hotfix << L"." << other; - retVersion = versionStream.str(); -} - -CefString AppGetProductVersionString() { - std::wstring s(APP_NAME); - size_t i = s.find(L" "); - while (i != std::wstring::npos) { - s.erase(i, 1); - i = s.find(L" "); - } - std::wstring version(L""); - GetFileVersionString(version); - s.append(L"/"); - s.append(version); - return CefString(s); -} - -CefString AppGetChromiumVersionString() { - std::wostringstream versionStream(L""); - versionStream << L"Chrome/" << cef_version_info(2) << L"." << cef_version_info(3) - << L"." << cef_version_info(4) << L"." << cef_version_info(5); - - return CefString(versionStream.str()); -} diff --git a/appshell/client_app.cpp b/appshell/client_app.cpp index c553cfd3a..828ac8084 100644 --- a/appshell/client_app.cpp +++ b/appshell/client_app.cpp @@ -14,6 +14,7 @@ #include "include/base/cef_logging.h" #include "config.h" #include "appshell/appshell_extension_handler.h" +#include "appshell/appshell_helpers.h" ClientApp::ClientApp() { CreateRenderDelegates(render_delegates_); @@ -21,7 +22,7 @@ ClientApp::ClientApp() { void ClientApp::OnWebKitInitialized() { // Register the appshell extension. - std::string extension_code = GetExtensionJSSource(); + std::string extension_code = appshell::GetExtensionJSSource(); CefRegisterExtension("appshell", extension_code, new appshell::AppShellExtensionHandler(this)); diff --git a/appshell/client_app.h b/appshell/client_app.h index 3388211fc..f1a64940c 100644 --- a/appshell/client_app.h +++ b/appshell/client_app.h @@ -87,13 +87,6 @@ class ClientApp : public CefApp, callback_map_[id] = std::make_pair(context, callbackFunction); } - // Platform-specific methods implemented in client_app_mac/client_app_win - double GetElapsedMilliseconds(); - CefString GetCurrentLanguage(); - std::string GetExtensionJSSource(); - static CefString AppGetSupportDirectory(); - static CefString AppGetDocumentsDirectory(); - private: // Creates all of the RenderDelegate objects. Implemented in // client_app_delegates. diff --git a/appshell/client_app_win.cpp b/appshell/client_app_win.cpp deleted file mode 100644 index b2836f6b5..000000000 --- a/appshell/client_app_win.cpp +++ /dev/null @@ -1,119 +0,0 @@ -/* - * Copyright (c) 2012 - present 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 "appshell/browser/resource.h" -#include "include/cef_base.h" -#include "config.h" - -#include -#include -#include -#include - -extern DWORD g_appStartupTime; - -CefString ClientApp::GetCurrentLanguage() -{ - // Get the user's selected language - // Defaults to the system installed language if not using MUI. - LANGID langID = GetUserDefaultUILanguage(); - - // Convert LANGID to a RFC 4646 language tag (per navigator.language) - int langSize = GetLocaleInfo(langID, LOCALE_SISO639LANGNAME, NULL, 0); - int countrySize = GetLocaleInfo(langID, LOCALE_SISO3166CTRYNAME, NULL, 0); - - wchar_t *lang = new wchar_t[langSize + countrySize + 1]; - wchar_t *country = new wchar_t[countrySize]; - - GetLocaleInfo(langID, LOCALE_SISO639LANGNAME, lang, langSize); - GetLocaleInfo(langID, LOCALE_SISO3166CTRYNAME, country, countrySize); - - // add hyphen - wcscat(wcscat(lang, L"-"), country); - std::wstring locale(lang); - - delete [] lang; - delete [] country; - - return CefString(locale); -} - -std::string ClientApp::GetExtensionJSSource() -{ - extern HINSTANCE hInst; - - HRSRC hRes = FindResource(hInst, MAKEINTRESOURCE(IDS_APPSHELL_EXTENSIONS), MAKEINTRESOURCE(256)); - DWORD dwSize; - LPBYTE pBytes = NULL; - - if(hRes) - { - HGLOBAL hGlob = LoadResource(hInst, hRes); - if(hGlob) - { - dwSize = SizeofResource(hInst, hRes); - pBytes = (LPBYTE)LockResource(hGlob); - } - } - - if (pBytes) { - std::string result((const char *)pBytes, dwSize); - return result; - } - - return ""; -} - -double ClientApp::GetElapsedMilliseconds() -{ - return (timeGetTime() - g_appStartupTime); -} - -CefString ClientApp::AppGetSupportDirectory() -{ - wchar_t dataPath[MAX_UNC_PATH]; - SHGetFolderPath(NULL, CSIDL_APPDATA, NULL, SHGFP_TYPE_CURRENT, dataPath); - - std::wstring appSupportPath = dataPath; - appSupportPath += L"\\" GROUP_NAME APP_NAME; - - // Convert '\\' to '/' - replace(appSupportPath.begin(), appSupportPath.end(), '\\', '/'); - - return CefString(appSupportPath); -} - - -CefString ClientApp::AppGetDocumentsDirectory() -{ - wchar_t dataPath[MAX_UNC_PATH] = {0}; - SHGetFolderPath(NULL, CSIDL_MYDOCUMENTS, NULL, SHGFP_TYPE_CURRENT, dataPath); - std::wstring appUserDocuments = dataPath; - - // Convert '\\' to '/' - replace(appUserDocuments.begin(), appUserDocuments.end(), '\\', '/'); - - return CefString(appUserDocuments); -} diff --git a/appshell_paths.gypi b/appshell_paths.gypi index ed5d1ee31..8655ec194 100755 --- a/appshell_paths.gypi +++ b/appshell_paths.gypi @@ -182,6 +182,7 @@ 'appshell/appshell_extensions.h', 'appshell/appshell_extensions_platform.h', 'appshell/appshell_extensions.js', + 'appshell/appshell_helpers.h', 'appshell/appshell_node_process.h', 'appshell/appshell_node_process_internal.h', 'appshell/appshell_node_process.cpp', @@ -225,7 +226,7 @@ 'appshell/cefclient.rc', 'appshell/version.rc', 'appshell/cefclient_win.cpp', - 'appshell/client_app_win.cpp', + 'appshell/appshell_helpers_win.cpp', 'appshell/client_handler_win.cpp', 'appshell/res/appshell.ico', 'appshell/cef_buffered_dc.h', @@ -280,7 +281,7 @@ 'appshell/FullScreenViewController.mm', 'appshell/appshell_extensions_mac.mm', 'appshell/appshell_node_process_mac.mm', - 'appshell/client_app_mac.mm', + 'appshell/appshell_helpers_mac.mm', 'appshell/cefclient_mac.mm', 'appshell/client_handler_mac.mm', '<@(appshell_sources_browser)', @@ -303,7 +304,7 @@ 'appshell/FullScreenViewController.mm', 'appshell/appshell_extensions_mac.mm', 'appshell/appshell_node_process_mac.mm', - 'appshell/client_app_mac.mm', + 'appshell/appshell_helpers_mac.mm', 'appshell/client_handler_mac.mm', 'appshell/process_helper_mac.cpp', '<@(appshell_sources_common_helper)', @@ -383,7 +384,7 @@ 'appshell/appshell_extensions_gtk.cpp', 'appshell/appshell_node_process_linux.cpp', - 'appshell/client_app_gtk.cpp', + 'appshell/appshell_helpers_gtk.cpp', 'appshell/client_handler_gtk.cpp', '<@(appshell_sources_browser)',