feat: [extensions] implement a couple of tabs APIs (#21779)

This commit is contained in:
Jeremy Apthorp 2020-01-15 15:11:51 -08:00 committed by GitHub
parent 8278a64e00
commit b9eb68c0b4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
21 changed files with 568 additions and 17 deletions

View file

@ -23,6 +23,8 @@
#include "ui/gfx/native_widget_types.h"
#include "url/gurl.h"
#include "shell/browser/api/atom_api_web_contents.h"
namespace extensions {
ElectronMessagingDelegate::ElectronMessagingDelegate() = default;
@ -39,13 +41,28 @@ ElectronMessagingDelegate::IsNativeMessagingHostAllowed(
std::unique_ptr<base::DictionaryValue>
ElectronMessagingDelegate::MaybeGetTabInfo(content::WebContents* web_contents) {
if (web_contents) {
auto* api_contents = electron::api::WebContents::FromWrappedClass(
v8::Isolate::GetCurrent(), web_contents);
if (api_contents) {
auto tab = std::make_unique<base::DictionaryValue>();
tab->SetWithoutPathExpansion(
"id", std::make_unique<base::Value>(api_contents->ID()));
return tab;
}
}
return nullptr;
}
content::WebContents* ElectronMessagingDelegate::GetWebContentsByTabId(
content::BrowserContext* browser_context,
int tab_id) {
return nullptr;
auto* contents = electron::api::WebContents::FromWeakMapID(
v8::Isolate::GetCurrent(), tab_id);
if (!contents) {
return nullptr;
}
return contents->web_contents();
}
std::unique_ptr<MessagePort> ElectronMessagingDelegate::CreateReceiverForTab(