blob: a45dd4f51e40f5d646116c9bf8acde3433ae7501 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
|
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "content/browser/media/media_internals_handler.h"
#include "base/bind.h"
#include "base/bind_helpers.h"
#include "base/values.h"
#include "content/browser/media/media_internals_proxy.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/render_view_host.h"
#include "content/public/browser/web_contents.h"
#include "content/public/browser/web_ui.h"
namespace content {
MediaInternalsMessageHandler::MediaInternalsMessageHandler()
: proxy_(new MediaInternalsProxy()),
page_load_complete_(false) {}
MediaInternalsMessageHandler::~MediaInternalsMessageHandler() {
proxy_->Detach();
}
void MediaInternalsMessageHandler::RegisterMessages() {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
proxy_->Attach(this);
web_ui()->RegisterMessageCallback("getEverything",
base::Bind(&MediaInternalsMessageHandler::OnGetEverything,
base::Unretained(this)));
}
void MediaInternalsMessageHandler::OnGetEverything(
const base::ListValue* list) {
page_load_complete_ = true;
proxy_->GetEverything();
}
void MediaInternalsMessageHandler::OnUpdate(const string16& update) {
// Don't try to execute JavaScript in a RenderView that no longer exists nor
// if the chrome://media-internals page hasn't finished loading.
RenderViewHost* host = web_ui()->GetWebContents()->GetRenderViewHost();
if (host && page_load_complete_)
host->ExecuteJavascriptInWebFrame(string16(), update);
}
} // namespace content
|