/* -*- Mode: js; js-indent-level: 2; indent-tabs-mode: nil; tab-width: 2 -*- */
/* vim: set shiftwidth=2 tabstop=2 autoindent cindent expandtab: */
/*
 * Copyright 2014 Mozilla Foundation
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

function requestTimelineBuffers() {
  var buffersPromises = [];

  // TODO request timelineBuffers using postMessage (instead of IFramePlayer.Shumway)

  if (IFramePlayer.Shumway.AVM2.timelineBuffer) {
    buffersPromises.push(Promise.resolve(IFramePlayer.Shumway.AVM2.timelineBuffer));
  } else if (Shumway.AVM2.timelineBuffer) {
    buffersPromises.push(Promise.resolve(Shumway.AVM2.timelineBuffer));
  }

  if (IFramePlayer.Shumway.Player.timelineBuffer) {
    buffersPromises.push(Promise.resolve(IFramePlayer.Shumway.Player.timelineBuffer));
  } else if (Shumway.Player.timelineBuffer) {
    buffersPromises.push(Promise.resolve(Shumway.Player.timelineBuffer));
  }

  if (Shumway.GFX.timelineBuffer) {
    buffersPromises.push(Promise.resolve(Shumway.GFX.timelineBuffer));
  }

  if (IFramePlayer.Shumway.SWF.timelineBuffer) {
    buffersPromises.push(Promise.resolve(IFramePlayer.Shumway.SWF.timelineBuffer));
  } else if (Shumway.SWF.timelineBuffer) {
    buffersPromises.push(Promise.resolve(Shumway.SWF.timelineBuffer));
  }


  return Promise.all(buffersPromises);
}

function viewProfile() {
  requestTimelineBuffers().then(function (buffers) {
    profiler.createProfile(buffers);
  });
}

function toggleProfile() {
  alert("Not Implemented");
}

@@ -808,17 +808,16 @@
 s = %5B%5D;%0A
-%0A
   // TOD
@@ -894,17 +894,51 @@
 humway)%0A
+  
 %0A
+  if (IFramePlayer.Shumway) %7B%0A  
   if (IF
@@ -971,32 +971,34 @@
 melineBuffer) %7B%0A
+  
     buffersPromi
@@ -1068,35 +1068,49 @@
 er));%0A  
-%7D else if (
+  %7D%0A    if (IFramePlayer.
 Shumway.
 AVM2.tim
@@ -1093,36 +1093,38 @@
 ePlayer.Shumway.
-AVM2
+Player
 .timelineBuffer)
@@ -1118,32 +1118,34 @@
 melineBuffer) %7B%0A
+  
     buffersPromi
@@ -1169,24 +1169,37 @@
 resolve(
+IFramePlayer.
 Shumway.
 AVM2.tim
@@ -1182,36 +1182,38 @@
 ePlayer.Shumway.
-AVM2
+Player
 .timelineBuffer)
@@ -1209,35 +1209,38 @@
 lineBuffer));%0A  
-%7D%0A%0A
+  %7D%0A  
   if (IFramePlay
@@ -1242,38 +1242,35 @@
 ePlayer.Shumway.
-Player
+SWF
 .timelineBuffer)
@@ -1264,32 +1264,34 @@
 melineBuffer) %7B%0A
+  
     buffersPromi
@@ -1328,38 +1328,165 @@
 ePlayer.Shumway.
-Player
+SWF.timelineBuffer));%0A    %7D%0A  %7D else %7B%0A    if (Shumway.AVM2.timelineBuffer) %7B%0A      buffersPromises.push(Promise.resolve(Shumway.AVM2
 .timelineBuffer)
@@ -1482,38 +1482,39 @@
 lineBuffer));%0A  
-%7D else
+  %7D%0A   
  if (Shumway.Pla
@@ -1527,32 +1527,34 @@
 melineBuffer) %7B%0A
+  
     buffersPromi
@@ -1607,29 +1607,151 @@
 neBuffer));%0A
+    %7D%0A    if (Shumway.SWF.timelineBuffer) %7B%0A      buffersPromises.push(Promise.resolve(Shumway.SWF.timelineBuffer));%0A    %7D%0A
   %7D%0A
-%0A
   if (Shumwa
@@ -1849,265 +1849,11 @@
 ));%0A
+
   %7D
-%0A%0A  if (IFramePlayer.Shumway.SWF.timelineBuffer) %7B%0A    buffersPromises.push(Promise.resolve(IFramePlayer.Shumway.SWF.timelineBuffer));%0A  %7D else if (Shumway.SWF.timelineBuffer) %7B%0A    buffersPromises.push(Promise.resolve(Shumway.SWF.timelineBuffer));%0A  %7D%0A%0A
 %0A  r

Make profiler work for now.