| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 // Event management for WebViewInternal. | 5 // Event management for WebViewInternal. |
| 6 | 6 |
| 7 var DeclarativeWebRequestSchema = | 7 var DeclarativeWebRequestSchema = |
| 8 requireNative('schema_registry').GetSchema('declarativeWebRequest'); | 8 requireNative('schema_registry').GetSchema('declarativeWebRequest'); |
| 9 var EventBindings = require('event_bindings'); | 9 var EventBindings = require('event_bindings'); |
| 10 var IdGenerator = requireNative('id_generator'); | 10 var IdGenerator = requireNative('id_generator'); |
| (...skipping 438 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 449 // Update the partition. | 449 // Update the partition. |
| 450 if (event.storagePartitionId) { | 450 if (event.storagePartitionId) { |
| 451 webViewInternal.onAttach(event.storagePartitionId); | 451 webViewInternal.onAttach(event.storagePartitionId); |
| 452 } | 452 } |
| 453 | 453 |
| 454 var attached = webViewInternal.attachWindow(event.windowId, true); | 454 var attached = webViewInternal.attachWindow(event.windowId, true); |
| 455 | 455 |
| 456 if (!attached) { | 456 if (!attached) { |
| 457 window.console.error(ERROR_MSG_NEWWINDOW_UNABLE_TO_ATTACH); | 457 window.console.error(ERROR_MSG_NEWWINDOW_UNABLE_TO_ATTACH); |
| 458 } | 458 } |
| 459 |
| 460 var guestInstanceId = getGuestInstanceId(); |
| 461 if (!guestInstanceId) { |
| 462 // If the opener is already gone, then we won't have its |
| 463 // guestInstanceId. |
| 464 return; |
| 465 } |
| 466 |
| 459 // If the object being passed into attach is not a valid <webview> | 467 // If the object being passed into attach is not a valid <webview> |
| 460 // then we will fail and it will be treated as if the new window | 468 // then we will fail and it will be treated as if the new window |
| 461 // was rejected. The permission API plumbing is used here to clean | 469 // was rejected. The permission API plumbing is used here to clean |
| 462 // up the state created for the new window if attaching fails. | 470 // up the state created for the new window if attaching fails. |
| 463 WebView.setPermission( | 471 WebView.setPermission( |
| 464 getGuestInstanceId(), requestId, attached ? 'allow' : 'deny'); | 472 guestInstanceId, requestId, attached ? 'allow' : 'deny'); |
| 465 }, 0); | 473 }, 0); |
| 466 }, | 474 }, |
| 467 discard: function() { | 475 discard: function() { |
| 468 validateCall(); | 476 validateCall(); |
| 469 WebView.setPermission(getGuestInstanceId(), requestId, 'deny'); | 477 var guestInstanceId = getGuestInstanceId(); |
| 478 if (!guestInstanceId) { |
| 479 // If the opener is already gone, then we won't have its |
| 480 // guestInstanceId. |
| 481 return; |
| 482 } |
| 483 WebView.setPermission(guestInstanceId, requestId, 'deny'); |
| 470 } | 484 } |
| 471 }; | 485 }; |
| 472 webViewEvent.window = windowObj; | 486 webViewEvent.window = windowObj; |
| 473 | 487 |
| 474 var defaultPrevented = !this.webViewInternal.dispatchEvent(webViewEvent); | 488 var defaultPrevented = !this.webViewInternal.dispatchEvent(webViewEvent); |
| 475 if (actionTaken) { | 489 if (actionTaken) { |
| 476 return; | 490 return; |
| 477 } | 491 } |
| 478 | 492 |
| 479 if (defaultPrevented) { | 493 if (defaultPrevented) { |
| 480 // Make browser plugin track lifetime of |windowObj|. | 494 // Make browser plugin track lifetime of |windowObj|. |
| 481 MessagingNatives.BindToGC(windowObj, function() { | 495 MessagingNatives.BindToGC(windowObj, function() { |
| 482 // Avoid showing a warning message if the decision has already been made. | 496 // Avoid showing a warning message if the decision has already been made. |
| 483 if (actionTaken) { | 497 if (actionTaken) { |
| 484 return; | 498 return; |
| 485 } | 499 } |
| 500 |
| 501 var guestInstanceId = getGuestInstanceId(); |
| 502 if (!guestInstanceId) { |
| 503 // If the opener is already gone, then we won't have its |
| 504 // guestInstanceId. |
| 505 return; |
| 506 } |
| 507 |
| 486 WebView.setPermission( | 508 WebView.setPermission( |
| 487 getGuestInstanceId(), requestId, 'default', '', function(allowed) { | 509 guestInstanceId, requestId, 'default', '', function(allowed) { |
| 488 if (allowed) { | 510 if (allowed) { |
| 489 return; | 511 return; |
| 490 } | 512 } |
| 491 showWarningMessage(); | 513 showWarningMessage(); |
| 492 }); | 514 }); |
| 493 }); | 515 }); |
| 494 } else { | 516 } else { |
| 495 actionTaken = true; | 517 actionTaken = true; |
| 496 // The default action is to discard the window. | 518 // The default action is to discard the window. |
| 497 WebView.setPermission( | 519 WebView.setPermission( |
| 498 getGuestInstanceId(), requestId, 'default', '', function(allowed) { | 520 getGuestInstanceId(), requestId, 'default', '', function(allowed) { |
| 499 if (allowed) { | 521 if (allowed) { |
| 500 return; | 522 return; |
| 501 } | 523 } |
| 502 showWarningMessage(); | 524 showWarningMessage(); |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 599 } | 621 } |
| 600 }; | 622 }; |
| 601 | 623 |
| 602 WebViewEvents.prototype.handleSizeChangedEvent = function( | 624 WebViewEvents.prototype.handleSizeChangedEvent = function( |
| 603 event, webViewEvent) { | 625 event, webViewEvent) { |
| 604 this.webViewInternal.onSizeChanged(webViewEvent); | 626 this.webViewInternal.onSizeChanged(webViewEvent); |
| 605 }; | 627 }; |
| 606 | 628 |
| 607 exports.WebViewEvents = WebViewEvents; | 629 exports.WebViewEvents = WebViewEvents; |
| 608 exports.CreateEvent = CreateEvent; | 630 exports.CreateEvent = CreateEvent; |
| OLD | NEW |