blob: 816e23ea0183bf4ef36e9428b0ae1e6205c407ea [file] [log] [blame]
[email protected]e6893672014-05-01 17:29:131// Copyright 2014 The Chromium Authors. All rights reserved.
[email protected]120028b9c2012-07-03 01:32:242// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
[email protected]e6893672014-05-01 17:29:135#include "extensions/renderer/runtime_custom_bindings.h"
[email protected]120028b9c2012-07-03 01:32:246
avi2d124c02015-12-23 06:36:427#include <stdint.h>
8
dchengf6f80662016-04-20 20:26:049#include <memory>
10
[email protected]120028b9c2012-07-03 01:32:2411#include "base/bind.h"
[email protected]120028b9c2012-07-03 01:32:2412#include "base/values.h"
rob248d6a82014-11-21 02:04:4813#include "content/public/renderer/render_frame.h"
John Abd-El-Malek312a30bb2017-10-23 19:51:5214#include "content/public/renderer/v8_value_converter.h"
[email protected]e4452d32013-11-15 23:07:4115#include "extensions/common/extension.h"
[email protected]fb820c02014-03-13 15:07:0816#include "extensions/common/extension_messages.h"
[email protected]d42c11152013-08-22 19:36:3217#include "extensions/common/manifest.h"
rdevlin.cronin6f42c2522015-06-19 18:58:5118#include "extensions/renderer/extension_frame_helper.h"
[email protected]bcd9580f2014-04-17 19:17:5919#include "extensions/renderer/script_context.h"
[email protected]120028b9c2012-07-03 01:32:2420
21namespace extensions {
22
[email protected]bcd9580f2014-04-17 19:17:5923RuntimeCustomBindings::RuntimeCustomBindings(ScriptContext* context)
Devlin Cronind9ea8342018-01-27 06:00:0424 : ObjectBackedNativeHandler(context) {}
25
26RuntimeCustomBindings::~RuntimeCustomBindings() {}
27
28void RuntimeCustomBindings::AddRoutes() {
29 RouteHandlerFunction(
[email protected]e6893672014-05-01 17:29:1330 "GetManifest",
31 base::Bind(&RuntimeCustomBindings::GetManifest, base::Unretained(this)));
Devlin Cronind9ea8342018-01-27 06:00:0432 RouteHandlerFunction("GetExtensionViews",
33 base::Bind(&RuntimeCustomBindings::GetExtensionViews,
34 base::Unretained(this)));
[email protected]e6893672014-05-01 17:29:1335}
[email protected]120028b9c2012-07-03 01:32:2436
[email protected]d8c5fbb2013-06-14 11:35:2537void RuntimeCustomBindings::GetManifest(
38 const v8::FunctionCallbackInfo<v8::Value>& args) {
[email protected]9a598442013-06-04 16:39:1239 CHECK(context()->extension());
[email protected]120028b9c2012-07-03 01:32:2440
rdevlin.cronin694c6052017-06-13 22:07:3541 args.GetReturnValue().Set(content::V8ValueConverter::Create()->ToV8Value(
[email protected]e6893672014-05-01 17:29:1342 context()->extension()->manifest()->value(), context()->v8_context()));
[email protected]120028b9c2012-07-03 01:32:2443}
44
[email protected]c1e5fb12013-11-13 03:40:3145void RuntimeCustomBindings::GetExtensionViews(
46 const v8::FunctionCallbackInfo<v8::Value>& args) {
catmullings15fd52b2016-07-14 23:46:5947 CHECK_EQ(args.Length(), 3);
rdevlin.croninc7ce4fc2016-05-10 01:41:3748 CHECK(args[0]->IsInt32());
catmullings15fd52b2016-07-14 23:46:5949 CHECK(args[1]->IsInt32());
50 CHECK(args[2]->IsString());
[email protected]c1e5fb12013-11-13 03:40:3151
52 // |browser_window_id| == extension_misc::kUnknownWindowId means getting
53 // all views for the current extension.
Dan Elphickd010a85a2018-08-03 11:32:2654 int browser_window_id = args[0].As<v8::Int32>()->Value();
55 int tab_id = args[1].As<v8::Int32>()->Value();
[email protected]c1e5fb12013-11-13 03:40:3156
brettwc15100c2015-08-06 22:54:1657 std::string view_type_string =
Adam Klein686c0e52018-01-17 23:42:3358 base::ToUpperASCII(*v8::String::Utf8Value(args.GetIsolate(), args[2]));
[email protected]c1e5fb12013-11-13 03:40:3159 // |view_type| == VIEW_TYPE_INVALID means getting any type of
60 // views.
61 ViewType view_type = VIEW_TYPE_INVALID;
Devlin Croninbe3421d2017-11-10 20:32:0762 bool parsed_view_type = GetViewTypeFromString(view_type_string, &view_type);
63 if (!parsed_view_type)
64 CHECK_EQ("ALL", view_type_string);
[email protected]c1e5fb12013-11-13 03:40:3165
rdevlin.croninc7ce4fc2016-05-10 01:41:3766 const std::string& extension_id = context()->GetExtensionID();
[email protected]c1e5fb12013-11-13 03:40:3167 if (extension_id.empty())
68 return;
69
Devlin Cronin16cb0e72017-11-16 19:31:0570 // We ignore iframes here. (Returning subframes can cause broken behavior by
71 // treating an app window's iframe as its main frame, and maybe other
72 // nastiness).
73 // TODO(devlin): Why wouldn't we just account for that? It seems like there
74 // can be reasons to want to access just a frame - especially with isolated
75 // extension frames in web pages.
76 v8::Local<v8::Array> v8_views = ExtensionFrameHelper::GetV8MainFrames(
Dan Elphickd010a85a2018-08-03 11:32:2677 context()->v8_context(), extension_id, browser_window_id, tab_id,
78 view_type);
[email protected]c1e5fb12013-11-13 03:40:3179
80 args.GetReturnValue().Set(v8_views);
81}
82
[email protected]bcdd992f2013-06-09 12:58:0383} // namespace extensions