| Index: dart/lib/uri/uri.dart
|
| diff --git a/dart/lib/uri/uri.dart b/dart/lib/uri/uri.dart
|
| index 7c6bfdd9ee27798c5c1495a5762bbf409dea254e..c05363827c9de9255f5c249067930e9082ae0446 100644
|
| --- a/dart/lib/uri/uri.dart
|
| +++ b/dart/lib/uri/uri.dart
|
| @@ -171,6 +171,38 @@ class Uri {
|
| return (userInfo != "") || (domain != "") || (port != 0);
|
| }
|
|
|
| + /**
|
| + * For http/https schemes returns URI's [origin][] - scheme://domain:port.
|
| + * For all other schemes throws IllegalArgumentException.
|
| + * [origin]: http://www.w3.org/TR/2011/WD-html5-20110405/origin-0.html#origin
|
| + */
|
| + String get origin() {
|
| + if (scheme == "") {
|
| + // TODO(aprelev@gmail.com): Use StateException instead
|
| + throw new IllegalArgumentException("Cannot use origin without a scheme");
|
| + }
|
| + if (scheme != "http" && scheme != "https") {
|
| + // TODO(aprelev@gmail.com): Use StateException instead
|
| + throw new IllegalArgumentException(
|
| + "origin is applicable to http/https schemes only. Not \'$scheme\'");
|
| + }
|
| + StringBuffer sb = new StringBuffer();
|
| + sb.add(scheme);
|
| + sb.add(":");
|
| + if (domain == null || domain == "") {
|
| + // TODO(aprelev@gmail.com): Use StateException instead
|
| + throw new IllegalArgumentException("Cannot use origin without a domain");
|
| + }
|
| +
|
| + sb.add("//");
|
| + sb.add(domain);
|
| + if (port != 0) {
|
| + sb.add(":");
|
| + sb.add(port);
|
| + }
|
| + return sb.toString();
|
| + }
|
| +
|
| String toString() {
|
| StringBuffer sb = new StringBuffer();
|
| _addIfNonEmpty(sb, scheme, scheme, ':');
|
|
|