Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / extensions / renderer / lazy_background_page_native_handler.cc
blobf09beec7a7f4319e85abdb228df54e069ed4f04b
1 // Copyright 2014 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 "extensions/renderer/lazy_background_page_native_handler.h"
7 #include "base/bind.h"
8 #include "content/public/renderer/render_frame.h"
9 #include "extensions/common/extension_messages.h"
10 #include "extensions/renderer/extension_frame_helper.h"
11 #include "extensions/renderer/script_context.h"
13 namespace extensions {
15 LazyBackgroundPageNativeHandler::LazyBackgroundPageNativeHandler(
16 ScriptContext* context)
17 : ObjectBackedNativeHandler(context) {
18 RouteFunction(
19 "IncrementKeepaliveCount",
20 base::Bind(&LazyBackgroundPageNativeHandler::IncrementKeepaliveCount,
21 base::Unretained(this)));
22 RouteFunction(
23 "DecrementKeepaliveCount",
24 base::Bind(&LazyBackgroundPageNativeHandler::DecrementKeepaliveCount,
25 base::Unretained(this)));
28 void LazyBackgroundPageNativeHandler::IncrementKeepaliveCount(
29 const v8::FunctionCallbackInfo<v8::Value>& args) {
30 if (context() && ExtensionFrameHelper::IsContextForEventPage(context())) {
31 content::RenderFrame* render_frame = context()->GetRenderFrame();
32 render_frame->Send(new ExtensionHostMsg_IncrementLazyKeepaliveCount(
33 render_frame->GetRoutingID()));
37 void LazyBackgroundPageNativeHandler::DecrementKeepaliveCount(
38 const v8::FunctionCallbackInfo<v8::Value>& args) {
39 if (context() && ExtensionFrameHelper::IsContextForEventPage(context())) {
40 content::RenderFrame* render_frame = context()->GetRenderFrame();
41 render_frame->Send(new ExtensionHostMsg_DecrementLazyKeepaliveCount(
42 render_frame->GetRoutingID()));
46 } // namespace extensions