Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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 'use strict'; | 5 'use strict'; |
| 6 | 6 |
| 7 /** | 7 /** |
| 8 * MetadataCache is a map from Entry to an object containing properties. | 8 * MetadataCache is a map from Entry to an object containing properties. |
| 9 * Properties are divided by types, and all properties of one type are accessed | 9 * Properties are divided by types, and all properties of one type are accessed |
| 10 * at once. | 10 * at once. |
| (...skipping 857 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 868 * fetchedMedia: { same fields here } | 868 * fetchedMedia: { same fields here } |
| 869 * @constructor | 869 * @constructor |
| 870 */ | 870 */ |
| 871 function ContentProvider() { | 871 function ContentProvider() { |
| 872 MetadataProvider.call(this); | 872 MetadataProvider.call(this); |
| 873 | 873 |
| 874 // Pass all URLs to the metadata reader until we have a correct filter. | 874 // Pass all URLs to the metadata reader until we have a correct filter. |
| 875 this.urlFilter_ = /.*/; | 875 this.urlFilter_ = /.*/; |
| 876 | 876 |
| 877 var path = document.location.pathname; | 877 var path = document.location.pathname; |
| 878 var workerPath = document.location.origin + | 878 var dispatcher = new SharedWorker(ContentProvider.WORKER_SCRIPT).port; |
| 879 path.substring(0, path.lastIndexOf('/') + 1) + | 879 dispatcher.start(); |
|
yoshiki
2014/04/23 07:08:39
I think, it's better to put start() after adding m
hirono
2014/04/23 08:13:15
Done.
| |
| 880 'foreground/js/metadata/metadata_dispatcher.js'; | 880 dispatcher.onmessage = this.onMessage_.bind(this); |
| 881 | 881 dispatcher.postMessage({verb: 'init'}); |
| 882 this.dispatcher_ = new SharedWorker(workerPath).port; | 882 this.dispatcher_ = dispatcher; |
| 883 this.dispatcher_.start(); | |
| 884 | |
| 885 this.dispatcher_.onmessage = this.onMessage_.bind(this); | |
| 886 this.dispatcher_.postMessage({verb: 'init'}); | |
| 887 | 883 |
| 888 // Initialization is not complete until the Worker sends back the | 884 // Initialization is not complete until the Worker sends back the |
| 889 // 'initialized' message. See below. | 885 // 'initialized' message. See below. |
| 890 this.initialized_ = false; | 886 this.initialized_ = false; |
| 891 | 887 |
| 892 // Map from Entry.toURL() to callback. | 888 // Map from Entry.toURL() to callback. |
| 893 // Note that simultaneous requests for same url are handled in MetadataCache. | 889 // Note that simultaneous requests for same url are handled in MetadataCache. |
| 894 this.callbacks_ = {}; | 890 this.callbacks_ = {}; |
| 895 } | 891 } |
| 896 | 892 |
| 893 /** | |
| 894 * Path of a worker script. | |
| 895 * @type {string} | |
|
yoshiki
2014/04/23 07:08:39
@const
hirono
2014/04/23 08:13:15
Done.
| |
| 896 */ | |
| 897 ContentProvider.WORKER_SCRIPT = | |
| 898 'chrome-extension://hhaomjibdihmijegdhdafkllkbggdgoj/' + | |
| 899 'foreground/js/metadata_dispatcher.js'; | |
| 900 | |
| 897 ContentProvider.prototype = { | 901 ContentProvider.prototype = { |
| 898 __proto__: MetadataProvider.prototype | 902 __proto__: MetadataProvider.prototype |
| 899 }; | 903 }; |
| 900 | 904 |
| 901 /** | 905 /** |
| 902 * @param {Entry} entry The entry. | 906 * @param {Entry} entry The entry. |
| 903 * @return {boolean} Whether this provider supports the entry. | 907 * @return {boolean} Whether this provider supports the entry. |
| 904 */ | 908 */ |
| 905 ContentProvider.prototype.supportsEntry = function(entry) { | 909 ContentProvider.prototype.supportsEntry = function(entry) { |
| 906 return entry.toURL().match(this.urlFilter_); | 910 return entry.toURL().match(this.urlFilter_); |
| (...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1042 | 1046 |
| 1043 /** | 1047 /** |
| 1044 * Handles the 'log' message from the worker. | 1048 * Handles the 'log' message from the worker. |
| 1045 * @param {Array.<*>} arglist Log arguments. | 1049 * @param {Array.<*>} arglist Log arguments. |
| 1046 * @private | 1050 * @private |
| 1047 */ | 1051 */ |
| 1048 ContentProvider.prototype.onLog_ = function(arglist) { | 1052 ContentProvider.prototype.onLog_ = function(arglist) { |
| 1049 if (MetadataCache.log) // Avoid log spam by default. | 1053 if (MetadataCache.log) // Avoid log spam by default. |
| 1050 console.log.apply(console, ['metadata:'].concat(arglist)); | 1054 console.log.apply(console, ['metadata:'].concat(arglist)); |
| 1051 }; | 1055 }; |
| OLD | NEW |