| Index: components/guest_view/browser/guest_view_manager.h
|
| diff --git a/components/guest_view/browser/guest_view_manager.h b/components/guest_view/browser/guest_view_manager.h
|
| index 034f7565310a0e025dc52d1927e36c908e820cc4..d2f3c2b381cfde3a38d37cbe33d08097f67fe45e 100644
|
| --- a/components/guest_view/browser/guest_view_manager.h
|
| +++ b/components/guest_view/browser/guest_view_manager.h
|
| @@ -6,6 +6,7 @@
|
| #define COMPONENTS_GUEST_VIEW_BROWSER_GUEST_VIEW_MANAGER_H_
|
|
|
| #include <map>
|
| +#include <vector>
|
|
|
| #include "base/bind.h"
|
| #include "base/gtest_prod_util.h"
|
| @@ -89,9 +90,19 @@ class GuestViewManager : public content::BrowserPluginGuestManager,
|
| // registered here.
|
| if (guest_view_registry_.count(T::Type))
|
| return;
|
| - guest_view_registry_[T::Type] = base::Bind(&T::Create);
|
| + auto registry_entry = std::make_pair(
|
| + T::Type,
|
| + GuestViewData(base::Bind(&T::Create), base::Bind(&T::CleanUp)));
|
| + guest_view_registry_.insert(registry_entry);
|
| }
|
|
|
| + // Registers a callback to be called when the view identified by
|
| + // |embedder_process_id| and |view_instance_id| is destroyed.
|
| + // Note that multiple callbacks can be registered for one view.
|
| + void RegisterViewDestructionCallback(int embedder_process_id,
|
| + int view_instance_id,
|
| + const base::Closure& callback);
|
| +
|
| using WebContentsCreatedCallback =
|
| base::Callback<void(content::WebContents*)>;
|
| void CreateGuest(const std::string& view_type,
|
| @@ -121,12 +132,20 @@ class GuestViewManager : public content::BrowserPluginGuestManager,
|
| friend class GuestViewEvent;
|
| friend class GuestViewMessageFilter;
|
|
|
| - // Can be overriden in tests.
|
| + // These methods are virtual so that they can be overriden in tests.
|
| +
|
| virtual void AddGuest(int guest_instance_id,
|
| content::WebContents* guest_web_contents);
|
| virtual void RemoveGuest(int guest_instance_id);
|
| +
|
| + // Called when a GuestView has been created in JavaScript.
|
| + virtual void ViewCreated(int embedder_process_id,
|
| + int view_instance_id,
|
| + const std::string& view_type);
|
| +
|
| + // Called when a GuestView has been garbage collected in JavaScript.
|
| virtual void ViewGarbageCollected(int embedder_process_id,
|
| - int view_instance_id) {}
|
| + int view_instance_id);
|
|
|
| // Creates a guest of the provided |view_type|.
|
| GuestViewBase* CreateGuestInternal(content::WebContents* owner_web_contents,
|
| @@ -146,6 +165,10 @@ class GuestViewManager : public content::BrowserPluginGuestManager,
|
| GuestViewBase* guest,
|
| int instance_id);
|
|
|
| + // This method is called when the embedder with ID |embedder_process_id| is
|
| + // about to be destroyed.
|
| + void EmbedderWillBeDestroyed(int embedder_process_id);
|
| +
|
| content::WebContents* GetGuestByInstanceID(int guest_instance_id);
|
|
|
| bool CanEmbedderAccessInstanceIDMaybeKill(
|
| @@ -190,11 +213,18 @@ class GuestViewManager : public content::BrowserPluginGuestManager,
|
| using GuestInstanceIDReverseMap = std::map<int, ElementInstanceKey>;
|
| GuestInstanceIDReverseMap reverse_instance_id_map_;
|
|
|
| - using GuestCreationCallback =
|
| + using GuestViewCreateFunction =
|
| base::Callback<GuestViewBase*(content::WebContents*)>;
|
| - using GuestViewCreationMap =
|
| - std::map<std::string, GuestViewManager::GuestCreationCallback>;
|
| - GuestViewCreationMap guest_view_registry_;
|
| + using GuestViewCleanUpFunction = base::Callback<void(int, int)>;
|
| + struct GuestViewData {
|
| + GuestViewData(const GuestViewCreateFunction& create_function,
|
| + const GuestViewCleanUpFunction& cleanup_function);
|
| + ~GuestViewData();
|
| + const GuestViewCreateFunction create_function;
|
| + const GuestViewCleanUpFunction cleanup_function;
|
| + };
|
| + using GuestViewMethodMap = std::map<std::string, GuestViewData>;
|
| + GuestViewMethodMap guest_view_registry_;
|
|
|
| int current_instance_id_;
|
|
|
| @@ -211,6 +241,13 @@ class GuestViewManager : public content::BrowserPluginGuestManager,
|
|
|
| scoped_ptr<GuestViewManagerDelegate> delegate_;
|
|
|
| + // |view_destruction_callback_map_| maps from embedder process ID to view ID
|
| + // to a vector of callback functions to be called when that view is destroyed.
|
| + using Callbacks = std::vector<base::Closure> ;
|
| + using CallbacksForEachViewID = std::map<int, Callbacks> ;
|
| + using CallbacksForEachEmbedderID = std::map<int, CallbacksForEachViewID> ;
|
| + CallbacksForEachEmbedderID view_destruction_callback_map_;
|
| +
|
| DISALLOW_COPY_AND_ASSIGN(GuestViewManager);
|
| };
|
|
|
|
|