2019-08-19 20:13:24 +00:00
|
|
|
// Copyright (c) 2019 GitHub, Inc.
|
|
|
|
// Use of this source code is governed by the MIT license that can be
|
|
|
|
// found in the LICENSE file.
|
|
|
|
|
2020-02-04 20:19:40 +00:00
|
|
|
#include "shell/browser/electron_autofill_driver.h"
|
2019-08-19 20:13:24 +00:00
|
|
|
|
2019-09-16 22:12:00 +00:00
|
|
|
#include <memory>
|
|
|
|
|
2019-08-19 20:13:24 +00:00
|
|
|
#include <utility>
|
|
|
|
|
|
|
|
#include "content/public/browser/render_widget_host_view.h"
|
2020-02-04 20:19:40 +00:00
|
|
|
#include "shell/browser/api/electron_api_web_contents.h"
|
2020-06-22 16:35:24 +00:00
|
|
|
#include "shell/browser/javascript_environment.h"
|
2019-08-19 20:13:24 +00:00
|
|
|
#include "shell/browser/native_window.h"
|
|
|
|
|
|
|
|
namespace electron {
|
|
|
|
|
|
|
|
AutofillDriver::AutofillDriver(
|
|
|
|
content::RenderFrameHost* render_frame_host,
|
|
|
|
mojom::ElectronAutofillDriverAssociatedRequest request)
|
|
|
|
: render_frame_host_(render_frame_host), binding_(this) {
|
2019-09-16 22:12:00 +00:00
|
|
|
autofill_popup_ = std::make_unique<AutofillPopup>();
|
2019-08-19 20:13:24 +00:00
|
|
|
binding_.Bind(std::move(request));
|
|
|
|
}
|
|
|
|
|
2019-09-16 22:12:00 +00:00
|
|
|
AutofillDriver::~AutofillDriver() = default;
|
2019-08-19 20:13:24 +00:00
|
|
|
|
|
|
|
void AutofillDriver::ShowAutofillPopup(
|
|
|
|
const gfx::RectF& bounds,
|
|
|
|
const std::vector<base::string16>& values,
|
|
|
|
const std::vector<base::string16>& labels) {
|
2020-06-22 16:35:24 +00:00
|
|
|
v8::Isolate* isolate = JavascriptEnvironment::GetIsolate();
|
2020-03-11 01:16:58 +00:00
|
|
|
v8::HandleScope scope(isolate);
|
2019-08-19 20:13:24 +00:00
|
|
|
auto* web_contents =
|
2020-03-11 01:16:58 +00:00
|
|
|
api::WebContents::From(isolate, content::WebContents::FromRenderFrameHost(
|
|
|
|
render_frame_host_))
|
2019-08-19 20:13:24 +00:00
|
|
|
.get();
|
|
|
|
if (!web_contents || !web_contents->owner_window())
|
|
|
|
return;
|
|
|
|
|
|
|
|
auto* embedder = web_contents->embedder();
|
|
|
|
|
|
|
|
bool osr =
|
|
|
|
web_contents->IsOffScreen() || (embedder && embedder->IsOffScreen());
|
|
|
|
gfx::RectF popup_bounds(bounds);
|
|
|
|
content::RenderFrameHost* embedder_frame_host = nullptr;
|
|
|
|
if (embedder) {
|
|
|
|
auto* embedder_view = embedder->web_contents()->GetMainFrame()->GetView();
|
|
|
|
auto* view = web_contents->web_contents()->GetMainFrame()->GetView();
|
|
|
|
auto offset = view->GetViewBounds().origin() -
|
|
|
|
embedder_view->GetViewBounds().origin();
|
2019-09-19 15:05:57 +00:00
|
|
|
popup_bounds.Offset(offset);
|
2019-08-19 20:13:24 +00:00
|
|
|
embedder_frame_host = embedder->web_contents()->GetMainFrame();
|
|
|
|
}
|
|
|
|
|
|
|
|
autofill_popup_->CreateView(render_frame_host_, embedder_frame_host, osr,
|
|
|
|
web_contents->owner_window()->content_view(),
|
2019-09-19 15:05:57 +00:00
|
|
|
popup_bounds);
|
2019-08-19 20:13:24 +00:00
|
|
|
autofill_popup_->SetItems(values, labels);
|
|
|
|
}
|
|
|
|
|
|
|
|
void AutofillDriver::HideAutofillPopup() {
|
|
|
|
if (autofill_popup_)
|
|
|
|
autofill_popup_->Hide();
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace electron
|