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

Unified Diff: chrome/browser/resources/file_manager/js/file_manager.js

Issue 10692090: Move FileCopyManager to background page. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 8 years, 5 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/resources/file_manager/js/file_manager.js
===================================================================
--- chrome/browser/resources/file_manager/js/file_manager.js (revision 145517)
+++ chrome/browser/resources/file_manager/js/file_manager.js (working copy)
@@ -14,6 +14,7 @@
* dialog UI.
*/
function FileManager(dialogDom) {
+ this.console_ = console;
dgozman 2012/07/12 13:17:36 Not used.
Oleg Eterevsky 2012/07/12 14:49:22 Done.
this.dialogDom_ = dialogDom;
this.filesystem_ = null;
this.params_ = location.search ?
@@ -543,7 +544,8 @@
};
FileManager.prototype.initDataTransferOperations_ = function() {
- this.copyManager_ = new FileCopyManager(this.filesystem_.root);
+ this.copyManager_ = FileCopyManagerWrapper.getInstance(
+ this.filesystem_.root);
this.copyManager_.addEventListener('copy-progress',
this.onCopyProgress_.bind(this));
this.copyManager_.addEventListener('copy-operation-complete',
@@ -1087,10 +1089,10 @@
// Hack goes below, since we don't receive beforepaste event, but receive
// beforecut and beforecopy events.
case 'paste':
- return this.isRenamingInProgress()
- ? this.document_.queryCommandEnabled(commandId)
- : (!!this.fileTransferController_ &&
- this.fileTransferController_.queryPasteCommandEnabled());
+ return this.isRenamingInProgress() ?
+ this.document_.queryCommandEnabled(commandId) :
+ (!!this.fileTransferController_ &&
+ this.fileTransferController_.queryPasteCommandEnabled());
case 'rename':
return (// Initialized to the point where we have a current directory
@@ -1102,11 +1104,9 @@
this.selection.totalCount == 1);
case 'delete':
- return (this.isRenamingInProgress()
- ? this.document_.queryCommandEnabled(commandId)
- : !readonly &&
- this.selection &&
- this.selection.totalCount > 0);
+ return (this.isRenamingInProgress() ?
+ this.document_.queryCommandEnabled(commandId) :
+ !readonly && this.selection && this.selection.totalCount > 0);
case 'newfolder':
return !readonly &&
@@ -4657,3 +4657,59 @@
}.bind(this));
}
})();
+
+var fileCopyManagerWrapper = null;
+
+/**
+ * @constructor
+ * @param {DirectoryEntry} root Root directory entry.
+ */
+function FileCopyManagerWrapper(root) {
+ var copyManagerPrototype =
+ chrome.extension.getBackgroundPage().FileCopyManager.prototype;
dgozman 2012/07/12 13:17:36 Does this work with unloaded background page?
Oleg Eterevsky 2012/07/12 14:49:22 I wasn't able to test it.
+
+ for (var property in copyManagerPrototype) {
+ if (this[property] === undefined &&
+ typeof copyManagerPrototype[property] === 'function') {
+ this[property] = (function(p) {
+ return function() {
+ var cmInstance =
+ chrome.extension.getBackgroundPage().FileCopyManager.getInstance(
+ root);
+ return cmInstance[p].apply(cmInstance, arguments);
+ }
+ })(property);
+ }
+ }
+}
+
+/**
+ * Extending cr.EventTarget
+ */
+FileCopyManagerWrapper.prototype.__proto__ = cr.EventTarget.prototype;
+
+/**
+ * Create a new instance or get existing instance of FCMW.
+ * @param {DirectoryEntry} root Root directory entry.
+ * @return {FileCopyManagerWrapper} A FileCopyManagerWrapper instance.
+ */
+FileCopyManagerWrapper.getInstance = function(root) {
+ if (fileCopyManagerWrapper === null) {
+ fileCopyManagerWrapper = new FileCopyManagerWrapper(root);
+ }
+ return fileCopyManagerWrapper;
+};
+
+/**
+ * Called be FileCopyManager to raise an event in this instance of FileManager.
+ * @param {string} eventName Event name.
+ * @param {Object} eventArgs Arbitratry field written to event object.
+ */
+FileCopyManagerWrapper.prototype.onEvent = function(eventName, eventArgs) {
+ var event = new cr.Event(eventName);
+ for (var arg in eventArgs)
dgozman 2012/07/12 13:17:36 if (eventArgs.hasOwnProperty(arg))
Oleg Eterevsky 2012/07/12 14:49:22 Done.
+ event[arg] = eventArgs[arg];
+
+ this.dispatchEvent(event);
+};
+

Powered by Google App Engine
This is Rietveld 408576698