blob: 780d63ce367d3dce169c4b80dc4c6e86954cb0ff [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]e4452d32013-11-15 23:07:4112#include "extensions/common/extension.h"
rdevlin.cronin6f42c2522015-06-19 18:58:5113#include "extensions/renderer/extension_frame_helper.h"
[email protected]bcd9580f2014-04-17 19:17:5914#include "extensions/renderer/script_context.h"
[email protected]120028b9c2012-07-03 01:32:2415
16namespace extensions {
17
[email protected]bcd9580f2014-04-17 19:17:5918RuntimeCustomBindings::RuntimeCustomBindings(ScriptContext* context)
Devlin Cronind9ea8342018-01-27 06:00:0419 : ObjectBackedNativeHandler(context) {}
20
21RuntimeCustomBindings::~RuntimeCustomBindings() {}
22
23void RuntimeCustomBindings::AddRoutes() {
24 RouteHandlerFunction(
Devlin Cronincc02a0c2019-01-03 22:15:0725 "GetExtensionViews",
26 base::BindRepeating(&RuntimeCustomBindings::GetExtensionViews,
27 base::Unretained(this)));
[email protected]e6893672014-05-01 17:29:1328}
[email protected]120028b9c2012-07-03 01:32:2429
[email protected]c1e5fb12013-11-13 03:40:3130void RuntimeCustomBindings::GetExtensionViews(
31 const v8::FunctionCallbackInfo<v8::Value>& args) {
catmullings15fd52b2016-07-14 23:46:5932 CHECK_EQ(args.Length(), 3);
rdevlin.croninc7ce4fc2016-05-10 01:41:3733 CHECK(args[0]->IsInt32());
catmullings15fd52b2016-07-14 23:46:5934 CHECK(args[1]->IsInt32());
35 CHECK(args[2]->IsString());
[email protected]c1e5fb12013-11-13 03:40:3136
37 // |browser_window_id| == extension_misc::kUnknownWindowId means getting
38 // all views for the current extension.
Dan Elphickd010a85a2018-08-03 11:32:2639 int browser_window_id = args[0].As<v8::Int32>()->Value();
40 int tab_id = args[1].As<v8::Int32>()->Value();
[email protected]c1e5fb12013-11-13 03:40:3141
brettwc15100c2015-08-06 22:54:1642 std::string view_type_string =
Adam Klein686c0e52018-01-17 23:42:3343 base::ToUpperASCII(*v8::String::Utf8Value(args.GetIsolate(), args[2]));
[email protected]c1e5fb12013-11-13 03:40:3144 // |view_type| == VIEW_TYPE_INVALID means getting any type of
45 // views.
46 ViewType view_type = VIEW_TYPE_INVALID;
Devlin Croninbe3421d2017-11-10 20:32:0747 bool parsed_view_type = GetViewTypeFromString(view_type_string, &view_type);
48 if (!parsed_view_type)
49 CHECK_EQ("ALL", view_type_string);
[email protected]c1e5fb12013-11-13 03:40:3150
rdevlin.croninc7ce4fc2016-05-10 01:41:3751 const std::string& extension_id = context()->GetExtensionID();
[email protected]c1e5fb12013-11-13 03:40:3152 if (extension_id.empty())
53 return;
54
Devlin Cronin16cb0e72017-11-16 19:31:0555 // We ignore iframes here. (Returning subframes can cause broken behavior by
56 // treating an app window's iframe as its main frame, and maybe other
57 // nastiness).
58 // TODO(devlin): Why wouldn't we just account for that? It seems like there
59 // can be reasons to want to access just a frame - especially with isolated
60 // extension frames in web pages.
61 v8::Local<v8::Array> v8_views = ExtensionFrameHelper::GetV8MainFrames(
Dan Elphickd010a85a2018-08-03 11:32:2662 context()->v8_context(), extension_id, browser_window_id, tab_id,
63 view_type);
[email protected]c1e5fb12013-11-13 03:40:3164
65 args.GetReturnValue().Set(v8_views);
66}
67
[email protected]bcdd992f2013-06-09 12:58:0368} // namespace extensions