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

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

Issue 264943006: BrowserPlugin: Simplify content/public API (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@guestview_manager_v1
Patch Set: Fixed nit Created 6 years, 7 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/guest_view_manager.cc
diff --git a/chrome/browser/guest_view/guest_view_manager.cc b/chrome/browser/guest_view/guest_view_manager.cc
index 1e07de105f5ddc1d603123133d849f51eaef1862..a1aaf5f26a05c729d1db56ac2bd9c6efb68b4b4e 100644
--- a/chrome/browser/guest_view/guest_view_manager.cc
+++ b/chrome/browser/guest_view/guest_view_manager.cc
@@ -75,6 +75,16 @@ GuestViewManager* GuestViewManager::FromBrowserContext(
return guest_manager;
}
+content::WebContents* GuestViewManager::GetGuestByInstanceIDSafely(
+ int guest_instance_id,
+ int embedder_render_process_id) {
+ if (!CanEmbedderAccessInstanceIDMaybeKill(embedder_render_process_id,
+ guest_instance_id)) {
+ return NULL;
+ }
+ return GetGuestByInstanceID(guest_instance_id, embedder_render_process_id);
+}
+
int GuestViewManager::GetNextInstanceID() {
return ++current_instance_id_;
}
@@ -97,13 +107,53 @@ void GuestViewManager::RemoveGuest(int guest_instance_id) {
guest_web_contents_by_instance_id_.erase(it);
}
-content::WebContents* GuestViewManager::GetGuestByInstanceID(
+void GuestViewManager::MaybeGetGuestByInstanceIDOrKill(
int guest_instance_id,
- int embedder_render_process_id) {
+ int embedder_render_process_id,
+ const GuestByInstanceIDCallback& callback) {
if (!CanEmbedderAccessInstanceIDMaybeKill(embedder_render_process_id,
guest_instance_id)) {
- return NULL;
+ // If we kill the embedder, then don't bother calling back.
+ return;
}
+ content::WebContents* guest_web_contents =
+ GetGuestByInstanceID(guest_instance_id, embedder_render_process_id);
+ callback.Run(guest_web_contents);
+}
+
+SiteInstance* GuestViewManager::GetGuestSiteInstance(
+ const GURL& guest_site) {
+ for (GuestInstanceMap::const_iterator it =
+ guest_web_contents_by_instance_id_.begin();
+ it != guest_web_contents_by_instance_id_.end(); ++it) {
+ if (it->second->GetSiteInstance()->GetSiteURL() == guest_site)
+ return it->second->GetSiteInstance();
+ }
+ return NULL;
+}
+
+bool GuestViewManager::ForEachGuest(WebContents* embedder_web_contents,
+ const GuestCallback& callback) {
+ for (GuestInstanceMap::iterator it =
+ guest_web_contents_by_instance_id_.begin();
+ it != guest_web_contents_by_instance_id_.end(); ++it) {
+ WebContents* guest = it->second;
+ if (embedder_web_contents != guest->GetEmbedderWebContents())
+ continue;
+
+ if (callback.Run(guest))
+ return true;
+ }
+ return false;
+}
+
+void GuestViewManager::AddRenderProcessHostID(int render_process_host_id) {
+ render_process_host_id_multiset_.insert(render_process_host_id);
+}
+
+content::WebContents* GuestViewManager::GetGuestByInstanceID(
+ int guest_instance_id,
+ int embedder_render_process_id) {
GuestInstanceMap::const_iterator it =
guest_web_contents_by_instance_id_.find(guest_instance_id);
if (it == guest_web_contents_by_instance_id_.end())
@@ -155,36 +205,6 @@ bool GuestViewManager::CanEmbedderAccessInstanceID(
return CanEmbedderAccessGuest(embedder_render_process_id, guest_view);
}
-SiteInstance* GuestViewManager::GetGuestSiteInstance(
- const GURL& guest_site) {
- for (GuestInstanceMap::const_iterator it =
- guest_web_contents_by_instance_id_.begin();
- it != guest_web_contents_by_instance_id_.end(); ++it) {
- if (it->second->GetSiteInstance()->GetSiteURL() == guest_site)
- return it->second->GetSiteInstance();
- }
- return NULL;
-}
-
-bool GuestViewManager::ForEachGuest(WebContents* embedder_web_contents,
- const GuestCallback& callback) {
- for (GuestInstanceMap::iterator it =
- guest_web_contents_by_instance_id_.begin();
- it != guest_web_contents_by_instance_id_.end(); ++it) {
- WebContents* guest = it->second;
- if (embedder_web_contents != guest->GetEmbedderWebContents())
- continue;
-
- if (callback.Run(guest))
- return true;
- }
- return false;
-}
-
-void GuestViewManager::AddRenderProcessHostID(int render_process_host_id) {
- render_process_host_id_multiset_.insert(render_process_host_id);
-}
-
bool GuestViewManager::CanEmbedderAccessGuest(int embedder_render_process_id,
GuestViewBase* guest) {
// The embedder can access the guest if it has not been attached and its

Powered by Google App Engine
This is Rietveld 408576698