OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2009 Google Inc. All rights reserved. | 2 * Copyright (C) 2009 Google 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 are | 5 * modification, are permitted provided that the following conditions are |
6 * met: | 6 * met: |
7 * | 7 * |
8 * * Redistributions of source code must retain the above copyright | 8 * * 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 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
(...skipping 445 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
456 * @override | 456 * @override |
457 * @return {boolean} | 457 * @return {boolean} |
458 */ | 458 */ |
459 isHostedMode: function() | 459 isHostedMode: function() |
460 { | 460 { |
461 return true; | 461 return true; |
462 } | 462 } |
463 }; | 463 }; |
464 | 464 |
465 /** | 465 /** |
| 466 * @constructor |
| 467 */ |
| 468 function InspectorFrontendAPIImpl() |
| 469 { |
| 470 this._debugFrontend = !!Runtime.queryParam("debugFrontend") || (window["Insp
ectorTest"] && window["InspectorTest"]["debugTest"]); |
| 471 |
| 472 var descriptors = InspectorFrontendHostAPI.EventDescriptors; |
| 473 for (var i = 0; i < descriptors.length; ++i) |
| 474 this[descriptors[i][1]] = this._dispatch.bind(this, descriptors[i][0], d
escriptors[i][2], descriptors[i][3]); |
| 475 } |
| 476 |
| 477 InspectorFrontendAPIImpl.prototype = { |
| 478 /** |
| 479 * @param {symbol} name |
| 480 * @param {!Array.<string>} signature |
| 481 * @param {boolean} runOnceLoaded |
| 482 */ |
| 483 _dispatch: function(name, signature, runOnceLoaded) |
| 484 { |
| 485 var params = Array.prototype.slice.call(arguments, 3); |
| 486 |
| 487 if (this._debugFrontend) |
| 488 setImmediate(innerDispatch); |
| 489 else |
| 490 innerDispatch(); |
| 491 |
| 492 function innerDispatch() |
| 493 { |
| 494 // Single argument methods get dispatched with the param. |
| 495 if (signature.length < 2) { |
| 496 try { |
| 497 InspectorFrontendHost.events.dispatchEventToListeners(name,
params[0]); |
| 498 } catch (e) { |
| 499 console.error(e + " " + e.stack); |
| 500 } |
| 501 return; |
| 502 } |
| 503 var data = {}; |
| 504 for (var i = 0; i < signature.length; ++i) |
| 505 data[signature[i]] = params[i]; |
| 506 try { |
| 507 InspectorFrontendHost.events.dispatchEventToListeners(name, data
); |
| 508 } catch (e) { |
| 509 console.error(e + " " + e.stack); |
| 510 } |
| 511 } |
| 512 }, |
| 513 |
| 514 /** |
| 515 * @param {number} id |
| 516 * @param {string} chunk |
| 517 */ |
| 518 streamWrite: function(id, chunk) |
| 519 { |
| 520 WebInspector.ResourceLoader.streamWrite(id, chunk); |
| 521 } |
| 522 }; |
| 523 |
| 524 /** |
466 * @type {!InspectorFrontendHostAPI} | 525 * @type {!InspectorFrontendHostAPI} |
467 */ | 526 */ |
468 var InspectorFrontendHost = window.InspectorFrontendHost || null; | 527 var InspectorFrontendHost = window.InspectorFrontendHost || null; |
469 window.InspectorFrontendHost = InspectorFrontendHost; | 528 window.InspectorFrontendHost = InspectorFrontendHost; |
470 (function(){ | 529 (function(){ |
471 | 530 |
472 function initializeInspectorFrontendHost() | 531 function initializeInspectorFrontendHost() |
473 { | 532 { |
474 if (!InspectorFrontendHost) { | 533 if (!InspectorFrontendHost) { |
475 // Instantiate stub for web-hosted mode if necessary. | 534 // Instantiate stub for web-hosted mode if necessary. |
(...skipping 18 matching lines...) Expand all Loading... |
494 { | 553 { |
495 console.error("Incompatible embedder: method InspectorFrontendHost."
+ name + " is missing. Using stub instead."); | 554 console.error("Incompatible embedder: method InspectorFrontendHost."
+ name + " is missing. Using stub instead."); |
496 var args = Array.prototype.slice.call(arguments, 1); | 555 var args = Array.prototype.slice.call(arguments, 1); |
497 return proto[name].apply(InspectorFrontendHost, args); | 556 return proto[name].apply(InspectorFrontendHost, args); |
498 } | 557 } |
499 | 558 |
500 // Attach the events object. | 559 // Attach the events object. |
501 InspectorFrontendHost.events = new WebInspector.Object(); | 560 InspectorFrontendHost.events = new WebInspector.Object(); |
502 } | 561 } |
503 | 562 |
504 /** | |
505 * @constructor | |
506 */ | |
507 function InspectorFrontendAPIImpl() | |
508 { | |
509 this._debugFrontend = !!Runtime.queryParam("debugFrontend") || (window["
InspectorTest"] && window["InspectorTest"]["debugTest"]); | |
510 | |
511 var descriptors = InspectorFrontendHostAPI.EventDescriptors; | |
512 for (var i = 0; i < descriptors.length; ++i) | |
513 this[descriptors[i][1]] = this._dispatch.bind(this, descriptors[i][0
], descriptors[i][2], descriptors[i][3]); | |
514 } | |
515 | |
516 InspectorFrontendAPIImpl.prototype = { | |
517 /** | |
518 * @param {symbol} name | |
519 * @param {!Array.<string>} signature | |
520 * @param {boolean} runOnceLoaded | |
521 */ | |
522 _dispatch: function(name, signature, runOnceLoaded) | |
523 { | |
524 var params = Array.prototype.slice.call(arguments, 3); | |
525 | |
526 if (this._debugFrontend) | |
527 setImmediate(innerDispatch); | |
528 else | |
529 innerDispatch(); | |
530 | |
531 function innerDispatch() | |
532 { | |
533 // Single argument methods get dispatched with the param. | |
534 if (signature.length < 2) { | |
535 try { | |
536 InspectorFrontendHost.events.dispatchEventToListeners(na
me, params[0]); | |
537 } catch (e) { | |
538 console.error(e + " " + e.stack); | |
539 } | |
540 return; | |
541 } | |
542 var data = {}; | |
543 for (var i = 0; i < signature.length; ++i) | |
544 data[signature[i]] = params[i]; | |
545 try { | |
546 InspectorFrontendHost.events.dispatchEventToListeners(name,
data); | |
547 } catch (e) { | |
548 console.error(e + " " + e.stack); | |
549 } | |
550 } | |
551 }, | |
552 | |
553 /** | |
554 * @param {number} id | |
555 * @param {string} chunk | |
556 */ | |
557 streamWrite: function(id, chunk) | |
558 { | |
559 WebInspector.ResourceLoader.streamWrite(id, chunk); | |
560 } | |
561 }; | |
562 | |
563 // FIXME: This file is included into both apps, since the devtools_app needs
the InspectorFrontendHostAPI only, | 563 // FIXME: This file is included into both apps, since the devtools_app needs
the InspectorFrontendHostAPI only, |
564 // so the host instance should not initialized there. | 564 // so the host instance should not initialized there. |
565 initializeInspectorFrontendHost(); | 565 initializeInspectorFrontendHost(); |
566 window.InspectorFrontendAPI = new InspectorFrontendAPIImpl(); | 566 window.InspectorFrontendAPI = new InspectorFrontendAPIImpl(); |
567 WebInspector.setLocalizationPlatform(InspectorFrontendHost.platform()); | 567 WebInspector.setLocalizationPlatform(InspectorFrontendHost.platform()); |
568 })(); | 568 })(); |
569 | 569 |
570 /** | 570 /** |
571 * @type {!WebInspector.EventTarget} | 571 * @type {!WebInspector.EventTarget} |
572 */ | 572 */ |
573 InspectorFrontendHost.events; | 573 InspectorFrontendHost.events; |
OLD | NEW |