OLD | NEW |
---|---|
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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/browser_plugin_guest_manager.h" | 5 #include "content/browser/browser_plugin/browser_plugin_guest_manager.h" |
6 | 6 |
7 #include "content/browser/browser_plugin/browser_plugin_guest.h" | 7 #include "content/browser/browser_plugin/browser_plugin_guest.h" |
8 #include "content/browser/browser_plugin/browser_plugin_host_factory.h" | 8 #include "content/browser/browser_plugin/browser_plugin_host_factory.h" |
9 #include "content/browser/renderer_host/render_view_host_impl.h" | 9 #include "content/browser/renderer_host/render_view_host_impl.h" |
10 #include "content/browser/web_contents/web_contents_impl.h" | 10 #include "content/browser/web_contents/web_contents_impl.h" |
11 #include "content/common/browser_plugin/browser_plugin_constants.h" | 11 #include "content/common/browser_plugin/browser_plugin_constants.h" |
12 #include "content/common/browser_plugin/browser_plugin_messages.h" | 12 #include "content/common/browser_plugin/browser_plugin_messages.h" |
13 #include "content/common/content_export.h" | 13 #include "content/common/content_export.h" |
14 #include "content/public/browser/browser_context.h" | 14 #include "content/public/browser/browser_context.h" |
15 #include "content/public/browser/browser_plugin_guest_manager_delegate.h" | 15 #include "content/public/browser/browser_plugin_guest_manager_delegate.h" |
16 #include "content/public/browser/content_browser_client.h" | 16 #include "content/public/browser/content_browser_client.h" |
17 #include "content/public/browser/render_process_host.h" | 17 #include "content/public/browser/render_process_host.h" |
lazyboy
2014/05/02 19:52:52
Remove this, no longer needed.
| |
18 #include "content/public/browser/user_metrics.h" | 18 #include "content/public/browser/user_metrics.h" |
19 #include "content/public/common/content_client.h" | 19 #include "content/public/common/content_client.h" |
20 #include "content/public/common/result_codes.h" | 20 #include "content/public/common/result_codes.h" |
21 #include "content/public/common/url_constants.h" | 21 #include "content/public/common/url_constants.h" |
22 #include "content/public/common/url_utils.h" | 22 #include "content/public/common/url_utils.h" |
23 #include "net/base/escape.h" | 23 #include "net/base/escape.h" |
lazyboy
2014/05/02 19:52:52
Remove
| |
24 | 24 |
25 namespace content { | 25 namespace content { |
26 | 26 |
27 // static | 27 // static |
28 BrowserPluginHostFactory* BrowserPluginGuestManager::factory_ = NULL; | 28 BrowserPluginHostFactory* BrowserPluginGuestManager::factory_ = NULL; |
29 | 29 |
30 BrowserPluginGuestManager::BrowserPluginGuestManager(BrowserContext* context) | 30 BrowserPluginGuestManager::BrowserPluginGuestManager(BrowserContext* context) |
31 : context_(context) {} | 31 : context_(context) {} |
32 | 32 |
33 BrowserPluginGuestManagerDelegate* | 33 BrowserPluginGuestManagerDelegate* |
(...skipping 29 matching lines...) Expand all Loading... | |
63 | 63 |
64 int BrowserPluginGuestManager::GetNextInstanceID() { | 64 int BrowserPluginGuestManager::GetNextInstanceID() { |
65 if (!GetDelegate()) | 65 if (!GetDelegate()) |
66 return 0; | 66 return 0; |
67 return GetDelegate()->GetNextInstanceID(); | 67 return GetDelegate()->GetNextInstanceID(); |
68 } | 68 } |
69 | 69 |
70 BrowserPluginGuest* BrowserPluginGuestManager::CreateGuest( | 70 BrowserPluginGuest* BrowserPluginGuestManager::CreateGuest( |
71 SiteInstance* embedder_site_instance, | 71 SiteInstance* embedder_site_instance, |
72 int instance_id, | 72 int instance_id, |
73 const BrowserPluginHostMsg_Attach_Params& params, | 73 const StorageInfo& storage_info, |
74 scoped_ptr<base::DictionaryValue> extra_params) { | 74 scoped_ptr<base::DictionaryValue> extra_params) { |
75 RenderProcessHost* embedder_process_host = | 75 if (!GetDelegate()) |
76 embedder_site_instance->GetProcess(); | |
77 // Validate that the partition id coming from the renderer is valid UTF-8, | |
78 // since we depend on this in other parts of the code, such as FilePath | |
79 // creation. If the validation fails, treat it as a bad message and kill the | |
80 // renderer process. | |
81 if (!IsStringUTF8(params.storage_partition_id)) { | |
82 content::RecordAction( | |
83 base::UserMetricsAction("BadMessageTerminate_BPGM")); | |
84 base::KillProcess( | |
85 embedder_process_host->GetHandle(), | |
86 content::RESULT_CODE_KILLED_BAD_MESSAGE, false); | |
87 return NULL; | 76 return NULL; |
88 } | 77 WebContents* guest_web_contents = |
78 GetDelegate()->CreateGuest(embedder_site_instance, | |
79 instance_id, | |
80 storage_info, | |
81 extra_params.Pass()); | |
89 | 82 |
90 const GURL& embedder_site_url = embedder_site_instance->GetSiteURL(); | 83 return static_cast<WebContentsImpl*>(guest_web_contents)-> |
91 const std::string& host = embedder_site_url.host(); | 84 GetBrowserPluginGuest(); |
92 | |
93 std::string url_encoded_partition = net::EscapeQueryParamValue( | |
94 params.storage_partition_id, false); | |
95 // The SiteInstance of a given webview tag is based on the fact that it's | |
96 // a guest process in addition to which platform application the tag | |
97 // belongs to and what storage partition is in use, rather than the URL | |
98 // that the tag is being navigated to. | |
99 GURL guest_site(base::StringPrintf("%s://%s/%s?%s", | |
100 kGuestScheme, | |
101 host.c_str(), | |
102 params.persist_storage ? "persist" : "", | |
103 url_encoded_partition.c_str())); | |
104 | |
105 // If we already have a webview tag in the same app using the same storage | |
106 // partition, we should use the same SiteInstance so the existing tag and | |
107 // the new tag can script each other. | |
108 SiteInstance* guest_site_instance = GetGuestSiteInstance(guest_site); | |
109 if (!guest_site_instance) { | |
110 // Create the SiteInstance in a new BrowsingInstance, which will ensure | |
111 // that webview tags are also not allowed to send messages across | |
112 // different partitions. | |
113 guest_site_instance = SiteInstance::CreateForURL( | |
114 embedder_site_instance->GetBrowserContext(), guest_site); | |
115 } | |
116 | |
117 return WebContentsImpl::CreateGuest( | |
118 embedder_site_instance->GetBrowserContext(), | |
119 guest_site_instance, | |
120 instance_id, | |
121 extra_params.Pass()); | |
122 } | 85 } |
123 | 86 |
124 static void BrowserPluginGuestByInstanceIDCallback( | 87 static void BrowserPluginGuestByInstanceIDCallback( |
125 const BrowserPluginGuestManager::GuestByInstanceIDCallback& callback, | 88 const BrowserPluginGuestManager::GuestByInstanceIDCallback& callback, |
126 WebContents* guest_web_contents) { | 89 WebContents* guest_web_contents) { |
127 if (!guest_web_contents) { | 90 if (!guest_web_contents) { |
128 callback.Run(NULL); | 91 callback.Run(NULL); |
129 return; | 92 return; |
130 } | 93 } |
131 callback.Run(static_cast<WebContentsImpl*>(guest_web_contents)-> | 94 callback.Run(static_cast<WebContentsImpl*>(guest_web_contents)-> |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
173 // All allowed messages must have instance_id as their first parameter. | 136 // All allowed messages must have instance_id as their first parameter. |
174 PickleIterator iter(message); | 137 PickleIterator iter(message); |
175 bool success = iter.ReadInt(&instance_id); | 138 bool success = iter.ReadInt(&instance_id); |
176 DCHECK(success); | 139 DCHECK(success); |
177 MaybeGetGuestByInstanceIDOrKill(instance_id, | 140 MaybeGetGuestByInstanceIDOrKill(instance_id, |
178 render_process_id, | 141 render_process_id, |
179 base::Bind(&BrowserPluginGuestMessageCallback, | 142 base::Bind(&BrowserPluginGuestMessageCallback, |
180 message)); | 143 message)); |
181 } | 144 } |
182 | 145 |
183 SiteInstance* BrowserPluginGuestManager::GetGuestSiteInstance( | |
184 const GURL& guest_site) { | |
185 if (!GetDelegate()) | |
186 return NULL; | |
187 return GetDelegate()->GetGuestSiteInstance(guest_site); | |
188 } | |
189 | |
190 static bool BrowserPluginGuestCallback( | 146 static bool BrowserPluginGuestCallback( |
191 const BrowserPluginGuestManager::GuestCallback& callback, | 147 const BrowserPluginGuestManager::GuestCallback& callback, |
192 WebContents* guest_web_contents) { | 148 WebContents* guest_web_contents) { |
193 return callback.Run(static_cast<WebContentsImpl*>(guest_web_contents) | 149 return callback.Run(static_cast<WebContentsImpl*>(guest_web_contents) |
194 ->GetBrowserPluginGuest()); | 150 ->GetBrowserPluginGuest()); |
195 } | 151 } |
196 | 152 |
197 bool BrowserPluginGuestManager::ForEachGuest( | 153 bool BrowserPluginGuestManager::ForEachGuest( |
198 WebContents* embedder_web_contents, const GuestCallback& callback) { | 154 WebContents* embedder_web_contents, const GuestCallback& callback) { |
199 if (!GetDelegate()) | 155 if (!GetDelegate()) |
200 return false; | 156 return false; |
201 return GetDelegate()->ForEachGuest(embedder_web_contents, | 157 return GetDelegate()->ForEachGuest(embedder_web_contents, |
202 base::Bind(&BrowserPluginGuestCallback, | 158 base::Bind(&BrowserPluginGuestCallback, |
203 callback)); | 159 callback)); |
204 } | 160 } |
205 | 161 |
206 } // namespace content | 162 } // namespace content |
OLD | NEW |