Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(657)

Unified Diff: lib/uri/uri.dart

Issue 10832092: Added origin property to Uri class Added unit test coverage for origin property (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Validate scheme, domain. TODO in place for IllegalArgumentException->StateException. Use Expect.thr… Created 8 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | tests/utils/uri_test.dart » ('j') | tests/utils/uri_test.dart » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: lib/uri/uri.dart
diff --git a/lib/uri/uri.dart b/lib/uri/uri.dart
index ad396eb74d601a970d140a396e406de93ba636b7..965f691d320d2e1faffac4c80c0d17b7871ee03c 100644
--- a/lib/uri/uri.dart
+++ b/lib/uri/uri.dart
@@ -167,6 +167,38 @@ class Uri {
return (userInfo != "") || (domain != "") || (port != 0);
}
+ /**
+ * Returns URI's origin: scheme://domain:port for http/https schemes
ahe 2012/08/21 20:36:28 Comments should be proper sentences. That is, they
+ * Throws IllegalArgumentException for all other schemes
ahe 2012/08/21 20:36:28 Not sure if you want a period or comma on the prev
+ * See (http://www.w3.org/TR/2011/WD-html5-20110405/origin-0.html#origin)
ahe 2012/08/21 20:36:28 There is an example on lines 13-15 for how to incl
+ */
+ 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.toString());
ahe 2012/08/21 20:36:28 I believe toString is no longer necessary.
+ }
+ return sb.toString();
+ }
+
String toString() {
StringBuffer sb = new StringBuffer();
_addIfNonEmpty(sb, scheme, scheme, ':');
« no previous file with comments | « no previous file | tests/utils/uri_test.dart » ('j') | tests/utils/uri_test.dart » ('J')

Powered by Google App Engine
This is Rietveld 408576698