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

Side by Side Diff: ios/web/web_state/js/resources/core.js

Issue 2669303004: Removed externalRequest code from CRWWebController. (Closed)
Patch Set: Removed kWindowNameSeparator Created 3 years, 10 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
OLDNEW
1 // Copyright 2012 The Chromium Authors. All rights reserved. 1 // Copyright 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 // This file adheres to closure-compiler conventions in order to enable 5 // This file adheres to closure-compiler conventions in order to enable
6 // compilation with ADVANCED_OPTIMIZATIONS. In particular, members that are to 6 // compilation with ADVANCED_OPTIMIZATIONS. In particular, members that are to
7 // be accessed externally should be specified in this['style'] as opposed to 7 // be accessed externally should be specified in this['style'] as opposed to
8 // this.style because member identifiers are minified by default. 8 // this.style because member identifiers are minified by default.
9 // See http://goo.gl/FwOgy 9 // See http://goo.gl/FwOgy
10 10
(...skipping 529 matching lines...) Expand 10 before | Expand all | Expand 10 after
540 if (node.target === '_blank') 540 if (node.target === '_blank')
541 return false; 541 return false;
542 542
543 // Otherwise UIWebView will take care of the case where there exists a 543 // Otherwise UIWebView will take care of the case where there exists a
544 // browsing context whose name is the same as the given browsing context 544 // browsing context whose name is the same as the given browsing context
545 // name. If there is no such a browsing context, a new browsing context is 545 // name. If there is no such a browsing context, a new browsing context is
546 // being requested. 546 // being requested.
547 return hasFrame_(window, node.target); 547 return hasFrame_(window, node.target);
548 }; 548 };
549 549
550 var getTargetLink_ = function(target) {
551 var node = target;
552 // Find the closest ancester that is a link.
553 while (node) {
554 if (node instanceof HTMLAnchorElement)
555 break;
556 node = node.parentNode;
557 }
558 return node;
559 };
560
561 var setExternalRequest_ = function(href, target) {
562 if (typeof(target) == 'undefined' || target == '_blank' || target == '') {
563 target = '' + Date.now() + '-' + Math.random();
564 }
565 if (typeof(href) == 'undefined') {
566 // W3C recommended behavior.
567 href = 'about:blank';
568 }
569 invokeOnHost_({'command': 'externalRequest',
570 'href': href,
571 'target': target,
572 'referrerPolicy': getReferrerPolicy_()});
573 };
574
575 var resetExternalRequest_ = function() {
576 invokeOnHost_({'command': 'resetExternalRequest'});
577 };
578
579 var clickBubbleListener_ = function(evt) {
580 if (evt['defaultPrevented']) {
581 resetExternalRequest_();
582 }
583 // Remove the listener.
584 evt.currentTarget.removeEventListener(
585 'click', clickBubbleListener_, false);
586 };
587
588 var getComputedWebkitTouchCallout_ = function(element) { 550 var getComputedWebkitTouchCallout_ = function(element) {
589 return window.getComputedStyle(element, null)['webkitTouchCallout']; 551 return window.getComputedStyle(element, null)['webkitTouchCallout'];
590 }; 552 };
591 553
592 // Flush the message queue. 554 // Flush the message queue.
593 if (__gCrWeb.message) { 555 if (__gCrWeb.message) {
594 __gCrWeb.message.invokeQueues(); 556 __gCrWeb.message.invokeQueues();
595 } 557 }
596 558
597 document.addEventListener('click', function(evt) {
598 var node = getTargetLink_(evt.target);
599
600 if (!node)
601 return;
602
603 if (isInternaLink_(node)) {
604 return;
605 }
606 setExternalRequest_(node.href, node.target);
607 // Add listener to the target and its immediate ancesters. These event
608 // listeners will be removed if they get called. The listeners for some
609 // elements might never be removed, but if multiple identical event
610 // listeners are registered on the same event target with the same
611 // parameters the duplicate instances are discarded.
612 for (var level = 0; level < 5; ++level) {
613 if (node && node != document) {
614 node.addEventListener('click', clickBubbleListener_, false);
615 node = node.parentNode;
616 } else {
617 break;
618 }
619 }
620 }, true);
621
622 // Intercept clicks on anchors (links) during bubbling phase so that the
623 // browser can handle target type appropriately.
624 document.addEventListener('click', function(evt) {
625 var node = getTargetLink_(evt.target);
626
627 if (!node)
628 return;
629
630 if (isInternaLink_(node)) {
631 return;
632 } else {
633 // Resets the external request if it has been canceled, otherwise
634 // updates the href in case it has been changed.
635 if (evt['defaultPrevented'])
636 resetExternalRequest_();
637 else
638 setExternalRequest_(node.href, node.target);
639 }
640 }, false);
641
642 // Capture form submit actions. 559 // Capture form submit actions.
643 document.addEventListener('submit', function(evt) { 560 document.addEventListener('submit', function(evt) {
644 if (evt['defaultPrevented']) 561 if (evt['defaultPrevented'])
645 return; 562 return;
646 563
647 var form = evt.target; 564 var form = evt.target;
648 var targetsFrame = form.target && hasFrame_(window, form.target); 565 var targetsFrame = form.target && hasFrame_(window, form.target);
649 566
650 var action = form.getAttribute('action'); 567 var action = form.getAttribute('action');
651 // Default action is to re-submit to same page. 568 // Default action is to re-submit to same page.
652 if (!action) 569 if (!action)
653 action = document.location.href; 570 action = document.location.href;
654 invokeOnHost_({ 571 invokeOnHost_({
655 'command': 'document.submit', 572 'command': 'document.submit',
656 'formName': __gCrWeb.common.getFormIdentifier(evt.srcElement), 573 'formName': __gCrWeb.common.getFormIdentifier(evt.srcElement),
657 'href': __gCrWeb['getFullyQualifiedURL'](action), 574 'href': __gCrWeb['getFullyQualifiedURL'](action),
658 'targetsFrame': targetsFrame 575 'targetsFrame': targetsFrame
659 }); 576 });
660 }, false); 577 }, false);
661 578
662 addFormEventListeners_(); 579 addFormEventListeners_();
663 580
664 }()); // End of anonymous object 581 }()); // End of anonymous object
OLDNEW
« no previous file with comments | « ios/chrome/browser/web/window_open_by_dom_egtest.mm ('k') | ios/web/web_state/ui/crw_web_controller.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698