blob: 6553e5e307155a7d9d48be9c59abdcc522401dae [file] [log] [blame]
[email protected]1eea3092012-05-25 04:12:181// 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
hashimotof784afd2014-09-05 02:38:315#include "extensions/renderer/app_window_custom_bindings.h"
[email protected]1eea3092012-05-25 04:12:186
[email protected]1f4da9e2013-06-27 05:23:447#include "base/command_line.h"
mek87e0ab52015-02-13 01:18:268#include "content/public/child/v8_value_converter.h"
rdevlin.cronin25fcbdd62015-07-07 14:11:599#include "content/public/renderer/render_frame.h"
[email protected]eb4bcac2012-06-27 01:32:0810#include "content/public/renderer/render_thread.h"
[email protected]1eea3092012-05-25 04:12:1811#include "content/public/renderer/render_view.h"
[email protected]fb820c02014-03-13 15:07:0812#include "extensions/common/extension_messages.h"
hashimotof784afd2014-09-05 02:38:3113#include "extensions/common/switches.h"
[email protected]bcd9580f2014-04-17 19:17:5914#include "extensions/renderer/script_context.h"
hashimotof784afd2014-09-05 02:38:3115#include "grit/extensions_renderer_resources.h"
[email protected]80504652014-04-18 04:41:5016#include "third_party/WebKit/public/web/WebLocalFrame.h"
[email protected]2255a9332013-06-17 05:12:3117#include "third_party/WebKit/public/web/WebView.h"
[email protected]1f4da9e2013-06-27 05:23:4418#include "ui/base/resource/resource_bundle.h"
[email protected]2bcbf712012-09-05 06:58:4919#include "v8/include/v8.h"
[email protected]1eea3092012-05-25 04:12:1820
21namespace extensions {
22
robaefd3582016-02-15 11:06:2623AppWindowCustomBindings::AppWindowCustomBindings(ScriptContext* context)
24 : ObjectBackedNativeHandler(context) {
rdevlin.croninc827ac22016-05-09 14:17:4925 RouteFunction("GetFrame", base::Bind(&AppWindowCustomBindings::GetFrame,
26 base::Unretained(this)));
[email protected]1f4da9e2013-06-27 05:23:4427
28 RouteFunction("GetWindowControlsHtmlTemplate",
29 base::Bind(&AppWindowCustomBindings::GetWindowControlsHtmlTemplate,
30 base::Unretained(this)));
[email protected]a4430482012-10-23 07:31:0731}
32
rdevlin.croninc3d6ba1b12015-07-09 17:36:5933void AppWindowCustomBindings::GetFrame(
[email protected]d8c5fbb2013-06-14 11:35:2534 const v8::FunctionCallbackInfo<v8::Value>& args) {
[email protected]1eea3092012-05-25 04:12:1835 // TODO(jeremya): convert this to IDL nocompile to get validation, and turn
36 // these argument checks into CHECK().
shuchen70a6b072016-02-23 10:09:0037 if (args.Length() != 2)
[email protected]d8c5fbb2013-06-14 11:35:2538 return;
[email protected]1eea3092012-05-25 04:12:1839
shuchen70a6b072016-02-23 10:09:0040 if (!args[0]->IsInt32() || !args[1]->IsBoolean())
[email protected]d8c5fbb2013-06-14 11:35:2541 return;
[email protected]1eea3092012-05-25 04:12:1842
rdevlin.croninc3d6ba1b12015-07-09 17:36:5943 int frame_id = args[0]->Int32Value();
shuchen70a6b072016-02-23 10:09:0044 bool notify_browser = args[1]->BooleanValue();
[email protected]1eea3092012-05-25 04:12:1845
rdevlin.croninc3d6ba1b12015-07-09 17:36:5946 if (frame_id == MSG_ROUTING_NONE)
[email protected]d8c5fbb2013-06-14 11:35:2547 return;
[email protected]1eea3092012-05-25 04:12:1848
rdevlin.croninc3d6ba1b12015-07-09 17:36:5949 content::RenderFrame* app_frame =
50 content::RenderFrame::FromRoutingID(frame_id);
51 if (!app_frame)
[email protected]d8c5fbb2013-06-14 11:35:2552 return;
[email protected]1eea3092012-05-25 04:12:1853
shuchen70a6b072016-02-23 10:09:0054 if (notify_browser) {
55 content::RenderThread::Get()->Send(new ExtensionHostMsg_AppWindowReady(
56 app_frame->GetRenderView()->GetRoutingID()));
57 }
rdevlin.croninc3d6ba1b12015-07-09 17:36:5958
59 v8::Local<v8::Value> window =
dcheng9e24bd352016-03-01 19:15:5160 app_frame->GetWebFrame()->mainWorldScriptContext()->Global();
[email protected]d8c5fbb2013-06-14 11:35:2561 args.GetReturnValue().Set(window);
[email protected]1eea3092012-05-25 04:12:1862}
63
[email protected]1f4da9e2013-06-27 05:23:4464void AppWindowCustomBindings::GetWindowControlsHtmlTemplate(
65 const v8::FunctionCallbackInfo<v8::Value>& args) {
66 CHECK_EQ(args.Length(), 0);
67
tfarinaf85316f2015-04-29 17:03:4068 v8::Local<v8::Value> result = v8::String::Empty(args.GetIsolate());
avi9ab037202014-12-22 23:49:5369 if (base::CommandLine::ForCurrentProcess()->HasSwitch(
70 switches::kEnableAppWindowControls)) {
[email protected]1aea5262014-07-09 04:55:3371 base::StringValue value(
72 ResourceBundle::GetSharedInstance()
73 .GetRawDataResource(IDR_WINDOW_CONTROLS_TEMPLATE_HTML)
74 .as_string());
dchengf6f80662016-04-20 20:26:0475 std::unique_ptr<content::V8ValueConverter> converter(
[email protected]1f4da9e2013-06-27 05:23:4476 content::V8ValueConverter::create());
[email protected]1aea5262014-07-09 04:55:3377 result = converter->ToV8Value(&value, context()->v8_context());
[email protected]1f4da9e2013-06-27 05:23:4478 }
79 args.GetReturnValue().Set(result);
80}
81
[email protected]1eea3092012-05-25 04:12:1882} // namespace extensions