Chromium Code Reviews| 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 "chrome/browser/guest_view/guest_view_manager.h" | 5 #include "chrome/browser/guest_view/guest_view_manager.h" |
| 6 | 6 |
| 7 #include "base/strings/stringprintf.h" | |
| 7 #include "chrome/browser/extensions/extension_service.h" | 8 #include "chrome/browser/extensions/extension_service.h" |
| 8 #include "chrome/browser/guest_view/guest_view_base.h" | 9 #include "chrome/browser/guest_view/guest_view_base.h" |
| 9 #include "chrome/browser/guest_view/guest_view_constants.h" | 10 #include "chrome/browser/guest_view/guest_view_constants.h" |
| 10 #include "chrome/browser/profiles/profile.h" | 11 #include "chrome/browser/profiles/profile.h" |
| 11 #include "content/public/browser/browser_context.h" | 12 #include "content/public/browser/browser_context.h" |
| 12 #include "content/public/browser/render_process_host.h" | 13 #include "content/public/browser/render_process_host.h" |
| 13 #include "content/public/browser/user_metrics.h" | 14 #include "content/public/browser/user_metrics.h" |
| 14 #include "content/public/browser/web_contents_observer.h" | 15 #include "content/public/browser/web_contents_observer.h" |
| 15 #include "content/public/common/result_codes.h" | 16 #include "content/public/common/result_codes.h" |
| 17 #include "content/public/common/url_constants.h" | |
| 16 #include "extensions/browser/extension_system.h" | 18 #include "extensions/browser/extension_system.h" |
| 19 #include "net/base/escape.h" | |
| 17 #include "url/gurl.h" | 20 #include "url/gurl.h" |
| 18 | 21 |
| 19 using content::BrowserContext; | 22 using content::BrowserContext; |
| 20 using content::SiteInstance; | 23 using content::SiteInstance; |
| 21 using content::WebContents; | 24 using content::WebContents; |
| 22 | 25 |
| 23 // A WebContents does not immediately have a RenderProcessHost. It acquires one | 26 // A WebContents does not immediately have a RenderProcessHost. It acquires one |
| 24 // on initial navigation. This observer exists until that initial navigation in | 27 // on initial navigation. This observer exists until that initial navigation in |
| 25 // order to grab the ID if tis RenderProcessHost so that it can register it as | 28 // order to grab the ID if tis RenderProcessHost so that it can register it as |
| 26 // a guest. | 29 // a guest. |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 72 guest_manager = new GuestViewManager(context); | 75 guest_manager = new GuestViewManager(context); |
| 73 context->SetUserData(guestview::kGuestViewManagerKeyName, guest_manager); | 76 context->SetUserData(guestview::kGuestViewManagerKeyName, guest_manager); |
| 74 } | 77 } |
| 75 return guest_manager; | 78 return guest_manager; |
| 76 } | 79 } |
| 77 | 80 |
| 78 int GuestViewManager::GetNextInstanceID() { | 81 int GuestViewManager::GetNextInstanceID() { |
| 79 return ++current_instance_id_; | 82 return ++current_instance_id_; |
| 80 } | 83 } |
| 81 | 84 |
| 85 content::WebContents* GuestViewManager::CreateGuest( | |
| 86 content::SiteInstance* embedder_site_instance, | |
| 87 int instance_id, | |
| 88 const content::StorageInfo& storage_info, | |
| 89 scoped_ptr<base::DictionaryValue> extra_params) { | |
| 90 content::RenderProcessHost* embedder_process_host = | |
| 91 embedder_site_instance->GetProcess(); | |
| 92 // Validate that the partition id coming from the renderer is valid UTF-8, | |
| 93 // since we depend on this in other parts of the code, such as FilePath | |
| 94 // creation. If the validation fails, treat it as a bad message and kill the | |
| 95 // renderer process. | |
| 96 if (!IsStringUTF8(storage_info.partition_id)) { | |
| 97 content::RecordAction( | |
| 98 base::UserMetricsAction("BadMessageTerminate_BPGM")); | |
| 99 base::KillProcess( | |
| 100 embedder_process_host->GetHandle(), | |
| 101 content::RESULT_CODE_KILLED_BAD_MESSAGE, false); | |
| 102 return NULL; | |
| 103 } | |
| 104 | |
| 105 const GURL& embedder_site_url = embedder_site_instance->GetSiteURL(); | |
| 106 const std::string& host = embedder_site_url.host(); | |
| 107 | |
| 108 std::string url_encoded_partition = net::EscapeQueryParamValue( | |
| 109 storage_info.partition_id, false); | |
| 110 // The SiteInstance of a given webview tag is based on the fact that it's | |
| 111 // a guest process in addition to which platform application the tag | |
| 112 // belongs to and what storage partition is in use, rather than the URL | |
| 113 // that the tag is being navigated to. | |
| 114 GURL guest_site(base::StringPrintf("%s://%s/%s?%s", | |
| 115 content::kGuestScheme, | |
| 116 host.c_str(), | |
| 117 storage_info.persist ? "persist" : "", | |
| 118 url_encoded_partition.c_str())); | |
| 119 | |
| 120 // If we already have a webview tag in the same app using the same storage | |
| 121 // partition, we should use the same SiteInstance so the existing tag and | |
| 122 // the new tag can script each other. | |
| 123 SiteInstance* guest_site_instance = GetGuestSiteInstance(guest_site); | |
| 124 if (!guest_site_instance) { | |
| 125 // Create the SiteInstance in a new BrowsingInstance, which will ensure | |
| 126 // that webview tags are also not allowed to send messages across | |
| 127 // different partitions. | |
| 128 guest_site_instance = SiteInstance::CreateForURL( | |
| 129 embedder_site_instance->GetBrowserContext(), guest_site); | |
| 130 } | |
| 131 WebContents::CreateParams create_params( | |
| 132 embedder_site_instance->GetBrowserContext(), | |
| 133 guest_site_instance); | |
| 134 create_params.guest_instance_id = instance_id; | |
| 135 create_params.guest_extra_params.reset(extra_params.release()); | |
| 136 WebContents* guest_web_contents = WebContents::Create(create_params); | |
|
lazyboy
2014/05/02 19:52:52
just return WebContents::Create(create_params);
Fady Samuel
2014/05/06 20:02:48
Done.
| |
| 137 return guest_web_contents; | |
| 138 } | |
| 139 | |
| 82 void GuestViewManager::AddGuest(int guest_instance_id, | 140 void GuestViewManager::AddGuest(int guest_instance_id, |
| 83 WebContents* guest_web_contents) { | 141 WebContents* guest_web_contents) { |
| 84 DCHECK(guest_web_contents_by_instance_id_.find(guest_instance_id) == | 142 DCHECK(guest_web_contents_by_instance_id_.find(guest_instance_id) == |
| 85 guest_web_contents_by_instance_id_.end()); | 143 guest_web_contents_by_instance_id_.end()); |
| 86 guest_web_contents_by_instance_id_[guest_instance_id] = guest_web_contents; | 144 guest_web_contents_by_instance_id_[guest_instance_id] = guest_web_contents; |
| 87 // This will add the RenderProcessHost ID when we get one. | 145 // This will add the RenderProcessHost ID when we get one. |
| 88 new GuestWebContentsObserver(guest_web_contents); | 146 new GuestWebContentsObserver(guest_web_contents); |
| 89 } | 147 } |
| 90 | 148 |
| 91 void GuestViewManager::RemoveGuest(int guest_instance_id) { | 149 void GuestViewManager::RemoveGuest(int guest_instance_id) { |
| (...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 214 return false; | 272 return false; |
| 215 | 273 |
| 216 return embedder_render_process_id == | 274 return embedder_render_process_id == |
| 217 guest->GetOpener()->GetEmbedderWebContents()->GetRenderProcessHost()-> | 275 guest->GetOpener()->GetEmbedderWebContents()->GetRenderProcessHost()-> |
| 218 GetID(); | 276 GetID(); |
| 219 } | 277 } |
| 220 | 278 |
| 221 return embedder_render_process_id == | 279 return embedder_render_process_id == |
| 222 guest->embedder_web_contents()->GetRenderProcessHost()->GetID(); | 280 guest->embedder_web_contents()->GetRenderProcessHost()->GetID(); |
| 223 } | 281 } |
| OLD | NEW |