Skip to content

Commit

Permalink
fix: clean up after rebase
Browse files Browse the repository at this point in the history
  • Loading branch information
brenca committed Aug 11, 2019
1 parent cee5779 commit 6f79ba3
Show file tree
Hide file tree
Showing 9 changed files with 47 additions and 137 deletions.
13 changes: 1 addition & 12 deletions shell/browser/api/atom_api_web_contents.cc
Expand Up @@ -472,7 +472,7 @@ void WebContents::InitWithSessionAndOptions(
base::Unretained(this)));
bindings_.set_connection_error_handler(base::BindRepeating(
&WebContents::OnElectronBrowserConnectionError, base::Unretained(this)));
atom::AutofillDriverFactory::CreateForWebContents(web_contents());
AutofillDriverFactory::CreateForWebContents(web_contents());

web_contents()->SetUserAgentOverride(GetBrowserContext()->GetUserAgent(),
false);
Expand Down Expand Up @@ -2202,17 +2202,6 @@ void WebContents::DoGetZoomLevel(DoGetZoomLevelCallback callback) {
std::move(callback).Run(GetZoomLevel());
}

void WebContents::ShowAutofillPopup(const gfx::RectF& bounds,
const std::vector<base::string16>& values,
const std::vector<base::string16>& labels) {
content::RenderFrameHost* frame_host = bindings_.dispatch_context();
ShowAutofillPopup(frame_host, bounds, values, labels);
}

void WebContents::HideAutofillPopup() {
CommonWebContentsDelegate::HideAutofillPopup();
}

