Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(75)

Unified Diff: components/framelet/browser/framelet_factory_impl.cc

Issue 1602663003: Framelet Prototype 2016 using Mojo IPC Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebased. Disabled oilpan Created 4 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « components/framelet/browser/framelet_factory_impl.h ('k') | components/framelet/browser/framelet_guest.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: components/framelet/browser/framelet_factory_impl.cc
diff --git a/components/framelet/browser/framelet_factory_impl.cc b/components/framelet/browser/framelet_factory_impl.cc
new file mode 100644
index 0000000000000000000000000000000000000000..63ef5208f43973ac8964e376b3f1c91955fb79b4
--- /dev/null
+++ b/components/framelet/browser/framelet_factory_impl.cc
@@ -0,0 +1,79 @@
+// Copyright 2015 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "components/framelet/browser/framelet_factory_impl.h"
+
+#include "base/values.h"
+#include "components/framelet/browser/framelet_guest.h"
+#include "components/framelet/common/value_type_converters.h"
+#include "components/guest_view/browser/guest_view_manager.h"
+#include "content/public/browser/render_frame_host.h"
+#include "content/public/browser/web_contents.h"
+
+namespace framelet {
+
+FrameletFactoryImpl::FrameletFactoryImpl(
+ content::WebContents* owner_web_contents,
+ const CreateGuestViewManagerDelegate& create_delegate,
+ mojo::InterfaceRequest<FrameletFactory> factory_request)
+ : owner_web_contents_(owner_web_contents),
+ create_delegate_(create_delegate),
+ binding_(this, std::move(factory_request)),
+ weak_ptr_factory_(this) {}
+
+FrameletFactoryImpl::~FrameletFactoryImpl() {}
+
+// static
+void FrameletFactoryImpl::CreateService(
+ content::RenderFrameHost* render_frame_host,
+ const CreateGuestViewManagerDelegate& create_delegate,
+ mojo::InterfaceRequest<FrameletFactory> factory_request) {
+ content::WebContents* owner_web_contents =
+ content::WebContents::FromRenderFrameHost(render_frame_host);
+ new FrameletFactoryImpl(owner_web_contents, create_delegate,
+ std::move(factory_request));
+}
+
+guest_view::GuestViewManager*
+FrameletFactoryImpl::GetOrCreateGuestViewManager() {
+ auto manager = guest_view::GuestViewManager::FromBrowserContext(
+ owner_web_contents_->GetBrowserContext());
+ if (!manager) {
+ manager = guest_view::GuestViewManager::CreateWithDelegate(
+ owner_web_contents_->GetBrowserContext(),
+ make_scoped_ptr(create_delegate_.Run()));
+ }
+ return manager;
+}
+
+// static
+void FrameletFactoryImpl::FrameletCreatedCallback(
+ mojo::InterfaceRequest<mojom::Framelet> framelet,
+ content::WebContents* guest_web_contents) {
+ if (!guest_web_contents)
+ return;
+
+ FrameletGuest* guest = FrameletGuest::FromWebContents(guest_web_contents);
+ if (!guest)
+ return;
+
+ guest->Bind(std::move(framelet));
+}
+
+void FrameletFactoryImpl::Create(
+ mojo::InterfaceRequest<mojom::Framelet> framelet,
+ mojo::Map<mojo::String, mojom::ValuePtr> params) {
+ base::DictionaryValue create_params;
+ for (auto& kv : params)
+ create_params.Set(kv.GetKey(), kv.GetValue().To<base::Value*>());
+
+ guest_view::GuestViewManager::WebContentsCreatedCallback callback =
+ base::Bind(&FrameletFactoryImpl::FrameletCreatedCallback,
+ base::Passed(std::move(framelet)));
+ auto manager = GetOrCreateGuestViewManager();
+ manager->CreateGuest(framelet::FrameletGuest::Type, owner_web_contents_,
+ create_params, callback);
+}
+
+} // namespace framelet
« no previous file with comments | « components/framelet/browser/framelet_factory_impl.h ('k') | components/framelet/browser/framelet_guest.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698