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

Unified Diff: chrome/browser/guest_view/chrome_guest_view_message_filter.cc

Issue 1560553002: Framelet Prototype 2016 Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebased + Applied Brett's Windows + Fixed security issue 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
Index: chrome/browser/guest_view/chrome_guest_view_message_filter.cc
diff --git a/chrome/browser/guest_view/chrome_guest_view_message_filter.cc b/chrome/browser/guest_view/chrome_guest_view_message_filter.cc
new file mode 100644
index 0000000000000000000000000000000000000000..3b20d12549598b97b7a94b563f2c7ce61f44c302
--- /dev/null
+++ b/chrome/browser/guest_view/chrome_guest_view_message_filter.cc
@@ -0,0 +1,140 @@
+// 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 "chrome/browser/guest_view/chrome_guest_view_message_filter.h"
+
+#include "chrome/browser/guest_view/chrome_guest_view_manager_delegate.h"
+#include "components/framelet/browser/framelet_guest.h"
+#include "components/framelet/browser/framelet_memory_tracker.h"
+#include "components/framelet/common/framelet_constants.h"
+#include "components/framelet/common/framelet_messages.h"
+#include "components/guest_view/browser/guest_view_manager.h"
+#include "components/guest_view/common/guest_view_constants.h"
+#include "content/public/browser/render_frame_host.h"
+#include "content/public/browser/render_process_host.h"
+#include "content/public/browser/web_contents.h"
+#include "ipc/ipc_message_macros.h"
+#include "ipc/ipc_message_start.h"
+#include "ui/gfx/geometry/size.h"
+
+namespace chrome {
+
+namespace {
+
+const uint32_t kFilteredGuestViewMessageClasses[] = {
+ GuestViewMsgStart,
+#if defined(ENABLE_EXTENSIONS)
+ ExtensionsGuestViewMsgStart,
+#endif
+ ChromeGuestViewMsgStart};
+
+} // namespace
+
+ChromeGuestViewMessageFilter::ChromeGuestViewMessageFilter(
+ int render_process_id,
+ content::BrowserContext* context)
+ : GuestViewMessageFilterBase(kFilteredGuestViewMessageClasses,
+ arraysize(kFilteredGuestViewMessageClasses),
+ render_process_id,
+ context) {}
+
+ChromeGuestViewMessageFilter::~ChromeGuestViewMessageFilter() {}
+
+guest_view::GuestViewManager*
+ChromeGuestViewMessageFilter::GetOrCreateGuestViewManager() {
+ auto manager =
+ guest_view::GuestViewManager::FromBrowserContext(browser_context_);
+ if (!manager) {
+ manager = guest_view::GuestViewManager::CreateWithDelegate(
+ browser_context_,
+ make_scoped_ptr(new ChromeGuestViewManagerDelegate(browser_context_)));
+ }
+ return manager;
+}
+
+bool ChromeGuestViewMessageFilter::OnMessageReceived(
+ const IPC::Message& message) {
+ bool handled = true;
+ IPC_BEGIN_MESSAGE_MAP(ChromeGuestViewMessageFilter, message)
+ IPC_MESSAGE_HANDLER(ChromeGuestViewHostMsg_AttachFramelet,
+ OnAttachFramelet);
+ IPC_MESSAGE_HANDLER(ChromeGuestViewHostMsg_CreateFramelet,
+ OnCreateFramelet);
+ IPC_MESSAGE_HANDLER(ChromeGuestViewHostMsg_HeapSize, OnHeapSize);
+ IPC_MESSAGE_UNHANDLED(
+ handled = GuestViewMessageFilterBase::OnMessageReceived(message));
+ IPC_END_MESSAGE_MAP();
+ return handled;
+}
+
+void ChromeGuestViewMessageFilter::OverrideThreadForMessage(
+ const IPC::Message& message,
+ content::BrowserThread::ID* thread) {
+ if (IPC_MESSAGE_CLASS(message) == ChromeGuestViewMsgStart) {
+ *thread = content::BrowserThread::UI;
+ return;
+ }
+ GuestViewMessageFilterBase::OverrideThreadForMessage(message, thread);
+}
+
+void ChromeGuestViewMessageFilter::OnAttachFramelet(
+ int render_frame_id,
+ int element_instance_id,
+ int guest_instance_id,
+ const base::DictionaryValue& params) {
+ auto rfh =
+ content::RenderFrameHost::FromID(render_process_id_, render_frame_id);
+ auto embedder_web_contents = content::WebContents::FromRenderFrameHost(rfh);
+ if (!embedder_web_contents)
+ return;
+ int embedder_render_process_host_id =
+ embedder_web_contents->GetRenderProcessHost()->GetID();
+ framelet::FrameletGuest* guest = framelet::FrameletGuest::From(
+ embedder_render_process_host_id, guest_instance_id);
+ if (!guest)
+ return;
+
+ guest->AttachToEmbedderFrame(element_instance_id, render_frame_id, params);
+}
+
+void ChromeGuestViewMessageFilter::OnCreateFramelet(
+ int render_frame_id,
+ int element_instance_id,
+ const base::DictionaryValue& params) {
+ DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
+ auto manager = GetOrCreateGuestViewManager();
+
+ auto rfh =
+ content::RenderFrameHost::FromID(render_process_id_, render_frame_id);
+ auto embedder_web_contents = content::WebContents::FromRenderFrameHost(rfh);
+ if (!embedder_web_contents)
+ return;
+
+ guest_view::GuestViewManager::WebContentsCreatedCallback callback =
+ base::Bind(&ChromeGuestViewMessageFilter::FrameletCreatedCallback, this,
+ element_instance_id, render_frame_id);
+
+ manager->CreateGuest(framelet::FrameletGuest::Type, embedder_web_contents,
+ params, callback);
+}
+
+void ChromeGuestViewMessageFilter::FrameletCreatedCallback(
+ int element_instance_id,
+ int embedder_local_render_frame_id,
+ content::WebContents* guest_web_contents) {
+ auto rfh = content::RenderFrameHost::FromID(render_process_id_,
+ embedder_local_render_frame_id);
+ auto* guest = framelet::FrameletGuest::FromWebContents(guest_web_contents);
+ rfh->Send(new ChromeGuestViewMsg_CreateFramelet_ACK(
+ element_instance_id, guest->guest_instance_id()));
+}
+
+void ChromeGuestViewMessageFilter::OnHeapSize(int routing_id, int heap_size) {
+ framelet::FrameletMemoryTracker::ClientID client_id(render_process_id_,
+ routing_id);
+ framelet::FrameletMemoryTracker::FromBrowserContext(browser_context_)
+ ->ReportHeapSize(client_id, heap_size);
+}
+
+} // namespace chrome
« no previous file with comments | « chrome/browser/guest_view/chrome_guest_view_message_filter.h ('k') | chrome/browser/profiles/profile_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698