Skip to content
This repository was archived by the owner on Sep 2, 2021. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions appshell/appshell_extension_handler.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
#include "include/cef_process_message.h"
#include "include/cef_v8.h"

#include "appshell/appshell_helpers.h"

namespace appshell {

// Forward declarations.
Expand Down Expand Up @@ -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 {
Expand Down
5 changes: 3 additions & 2 deletions appshell/appshell_extensions_gtk.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@

#include "appshell_extensions_platform.h"

#include "client_app.h"
#include "appshell/appshell_helpers.h"

#include <glib.h>
#include <glib/gstdio.h>
#include <gio/gio.h>
Expand Down Expand Up @@ -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()
Expand Down
4 changes: 2 additions & 2 deletions appshell/appshell_extensions_mac.mm
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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
Expand Down
5 changes: 2 additions & 3 deletions appshell/appshell_extensions_win.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 <algorithm>
#include <CommDlg.h>
Expand Down Expand Up @@ -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;
Expand Down
48 changes: 48 additions & 0 deletions appshell/appshell_helpers.h
Original file line number Diff line number Diff line change
@@ -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 <string>

#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
39 changes: 29 additions & 10 deletions appshell/client_app_gtk.cpp → appshell/appshell_helpers_gtk.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 <gtk/gtk.h>
#include <pwd.h>
#include <algorithm>
//#include <MMSystem.h>
//#include <ShlObj.h>
#include <string>
#include <glib.h>

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 "-"
Expand All @@ -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
Expand All @@ -76,26 +77,44 @@ 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) {
return AppGetSupportDirectory();
} else {
return CefString(dir);
}
}
}

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
67 changes: 48 additions & 19 deletions appshell/client_app_mac.mm → appshell/appshell_helpers_mac.mm
Original file line number Diff line number Diff line change
Expand Up @@ -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 <Cocoa/Cocoa.h>

#include <string>

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
Expand All @@ -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 {
Expand All @@ -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
Loading