| 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" | 7 #include "base/command_line.h" |
| 8 #include "content/browser/browser_plugin/browser_plugin_guest.h" | 8 #include "content/browser/browser_plugin/browser_plugin_guest.h" |
| 9 #include "content/browser/browser_plugin/browser_plugin_host_factory.h" | 9 #include "content/browser/browser_plugin/browser_plugin_host_factory.h" |
| 10 #include "content/browser/renderer_host/render_view_host_impl.h" | 10 #include "content/browser/renderer_host/render_view_host_impl.h" |
| 11 #include "content/browser/web_contents/web_contents_impl.h" | 11 #include "content/browser/web_contents/web_contents_impl.h" |
| 12 #include "content/common/browser_plugin/browser_plugin_constants.h" | 12 #include "content/common/browser_plugin/browser_plugin_constants.h" |
| 13 #include "content/common/browser_plugin/browser_plugin_messages.h" | 13 #include "content/common/browser_plugin/browser_plugin_messages.h" |
| 14 #include "content/common/content_export.h" | 14 #include "content/common/content_export.h" |
| 15 #include "content/public/browser/user_metrics.h" | 15 #include "content/public/browser/user_metrics.h" |
| 16 #include "content/public/common/content_switches.h" | 16 #include "content/public/common/content_switches.h" |
| 17 #include "content/public/common/result_codes.h" | 17 #include "content/public/common/result_codes.h" |
| 18 #include "content/public/common/url_constants.h" | 18 #include "content/public/common/url_constants.h" |
| 19 #include "content/public/common/url_utils.h" |
| 19 #include "net/base/escape.h" | 20 #include "net/base/escape.h" |
| 20 #include "ui/events/keycodes/keyboard_codes.h" | 21 #include "ui/events/keycodes/keyboard_codes.h" |
| 21 | 22 |
| 22 namespace content { | 23 namespace content { |
| 23 | 24 |
| 24 // static | 25 // static |
| 25 BrowserPluginHostFactory* BrowserPluginGuestManager::factory_ = NULL; | 26 BrowserPluginHostFactory* BrowserPluginGuestManager::factory_ = NULL; |
| 26 | 27 |
| 27 BrowserPluginGuestManager::BrowserPluginGuestManager() | 28 BrowserPluginGuestManager::BrowserPluginGuestManager() |
| 28 : next_instance_id_(browser_plugin::kInstanceIDNone) { | 29 : next_instance_id_(browser_plugin::kInstanceIDNone) { |
| 29 } | 30 } |
| 30 | 31 |
| 31 BrowserPluginGuestManager::~BrowserPluginGuestManager() { | 32 BrowserPluginGuestManager::~BrowserPluginGuestManager() { |
| 32 } | 33 } |
| 33 | 34 |
| 34 // static | 35 // static |
| 35 BrowserPluginGuestManager* BrowserPluginGuestManager::Create() { | 36 BrowserPluginGuestManager* BrowserPluginGuestManager::Create() { |
| 36 if (factory_) | 37 if (factory_) |
| 37 return factory_->CreateBrowserPluginGuestManager(); | 38 return factory_->CreateBrowserPluginGuestManager(); |
| 38 return new BrowserPluginGuestManager(); | 39 return new BrowserPluginGuestManager(); |
| 39 } | 40 } |
| 40 | 41 |
| 41 BrowserPluginGuest* BrowserPluginGuestManager::CreateGuest( | 42 BrowserPluginGuest* BrowserPluginGuestManager::CreateGuest( |
| 42 SiteInstance* embedder_site_instance, | 43 SiteInstance* embedder_site_instance, |
| 43 int instance_id, | 44 int instance_id, |
| 44 const BrowserPluginHostMsg_Attach_Params& params, | 45 const BrowserPluginHostMsg_Attach_Params& params, |
| 45 scoped_ptr<base::DictionaryValue> extra_params) { | 46 scoped_ptr<base::DictionaryValue> extra_params) { |
| 46 SiteInstance* guest_site_instance = NULL; | 47 SiteInstance* guest_site_instance = NULL; |
| 48 RenderProcessHost* embedder_process_host = |
| 49 embedder_site_instance->GetProcess(); |
| 47 // Validate that the partition id coming from the renderer is valid UTF-8, | 50 // Validate that the partition id coming from the renderer is valid UTF-8, |
| 48 // since we depend on this in other parts of the code, such as FilePath | 51 // since we depend on this in other parts of the code, such as FilePath |
| 49 // creation. If the validation fails, treat it as a bad message and kill the | 52 // creation. If the validation fails, treat it as a bad message and kill the |
| 50 // renderer process. | 53 // renderer process. |
| 51 if (!IsStringUTF8(params.storage_partition_id)) { | 54 if (!IsStringUTF8(params.storage_partition_id)) { |
| 52 content::RecordAction(UserMetricsAction("BadMessageTerminate_BPGM")); | 55 content::RecordAction(UserMetricsAction("BadMessageTerminate_BPGM")); |
| 53 base::KillProcess( | 56 base::KillProcess( |
| 54 embedder_site_instance->GetProcess()->GetHandle(), | 57 embedder_process_host->GetHandle(), |
| 55 content::RESULT_CODE_KILLED_BAD_MESSAGE, false); | 58 content::RESULT_CODE_KILLED_BAD_MESSAGE, false); |
| 56 return NULL; | 59 return NULL; |
| 57 } | 60 } |
| 58 | 61 |
| 59 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); | 62 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); |
| 60 if (command_line.HasSwitch(switches::kSitePerProcess)) { | 63 if (command_line.HasSwitch(switches::kSitePerProcess)) { |
| 61 // When --site-per-process is specified, the behavior of BrowserPlugin | 64 // When --site-per-process is specified, the behavior of BrowserPlugin |
| 62 // as <webview> is broken and we use it for rendering out-of-process | 65 // as <webview> is broken and we use it for rendering out-of-process |
| 63 // iframes instead. We use the src URL sent by the renderer to find the | 66 // iframes instead. We use the src URL sent by the renderer to find the |
| 64 // right process in which to place this instance. | 67 // right process in which to place this instance. |
| 65 // Note: Since BrowserPlugin doesn't support cross-process navigation, | 68 // Note: Since BrowserPlugin doesn't support cross-process navigation, |
| 66 // the instance will stay in the initially assigned process, regardless | 69 // the instance will stay in the initially assigned process, regardless |
| 67 // of the site it is navigated to. | 70 // of the site it is navigated to. |
| 68 // TODO(nasko): Fix this, and such that cross-process navigations are | 71 // TODO(nasko): Fix this, and such that cross-process navigations are |
| 69 // supported. | 72 // supported. |
| 70 guest_site_instance = | 73 guest_site_instance = |
| 71 embedder_site_instance->GetRelatedSiteInstance(GURL(params.src)); | 74 embedder_site_instance->GetRelatedSiteInstance(GURL(params.src)); |
| 72 } else { | 75 } else { |
| 73 const std::string& host = embedder_site_instance->GetSiteURL().host(); | 76 // Only trust |embedder_frame_url| reported by a WebUI renderer. |
| 77 const GURL& embedder_site_url = embedder_site_instance->GetSiteURL(); |
| 78 GURL validated_frame_url(params.embedder_frame_url); |
| 79 RenderViewHost::FilterURL( |
| 80 embedder_process_host, false, &validated_frame_url); |
| 81 const std::string& host = content::HasWebUIScheme(embedder_site_url) ? |
| 82 validated_frame_url.host() : embedder_site_url.host(); |
| 74 | 83 |
| 75 std::string url_encoded_partition = net::EscapeQueryParamValue( | 84 std::string url_encoded_partition = net::EscapeQueryParamValue( |
| 76 params.storage_partition_id, false); | 85 params.storage_partition_id, false); |
| 77 // The SiteInstance of a given webview tag is based on the fact that it's | 86 // The SiteInstance of a given webview tag is based on the fact that it's |
| 78 // a guest process in addition to which platform application the tag | 87 // a guest process in addition to which platform application the tag |
| 79 // belongs to and what storage partition is in use, rather than the URL | 88 // belongs to and what storage partition is in use, rather than the URL |
| 80 // that the tag is being navigated to. | 89 // that the tag is being navigated to. |
| 81 GURL guest_site( | 90 GURL guest_site( |
| 82 base::StringPrintf("%s://%s/%s?%s", chrome::kGuestScheme, | 91 base::StringPrintf("%s://%s/%s?%s", chrome::kGuestScheme, |
| 83 host.c_str(), | 92 host.c_str(), |
| (...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 265 BrowserPluginGuest* guest = it->second->GetBrowserPluginGuest(); | 274 BrowserPluginGuest* guest = it->second->GetBrowserPluginGuest(); |
| 266 if (embedder_web_contents == guest->embedder_web_contents()) { | 275 if (embedder_web_contents == guest->embedder_web_contents()) { |
| 267 if (guest->UnlockMouseIfNecessary(event)) | 276 if (guest->UnlockMouseIfNecessary(event)) |
| 268 return true; | 277 return true; |
| 269 } | 278 } |
| 270 } | 279 } |
| 271 return false; | 280 return false; |
| 272 } | 281 } |
| 273 | 282 |
| 274 } // namespace content | 283 } // namespace content |
| OLD | NEW |