Index: content/shell/browser/browser_plugin/test_guest_manager_delegate.cc |
diff --git a/content/shell/browser/browser_plugin/test_guest_manager_delegate.cc b/content/shell/browser/browser_plugin/test_guest_manager_delegate.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..c4d12662beeb036ed85a96e6c3d1ae66d47eb716 |
--- /dev/null |
+++ b/content/shell/browser/browser_plugin/test_guest_manager_delegate.cc |
@@ -0,0 +1,101 @@ |
+// Copyright 2014 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 "content/shell/browser/browser_plugin/test_guest_manager_delegate.h" |
+ |
+#include "base/logging.h" |
+#include "base/memory/singleton.h" |
+#include "content/public/browser/site_instance.h" |
+#include "content/public/browser/web_contents.h" |
+ |
+namespace content { |
+ |
+TestGuestManagerDelegate::TestGuestManagerDelegate() |
+ : next_instance_id_(0) { |
+} |
+ |
+TestGuestManagerDelegate::~TestGuestManagerDelegate() { |
+} |
+ |
+// static. |
+TestGuestManagerDelegate* TestGuestManagerDelegate::GetInstance() { |
+ return Singleton<TestGuestManagerDelegate>::get(); |
+} |
+ |
+int TestGuestManagerDelegate::GetNextInstanceID() { |
+ return ++next_instance_id_; |
+} |
+ |
+void TestGuestManagerDelegate::AddGuest( |
+ int guest_instance_id, |
+ WebContents* guest_web_contents) { |
+ DCHECK(guest_web_contents_by_instance_id_.find(guest_instance_id) == |
+ guest_web_contents_by_instance_id_.end()); |
+ guest_web_contents_by_instance_id_[guest_instance_id] = guest_web_contents; |
+} |
+ |
+void TestGuestManagerDelegate::RemoveGuest( |
+ int guest_instance_id) { |
+ GuestInstanceMap::iterator it = |
+ guest_web_contents_by_instance_id_.find(guest_instance_id); |
+ DCHECK(it != guest_web_contents_by_instance_id_.end()); |
+ guest_web_contents_by_instance_id_.erase(it); |
+} |
+ |
+WebContents* TestGuestManagerDelegate::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()) |
+ return NULL; |
+ return it->second; |
+} |
+ |
+bool TestGuestManagerDelegate::CanEmbedderAccessInstanceIDMaybeKill( |
+ int embedder_render_process_id, |
+ int guest_instance_id) { |
+ return true; |
+} |
+ |
+bool TestGuestManagerDelegate::CanEmbedderAccessInstanceID( |
+ int embedder_render_process_id, |
+ int guest_instance_id) { |
+ return true; |
+} |
+ |
+SiteInstance* TestGuestManagerDelegate::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 TestGuestManagerDelegate::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 TestGuestManagerDelegate::RequestInstanceID( |
+ const std::string& src, |
+ const InstanceIDResponseCallback& callback) { |
+ callback.Run(GetNextInstanceID()); |
+} |
+ |
+} // namespace content |