std::vector<base::FilePath::StringType> WebContents::GetPreloadPaths() const {
auto result = SessionPreferences::GetValidPreloads(GetBrowserContext());

Expand Down
3 changes: 2 additions & 1 deletion shell/browser/api/atom_api_web_contents.h
Expand Up @@ -28,7 +28,6 @@
#include "shell/browser/api/save_page_handler.h"
#include "shell/browser/api/trackable_object.h"
#include "shell/browser/common_web_contents_delegate.h"
#include "shell/browser/ui/autofill_popup.h"
#include "ui/gfx/image/image.h"

#if BUILDFLAG(ENABLE_PRINTING)
Expand Down Expand Up @@ -324,6 +323,8 @@ class WebContents : public mate::TrackableObject<WebContents>,
bool EmitNavigationEvent(const std::string& event,
content::NavigationHandle* navigation_handle);

WebContents* embedder() { return embedder_; }

protected:
// Does not manage lifetime of |web_contents|.
WebContents(v8::Isolate* isolate, content::WebContents* web_contents);
Expand Down
Expand Up @@ -2,53 +2,15 @@
// Use of this source code is governed by the MIT license that can be
// found in the LICENSE file.

#include "atom/browser/atom_autofill_driver.h"
#include "shell/browser/atom_autofill_driver.h"

#include <utility>

#include "atom/browser/api/atom_api_web_contents.h"
#include "atom/browser/native_window.h"
#include "content/public/browser/render_widget_host_view.h"
#include "shell/browser/api/atom_api_web_contents.h"
#include "shell/browser/native_window.h"

namespace atom {

namespace {

const api::WebContents* WebContentsFromContentWebContents(
content::WebContents* web_contents) {
auto api_web_contents =
api::WebContents::From(v8::Isolate::GetCurrent(), web_contents);
if (!api_web_contents.IsEmpty()) {
return api_web_contents.get();
}

return nullptr;
}

const api::WebContents* WebContentsFromRenderFrameHost(
content::RenderFrameHost* render_frame_host) {
content::WebContents* web_contents =
content::WebContents::FromRenderFrameHost(render_frame_host);

if (web_contents) {
return WebContentsFromContentWebContents(web_contents);
}

return nullptr;
}

const api::WebContents* EmbedderFromWebContents(
const api::WebContents* web_contents) {
auto* embedder_web_contents = web_contents->HostWebContents();

if (embedder_web_contents) {
return WebContentsFromContentWebContents(embedder_web_contents);
}

return nullptr;
}

} // namespace
namespace electron {

AutofillDriver::AutofillDriver(content::RenderFrameHost* render_frame_host)
: render_frame_host_(render_frame_host), binding_(this) {
Expand All @@ -66,11 +28,15 @@ void AutofillDriver::ShowAutofillPopup(
const gfx::RectF& bounds,
const std::vector<base::string16>& values,
const std::vector<base::string16>& labels) {
auto* web_contents = WebContentsFromRenderFrameHost(render_frame_host_);
auto* web_contents =
api::WebContents::From(
v8::Isolate::GetCurrent(),
content::WebContents::FromRenderFrameHost(render_frame_host_))
.get();
if (!web_contents || !web_contents->owner_window())
return;

auto* embedder = EmbedderFromWebContents(web_contents);
auto* embedder = web_contents->embedder();

bool osr =
web_contents->IsOffScreen() || (embedder && embedder->IsOffScreen());
Expand All @@ -96,4 +62,4 @@ void AutofillDriver::HideAutofillPopup() {
autofill_popup_->Hide();
}

} // namespace atom
} // namespace electron
Expand Up @@ -8,13 +8,13 @@
#include <memory>

#if defined(TOOLKIT_VIEWS)
#include "atom/browser/ui/autofill_popup.h"
#include "shell/browser/ui/autofill_popup.h"
#endif

#include "atom/common/api/api.mojom.h"
#include "mojo/public/cpp/bindings/associated_binding.h"
#include "shell/common/api/api.mojom.h"

namespace atom {
namespace electron {

class AutofillDriver : public mojom::ElectronAutofillDriver {
public:
Expand All @@ -39,6 +39,6 @@ class AutofillDriver : public mojom::ElectronAutofillDriver {
mojo::AssociatedBinding<mojom::ElectronAutofillDriver> binding_;
};

} // namespace atom
} // namespace electron

#endif // ATOM_BROWSER_ATOM_AUTOFILL_DRIVER_H_
Expand Up @@ -2,20 +2,20 @@
// Use of this source code is governed by the MIT license that can be
// found in the LICENSE file.

#include "atom/browser/atom_autofill_driver_factory.h"
#include "shell/browser/atom_autofill_driver_factory.h"

#include <memory>
#include <utility>
#include <vector>

#include "atom/browser/atom_autofill_driver.h"
#include "base/bind.h"
#include "base/callback.h"
#include "content/public/browser/navigation_handle.h"
#include "content/public/browser/render_frame_host.h"
#include "content/public/browser/web_contents.h"
#include "shell/browser/atom_autofill_driver.h"

namespace atom {
namespace electron {

namespace {

Expand All @@ -26,37 +26,8 @@ std::unique_ptr<AutofillDriver> CreateDriver(

} // namespace

const char
AutofillDriverFactory::kAtomAutofillDriverFactoryWebContentsUserDataKey[] =
"atom_web_contents_autofill_driver_factory";

AutofillDriverFactory::~AutofillDriverFactory() {}

// static
void AutofillDriverFactory::CreateForWebContents(
content::WebContents* contents) {
if (FromWebContents(contents))
return;

auto new_factory = std::make_unique<AutofillDriverFactory>(contents);
const std::vector<content::RenderFrameHost*> frames =
contents->GetAllFrames();
for (content::RenderFrameHost* frame : frames) {
if (frame->IsRenderFrameLive())
new_factory->RenderFrameCreated(frame);
}

contents->SetUserData(kAtomAutofillDriverFactoryWebContentsUserDataKey,
std::move(new_factory));
}

// static
AutofillDriverFactory* AutofillDriverFactory::FromWebContents(
content::WebContents* contents) {
return static_cast<AutofillDriverFactory*>(
contents->GetUserData(kAtomAutofillDriverFactoryWebContentsUserDataKey));
}

// static
void AutofillDriverFactory::BindAutofillDriver(
mojom::ElectronAutofillDriverAssociatedRequest request,
Expand All @@ -77,7 +48,14 @@ void AutofillDriverFactory::BindAutofillDriver(
}

AutofillDriverFactory::AutofillDriverFactory(content::WebContents* web_contents)
: content::WebContentsObserver(web_contents) {}
: content::WebContentsObserver(web_contents) {
const std::vector<content::RenderFrameHost*> frames =
web_contents->GetAllFrames();
for (content::RenderFrameHost* frame : frames) {
if (frame->IsRenderFrameLive())
RenderFrameCreated(frame);
}
}

void AutofillDriverFactory::RenderFrameCreated(
content::RenderFrameHost* render_frame_host) {
Expand Down Expand Up @@ -130,4 +108,6 @@ void AutofillDriverFactory::CloseAllPopups() {
}
}

} // namespace atom
WEB_CONTENTS_USER_DATA_KEY_IMPL(AutofillDriverFactory)

} // namespace electron
Expand Up @@ -9,24 +9,20 @@
#include <unordered_map>

#include "base/callback_forward.h"
#include "base/supports_user_data.h"
#include "content/public/browser/web_contents_observer.h"
#include "electron/atom/common/api/api.mojom.h"
#include "content/public/browser/web_contents_user_data.h"
#include "shell/common/api/api.mojom.h"

namespace atom {
namespace electron {

class AutofillDriver;

class AutofillDriverFactory : public content::WebContentsObserver,
public base::SupportsUserData::Data {
class AutofillDriverFactory
: public content::WebContentsObserver,
public content::WebContentsUserData<AutofillDriverFactory> {
public:
explicit AutofillDriverFactory(content::WebContents* web_contents);

~AutofillDriverFactory() override;

static void CreateForWebContents(content::WebContents* contents);

static AutofillDriverFactory* FromWebContents(content::WebContents* contents);
static void BindAutofillDriver(
mojom::ElectronAutofillDriverAssociatedRequest request,
content::RenderFrameHost* render_frame_host);
Expand All @@ -45,13 +41,16 @@ class AutofillDriverFactory : public content::WebContentsObserver,

void CloseAllPopups();

static const char kAtomAutofillDriverFactoryWebContentsUserDataKey[];
WEB_CONTENTS_USER_DATA_KEY_DECL();

private:
explicit AutofillDriverFactory(content::WebContents* web_contents);
friend class content::WebContentsUserData<AutofillDriverFactory>;

std::unordered_map<content::RenderFrameHost*, std::unique_ptr<AutofillDriver>>
driver_map_;
};

} // namespace atom
} // namespace electron

#endif // ATOM_BROWSER_ATOM_AUTOFILL_DRIVER_FACTORY_H_
9 changes: 4 additions & 5 deletions shell/browser/atom_browser_client.cc
Expand Up @@ -39,7 +39,6 @@
#include "content/public/common/service_names.mojom.h"
#include "content/public/common/url_constants.h"
#include "content/public/common/web_preferences.h"
#include "electron/atom/common/api/api.mojom.h"
#include "electron/buildflags/buildflags.h"
#include "electron/grit/electron_resources.h"
#include "net/base/escape.h"
Expand Down Expand Up @@ -75,6 +74,7 @@
#include "shell/browser/web_contents_permission_helper.h"
#include "shell/browser/web_contents_preferences.h"
#include "shell/browser/window_list.h"
#include "shell/common/api/api.mojom.h"
#include "shell/common/application_info.h"
#include "shell/common/options_switches.h"
#include "shell/common/platform_util.h"
Expand Down Expand Up @@ -1049,10 +1049,9 @@ bool AtomBrowserClient::BindAssociatedInterfaceRequestFromFrame(
content::RenderFrameHost* render_frame_host,
const std::string& interface_name,
mojo::ScopedInterfaceEndpointHandle* handle) {
if (interface_name == atom::mojom::ElectronAutofillDriver::Name_) {
atom::AutofillDriverFactory::BindAutofillDriver(
atom::mojom::ElectronAutofillDriverAssociatedRequest(
std::move(*handle)),
if (interface_name == mojom::ElectronAutofillDriver::Name_) {
AutofillDriverFactory::BindAutofillDriver(
mojom::ElectronAutofillDriverAssociatedRequest(std::move(*handle)),
render_frame_host);
return true;
}
Expand Down
20 changes: 0 additions & 20 deletions shell/browser/common_web_contents_delegate.cc
Expand Up @@ -636,24 +636,4 @@ void CommonWebContentsDelegate::SetHtmlApiFullscreen(bool enter_fullscreen) {
native_fullscreen_ = false;
}

void CommonWebContentsDelegate::ShowAutofillPopup(
content::RenderFrameHost* frame_host,
content::RenderFrameHost* embedder_frame_host,
bool offscreen,
const gfx::RectF& bounds,
const std::vector<base::string16>& values,
const std::vector<base::string16>& labels) {
if (!owner_window())
return;

autofill_popup_->CreateView(frame_host, embedder_frame_host, offscreen,
owner_window()->content_view(), bounds);
autofill_popup_->SetItems(values, labels);
}

void CommonWebContentsDelegate::HideAutofillPopup() {
if (autofill_popup_)
autofill_popup_->Hide();
}

} // namespace electron
4 changes: 0 additions & 4 deletions shell/browser/common_web_contents_delegate.h
Expand Up @@ -18,10 +18,6 @@
#include "shell/browser/ui/inspectable_web_contents_impl.h"
#include "shell/browser/ui/inspectable_web_contents_view_delegate.h"

#if defined(TOOLKIT_VIEWS)
#include "shell/browser/ui/autofill_popup.h"
#endif

namespace base {
class SequencedTaskRunner;
}
Expand Down

0 comments on commit 6f79ba3

Please sign in to comment.