| OLD | NEW |
| 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 463 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 474 window.scrollTo = function(x, y) { | 474 window.scrollTo = function(x, y) { |
| 475 if (webViewScrollViewIsDragging_) | 475 if (webViewScrollViewIsDragging_) |
| 476 return; | 476 return; |
| 477 originalWindowScrollTo(x, y); | 477 originalWindowScrollTo(x, y); |
| 478 }; | 478 }; |
| 479 | 479 |
| 480 window.addEventListener('hashchange', function(evt) { | 480 window.addEventListener('hashchange', function(evt) { |
| 481 invokeOnHost_({'command': 'window.hashchange'}); | 481 invokeOnHost_({'command': 'window.hashchange'}); |
| 482 }); | 482 }); |
| 483 | 483 |
| 484 // Returns if a frame with |name| is found in |currentWindow|. | |
| 485 // Note frame.name is undefined for cross domain frames. | |
| 486 var hasFrame_ = function(currentWindow, name) { | |
| 487 if (currentWindow.name === name) | |
| 488 return true; | |
| 489 | |
| 490 var frames = currentWindow.frames; | |
| 491 for (var index = 0; index < frames.length; ++index) { | |
| 492 var frame = frames[index]; | |
| 493 if (frame === undefined) | |
| 494 continue; | |
| 495 if (hasFrame_(frame, name)) | |
| 496 return true; | |
| 497 } | |
| 498 return false; | |
| 499 }; | |
| 500 | |
| 501 // Checks if |node| is an anchor to be opened in the current tab. | |
| 502 var isInternaLink_ = function(node) { | |
| 503 if (!(node instanceof HTMLAnchorElement)) | |
| 504 return false; | |
| 505 | |
| 506 // Anchor with href='javascript://.....' will be opened in the current tab | |
| 507 // for simplicity. | |
| 508 if (node.href.indexOf('javascript:') == 0) | |
| 509 return true; | |
| 510 | |
| 511 // UIWebView will take care of the following cases. | |
| 512 // | |
| 513 // - If the given browsing context name is the empty string or '_self', then | |
| 514 // the chosen browsing context must be the current one. | |
| 515 // | |
| 516 // - If the given browsing context name is '_parent', then the chosen | |
| 517 // browsing context must be the parent browsing context of the current | |
| 518 // one, unless there is no one, in which case the chosen browsing context | |
| 519 // must be the current browsing context. | |
| 520 // | |
| 521 // - If the given browsing context name is '_top', then the chosen browsing | |
| 522 // context must be the top-level browsing context of the current one, if | |
| 523 // there is one, or else the current browsing context. | |
| 524 // | |
| 525 // Here an undefined target is considered in the same way as an empty | |
| 526 // target. | |
| 527 if (node.target === undefined || node.target === '' || | |
| 528 node.target === '_self' || node.target === '_parent' || | |
| 529 node.target === '_top') { | |
| 530 return true; | |
| 531 } | |
| 532 | |
| 533 // A new browsing context is being requested for an '_blank' target. | |
| 534 if (node.target === '_blank') | |
| 535 return false; | |
| 536 | |
| 537 // Otherwise UIWebView will take care of the case where there exists a | |
| 538 // browsing context whose name is the same as the given browsing context | |
| 539 // name. If there is no such a browsing context, a new browsing context is | |
| 540 // being requested. | |
| 541 return hasFrame_(window, node.target); | |
| 542 }; | |
| 543 | |
| 544 var getComputedWebkitTouchCallout_ = function(element) { | 484 var getComputedWebkitTouchCallout_ = function(element) { |
| 545 return window.getComputedStyle(element, null)['webkitTouchCallout']; | 485 return window.getComputedStyle(element, null)['webkitTouchCallout']; |
| 546 }; | 486 }; |
| 547 | 487 |
| 548 // Flush the message queue. | 488 // Flush the message queue. |
| 549 if (__gCrWeb.message) { | 489 if (__gCrWeb.message) { |
| 550 __gCrWeb.message.invokeQueues(); | 490 __gCrWeb.message.invokeQueues(); |
| 551 } | 491 } |
| 552 | 492 |
| 553 // Capture form submit actions. | 493 // Capture form submit actions. |
| 554 document.addEventListener('submit', function(evt) { | 494 document.addEventListener('submit', function(evt) { |
| 555 var action; | 495 var action; |
| 556 if (evt['defaultPrevented']) | 496 if (evt['defaultPrevented']) |
| 557 return; | 497 return; |
| 558 action = evt.target.getAttribute('action'); | 498 action = evt.target.getAttribute('action'); |
| 559 // Default action is to re-submit to same page. | 499 // Default action is to re-submit to same page. |
| 560 if (!action) | 500 if (!action) |
| 561 action = document.location.href; | 501 action = document.location.href; |
| 562 invokeOnHost_({ | 502 invokeOnHost_({ |
| 563 'command': 'document.submit', | 503 'command': 'document.submit', |
| 564 'formName': __gCrWeb.common.getFormIdentifier(evt.srcElement), | 504 'formName': __gCrWeb.common.getFormIdentifier(evt.srcElement), |
| 565 'href': __gCrWeb['getFullyQualifiedURL'](action) | 505 'href': __gCrWeb['getFullyQualifiedURL'](action) |
| 566 }); | 506 }); |
| 567 }, false); | 507 }, false); |
| 568 | 508 |
| 569 addFormEventListeners_(); | 509 addFormEventListeners_(); |
| 570 | 510 |
| 571 }()); // End of anonymous object | 511 }()); // End of anonymous object |
| OLD | NEW |