@capacitor-community/camera-preview 4.0.0 → 5.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (187) hide show
  1. package/README.md +19 -13
  2. package/android/.gradle/8.0.2/checksums/checksums.lock +0 -0
  3. package/android/.gradle/{4.10.1/fileHashes/fileHashes.bin → 8.0.2/checksums/md5-checksums.bin} +0 -0
  4. package/android/.gradle/8.0.2/checksums/sha1-checksums.bin +0 -0
  5. package/android/.gradle/8.0.2/dependencies-accessors/dependencies-accessors.lock +0 -0
  6. package/android/.gradle/8.0.2/executionHistory/executionHistory.bin +0 -0
  7. package/android/.gradle/8.0.2/executionHistory/executionHistory.lock +0 -0
  8. package/android/.gradle/8.0.2/fileHashes/fileHashes.bin +0 -0
  9. package/android/.gradle/8.0.2/fileHashes/fileHashes.lock +0 -0
  10. package/android/.gradle/8.0.2/fileHashes/resourceHashesCache.bin +0 -0
  11. package/android/.gradle/8.0.2/gc.properties +0 -0
  12. package/android/.gradle/buildOutputCleanup/buildOutputCleanup.lock +0 -0
  13. package/android/.gradle/buildOutputCleanup/cache.properties +2 -0
  14. package/android/.gradle/buildOutputCleanup/outputFiles.bin +0 -0
  15. package/android/.gradle/file-system.probe +0 -0
  16. package/android/build.gradle +10 -8
  17. package/android/gradle/wrapper/gradle-wrapper.jar +0 -0
  18. package/android/gradle/wrapper/gradle-wrapper.properties +2 -2
  19. package/android/gradle.properties +1 -1
  20. package/android/gradlew +14 -4
  21. package/android/gradlew.bat +34 -32
  22. package/android/src/androidTest/java/com/getcapacitor/android/ExampleInstrumentedTest.java +3 -3
  23. package/android/src/main/AndroidManifest.xml +1 -1
  24. package/android/src/main/java/com/ahm/capacitor/camera/preview/CameraActivity.java +5 -7
  25. package/dist/esm/definitions.d.ts +4 -2
  26. package/dist/esm/index.d.ts +1 -1
  27. package/dist/esm/index.js.map +1 -1
  28. package/dist/esm/web.d.ts +3 -3
  29. package/dist/esm/web.js +14 -10
  30. package/dist/esm/web.js.map +1 -1
  31. package/dist/plugin.cjs.js +155 -0
  32. package/dist/plugin.cjs.js.map +1 -0
  33. package/dist/plugin.js +158 -0
  34. package/dist/plugin.js.map +1 -0
  35. package/ios/Plugin/CameraController.swift +1 -1
  36. package/ios/Plugin/Plugin.swift +5 -5
  37. package/ios/Podfile +7 -4
  38. package/ios/Podfile.lock +9 -10
  39. package/ios/Pods/CapacitorCordova/LICENSE +23 -0
  40. package/ios/Pods/CapacitorCordova/README.md +39 -0
  41. package/ios/Pods/CapacitorCordova/ios/CapacitorCordova/CapacitorCordova/CapacitorCordova.h +21 -0
  42. package/ios/Pods/CapacitorCordova/ios/CapacitorCordova/CapacitorCordova/Classes/Public/AppDelegate.h +8 -0
  43. package/ios/Pods/CapacitorCordova/ios/CapacitorCordova/CapacitorCordova/Classes/Public/AppDelegate.m +5 -0
  44. package/ios/Pods/CapacitorCordova/ios/CapacitorCordova/CapacitorCordova/Classes/Public/CDV.h +28 -0
  45. package/ios/Pods/CapacitorCordova/ios/CapacitorCordova/CapacitorCordova/Classes/Public/CDVAvailability.h +109 -0
  46. package/ios/Pods/CapacitorCordova/ios/CapacitorCordova/CapacitorCordova/Classes/Public/CDVCommandDelegate.h +51 -0
  47. package/ios/Pods/CapacitorCordova/ios/CapacitorCordova/CapacitorCordova/Classes/Public/CDVCommandDelegateImpl.h +39 -0
  48. package/ios/Pods/CapacitorCordova/ios/CapacitorCordova/CapacitorCordova/Classes/Public/CDVCommandDelegateImpl.m +154 -0
  49. package/ios/Pods/CapacitorCordova/ios/CapacitorCordova/CapacitorCordova/Classes/Public/CDVConfigParser.h +31 -0
  50. package/ios/Pods/CapacitorCordova/ios/CapacitorCordova/CapacitorCordova/Classes/Public/CDVConfigParser.m +81 -0
  51. package/ios/Pods/CapacitorCordova/ios/CapacitorCordova/CapacitorCordova/Classes/Public/CDVInvokedUrlCommand.h +52 -0
  52. package/ios/Pods/CapacitorCordova/ios/CapacitorCordova/CapacitorCordova/Classes/Public/CDVInvokedUrlCommand.m +116 -0
  53. package/ios/Pods/CapacitorCordova/ios/CapacitorCordova/CapacitorCordova/Classes/Public/CDVPlugin.h +81 -0
  54. package/ios/Pods/CapacitorCordova/ios/CapacitorCordova/CapacitorCordova/Classes/Public/CDVPlugin.m +154 -0
  55. package/ios/Pods/CapacitorCordova/ios/CapacitorCordova/CapacitorCordova/Classes/Public/CDVPluginManager.h +25 -0
  56. package/ios/Pods/CapacitorCordova/ios/CapacitorCordova/CapacitorCordova/Classes/Public/CDVPluginManager.m +77 -0
  57. package/ios/Pods/CapacitorCordova/ios/CapacitorCordova/CapacitorCordova/Classes/Public/CDVPluginResult.h +82 -0
  58. package/ios/Pods/CapacitorCordova/ios/CapacitorCordova/CapacitorCordova/Classes/Public/CDVPluginResult.m +216 -0
  59. package/ios/Pods/CapacitorCordova/ios/CapacitorCordova/CapacitorCordova/Classes/Public/CDVScreenOrientationDelegate.h +33 -0
  60. package/ios/Pods/CapacitorCordova/ios/CapacitorCordova/CapacitorCordova/Classes/Public/CDVUIWebViewDelegate.h +41 -0
  61. package/ios/Pods/CapacitorCordova/ios/CapacitorCordova/CapacitorCordova/Classes/Public/CDVUIWebViewDelegate.m +399 -0
  62. package/ios/Pods/CapacitorCordova/ios/CapacitorCordova/CapacitorCordova/Classes/Public/CDVURLProtocol.h +27 -0
  63. package/ios/Pods/CapacitorCordova/ios/CapacitorCordova/CapacitorCordova/Classes/Public/CDVURLProtocol.m +74 -0
  64. package/ios/Pods/CapacitorCordova/ios/CapacitorCordova/CapacitorCordova/Classes/Public/CDVUserAgentUtil.h +27 -0
  65. package/ios/Pods/CapacitorCordova/ios/CapacitorCordova/CapacitorCordova/Classes/Public/CDVUserAgentUtil.m +156 -0
  66. package/ios/Pods/CapacitorCordova/ios/CapacitorCordova/CapacitorCordova/Classes/Public/CDVViewController.h +30 -0
  67. package/ios/Pods/CapacitorCordova/ios/CapacitorCordova/CapacitorCordova/Classes/Public/CDVViewController.m +34 -0
  68. package/ios/Pods/CapacitorCordova/ios/CapacitorCordova/CapacitorCordova/Classes/Public/NSDictionary+CordovaPreferences.h +35 -0
  69. package/ios/Pods/CapacitorCordova/ios/CapacitorCordova/CapacitorCordova/Classes/Public/NSDictionary+CordovaPreferences.m +63 -0
  70. package/ios/Pods/Local Podspecs/Capacitor.podspec.json +34 -0
  71. package/ios/Pods/Local Podspecs/CapacitorCordova.podspec.json +26 -0
  72. package/ios/Pods/Manifest.lock +22 -0
  73. package/ios/Pods/Pods.xcodeproj/project.pbxproj +1374 -0
  74. package/ios/Pods/Pods.xcodeproj/xcuserdata/julionic.xcuserdatad/xcschemes/Capacitor.xcscheme +58 -0
  75. package/ios/Pods/Pods.xcodeproj/xcuserdata/julionic.xcuserdatad/xcschemes/CapacitorCordova.xcscheme +58 -0
  76. package/ios/Pods/Pods.xcodeproj/xcuserdata/julionic.xcuserdatad/xcschemes/Pods-Plugin.xcscheme +58 -0
  77. package/ios/Pods/Pods.xcodeproj/xcuserdata/julionic.xcuserdatad/xcschemes/Pods-PluginTests.xcscheme +58 -0
  78. package/ios/Pods/Pods.xcodeproj/xcuserdata/julionic.xcuserdatad/xcschemes/xcschememanagement.plist +31 -0
  79. package/ios/Pods/Target Support Files/Capacitor/Capacitor-Info.plist +26 -0
  80. package/ios/Pods/Target Support Files/Capacitor/Capacitor-dummy.m +5 -0
  81. package/ios/Pods/Target Support Files/Capacitor/Capacitor-prefix.pch +12 -0
  82. package/ios/Pods/Target Support Files/Capacitor/Capacitor.debug.xcconfig +15 -0
  83. package/ios/Pods/Target Support Files/Capacitor/Capacitor.modulemap +8 -0
  84. package/ios/Pods/Target Support Files/Capacitor/Capacitor.release.xcconfig +15 -0
  85. package/ios/Pods/Target Support Files/CapacitorCordova/CapacitorCordova-Info.plist +26 -0
  86. package/ios/Pods/Target Support Files/CapacitorCordova/CapacitorCordova-dummy.m +5 -0
  87. package/ios/Pods/Target Support Files/CapacitorCordova/CapacitorCordova-prefix.pch +12 -0
  88. package/ios/Pods/Target Support Files/CapacitorCordova/CapacitorCordova-umbrella.h +32 -0
  89. package/ios/Pods/Target Support Files/CapacitorCordova/CapacitorCordova.debug.xcconfig +12 -0
  90. package/ios/Pods/Target Support Files/CapacitorCordova/CapacitorCordova.modulemap +6 -0
  91. package/ios/Pods/Target Support Files/CapacitorCordova/CapacitorCordova.release.xcconfig +12 -0
  92. package/ios/Pods/Target Support Files/Pods-Plugin/Pods-Plugin-Info.plist +26 -0
  93. package/ios/Pods/Target Support Files/Pods-Plugin/Pods-Plugin-acknowledgements.markdown +53 -0
  94. package/ios/Pods/Target Support Files/Pods-Plugin/Pods-Plugin-acknowledgements.plist +91 -0
  95. package/ios/Pods/Target Support Files/Pods-Plugin/Pods-Plugin-dummy.m +5 -0
  96. package/ios/Pods/Target Support Files/Pods-Plugin/Pods-Plugin-umbrella.h +16 -0
  97. package/ios/Pods/Target Support Files/Pods-Plugin/Pods-Plugin.debug.xcconfig +14 -0
  98. package/ios/Pods/Target Support Files/Pods-Plugin/Pods-Plugin.modulemap +6 -0
  99. package/ios/Pods/Target Support Files/Pods-Plugin/Pods-Plugin.release.xcconfig +14 -0
  100. package/ios/Pods/Target Support Files/Pods-PluginTests/Pods-PluginTests-Info.plist +26 -0
  101. package/ios/Pods/Target Support Files/Pods-PluginTests/Pods-PluginTests-acknowledgements.markdown +53 -0
  102. package/ios/Pods/Target Support Files/Pods-PluginTests/Pods-PluginTests-acknowledgements.plist +91 -0
  103. package/ios/Pods/Target Support Files/Pods-PluginTests/Pods-PluginTests-dummy.m +5 -0
  104. package/ios/Pods/Target Support Files/Pods-PluginTests/Pods-PluginTests-frameworks.sh +188 -0
  105. package/ios/Pods/Target Support Files/Pods-PluginTests/Pods-PluginTests-umbrella.h +16 -0
  106. package/ios/Pods/Target Support Files/Pods-PluginTests/Pods-PluginTests.debug.xcconfig +15 -0
  107. package/ios/Pods/Target Support Files/Pods-PluginTests/Pods-PluginTests.modulemap +6 -0
  108. package/ios/Pods/Target Support Files/Pods-PluginTests/Pods-PluginTests.release.xcconfig +15 -0
  109. package/package.json +19 -9
  110. package/android/.gradle/4.10.1/fileHashes/fileHashes.lock +0 -0
  111. package/android/.idea/compiler.xml +0 -6
  112. package/android/.idea/gradle.xml +0 -20
  113. package/android/.idea/jarRepositories.xml +0 -45
  114. package/android/.idea/libraries/Gradle__androidx_activity_activity_1_2_0_aar.xml +0 -14
  115. package/android/.idea/libraries/Gradle__androidx_activity_activity_1_2_3_aar.xml +0 -14
  116. package/android/.idea/libraries/Gradle__androidx_annotation_annotation_1_1_0.xml +0 -9
  117. package/android/.idea/libraries/Gradle__androidx_annotation_annotation_1_2_0.xml +0 -9
  118. package/android/.idea/libraries/Gradle__androidx_annotation_annotation_experimental_1_0_0_aar.xml +0 -11
  119. package/android/.idea/libraries/Gradle__androidx_appcompat_appcompat_1_2_0_aar.xml +0 -14
  120. package/android/.idea/libraries/Gradle__androidx_appcompat_appcompat_1_3_0_aar.xml +0 -14
  121. package/android/.idea/libraries/Gradle__androidx_appcompat_appcompat_resources_1_2_0_aar.xml +0 -11
  122. package/android/.idea/libraries/Gradle__androidx_appcompat_appcompat_resources_1_3_0_aar.xml +0 -11
  123. package/android/.idea/libraries/Gradle__androidx_arch_core_core_common_2_1_0.xml +0 -9
  124. package/android/.idea/libraries/Gradle__androidx_arch_core_core_runtime_2_1_0_aar.xml +0 -11
  125. package/android/.idea/libraries/Gradle__androidx_collection_collection_1_1_0.xml +0 -9
  126. package/android/.idea/libraries/Gradle__androidx_coordinatorlayout_coordinatorlayout_1_1_0_aar.xml +0 -14
  127. package/android/.idea/libraries/Gradle__androidx_core_core_1_3_2_aar.xml +0 -14
  128. package/android/.idea/libraries/Gradle__androidx_core_core_1_5_0_aar.xml +0 -14
  129. package/android/.idea/libraries/Gradle__androidx_cursoradapter_cursoradapter_1_0_0_aar.xml +0 -11
  130. package/android/.idea/libraries/Gradle__androidx_customview_customview_1_0_0_aar.xml +0 -11
  131. package/android/.idea/libraries/Gradle__androidx_drawerlayout_drawerlayout_1_0_0_aar.xml +0 -14
  132. package/android/.idea/libraries/Gradle__androidx_exifinterface_exifinterface_1_3_2_aar.xml +0 -14
  133. package/android/.idea/libraries/Gradle__androidx_fragment_fragment_1_3_0_aar.xml +0 -14
  134. package/android/.idea/libraries/Gradle__androidx_fragment_fragment_1_3_4_aar.xml +0 -14
  135. package/android/.idea/libraries/Gradle__androidx_interpolator_interpolator_1_0_0_aar.xml +0 -11
  136. package/android/.idea/libraries/Gradle__androidx_lifecycle_lifecycle_common_2_3_0.xml +0 -9
  137. package/android/.idea/libraries/Gradle__androidx_lifecycle_lifecycle_common_2_3_1.xml +0 -9
  138. package/android/.idea/libraries/Gradle__androidx_lifecycle_lifecycle_livedata_2_0_0_aar.xml +0 -11
  139. package/android/.idea/libraries/Gradle__androidx_lifecycle_lifecycle_livedata_core_2_3_0_aar.xml +0 -11
  140. package/android/.idea/libraries/Gradle__androidx_lifecycle_lifecycle_livedata_core_2_3_1_aar.xml +0 -11
  141. package/android/.idea/libraries/Gradle__androidx_lifecycle_lifecycle_runtime_2_3_0_aar.xml +0 -11
  142. package/android/.idea/libraries/Gradle__androidx_lifecycle_lifecycle_runtime_2_3_1_aar.xml +0 -11
  143. package/android/.idea/libraries/Gradle__androidx_lifecycle_lifecycle_viewmodel_2_3_0_aar.xml +0 -11
  144. package/android/.idea/libraries/Gradle__androidx_lifecycle_lifecycle_viewmodel_2_3_1_aar.xml +0 -11
  145. package/android/.idea/libraries/Gradle__androidx_lifecycle_lifecycle_viewmodel_savedstate_2_3_0_aar.xml +0 -11
  146. package/android/.idea/libraries/Gradle__androidx_lifecycle_lifecycle_viewmodel_savedstate_2_3_1_aar.xml +0 -11
  147. package/android/.idea/libraries/Gradle__androidx_loader_loader_1_0_0_aar.xml +0 -11
  148. package/android/.idea/libraries/Gradle__androidx_savedstate_savedstate_1_1_0_aar.xml +0 -11
  149. package/android/.idea/libraries/Gradle__androidx_test_core_1_3_0_aar.xml +0 -11
  150. package/android/.idea/libraries/Gradle__androidx_test_espresso_espresso_core_3_1_0_alpha3_aar.xml +0 -11
  151. package/android/.idea/libraries/Gradle__androidx_test_espresso_espresso_core_3_3_0_aar.xml +0 -11
  152. package/android/.idea/libraries/Gradle__androidx_test_espresso_espresso_idling_resource_3_1_0_alpha3_aar.xml +0 -11
  153. package/android/.idea/libraries/Gradle__androidx_test_espresso_espresso_idling_resource_3_3_0_aar.xml +0 -11
  154. package/android/.idea/libraries/Gradle__androidx_test_ext_junit_1_1_2_aar.xml +0 -11
  155. package/android/.idea/libraries/Gradle__androidx_test_monitor_1_1_0_alpha3_aar.xml +0 -11
  156. package/android/.idea/libraries/Gradle__androidx_test_monitor_1_3_0_aar.xml +0 -11
  157. package/android/.idea/libraries/Gradle__androidx_test_runner_1_1_0_alpha3_aar.xml +0 -11
  158. package/android/.idea/libraries/Gradle__androidx_test_runner_1_3_0_aar.xml +0 -11
  159. package/android/.idea/libraries/Gradle__androidx_tracing_tracing_1_0_0_aar.xml +0 -11
  160. package/android/.idea/libraries/Gradle__androidx_vectordrawable_vectordrawable_1_1_0_aar.xml +0 -11
  161. package/android/.idea/libraries/Gradle__androidx_vectordrawable_vectordrawable_animated_1_1_0_aar.xml +0 -11
  162. package/android/.idea/libraries/Gradle__androidx_versionedparcelable_versionedparcelable_1_1_0_aar.xml +0 -11
  163. package/android/.idea/libraries/Gradle__androidx_versionedparcelable_versionedparcelable_1_1_1_aar.xml +0 -11
  164. package/android/.idea/libraries/Gradle__androidx_viewpager_viewpager_1_0_0_aar.xml +0 -11
  165. package/android/.idea/libraries/Gradle__com_google_code_findbugs_jsr305_2_0_1.xml +0 -9
  166. package/android/.idea/libraries/Gradle__com_squareup_javawriter_2_1_1.xml +0 -9
  167. package/android/.idea/libraries/Gradle__javax_inject_javax_inject_1.xml +0 -9
  168. package/android/.idea/libraries/Gradle__junit_junit_4_12.xml +0 -9
  169. package/android/.idea/libraries/Gradle__junit_junit_4_13_1.xml +0 -9
  170. package/android/.idea/libraries/Gradle__net_bytebuddy_byte_buddy_1_10_18.xml +0 -9
  171. package/android/.idea/libraries/Gradle__net_bytebuddy_byte_buddy_agent_1_10_18.xml +0 -9
  172. package/android/.idea/libraries/Gradle__net_sf_kxml_kxml2_2_3_0.xml +0 -9
  173. package/android/.idea/libraries/Gradle__org_apache_cordova_framework_7_0_0_aar.xml +0 -11
  174. package/android/.idea/libraries/Gradle__org_hamcrest_hamcrest_core_1_3.xml +0 -9
  175. package/android/.idea/libraries/Gradle__org_hamcrest_hamcrest_integration_1_3.xml +0 -9
  176. package/android/.idea/libraries/Gradle__org_hamcrest_hamcrest_library_1_3.xml +0 -9
  177. package/android/.idea/libraries/Gradle__org_json_json_20140107.xml +0 -9
  178. package/android/.idea/libraries/Gradle__org_mockito_mockito_core_3_6_28.xml +0 -9
  179. package/android/.idea/libraries/Gradle__org_mockito_mockito_inline_3_6_28.xml +0 -9
  180. package/android/.idea/libraries/Gradle__org_objenesis_objenesis_3_1.xml +0 -9
  181. package/android/.idea/misc.xml +0 -9
  182. package/android/.idea/modules/1419750366/android.capacitor-android.iml +0 -92
  183. package/android/.idea/modules/android.iml +0 -87
  184. package/android/.idea/modules.xml +0 -9
  185. package/android/.idea/vcs.xml +0 -6
  186. /package/android/.gradle/{4.10.1 → 8.0.2/dependencies-accessors}/gc.properties +0 -0
  187. /package/android/.gradle/{4.10.1 → 8.0.2}/fileChanges/last-build.bin +0 -0
