OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2007, 2008 Apple Inc. All rights reserved. | 2 * Copyright (C) 2007, 2008 Apple Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions |
6 * are met: | 6 * are met: |
7 * | 7 * |
8 * 1. Redistributions of source code must retain the above copyright | 8 * 1. Redistributions of source code must retain the above copyright |
9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
10 * 2. Redistributions in binary form must reproduce the above copyright | 10 * 2. Redistributions in binary form must reproduce the above copyright |
(...skipping 607 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
618 | 618 |
619 if (msg) | 619 if (msg) |
620 WebInspector.console.addMessage(msg); | 620 WebInspector.console.addMessage(msg); |
621 }, | 621 }, |
622 | 622 |
623 get content() | 623 get content() |
624 { | 624 { |
625 return this._content; | 625 return this._content; |
626 }, | 626 }, |
627 | 627 |
628 set content(content) | |
629 { | |
630 var data = { oldContent: this._content, oldContentTimestamp: this._conte
ntTimestamp }; | |
631 this._content = content; | |
632 this._contentTimestamp = new Date(); | |
633 this.dispatchEventToListeners("content-changed", data); | |
634 }, | |
635 | |
636 get contentTimestamp() | 628 get contentTimestamp() |
637 { | 629 { |
638 return this._contentTimestamp; | 630 return this._contentTimestamp; |
639 }, | 631 }, |
640 | 632 |
641 setInitialContent: function(content) | 633 setInitialContent: function(content) |
642 { | 634 { |
643 this._content = content; | 635 this._content = content; |
644 }, | 636 }, |
645 | 637 |
| 638 isLocallyModified: function() |
| 639 { |
| 640 return !!this._baseRevision; |
| 641 }, |
| 642 |
| 643 setContent: function(newContent, onRevert) |
| 644 { |
| 645 var revisionResource = new WebInspector.Resource(null, this.url); |
| 646 revisionResource.type = this.type; |
| 647 revisionResource.loader = this.loader; |
| 648 revisionResource.timestamp = this.timestamp; |
| 649 revisionResource._content = this._content; |
| 650 revisionResource._actualResource = this; |
| 651 revisionResource._fireOnRevert = onRevert; |
| 652 |
| 653 if (this.finished) |
| 654 revisionResource.finished = true; |
| 655 else { |
| 656 function finished() |
| 657 { |
| 658 this.removeEventListener("finished", finished); |
| 659 revisionResource.finished = true; |
| 660 } |
| 661 this.addEventListener("finished", finished.bind(this)); |
| 662 } |
| 663 |
| 664 if (!this._baseRevision) |
| 665 this._baseRevision = revisionResource; |
| 666 else |
| 667 revisionResource._baseRevision = this._baseRevision; |
| 668 |
| 669 var data = { revision: revisionResource }; |
| 670 this._content = newContent; |
| 671 this.timestamp = new Date(); |
| 672 this.dispatchEventToListeners("content-changed", data); |
| 673 }, |
| 674 |
| 675 revertToThis: function() |
| 676 { |
| 677 if (!this._actualResource || !this._fireOnRevert) |
| 678 return; |
| 679 |
| 680 function callback(content) |
| 681 { |
| 682 if (content) |
| 683 this._fireOnRevert(content); |
| 684 } |
| 685 this.requestContent(callback.bind(this)); |
| 686 }, |
| 687 |
| 688 get baseRevision() |
| 689 { |
| 690 return this._baseRevision; |
| 691 }, |
| 692 |
646 requestContent: function(callback) | 693 requestContent: function(callback) |
647 { | 694 { |
648 if (this._content) { | 695 if (this._content) { |
649 callback(this._content, this._contentEncoded); | 696 callback(this._content, this._contentEncoded); |
650 return; | 697 return; |
651 } | 698 } |
652 this._pendingContentCallbacks.push(callback); | 699 this._pendingContentCallbacks.push(callback); |
653 if (this.finished) | 700 if (this.finished) |
654 this._innerRequestContent(); | 701 this._innerRequestContent(); |
655 }, | 702 }, |
(...skipping 22 matching lines...) Expand all Loading... |
678 for (var i = 0; i < callbacks.length; ++i) | 725 for (var i = 0; i < callbacks.length; ++i) |
679 callbacks[i](this._content, this._contentEncoded); | 726 callbacks[i](this._content, this._contentEncoded); |
680 this._pendingContentCallbacks.length = 0; | 727 this._pendingContentCallbacks.length = 0; |
681 delete this._contentRequested; | 728 delete this._contentRequested; |
682 } | 729 } |
683 WebInspector.ResourceManager.requestContent(this, this._contentEncoded,
onResourceContent.bind(this)); | 730 WebInspector.ResourceManager.requestContent(this, this._contentEncoded,
onResourceContent.bind(this)); |
684 } | 731 } |
685 } | 732 } |
686 | 733 |
687 WebInspector.Resource.prototype.__proto__ = WebInspector.Object.prototype; | 734 WebInspector.Resource.prototype.__proto__ = WebInspector.Object.prototype; |
OLD | NEW |