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 21 MediaInternalsMessageHandler::~MediaInternalsMessageHandler() { 22 proxy_->Detach(); 23 } 24 25 void MediaInternalsMessageHandler::RegisterMessages() { 26 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 27 proxy_->Attach(this); 28 29 web_ui()->RegisterMessageCallback("getEverything", 30 base::Bind(&MediaInternalsMessageHandler::OnGetEverything, 31 base::Unretained(this))); 32 } 33 34 void MediaInternalsMessageHandler::OnGetEverything( 35 const base::ListValue* list) { 36 proxy_->GetEverything(); 37 } 38 39 void MediaInternalsMessageHandler::OnUpdate(const string16& update) { 40 // Don't try to execute JavaScript in a RenderView that no longer exists. 41 RenderViewHost* host = web_ui()->GetWebContents()->GetRenderViewHost(); 42 if (host) 43 host->ExecuteJavascriptInWebFrame(string16(), update); 44 } 45 46 } // namespace content 47