@@ -0,0 +1,41 @@
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 <UIKit/UIKit.h>
21
+ #import "CDVAvailability.h"
22
+
23
+ /**
24
+ * Distinguishes top-level navigations from sub-frame navigations.
25
+ * shouldStartLoadWithRequest is called for every request, but didStartLoad
26
+ * and didFinishLoad is called only for top-level navigations.
27
+ * Relevant bug: CB-2389
28
+ */
29
+ @interface CDVUIWebViewDelegate : NSObject <UIWebViewDelegate>{
30
+ __weak NSObject <UIWebViewDelegate>* _delegate;
31
+ NSInteger _loadCount;
32
+ NSInteger _state;
33
+ NSInteger _curLoadToken;
34
+ NSInteger _loadStartPollCount;
35
+ }
36
+
37
+ - (id)initWithDelegate:(NSObject <UIWebViewDelegate>*)delegate;
38
+
39
+ - (BOOL)request:(NSURLRequest*)newRequest isEqualToRequestAfterStrippingFragments:(NSURLRequest*)originalRequest;
40
+
41
+ @end
@@ -0,0 +1,399 @@
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
+ // Testing shows:
22
+ //
23
+ // In all cases, webView.request.URL is the previous page's URL (or empty) during the didStartLoad callback.
24
+ // When loading a page with a redirect:
25
+ // 1. shouldStartLoading (requestURL is target page)
26
+ // 2. didStartLoading
27
+ // 3. shouldStartLoading (requestURL is redirect target)
28
+ // 4. didFinishLoad (request.URL is redirect target)
29
+ //
30
+ // Note the lack of a second didStartLoading **
31
+ //
32
+ // When loading a page with iframes:
33
+ // 1. shouldStartLoading (requestURL is main page)
34
+ // 2. didStartLoading
35
+ // 3. shouldStartLoading (requestURL is one of the iframes)
36
+ // 4. didStartLoading
37
+ // 5. didFinishLoad
38
+ // 6. didFinishLoad
39
+ //
40
+ // Note there is no way to distinguish which didFinishLoad maps to which didStartLoad **
41
+ //
42
+ // Loading a page by calling window.history.go(-1):
43
+ // 1. didStartLoading
44
+ // 2. didFinishLoad
45
+ //
46
+ // Note the lack of a shouldStartLoading call **
47
+ // Actually - this is fixed on iOS6. iOS6 has a shouldStart. **
48
+ //
49
+ // Loading a page by calling location.reload()
50
+ // 1. shouldStartLoading
51
+ // 2. didStartLoading
52
+ // 3. didFinishLoad
53
+ //
54
+ // Loading a page with an iframe that fails to load:
55
+ // 1. shouldStart (main page)
56
+ // 2. didStart
57
+ // 3. shouldStart (iframe)
58
+ // 4. didStart
59
+ // 5. didFailWithError
60
+ // 6. didFinish
61
+ //
62
+ // Loading a page with an iframe that fails to load due to an invalid URL:
63
+ // 1. shouldStart (main page)
64
+ // 2. didStart
65
+ // 3. shouldStart (iframe)
66
+ // 5. didFailWithError
67
+ // 6. didFinish
68
+ //
69
+ // This case breaks our logic since there is a missing didStart. To prevent this,
70
+ // we check URLs in shouldStart and return NO if they are invalid.
71
+ //
72
+ // Loading a page with an invalid URL
73
+ // 1. shouldStart (main page)
74
+ // 2. didFailWithError
75
+ //
76
+ // TODO: Record order when page is re-navigated before the first navigation finishes.
77
+ //
78
+
79
+ #import "CDVUIWebViewDelegate.h"
80
+
81
+ // #define VerboseLog NSLog
82
+ #define VerboseLog(...) do { \
83
+ } while (0)
84
+
85
+ typedef enum {
86
+ STATE_IDLE = 0,
87
+ STATE_WAITING_FOR_LOAD_START = 1,
88
+ STATE_WAITING_FOR_LOAD_FINISH = 2,
89
+ STATE_IOS5_POLLING_FOR_LOAD_START = 3,
90
+ STATE_IOS5_POLLING_FOR_LOAD_FINISH = 4,
91
+ STATE_CANCELLED = 5
92
+ } State;
93
+
94
+ static NSString *stripFragment(NSString* url)
95
+ {
96
+ NSRange r = [url rangeOfString:@"#"];
97
+
98
+ if (r.location == NSNotFound) {
99
+ return url;
100
+ }
101
+ return [url substringToIndex:r.location];
102
+ }
103
+
104
+ @implementation CDVUIWebViewDelegate
105
+
106
+ - (id)initWithDelegate:(NSObject <UIWebViewDelegate>*)delegate
107
+ {
108
+ self = [super init];
109
+ if (self != nil) {
110
+ _delegate = delegate;
111
+ _loadCount = -1;
112
+ _state = STATE_IDLE;
113
+ }
114
+ return self;
115
+ }
116
+
117
+ - (BOOL)request:(NSURLRequest*)newRequest isEqualToRequestAfterStrippingFragments:(NSURLRequest*)originalRequest
118
+ {
119
+ if (originalRequest.URL && newRequest.URL) {
120
+ NSString* originalRequestUrl = [originalRequest.URL absoluteString];
121
+ NSString* newRequestUrl = [newRequest.URL absoluteString];
122
+
123
+ NSString* baseOriginalRequestUrl = stripFragment(originalRequestUrl);
124
+ NSString* baseNewRequestUrl = stripFragment(newRequestUrl);
125
+ return [baseOriginalRequestUrl isEqualToString:baseNewRequestUrl];
126
+ }
127
+
128
+ return NO;
129
+ }
130
+
131
+ - (BOOL)isPageLoaded:(UIWebView*)webView
132
+ {
133
+ NSString* readyState = [webView stringByEvaluatingJavaScriptFromString:@"document.readyState"];
134
+
135
+ return [readyState isEqualToString:@"loaded"] || [readyState isEqualToString:@"complete"];
136
+ }
137
+
138
+ - (BOOL)isJsLoadTokenSet:(UIWebView*)webView
139
+ {
140
+ NSString* loadToken = [webView stringByEvaluatingJavaScriptFromString:@"window.__cordovaLoadToken"];
141
+
142
+ return [[NSString stringWithFormat:@"%ld", (long)_curLoadToken] isEqualToString:loadToken];
143
+ }
144
+
145
+ - (void)setLoadToken:(UIWebView*)webView
146
+ {
147
+ _curLoadToken += 1;
148
+ [webView stringByEvaluatingJavaScriptFromString:[NSString stringWithFormat:@"window.__cordovaLoadToken=%ld", (long)_curLoadToken]];
149
+ }
150
+
151
+ - (NSString*)evalForCurrentURL:(UIWebView*)webView
152
+ {
153
+ return [webView stringByEvaluatingJavaScriptFromString:@"location.href"];
154
+ }
155
+
156
+ - (void)pollForPageLoadStart:(UIWebView*)webView
157
+ {
158
+ if (_state != STATE_IOS5_POLLING_FOR_LOAD_START) {
159
+ return;
160
+ }
161
+ if (![self isJsLoadTokenSet:webView]) {
162
+ VerboseLog(@"Polled for page load start. result = YES!");
163
+ _state = STATE_IOS5_POLLING_FOR_LOAD_FINISH;
164
+ [self setLoadToken:webView];
165
+ if ([_delegate respondsToSelector:@selector(webViewDidStartLoad:)]) {
166
+ [_delegate webViewDidStartLoad:webView];
167
+ }
168
+ [self pollForPageLoadFinish:webView];
169
+ } else {
170
+ VerboseLog(@"Polled for page load start. result = NO");
171
+ // Poll only for 1 second, and then fall back on checking only when delegate methods are called.
172
+ ++_loadStartPollCount;
173
+ if (_loadStartPollCount < (1000 * .05)) {
174
+ [self performSelector:@selector(pollForPageLoadStart:) withObject:webView afterDelay:.05];
175
+ }
176
+ }
177
+ }
178
+
179
+ - (void)pollForPageLoadFinish:(UIWebView*)webView
180
+ {
181
+ if (_state != STATE_IOS5_POLLING_FOR_LOAD_FINISH) {
182
+ return;
183
+ }
184
+ if ([self isPageLoaded:webView]) {
185
+ VerboseLog(@"Polled for page load finish. result = YES!");
186
+ _state = STATE_IDLE;
187
+ if ([_delegate respondsToSelector:@selector(webViewDidFinishLoad:)]) {
188
+ [_delegate webViewDidFinishLoad:webView];
189
+ }
190
+ } else {
191
+ VerboseLog(@"Polled for page load finish. result = NO");
192
+ [self performSelector:@selector(pollForPageLoadFinish:) withObject:webView afterDelay:.05];
193
+ }
194
+ }
195
+
196
+ - (BOOL)shouldLoadRequest:(NSURLRequest*)request
197
+ {
198
+ NSString* scheme = [[request URL] scheme];
199
+ NSArray* allowedSchemes = [NSArray arrayWithObjects:@"mailto",@"tel",@"blob",@"sms",@"data", nil];
200
+ if([allowedSchemes containsObject:scheme]) {
201
+ return YES;
202
+ }
203
+ else {
204
+ return [NSURLConnection canHandleRequest:request];
205
+ }
206
+ }
207
+
208
+ - (BOOL)webView:(UIWebView*)webView shouldStartLoadWithRequest:(NSURLRequest*)request navigationType:(UIWebViewNavigationType)navigationType
209
+ {
210
+ BOOL shouldLoad = YES;
211
+
212
+ if ([_delegate respondsToSelector:@selector(webView:shouldStartLoadWithRequest:navigationType:)]) {
213
+ shouldLoad = [_delegate webView:webView shouldStartLoadWithRequest:request navigationType:navigationType];
214
+ }
215
+
216
+ VerboseLog(@"webView shouldLoad=%d (before) state=%d loadCount=%d URL=%@", shouldLoad, _state, _loadCount, request.URL);
217
+
218
+ if (shouldLoad) {
219
+ // When devtools refresh occurs, it blindly uses the same request object. If a history.replaceState() has occured, then
220
+ // mainDocumentURL != URL even though it's a top-level navigation.
221
+ BOOL isDevToolsRefresh = (request == webView.request);
222
+ BOOL isTopLevelNavigation = isDevToolsRefresh || [request.URL isEqual:[request mainDocumentURL]];
223
+ if (isTopLevelNavigation) {
224
+ // Ignore hash changes that don't navigate to a different page.
225
+ // webView.request does actually update when history.replaceState() gets called.
226
+ if ([self request:request isEqualToRequestAfterStrippingFragments:webView.request]) {
227
+ NSString* prevURL = [self evalForCurrentURL:webView];
228
+ if ([prevURL isEqualToString:[request.URL absoluteString]]) {
229
+ VerboseLog(@"Page reload detected.");
230
+ } else {
231
+ VerboseLog(@"Detected hash change shouldLoad");
232
+ return shouldLoad;
233
+ }
234
+ }
235
+
236
+ switch (_state) {
237
+ case STATE_WAITING_FOR_LOAD_FINISH:
238
+ // Redirect case.
239
+ // We expect loadCount == 1.
240
+ if (_loadCount != 1) {
241
+ NSLog(@"CDVWebViewDelegate: Detected redirect when loadCount=%ld", (long)_loadCount);
242
+ }
243
+ break;
244
+
245
+ case STATE_IDLE:
246
+ case STATE_IOS5_POLLING_FOR_LOAD_START:
247
+ case STATE_CANCELLED:
248
+ // Page navigation start.
249
+ _loadCount = 0;
250
+ _state = STATE_WAITING_FOR_LOAD_START;
251
+ break;
252
+
253
+ default:
254
+ {
255
+ NSString* description = [NSString stringWithFormat:@"CDVWebViewDelegate: Navigation started when state=%ld", (long)_state];
256
+ NSLog(@"%@", description);
257
+ _loadCount = 0;
258
+ _state = STATE_WAITING_FOR_LOAD_START;
259
+
260
+ NSDictionary* errorDictionary = @{NSLocalizedDescriptionKey : description};
261
+ NSError* error = [[NSError alloc] initWithDomain:@"CDVUIWebViewDelegate" code:1 userInfo:errorDictionary];
262
+ [self webView:webView didFailLoadWithError:error];
263
+ }
264
+ }
265
+ } else {
266
+ // Deny invalid URLs so that we don't get the case where we go straight from
267
+ // webViewShouldLoad -> webViewDidFailLoad (messes up _loadCount).
268
+ shouldLoad = shouldLoad && [self shouldLoadRequest:request];
269
+ }
270
+ VerboseLog(@"webView shouldLoad=%d (after) isTopLevelNavigation=%d state=%d loadCount=%d", shouldLoad, isTopLevelNavigation, _state, _loadCount);
271
+ }
272
+ return shouldLoad;
273
+ }
274
+
275
+ - (void)webViewDidStartLoad:(UIWebView*)webView
276
+ {
277
+ VerboseLog(@"webView didStartLoad (before). state=%d loadCount=%d", _state, _loadCount);
278
+ BOOL fireCallback = NO;
279
+ switch (_state) {
280
+ case STATE_IDLE:
281
+ break;
282
+
283
+ case STATE_CANCELLED:
284
+ fireCallback = YES;
285
+ _state = STATE_WAITING_FOR_LOAD_FINISH;
286
+ _loadCount += 1;
287
+ break;
288
+
289
+ case STATE_WAITING_FOR_LOAD_START:
290
+ if (_loadCount != 0) {
291
+ NSLog(@"CDVWebViewDelegate: Unexpected loadCount in didStart. count=%ld", (long)_loadCount);
292
+ }
293
+ fireCallback = YES;
294
+ _state = STATE_WAITING_FOR_LOAD_FINISH;
295
+ _loadCount = 1;
296
+ break;
297
+
298
+ case STATE_WAITING_FOR_LOAD_FINISH:
299
+ _loadCount += 1;
300
+ break;
301
+
302
+ case STATE_IOS5_POLLING_FOR_LOAD_START:
303
+ [self pollForPageLoadStart:webView];
304
+ break;
305
+
306
+ case STATE_IOS5_POLLING_FOR_LOAD_FINISH:
307
+ [self pollForPageLoadFinish:webView];
308
+ break;
309
+
310
+ default:
311
+ NSLog(@"CDVWebViewDelegate: Unexpected didStart with state=%ld loadCount=%ld", (long)_state, (long)_loadCount);
312
+ }
313
+ VerboseLog(@"webView didStartLoad (after). state=%d loadCount=%d fireCallback=%d", _state, _loadCount, fireCallback);
314
+ if (fireCallback && [_delegate respondsToSelector:@selector(webViewDidStartLoad:)]) {
315
+ [_delegate webViewDidStartLoad:webView];
316
+ }
317
+ }
318
+
319
+ - (void)webViewDidFinishLoad:(UIWebView*)webView
320
+ {
321
+ VerboseLog(@"webView didFinishLoad (before). state=%d loadCount=%d", _state, _loadCount);
322
+ BOOL fireCallback = NO;
323
+ switch (_state) {
324
+ case STATE_IDLE:
325
+ break;
326
+
327
+ case STATE_WAITING_FOR_LOAD_START:
328
+ NSLog(@"CDVWebViewDelegate: Unexpected didFinish while waiting for load start.");
329
+ break;
330
+
331
+ case STATE_WAITING_FOR_LOAD_FINISH:
332
+ if (_loadCount == 1) {
333
+ fireCallback = YES;
334
+ _state = STATE_IDLE;
335
+ }
336
+ _loadCount -= 1;
337
+ break;
338
+
339
+ case STATE_IOS5_POLLING_FOR_LOAD_START:
340
+ [self pollForPageLoadStart:webView];
341
+ break;
342
+
343
+ case STATE_IOS5_POLLING_FOR_LOAD_FINISH:
344
+ [self pollForPageLoadFinish:webView];
345
+ break;
346
+ }
347
+ VerboseLog(@"webView didFinishLoad (after). state=%d loadCount=%d fireCallback=%d", _state, _loadCount, fireCallback);
348
+ if (fireCallback && [_delegate respondsToSelector:@selector(webViewDidFinishLoad:)]) {
349
+ [_delegate webViewDidFinishLoad:webView];
350
+ }
351
+ }
352
+
353
+ - (void)webView:(UIWebView*)webView didFailLoadWithError:(NSError*)error
354
+ {
355
+ VerboseLog(@"webView didFailLoad (before). state=%d loadCount=%d", _state, _loadCount);
356
+ BOOL fireCallback = NO;
357
+
358
+ switch (_state) {
359
+ case STATE_IDLE:
360
+ break;
361
+
362
+ case STATE_WAITING_FOR_LOAD_START:
363
+ if ([error code] == NSURLErrorCancelled) {
364
+ _state = STATE_CANCELLED;
365
+ } else {
366
+ _state = STATE_IDLE;
367
+ }
368
+ fireCallback = YES;
369
+ break;
370
+
371
+ case STATE_WAITING_FOR_LOAD_FINISH:
372
+ if ([error code] != NSURLErrorCancelled) {
373
+ if (_loadCount == 1) {
374
+ _state = STATE_IDLE;
375
+ fireCallback = YES;
376
+ }
377
+ _loadCount = -1;
378
+ } else {
379
+ fireCallback = YES;
380
+ _state = STATE_CANCELLED;
381
+ _loadCount -= 1;
382
+ }
383
+ break;
384
+
385
+ case STATE_IOS5_POLLING_FOR_LOAD_START:
386
+ [self pollForPageLoadStart:webView];
387
+ break;
388
+
389
+ case STATE_IOS5_POLLING_FOR_LOAD_FINISH:
390
+ [self pollForPageLoadFinish:webView];
391
+ break;
392
+ }
393
+ VerboseLog(@"webView didFailLoad (after). state=%d loadCount=%d, fireCallback=%d", _state, _loadCount, fireCallback);
394
+ if (fireCallback && [_delegate respondsToSelector:@selector(webView:didFailLoadWithError:)]) {
395
+ [_delegate webView:webView didFailLoadWithError:error];
396
+ }
397
+ }
398
+
399
+ @end
@@ -0,0 +1,27 @@
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 <Foundation/Foundation.h>
21
+ #import "CDVAvailability.h"
22
+
23
+ @class CDVViewController;
24
+
25
+ @interface CDVURLProtocol : NSURLProtocol {}
26
+
27
+ @end
@@ -0,0 +1,74 @@
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 <MobileCoreServices/MobileCoreServices.h>
21
+ #import "CDVURLProtocol.h"
22
+ #import "CDVViewController.h"
23
+
24
+ // Contains a set of NSNumbers of addresses of controllers. It doesn't store
25
+ // the actual pointer to avoid retaining.
26
+ static NSMutableSet* gRegisteredControllers = nil;
27
+
28
+ NSString* const kCDVAssetsLibraryPrefixes = @"assets-library://";
29
+
30
+ @implementation CDVURLProtocol
31
+
32
+
33
+ + (BOOL)canInitWithRequest:(NSURLRequest*)theRequest
34
+ {
35
+ return NO;
36
+ }
37
+
38
+ + (NSURLRequest*)canonicalRequestForRequest:(NSURLRequest*)request
39
+ {
40
+ // NSLog(@"%@ received %@", self, NSStringFromSelector(_cmd));
41
+ return request;
42
+ }
43
+
44
+ - (void)startLoading
45
+ {
46
+ return;
47
+ }
48
+
49
+ - (void)stopLoading
50
+ {
51
+ // do any cleanup here
52
+ }
53
+
54
+ + (BOOL)requestIsCacheEquivalent:(NSURLRequest*)requestA toRequest:(NSURLRequest*)requestB
55
+ {
56
+ return NO;
57
+ }
58
+
59
+ - (void)sendResponseWithResponseCode:(NSInteger)statusCode data:(NSData*)data mimeType:(NSString*)mimeType
60
+ {
61
+ if (mimeType == nil) {
62
+ mimeType = @"text/plain";
63
+ }
64
+
65
+ NSHTTPURLResponse* response = [[NSHTTPURLResponse alloc] initWithURL:[[self request] URL] statusCode:statusCode HTTPVersion:@"HTTP/1.1" headerFields:@{@"Content-Type" : mimeType}];
66
+
67
+ [[self client] URLProtocol:self didReceiveResponse:response cacheStoragePolicy:NSURLCacheStorageNotAllowed];
68
+ if (data != nil) {
69
+ [[self client] URLProtocol:self didLoadData:data];
70
+ }
71
+ [[self client] URLProtocolDidFinishLoading:self];
72
+ }
73
+
74
+ @end
@@ -0,0 +1,27 @@
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 <Foundation/Foundation.h>
21
+
22
+ @interface CDVUserAgentUtil : NSObject
23
+ + (NSString*)originalUserAgent;
24
+ + (void)acquireLock:(void (^)(NSInteger lockToken))block;
25
+ + (void)releaseLock:(NSInteger*)lockToken;
26
+ + (void)setUserAgent:(NSString*)value lockToken:(NSInteger)lockToken;
27
+ @end