Home | History | Annotate | Download | only in media
      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
      3 // found in the LICENSE file.
      4 
      5 #include "content/browser/media/media_internals_handler.h"
      6 
      7 #include "base/bind.h"
      8 #include "base/bind_helpers.h"
      9 #include "base/values.h"
     10 #include "content/browser/media/media_internals_proxy.h"
     11 #include "content/public/browser/browser_thread.h"
     12 #include "content/public/browser/render_view_host.h"
     13 #include "content/public/browser/web_contents.h"
     14 #include "content/public/browser/web_ui.h"
     15 
     16 namespace content {
     17 
     18 MediaInternalsMessageHandler::MediaInternalsMessageHandler()
     19     : proxy_(new MediaInternalsProxy()),
     20       page_load_complete_(false) {}
     21 
     22 MediaInternalsMessageHandler::~MediaInternalsMessageHandler() {
     23   proxy_->Detach();
     24 }
     25 
     26 void MediaInternalsMessageHandler::RegisterMessages() {
     27   DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
     28   proxy_->Attach(this);
     29 
     30   web_ui()->RegisterMessageCallback("getEverything",
     31       base::Bind(&MediaInternalsMessageHandler::OnGetEverything,
     32                  base::Unretained(this)));
     33 }
     34 
     35 void MediaInternalsMessageHandler::OnGetEverything(
     36     const base::ListValue* list) {
     37   page_load_complete_ = true;
     38   proxy_->GetEverything();
     39 }
     40 
     41 void MediaInternalsMessageHandler::OnUpdate(const base::string16& update) {
     42   // Don't try to execute JavaScript in a RenderView that no longer exists nor
     43   // if the chrome://media-internals page hasn't finished loading.
     44   RenderViewHost* host = web_ui()->GetWebContents()->GetRenderViewHost();
     45   if (host && page_load_complete_)
     46     host->ExecuteJavascriptInWebFrame(base::string16(), update);
     47 }
     48 
     49 }  // namespace content
     50