39 |
40 |
41 |
44 |
45 |
46 |
--------------------------------------------------------------------------------
/bin/templates/project/__PROJECT_NAME__/Images.xcassets/AppIcon.appiconset/Contents.json:
--------------------------------------------------------------------------------
1 | {
2 | "images": [
3 | {
4 | "size": "16x16",
5 | "idiom": "mac",
6 | "filename": "icon-16x16.png",
7 | "scale": "1x"
8 | },
9 | {
10 | "size": "16x16",
11 | "idiom": "mac",
12 | "filename": "icon-32x32.png",
13 | "scale": "2x"
14 | },
15 | {
16 | "size": "32x32",
17 | "idiom": "mac",
18 | "filename": "icon-32x32.png",
19 | "scale": "1x"
20 | },
21 | {
22 | "size": "32x32",
23 | "idiom": "mac",
24 | "filename": "icon-64x64.png",
25 | "scale": "2x"
26 | },
27 | {
28 | "size": "128x128",
29 | "idiom": "mac",
30 | "filename": "icon-128x128.png",
31 | "scale": "1x"
32 | },
33 | {
34 | "size": "128x128",
35 | "idiom": "mac",
36 | "filename": "icon-256x256.png",
37 | "scale": "2x"
38 | },
39 | {
40 | "size": "256x256",
41 | "idiom": "mac",
42 | "filename": "icon-256x256.png",
43 | "scale": "1x"
44 | },
45 | {
46 | "size": "256x256",
47 | "idiom": "mac",
48 | "filename": "icon-512x512.png",
49 | "scale": "2x"
50 | },
51 | {
52 | "size": "512x512",
53 | "idiom": "mac",
54 | "filename": "icon-512x512.png",
55 | "scale": "1x"
56 | },
57 | {
58 | "idiom": "mac",
59 | "size": "512x512",
60 | "filename": "icon-1024x1024.png",
61 | "scale": "2x"
62 | }
63 | ],
64 | "info": {
65 | "version": 1,
66 | "author": "xcode"
67 | }
68 | }
69 |
--------------------------------------------------------------------------------
/bin/templates/scripts/cordova/build:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env node
2 |
3 | /*
4 | Licensed to the Apache Software Foundation (ASF) under one
5 | or more contributor license agreements. See the NOTICE file
6 | distributed with this work for additional information
7 | regarding copyright ownership. The ASF licenses this file
8 | to you under the Apache License, Version 2.0 (the
9 | "License"); you may not use this file except in compliance
10 | with the License. You may obtain a copy of the License at
11 |
12 | http://www.apache.org/licenses/LICENSE-2.0
13 |
14 | Unless required by applicable law or agreed to in writing,
15 | software distributed under the License is distributed on an
16 | "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17 | KIND, either express or implied. See the License for the
18 | specific language governing permissions and limitations
19 | under the License.
20 | */
21 |
22 | const args = process.argv;
23 | const Api = require('./Api');
24 | const nopt = require('nopt');
25 |
26 | // Support basic help commands
27 | if (['--help', '/?', '-h', 'help', '-help', '/help'].indexOf(process.argv[2]) >= 0) {
28 | require('./lib/build').help();
29 | process.exit(0);
30 | }
31 |
32 | // Parse arguments
33 | const buildOpts = nopt({
34 | verbose: Boolean,
35 | silent: Boolean,
36 | debug: Boolean,
37 | release: Boolean,
38 | codeSignIdentity: String,
39 | codeSignResourceRules: String,
40 | provisioningProfile: String,
41 | buildConfig: String,
42 | noSign: Boolean
43 | }, { '-r': '--release' }, args);
44 |
45 | // Make buildOptions compatible with PlatformApi build method spec
46 | buildOpts.argv = buildOpts.argv.remain;
47 |
48 | new Api().build(buildOpts).then(function () {
49 | console.log('** BUILD SUCCEEDED **');
50 | }, function (err) {
51 | const errorMessage = (err && err.stack) ? err.stack : err;
52 | console.error(errorMessage);
53 | process.exit(2);
54 | });
55 |
--------------------------------------------------------------------------------
/bin/templates/scripts/cordova/lib/spawn.js:
--------------------------------------------------------------------------------
1 | /*
2 | Licensed to the Apache Software Foundation (ASF) under one
3 | or more contributor license agreements. See the NOTICE file
4 | distributed with this work for additional information
5 | regarding copyright ownership. The ASF licenses this file
6 | to you under the Apache License, Version 2.0 (the
7 | "License"); you may not use this file except in compliance
8 | with the License. You may obtain a copy of the License at
9 |
10 | http://www.apache.org/licenses/LICENSE-2.0
11 |
12 | Unless required by applicable law or agreed to in writing,
13 | software distributed under the License is distributed on an
14 | "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 | KIND, either express or implied. See the License for the
16 | specific language governing permissions and limitations
17 | under the License.
18 | */
19 |
20 | const proc = require('child_process');
21 |
22 | /**
23 | * Run specified command with arguments
24 | * @param {String} cmd Command
25 | * @param {Array} args Array of arguments that should be passed to command
26 | * @param {String} opt_cwd Working directory for command
27 | * @param {String} opt_verbosity Verbosity level for command stdout output, "verbose" by default
28 | * @return {Promise} Promise either fullfilled or rejected with error code
29 | */
30 | module.exports = function (cmd, args, opt_cwd) {
31 | return new Promise((resolve, reject) => {
32 | try {
33 | const child = proc.spawn(cmd, args, { cwd: opt_cwd, stdio: 'inherit' });
34 |
35 | child.on('exit', function (code) {
36 | if (code) {
37 | reject('Error code ' + code + ' for command: ' + cmd + ' with args: ' + args);
38 | } else {
39 | resolve();
40 | }
41 | });
42 | } catch (e) {
43 | console.error('error caught: ' + e);
44 | reject(e);
45 | }
46 | });
47 | };
48 |
--------------------------------------------------------------------------------
/bin/templates/project/www/js/index.js:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed to the Apache Software Foundation (ASF) under one
3 | * or more contributor license agreements. See the NOTICE file
4 | * distributed with this work for additional information
5 | * regarding copyright ownership. The ASF licenses this file
6 | * to you under the Apache License, Version 2.0 (the
7 | * "License"); you may not use this file except in compliance
8 | * with the License. You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing,
13 | * software distributed under the License is distributed on an
14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 | * KIND, either express or implied. See the License for the
16 | * specific language governing permissions and limitations
17 | * under the License.
18 | */
19 | var app = {
20 | // Application Constructor
21 | initialize: function () {
22 | this.bindEvents();
23 | },
24 | // Bind Event Listeners
25 | //
26 | // Bind any events that are required on startup. Common events are:
27 | // 'load', 'deviceready', 'offline', and 'online'.
28 | bindEvents: function () {
29 | document.addEventListener('deviceready', this.onDeviceReady, false);
30 | },
31 | // deviceready Event Handler
32 | //
33 | // The scope of 'this' is the event. In order to call the 'receivedEvent'
34 | // function, we must explicity call 'app.receivedEvent(...);'
35 | onDeviceReady: function () {
36 | app.receivedEvent('deviceready');
37 | },
38 | // Update DOM on a Received Event
39 | receivedEvent: function (id) {
40 | var parentElement = document.getElementById(id);
41 | var listeningElement = parentElement.querySelector('.listening');
42 | var receivedElement = parentElement.querySelector('.received');
43 |
44 | listeningElement.setAttribute('style', 'display:none;');
45 | receivedElement.setAttribute('style', 'display:block;');
46 |
47 | console.log('Received Event: ' + id);
48 | }
49 | };
50 |
--------------------------------------------------------------------------------
/tests/CordovaLibTests/CordovaLibApp/www/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
46 |
47 |
48 |
Hey, it's Cordova!
49 |
50 |
Check your console log for any white-list rejection errors.
51 |
Add your allowed hosts in config.xml as access tags and set the origin attribute. (wildcards
52 | OK, don't enter the URL scheme)
53 |
54 |
55 |
56 |
57 |
--------------------------------------------------------------------------------
/bin/templates/scripts/cordova/run:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env node
2 |
3 | /*
4 | Licensed to the Apache Software Foundation (ASF) under one
5 | or more contributor license agreements. See the NOTICE file
6 | distributed with this work for additional information
7 | regarding copyright ownership. The ASF licenses this file
8 | to you under the Apache License, Version 2.0 (the
9 | "License"); you may not use this file except in compliance
10 | with the License. You may obtain a copy of the License at
11 |
12 | http://www.apache.org/licenses/LICENSE-2.0
13 |
14 | Unless required by applicable law or agreed to in writing,
15 | software distributed under the License is distributed on an
16 | "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17 | KIND, either express or implied. See the License for the
18 | specific language governing permissions and limitations
19 | under the License.
20 | */
21 |
22 | const args = process.argv;
23 | const Api = require('./Api');
24 | const nopt = require('nopt');
25 |
26 | // Handle help flag
27 | if (['--help', '/?', '-h', 'help', '-help', '/help'].indexOf(process.argv[2]) >= 0) {
28 | require('./lib/run').help();
29 | process.exit(0);
30 | }
31 |
32 | // Parse arguments (includes build params as well)
33 | const opts = nopt({
34 | verbose: Boolean,
35 | silent: Boolean,
36 | debug: Boolean,
37 | release: Boolean,
38 | nobuild: Boolean,
39 | archs: String,
40 | list: Boolean,
41 | device: Boolean,
42 | emulator: Boolean,
43 | target: String,
44 | codeSignIdentity: String,
45 | codeSignResourceRules: String,
46 | provisioningProfile: String,
47 | buildConfig: String,
48 | noSign: Boolean
49 | }, {}, args);
50 |
51 | // Make options compatible with PlatformApi build method spec
52 | opts.argv = opts.argv.remain;
53 |
54 | new Api().run(opts).then(function () {
55 | console.log('** RUN SUCCEEDED **');
56 | }, function (err) {
57 | const errorMessage = (err && err.stack) ? err.stack : err;
58 | console.error(errorMessage);
59 | process.exit(2);
60 | });
61 |
--------------------------------------------------------------------------------
/tests/cdv-test-project/www/js/index.js:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed to the Apache Software Foundation (ASF) under one
3 | * or more contributor license agreements. See the NOTICE file
4 | * distributed with this work for additional information
5 | * regarding copyright ownership. The ASF licenses this file
6 | * to you under the Apache License, Version 2.0 (the
7 | * "License"); you may not use this file except in compliance
8 | * with the License. You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing,
13 | * software distributed under the License is distributed on an
14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 | * KIND, either express or implied. See the License for the
16 | * specific language governing permissions and limitations
17 | * under the License.
18 | */
19 | var app = {
20 | // Application Constructor
21 | initialize: function() {
22 | this.bindEvents();
23 | },
24 | // Bind Event Listeners
25 | //
26 | // Bind any events that are required on startup. Common events are:
27 | // 'load', 'deviceready', 'offline', and 'online'.
28 | bindEvents: function() {
29 | document.addEventListener('deviceready', this.onDeviceReady, false);
30 | },
31 | // deviceready Event Handler
32 | //
33 | // The scope of 'this' is the event. In order to call the 'receivedEvent'
34 | // function, we must explicitly call 'app.receivedEvent(...);'
35 | onDeviceReady: function() {
36 | app.receivedEvent('deviceready');
37 | },
38 | // Update DOM on a Received Event
39 | receivedEvent: function(id) {
40 | var parentElement = document.getElementById(id);
41 | var listeningElement = parentElement.querySelector('.listening');
42 | var receivedElement = parentElement.querySelector('.received');
43 |
44 | listeningElement.setAttribute('style', 'display:none;');
45 | receivedElement.setAttribute('style', 'display:block;');
46 |
47 | console.log('Received Event: ' + id);
48 | }
49 | };
50 |
51 | app.initialize();
--------------------------------------------------------------------------------
/tests/CordovaLibTests/CDVBase64Tests.m:
--------------------------------------------------------------------------------
1 | /*
2 | Licensed to the Apache Software Foundation (ASF) under one
3 | or more contributor license agreements. See the NOTICE file
4 | distributed with this work for additional information
5 | regarding copyright ownership. The ASF licenses this file
6 | to you under the Apache License, Version 2.0 (the
7 | "License"); you may not use this file except in compliance
8 | with the License. You may obtain a copy of the License at
9 |
10 | http://www.apache.org/licenses/LICENSE-2.0
11 |
12 | Unless required by applicable law or agreed to in writing,
13 | software distributed under the License is distributed on an
14 | "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 | KIND, either express or implied. See the License for the
16 | specific language governing permissions and limitations
17 | under the License.
18 | */
19 |
20 | #import
21 |
22 | #import
23 |
24 | @interface CDVBase64Tests : XCTestCase
25 | @end
26 |
27 | @implementation CDVBase64Tests
28 |
29 | - (void) setUp {
30 | [super setUp];
31 |
32 | // setup code here
33 | }
34 |
35 | - (void) tearDown {
36 | // Tear-down code here.
37 |
38 | [super tearDown];
39 | }
40 |
41 | - (void) testBase64Encode {
42 | NSString* decodedString = @"abcdefghijklmnopqrstuvwxyz1234567890!@#$%^&";
43 | NSData* decodedData = [decodedString dataUsingEncoding:NSUTF8StringEncoding];
44 |
45 | NSString* expectedEncodedString = @"YWJjZGVmZ2hpamtsbW5vcHFyc3R1dnd4eXoxMjM0NTY3ODkwIUAjJCVeJg==";
46 | NSString* actualEncodedString = [decodedData base64EncodedString];
47 |
48 | XCTAssertTrue([expectedEncodedString isEqualToString:actualEncodedString]);
49 | }
50 |
51 | - (void) testBase64Decode {
52 | NSString* encodedString = @"YWJjZGVmZ2hpamtsbW5vcHFyc3R1dnd4eXoxMjM0NTY3ODkwIUAjJCVeJg==";
53 | NSString* decodedString = @"abcdefghijklmnopqrstuvwxyz1234567890!@#$%^&";
54 | NSData* encodedData = [decodedString dataUsingEncoding:NSUTF8StringEncoding];
55 | NSData* decodedData = [NSData dataFromBase64String:encodedString];
56 |
57 | XCTAssertTrue([encodedData isEqualToData:decodedData]);
58 | }
59 |
60 | @end
61 |
--------------------------------------------------------------------------------
/CordovaLib/CordovaLib/Classes/Commands/CDVAvailability.h:
--------------------------------------------------------------------------------
1 | /*
2 | #define CORDOVA_VERSION_MIN_REQUIRED __CORDOVA_7_0_0
3 | or more contributor license agreements. See the NOTICE file
4 | distributed with this work for additional information
5 | regarding copyright ownership. The ASF licenses this file
6 | to you under the Apache License, Version 2.0 (the
7 | "License"); you may not use this file except in compliance
8 | with the License. You may obtain a copy of the License at
9 |
10 | http://www.apache.org/licenses/LICENSE-2.0
11 |
12 | Unless required by applicable law or agreed to in writing,
13 | software distributed under the License is distributed on an
14 | "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 | KIND, either express or implied. See the License for the
16 | specific language governing permissions and limitations
17 | under the License.
18 | */
19 |
20 | #define __CORDOVA_OSX__
21 |
22 | #define __CORDOVA_4_0_0 40000
23 | #define __CORDOVA_NA 99999 /* not available */
24 |
25 | /*
26 | #if CORDOVA_VERSION_MIN_REQUIRED >= __CORDOVA_4_0_0
27 | // do something when its at least 4.0.0
28 | #else
29 | // do something else (non 4.0.0)
30 | #endif
31 | */
32 | #ifndef CORDOVA_VERSION_MIN_REQUIRED
33 | #define CORDOVA_VERSION_MIN_REQUIRED __CORDOVA_4_0_0
34 | #endif
35 |
36 |
37 | /* Return the string version of the decimal version */
38 | #define CDV_VERSION [NSString stringWithFormat:@"%d.%d.%d", \
39 | (CORDOVA_VERSION_MIN_REQUIRED / 10000), \
40 | (CORDOVA_VERSION_MIN_REQUIRED % 10000) / 100, \
41 | (CORDOVA_VERSION_MIN_REQUIRED % 10000) % 100]
42 |
43 | #ifdef __clang__
44 | #define CDV_DEPRECATED(version, msg) __attribute__((deprecated("Deprecated in Cordova " #version ". " msg)))
45 | #else
46 | #define CDV_DEPRECATED(version, msg) __attribute__((deprecated()))
47 | #endif
48 |
49 | // Enable this to log all exec() calls.
50 | #define CDV_ENABLE_EXEC_LOGGING 0
51 | #if CDV_ENABLE_EXEC_LOGGING
52 | #define CDV_EXEC_LOG NSLog
53 | #else
54 | #define CDV_EXEC_LOG(...) do {} while (NO)
55 | #endif
56 | #define __CORDOVA_5_0_0 50000
57 | #define __CORDOVA_6_0_0 60000
58 | #define __CORDOVA_7_0_0 70000
59 |
--------------------------------------------------------------------------------
/tests/cdv-test-project/plugins/cordova-plugin-whitelist/plugin.xml:
--------------------------------------------------------------------------------
1 |
2 |
20 |
21 |
24 | Whitelist
25 | Cordova Network Whitelist Plugin
26 | Apache 2.0
27 | cordova,whitelist,policy
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 | This plugin is only applicable for versions of cordova-android greater than 4.0. If you have a previous platform version, you do *not* need this plugin since the whitelist will be built in.
48 |
49 |
50 |
51 |
52 |
53 |
54 |
--------------------------------------------------------------------------------
/tests/CordovaLibTests/CordovaLibApp/AppDelegate.m:
--------------------------------------------------------------------------------
1 | /*
2 | Licensed to the Apache Software Foundation (ASF) under one
3 | or more contributor license agreements. See the NOTICE file
4 | distributed with this work for additional information
5 | regarding copyright ownership. The ASF licenses this file
6 | to you under the Apache License, Version 2.0 (the
7 | "License"); you may not use this file except in compliance
8 | with the License. You may obtain a copy of the License at
9 |
10 | http://www.apache.org/licenses/LICENSE-2.0
11 |
12 | Unless required by applicable law or agreed to in writing,
13 | software distributed under the License is distributed on an
14 | "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 | KIND, either express or implied. See the License for the
16 | specific language governing permissions and limitations
17 | under the License.
18 | */
19 |
20 | #import "AppDelegate.h"
21 | #import "MainViewController.h"
22 |
23 | @implementation AppDelegate
24 |
25 |
26 | @synthesize viewController;
27 | @synthesize window;
28 |
29 | - (id)init{
30 | self = [super init];
31 | return self;
32 | }
33 |
34 | - (void)createViewController: (NSString*) startPage {
35 | NSAssert(!self.viewController, @"ViewController already created.");
36 | if (startPage == nil) {
37 | startPage = @"index.html";
38 | }
39 | self.viewController = [[MainViewController alloc] initWithWindowNibName:@"MainViewController"];
40 | self.viewController.wwwFolderName = @"www";
41 | self.viewController.startPage = startPage;
42 | [[self.viewController window] makeKeyAndOrderFront:self];
43 | }
44 |
45 | - (void)destroyViewController
46 | {
47 | [self.viewController close];
48 | self.viewController = nil;
49 | }
50 |
51 | - (void) applicationDidStartLaunching:(NSNotification*) aNotification {
52 | }
53 |
54 | - (void) applicationWillFinishLaunching:(NSNotification*)aNotification{
55 | }
56 |
57 | - (void) applicationDidFinishLaunching:(NSNotification*)aNotification {
58 | // Create the main view on start-up only when not running unit tests.
59 | Class testProbeClass = NSClassFromString(@"XCTestProbe");
60 | if (!testProbeClass) {
61 | testProbeClass = NSClassFromString(@"SenTestProbe");
62 | }
63 | if (!testProbeClass) {
64 | [self createViewController: nil];
65 | }
66 | }
67 |
68 | @end
69 |
--------------------------------------------------------------------------------
/tests/CordovaLibTests/CDVInvokedUrlCommandTests.m:
--------------------------------------------------------------------------------
1 | /*
2 | Licensed to the Apache Software Foundation (ASF) under one
3 | or more contributor license agreements. See the NOTICE file
4 | distributed with this work for additional information
5 | regarding copyright ownership. The ASF licenses this file
6 | to you under the Apache License, Version 2.0 (the
7 | "License"); you may not use this file except in compliance
8 | with the License. You may obtain a copy of the License at
9 |
10 | http://www.apache.org/licenses/LICENSE-2.0
11 |
12 | Unless required by applicable law or agreed to in writing,
13 | software distributed under the License is distributed on an
14 | "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 | KIND, either express or implied. See the License for the
16 | specific language governing permissions and limitations
17 | under the License.
18 | */
19 |
20 | #import
21 | #import
22 |
23 | #import
24 |
25 | @interface CDVInvokedUrlCommandTests : XCTestCase
26 | @end
27 |
28 | @implementation CDVInvokedUrlCommandTests
29 |
30 | - (void) testInitWithNoArgs {
31 | NSArray* jsonArr = @[@"callbackId", @"className", @"methodName", [NSArray array]];
32 | CDVInvokedUrlCommand* command = [CDVInvokedUrlCommand commandFromJson:jsonArr];
33 |
34 | XCTAssertEqual(@"callbackId", command.callbackId);
35 | XCTAssertEqual(@"className", command.cmdClassName);
36 | XCTAssertEqual(@"methodName", command.methodName);
37 | XCTAssertEqual([NSArray array], command.arguments);
38 | }
39 |
40 | - (void) testArgumentAtIndex {
41 | NSArray* arguments = @[[NSNull null], [WebUndefined undefined]];
42 | NSArray* jsonArr = @[[NSNull null], @"className", @"methodName", arguments];
43 | CDVInvokedUrlCommand* command = [CDVInvokedUrlCommand commandFromJson:jsonArr];
44 |
45 | XCTAssertNil([command argumentAtIndex:0], @"NSNull to nil");
46 | XCTAssertNil([command argumentAtIndex:1], @"WebUndefined to nil");
47 | XCTAssertNil([command argumentAtIndex:100], @"Invalid index to nil");
48 | XCTAssertEqual(@"default", [command argumentAtIndex:0 withDefault:@"default"], @"NSNull to default");
49 | XCTAssertEqual(@"default", [command argumentAtIndex:1 withDefault:@"default"], @"WebUndefined to default");
50 | XCTAssertEqual(@"default", [command argumentAtIndex:100 withDefault:@"default"], @"Invalid index to default");
51 | }
52 |
53 | @end
54 |
--------------------------------------------------------------------------------
/CordovaLib/CordovaLib/Classes/Commands/CDVPlugin.h:
--------------------------------------------------------------------------------
1 | /*
2 | Licensed to the Apache Software Foundation (ASF) under one
3 | or more contributor license agreements. See the NOTICE file
4 | distributed with this work for additional information
5 | regarding copyright ownership. The ASF licenses this file
6 | to you under the Apache License, Version 2.0 (the
7 | "License"); you may not use this file except in compliance
8 | with the License. You may obtain a copy of the License at
9 |
10 | http://www.apache.org/licenses/LICENSE-2.0
11 |
12 | Unless required by applicable law or agreed to in writing,
13 | software distributed under the License is distributed on an
14 | "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 | KIND, either express or implied. See the License for the
16 | specific language governing permissions and limitations
17 | under the License.
18 | */
19 |
20 | #import
21 | #import
22 | #import "CDVPluginResult.h"
23 | #import "CDVCommandDelegate.h"
24 | #import "CDVViewController.h"
25 |
26 | #pragma clang diagnostic push
27 | #pragma ide diagnostic ignored "OCUnusedPropertyInspection"
28 | #pragma ide diagnostic ignored "OCUnusedGlobalDeclarationInspection"
29 | #pragma ide diagnostic ignored "OCUnusedMethodInspection"
30 |
31 | extern NSString* const CDVPageDidLoadNotification;
32 | extern NSString* const CDVPluginHandleOpenURLNotification;
33 | extern NSString* const CDVPluginResetNotification;
34 | extern NSString* const CDVLocalNotification;
35 |
36 | @interface CDVPlugin : NSObject {}
37 |
38 | @property (nonatomic, weak) WebView* webView;
39 | @property (nonatomic, unsafe_unretained) CDVViewController* viewController;
40 | @property (nonatomic, unsafe_unretained) id commandDelegate;
41 |
42 | @property (readonly, assign) BOOL hasPendingOperation;
43 |
44 | - (CDVPlugin*)initWithWebView:(WebView*)theWebView;
45 | - (void)pluginInitialize;
46 |
47 | - (void)handleOpenURL:(NSNotification*)notification;
48 | - (void)onAppTerminate;
49 | - (void)onMemoryWarning;
50 | - (void)onReset;
51 | - (void)dispose;
52 |
53 | /*
54 | // see initWithWebView implementation
55 | - (void) onPause {}
56 | - (void) onResume {}
57 | - (void) onOrientationWillChange {}
58 | - (void) onOrientationDidChange {}
59 | - (void)didReceiveLocalNotification:(NSNotification *)notification;
60 | */
61 |
62 | - (id)appDelegate;
63 |
64 | @end
65 |
66 | #pragma clang diagnostic pop
67 |
--------------------------------------------------------------------------------
/CordovaLib/CordovaLib/Classes/Commands/CDVInvokedUrlCommand.h:
--------------------------------------------------------------------------------
1 | /*
2 | Licensed to the Apache Software Foundation (ASF) under one
3 | or more contributor license agreements. See the NOTICE file
4 | distributed with this work for additional information
5 | regarding copyright ownership. The ASF licenses this file
6 | to you under the Apache License, Version 2.0 (the
7 | "License"); you may not use this file except in compliance
8 | with the License. You may obtain a copy of the License at
9 |
10 | http://www.apache.org/licenses/LICENSE-2.0
11 |
12 | Unless required by applicable law or agreed to in writing,
13 | software distributed under the License is distributed on an
14 | "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 | KIND, either express or implied. See the License for the
16 | specific language governing permissions and limitations
17 | under the License.
18 | */
19 |
20 | #import
21 |
22 | #pragma clang diagnostic push
23 | #pragma ide diagnostic ignored "OCUnusedPropertyInspection"
24 |
25 | @interface CDVInvokedUrlCommand : NSObject {
26 | NSString* _callbackId;
27 | NSString* _cmdClassName;
28 | NSString* _methodName;
29 | NSArray* _arguments;
30 | }
31 |
32 | @property(nonatomic, readonly) NSArray* arguments;
33 | @property(nonatomic, readonly) NSString* callbackId;
34 | @property(nonatomic, readonly) NSString* cmdClassName;
35 | @property(nonatomic, readonly) NSString* methodName;
36 |
37 | + (CDVInvokedUrlCommand*) commandFromJson:(NSArray*) jsonEntry;
38 |
39 | - (id) initWithArguments:(NSArray*) arguments
40 | callbackId:(NSString*) callbackId
41 | className:(NSString*) className
42 | methodName:(NSString*) methodName;
43 |
44 | - (id) initFromJson:(NSArray*) jsonEntry;
45 |
46 | /**
47 | * Returns the argument at the given index.
48 | * If index >= the number of arguments, returns nil.
49 | * If the argument at the given index is NSNull, returns nil.
50 | */
51 | - (id) argumentAtIndex:(NSUInteger) index;
52 |
53 | /**
54 | * Same as above, but returns defaultValue instead of nil.
55 | */
56 | - (id) argumentAtIndex:(NSUInteger) index withDefault:(id) defaultValue;
57 |
58 | /**
59 | * Same as above, but returns defaultValue instead of nil, and if the argument is not of the expected class, returns defaultValue
60 | */
61 | - (id) argumentAtIndex:(NSUInteger) index withDefault:(id) defaultValue andClass:(Class) aClass;
62 |
63 | @end
64 |
65 | #pragma clang diagnostic pop
66 |
--------------------------------------------------------------------------------
/tests/CordovaLibTests/CordovaLibApp/config.xml:
--------------------------------------------------------------------------------
1 |
2 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 | TestApp
40 |
41 | A sample Apache Cordova application that responds to the deviceready event.
42 |
43 |
44 | Apache Cordova Team
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
--------------------------------------------------------------------------------
/tests/spec/component/create.spec.js:
--------------------------------------------------------------------------------
1 | /*
2 | Licensed to the Apache Software Foundation (ASF) under one
3 | or more contributor license agreements. See the NOTICE file
4 | distributed with this work for additional information
5 | regarding copyright ownership. The ASF licenses this file
6 | to you under the Apache License, Version 2.0 (the
7 | "License"); you may not use this file except in compliance
8 | with the License. You may obtain a copy of the License at
9 |
10 | http://www.apache.org/licenses/LICENSE-2.0
11 |
12 | Unless required by applicable law or agreed to in writing,
13 | software distributed under the License is distributed on an
14 | "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 | KIND, either express or implied. See the License for the
16 | specific language governing permissions and limitations
17 | under the License.
18 | */
19 |
20 | const shell = require('shelljs');
21 | const path = require('path');
22 | const util = require('util');
23 | const fs = require('fs');
24 | const tmp = require('tmp').dirSync().name;
25 |
26 | const cordova_bin = path.join(__dirname, '../../..', 'bin');
27 |
28 | function initProjectPath (projectname) {
29 | // remove existing folder
30 | const pPath = path.join(tmp, projectname);
31 | shell.rm('-rf', pPath);
32 | return pPath;
33 | }
34 |
35 | function createProject (projectname, projectid) {
36 | const projectPath = initProjectPath(projectname);
37 |
38 | // create the project
39 | const command = util.format('"%s/create" "%s/%s" %s "%s"', cordova_bin, tmp, projectname, projectid, projectname);
40 | shell.echo(command);
41 |
42 | const return_code = shell.exec(command).code;
43 | expect(return_code).toBe(0);
44 | expect(fs.existsSync(projectPath)).toBe(true);
45 |
46 | console.log('created project at %s', projectPath);
47 | return projectPath;
48 | }
49 |
50 | function createAndBuild (projectname, projectid) {
51 | const projectPath = createProject(projectname, projectid);
52 |
53 | // build the project
54 | const command = util.format('"%s/cordova/build"', path.join(tmp, projectname));
55 | shell.echo(command);
56 |
57 | const return_code = shell.exec(command, { silent: true }).code;
58 | expect(return_code).toBe(0);
59 |
60 | // clean-up
61 | shell.rm('-rf', projectPath);
62 | }
63 |
64 | describe('create', () => {
65 | it('create project with ascii+unicode name, and spaces', () => {
66 | const projectname = '応応応応 hello 用用用用';
67 | const projectid = 'com.test.app6';
68 |
69 | createAndBuild(projectname, projectid);
70 | });
71 | });
72 |
--------------------------------------------------------------------------------
/bin/templates/project/www/spec.html:
--------------------------------------------------------------------------------
1 |
2 |
20 |
21 |
22 | Jasmine Spec Runner
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
64 |
65 |
66 |
67 |
68 |
69 |
--------------------------------------------------------------------------------
/tests/cdv-test-project/www/index.html:
--------------------------------------------------------------------------------
1 |
2 |
20 |
21 |
22 |
31 |
32 |
33 |
34 |
35 |
36 | Hello World
37 |
38 |
39 |
40 |
Apache Cordova
41 |
42 |
Connecting to Device
43 |
Device is Ready
44 |
45 |
46 |
47 |
48 |
49 |
50 |
--------------------------------------------------------------------------------
/bin/create:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env node
2 |
3 | /*
4 | Licensed to the Apache Software Foundation (ASF) under one
5 | or more contributor license agreements. See the NOTICE file
6 | distributed with this work for additional information
7 | regarding copyright ownership. The ASF licenses this file
8 | to you under the Apache License, Version 2.0 (the
9 | "License"); you may not use this file except in compliance
10 | with the License. You may obtain a copy of the License at
11 |
12 | http://www.apache.org/licenses/LICENSE-2.0
13 |
14 | Unless required by applicable law or agreed to in writing,
15 | software distributed under the License is distributed on an
16 | "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17 | KIND, either express or implied. See the License for the
18 | specific language governing permissions and limitations
19 | under the License.
20 | */
21 |
22 | /*
23 | * create a Cordova/OSX project
24 | *
25 | * USAGE
26 | * ./create
27 | *
28 | * EXAMPLE
29 | * ./create ~/Desktop/radness org.apache.cordova.radness Radness
30 | */
31 |
32 | const path = require('path');
33 | const ConfigParser = require('cordova-common').ConfigParser;
34 | const Api = require('./templates/scripts/cordova/Api');
35 |
36 | const argv = require('nopt')({
37 | help: Boolean,
38 | link: Boolean
39 | });
40 |
41 | const projectPath = argv.argv.remain[0];
42 |
43 | if (argv.help || !projectPath) {
44 | console.log('Usage: $0 [--link] []');
45 | console.log(' --link (optional): Link directly against the shared copy of the CordovaLib instead of a copy of it.');
46 | console.log(' : Path to your new Cordova OSX project');
47 | console.log(' : Package name, following reverse-domain style convention');
48 | console.log(' : Project name');
49 | console.log(' : Path to project template (override).');
50 | process.exit(0);
51 | }
52 |
53 | // use default configuration file from project template
54 | const config = new ConfigParser(path.resolve(__dirname, 'templates/project/__PROJECT_NAME__/config.xml'));
55 |
56 | // apply overrides (package and project names
57 | if (argv.argv.remain[1]) config.setPackageName(argv.argv.remain[1]);
58 | if (argv.argv.remain[2]) config.setName(argv.argv.remain[2]);
59 |
60 | const options = {
61 | link: argv.link,
62 | customTemplate: argv.argv.remain[3]
63 | };
64 |
65 | Api.createPlatform(projectPath, config, options).catch(err => {
66 | console.error(err);
67 | process.exit(2);
68 | });
69 |
--------------------------------------------------------------------------------
/bin/templates/scripts/cordova/lib/run.js:
--------------------------------------------------------------------------------
1 | /*
2 | Licensed to the Apache Software Foundation (ASF) under one
3 | or more contributor license agreements. See the NOTICE file
4 | distributed with this work for additional information
5 | regarding copyright ownership. The ASF licenses this file
6 | to you under the Apache License, Version 2.0 (the
7 | "License"); you may not use this file except in compliance
8 | with the License. You may obtain a copy of the License at
9 |
10 | http://www.apache.org/licenses/LICENSE-2.0
11 |
12 | Unless required by applicable law or agreed to in writing,
13 | software distributed under the License is distributed on an
14 | "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 | KIND, either express or implied. See the License for the
16 | specific language governing permissions and limitations
17 | under the License.
18 | */
19 |
20 | /* jshint node: true */
21 |
22 | const path = require('path');
23 | const build = require('./build');
24 | const spawn = require('./spawn');
25 | const events = require('cordova-common').events;
26 |
27 | const projectPath = path.join(__dirname, '..', '..');
28 |
29 | module.exports.run = function (runOptions) {
30 | return Promise.resolve().then(function () {
31 | if (!runOptions.nobuild) {
32 | return build.run(runOptions);
33 | }
34 | }).then(function () {
35 | return build.findXCodeProjectIn(projectPath);
36 | }).then(function (projectName) {
37 | const appPath = path.join(projectPath, 'build', projectName + '.app');
38 | return runApp(appPath, projectName);
39 | });
40 | };
41 |
42 | /**
43 | * runs the app
44 | * @return {Promise} Resolves when run succeeds otherwise rejects
45 | */
46 | function runApp (appDir, appName) {
47 | const binPath = path.join(appDir, 'Contents', 'MacOS', appName);
48 | events.emit('log', 'Starting: ' + binPath);
49 | return spawn(binPath);
50 | }
51 |
52 | module.exports.help = function () {
53 | console.log('\nUsage: run [ --debug | --release | --nobuild ]');
54 | console.log(' --debug : Builds project in debug mode. (Passed down to build command, if necessary)');
55 | console.log(' --release : Builds project in release mode. (Passed down to build command, if necessary)');
56 | console.log(' --nobuild : Uses pre-built package, or errors if project is not built.');
57 | console.log('');
58 | console.log('Examples:');
59 | console.log(' run');
60 | console.log(' run --release');
61 | console.log(' run --debug');
62 | console.log('');
63 | process.exit(0);
64 | };
65 |
--------------------------------------------------------------------------------
/CordovaLib/CordovaLib/Classes/Commands/CDVCommandDelegate.h:
--------------------------------------------------------------------------------
1 | /*
2 | Licensed to the Apache Software Foundation (ASF) under one
3 | or more contributor license agreements. See the NOTICE file
4 | distributed with this work for additional information
5 | regarding copyright ownership. The ASF licenses this file
6 | to you under the Apache License, Version 2.0 (the
7 | "License"); you may not use this file except in compliance
8 | with the License. You may obtain a copy of the License at
9 |
10 | http://www.apache.org/licenses/LICENSE-2.0
11 |
12 | Unless required by applicable law or agreed to in writing,
13 | software distributed under the License is distributed on an
14 | "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 | KIND, either express or implied. See the License for the
16 | specific language governing permissions and limitations
17 | under the License.
18 | */
19 |
20 | #import "CDVAvailability.h"
21 | #import "CDVInvokedUrlCommand.h"
22 |
23 | #pragma clang diagnostic push
24 | #pragma ide diagnostic ignored "OCUnusedPropertyInspection"
25 | #pragma ide diagnostic ignored "OCUnusedMethodInspection"
26 |
27 | @class CDVPlugin;
28 | @class CDVPluginResult;
29 |
30 | @protocol CDVCommandDelegate
31 |
32 | @property (nonatomic, readonly) NSDictionary* settings;
33 |
34 | /**
35 | * Resolves the path for a given resource.
36 | */
37 | - (NSString*) pathForResource:(NSString*) resourcepath;
38 |
39 | /**
40 | * Returns the command instance for the given plugin name
41 | */
42 | - (id) getCommandInstance:(NSString*) pluginName;
43 |
44 | /**
45 | * Sends a plugin result to the JS. This is thread-safe.
46 | */
47 | - (void) sendPluginResult:(CDVPluginResult*) result callbackId:(NSString*) callbackId;
48 |
49 | /**
50 | * Evaluates the given JS. This is thread-safe.
51 | */
52 | - (void) evalJs:(NSString*) js;
53 |
54 | /**
55 | * Can be used to evaluate JS right away instead of scheduling it on the run-loop.
56 | * This is required for dispatch resign and pause events, but should not be used
57 | * without reason. Without the run-loop delay, alerts used in JS callbacks may result
58 | * in dead-lock. This method must be called from the UI thread.
59 | */
60 | - (void) evalJs:(NSString*) js scheduledOnRunLoop:(BOOL) scheduledOnRunLoop;
61 |
62 | /**
63 | * Runs the given block on a background thread using a shared thread-pool.
64 | */
65 | - (void) runInBackground:(void (^)()) block;
66 |
67 | /**
68 | * Returns the User-Agent of the associated UIWebView.
69 | */
70 | - (NSString*) userAgent;
71 |
72 | /**
73 | * Returns whether the given URL passes the white-list.
74 | */
75 | - (BOOL) URLIsWhitelisted:(NSURL*) url;
76 |
77 | @end
78 |
79 | #pragma clang diagnostic pop
80 |
--------------------------------------------------------------------------------
/CordovaLib/CordovaLib/Classes/Commands/CDVWindowSizeCommand.m:
--------------------------------------------------------------------------------
1 | /*
2 | Licensed to the Apache Software Foundation (ASF) under one
3 | or more contributor license agreements. See the NOTICE file
4 | distributed with this work for additional information
5 | regarding copyright ownership. The ASF licenses this file
6 | to you under the Apache License, Version 2.0 (the
7 | "License"); you may not use this file except in compliance
8 | with the License. You may obtain a copy of the License at
9 |
10 | http://www.apache.org/licenses/LICENSE-2.0
11 |
12 | Unless required by applicable law or agreed to in writing,
13 | software distributed under the License is distributed on an
14 | "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 | KIND, either express or implied. See the License for the
16 | specific language governing permissions and limitations
17 | under the License.
18 | */
19 |
20 | #import "CDVWindowSizeCommand.h"
21 | #import "NSScreen+Utils.h"
22 |
23 | @implementation CDVWindowSizeCommand {
24 | }
25 |
26 | static NSRect savedFrameRect;
27 |
28 | /**
29 | * Makes the window fullscreen by resizing it to the size of all attached displays. This is different from just entering
30 | * normal OSX fullscreen mode which only covers the main display.
31 | */
32 | + (void) makeFullScreen:(NSWindow*) window {
33 | NSRect fullScreenRect = [NSScreen fullScreenRect];
34 | NSLog(@"Full screen resolution: %.f x %.f", fullScreenRect.size.width, fullScreenRect.size.height);
35 | [window setStyleMask:window.styleMask & ~NSTitledWindowMask];
36 | [window setHidesOnDeactivate:YES];
37 | [window setLevel:NSMainMenuWindowLevel + 1];
38 | savedFrameRect = window.frame;
39 | [window setFrame:fullScreenRect display:YES];
40 | }
41 |
42 | /**
43 | * Takes the window off fullscreen mode.
44 | */
45 | + (void) removeFullScreen:(NSWindow*) window {
46 | [window setStyleMask:window.styleMask | NSTitledWindowMask];
47 | [window setHidesOnDeactivate:NO];
48 | [window setLevel:NSNormalWindowLevel];
49 | [window setFrame:savedFrameRect display:YES];
50 | }
51 |
52 | /**
53 | * Toggles fullscreen mode of the window.
54 | */
55 | + (void) toggleFullScreen:(NSWindow*) window {
56 | if ((window.styleMask & NSTitledWindowMask) == NSTitledWindowMask) {
57 | [CDVWindowSizeCommand makeFullScreen:window];
58 | } else {
59 | [CDVWindowSizeCommand removeFullScreen:window];
60 | }
61 | }
62 |
63 | + (void) setSizeOfWindow:(NSWindow*) window size:(NSSize) size {
64 | NSLog(@"Set window size to %.f x %.f", size.width, size.height);
65 | NSRect frameRect = window.frame;
66 | frameRect.size = size;
67 | [window setFrame:frameRect display:YES];
68 | }
69 |
70 | @end
71 |
--------------------------------------------------------------------------------
/CordovaLib/CordovaLib/Classes/Commands/CDVJSON.m:
--------------------------------------------------------------------------------
1 | /*
2 | Licensed to the Apache Software Foundation (ASF) under one
3 | or more contributor license agreements. See the NOTICE file
4 | distributed with this work for additional information
5 | regarding copyright ownership. The ASF licenses this file
6 | to you under the Apache License, Version 2.0 (the
7 | "License"); you may not use this file except in compliance
8 | with the License. You may obtain a copy of the License at
9 |
10 | http://www.apache.org/licenses/LICENSE-2.0
11 |
12 | Unless required by applicable law or agreed to in writing,
13 | software distributed under the License is distributed on an
14 | "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 | KIND, either express or implied. See the License for the
16 | specific language governing permissions and limitations
17 | under the License.
18 | */
19 |
20 | #import "CDVJSON.h"
21 |
22 | @implementation NSArray (CDVJSONSerializing)
23 |
24 | - (NSString*) JSONString {
25 | NSError* error = nil;
26 | NSData* jsonData = [NSJSONSerialization dataWithJSONObject:self
27 | options:NSJSONWritingPrettyPrinted
28 | error:&error];
29 |
30 | if (error != nil) {
31 | NSLog(@"NSArray JSONString error: %@", [error localizedDescription]);
32 | return nil;
33 | } else {
34 | return [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
35 | }
36 | }
37 |
38 | @end
39 |
40 | @implementation NSDictionary (CDVJSONSerializing)
41 |
42 | - (NSString*) JSONString {
43 | NSError* error = nil;
44 | NSData* jsonData = [NSJSONSerialization dataWithJSONObject:self
45 | options:NSJSONWritingPrettyPrinted
46 | error:&error];
47 |
48 | if (error != nil) {
49 | NSLog(@"NSDictionary JSONString error: %@", [error localizedDescription]);
50 | return nil;
51 | } else {
52 | return [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
53 | }
54 | }
55 |
56 | @end
57 |
58 | @implementation NSString (CDVJSONSerializing)
59 |
60 | - (id) JSONObject {
61 | NSError* error = nil;
62 | id object = [NSJSONSerialization JSONObjectWithData:[self dataUsingEncoding:NSUTF8StringEncoding]
63 | options:kNilOptions
64 | error:&error];
65 |
66 | if (error != nil) {
67 | NSLog(@"NSString JSONObject error: %@", [error localizedDescription]);
68 | }
69 |
70 | return object;
71 | }
72 |
73 | @end
74 |
--------------------------------------------------------------------------------
/CordovaLib/CordovaLib/Classes/Commands/CDVConsole.m:
--------------------------------------------------------------------------------
1 | /*
2 | Licensed to the Apache Software Foundation (ASF) under one
3 | or more contributor license agreements. See the NOTICE file
4 | distributed with this work for additional information
5 | regarding copyright ownership. The ASF licenses this file
6 | to you under the Apache License, Version 2.0 (the
7 | "License"); you may not use this file except in compliance
8 | with the License. You may obtain a copy of the License at
9 |
10 | http://www.apache.org/licenses/LICENSE-2.0
11 |
12 | Unless required by applicable law or agreed to in writing,
13 | software distributed under the License is distributed on an
14 | "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 | KIND, either express or implied. See the License for the
16 | specific language governing permissions and limitations
17 | under the License.
18 | */
19 |
20 | #import "CDVConsole.h"
21 |
22 |
23 | @implementation CDVConsole
24 |
25 |
26 | - (void) log:(NSString*) message {
27 | NSLog(@"%@", message);
28 | }
29 |
30 | - (void) trace:(NSString*) message {
31 | NSLog(@"trace: %@", message);
32 | }
33 |
34 | - (void) debug:(NSString*) message {
35 | NSLog(@"debug: %@", message);
36 | }
37 |
38 | - (void) info:(NSString*) message {
39 | NSLog(@"info: %@", message);
40 | }
41 |
42 | - (void) warn:(NSString*) message {
43 | NSLog(@"warn: %@", message);
44 | }
45 |
46 | - (void) error:(NSString*) message {
47 | NSLog(@"error: %@", message);
48 | }
49 |
50 | #pragma mark WebScripting Protocol
51 |
52 | /* checks whether a selector is acceptable to be called from JavaScript */
53 | + (BOOL) isSelectorExcludedFromWebScript:(SEL) sel {
54 | return sel != @selector(log:) &&
55 | sel != @selector(trace:) &&
56 | sel != @selector(debug:) &&
57 | sel != @selector(info:) &&
58 | sel != @selector(warn:) &&
59 | sel != @selector(error:);
60 | }
61 |
62 | /* helper function so we don't have to have underscores and stuff in js to refer to the right method */
63 | + (NSString*) webScriptNameForSelector:(SEL) sel {
64 | if (sel == @selector(log:)) {
65 | return @"log";
66 | } else if (sel == @selector(trace:)) {
67 | return @"trace";
68 | } else if (sel == @selector(debug:)) {
69 | return @"debug";
70 | } else if (sel == @selector(info:)) {
71 | return @"info";
72 | } else if (sel == @selector(warn:)) {
73 | return @"warn";
74 | } else if (sel == @selector(error:)) {
75 | return @"error";
76 | } else {
77 | return nil;
78 | }
79 | }
80 |
81 | // right now exclude all properties (eg keys)
82 | + (BOOL) isKeyExcludedFromWebScript:(const char*) name {
83 | return YES;
84 | }
85 |
86 | @end
87 |
--------------------------------------------------------------------------------
/CordovaLib/CordovaLib/Classes/Utils/NSWindow+Utils.m:
--------------------------------------------------------------------------------
1 | /*
2 | Licensed to the Apache Software Foundation (ASF) under one
3 | or more contributor license agreements. See the NOTICE file
4 | distributed with this work for additional information
5 | regarding copyright ownership. The ASF licenses this file
6 | to you under the Apache License, Version 2.0 (the
7 | "License"); you may not use this file except in compliance
8 | with the License. You may obtain a copy of the License at
9 |
10 | http://www.apache.org/licenses/LICENSE-2.0
11 |
12 | Unless required by applicable law or agreed to in writing,
13 | software distributed under the License is distributed on an
14 | "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 | KIND, either express or implied. See the License for the
16 | specific language governing permissions and limitations
17 | under the License.
18 | */
19 |
20 |
21 | #import
22 | #import "NSWindow+Utils.h"
23 |
24 | #define KEY_LEVEL_LOCKED @"level_lock"
25 |
26 | @implementation NSWindow (Utils)
27 |
28 |
29 | + (NSWindow*) instance {
30 | static NSWindow* _instance = nil;
31 |
32 | @synchronized (self) {
33 | if (_instance == nil) {
34 | _instance = [[self alloc] init];
35 | }
36 | }
37 |
38 | return _instance;
39 | }
40 |
41 | - (float) titleBarHeight {
42 | NSRect frame = [self frame];
43 | NSRect contentRect = [NSWindow contentRectForFrameRect: frame
44 | styleMask: NSTitledWindowMask];
45 |
46 | return (float) (frame.size.height - contentRect.size.height);
47 | }
48 |
49 | - (NSMutableDictionary*) props {
50 | NSMutableDictionary* p = objc_getAssociatedObject(self, @selector(props));
51 | if (p == nil) {
52 | p = [NSMutableDictionary dictionary];
53 | p[KEY_LEVEL_LOCKED] = @NO;
54 | objc_setAssociatedObject(self, @selector(props), p, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
55 | }
56 | return p;
57 | }
58 |
59 | - (bool) getIsLevelLocked {
60 | NSMutableDictionary* p = [self props];
61 | return [@YES isEqualTo:p[KEY_LEVEL_LOCKED]];
62 | }
63 |
64 | - (void) setIsLevelLocked:(bool) lock {
65 | NSMutableDictionary* p = [self props];
66 | p[KEY_LEVEL_LOCKED] = lock ? @YES : @NO;
67 | }
68 |
69 | - (void) swizzled_setLevel: (NSInteger) level {
70 | if ([self getIsLevelLocked]) {
71 | return;
72 | }
73 |
74 | #pragma clang diagnostic push
75 | #pragma ide diagnostic ignored "InfiniteRecursion"
76 | [self swizzled_setLevel:level];
77 | #pragma clang diagnostic pop
78 | }
79 |
80 | + (void)load {
81 | Method original, swizzled;
82 |
83 | original = class_getInstanceMethod(self, @selector(setLevel:));
84 | swizzled = class_getInstanceMethod(self, @selector(swizzled_setLevel:));
85 | method_exchangeImplementations(original, swizzled);
86 | }
87 |
88 | @end
89 |
--------------------------------------------------------------------------------
/bin/templates/project/www/spec/index.js:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed to the Apache Software Foundation (ASF) under one
3 | * or more contributor license agreements. See the NOTICE file
4 | * distributed with this work for additional information
5 | * regarding copyright ownership. The ASF licenses this file
6 | * to you under the Apache License, Version 2.0 (the
7 | * "License"); you may not use this file except in compliance
8 | * with the License. You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing,
13 | * software distributed under the License is distributed on an
14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 | * KIND, either express or implied. See the License for the
16 | * specific language governing permissions and limitations
17 | * under the License.
18 | */
19 | describe('app', function () {
20 | describe('initialize', function () {
21 | it('should bind deviceready', function () {
22 | runs(function () {
23 | spyOn(app, 'onDeviceReady');
24 | app.initialize();
25 | helper.trigger(window.document, 'deviceready');
26 | });
27 |
28 | waitsFor(function () {
29 | return (app.onDeviceReady.calls.length > 0);
30 | }, 'onDeviceReady should be called once', 500);
31 |
32 | runs(function () {
33 | expect(app.onDeviceReady).toHaveBeenCalled();
34 | });
35 | });
36 | });
37 |
38 | describe('onDeviceReady', function () {
39 | it('should report that it fired', function () {
40 | spyOn(app, 'receivedEvent');
41 | app.onDeviceReady();
42 | expect(app.receivedEvent).toHaveBeenCalledWith('deviceready');
43 | });
44 | });
45 |
46 | describe('receivedEvent', function () {
47 | beforeEach(function () {
48 | var el = document.getElementById('stage');
49 | el.innerHTML = ['
',
50 | '
Listening
',
51 | '
Received
',
52 | '
'].join('\n');
53 | });
54 |
55 | it('should hide the listening element', function () {
56 | app.receivedEvent('deviceready');
57 | var displayStyle = helper.getComputedStyle('#deviceready .listening', 'display');
58 | expect(displayStyle).toEqual('none');
59 | });
60 |
61 | it('should show the received element', function () {
62 | app.receivedEvent('deviceready');
63 | var displayStyle = helper.getComputedStyle('#deviceready .received', 'display');
64 | expect(displayStyle).toEqual('block');
65 | });
66 | });
67 | });
68 |
--------------------------------------------------------------------------------
/bin/templates/scripts/cordova/lib/copy-www-build-step.js:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env node
2 |
3 | /*
4 | Licensed to the Apache Software Foundation (ASF) under one
5 | or more contributor license agreements. See the NOTICE file
6 | distributed with this work for additional information
7 | regarding copyright ownership. The ASF licenses this file
8 | to you under the Apache License, Version 2.0 (the
9 | "License"); you may not use this file except in compliance
10 | with the License. You may obtain a copy of the License at
11 |
12 | http://www.apache.org/licenses/LICENSE-2.0
13 |
14 | Unless required by applicable law or agreed to in writing,
15 | software distributed under the License is distributed on an
16 | "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17 | KIND, either express or implied. See the License for the
18 | specific language governing permissions and limitations
19 | under the License.
20 | */
21 |
22 | // This script copies the www directory into the Xcode project.
23 |
24 | // This script should not be called directly.
25 | // It is called as a build step from Xcode.
26 |
27 | const BUILT_PRODUCTS_DIR = process.env.BUILT_PRODUCTS_DIR;
28 | const FULL_PRODUCT_NAME = process.env.FULL_PRODUCT_NAME;
29 | const COPY_HIDDEN = process.env.COPY_HIDDEN;
30 | const PROJECT_FILE_PATH = process.env.PROJECT_FILE_PATH;
31 |
32 | const path = require('path');
33 | const fs = require('fs');
34 | const shell = require('shelljs');
35 | const srcDir = 'www';
36 | const dstDir = path.join(BUILT_PRODUCTS_DIR, FULL_PRODUCT_NAME, 'Contents', 'Resources');
37 | const dstWwwDir = path.join(dstDir, 'www');
38 |
39 | if (!BUILT_PRODUCTS_DIR) {
40 | console.error('The script is meant to be run as an Xcode build step and relies on env variables set by Xcode.');
41 | process.exit(1);
42 | }
43 |
44 | try {
45 | fs.statSync(srcDir);
46 | } catch (e) {
47 | console.error('Path does not exist: ' + srcDir);
48 | process.exit(2);
49 | }
50 |
51 | // Code signing files must be removed or else there are
52 | // resource signing errors.
53 | shell.rm('-rf', dstWwwDir);
54 | shell.rm('-rf', path.join(dstDir, '_CodeSignature'));
55 | shell.rm('-rf', path.join(dstDir, 'PkgInfo'));
56 | shell.rm('-rf', path.join(dstDir, 'embedded.mobileprovision'));
57 |
58 | // Copy www dir recursively
59 | let code;
60 | if (COPY_HIDDEN) {
61 | code = shell.exec('rsync -Lra "' + srcDir + '" "' + dstDir + '"').code;
62 | } else {
63 | code = shell.exec('rsync -Lra --exclude="- .*" "' + srcDir + '" "' + dstDir + '"').code;
64 | }
65 |
66 | if (code !== 0) {
67 | console.error('Error occurred on copying www. Code: ' + code);
68 | process.exit(3);
69 | }
70 |
71 | // Copy the config.xml file.
72 | shell.cp('-f', path.join(path.dirname(PROJECT_FILE_PATH), path.basename(PROJECT_FILE_PATH, '.xcodeproj'), 'config.xml'),
73 | dstDir);
74 |
--------------------------------------------------------------------------------
/bin/templates/scripts/cordova/lib/ConsoleLogger.js:
--------------------------------------------------------------------------------
1 | /**
2 | Licensed to the Apache Software Foundation (ASF) under one
3 | or more contributor license agreements. See the NOTICE file
4 | distributed with this work for additional information
5 | regarding copyright ownership. The ASF licenses this file
6 | to you under the Apache License, Version 2.0 (the
7 | "License"); you may not use this file except in compliance
8 | with the License. You may obtain a copy of the License at
9 |
10 | http://www.apache.org/licenses/LICENSE-2.0
11 |
12 | Unless required by applicable law or agreed to in writing,
13 | software distributed under the License is distributed on an
14 | "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 | KIND, either express or implied. See the License for the
16 | specific language governing permissions and limitations
17 | under the License.
18 | */
19 |
20 | let loggerInstance;
21 | const util = require('util');
22 | const EventEmitter = require('events').EventEmitter;
23 | const CordovaError = require('cordova-common').CordovaError;
24 |
25 | /**
26 | * @class ConsoleLogger
27 | * @extends EventEmitter
28 | *
29 | * Implementing basic logging for platform. Inherits regular NodeJS
30 | * EventEmitter. All events, emitted on this class instance are immediately
31 | * logged to console.
32 | *
33 | * Also attaches handler to process' uncaught exceptions, so these exceptions
34 | * logged to console similar to regular error events.
35 | */
36 | function ConsoleLogger () {
37 | EventEmitter.call(this);
38 |
39 | const isVerbose = process.argv.indexOf('-d') >= 0 || process.argv.indexOf('--verbose') >= 0;
40 | // For CordovaError print only the message without stack trace unless we
41 | // are in a verbose mode.
42 | process.on('uncaughtException', function (err) {
43 | if ((err instanceof CordovaError) && isVerbose) {
44 | console.error(err.stack);
45 | } else {
46 | console.error(err.message);
47 | }
48 | process.exit(1);
49 | });
50 |
51 | this.on('results', console.log);
52 | this.on('verbose', function () {
53 | if (isVerbose) { console.log.apply(console, arguments); }
54 | });
55 | this.on('info', console.log);
56 | this.on('log', console.log);
57 | this.on('warn', console.warn);
58 | }
59 | util.inherits(ConsoleLogger, EventEmitter);
60 |
61 | /**
62 | * Returns already instantiated/newly created instance of ConsoleLogger class.
63 | * This method should be used instead of creating ConsoleLogger directly,
64 | * otherwise we'll get multiple handlers attached to process'
65 | * uncaughtException
66 | *
67 | * @return {ConsoleLogger} New or already created instance of ConsoleLogger
68 | */
69 | ConsoleLogger.get = function () {
70 | loggerInstance = loggerInstance || new ConsoleLogger();
71 | return loggerInstance;
72 | };
73 |
74 | module.exports = ConsoleLogger;
75 |
--------------------------------------------------------------------------------
/bin/templates/project/__PROJECT_NAME__/config.xml:
--------------------------------------------------------------------------------
1 |
2 |
18 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 | __PROJECT_NAME__
47 | __CDV_ORGANIZATION_NAME__
48 |
49 | A sample Apache Cordova application that responds to the deviceready event.
50 |
51 |
52 | Apache Cordova Team
53 |
54 |
55 |
56 |
57 |
--------------------------------------------------------------------------------
/tests/cdv-test-project/plugins/cordova-plugin-whitelist/RELEASENOTES.md:
--------------------------------------------------------------------------------
1 |
21 | # Release Notes
22 |
23 | ### 1.2.1 (Jan 15, 2016)
24 | * CB-10194 info tag prints for ios when not applicable
25 |
26 | ### 1.2.0 (Nov 18, 2015)
27 | * removed **iOS** engine check from `plugin.xml`
28 | * [CB-10035](https://issues.apache.org/jira/browse/CB-10035) Updated `RELEASENOTES` to be newest to oldest
29 | * [CB-9972](https://issues.apache.org/jira/browse/CB-9972) - Remove **iOS** whitelist
30 | * Updated the text, it should read 4.0.x and greater, since this plugin will be required for `cordova-android 5.0`
31 | * Fixing contribute link.
32 | * Updated `plugin.xml ` tag to remove warning about not needing this plugin if you are using the **iOS 9 SDK**
33 | * [CB-9738](https://issues.apache.org/jira/browse/CB-9738) - Disable whitelist use when runtime environment is **iOS 9**
34 | * [CB-9740](https://issues.apache.org/jira/browse/CB-9740) - Add `` tag describing whitelist plugin not needed on `cordova-ios` and cordova-android 3.x`
35 | * [CB-9568](https://issues.apache.org/jira/browse/CB-9568) - Update whitelist plugin to allow all network access by default
36 | * [CB-9337](https://issues.apache.org/jira/browse/CB-9337) - enable use of `` tags for native code network requests
37 |
38 | ### 1.1.0 (Jun 17, 2015)
39 | * [CB-9128](https://issues.apache.org/jira/browse/CB-9128) cordova-plugin-whitelist documentation translation: cordova-plugin-whitelist
40 | * fix npm md issue
41 | * Usage of CDVURLRequestFilter protocol.
42 | * [CB-9089](https://issues.apache.org/jira/browse/CB-9089) - iOS whitelist plugin does not compile
43 | * [CB-9090](https://issues.apache.org/jira/browse/CB-9090) - Enable whitelist plugin for cordova-ios 4.0.0
44 | * Fixed error in Content-Security-Policy example
45 |
46 | ### 1.0.0 (Mar 25, 2015)
47 | * [CB-8739](https://issues.apache.org/jira/browse/CB-8739) added missing license headers
48 | * Add @Override to CustomConfigXmlParser methods
49 | * Change ID to cordova-plugin-whitelist rather than reverse-DNS-style
50 | * Tweak CSP examples in README
51 | * [CB-8660](https://issues.apache.org/jira/browse/CB-8660) remove extra commas from package.json
52 |
--------------------------------------------------------------------------------
/tests/CordovaLibTests/CordovaLibApp/www/tests.js:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed to the Apache Software Foundation (ASF) under one
3 | * or more contributor license agreements. See the NOTICE file
4 | * distributed with this work for additional information
5 | * regarding copyright ownership. The ASF licenses this file
6 | * to you under the Apache License, Version 2.0 (the
7 | * "License"); you may not use this file except in compliance
8 | * with the License. You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing,
13 | * software distributed under the License is distributed on an
14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 | * KIND, either express or implied. See the License for the
16 | * specific language governing permissions and limitations
17 | * under the License.
18 | */
19 |
20 |
21 | function echoTests() {
22 | var payloads = {
23 | 'string': "Hello, World",
24 | 'empty-string': "",
25 | 'one': 1,
26 | 'zero': 0,
27 | 'true': true,
28 | 'false': false,
29 | 'double': 3.141,
30 | 'array': ['a','b','c'],
31 | 'nested-array': ['a','b','c', [1,2,3]],
32 | 'object': {a:'a', b:'b'},
33 | 'nested-object': {a:'a', b:'b', c:{d:'d'}}
34 | };
35 |
36 | var tests = [];
37 | var numCompleted = 0;
38 | var numFailed = 0;
39 | function completed() {
40 | numCompleted++;
41 | if (numCompleted === tests.length) {
42 | window.jsTests.echo.result = numFailed === 0;
43 | }
44 | }
45 |
46 | var Test = function(name, payload) {
47 | this.payload = payload;
48 | this.name = name;
49 | this.result = '';
50 | };
51 | var _success = function(ret) {
52 | var result = JSON.stringify(ret);
53 | var expected = JSON.stringify(this.payload);
54 | if (result === expected) {
55 | console.log('success of ' + this.name);
56 | this.result = true;
57 | } else {
58 | console.log(this.name + ' failed. Expected ' + expected +' but got ' + result);
59 | this.result = false;
60 | numFailed++;
61 | }
62 | completed();
63 | };
64 |
65 | var _failure = function(e) {
66 | console.log('failure of ' + this.name);
67 | this.result = false;
68 | numFailed++;
69 | completed();
70 | };
71 |
72 | Test.prototype.run = function() {
73 | plugins.Test.echo(_success.bind(this), _failure.bind(this), this.payload);
74 | };
75 |
76 |
77 | for (var name in payloads) {
78 | var test = new Test(name, payloads[name]);
79 | tests.push(test);
80 | test.run();
81 | }
82 | }
83 |
84 | function runTests() {
85 |
86 | console.log('running tests...');
87 | echoTests();
88 | return 'echo';
89 |
90 | }
91 |
92 | window.jsTests = {
93 |
94 | echo: {
95 | result: ''
96 | }
97 | };
98 |
--------------------------------------------------------------------------------
/CordovaLib/CordovaLib/Classes/Utils/NSScreen+Utils.m:
--------------------------------------------------------------------------------
1 | /*
2 | Licensed to the Apache Software Foundation (ASF) under one
3 | or more contributor license agreements. See the NOTICE file
4 | distributed with this work for additional information
5 | regarding copyright ownership. The ASF licenses this file
6 | to you under the Apache License, Version 2.0 (the
7 | "License"); you may not use this file except in compliance
8 | with the License. You may obtain a copy of the License at
9 |
10 | http://www.apache.org/licenses/LICENSE-2.0
11 |
12 | Unless required by applicable law or agreed to in writing,
13 | software distributed under the License is distributed on an
14 | "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 | KIND, either express or implied. See the License for the
16 | specific language governing permissions and limitations
17 | under the License.
18 | */
19 |
20 | #import "NSScreen+Utils.h"
21 | #import
22 |
23 | NSString* screenNameForDisplay(CGDirectDisplayID displayID) {
24 | NSString *screenName = nil;
25 |
26 | NSDictionary *deviceInfo = (__bridge NSDictionary *) IODisplayCreateInfoDictionary(CGDisplayIOServicePort(displayID), kIODisplayOnlyPreferredName);
27 | NSDictionary *localizedNames = deviceInfo[[NSString stringWithUTF8String:kDisplayProductName]];
28 |
29 | if ([localizedNames count] > 0) {
30 | screenName = localizedNames[[localizedNames allKeys][0]];
31 | }
32 |
33 | return screenName;
34 | }
35 |
36 | @implementation NSScreen (Utils)
37 |
38 | + (NSRect) fullScreenRect {
39 | CGFloat x0 = 0.0f;
40 | CGFloat y0 = 0.0f;
41 | CGFloat x1 = 0.0f;
42 | CGFloat y1 = 0.0f;
43 |
44 | NSArray* screens = [NSScreen screens];
45 | NSLog(@"Detected %lu display%s:", screens.count, screens.count > 1 ? "s" : "");
46 | for (NSScreen* screen in [NSScreen screens]) {
47 | NSNumber* screenID = [screen.deviceDescription objectForKey:@"NSScreenNumber"];
48 | CGDirectDisplayID aID = [screenID unsignedIntValue];
49 | NSLog(@"- %@ at: %.lf,%.lf size: %.lf x %.lf", screenNameForDisplay(aID),
50 | screen.frame.origin.x, screen.frame.origin.y,
51 | screen.frame.size.width, screen.frame.size.height);
52 |
53 | if (NSMinX(screen.frame) < x0) {
54 | x0 = NSMinX(screen.frame);
55 | };
56 | if (NSMinY(screen.frame) < y0) {
57 | y0 = NSMinY(screen.frame);
58 | };
59 | if (NSMaxX(screen.frame) > x1) {
60 | x1 = NSMaxX(screen.frame);
61 | };
62 | if (NSMaxY(screen.frame) > y1) {
63 | y1 = NSMaxY(screen.frame);
64 | };
65 | }
66 | if ([NSScreen screensHaveSeparateSpaces] && screens.count > 1) {
67 | NSLog(@"Fullscreen only possible to cover main screen. Disable 'Displays have separate Spaces' in 'System Preferences -> Mission Control' to span all displays.");
68 | return [NSScreen mainScreen].frame;
69 | }
70 |
71 | return NSMakeRect(x0, y0, x1-x0, y1-y0);
72 | }
73 |
74 | @end
75 |
--------------------------------------------------------------------------------
/tests/CordovaLibTests/CordovaLibApp/MainViewController.m:
--------------------------------------------------------------------------------
1 | /*
2 | Licensed to the Apache Software Foundation (ASF) under one
3 | or more contributor license agreements. See the NOTICE file
4 | distributed with this work for additional information
5 | regarding copyright ownership. The ASF licenses this file
6 | to you under the Apache License, Version 2.0 (the
7 | "License"); you may not use this file except in compliance
8 | with the License. You may obtain a copy of the License at
9 |
10 | http://www.apache.org/licenses/LICENSE-2.0
11 |
12 | Unless required by applicable law or agreed to in writing,
13 | software distributed under the License is distributed on an
14 | "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 | KIND, either express or implied. See the License for the
16 | specific language governing permissions and limitations
17 | under the License.
18 | */
19 |
20 | #import "MainViewController.h"
21 |
22 | @interface MainViewController ()
23 |
24 | @end
25 |
26 | @implementation MainViewController
27 |
28 | - (id) initWithWindow:(NSWindow*) window {
29 | self = [super initWithWindow:window];
30 | if (self) {
31 | // Initialization code here.
32 | }
33 |
34 | return self;
35 | }
36 |
37 | - (id) initWithWindowNibName:(NSString*) nibNameOrNil {
38 | self = [super initWithWindowNibName:nibNameOrNil];
39 | if (self) {
40 | // Uncomment to override the CDVCommandDelegateImpl used
41 | // _commandDelegate = [[MainCommandDelegate alloc] initWithViewController:self];
42 | // Uncomment to override the CDVCommandQueue used
43 | // _commandQueue = [[MainCommandQueue alloc] initWithViewController:self];
44 | }
45 | return self;
46 | }
47 |
48 |
49 | - (id) init {
50 | self = [super init];
51 | if (self) {
52 | // Uncomment to override the CDVCommandDelegateImpl used
53 | // _commandDelegate = [[MainCommandDelegate alloc] initWithViewController:self];
54 | // Uncomment to override the CDVCommandQueue used
55 | // _commandQueue = [[MainCommandQueue alloc] initWithViewController:self];
56 | }
57 | return self;
58 | }
59 |
60 |
61 | - (void) awakeFromNib {
62 | [super awakeFromNib];
63 |
64 | // Implement this method to handle any initialization after your window controller's window has been loaded from its nib file.
65 | }
66 |
67 | @end
68 |
69 | @implementation MainCommandDelegate
70 |
71 | /* To override the methods, uncomment the line in the init function(s)
72 | in MainViewController.m
73 | */
74 |
75 | #pragma mark CDVCommandDelegate implementation
76 |
77 | - (id) getCommandInstance:(NSString*) className {
78 | return [super getCommandInstance:className];
79 | }
80 |
81 | - (NSString*) pathForResource:(NSString*) resourcepath; {
82 | return [super pathForResource:resourcepath];
83 | }
84 |
85 | @end
86 |
87 | @implementation MainCommandQueue
88 |
89 | /* To override, uncomment the line in the init function(s)
90 | in MainViewController.m
91 | */
92 | - (BOOL) execute:(CDVInvokedUrlCommand*) command {
93 | return [super execute:command];
94 | }
95 |
96 | @end
97 |
98 |
--------------------------------------------------------------------------------
/bin/templates/project/__PROJECT_NAME__/Classes/MainViewController.m:
--------------------------------------------------------------------------------
1 | /*
2 | Licensed to the Apache Software Foundation (ASF) under one
3 | or more contributor license agreements. See the NOTICE file
4 | distributed with this work for additional information
5 | regarding copyright ownership. The ASF licenses this file
6 | to you under the Apache License, Version 2.0 (the
7 | "License"); you may not use this file except in compliance
8 | with the License. You may obtain a copy of the License at
9 |
10 | http://www.apache.org/licenses/LICENSE-2.0
11 |
12 | Unless required by applicable law or agreed to in writing,
13 | software distributed under the License is distributed on an
14 | "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 | KIND, either express or implied. See the License for the
16 | specific language governing permissions and limitations
17 | under the License.
18 | */
19 |
20 | #import "MainViewController.h"
21 |
22 | @interface MainViewController ()
23 |
24 | @end
25 |
26 | @implementation MainViewController
27 |
28 | - (id)initWithWindow:(NSWindow *)window
29 | {
30 | self = [super initWithWindow:window];
31 | if (self) {
32 | // Initialization code here.
33 | }
34 |
35 | return self;
36 | }
37 |
38 | - (id)initWithWindowNibName:(NSString*)nibNameOrNil
39 | {
40 | self = [super initWithWindowNibName:nibNameOrNil];
41 | if (self) {
42 | // Uncomment to override the CDVCommandDelegateImpl used
43 | // _commandDelegate = [[MainCommandDelegate alloc] initWithViewController:self];
44 | // Uncomment to override the CDVCommandQueue used
45 | // _commandQueue = [[MainCommandQueue alloc] initWithViewController:self];
46 | }
47 | return self;
48 | }
49 |
50 |
51 | - (id)init
52 | {
53 | self = [super init];
54 | if (self) {
55 | // Uncomment to override the CDVCommandDelegateImpl used
56 | // _commandDelegate = [[MainCommandDelegate alloc] initWithViewController:self];
57 | // Uncomment to override the CDVCommandQueue used
58 | // _commandQueue = [[MainCommandQueue alloc] initWithViewController:self];
59 | }
60 | return self;
61 | }
62 |
63 |
64 | - (void)awakeFromNib
65 | {
66 | [super awakeFromNib];
67 |
68 | // Implement this method to handle any initialization after your window controller's window has been loaded from its nib file.
69 | }
70 |
71 | @end
72 |
73 | @implementation MainCommandDelegate
74 |
75 | /* To override the methods, uncomment the line in the init function(s)
76 | in MainViewController.m
77 | */
78 |
79 | #pragma mark CDVCommandDelegate implementation
80 |
81 | - (id)getCommandInstance:(NSString*)className
82 | {
83 | return [super getCommandInstance:className];
84 | }
85 |
86 | - (NSString*)pathForResource:(NSString*)resourcepath;
87 | {
88 | return [super pathForResource:resourcepath];
89 | }
90 |
91 | @end
92 |
93 | @implementation MainCommandQueue
94 |
95 | /* To override, uncomment the line in the init function(s)
96 | in MainViewController.m
97 | */
98 | - (BOOL)execute:(CDVInvokedUrlCommand*)command
99 | {
100 | return [super execute:command];
101 | }
102 |
103 | @end
104 |
105 |
--------------------------------------------------------------------------------
/tests/spec/component/platform.spec.js:
--------------------------------------------------------------------------------
1 | /*
2 | Licensed to the Apache Software Foundation (ASF) under one
3 | or more contributor license agreements. See the NOTICE file
4 | distributed with this work for additional information
5 | regarding copyright ownership. The ASF licenses this file
6 | to you under the Apache License, Version 2.0 (the
7 | "License"); you may not use this file except in compliance
8 | with the License. You may obtain a copy of the License at
9 |
10 | http://www.apache.org/licenses/LICENSE-2.0
11 |
12 | Unless required by applicable law or agreed to in writing,
13 | software distributed under the License is distributed on an
14 | "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 | KIND, either express or implied. See the License for the
16 | specific language governing permissions and limitations
17 | under the License.
18 | */
19 |
20 | const shell = require('shelljs');
21 | const path = require('path');
22 | const util = require('util');
23 | const fs = require('fs');
24 |
25 | const test_projectPath = path.join(__dirname, '../../', 'cdv-test-project');
26 | const test_platformPath = path.join(test_projectPath, 'platforms', 'osx');
27 |
28 | function initProject () {
29 | // remove existing folder
30 | const pPath = path.join(test_projectPath, 'platforms');
31 | shell.rm('-rf', pPath);
32 | }
33 |
34 | describe('platform add', () => {
35 | beforeEach(() => {
36 | initProject();
37 |
38 | shell.cd(test_projectPath);
39 |
40 | const command = 'cordova platform add ../../';
41 | console.log('executing "%s" in "%s"', command, shell.pwd());
42 |
43 | const return_code = shell.exec(command, { silent: false }).code;
44 | expect(return_code).toBe(0);
45 | });
46 |
47 | it('should have a config.xml', () => {
48 | const configXmlPath = path.join(test_platformPath, 'HelloCordova', 'config.xml');
49 | expect(fs.existsSync(configXmlPath)).toBe(true);
50 | });
51 |
52 | it('should have the correct icons', () => {
53 | const platformIcons = [
54 | { name: 'icon-16x16.png', width: 16, height: 16 },
55 | { name: 'icon-32x32.png', width: 32, height: 32 },
56 | { name: 'icon-64x64.png', width: 64, height: 64 },
57 | { name: 'icon-128x128.png', width: 128, height: 128 },
58 | { name: 'icon-256x256.png', width: 256, height: 256 },
59 | { name: 'icon-512x512.png', width: 512, height: 512 },
60 | { name: 'icon-1024x1024.png', width: 1024, height: 1024 }
61 | ];
62 |
63 | const appIconsPath = path.join(test_platformPath, 'HelloCordova', 'Images.xcassets', 'AppIcon.appiconset');
64 | const srcIcon = path.join(test_projectPath, 'res', 'test-64x64.png');
65 |
66 | platformIcons.forEach(function (iconDef) {
67 | const iconPath = path.join(appIconsPath, iconDef.name);
68 | expect(fs.existsSync(iconPath)).toBe(true);
69 |
70 | // check if the icons are the same as the one specified in the config.xml
71 | const cmd = util.format('cmp "%s" "%s"', srcIcon, iconPath);
72 | const return_code = shell.exec(cmd, { silent: false }).code;
73 |
74 | expect(return_code).toBe(0);
75 | });
76 | });
77 | });
78 |
--------------------------------------------------------------------------------
/CordovaLib/CordovaLib/Classes/Commands/CDVPluginResult.h:
--------------------------------------------------------------------------------
1 | /*
2 | Licensed to the Apache Software Foundation (ASF) under one
3 | or more contributor license agreements. See the NOTICE file
4 | distributed with this work for additional information
5 | regarding copyright ownership. The ASF licenses this file
6 | to you under the Apache License, Version 2.0 (the
7 | "License"); you may not use this file except in compliance
8 | with the License. You may obtain a copy of the License at
9 |
10 | http://www.apache.org/licenses/LICENSE-2.0
11 |
12 | Unless required by applicable law or agreed to in writing,
13 | software distributed under the License is distributed on an
14 | "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 | KIND, either express or implied. See the License for the
16 | specific language governing permissions and limitations
17 | under the License.
18 | */
19 |
20 | #import
21 |
22 | #pragma clang diagnostic push
23 | #pragma ide diagnostic ignored "OCUnusedPropertyInspection"
24 | #pragma ide diagnostic ignored "OCUnusedGlobalDeclarationInspection"
25 | #pragma ide diagnostic ignored "OCUnusedMethodInspection"
26 | typedef enum {
27 | CDVCommandStatus_NO_RESULT = 0,
28 | CDVCommandStatus_OK,
29 | CDVCommandStatus_CLASS_NOT_FOUND_EXCEPTION,
30 | CDVCommandStatus_ILLEGAL_ACCESS_EXCEPTION,
31 | CDVCommandStatus_INSTANTIATION_EXCEPTION,
32 | CDVCommandStatus_MALFORMED_URL_EXCEPTION,
33 | CDVCommandStatus_IO_EXCEPTION,
34 | CDVCommandStatus_INVALID_ACTION,
35 | CDVCommandStatus_JSON_EXCEPTION,
36 | CDVCommandStatus_ERROR
37 | } CDVCommandStatus;
38 |
39 | @interface CDVPluginResult : NSObject {}
40 |
41 | @property (nonatomic, strong, readonly) NSNumber* status;
42 | @property (nonatomic, strong, readonly) id message;
43 | @property (nonatomic, strong) NSNumber* keepCallback;
44 |
45 | /**
46 | * This property can be used to scope the lifetime of another object. For example,
47 | * Use it to store the associated NSData when `message` is created using initWithBytesNoCopy.
48 | */
49 | @property (nonatomic, strong) id associatedObject;
50 |
51 | - (CDVPluginResult*)init;
52 | + (CDVPluginResult*)resultWithStatus:(CDVCommandStatus)statusOrdinal;
53 | + (CDVPluginResult*)resultWithStatus:(CDVCommandStatus)statusOrdinal messageAsString:(NSString*)theMessage;
54 | + (CDVPluginResult*)resultWithStatus:(CDVCommandStatus)statusOrdinal messageAsArray:(NSArray*)theMessage;
55 | + (CDVPluginResult*)resultWithStatus:(CDVCommandStatus)statusOrdinal messageAsInt:(int)theMessage;
56 | + (CDVPluginResult*)resultWithStatus:(CDVCommandStatus)statusOrdinal messageAsDouble:(double)theMessage;
57 | + (CDVPluginResult*)resultWithStatus:(CDVCommandStatus)statusOrdinal messageAsBool:(BOOL)theMessage;
58 | + (CDVPluginResult*)resultWithStatus:(CDVCommandStatus)statusOrdinal messageAsDictionary:(NSDictionary*)theMessage;
59 | + (CDVPluginResult*)resultWithStatus:(CDVCommandStatus)statusOrdinal messageAsArrayBuffer:(NSData*)theMessage;
60 | + (CDVPluginResult*)resultWithStatus:(CDVCommandStatus)statusOrdinal messageAsMultipart:(NSArray*)theMessages;
61 | + (CDVPluginResult*)resultWithStatus:(CDVCommandStatus)statusOrdinal messageToErrorObject:(int)errorCode;
62 |
63 | + (void)setVerbose:(BOOL)verbose;
64 | + (BOOL)isVerbose;
65 |
66 | - (void)setKeepCallbackAsBool:(BOOL)bKeepCallback;
67 |
68 | - (NSString*)argumentsAsJSON;
69 |
70 | @end
71 |
72 | #pragma clang diagnostic pop
73 |
--------------------------------------------------------------------------------
/tests/CordovaLibTests/CDVWebViewTest.m:
--------------------------------------------------------------------------------
1 | /*
2 | Licensed to the Apache Software Foundation (ASF) under one
3 | or more contributor license agreements. See the NOTICE file
4 | distributed with this work for additional information
5 | regarding copyright ownership. The ASF licenses this file
6 | to you under the Apache License, Version 2.0 (the
7 | "License"); you may not use this file except in compliance
8 | with the License. You may obtain a copy of the License at
9 |
10 | http://www.apache.org/licenses/LICENSE-2.0
11 |
12 | Unless required by applicable law or agreed to in writing,
13 | software distributed under the License is distributed on an
14 | "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 | KIND, either express or implied. See the License for the
16 | specific language governing permissions and limitations
17 | under the License.
18 | */
19 |
20 | #import "CDVWebViewTest.h"
21 |
22 | #import "AppDelegate.h"
23 |
24 | @interface CDVWebViewTest ()
25 | // Runs the run loop until the webview has finished loading.
26 | - (void) waitForPageLoad;
27 | @end
28 |
29 | @implementation CDVWebViewTest
30 |
31 | @synthesize startPage;
32 |
33 | - (void) setUp {
34 | [super setUp];
35 | }
36 |
37 | - (void) tearDown {
38 | // Enforce that the view controller is released between tests to ensure
39 | // tests don't affect each other.
40 | // [self.appDelegate destroyViewController];
41 | [super tearDown];
42 | }
43 |
44 | - (AppDelegate*) appDelegate {
45 | return [[NSApplication sharedApplication] delegate];
46 | }
47 |
48 | - (CDVViewController*) viewController {
49 | // Lazily create the view controller so that tests that do not require it
50 | // are not slowed down by it.
51 | if (self.appDelegate.viewController == nil) {
52 |
53 | [self.appDelegate createViewController:self.startPage];
54 |
55 | // Things break if tearDown is called before the page has finished
56 | // loading (a JS error happens and an alert pops up), so enforce a wait here
57 | [self waitForPageLoad];
58 | }
59 |
60 | XCTAssertNotNil(self.appDelegate.viewController, @"createViewController failed");
61 | return self.appDelegate.viewController;
62 | }
63 |
64 | - (WebView*) webView {
65 | return self.viewController.webView;
66 | }
67 |
68 | - (id) pluginInstance:(NSString*) pluginName {
69 | id ret = [self.viewController getCommandInstance:pluginName];
70 |
71 | XCTAssertNotNil(ret, @"Missing plugin %@", pluginName);
72 | return ret;
73 | }
74 |
75 | - (void) reloadWebView {
76 | [self.appDelegate destroyViewController];
77 | [self viewController];
78 | }
79 |
80 | - (void) waitForConditionName:(NSString*) conditionName block:(BOOL (^)()) block {
81 | // Number of seconds to wait for a condition to become true before giving up.
82 | const NSTimeInterval kConditionTimeout = 5.0;
83 | // Useful when debugging so that it does not timeout after one loop.
84 | const int kMinIterations = 4;
85 |
86 | NSDate* startTime = [NSDate date];
87 | int i = 0;
88 |
89 | while (!block()) {
90 | [[NSRunLoop currentRunLoop] runUntilDate:[NSDate dateWithTimeIntervalSinceNow:0.1]];
91 | NSTimeInterval elapsed = -[startTime timeIntervalSinceNow];
92 | if (i > kMinIterations && elapsed > kConditionTimeout) {
93 | XCTFail(@"Timed out waiting for condition %@", conditionName);
94 | break;
95 | }
96 | ++i;
97 | }
98 | }
99 |
100 | - (void) waitForPageLoad {
101 | [self waitForConditionName:@"PageLoad" block:^{
102 | return [@"true" isEqualToString:[self evalJs:@"window.pageIsLoaded"]];
103 | }];
104 | }
105 |
106 | - (NSString*) evalJs:(NSString*) code {
107 | return [self.webView stringByEvaluatingJavaScriptFromString:code];
108 | }
109 |
110 | @end
111 |
--------------------------------------------------------------------------------
/CordovaLib/CordovaLib/Classes/Commands/CDVInvokedUrlCommand.m:
--------------------------------------------------------------------------------
1 | /*
2 | Licensed to the Apache Software Foundation (ASF) under one
3 | or more contributor license agreements. See the NOTICE file
4 | distributed with this work for additional information
5 | regarding copyright ownership. The ASF licenses this file
6 | to you under the Apache License, Version 2.0 (the
7 | "License"); you may not use this file except in compliance
8 | with the License. You may obtain a copy of the License at
9 |
10 | http://www.apache.org/licenses/LICENSE-2.0
11 |
12 | Unless required by applicable law or agreed to in writing,
13 | software distributed under the License is distributed on an
14 | "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 | KIND, either express or implied. See the License for the
16 | specific language governing permissions and limitations
17 | under the License.
18 | */
19 |
20 | #import
21 | #import "CDVInvokedUrlCommand.h"
22 |
23 | @implementation CDVInvokedUrlCommand
24 |
25 | @synthesize arguments = _arguments;
26 | @synthesize callbackId = _callbackId;
27 | @synthesize cmdClassName = _cmdClassName;
28 | @synthesize methodName = _methodName;
29 |
30 | + (CDVInvokedUrlCommand*) commandFromJson:(NSArray*) jsonEntry {
31 | return [[CDVInvokedUrlCommand alloc] initFromJson:jsonEntry];
32 | }
33 |
34 | - (id) initFromJson:(NSArray*) jsonEntry {
35 | id tmp = jsonEntry[0];
36 | NSString* callbackId = tmp == [NSNull null] ? nil : tmp;
37 | NSString* className = jsonEntry[1];
38 | NSString* methodName = jsonEntry[2];
39 | NSMutableArray* arguments = jsonEntry[3];
40 |
41 | return [self initWithArguments:arguments
42 | callbackId:callbackId
43 | className:className
44 | methodName:methodName];
45 | }
46 |
47 | - (id) initWithArguments:(NSArray*) arguments
48 | callbackId:(NSString*) callbackId
49 | className:(NSString*) className
50 | methodName:(NSString*) methodName {
51 | self = [super init];
52 | if (self != nil) {
53 | _arguments = arguments;
54 | _callbackId = callbackId;
55 | _cmdClassName = className;
56 | _methodName = methodName;
57 | }
58 | [self massageArguments];
59 | return self;
60 | }
61 |
62 | - (void) massageArguments {
63 | NSMutableArray* newArgs = nil;
64 |
65 | for (NSUInteger i = 0, count = [_arguments count]; i < count; ++i) {
66 | id arg = _arguments[i];
67 | if (![arg isKindOfClass:[NSDictionary class]]) {
68 | continue;
69 | }
70 | NSDictionary* dict = arg;
71 | NSString* type = dict[@"CDVType"];
72 | if (!type || ![type isEqualToString:@"ArrayBuffer"]) {
73 | continue;
74 | }
75 | NSString* data = dict[@"data"];
76 | if (!data) {
77 | continue;
78 | }
79 | if (newArgs == nil) {
80 | newArgs = [NSMutableArray arrayWithArray:_arguments];
81 | _arguments = newArgs;
82 | }
83 | newArgs[i] = [[NSData alloc] initWithBase64EncodedString:data options:0];
84 | }
85 | }
86 |
87 | - (id) argumentAtIndex:(NSUInteger) index {
88 | return [self argumentAtIndex:index withDefault:nil];
89 | }
90 |
91 | - (id) argumentAtIndex:(NSUInteger) index withDefault:(id) defaultValue {
92 | return [self argumentAtIndex:index withDefault:defaultValue andClass:nil];
93 | }
94 |
95 | - (id) argumentAtIndex:(NSUInteger) index withDefault:(id) defaultValue andClass:(Class) aClass {
96 | if (index >= [_arguments count]) {
97 | return defaultValue;
98 | }
99 | id ret = _arguments[index];
100 | if (ret == [NSNull null] || ret == [WebUndefined undefined]) {
101 | ret = defaultValue;
102 | }
103 | if ((aClass != nil) && ![ret isKindOfClass:aClass]) {
104 | ret = defaultValue;
105 | }
106 | return ret;
107 | }
108 |
109 | @end
110 |
--------------------------------------------------------------------------------
/cordova-js-src/exec.js:
--------------------------------------------------------------------------------
1 | /*
2 | *
3 | * Licensed to the Apache Software Foundation (ASF) under one
4 | * or more contributor license agreements. See the NOTICE file
5 | * distributed with this work for additional information
6 | * regarding copyright ownership. The ASF licenses this file
7 | * to you under the Apache License, Version 2.0 (the
8 | * "License"); you may not use this file except in compliance
9 | * with the License. You may obtain a copy of the License at
10 | *
11 | * http://www.apache.org/licenses/LICENSE-2.0
12 | *
13 | * Unless required by applicable law or agreed to in writing,
14 | * software distributed under the License is distributed on an
15 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 | * KIND, either express or implied. See the License for the
17 | * specific language governing permissions and limitations
18 | * under the License.
19 | *
20 | */
21 |
22 | /**
23 | * Creates a gap bridge used to notify the native code about commands.
24 |
25 | * @private
26 | */
27 | const cordova = require('cordova');
28 | const utils = require('cordova/utils');
29 | const base64 = require('cordova/base64');
30 |
31 | function massageMessageNativeToJs (message) {
32 | if (message.CDVType === 'ArrayBuffer') {
33 | const stringToArrayBuffer = function (str) {
34 | const ret = new Uint8Array(str.length);
35 | for (let i = 0; i < str.length; i++) {
36 | ret[i] = str.charCodeAt(i);
37 | }
38 | return ret.buffer;
39 | };
40 | const base64ToArrayBuffer = function (b64) {
41 | return stringToArrayBuffer(atob(b64));
42 | };
43 | message = base64ToArrayBuffer(message.data);
44 | }
45 | return message;
46 | }
47 |
48 | function convertMessageToArgsNativeToJs (message) {
49 | const args = [];
50 | if (!message || !Object.prototype.hasOwnProperty.call(message, 'CDVType')) {
51 | args.push(message);
52 | } else if (message.CDVType === 'MultiPart') {
53 | message.messages.forEach(function (e) {
54 | args.push(massageMessageNativeToJs(e));
55 | });
56 | } else {
57 | args.push(massageMessageNativeToJs(message));
58 | }
59 | return args;
60 | }
61 |
62 | function massageArgsJsToNative (args) {
63 | if (!args || utils.typeName(args) !== 'Array') {
64 | return args;
65 | }
66 | const ret = [];
67 | args.forEach(function (arg, i) {
68 | if (utils.typeName(arg) === 'ArrayBuffer') {
69 | ret.push({
70 | CDVType: 'ArrayBuffer',
71 | data: base64.fromArrayBuffer(arg)
72 | });
73 | } else {
74 | ret.push(arg);
75 | }
76 | });
77 | return ret;
78 | }
79 |
80 | function OSXExec () {
81 | let callbackId = 'INVALID';
82 |
83 | const successCallback = arguments[0];
84 | const failCallback = arguments[1];
85 | const service = arguments[2];
86 | const action = arguments[3];
87 | let actionArgs = arguments[4];
88 |
89 | // Register the callbacks and add the callbackId to the positional
90 | // arguments if given.
91 | if (successCallback || failCallback) {
92 | callbackId = service + cordova.callbackId++;
93 | cordova.callbacks[callbackId] =
94 | { success: successCallback, fail: failCallback };
95 | }
96 |
97 | actionArgs = massageArgsJsToNative(actionArgs);
98 |
99 | if (window.cordovabridge && window.cordovabridge.exec) {
100 | window.cordovabridge.exec(callbackId, service, action, actionArgs);
101 | } else {
102 | alert('window.cordovabridge binding is missing.');
103 | }
104 | }
105 |
106 | OSXExec.nativeCallback = function (callbackId, status, message, keepCallback) {
107 | const success = status === 0 || status === 1;
108 | const args = convertMessageToArgsNativeToJs(message);
109 | cordova.callbackFromNative(callbackId, success, status, args, keepCallback);
110 | };
111 |
112 | module.exports = OSXExec;
113 |
--------------------------------------------------------------------------------