| 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 "base/command_line.h" | |
| 8 #include "content/browser/browser_plugin/browser_plugin_guest.h" | 7 #include "content/browser/browser_plugin/browser_plugin_guest.h" |
| 9 #include "content/browser/browser_plugin/browser_plugin_host_factory.h" | 8 #include "content/browser/browser_plugin/browser_plugin_host_factory.h" |
| 10 #include "content/browser/renderer_host/render_view_host_impl.h" | 9 #include "content/browser/renderer_host/render_view_host_impl.h" |
| 11 #include "content/browser/web_contents/web_contents_impl.h" | 10 #include "content/browser/web_contents/web_contents_impl.h" |
| 12 #include "content/common/browser_plugin/browser_plugin_constants.h" | 11 #include "content/common/browser_plugin/browser_plugin_constants.h" |
| 13 #include "content/common/browser_plugin/browser_plugin_messages.h" | 12 #include "content/common/browser_plugin/browser_plugin_messages.h" |
| 14 #include "content/common/content_export.h" | 13 #include "content/common/content_export.h" |
| 15 #include "content/public/browser/user_metrics.h" | 14 #include "content/public/browser/user_metrics.h" |
| 16 #include "content/public/common/content_switches.h" | |
| 17 #include "content/public/common/result_codes.h" | 15 #include "content/public/common/result_codes.h" |
| 18 #include "content/public/common/url_constants.h" | 16 #include "content/public/common/url_constants.h" |
| 19 #include "content/public/common/url_utils.h" | 17 #include "content/public/common/url_utils.h" |
| 20 #include "net/base/escape.h" | 18 #include "net/base/escape.h" |
| 21 #include "ui/events/keycodes/keyboard_codes.h" | 19 #include "ui/events/keycodes/keyboard_codes.h" |
| 22 | 20 |
| 23 namespace content { | 21 namespace content { |
| 24 | 22 |
| 25 // static | 23 // static |
| 26 BrowserPluginHostFactory* BrowserPluginGuestManager::factory_ = NULL; | 24 BrowserPluginHostFactory* BrowserPluginGuestManager::factory_ = NULL; |
| (...skipping 10 matching lines...) Expand all Loading... |
| 37 if (factory_) | 35 if (factory_) |
| 38 return factory_->CreateBrowserPluginGuestManager(); | 36 return factory_->CreateBrowserPluginGuestManager(); |
| 39 return new BrowserPluginGuestManager(); | 37 return new BrowserPluginGuestManager(); |
| 40 } | 38 } |
| 41 | 39 |
| 42 BrowserPluginGuest* BrowserPluginGuestManager::CreateGuest( | 40 BrowserPluginGuest* BrowserPluginGuestManager::CreateGuest( |
| 43 SiteInstance* embedder_site_instance, | 41 SiteInstance* embedder_site_instance, |
| 44 int instance_id, | 42 int instance_id, |
| 45 const BrowserPluginHostMsg_Attach_Params& params, | 43 const BrowserPluginHostMsg_Attach_Params& params, |
| 46 scoped_ptr<base::DictionaryValue> extra_params) { | 44 scoped_ptr<base::DictionaryValue> extra_params) { |
| 47 SiteInstance* guest_site_instance = NULL; | |
| 48 RenderProcessHost* embedder_process_host = | 45 RenderProcessHost* embedder_process_host = |
| 49 embedder_site_instance->GetProcess(); | 46 embedder_site_instance->GetProcess(); |
| 50 // Validate that the partition id coming from the renderer is valid UTF-8, | 47 // Validate that the partition id coming from the renderer is valid UTF-8, |
| 51 // since we depend on this in other parts of the code, such as FilePath | 48 // since we depend on this in other parts of the code, such as FilePath |
| 52 // creation. If the validation fails, treat it as a bad message and kill the | 49 // creation. If the validation fails, treat it as a bad message and kill the |
| 53 // renderer process. | 50 // renderer process. |
| 54 if (!IsStringUTF8(params.storage_partition_id)) { | 51 if (!IsStringUTF8(params.storage_partition_id)) { |
| 55 content::RecordAction(UserMetricsAction("BadMessageTerminate_BPGM")); | 52 content::RecordAction(UserMetricsAction("BadMessageTerminate_BPGM")); |
| 56 base::KillProcess( | 53 base::KillProcess( |
| 57 embedder_process_host->GetHandle(), | 54 embedder_process_host->GetHandle(), |
| 58 content::RESULT_CODE_KILLED_BAD_MESSAGE, false); | 55 content::RESULT_CODE_KILLED_BAD_MESSAGE, false); |
| 59 return NULL; | 56 return NULL; |
| 60 } | 57 } |
| 61 | 58 |
| 62 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); | 59 // We usually require BrowserPlugins to be hosted by a storage isolated |
| 63 if (command_line.HasSwitch(switches::kSitePerProcess)) { | 60 // extension. We treat WebUI pages as a special case if they host the |
| 64 // When --site-per-process is specified, the behavior of BrowserPlugin | 61 // BrowserPlugin in a component extension iframe. In that case, we use the |
| 65 // as <webview> is broken and we use it for rendering out-of-process | 62 // iframe's URL to determine the extension. |
| 66 // iframes instead. We use the src URL sent by the renderer to find the | 63 const GURL& embedder_site_url = embedder_site_instance->GetSiteURL(); |
| 67 // right process in which to place this instance. | 64 GURL validated_frame_url(params.embedder_frame_url); |
| 68 // Note: Since BrowserPlugin doesn't support cross-process navigation, | 65 RenderViewHost::FilterURL( |
| 69 // the instance will stay in the initially assigned process, regardless | 66 embedder_process_host, false, &validated_frame_url); |
| 70 // of the site it is navigated to. | 67 const std::string& host = content::HasWebUIScheme(embedder_site_url) ? |
| 71 // TODO(nasko): Fix this, and such that cross-process navigations are | 68 validated_frame_url.host() : embedder_site_url.host(); |
| 72 // supported. | |
| 73 guest_site_instance = | |
| 74 embedder_site_instance->GetRelatedSiteInstance(GURL(params.src)); | |
| 75 } else { | |
| 76 // We usually require BrowserPlugins to be hosted by a storage isolated | |
| 77 // extension. We treat WebUI pages as a special case if they host the | |
| 78 // BrowserPlugin in a component extension iframe. In that case, we use the | |
| 79 // iframe's URL to determine the extension. | |
| 80 const GURL& embedder_site_url = embedder_site_instance->GetSiteURL(); | |
| 81 GURL validated_frame_url(params.embedder_frame_url); | |
| 82 RenderViewHost::FilterURL( | |
| 83 embedder_process_host, false, &validated_frame_url); | |
| 84 const std::string& host = content::HasWebUIScheme(embedder_site_url) ? | |
| 85 validated_frame_url.host() : embedder_site_url.host(); | |
| 86 | 69 |
| 87 std::string url_encoded_partition = net::EscapeQueryParamValue( | 70 std::string url_encoded_partition = net::EscapeQueryParamValue( |
| 88 params.storage_partition_id, false); | 71 params.storage_partition_id, false); |
| 89 // The SiteInstance of a given webview tag is based on the fact that it's | 72 // The SiteInstance of a given webview tag is based on the fact that it's |
| 90 // a guest process in addition to which platform application the tag | 73 // a guest process in addition to which platform application the tag |
| 91 // belongs to and what storage partition is in use, rather than the URL | 74 // belongs to and what storage partition is in use, rather than the URL |
| 92 // that the tag is being navigated to. | 75 // that the tag is being navigated to. |
| 93 GURL guest_site(base::StringPrintf("%s://%s/%s?%s", | 76 GURL guest_site(base::StringPrintf("%s://%s/%s?%s", |
| 94 kGuestScheme, | 77 kGuestScheme, |
| 95 host.c_str(), | 78 host.c_str(), |
| 96 params.persist_storage ? "persist" : "", | 79 params.persist_storage ? "persist" : "", |
| 97 url_encoded_partition.c_str())); | 80 url_encoded_partition.c_str())); |
| 98 | 81 |
| 99 // If we already have a webview tag in the same app using the same storage | 82 // If we already have a webview tag in the same app using the same storage |
| 100 // partition, we should use the same SiteInstance so the existing tag and | 83 // partition, we should use the same SiteInstance so the existing tag and |
| 101 // the new tag can script each other. | 84 // the new tag can script each other. |
| 102 guest_site_instance = GetGuestSiteInstance(guest_site); | 85 SiteInstance* guest_site_instance = GetGuestSiteInstance(guest_site); |
| 103 if (!guest_site_instance) { | 86 if (!guest_site_instance) { |
| 104 // Create the SiteInstance in a new BrowsingInstance, which will ensure | 87 // Create the SiteInstance in a new BrowsingInstance, which will ensure |
| 105 // that webview tags are also not allowed to send messages across | 88 // that webview tags are also not allowed to send messages across |
| 106 // different partitions. | 89 // different partitions. |
| 107 guest_site_instance = SiteInstance::CreateForURL( | 90 guest_site_instance = SiteInstance::CreateForURL( |
| 108 embedder_site_instance->GetBrowserContext(), guest_site); | 91 embedder_site_instance->GetBrowserContext(), guest_site); |
| 109 } | |
| 110 } | 92 } |
| 111 | 93 |
| 112 return WebContentsImpl::CreateGuest( | 94 return WebContentsImpl::CreateGuest( |
| 113 embedder_site_instance->GetBrowserContext(), | 95 embedder_site_instance->GetBrowserContext(), |
| 114 guest_site_instance, | 96 guest_site_instance, |
| 115 instance_id, | 97 instance_id, |
| 116 extra_params.Pass()); | 98 extra_params.Pass()); |
| 117 } | 99 } |
| 118 | 100 |
| 119 BrowserPluginGuest* BrowserPluginGuestManager::GetGuestByInstanceID( | 101 BrowserPluginGuest* BrowserPluginGuestManager::GetGuestByInstanceID( |
| (...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 277 BrowserPluginGuest* guest = it->second->GetBrowserPluginGuest(); | 259 BrowserPluginGuest* guest = it->second->GetBrowserPluginGuest(); |
| 278 if (embedder_web_contents == guest->embedder_web_contents()) { | 260 if (embedder_web_contents == guest->embedder_web_contents()) { |
| 279 if (guest->UnlockMouseIfNecessary(event)) | 261 if (guest->UnlockMouseIfNecessary(event)) |
| 280 return true; | 262 return true; |
| 281 } | 263 } |
| 282 } | 264 } |
| 283 return false; | 265 return false; |
| 284 } | 266 } |
| 285 | 267 |
| 286 } // namespace content | 268 } // namespace content |
| OLD | NEW |