NaCl: Update revision in DEPS, r12770 -> r12773
[chromium-blink-merge.git] / chrome / browser / ui / webui / memory_internals / memory_internals_handler.cc
blobc666e8a77873cd32b92ce4f9aae7777ca2c5023e
1 // Copyright 2013 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.
5 #include "chrome/browser/ui/webui/memory_internals/memory_internals_handler.h"
7 #include <vector>
9 #include "base/bind.h"
10 #include "base/bind_helpers.h"
11 #include "base/strings/string16.h"
12 #include "base/values.h"
13 #include "chrome/browser/ui/webui/memory_internals/memory_internals_proxy.h"
14 #include "content/public/browser/browser_thread.h"
15 #include "content/public/browser/render_view_host.h"
16 #include "content/public/browser/web_contents.h"
17 #include "content/public/browser/web_ui.h"
19 MemoryInternalsHandler::MemoryInternalsHandler()
20 : proxy_(new MemoryInternalsProxy()) {}
22 MemoryInternalsHandler::~MemoryInternalsHandler() {
23 proxy_->Detach();
26 void MemoryInternalsHandler::RegisterMessages() {
27 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
28 proxy_->Attach(this);
30 // Set callback functions called by JavaScript messages.
31 web_ui()->RegisterMessageCallback(
32 "update",
33 base::Bind(&MemoryInternalsHandler::OnJSUpdate,
34 base::Unretained(this)));
37 void MemoryInternalsHandler::OnJSUpdate(const base::ListValue* list) {
38 proxy_->StartFetch(list);
41 void MemoryInternalsHandler::OnUpdate(const base::string16& update) {
42 // Don't try to execute JavaScript in a RenderView that no longer exists.
43 content::RenderViewHost* host =
44 web_ui()->GetWebContents()->GetRenderViewHost();
45 if (host)
46 host->ExecuteJavascriptInWebFrame(base::string16(), update);