Skip to content
This repository was archived by the owner on Sep 2, 2021. It is now read-only.

Commit 7173d21

Browse files
authored
Merge pull request #585 from ficristo/appshell_helpers
Appshell helpers
2 parents 6fa7509 + 9a12246 commit 7173d21

17 files changed

Lines changed: 344 additions & 300 deletions

appshell/appshell_extension_handler.h

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@
2525
#include "include/cef_process_message.h"
2626
#include "include/cef_v8.h"
2727

28+
#include "appshell/appshell_helpers.h"
29+
2830
namespace appshell {
2931

3032
// Forward declarations.
@@ -161,13 +163,13 @@ class AppShellExtensionHandler : public CefV8Handler {
161163
// GetCurrentLanguage(), GetApplicationSupportDirectory(), and GetRemoteDebuggingPort().
162164
// All other messages are passed to the browser process.
163165
if (name == "GetElapsedMilliseconds") {
164-
retval = CefV8Value::CreateDouble(client_app_->GetElapsedMilliseconds());
166+
retval = CefV8Value::CreateDouble(GetElapsedMilliseconds());
165167
} else if (name == "GetCurrentLanguage") {
166-
retval = CefV8Value::CreateString(client_app_->GetCurrentLanguage());
168+
retval = CefV8Value::CreateString(GetCurrentLanguage());
167169
} else if (name == "GetApplicationSupportDirectory") {
168-
retval = CefV8Value::CreateString(ClientApp::AppGetSupportDirectory());
170+
retval = CefV8Value::CreateString(AppGetSupportDirectory());
169171
} else if (name == "GetUserDocumentsDirectory") {
170-
retval = CefV8Value::CreateString(ClientApp::AppGetDocumentsDirectory());
172+
retval = CefV8Value::CreateString(AppGetDocumentsDirectory());
171173
} else if (name == "GetRemoteDebuggingPort") {
172174
retval = CefV8Value::CreateInt(REMOTE_DEBUGGING_PORT);
173175
} else {

appshell/appshell_extensions_gtk.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@
2323

2424
#include "appshell_extensions_platform.h"
2525

26-
#include "client_app.h"
26+
#include "appshell/appshell_helpers.h"
27+
2728
#include <glib.h>
2829
#include <glib/gstdio.h>
2930
#include <gio/gio.h>
@@ -70,7 +71,7 @@ int32 OpenLiveBrowser(ExtensionString argURL, bool enableRemoteDebugging)
7071
GError *gerror = NULL;
7172

7273
if (enableRemoteDebugging) {
73-
CefString appSupportDirectory = ClientApp::AppGetSupportDirectory();
74+
CefString appSupportDirectory = appshell::AppGetSupportDirectory();
7475

7576
// TODO: (INGO) to better understand to string conversion issue, I need a consultant
7677
// here. Getting the char* from CefString I had to call ToString().c_str()

appshell/appshell_extensions_mac.mm

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323

2424
#include "appshell_extensions_platform.h"
2525

26-
#include "client_app.h"
26+
#include "appshell/appshell_helpers.h"
2727
#include "native_menu_model.h"
2828

2929
#include "GoogleChrome.h"
@@ -50,7 +50,7 @@ - (void)timeoutTimer:(NSTimer*)timer;
5050
// Live Development browser debug paramaters
5151
int const debugPort = 9222;
5252
NSString* debugPortCommandlineArguments = [NSString stringWithFormat:@"--remote-debugging-port=%d", debugPort];
53-
NSString* debugProfilePath = [NSString stringWithFormat:@"--user-data-dir=%s/live-dev-profile", ClientApp::AppGetSupportDirectory().ToString().c_str()];
53+
NSString* debugProfilePath = [NSString stringWithFormat:@"--user-data-dir=%s/live-dev-profile", appshell::AppGetSupportDirectory().ToString().c_str()];
5454

5555
///////////////////////////////////////////////////////////////////////////////
5656
// LiveBrowserMgrMac

appshell/appshell_extensions_win.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,8 @@
2323

2424
#include "appshell_extensions_platform.h"
2525

26-
#include "client_app.h"
26+
#include "appshell/appshell_helpers.h"
2727
#include "native_menu_model.h"
28-
#include "client_handler.h"
2928

3029
#include <algorithm>
3130
#include <CommDlg.h>
@@ -339,7 +338,7 @@ int32 OpenLiveBrowser(ExtensionString argURL, bool enableRemoteDebugging)
339338
std::wstring args = appPath;
340339

341340
if (enableRemoteDebugging) {
342-
std::wstring profilePath(ClientApp::AppGetSupportDirectory());
341+
std::wstring profilePath(appshell::AppGetSupportDirectory());
343342
profilePath += L"\\live-dev-profile";
344343
args += L" --user-data-dir=\"";
345344
args += profilePath;

appshell/appshell_helpers.h

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
/*
2+
* Copyright (c) 2016 - present Adobe Systems Incorporated. All rights reserved.
3+
*
4+
* Permission is hereby granted, free of charge, to any person obtaining a
5+
* copy of this software and associated documentation files (the "Software"),
6+
* to deal in the Software without restriction, including without limitation
7+
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
8+
* and/or sell copies of the Software, and to permit persons to whom the
9+
* Software is furnished to do so, subject to the following conditions:
10+
*
11+
* The above copyright notice and this permission notice shall be included in
12+
* all copies or substantial portions of the Software.
13+
*
14+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19+
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
20+
* DEALINGS IN THE SOFTWARE.
21+
*/
22+
23+
#pragma once
24+
25+
#include <string>
26+
27+
#include "include/internal/cef_string.h"
28+
29+
#include "config.h"
30+
31+
namespace appshell {
32+
33+
double GetElapsedMilliseconds();
34+
CefString GetCurrentLanguage();
35+
std::string GetExtensionJSSource();
36+
CefString AppGetSupportDirectory();
37+
CefString AppGetDocumentsDirectory();
38+
39+
// Returns the default CEF cache location
40+
CefString AppGetCachePath();
41+
42+
// Returns a string containing the product and version (e.g. "Brackets/0.19.0.0")
43+
CefString AppGetProductVersionString();
44+
45+
// Returns a string containing "Chrome/" appends with its version (e.g. "Chrome/29.0.1547.65")
46+
CefString AppGetChromiumVersionString();
47+
48+
} // namespace appshell
Lines changed: 29 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,24 +21,25 @@
2121
*
2222
*/
2323

24-
#include "client_app.h"
24+
#include "appshell/appshell_helpers.h"
2525

2626
#include "appshell/browser/resource.h"
2727
#include "include/cef_base.h"
28-
#include "config.h"
28+
#include "include/cef_version.h"
2929

3030
#include <gtk/gtk.h>
3131
#include <pwd.h>
3232
#include <algorithm>
3333
//#include <MMSystem.h>
3434
//#include <ShlObj.h>
35-
#include <string>
3635
#include <glib.h>
3736

3837
extern time_t g_appStartupTime;
3938
extern char _binary_appshell_appshell_extensions_js_start;
4039

41-
CefString ClientApp::GetCurrentLanguage()
40+
namespace appshell {
41+
42+
CefString GetCurrentLanguage()
4243
{
4344
const char* locconst = pango_language_to_string( gtk_get_default_language() );
4445
//Rado: for me it prints "en-us", so I have to strip everything after the "-"
@@ -51,7 +52,7 @@ CefString ClientApp::GetCurrentLanguage()
5152
return CefString(loc);
5253
}
5354

54-
std::string ClientApp::GetExtensionJSSource()
55+
std::string GetExtensionJSSource()
5556
{
5657
//# We objcopy the appshell/appshell_extensions.js file, and link it directly into the binary.
5758
//# See http://www.linuxjournal.com/content/embedding-file-executable-aka-hello-world-version-5967
@@ -76,26 +77,44 @@ std::string ClientApp::GetExtensionJSSource()
7677
return content;
7778
}
7879

79-
double ClientApp::GetElapsedMilliseconds()
80+
double GetElapsedMilliseconds()
8081
{
8182
return (time(NULL) - g_appStartupTime);
8283
}
8384

84-
CefString ClientApp::AppGetSupportDirectory()
85+
CefString AppGetSupportDirectory()
8586
{
8687
gchar *supportDir = g_strdup_printf("%s/%s", g_get_user_config_dir(), APP_NAME);
8788
CefString result = CefString(supportDir);
8889
g_free(supportDir);
89-
90+
9091
return result;
9192
}
9293

93-
CefString ClientApp::AppGetDocumentsDirectory()
94+
CefString AppGetDocumentsDirectory()
9495
{
9596
const char *dir = g_get_user_special_dir(G_USER_DIRECTORY_DOCUMENTS);
9697
if (dir == NULL) {
9798
return AppGetSupportDirectory();
9899
} else {
99100
return CefString(dir);
100101
}
101-
}
102+
}
103+
104+
CefString AppGetCachePath() {
105+
std::string cachePath = std::string(AppGetSupportDirectory()) + "/cef_data";
106+
107+
return CefString(cachePath);
108+
}
109+
110+
CefString AppGetProductVersionString() {
111+
// TODO
112+
return CefString("");
113+
}
114+
115+
CefString AppGetChromiumVersionString() {
116+
// TODO
117+
return CefString("");
118+
}
119+
120+
} // namespace appshell
Lines changed: 48 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -21,24 +21,25 @@
2121
*
2222
*/
2323

24-
#include "client_app.h"
24+
#include "appshell/appshell_helpers.h"
2525

2626
#include "include/cef_base.h"
27+
#include "include/cef_version.h"
2728
#include "config.h"
2829
#include <Cocoa/Cocoa.h>
2930

30-
#include <string>
31-
3231
extern CFTimeInterval g_appStartupTime;
3332

34-
double ClientApp::GetElapsedMilliseconds()
33+
namespace appshell {
34+
35+
double GetElapsedMilliseconds()
3536
{
3637
CFAbsoluteTime elapsed = CFAbsoluteTimeGetCurrent() - g_appStartupTime;
37-
38+
3839
return round(elapsed * 1000);
3940
}
4041

41-
CefString ClientApp::GetCurrentLanguage()
42+
CefString GetCurrentLanguage()
4243
{
4344
// Do not confuse preferredLanguages with currentLocale.
4445
// preferredLanguages specifies to UI language. currentLocale
@@ -49,24 +50,24 @@
4950
// default on US systems.
5051
// NSLog(@"localeIdentifier: %@", [[NSLocale currentLocale] localeIdentifier]);
5152
// NSLog(@"%@", language);
52-
53+
5354
NSString* language = [[NSLocale preferredLanguages] objectAtIndex:0];
54-
55+
5556
CefString result = [language UTF8String];
5657
return result;
5758
}
5859

59-
std::string ClientApp::GetExtensionJSSource()
60+
std::string GetExtensionJSSource()
6061
{
6162
std::string result;
62-
63+
6364
// This is a hack to grab the extension file from the main app resource bundle.
6465
// This code may be run in a sub process in an app that is bundled inside the main app.
6566
#if 1
6667
NSString* bundlePath = [[NSBundle mainBundle] bundlePath];
6768
NSString* sourcePath;
6869
NSRange range = [bundlePath rangeOfString: @"/Frameworks/"];
69-
70+
7071
if (range.location == NSNotFound) {
7172
sourcePath = [[NSBundle mainBundle] pathForResource: @"appshell_extensions" ofType: @"js"];
7273
} else {
@@ -76,23 +77,51 @@
7677
#else
7778
NSString* sourcePath = [[NSBundle mainBundle] pathForResource: @"appshell_extensions" ofType: @"js"];
7879
#endif
79-
80+
8081
NSString* jsSource = [[NSString alloc] initWithContentsOfFile:sourcePath encoding:NSUTF8StringEncoding error:nil];
8182
result = [jsSource UTF8String];
8283
[jsSource release];
83-
84+
8485
return result;
8586
}
8687

88+
CefString AppGetSupportDirectory() {
89+
NSString *libraryDirectory = [NSSearchPathForDirectoriesInDomains(NSApplicationSupportDirectory, NSUserDomainMask, YES) objectAtIndex:0];
90+
NSString *supportDirectory = [NSString stringWithFormat:@"%@/%@%@", libraryDirectory, GROUP_NAME, APP_NAME];
8791

88-
CefString ClientApp::AppGetSupportDirectory() {
89-
NSString *libraryDirectory = [NSSearchPathForDirectoriesInDomains(NSApplicationSupportDirectory, NSUserDomainMask, YES) objectAtIndex:0];
90-
NSString *supportDirectory = [NSString stringWithFormat:@"%@/%@%@", libraryDirectory, GROUP_NAME, APP_NAME];
91-
92-
return CefString([supportDirectory UTF8String]);
92+
return CefString([supportDirectory UTF8String]);
9393
}
9494

95-
CefString ClientApp::AppGetDocumentsDirectory() {
95+
CefString AppGetDocumentsDirectory() {
9696
NSString *documentsDirectory = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];
9797
return CefString([documentsDirectory UTF8String]);
9898
}
99+
100+
CefString AppGetCachePath() {
101+
std::string cachePath = std::string(AppGetSupportDirectory()) + "/cef_data";
102+
103+
return CefString(cachePath);
104+
}
105+
106+
CefString AppGetProductVersionString() {
107+
NSMutableString *s = [NSMutableString stringWithString:APP_NAME];
108+
[s replaceOccurrencesOfString:@" "
109+
withString:@""
110+
options:NSLiteralSearch
111+
range:NSMakeRange(0, [s length])];
112+
[s appendString:@"/"];
113+
[s appendString:(NSString*)[[NSBundle mainBundle]
114+
objectForInfoDictionaryKey:(NSString *)kCFBundleVersionKey]];
115+
CefString result = CefString([s UTF8String]);
116+
return result;
117+
}
118+
119+
CefString AppGetChromiumVersionString() {
120+
NSMutableString *s = [NSMutableString stringWithFormat:@"Chrome/%d.%d.%d.%d",
121+
cef_version_info(2), cef_version_info(3),
122+
cef_version_info(4), cef_version_info(5)];
123+
CefString result = CefString([s UTF8String]);
124+
return result;
125+
}
126+
127+
} // namespace appshell

0 commit comments

Comments
 (0)