This source file includes following definitions.
- RegisterMessages
- OnJSUpdate
- OnUpdate
#include "chrome/browser/ui/webui/memory_internals/memory_internals_handler.h"
#include <vector>
#include "base/bind.h"
#include "base/bind_helpers.h"
#include "base/strings/string16.h"
#include "base/values.h"
#include "chrome/browser/ui/webui/memory_internals/memory_internals_proxy.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/render_frame_host.h"
#include "content/public/browser/web_contents.h"
#include "content/public/browser/web_ui.h"
MemoryInternalsHandler::MemoryInternalsHandler()
: proxy_(new MemoryInternalsProxy()) {}
MemoryInternalsHandler::~MemoryInternalsHandler() {
proxy_->Detach();
}
void MemoryInternalsHandler::RegisterMessages() {
DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
proxy_->Attach(this);
web_ui()->RegisterMessageCallback(
"update",
base::Bind(&MemoryInternalsHandler::OnJSUpdate,
base::Unretained(this)));
}
void MemoryInternalsHandler::OnJSUpdate(const base::ListValue* list) {
proxy_->StartFetch(list);
}
void MemoryInternalsHandler::OnUpdate(const base::string16& update) {
content::RenderFrameHost* frame = web_ui()->GetWebContents()->GetMainFrame();
if (frame)
frame->ExecuteJavaScript(update);
}