OLD | NEW |
(Empty) | |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "content/browser/browser_plugin/test_guest_manager_delegate.h" |
| 6 |
| 7 #include "base/logging.h" |
| 8 #include "base/memory/singleton.h" |
| 9 #include "content/public/browser/site_instance.h" |
| 10 #include "content/public/browser/web_contents.h" |
| 11 |
| 12 namespace content { |
| 13 |
| 14 TestGuestManagerDelegate::TestGuestManagerDelegate() |
| 15 : next_instance_id_(0) { |
| 16 } |
| 17 |
| 18 TestGuestManagerDelegate::~TestGuestManagerDelegate() { |
| 19 } |
| 20 |
| 21 // static. |
| 22 TestGuestManagerDelegate* TestGuestManagerDelegate::GetInstance() { |
| 23 return Singleton<TestGuestManagerDelegate>::get(); |
| 24 } |
| 25 |
| 26 int TestGuestManagerDelegate::GetNextInstanceID() { |
| 27 return ++next_instance_id_; |
| 28 } |
| 29 |
| 30 void TestGuestManagerDelegate::AddGuest( |
| 31 int guest_instance_id, |
| 32 WebContents* guest_web_contents) { |
| 33 DCHECK(guest_web_contents_by_instance_id_.find(guest_instance_id) == |
| 34 guest_web_contents_by_instance_id_.end()); |
| 35 guest_web_contents_by_instance_id_[guest_instance_id] = guest_web_contents; |
| 36 } |
| 37 |
| 38 void TestGuestManagerDelegate::RemoveGuest( |
| 39 int guest_instance_id) { |
| 40 GuestInstanceMap::iterator it = |
| 41 guest_web_contents_by_instance_id_.find(guest_instance_id); |
| 42 DCHECK(it != guest_web_contents_by_instance_id_.end()); |
| 43 guest_web_contents_by_instance_id_.erase(it); |
| 44 } |
| 45 |
| 46 WebContents* TestGuestManagerDelegate::GetGuestByInstanceID( |
| 47 int guest_instance_id, |
| 48 int embedder_render_process_id) { |
| 49 GuestInstanceMap::const_iterator it = |
| 50 guest_web_contents_by_instance_id_.find(guest_instance_id); |
| 51 if (it == guest_web_contents_by_instance_id_.end()) |
| 52 return NULL; |
| 53 return it->second; |
| 54 } |
| 55 |
| 56 bool TestGuestManagerDelegate::CanEmbedderAccessInstanceIDMaybeKill( |
| 57 int embedder_render_process_id, |
| 58 int guest_instance_id) { |
| 59 return true; |
| 60 } |
| 61 |
| 62 bool TestGuestManagerDelegate::CanEmbedderAccessInstanceID( |
| 63 int embedder_render_process_id, |
| 64 int guest_instance_id) { |
| 65 return true; |
| 66 } |
| 67 |
| 68 SiteInstance* TestGuestManagerDelegate::GetGuestSiteInstance( |
| 69 const GURL& guest_site) { |
| 70 for (GuestInstanceMap::const_iterator it = |
| 71 guest_web_contents_by_instance_id_.begin(); |
| 72 it != guest_web_contents_by_instance_id_.end(); ++it) { |
| 73 if (it->second->GetSiteInstance()->GetSiteURL() == guest_site) |
| 74 return it->second->GetSiteInstance(); |
| 75 } |
| 76 return NULL; |
| 77 } |
| 78 |
| 79 bool TestGuestManagerDelegate::ForEachGuest( |
| 80 WebContents* embedder_web_contents, |
| 81 const GuestCallback& callback) { |
| 82 for (GuestInstanceMap::iterator it = |
| 83 guest_web_contents_by_instance_id_.begin(); |
| 84 it != guest_web_contents_by_instance_id_.end(); ++it) { |
| 85 WebContents* guest = it->second; |
| 86 if (embedder_web_contents != guest->GetEmbedderWebContents()) |
| 87 continue; |
| 88 |
| 89 if (callback.Run(guest)) |
| 90 return true; |
| 91 } |
| 92 return false; |
| 93 } |
| 94 |
| 95 } // namespace content |
OLD | NEW |