OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "content/browser/browser_plugin/test_guest_manager.h" | 5 #include "content/browser/browser_plugin/test_guest_manager.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "base/memory/singleton.h" | 8 #include "base/memory/singleton.h" |
9 #include "base/strings/stringprintf.h" | 9 #include "base/strings/stringprintf.h" |
10 #include "base/values.h" | 10 #include "base/values.h" |
| 11 #include "content/browser/browser_plugin/browser_plugin_guest.h" |
| 12 #include "content/browser/browser_plugin/test_browser_plugin_guest_delegate.h" |
11 #include "content/browser/web_contents/web_contents_impl.h" | 13 #include "content/browser/web_contents/web_contents_impl.h" |
12 #include "content/public/browser/site_instance.h" | 14 #include "content/public/browser/site_instance.h" |
13 #include "content/public/browser/web_contents.h" | 15 #include "content/public/browser/web_contents.h" |
14 #include "content/public/browser/web_contents_observer.h" | 16 #include "content/public/browser/web_contents_observer.h" |
15 #include "content/public/common/url_constants.h" | 17 #include "content/public/common/url_constants.h" |
16 #include "content/public/test/test_utils.h" | 18 #include "content/public/test/test_utils.h" |
17 #include "net/base/escape.h" | 19 #include "net/base/escape.h" |
18 | 20 |
19 namespace content { | 21 namespace content { |
20 | 22 |
21 class GuestWebContentsObserver | 23 class GuestWebContentsObserver |
22 : public WebContentsObserver { | 24 : public WebContentsObserver { |
23 public: | 25 public: |
24 explicit GuestWebContentsObserver(WebContents* guest_web_contents) | 26 explicit GuestWebContentsObserver(WebContents* guest_web_contents) |
25 : WebContentsObserver(guest_web_contents), | 27 : WebContentsObserver(guest_web_contents) { |
26 guest_instance_id_(guest_web_contents->GetEmbeddedInstanceID()) { | 28 BrowserPluginGuest* guest = |
| 29 static_cast<WebContentsImpl*>(guest_web_contents)-> |
| 30 GetBrowserPluginGuest(); |
| 31 guest_instance_id_ = guest->instance_id(); |
27 } | 32 } |
28 | 33 |
29 virtual ~GuestWebContentsObserver() { | 34 virtual ~GuestWebContentsObserver() { |
30 } | 35 } |
31 | 36 |
32 virtual void WebContentsDestroyed() OVERRIDE { | 37 virtual void WebContentsDestroyed() OVERRIDE { |
33 TestGuestManager::GetInstance()->RemoveGuest(guest_instance_id_); | 38 TestGuestManager::GetInstance()->RemoveGuest(guest_instance_id_); |
34 delete this; | 39 delete this; |
35 } | 40 } |
36 | 41 |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
93 // that webview tags are also not allowed to send messages across | 98 // that webview tags are also not allowed to send messages across |
94 // different partitions. | 99 // different partitions. |
95 guest_site_instance = SiteInstance::CreateForURL( | 100 guest_site_instance = SiteInstance::CreateForURL( |
96 embedder_site_instance->GetBrowserContext(), guest_site); | 101 embedder_site_instance->GetBrowserContext(), guest_site); |
97 } | 102 } |
98 WebContents::CreateParams create_params( | 103 WebContents::CreateParams create_params( |
99 embedder_site_instance->GetBrowserContext(), | 104 embedder_site_instance->GetBrowserContext(), |
100 guest_site_instance); | 105 guest_site_instance); |
101 create_params.guest_instance_id = instance_id; | 106 create_params.guest_instance_id = instance_id; |
102 create_params.guest_extra_params.reset(extra_params.release()); | 107 create_params.guest_extra_params.reset(extra_params.release()); |
103 WebContents* guest_web_contents = WebContents::Create(create_params); | 108 WebContentsImpl* guest_web_contents = static_cast<WebContentsImpl*>( |
| 109 WebContents::Create(create_params)); |
| 110 BrowserPluginGuest* guest = guest_web_contents->GetBrowserPluginGuest(); |
| 111 guest_web_contents->GetBrowserPluginGuest()->SetDelegate( |
| 112 new TestBrowserPluginGuestDelegate(guest)); |
104 AddGuest(instance_id, guest_web_contents); | 113 AddGuest(instance_id, guest_web_contents); |
105 return guest_web_contents; | 114 return guest_web_contents; |
106 } | 115 } |
107 | 116 |
108 int TestGuestManager::GetNextInstanceID() { | 117 int TestGuestManager::GetNextInstanceID() { |
109 return ++next_instance_id_; | 118 return ++next_instance_id_; |
110 } | 119 } |
111 | 120 |
112 void TestGuestManager::AddGuest( | 121 void TestGuestManager::AddGuest( |
113 int guest_instance_id, | 122 int guest_instance_id, |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
152 } | 161 } |
153 return NULL; | 162 return NULL; |
154 } | 163 } |
155 | 164 |
156 bool TestGuestManager::ForEachGuest( | 165 bool TestGuestManager::ForEachGuest( |
157 WebContents* embedder_web_contents, | 166 WebContents* embedder_web_contents, |
158 const GuestCallback& callback) { | 167 const GuestCallback& callback) { |
159 for (GuestInstanceMap::iterator it = | 168 for (GuestInstanceMap::iterator it = |
160 guest_web_contents_by_instance_id_.begin(); | 169 guest_web_contents_by_instance_id_.begin(); |
161 it != guest_web_contents_by_instance_id_.end(); ++it) { | 170 it != guest_web_contents_by_instance_id_.end(); ++it) { |
162 WebContents* guest = it->second; | 171 WebContentsImpl* guest_web_contents = |
163 if (embedder_web_contents != guest->GetEmbedderWebContents()) | 172 static_cast<WebContentsImpl*>(it->second); |
| 173 BrowserPluginGuest* guest = guest_web_contents->GetBrowserPluginGuest(); |
| 174 if (embedder_web_contents != guest->embedder_web_contents()) |
164 continue; | 175 continue; |
165 | 176 |
166 if (callback.Run(guest)) | 177 if (callback.Run(guest_web_contents)) |
167 return true; | 178 return true; |
168 } | 179 } |
169 return false; | 180 return false; |
170 } | 181 } |
171 | 182 |
172 } // namespace content | 183 } // namespace content |
OLD | NEW |