1 | /*
|
2 | * Copyright (c) 2013 Adobe Systems Incorporated. All rights reserved.
|
3 | *
|
4 | * Permission is hereby granted, free of charge, to any person obtaining a
|
5 | * copy of this software and associated documentation files (the "Software"),
|
6 | * to deal in the Software without restriction, including without limitation
|
7 | * the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
8 | * and/or sell copies of the Software, and to permit persons to whom the
|
9 | * Software is furnished to do so, subject to the following conditions:
|
10 | *
|
11 | * The above copyright notice and this permission notice shall be included in
|
12 | * all copies or substantial portions of the Software.
|
13 | *
|
14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
19 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
20 | * DEALINGS IN THE SOFTWARE.
|
21 | *
|
22 | */
|
23 |
|
24 | /*jslint vars: true, plusplus: true, devel: true, nomen: true, indent: 4, maxerr: 50 */
|
25 | /*global brackets: true, navigator:true, document:true, window:true */
|
26 |
|
27 | /**
|
28 | * Function to test whether a given error represents an illegal cross origin access
|
29 | */
|
30 | (function () {
|
31 | ;
|
32 |
|
33 | var testCrossOriginError;
|
34 |
|
35 | if (navigator.userAgent.search(" Chrome/") !== -1) {
|
36 | // Chrome support
|
37 | testCrossOriginError = function (message, url, line) {
|
38 | return url === "" && line === 0 && message === "Script error.";
|
39 | };
|
40 | } else if (navigator.userAgent.slice(0, 6) === 'Opera/') {
|
41 | // Opera support
|
42 | testCrossOriginError = function (message, url, line) {
|
43 | return message === "Uncaught exception: DOMException: NETWORK_ERR";
|
44 | };
|
45 | }
|
46 |
|
47 | // Abort if running in the shell, running on a server or not running in a supported and affected browser
|
48 | if (typeof (brackets) !== "undefined" ||
|
49 | document.location.href.substr(0, 7) !== "file://" ||
|
50 | !testCrossOriginError) {
|
51 | return;
|
52 | }
|
53 |
|
54 | // Remember the current error handler to restore it once we're done
|
55 | var previousErrorHandler = window.onerror;
|
56 |
|
57 | // Our error handler
|
58 | function handleError(message, url, line) {
|
59 | // Ignore this error if it does not look like the rather vague cross origin error in Chrome
|
60 | // Chrome will print it to the console anyway
|
61 | if (!testCrossOriginError(message, url, line)) {
|
62 | if (previousErrorHandler) {
|
63 | return previousErrorHandler(message, url, line);
|
64 | }
|
65 | return;
|
66 | }
|
67 |
|
68 | // Show an error message
|
69 | alert("Oops! This application doesn't run in browsers yet.\n\nIt is built in HTML, but right now it runs as a desktop app so you can use it to edit local files. Please use the application shell in the following repo to run this application:\n\ngithub.com/adobe/brackets-shell");
|
70 |
|
71 | // Restore the original handler for later errors
|
72 | window.onerror = previousErrorHandler;
|
73 | }
|
74 |
|
75 | // Install our error handler
|
76 | window.onerror = handleError;
|
77 | }()); |
\ | No newline at end of file |