Skip to content

Commit 3e0d969

Browse files
authored
Merge pull request #162 from gree/feature/playi-extension
WKScriptMessageHandler support for WKWebView and WebViewSeparated.bundle
2 parents ba84f1c + 508cd41 commit 3e0d969

File tree

15 files changed

+1122
-98
lines changed

15 files changed

+1122
-98
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,6 @@ Temp
44
*.sln
55
*.pidb
66
*.userprefs
7+
**/*.xcodeproj/*
8+
!**/*.xcodeproj/project.pbxproj
9+
!**/*.xcworkspace/contents.xcworkspacedata

README.md

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ below:
2121

2222
### OS X (Editor)
2323

24+
#### App Transport Security
25+
2426
Since Unity 5.3.0, Unity.app is built with ATS (App Transport
2527
Security) enabled and non-secured connection (HTTP) is not
2628
permitted. If you want to open `http://foo/bar.html` with this plugin
@@ -50,11 +52,19 @@ or invoke the following from your terminal,
5052
/usr/libexec/PlistBuddy -c "Add NSAppTransportSecurity:NSAllowsArbitraryLoads bool true" /Applications/Unity/Unity.app/Contents/Info.plist
5153
```
5254

53-
#### References
55+
##### References
5456

5557
* https://github.com/gree/unity-webview/issues/64
5658
* https://onevcat.zendesk.com/hc/en-us/articles/215527307-I-cannot-open-the-web-page-in-Unity-Editor-
5759

60+
#### WebViewSeparated.bundle
61+
62+
WebViewSeparated.bundle is a variation of WebView.bundle. It is based
63+
on https://github.com/gree/unity-webview/pull/161 . As noted in the
64+
pull-request, it shows a separate window and allows a developer to
65+
utilize the Safari debugger. For enabling it, please define
66+
`WEBVIEW_SEPARATED`.
67+
5868
### iOS
5969

6070
The implementation now supports WKWebView but it is disabled by

dist/unity-webview.unitypackage

23.5 KB
Binary file not shown.

dist/unity-webview.zip

25.5 KB
Binary file not shown.
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3+
<plist version="1.0">
4+
<dict>
5+
<key>CFBundleDevelopmentRegion</key>
6+
<string>English</string>
7+
<key>CFBundleExecutable</key>
8+
<string>${EXECUTABLE_NAME}</string>
9+
<key>CFBundleIconFile</key>
10+
<string></string>
11+
<key>CFBundleIdentifier</key>
12+
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
13+
<key>CFBundleInfoDictionaryVersion</key>
14+
<string>6.0</string>
15+
<key>CFBundleName</key>
16+
<string>${PRODUCT_NAME}</string>
17+
<key>CFBundlePackageType</key>
18+
<string>BNDL</string>
19+
<key>CFBundleShortVersionString</key>
20+
<string>1.0</string>
21+
<key>CFBundleSignature</key>
22+
<string>????</string>
23+
<key>CFBundleVersion</key>
24+
<string>1</string>
25+
<key>NSPrincipalClass</key>
26+
<string></string>
27+
</dict>
28+
</plist>

plugins/Mac/Resources/Info.plist

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
<key>CFBundleIconFile</key>
1010
<string></string>
1111
<key>CFBundleIdentifier</key>
12-
<string>net.gree.unitywebview.${PRODUCT_NAME:rfc1034identifier}</string>
12+
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
1313
<key>CFBundleInfoDictionaryVersion</key>
1414
<string>6.0</string>
1515
<key>CFBundleName</key>

plugins/Mac/Sources/WebView.m

Lines changed: 26 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
/*
22
* Copyright (C) 2011 Keijiro Takahashi
33
* Copyright (C) 2012 GREE, Inc.
4-
*
4+
*
55
* This software is provided 'as-is', without any express or implied
66
* warranty. In no event will the authors be held liable for any damages
77
* arising from the use of this software.
8-
*
8+
*
99
* Permission is granted to anyone to use this software for any purpose,
1010
* including commercial applications, and to alter it and redistribute it
1111
* freely, subject to the following restrictions:
12-
*
12+
*
1313
* 1. The origin of this software must not be misrepresented; you must not
1414
* claim that you wrote the original software. If you use this software
1515
* in a product, an acknowledgment in the product documentation would be
@@ -34,20 +34,20 @@
3434
typedef void *MonoMethod;
3535
typedef void *MonoString;
3636

37+
#ifdef __cplusplus
3738
extern "C" {
39+
#endif
3840
MonoDomain *mono_domain_get();
39-
MonoAssembly *mono_domain_assembly_open(
40-
MonoDomain *domain, const char *assemblyName);
41+
MonoAssembly *mono_domain_assembly_open(MonoDomain *domain, const char *assemblyName);
4142
MonoImage *mono_assembly_get_image(MonoAssembly *assembly);
42-
MonoMethodDesc *mono_method_desc_new(
43-
const char *methodString, int useNamespace);
43+
MonoMethodDesc *mono_method_desc_new(const char *methodString, int useNamespace);
4444
MonoMethodDesc *mono_method_desc_free(MonoMethodDesc *desc);
45-
MonoMethod *mono_method_desc_search_in_image(
46-
MonoMethodDesc *methodDesc, MonoImage *image);
47-
MonoObject *mono_runtime_invoke(
48-
MonoMethod *method, void *obj, void **params, MonoObject **exc);
45+
MonoMethod *mono_method_desc_search_in_image(MonoMethodDesc *methodDesc, MonoImage *image);
46+
MonoObject *mono_runtime_invoke(MonoMethod *method, void *obj, void **params, MonoObject **exc);
4947
MonoString *mono_string_new(MonoDomain *domain, const char *text);
48+
#ifdef __cplusplus
5049
}
50+
#endif
5151

5252
static BOOL inEditor;
5353
static MonoDomain *monoDomain;
@@ -73,16 +73,16 @@ static void UnitySendMessage(
7373
monoDomain = mono_domain_get();
7474
monoDesc = mono_method_desc_new(
7575
"UnitySendMessageDispatcher:Dispatch(string,string,string)", FALSE);
76-
76+
7777
monoAssembly =
7878
mono_domain_assembly_open(monoDomain, [assemblyPath UTF8String]);
7979

8080
if (monoAssembly != 0) {
8181
monoImage = mono_assembly_get_image(monoAssembly);
8282
monoMethod = mono_method_desc_search_in_image(monoDesc, monoImage);
8383
}
84-
85-
84+
85+
8686
if (monoMethod == 0) {
8787
if (inEditor) {
8888
assemblyPath =
@@ -102,11 +102,11 @@ static void UnitySendMessage(
102102
}
103103
}
104104
}
105-
105+
106106
if (monoMethod == 0) {
107107
return;
108108
}
109-
109+
110110
void *args[] = {
111111
mono_string_new(monoDomain, gameObject),
112112
mono_string_new(monoDomain, method),
@@ -196,7 +196,7 @@ - (void)webView:(WebView *)sender decidePolicyForNavigationAction:(NSDictionary
196196
} else {
197197
if ([customRequestHeader count] > 0) {
198198
bool isCustomized = YES;
199-
199+
200200
// Check for additional custom header.
201201
for (NSString *key in [customRequestHeader allKeys])
202202
{
@@ -213,7 +213,7 @@ - (void)webView:(WebView *)sender decidePolicyForNavigationAction:(NSDictionary
213213
return;
214214
}
215215
}
216-
216+
217217
[listener use];
218218
}
219219
}
@@ -321,20 +321,20 @@ - (void)update:(int)x y:(int)y deltaY:(float)deltaY buttonDown:(BOOL)buttonDown
321321
event = [NSEvent mouseEventWithType:NSLeftMouseDown
322322
location:NSMakePoint(x, y) modifierFlags:nil
323323
timestamp:GetCurrentEventTime() windowNumber:0
324-
context:context eventNumber:nil clickCount:1 pressure:nil];
324+
context:context eventNumber:nil clickCount:1 pressure:1];
325325
[view mouseDown:event];
326326
} else {
327327
event = [NSEvent mouseEventWithType:NSLeftMouseDragged
328328
location:NSMakePoint(x, y) modifierFlags:nil
329329
timestamp:GetCurrentEventTime() windowNumber:0
330-
context:context eventNumber:nil clickCount:0 pressure:nil];
330+
context:context eventNumber:nil clickCount:0 pressure:1];
331331
[view mouseDragged:event];
332332
}
333333
} else if (buttonRelease) {
334334
event = [NSEvent mouseEventWithType:NSLeftMouseUp
335335
location:NSMakePoint(x, y) modifierFlags:nil
336336
timestamp:GetCurrentEventTime() windowNumber:0
337-
context:context eventNumber:nil clickCount:0 pressure:nil];
337+
context:context eventNumber:nil clickCount:0 pressure:0];
338338
[view mouseUp:event];
339339
}
340340

@@ -452,7 +452,7 @@ - (const char *)getCustomRequestHeaderValue:(const char *)headerKey
452452
if (!result) {
453453
return NULL;
454454
}
455-
455+
456456
const char *s = [result UTF8String];
457457
char *r = (char *)malloc(strlen(s) + 1);
458458
strcpy(r, s);
@@ -462,7 +462,9 @@ - (const char *)getCustomRequestHeaderValue:(const char *)headerKey
462462
@end
463463

464464
typedef void (*UnityRenderEventFunc)(int eventId);
465+
#ifdef __cplusplus
465466
extern "C" {
467+
#endif
466468
const char *_CWebViewPlugin_GetAppPath();
467469
void *_CWebViewPlugin_Init(
468470
const char *gameObject, BOOL transparent, int width, int height, const char *ua, BOOL ineditor);
@@ -489,7 +491,9 @@ void _CWebViewPlugin_Update(void *instance, int x, int y, float deltaY,
489491
void _CWebViewPlugin_RemoveCustomHeader(void *instance, const char *headerKey);
490492
void _CWebViewPlugin_ClearCustomHeader(void *instance);
491493
const char *_CWebViewPlugin_GetCustomHeaderValue(void *instance, const char *headerKey);
494+
#ifdef __cplusplus
492495
}
496+
#endif
493497

494498
const char *_CWebViewPlugin_GetAppPath()
495499
{

0 commit comments

Comments
 (0)