summaryrefslogtreecommitdiff
path: root/native_client_sdk
diff options
context:
space:
mode:
authorBen Murdoch <benm@google.com>2013-07-30 15:19:42 +0100
committerBen Murdoch <benm@google.com>2013-07-30 15:19:42 +0100
commit558790d6acca3451cf3a6b497803a5f07d0bec58 (patch)
treefcc36c3da74559ee6015cb5e9f596105cdc9f56e /native_client_sdk
parent8643c35ec8e6546ae6e04c51e08c4d57d40e88da (diff)
downloadchromium_org-558790d6acca3451cf3a6b497803a5f07d0bec58.tar.gz
Merge from Chromium at DEPS revision r214332
This commit was generated by merge_to_master.py. Change-Id: I82a7c38de906244dc882493568013be659aa65d1
Diffstat (limited to 'native_client_sdk')
-rwxr-xr-xnative_client_sdk/src/build_tools/build_app.py21
-rw-r--r--native_client_sdk/src/build_tools/generate_make.py10
-rwxr-xr-xnative_client_sdk/src/build_tools/parse_dsc.py1
-rwxr-xr-xnative_client_sdk/src/build_tools/test_projects.py3
-rw-r--r--native_client_sdk/src/examples/resources/manifest.json.template7
-rw-r--r--native_client_sdk/src/libraries/nacl_io/kernel_wrap.h1
-rw-r--r--native_client_sdk/src/libraries/nacl_io/kernel_wrap_win.cc14
-rw-r--r--native_client_sdk/src/libraries/ppapi_simple/ps.h56
-rw-r--r--native_client_sdk/src/libraries/ppapi_simple/ps_instance.cc105
-rw-r--r--native_client_sdk/src/libraries/ppapi_simple/ps_instance.h9
-rw-r--r--native_client_sdk/src/libraries/ppapi_simple/ps_main.cc4
-rw-r--r--native_client_sdk/src/libraries/ppapi_simple/ps_main.h12
-rw-r--r--native_client_sdk/src/tools/common.mk2
13 files changed, 91 insertions, 154 deletions
diff --git a/native_client_sdk/src/build_tools/build_app.py b/native_client_sdk/src/build_tools/build_app.py
index f370b9e3a1..5ed0fb6660 100755
--- a/native_client_sdk/src/build_tools/build_app.py
+++ b/native_client_sdk/src/build_tools/build_app.py
@@ -3,6 +3,7 @@
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
+import json
import optparse
import os
import re
@@ -99,22 +100,32 @@ def main(args):
filters['DEST'] = ['examples/api', 'examples/getting_started',
'examples/demo', 'examples/tutorial']
tree = parse_dsc.LoadProjectTree(SDK_SRC_DIR, include=filters)
- build_projects.UpdateHelpers(app_dir, platform, clobber=True)
- build_projects.UpdateProjects(app_dir, platform, tree, clobber=False,
+ build_projects.UpdateHelpers(app_dir, clobber=True)
+ build_projects.UpdateProjects(app_dir, tree, clobber=False,
toolchains=toolchains, configs=[config],
first_toolchain=True)
# Collect permissions from each example, and aggregate them.
+ def MergeLists(list1, list2):
+ return list1 + [x for x in list2 if x not in list1]
all_permissions = []
+ all_socket_permissions = []
for _, project in parse_dsc.GenerateProjects(tree):
- all_permissions.extend(project.get('PERMISSIONS', []))
+ permissions = project.get('PERMISSIONS', [])
+ all_permissions = MergeLists(all_permissions, permissions)
+ socket_permissions = project.get('SOCKET_PERMISSIONS', [])
+ all_socket_permissions = MergeLists(all_socket_permissions,
+ socket_permissions)
+ if all_socket_permissions:
+ all_permissions.append({'socket': all_socket_permissions})
+ pretty_permissions = json.dumps(all_permissions, sort_keys=True, indent=4)
template_dict = {
'name': 'Native Client SDK',
'description':
'Native Client SDK examples, showing API use and key concepts.',
'key': False, # manifests with "key" are rejected when uploading to CWS.
- 'permissions': all_permissions,
+ 'permissions': pretty_permissions,
'version': build_version.ChromeVersionNoTrunk()
}
easy_template.RunTemplateFile(
@@ -127,7 +138,7 @@ def main(args):
os.environ['NACL_SDK_ROOT'] = pepperdir
- build_projects.BuildProjects(app_dir, platform, tree, deps=True, clean=False,
+ build_projects.BuildProjects(app_dir, tree, deps=True, clean=False,
config=config)
RemoveBuildCruft(app_dir)
diff --git a/native_client_sdk/src/build_tools/generate_make.py b/native_client_sdk/src/build_tools/generate_make.py
index e74891b26c..db124448e6 100644
--- a/native_client_sdk/src/build_tools/generate_make.py
+++ b/native_client_sdk/src/build_tools/generate_make.py
@@ -2,6 +2,7 @@
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
+import json
import os
import sys
@@ -138,11 +139,18 @@ def GenerateManifest(srcroot, dstroot, desc):
outdir = os.path.join(dstroot, desc['DEST'], desc['NAME'])
srcpath = os.path.join(SDK_EXAMPLE_DIR, 'resources', 'manifest.json.template')
dstpath = os.path.join(outdir, 'manifest.json')
+ permissions = desc.get('PERMISSIONS', [])
+ socket_permissions = desc.get('SOCKET_PERMISSIONS', [])
+ combined_permissions = list(permissions)
+ if socket_permissions:
+ combined_permissions.append({'socket': socket_permissions})
+ pretty_permissions = json.dumps(combined_permissions,
+ sort_keys=True, indent=4)
replace = {
'name': desc['TITLE'],
'description': '%s Example' % desc['TITLE'],
'key': True,
- 'permissions': desc.get('PERMISSIONS', []),
+ 'permissions': pretty_permissions,
'version': build_version.ChromeVersionNoTrunk()
}
RunTemplateFileIfChanged(srcpath, dstpath, replace)
diff --git a/native_client_sdk/src/build_tools/parse_dsc.py b/native_client_sdk/src/build_tools/parse_dsc.py
index 48c3761aad..001556299e 100755
--- a/native_client_sdk/src/build_tools/parse_dsc.py
+++ b/native_client_sdk/src/build_tools/parse_dsc.py
@@ -53,6 +53,7 @@ DSC_FORMAT = {
'GROUP': (str, '', False),
'EXPERIMENTAL': (bool, [True, False], False),
'PERMISSIONS': (list, '', False),
+ 'SOCKET_PERMISSIONS': (list, '', False)
}
diff --git a/native_client_sdk/src/build_tools/test_projects.py b/native_client_sdk/src/build_tools/test_projects.py
index 9c1a057212..8007a1fe6d 100755
--- a/native_client_sdk/src/build_tools/test_projects.py
+++ b/native_client_sdk/src/build_tools/test_projects.py
@@ -102,9 +102,6 @@ def GetBrowserTesterCommand(desc, toolchain, config):
ppapi_plugin += '.so'
args.extend(['--ppapi_plugin', ppapi_plugin])
- if toolchain == 'pnacl':
- args.extend(['--browser_flag', '--enable-pnacl'])
-
url = 'index.html'
url += '?tc=%s&config=%s&test=true' % (toolchain, config)
args.extend(['--url', url])
diff --git a/native_client_sdk/src/examples/resources/manifest.json.template b/native_client_sdk/src/examples/resources/manifest.json.template
index c4a111c3ae..e7e97609fe 100644
--- a/native_client_sdk/src/examples/resources/manifest.json.template
+++ b/native_client_sdk/src/examples/resources/manifest.json.template
@@ -19,10 +19,5 @@
"client_id": "903965034255.apps.googleusercontent.com",
"scopes": ["https://www.googleapis.com/auth/drive"]
},
- "permissions": [
-[[if permissions:]]
-[[ for i, perm in enumerate(permissions):]]
- "{{perm}}"{{(i != len(permissions) - 1) and ',' or ''}}
-[[]]
- ]
+ "permissions": {{permissions}}
}
diff --git a/native_client_sdk/src/libraries/nacl_io/kernel_wrap.h b/native_client_sdk/src/libraries/nacl_io/kernel_wrap.h
index 3f626980c2..3380dd7186 100644
--- a/native_client_sdk/src/libraries/nacl_io/kernel_wrap.h
+++ b/native_client_sdk/src/libraries/nacl_io/kernel_wrap.h
@@ -81,6 +81,7 @@ read_ssize_t NAME(read)(int fd, void* buf, size_t nbyte);
int remove(const char* path) NOTHROW;
int NAME(rmdir)(const char* path) NOTHROW;
#if defined(WIN32)
+int setenv(const char* name, const char* value, int overwrite);
int _stat32(const char* path, struct _stat32* buf);
int _stat64(const char* path, struct _stat64* buf);
int _stat32i64(const char* path, struct _stat32i64* buf);
diff --git a/native_client_sdk/src/libraries/nacl_io/kernel_wrap_win.cc b/native_client_sdk/src/libraries/nacl_io/kernel_wrap_win.cc
index 89db245de3..e59b6c0a98 100644
--- a/native_client_sdk/src/libraries/nacl_io/kernel_wrap_win.cc
+++ b/native_client_sdk/src/libraries/nacl_io/kernel_wrap_win.cc
@@ -10,6 +10,7 @@
#include <errno.h>
#include <fcntl.h>
#include <stdarg.h>
+#include <stdlib.h>
#include <string.h>
#include <sys/types.h> // This must be included before <sys/stat.h>.
#include <sys/stat.h>
@@ -203,6 +204,19 @@ int _rmdir(const char* path) {
return ki_rmdir(path);
}
+int setenv(const char* name, const char* value, int overwrite) {
+ if (0 == overwrite && NULL != getenv(name)) {
+ return 0;
+ }
+ errno_t result = _putenv_s(name, value);
+ if (result != 0) {
+ errno = result;
+ return -1;
+ } else {
+ return 0;
+ }
+}
+
int _stat32(const char* path, struct _stat32* buf) {
struct stat ki_buf;
int res = ki_stat(path, &ki_buf);
diff --git a/native_client_sdk/src/libraries/ppapi_simple/ps.h b/native_client_sdk/src/libraries/ppapi_simple/ps.h
index fe5205b36a..a6bb3d3fc7 100644
--- a/native_client_sdk/src/libraries/ppapi_simple/ps.h
+++ b/native_client_sdk/src/libraries/ppapi_simple/ps.h
@@ -69,64 +69,16 @@ extern void* PSUserCreateInstance(PP_Instance inst);
/**
- * PPAPI_SIMPLE_DECLARE_PARAMS
- *
- * Macro for creating the param string array. Used by the Factory macros
- * to enable wrapping of the param array with terminating NULL, NULL.
- */
-#define PPAPI_SIMPLE_DECLARE_PARAMS(params, ...) \
- static const char* params[] = { __VA_ARGS__ };
-
-
-/**
* PPAPI_SIMPLE_USE_MAIN
*
* For use with C projects, this macro calls the provided factory with
- * configuration information and optional extra arguments which are passed to
- * the 'main' function. See the appropriate ppapi_simple_main(XX).h header.
- */
-#if defined(WIN32)
-
-/* In MSVC, ##__VA_ARGS does not remove the following comma, only the
- * previous one. As a result, passing no extra arguments to
- * PPAPI_SIMPLE_USE_MAIN yields:
- *
- * static const char* params[] = { , NULL, NULL };
- *
- * We work around this by always preceding it with a "NULL,". That way the
- * previous comma is removed and the following comma takes its place. We then
- * skip this initial bogus value when passing the array to the factory.
+ * configuration information.
*/
-#define PPAPI_SIMPLE_USE_MAIN(factory, func, ...) \
-void* PSUserCreateInstance(PP_Instance inst) { \
- PPAPI_SIMPLE_DECLARE_PARAMS(params, NULL, ##__VA_ARGS__, NULL, NULL) \
- return factory(inst, func, params + 1); \
+#define PPAPI_SIMPLE_USE_MAIN(factory, func) \
+void* PSUserCreateInstance(PP_Instance inst) { \
+ return factory(inst, func); \
}
-#else
-
-#define PPAPI_SIMPLE_USE_MAIN(factory, func, ...) \
-void* PSUserCreateInstance(PP_Instance inst) { \
- PPAPI_SIMPLE_DECLARE_PARAMS(params, ##__VA_ARGS__, NULL, NULL) \
- return factory(inst, func, params); \
-}
-
-#endif
-
-
-/**
- * PPAPI_SIMPLE_USE_CLASS
- *
- * For use with C++ projects, this macro instantiates the provided class
- * passing it back to the generic module initialization code. Simply derive
- * a class from the appropriate ppapi_simple_instance(XX).h and pass the
- * class name here.
- */
-#define PPAPI_SIMPLE_USE_CLASS(classname, ...) \
-void* PSUserCreateInstance(PP_Instance inst) { \
- PPAPI_SIMPLE_DECLARE_PARAMS(params, ##__VA_ARGS__, NULL, NULL) \
- return (void *) new classname(inst, params); \
-}
EXTERN_C_END
diff --git a/native_client_sdk/src/libraries/ppapi_simple/ps_instance.cc b/native_client_sdk/src/libraries/ppapi_simple/ps_instance.cc
index 741697c452..711c11947f 100644
--- a/native_client_sdk/src/libraries/ppapi_simple/ps_instance.cc
+++ b/native_client_sdk/src/libraries/ppapi_simple/ps_instance.cc
@@ -10,9 +10,10 @@
#include <sys/types.h>
#include <sys/stat.h>
+#include <algorithm>
#include <cstdlib>
#include <cstring>
-#include <map>
+#include <sstream>
#include <string>
#include <vector>
@@ -88,7 +89,7 @@ int PSInstance::MainThread(int argc, char *argv[]) {
return ret;
}
-PSInstance::PSInstance(PP_Instance instance, const char *argv[])
+PSInstance::PSInstance(PP_Instance instance)
: pp::Instance(instance),
pp::MouseLock(this),
pp::Graphics3DClient(this),
@@ -103,13 +104,6 @@ PSInstance::PSInstance(PP_Instance instance, const char *argv[])
SetVerbosity(PSV_LOG);
#endif
- // Place PPAPI_MAIN_USE arguments into properties map
- while (*argv) {
- std::string key = *argv++;
- std::string val = *argv++;
- properties_[key] = val;
- }
-
RequestInputEvents(PP_INPUTEVENT_CLASS_MOUSE |
PP_INPUTEVENT_CLASS_KEYBOARD |
PP_INPUTEVENT_CLASS_WHEEL |
@@ -129,54 +123,35 @@ bool PSInstance::Init(uint32_t arg,
si->inst_ = this;
si->argc_ = 1;
- si->argv_ = new char *[arg*2+1];
+ si->argv_ = new char *[arg+1];
si->argv_[0] = NULL;
- // Process arguments passed into Module INIT from JavaScript
+ // Process embed attributes into the environment.
+ // Converted the attribute names to uppercase as environment variables are
+ // case sensitive but are almost universally uppercase in practice.
for (uint32_t i = 0; i < arg; i++) {
- // If we start with PM prefix set the instance argument map
- if (0 == strncmp(argn[i], "ps_", 3)) {
- std::string key = argn[i];
- std::string val = argv[i];
- properties_[key] = val;
- continue;
- }
-
- // Chrome passed @dev as an internal extra attribute in
- // some cases. Ignore this.
- if (0 == strcmp(argn[i], "@dev")) {
- continue;
- }
-
- // If this is the 'src' tag, then get the NMF name.
- if (!strcmp("src", argn[i])) {
- char *name = new char[strlen(argv[i]) + 1];
- strcpy(name, argv[i]);
- si->argv_[0] = name;
- } else {
- // Otherwise turn html tag attributes into arguments
- // that get passed to the main funciton. Attributes
- // without values get transformed into "--name" and
- // attributes with values become "--name=value".
- int arglen = strlen(argn[i]) + 3;
- if (argv[i] && argv[i][0])
- arglen += strlen(argv[i]) + 1;
-
- char* arg = new char[arglen];
- if (argv[i] && argv[i][0])
- sprintf(arg, "--%s=%s", argn[i], argv[i]);
- else
- sprintf(arg, "--%s", argn[i]);
-
- si->argv_[si->argc_++] = arg;
- }
+ std::string key = argn[i];
+ std::transform(key.begin(), key.end(), key.begin(), toupper);
+ setenv(key.c_str(), argv[i], 1);
}
- // If src was not found, set the first arg to something
- if (NULL == si->argv_[0]) {
- char *name = new char[5];
- strcpy(name, "NMF?");
- si->argv_[0] = name;
+ // Set a default value for SRC.
+ setenv("SRC", "NMF?", 0);
+ // Use the src tag name if ARG0 is not explicitly specified.
+ setenv("ARG0", getenv("SRC"), 0);
+
+ // Walk ARG0..ARGn populating argv until an argument is missing.
+ for (;;) {
+ std::ostringstream arg_stream;
+ arg_stream << "ARG" << si->argc_;
+ std::string arg_name = arg_stream.str();
+ const char* next_arg = getenv(arg_name.c_str());
+ if (NULL == next_arg)
+ break;
+
+ char* value = new char[strlen(next_arg) + 1];
+ strcpy(value, next_arg);
+ si->argv_[si->argc_++] = value;
}
PSInterfaceInit();
@@ -208,39 +183,31 @@ bool PSInstance::Init(uint32_t arg,
return ret == 0;
}
-const char* PSInstance::GetProperty(const char* key, const char* def) {
- PropertyMap_t::iterator it = properties_.find(key);
- if (it != properties_.end()) {
- return it->second.c_str();
- }
- return def;
-}
-
// Processes the properties set at compile time via the
// initialization macro, or via dynamically set embed attributes
// through instance DidCreate.
bool PSInstance::ProcessProperties() {
- // Get the default values
- const char* stdin_path = GetProperty("ps_stdin", "/dev/stdin");
- const char* stdout_path = GetProperty("ps_stdout", "/dev/stdout");
- const char* stderr_path = GetProperty("ps_stderr", "/dev/console3");
- const char* verbosity = GetProperty("ps_verbosity", NULL);
- const char* tty_prefix = GetProperty("ps_tty_prefix", NULL);
+ // Set default values
+ setenv("PS_STDIN", "/dev/stdin", 0);
+ setenv("PS_STDOUT", "/dev/stdout", 0);
+ setenv("PS_STDERR", "/dev/console3", 0);
// Reset verbosity if passed in
+ const char* verbosity = getenv("PS_VERBOSITY");
if (verbosity) SetVerbosity(static_cast<Verbosity>(atoi(verbosity)));
// Enable NaCl IO to map STDIN, STDOUT, and STDERR
nacl_io_init_ppapi(PSGetInstanceId(), PSGetInterface);
- int fd0 = open(stdin_path, O_RDONLY);
+ int fd0 = open(getenv("PS_STDIN"), O_RDONLY);
dup2(fd0, 0);
- int fd1 = open(stdout_path, O_WRONLY);
+ int fd1 = open(getenv("PS_STDOUT"), O_WRONLY);
dup2(fd1, 1);
- int fd2 = open(stderr_path, O_WRONLY);
+ int fd2 = open(getenv("PS_STDERR"), O_WRONLY);
dup2(fd2, 2);
+ const char* tty_prefix = getenv("PS_TTY_PREFIX");
if (tty_prefix) {
fd_tty_ = open("/dev/tty", O_WRONLY);
if (fd_tty_ >= 0) {
diff --git a/native_client_sdk/src/libraries/ppapi_simple/ps_instance.h b/native_client_sdk/src/libraries/ppapi_simple/ps_instance.h
index cf97714cb7..2df1550dbb 100644
--- a/native_client_sdk/src/libraries/ppapi_simple/ps_instance.h
+++ b/native_client_sdk/src/libraries/ppapi_simple/ps_instance.h
@@ -6,7 +6,6 @@
#define PPAPI_SIMPLE_PS_INSTANCE_H_
#include <stdarg.h>
-#include <map>
#include "ppapi/c/pp_instance.h"
#include "ppapi/c/pp_stdint.h"
@@ -28,8 +27,6 @@
#include "sdk_util/thread_safe_queue.h"
-typedef std::map<std::string, std::string> PropertyMap_t;
-
// The basic instance class which also inherits the MouseLock and
// Graphics3DClient interfaces.
class PSInstance : public pp::Instance, pp::MouseLock, pp::Graphics3DClient {
@@ -47,7 +44,7 @@ class PSInstance : public pp::Instance, pp::MouseLock, pp::Graphics3DClient {
// Returns a pointer to the global instance
static PSInstance* GetInstance();
- PSInstance(PP_Instance inst, const char *argv[]);
+ PSInstance(PP_Instance inst);
virtual ~PSInstance();
// Set a function which will be called on a new thread once initialized.
@@ -55,9 +52,6 @@ class PSInstance : public pp::Instance, pp::MouseLock, pp::Graphics3DClient {
// function will have no effect.
void SetMain(PSMainFunc_t func);
- // Returns value based on KEY or default.
- const char* GetProperty(const char* key, const char* def = NULL);
-
// Started on Init, a thread which can be safely blocked.
virtual int MainThread(int argc, char* argv[]);
@@ -123,7 +117,6 @@ class PSInstance : public pp::Instance, pp::MouseLock, pp::Graphics3DClient {
protected:
pp::MessageLoop* main_loop_;
- PropertyMap_t properties_;
sdk_util::ThreadSafeQueue<PSEvent> event_queue_;
uint32_t events_enabled_;
Verbosity verbosity_;
diff --git a/native_client_sdk/src/libraries/ppapi_simple/ps_main.cc b/native_client_sdk/src/libraries/ppapi_simple/ps_main.cc
index 1e8cc8dc1f..eabbeaace6 100644
--- a/native_client_sdk/src/libraries/ppapi_simple/ps_main.cc
+++ b/native_client_sdk/src/libraries/ppapi_simple/ps_main.cc
@@ -9,8 +9,8 @@
#include "ppapi_simple/ps_main.h"
-void* PSMainCreate(PP_Instance inst, PSMainFunc_t func, const char* argv[]) {
- PSInstance* pInst = new PSInstance(inst, argv);
+void* PSMainCreate(PP_Instance inst, PSMainFunc_t func) {
+ PSInstance* pInst = new PSInstance(inst);
pInst->SetMain(func);
return pInst;
}
diff --git a/native_client_sdk/src/libraries/ppapi_simple/ps_main.h b/native_client_sdk/src/libraries/ppapi_simple/ps_main.h
index 9e18edf9e4..c269d3abaa 100644
--- a/native_client_sdk/src/libraries/ppapi_simple/ps_main.h
+++ b/native_client_sdk/src/libraries/ppapi_simple/ps_main.h
@@ -18,19 +18,17 @@ typedef int (*PSMainFunc_t)(int argc, char *argv[]);
* Constructs an instance SimpleInstance and configures it to call into
* the provided "main" function.
*/
-void* PSMainCreate(PP_Instance inst, PSMainFunc_t func, const char **argv);
+void* PSMainCreate(PP_Instance inst, PSMainFunc_t func);
/**
* PPAPI_SIMPLE_REGISTER_MAIN
*
- * Constructs a PSInstance ojbect and configures it to use call the provided
- * 'main' function on it's own thread once initialization is complete.
+ * Constructs a PSInstance object and configures it to use call the provided
+ * 'main' function on its own thread once initialization is complete.
*/
-
-
-#define PPAPI_SIMPLE_REGISTER_MAIN(main, ...) \
- PPAPI_SIMPLE_USE_MAIN(PSMainCreate, main, ##__VA_ARGS__)
+#define PPAPI_SIMPLE_REGISTER_MAIN(main) \
+ PPAPI_SIMPLE_USE_MAIN(PSMainCreate, main)
EXTERN_C_END
diff --git a/native_client_sdk/src/tools/common.mk b/native_client_sdk/src/tools/common.mk
index 6ffc8cbfbd..91d123da57 100644
--- a/native_client_sdk/src/tools/common.mk
+++ b/native_client_sdk/src/tools/common.mk
@@ -431,7 +431,7 @@ RUN_PY := python $(NACL_SDK_ROOT)/tools/run.py
CHROME_ENV ?=
# Additional arguments to pass to Chrome.
-CHROME_ARGS += --enable-nacl --enable-pnacl --no-first-run
+CHROME_ARGS += --enable-nacl --no-first-run
CHROME_ARGS += --user-data-dir=$(CURDIR)/user-data-dir