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

Side by Side Diff: Source/core/html/HTMLAnchorElement.cpp

Issue 24066010: Implement URLUtils and URL interface (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: updates based on code review comments Created 7 years, 2 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « Source/core/html/HTMLAnchorElement.h ('k') | Source/core/html/HTMLAnchorElement.idl » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org) 2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org)
3 * (C) 1999 Antti Koivisto (koivisto@kde.org) 3 * (C) 1999 Antti Koivisto (koivisto@kde.org)
4 * (C) 2000 Simon Hausmann <hausmann@kde.org> 4 * (C) 2000 Simon Hausmann <hausmann@kde.org>
5 * Copyright (C) 2003, 2006, 2007, 2008, 2009, 2010 Apple Inc. All rights reserv ed. 5 * Copyright (C) 2003, 2006, 2007, 2008, 2009, 2010 Apple Inc. All rights reserv ed.
6 * (C) 2006 Graham Dennis (graham.dennis@gmail.com) 6 * (C) 2006 Graham Dennis (graham.dennis@gmail.com)
7 * 7 *
8 * This library is free software; you can redistribute it and/or 8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Library General Public 9 * modify it under the terms of the GNU Library General Public
10 * License as published by the Free Software Foundation; either 10 * License as published by the Free Software Foundation; either
(...skipping 325 matching lines...) Expand 10 before | Expand all | Expand 10 after
336 KURL HTMLAnchorElement::href() const 336 KURL HTMLAnchorElement::href() const
337 { 337 {
338 return document().completeURL(stripLeadingAndTrailingHTMLSpaces(getAttribute (hrefAttr))); 338 return document().completeURL(stripLeadingAndTrailingHTMLSpaces(getAttribute (hrefAttr)));
339 } 339 }
340 340
341 void HTMLAnchorElement::setHref(const AtomicString& value) 341 void HTMLAnchorElement::setHref(const AtomicString& value)
342 { 342 {
343 setAttribute(hrefAttr, value); 343 setAttribute(hrefAttr, value);
344 } 344 }
345 345
346 KURL HTMLAnchorElement::url() const
347 {
348 return href();
349 }
350
351 void HTMLAnchorElement::setURL(const KURL& url)
352 {
353 setHref(url.string());
354 }
355
356 String HTMLAnchorElement::input() const
357 {
358 return getAttribute(hrefAttr);
359 }
360
361 void HTMLAnchorElement::setInput(const String& value)
362 {
363 setHref(value);
364 }
365
346 bool HTMLAnchorElement::hasRel(uint32_t relation) const 366 bool HTMLAnchorElement::hasRel(uint32_t relation) const
347 { 367 {
348 return m_linkRelations & relation; 368 return m_linkRelations & relation;
349 } 369 }
350 370
351 void HTMLAnchorElement::setRel(const String& value) 371 void HTMLAnchorElement::setRel(const String& value)
352 { 372 {
353 m_linkRelations = 0; 373 m_linkRelations = 0;
354 SpaceSplitString newLinkRelations(value, true); 374 SpaceSplitString newLinkRelations(value, true);
355 // FIXME: Add link relations as they are implemented 375 // FIXME: Add link relations as they are implemented
(...skipping 10 matching lines...) Expand all
366 { 386 {
367 // Skip the supportsFocus check in HTMLElement. 387 // Skip the supportsFocus check in HTMLElement.
368 return Element::tabIndex(); 388 return Element::tabIndex();
369 } 389 }
370 390
371 String HTMLAnchorElement::target() const 391 String HTMLAnchorElement::target() const
372 { 392 {
373 return getAttribute(targetAttr); 393 return getAttribute(targetAttr);
374 } 394 }
375 395
376 String HTMLAnchorElement::hash() const
377 {
378 String fragmentIdentifier = href().fragmentIdentifier();
379 if (fragmentIdentifier.isEmpty())
380 return emptyString();
381 return AtomicString(String("#" + fragmentIdentifier));
382 }
383
384 void HTMLAnchorElement::setHash(const String& value)
385 {
386 KURL url = href();
387 if (value[0] == '#')
388 url.setFragmentIdentifier(value.substring(1));
389 else
390 url.setFragmentIdentifier(value);
391 setHref(url.string());
392 }
393
394 String HTMLAnchorElement::host() const
395 {
396 const KURL& url = href();
397 if (url.hostEnd() == url.pathStart())
398 return url.host();
399 if (isDefaultPortForProtocol(url.port(), url.protocol()))
400 return url.host();
401 return url.host() + ":" + String::number(url.port());
402 }
403
404 void HTMLAnchorElement::setHost(const String& value)
405 {
406 if (value.isEmpty())
407 return;
408 KURL url = href();
409 if (!url.canSetHostOrPort())
410 return;
411
412 size_t separator = value.find(':');
413 if (!separator)
414 return;
415
416 if (separator == kNotFound) {
417 url.setHost(value);
418 } else {
419 unsigned portEnd;
420 unsigned port = parsePortFromStringPosition(value, separator + 1, portEn d);
421 if (!port) {
422 // http://dev.w3.org/html5/spec/infrastructure.html#url-decompositio n-idl-attributes
423 // specifically goes against RFC 3986 (p3.2) and
424 // requires setting the port to "0" if it is set to empty string.
425 url.setHostAndPort(value.substring(0, separator + 1) + "0");
426 } else {
427 if (isDefaultPortForProtocol(port, url.protocol()))
428 url.setHostAndPort(value.substring(0, separator));
429 else
430 url.setHostAndPort(value.substring(0, portEnd));
431 }
432 }
433 setHref(url.string());
434 }
435
436 String HTMLAnchorElement::hostname() const
437 {
438 return href().host();
439 }
440
441 void HTMLAnchorElement::setHostname(const String& value)
442 {
443 // Before setting new value:
444 // Remove all leading U+002F SOLIDUS ("/") characters.
445 unsigned i = 0;
446 unsigned hostLength = value.length();
447 while (value[i] == '/')
448 i++;
449
450 if (i == hostLength)
451 return;
452
453 KURL url = href();
454 if (!url.canSetHostOrPort())
455 return;
456
457 url.setHost(value.substring(i));
458 setHref(url.string());
459 }
460
461 String HTMLAnchorElement::pathname() const
462 {
463 return href().path();
464 }
465
466 void HTMLAnchorElement::setPathname(const String& value)
467 {
468 KURL url = href();
469 if (!url.canSetPathname())
470 return;
471
472 if (value[0] == '/')
473 url.setPath(value);
474 else
475 url.setPath("/" + value);
476
477 setHref(url.string());
478 }
479
480 String HTMLAnchorElement::port() const
481 {
482 if (href().hasPort())
483 return String::number(href().port());
484
485 return emptyString();
486 }
487
488 void HTMLAnchorElement::setPort(const String& value)
489 {
490 KURL url = href();
491 if (!url.canSetHostOrPort())
492 return;
493
494 // http://dev.w3.org/html5/spec/infrastructure.html#url-decomposition-idl-at tributes
495 // specifically goes against RFC 3986 (p3.2) and
496 // requires setting the port to "0" if it is set to empty string.
497 unsigned port = value.toUInt();
498 if (isDefaultPortForProtocol(port, url.protocol()))
499 url.removePort();
500 else
501 url.setPort(port);
502
503 setHref(url.string());
504 }
505
506 String HTMLAnchorElement::protocol() const
507 {
508 return href().protocol() + ":";
509 }
510
511 void HTMLAnchorElement::setProtocol(const String& value)
512 {
513 KURL url = href();
514 url.setProtocol(value);
515 setHref(url.string());
516 }
517
518 String HTMLAnchorElement::search() const
519 {
520 String query = href().query();
521 return query.isEmpty() ? emptyString() : "?" + query;
522 }
523
524 String HTMLAnchorElement::origin() const
525 {
526 RefPtr<SecurityOrigin> origin = SecurityOrigin::create(href());
527 return origin->toString();
528 }
529
530 void HTMLAnchorElement::setSearch(const String& value)
531 {
532 KURL url = href();
533 String newSearch = (value[0] == '?') ? value.substring(1) : value;
534 // Make sure that '#' in the query does not leak to the hash.
535 url.setQuery(newSearch.replaceWithLiteral('#', "%23"));
536
537 setHref(url.string());
538 }
539 396
540 String HTMLAnchorElement::text() 397 String HTMLAnchorElement::text()
541 { 398 {
542 return innerText(); 399 return innerText();
543 } 400 }
544 401
545 String HTMLAnchorElement::toString() const
546 {
547 return href().string();
548 }
549
550 bool HTMLAnchorElement::isLiveLink() const 402 bool HTMLAnchorElement::isLiveLink() const
551 { 403 {
552 return isLink() && treatLinkAsLiveForEventType(m_wasShiftKeyDownOnMouseDown ? MouseEventWithShiftKey : MouseEventWithoutShiftKey); 404 return isLink() && treatLinkAsLiveForEventType(m_wasShiftKeyDownOnMouseDown ? MouseEventWithShiftKey : MouseEventWithoutShiftKey);
553 } 405 }
554 406
555 void HTMLAnchorElement::sendPings(const KURL& destinationURL) 407 void HTMLAnchorElement::sendPings(const KURL& destinationURL)
556 { 408 {
557 if (!hasAttribute(pingAttr) || !document().settings() || !document().setting s()->hyperlinkAuditingEnabled()) 409 if (!hasAttribute(pingAttr) || !document().settings() || !document().setting s()->hyperlinkAuditingEnabled())
558 return; 410 return;
559 411
(...skipping 286 matching lines...) Expand 10 before | Expand all | Expand 10 after
846 698
847 // The precision of current MouseOver trigger is too low to actually trigger preconnects. 699 // The precision of current MouseOver trigger is too low to actually trigger preconnects.
848 if (motivation == WebKit::WebPreconnectMotivationLinkMouseOver) 700 if (motivation == WebKit::WebPreconnectMotivationLinkMouseOver)
849 return; 701 return;
850 702
851 preconnectToURL(url, motivation); 703 preconnectToURL(url, motivation);
852 m_hasIssuedPreconnect = true; 704 m_hasIssuedPreconnect = true;
853 } 705 }
854 706
855 } 707 }
OLDNEW
« no previous file with comments | « Source/core/html/HTMLAnchorElement.h ('k') | Source/core/html/HTMLAnchorElement.idl » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698