From 6710571576aefd008be46cff803c6bd627aec5d2 Mon Sep 17 00:00:00 2001 From: ficristo Date: Sat, 1 Oct 2016 17:15:45 +0200 Subject: [PATCH 1/2] Renamed client_app_ to appshell_helpers_ --- appshell/appshell_extension_handler.h | 10 +-- appshell/appshell_extensions_gtk.cpp | 5 +- appshell/appshell_extensions_mac.mm | 4 +- appshell/appshell_extensions_win.cpp | 5 +- appshell/appshell_helpers.h | 42 ++++++++++++ ...t_app_gtk.cpp => appshell_helpers_gtk.cpp} | 28 +++++--- ...ent_app_mac.mm => appshell_helpers_mac.mm} | 45 +++++++------ ...t_app_win.cpp => appshell_helpers_win.cpp} | 65 ++++++++++--------- appshell/cefclient.cpp | 2 +- appshell/cefclient.h | 4 -- appshell/cefclient_gtk.cc | 9 +-- appshell/cefclient_mac.mm | 9 +-- appshell/cefclient_win.cpp | 10 +-- appshell/client_app.cpp | 3 +- appshell/client_app.h | 7 -- appshell_paths.gypi | 9 +-- 16 files changed, 149 insertions(+), 108 deletions(-) create mode 100644 appshell/appshell_helpers.h rename appshell/{client_app_gtk.cpp => appshell_helpers_gtk.cpp} (88%) rename appshell/{client_app_mac.mm => appshell_helpers_mac.mm} (82%) rename appshell/{client_app_win.cpp => appshell_helpers_win.cpp} (67%) 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..0673514f7 --- /dev/null +++ b/appshell/appshell_helpers.h @@ -0,0 +1,42 @@ +/* + * 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(); + +} // namespace appshell diff --git a/appshell/client_app_gtk.cpp b/appshell/appshell_helpers_gtk.cpp similarity index 88% rename from appshell/client_app_gtk.cpp rename to appshell/appshell_helpers_gtk.cpp index 381504021..e3ab09288 100644 --- a/appshell/client_app_gtk.cpp +++ b/appshell/appshell_helpers_gtk.cpp @@ -21,24 +21,24 @@ * */ -#include "client_app.h" +#include "appshell/appshell_helpers.h" #include "appshell/browser/resource.h" #include "include/cef_base.h" -#include "config.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 +51,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 +76,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 +98,12 @@ 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); +} + +} // namespace appshell diff --git a/appshell/client_app_mac.mm b/appshell/appshell_helpers_mac.mm similarity index 82% rename from appshell/client_app_mac.mm rename to appshell/appshell_helpers_mac.mm index 427e041d2..888bb839e 100644 --- a/appshell/client_app_mac.mm +++ b/appshell/appshell_helpers_mac.mm @@ -21,24 +21,24 @@ * */ -#include "client_app.h" +#include "appshell/appshell_helpers.h" #include "include/cef_base.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 +49,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 +76,30 @@ #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); +} + +} // namespace appshell diff --git a/appshell/client_app_win.cpp b/appshell/appshell_helpers_win.cpp similarity index 67% rename from appshell/client_app_win.cpp rename to appshell/appshell_helpers_win.cpp index b2836f6b5..92c429137 100644 --- a/appshell/client_app_win.cpp +++ b/appshell/appshell_helpers_win.cpp @@ -21,49 +21,48 @@ * */ -#include "client_app.h" +#include "appshell/appshell_helpers.h" #include "appshell/browser/resource.h" #include "include/cef_base.h" -#include "config.h" #include #include #include -#include extern DWORD g_appStartupTime; +extern HINSTANCE hInst; -CefString ClientApp::GetCurrentLanguage() +namespace appshell { + +CefString GetCurrentLanguage() { - // Get the user's selected language - // Defaults to the system installed language if not using MUI. - LANGID langID = GetUserDefaultUILanguage(); + // 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); - // 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]; - 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); + GetLocaleInfo(langID, LOCALE_SISO639LANGNAME, lang, langSize); + GetLocaleInfo(langID, LOCALE_SISO3166CTRYNAME, country, countrySize); - // add hyphen - wcscat(wcscat(lang, L"-"), country); - std::wstring locale(lang); + // add hyphen + wcscat(wcscat(lang, L"-"), country); + std::wstring locale(lang); - delete [] lang; - delete [] country; + delete [] lang; + delete [] country; - return CefString(locale); + return CefString(locale); } -std::string ClientApp::GetExtensionJSSource() +std::string GetExtensionJSSource() { - extern HINSTANCE hInst; - HRSRC hRes = FindResource(hInst, MAKEINTRESOURCE(IDS_APPSHELL_EXTENSIONS), MAKEINTRESOURCE(256)); DWORD dwSize; LPBYTE pBytes = NULL; @@ -86,16 +85,16 @@ std::string ClientApp::GetExtensionJSSource() return ""; } -double ClientApp::GetElapsedMilliseconds() +double GetElapsedMilliseconds() { return (timeGetTime() - g_appStartupTime); } -CefString ClientApp::AppGetSupportDirectory() +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; @@ -105,8 +104,7 @@ CefString ClientApp::AppGetSupportDirectory() return CefString(appSupportPath); } - -CefString ClientApp::AppGetDocumentsDirectory() +CefString AppGetDocumentsDirectory() { wchar_t dataPath[MAX_UNC_PATH] = {0}; SHGetFolderPath(NULL, CSIDL_MYDOCUMENTS, NULL, SHGFP_TYPE_CURRENT, dataPath); @@ -117,3 +115,12 @@ CefString ClientApp::AppGetDocumentsDirectory() return CefString(appUserDocuments); } + +CefString AppGetCachePath() { + std::wstring cachePath = AppGetSupportDirectory(); + cachePath += L"/cef_data"; + + return CefString(cachePath); +} + +} // namespace appshell diff --git a/appshell/cefclient.cpp b/appshell/cefclient.cpp index 42c55ceee..3d4f1ba15 100644 --- a/appshell/cefclient.cpp +++ b/appshell/cefclient.cpp @@ -87,7 +87,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); diff --git a/appshell/cefclient.h b/appshell/cefclient.h index 67120d066..8d28edf69 100644 --- a/appshell/cefclient.h +++ b/appshell/cefclient.h @@ -26,10 +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(); diff --git a/appshell/cefclient_gtk.cc b/appshell/cefclient_gtk.cc index 3ea5a1470..7521cc01f 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(); diff --git a/appshell/cefclient_mac.mm b/appshell/cefclient_mac.mm index 3d8ae5f30..187a88364 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. @@ -920,12 +921,6 @@ int main(int argc, char* argv[]) { 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:@" " diff --git a/appshell/cefclient_win.cpp b/appshell/cefclient_win.cpp index 2df5fe01b..35335005d 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,13 +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; } 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_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)', From 9a1224693df4dd13d0ee6eb58485d08622bfad3a Mon Sep 17 00:00:00 2001 From: ficristo Date: Sat, 1 Oct 2016 20:23:56 +0200 Subject: [PATCH 2/2] Move AppGetProductVersionString and AppGetChromiumVersionString in appshell_helpers --- appshell/appshell_helpers.h | 6 +++ appshell/appshell_helpers_gtk.cpp | 11 ++++++ appshell/appshell_helpers_mac.mm | 22 +++++++++++ appshell/appshell_helpers_win.cpp | 63 +++++++++++++++++++++++++++++++ appshell/cefclient.cpp | 5 ++- appshell/cefclient.h | 6 --- appshell/cefclient_gtk.cc | 10 ----- appshell/cefclient_mac.mm | 21 ----------- appshell/cefclient_win.cpp | 63 ------------------------------- 9 files changed, 105 insertions(+), 102 deletions(-) diff --git a/appshell/appshell_helpers.h b/appshell/appshell_helpers.h index 0673514f7..1ade3019f 100644 --- a/appshell/appshell_helpers.h +++ b/appshell/appshell_helpers.h @@ -39,4 +39,10 @@ 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/appshell_helpers_gtk.cpp b/appshell/appshell_helpers_gtk.cpp index e3ab09288..06856b8e0 100644 --- a/appshell/appshell_helpers_gtk.cpp +++ b/appshell/appshell_helpers_gtk.cpp @@ -25,6 +25,7 @@ #include "appshell/browser/resource.h" #include "include/cef_base.h" +#include "include/cef_version.h" #include #include @@ -106,4 +107,14 @@ CefString AppGetCachePath() { return CefString(cachePath); } +CefString AppGetProductVersionString() { + // TODO + return CefString(""); +} + +CefString AppGetChromiumVersionString() { + // TODO + return CefString(""); +} + } // namespace appshell diff --git a/appshell/appshell_helpers_mac.mm b/appshell/appshell_helpers_mac.mm index 888bb839e..b47a1b1dd 100644 --- a/appshell/appshell_helpers_mac.mm +++ b/appshell/appshell_helpers_mac.mm @@ -24,6 +24,7 @@ #include "appshell/appshell_helpers.h" #include "include/cef_base.h" +#include "include/cef_version.h" #include "config.h" #include @@ -102,4 +103,25 @@ CefString AppGetCachePath() { 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 index 92c429137..e916faef7 100644 --- a/appshell/appshell_helpers_win.cpp +++ b/appshell/appshell_helpers_win.cpp @@ -25,6 +25,7 @@ #include "appshell/browser/resource.h" #include "include/cef_base.h" +#include "include/cef_version.h" #include #include @@ -122,5 +123,67 @@ CefString AppGetCachePath() { 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 3d4f1ba15..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; @@ -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 8d28edf69..5cf80477c 100644 --- a/appshell/cefclient.h +++ b/appshell/cefclient.h @@ -26,12 +26,6 @@ std::string AppGetWorkingDirectory(); // Returns the starting URL CefString AppGetInitialURL(); -// 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 7521cc01f..16510956d 100644 --- a/appshell/cefclient_gtk.cc +++ b/appshell/cefclient_gtk.cc @@ -266,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 187a88364..43797cc1b 100644 --- a/appshell/cefclient_mac.mm +++ b/appshell/cefclient_mac.mm @@ -920,24 +920,3 @@ int main(int argc, char* argv[]) { std::string AppGetWorkingDirectory() { return szWorkingDir; } - -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 35335005d..b3ee4b988 100644 --- a/appshell/cefclient_win.cpp +++ b/appshell/cefclient_win.cpp @@ -358,66 +358,3 @@ std::string AppGetWorkingDirectory() { 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()); -}