| 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 "extensions/browser/guest_view/web_view/web_view_guest.h" | 5 #include "extensions/browser/guest_view/web_view/web_view_guest.h" |
| 6 | 6 |
| 7 #include "base/message_loop/message_loop.h" | 7 #include "base/message_loop/message_loop.h" |
| 8 #include "base/strings/stringprintf.h" | 8 #include "base/strings/stringprintf.h" |
| 9 #include "base/strings/utf_string_conversions.h" | 9 #include "base/strings/utf_string_conversions.h" |
| 10 #include "content/public/browser/browser_context.h" | 10 #include "content/public/browser/browser_context.h" |
| (...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 213 | 213 |
| 214 // static | 214 // static |
| 215 int WebViewGuest::GetViewInstanceId(WebContents* contents) { | 215 int WebViewGuest::GetViewInstanceId(WebContents* contents) { |
| 216 WebViewGuest* guest = FromWebContents(contents); | 216 WebViewGuest* guest = FromWebContents(contents); |
| 217 if (!guest) | 217 if (!guest) |
| 218 return guestview::kInstanceIDNone; | 218 return guestview::kInstanceIDNone; |
| 219 | 219 |
| 220 return guest->view_instance_id(); | 220 return guest->view_instance_id(); |
| 221 } | 221 } |
| 222 | 222 |
| 223 const char* WebViewGuest::GetAPINamespace() const { | 223 bool WebViewGuest::CanRunInDetachedState() const { |
| 224 return webview::kAPINamespace; | 224 return true; |
| 225 } | |
| 226 | |
| 227 int WebViewGuest::GetTaskPrefix() const { | |
| 228 return IDS_EXTENSION_TASK_MANAGER_WEBVIEW_TAG_PREFIX; | |
| 229 } | 225 } |
| 230 | 226 |
| 231 void WebViewGuest::CreateWebContents( | 227 void WebViewGuest::CreateWebContents( |
| 232 const base::DictionaryValue& create_params, | 228 const base::DictionaryValue& create_params, |
| 233 const WebContentsCreatedCallback& callback) { | 229 const WebContentsCreatedCallback& callback) { |
| 234 content::RenderProcessHost* owner_render_process_host = | 230 content::RenderProcessHost* owner_render_process_host = |
| 235 owner_web_contents()->GetRenderProcessHost(); | 231 owner_web_contents()->GetRenderProcessHost(); |
| 236 std::string storage_partition_id; | 232 std::string storage_partition_id; |
| 237 bool persist_storage = false; | 233 bool persist_storage = false; |
| 238 ParsePartitionParam(create_params, &storage_partition_id, &persist_storage); | 234 ParsePartitionParam(create_params, &storage_partition_id, &persist_storage); |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 301 | 297 |
| 302 rules_registry_id_ = GetOrGenerateRulesRegistryID( | 298 rules_registry_id_ = GetOrGenerateRulesRegistryID( |
| 303 owner_web_contents()->GetRenderProcessHost()->GetID(), | 299 owner_web_contents()->GetRenderProcessHost()->GetID(), |
| 304 view_instance_id()); | 300 view_instance_id()); |
| 305 | 301 |
| 306 // We must install the mapping from guests to WebViews prior to resuming | 302 // We must install the mapping from guests to WebViews prior to resuming |
| 307 // suspended resource loads so that the WebRequest API will catch resource | 303 // suspended resource loads so that the WebRequest API will catch resource |
| 308 // requests. | 304 // requests. |
| 309 PushWebViewStateToIOThread(); | 305 PushWebViewStateToIOThread(); |
| 310 | 306 |
| 311 // TODO(fsamuel): Once <webview> can run in a detached state, call | 307 ApplyAttributes(create_params); |
| 312 // ApplyAttributes here. | |
| 313 } | 308 } |
| 314 | 309 |
| 315 void WebViewGuest::AttachWebViewHelpers(WebContents* contents) { | 310 void WebViewGuest::AttachWebViewHelpers(WebContents* contents) { |
| 316 if (web_view_guest_delegate_) | 311 if (web_view_guest_delegate_) |
| 317 web_view_guest_delegate_->OnAttachWebViewHelpers(contents); | 312 web_view_guest_delegate_->OnAttachWebViewHelpers(contents); |
| 318 web_view_permission_helper_.reset(new WebViewPermissionHelper(this)); | 313 web_view_permission_helper_.reset(new WebViewPermissionHelper(this)); |
| 319 } | 314 } |
| 320 | 315 |
| 321 void WebViewGuest::DidStopLoading() { | 316 void WebViewGuest::DidStopLoading() { |
| 322 scoped_ptr<base::DictionaryValue> args(new base::DictionaryValue()); | 317 scoped_ptr<base::DictionaryValue> args(new base::DictionaryValue()); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 336 content::BrowserThread::IO, | 331 content::BrowserThread::IO, |
| 337 FROM_HERE, | 332 FROM_HERE, |
| 338 base::Bind( | 333 base::Bind( |
| 339 &RemoveWebViewEventListenersOnIOThread, | 334 &RemoveWebViewEventListenersOnIOThread, |
| 340 browser_context(), | 335 browser_context(), |
| 341 owner_extension_id(), | 336 owner_extension_id(), |
| 342 owner_web_contents()->GetRenderProcessHost()->GetID(), | 337 owner_web_contents()->GetRenderProcessHost()->GetID(), |
| 343 view_instance_id())); | 338 view_instance_id())); |
| 344 } | 339 } |
| 345 | 340 |
| 341 const char* WebViewGuest::GetAPINamespace() const { |
| 342 return webview::kAPINamespace; |
| 343 } |
| 344 |
| 345 int WebViewGuest::GetTaskPrefix() const { |
| 346 return IDS_EXTENSION_TASK_MANAGER_WEBVIEW_TAG_PREFIX; |
| 347 } |
| 348 |
| 346 void WebViewGuest::GuestDestroyed() { | 349 void WebViewGuest::GuestDestroyed() { |
| 347 // Clean up custom context menu items for this guest. | 350 // Clean up custom context menu items for this guest. |
| 348 if (web_view_guest_delegate_) | 351 if (web_view_guest_delegate_) |
| 349 web_view_guest_delegate_->OnGuestDestroyed(); | 352 web_view_guest_delegate_->OnGuestDestroyed(); |
| 350 RemoveWebViewStateFromIOThread(web_contents()); | 353 RemoveWebViewStateFromIOThread(web_contents()); |
| 351 } | 354 } |
| 352 | 355 |
| 353 void WebViewGuest::GuestReady() { | 356 void WebViewGuest::GuestReady() { |
| 354 // The guest RenderView should always live in an isolated guest process. | 357 // The guest RenderView should always live in an isolated guest process. |
| 355 CHECK(web_contents()->GetRenderProcessHost()->IsIsolatedGuest()); | 358 CHECK(web_contents()->GetRenderProcessHost()->IsIsolatedGuest()); |
| (...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 479 const std::string& name) { | 482 const std::string& name) { |
| 480 if (!is_top_level) | 483 if (!is_top_level) |
| 481 return; | 484 return; |
| 482 | 485 |
| 483 if (name_ == name) | 486 if (name_ == name) |
| 484 return; | 487 return; |
| 485 | 488 |
| 486 ReportFrameNameChange(name); | 489 ReportFrameNameChange(name); |
| 487 } | 490 } |
| 488 | 491 |
| 489 bool WebViewGuest::CanRunInDetachedState() const { | |
| 490 return false; | |
| 491 } | |
| 492 | |
| 493 void WebViewGuest::CreateNewGuestWebViewWindow( | 492 void WebViewGuest::CreateNewGuestWebViewWindow( |
| 494 const content::OpenURLParams& params) { | 493 const content::OpenURLParams& params) { |
| 495 GuestViewManager* guest_manager = | 494 GuestViewManager* guest_manager = |
| 496 GuestViewManager::FromBrowserContext(browser_context()); | 495 GuestViewManager::FromBrowserContext(browser_context()); |
| 497 // Set the attach params to use the same partition as the opener. | 496 // Set the attach params to use the same partition as the opener. |
| 498 // We pull the partition information from the site's URL, which is of the | 497 // We pull the partition information from the site's URL, which is of the |
| 499 // form guest://site/{persist}?{partition_name}. | 498 // form guest://site/{persist}?{partition_name}. |
| 500 const GURL& site_url = web_contents()->GetSiteInstance()->GetSiteURL(); | 499 const GURL& site_url = web_contents()->GetSiteInstance()->GetSiteURL(); |
| 501 const std::string storage_partition_id = | 500 const std::string storage_partition_id = |
| 502 GetStoragePartitionIdFromSiteURL(site_url); | 501 GetStoragePartitionIdFromSiteURL(site_url); |
| (...skipping 753 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1256 WebViewGuest::From(owner_web_contents()->GetRenderProcessHost()->GetID(), | 1255 WebViewGuest::From(owner_web_contents()->GetRenderProcessHost()->GetID(), |
| 1257 new_window_instance_id); | 1256 new_window_instance_id); |
| 1258 if (!guest) | 1257 if (!guest) |
| 1259 return; | 1258 return; |
| 1260 | 1259 |
| 1261 if (!allow) | 1260 if (!allow) |
| 1262 guest->Destroy(); | 1261 guest->Destroy(); |
| 1263 } | 1262 } |
| 1264 | 1263 |
| 1265 } // namespace extensions | 1264 } // namespace extensions |
| OLD | NEW |