Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 library browser; | 4 library browser; |
| 5 | 5 |
| 6 import "dart:async"; | 6 import "dart:async"; |
| 7 import "dart:core"; | 7 import "dart:core"; |
| 8 import "dart:io"; | 8 import "dart:io"; |
| 9 | 9 |
| 10 import 'android.dart'; | 10 import 'android.dart'; |
| (...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 176 * The binary used to run safari - changing this can be nececcary for | 176 * The binary used to run safari - changing this can be nececcary for |
| 177 * testing or using non standard safari installation. | 177 * testing or using non standard safari installation. |
| 178 */ | 178 */ |
| 179 const String binary = "/Applications/Safari.app/Contents/MacOS/Safari"; | 179 const String binary = "/Applications/Safari.app/Contents/MacOS/Safari"; |
| 180 | 180 |
| 181 /** | 181 /** |
| 182 * We get the safari version by parsing a version file | 182 * We get the safari version by parsing a version file |
| 183 */ | 183 */ |
| 184 const String versionFile = "/Applications/Safari.app/Contents/version.plist"; | 184 const String versionFile = "/Applications/Safari.app/Contents/version.plist"; |
| 185 | 185 |
| 186 /** | |
| 187 * Directories where safari stores state. We delete these if the deleteCache | |
| 188 * is set | |
| 189 */ | |
| 190 static const List<String> CACHE_DIRECTORIES = | |
| 191 const ["Library/Caches/com.apple.Safari", | |
| 192 "Library/Safari"]; | |
| 193 | |
| 194 | |
| 186 Future<bool> allowPopUps() { | 195 Future<bool> allowPopUps() { |
| 187 var command = "defaults"; | 196 var command = "defaults"; |
| 188 var args = ["write", "com.apple.safari", | 197 var args = ["write", "com.apple.safari", |
| 189 "com.apple.Safari.ContentPageGroupIdentifier." | 198 "com.apple.Safari.ContentPageGroupIdentifier." |
| 190 "WebKit2JavaScriptCanOpenWindowsAutomatically", | 199 "WebKit2JavaScriptCanOpenWindowsAutomatically", |
| 191 "1"]; | 200 "1"]; |
| 192 return Process.run(command, args).then((result) { | 201 return Process.run(command, args).then((result) { |
| 193 if (result.exitCode != 0) { | 202 if (result.exitCode != 0) { |
| 194 _logEvent("Could not disable pop-up blocking for safari"); | 203 _logEvent("Could not disable pop-up blocking for safari"); |
| 195 return false; | 204 return false; |
| 196 } | 205 } |
| 197 return true; | 206 return true; |
| 198 }); | 207 }); |
| 199 } | 208 } |
| 200 | 209 |
| 210 Future<bool> deleteIfExists(Iterator<String> paths) { | |
| 211 if (!paths.moveNext()) return new Future.immediate(true); | |
| 212 Directory directory = new Directory(paths.current); | |
| 213 return directory.exists().then((exists) { | |
| 214 if (exists) { | |
| 215 _logEvent("Deleting ${paths.current}"); | |
| 216 return directory.delete(recursive: true) | |
| 217 .then((_) => deleteIfExists(paths)) | |
| 218 .catchError((error) { | |
| 219 _logEvent("Failure trying to delete $paths.current"); | |
|
kustermann
2013/06/20 15:54:11
'$paths.current' -> '${paths.current}'
print error
ricow1
2013/06/20 15:59:05
Done.
| |
| 220 return false; | |
| 221 }); | |
| 222 } else { | |
| 223 _logEvent("${paths.current} is not present"); | |
| 224 return deleteIfExists(paths); | |
| 225 } | |
| 226 }); | |
| 227 } | |
| 228 | |
| 201 // Clears the cache if the static deleteCache flag is set. | 229 // Clears the cache if the static deleteCache flag is set. |
| 202 // Returns false if the command to actually clear the cache did not complete. | 230 // Returns false if the command to actually clear the cache did not complete. |
| 203 Future<bool> clearCache() { | 231 Future<bool> clearCache() { |
| 204 if (!deleteCache) return new Future.immediate(true); | 232 if (!deleteCache) return new Future.immediate(true); |
| 205 var home = Platform.environment['HOME']; | 233 var home = Platform.environment['HOME']; |
| 206 var cache = "$home/Library/Caches/com.apple.Safari"; | 234 void addHome(dir) => "$home/$dir"; |
|
kustermann
2013/06/20 15:54:11
addHome seems to be unused
ricow1
2013/06/20 15:59:05
Done.
| |
| 207 _logEvent("Clearing safari cache: $cache}"); | 235 Iterator iterator = CACHE_DIRECTORIES.map((s) => "$home/$s").iterator; |
| 208 return new Directory(cache).delete(recursive: true) | 236 return deleteIfExists(iterator); |
| 209 .then((_) => true) | |
| 210 » // This normally means that the directory was not there. | |
| 211 » .catchError((error) => true); | |
| 212 } | 237 } |
| 213 | 238 |
| 214 Future<String> getVersion() { | 239 Future<String> getVersion() { |
| 215 /** | 240 /** |
| 216 * Example of the file: | 241 * Example of the file: |
| 217 * <?xml version="1.0" encoding="UTF-8"?> | 242 * <?xml version="1.0" encoding="UTF-8"?> |
| 218 * <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.co m/DTDs/PropertyList-1.0.dtd"> | 243 * <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.co m/DTDs/PropertyList-1.0.dtd"> |
| 219 * <plist version="1.0"> | 244 * <plist version="1.0"> |
| 220 * <dict> | 245 * <dict> |
| 221 * <key>BuildVersion</key> | 246 * <key>BuildVersion</key> |
| (...skipping 27 matching lines...) Expand all Loading... | |
| 249 var randomFile = file.openSync(FileMode.WRITE); | 274 var randomFile = file.openSync(FileMode.WRITE); |
| 250 var content = '<script language="JavaScript">location = "$url"</script>'; | 275 var content = '<script language="JavaScript">location = "$url"</script>'; |
| 251 randomFile.writeStringSync(content); | 276 randomFile.writeStringSync(content); |
| 252 randomFile.close(); | 277 randomFile.close(); |
| 253 } | 278 } |
| 254 | 279 |
| 255 Future<bool> start(String url) { | 280 Future<bool> start(String url) { |
| 256 _logEvent("Starting Safari browser on: $url"); | 281 _logEvent("Starting Safari browser on: $url"); |
| 257 return allowPopUps().then((success) { | 282 return allowPopUps().then((success) { |
| 258 if (!success) { | 283 if (!success) { |
| 259 return new Future.immediate(false); | 284 return false; |
| 260 } | 285 } |
| 261 return clearCache().then((_) { | 286 return clearCache().then((cleared) { |
| 287 if (!cleared) { | |
| 288 _logEvent("Could not clear cache"); | |
| 289 return false; | |
| 290 } | |
| 262 // Get the version and log that. | 291 // Get the version and log that. |
| 263 return getVersion().then((version) { | 292 return getVersion().then((version) { |
| 264 _logEvent("Got version: $version"); | 293 _logEvent("Got version: $version"); |
| 265 return new Directory('').createTemp().then((userDir) { | 294 return new Directory('').createTemp().then((userDir) { |
| 266 _cleanup = () { userDir.deleteSync(recursive: true); }; | 295 _cleanup = () { userDir.deleteSync(recursive: true); }; |
| 267 _createLaunchHTML(userDir.path, url); | 296 _createLaunchHTML(userDir.path, url); |
| 268 var args = ["${userDir.path}/launch.html"]; | 297 var args = ["${userDir.path}/launch.html"]; |
| 269 return startBrowser(binary, args); | 298 return startBrowser(binary, args); |
| 270 }); | 299 }); |
| 271 }).catchError((error) { | 300 }).catchError((error) { |
| (...skipping 753 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1025 </head> | 1054 </head> |
| 1026 <body onload="startTesting()"> | 1055 <body onload="startTesting()"> |
| 1027 Dart test driver, number of tests: <div id="number"></div> | 1056 Dart test driver, number of tests: <div id="number"></div> |
| 1028 <iframe id="embedded_iframe"></iframe> | 1057 <iframe id="embedded_iframe"></iframe> |
| 1029 </body> | 1058 </body> |
| 1030 </html> | 1059 </html> |
| 1031 """; | 1060 """; |
| 1032 return driverContent; | 1061 return driverContent; |
| 1033 } | 1062 } |
| 1034 } | 1063 } |
| OLD | NEW |