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
3 // found in the LICENSE file.
5 #include "extensions/browser/guest_view/surface_worker/surface_worker_guest.h"
7 #include "content/public/common/url_constants.h"
8 #include "extensions/browser/guest_view/guest_view_manager.h"
9 #include "extensions/browser/guest_view/surface_worker/surface_worker_constants.h"
10 #include "extensions/strings/grit/extensions_strings.h"
11 #include "ipc/ipc_message_macros.h"
13 using content::RenderFrameHost
;
14 using content::WebContents
;
16 namespace extensions
{
19 const char SurfaceWorkerGuest::Type
[] = "surfaceview";
22 GuestViewBase
* SurfaceWorkerGuest::Create(
23 content::WebContents
* owner_web_contents
) {
24 return new SurfaceWorkerGuest(owner_web_contents
);
27 SurfaceWorkerGuest::SurfaceWorkerGuest(
28 content::WebContents
* owner_web_contents
)
29 : GuestView
<SurfaceWorkerGuest
>(owner_web_contents
),
30 weak_ptr_factory_(this) {
33 SurfaceWorkerGuest::~SurfaceWorkerGuest() {
36 bool SurfaceWorkerGuest::HandleContextMenu(
37 const content::ContextMenuParams
& params
) {
41 const char* SurfaceWorkerGuest::GetAPINamespace() const {
42 return surface_worker::kEmbedderAPINamespace
;
45 int SurfaceWorkerGuest::GetTaskPrefix() const {
46 return IDS_EXTENSION_TASK_MANAGER_SURFACEWORKER_TAG_PREFIX
;
49 void SurfaceWorkerGuest::CreateWebContents(
50 const base::DictionaryValue
& create_params
,
51 const WebContentsCreatedCallback
& callback
) {
53 if (!create_params
.GetString(surface_worker::kURL
, &url
)) {
59 if (!url_
.is_valid()) {
64 GURL
guest_site(base::StringPrintf("%s://surface-%s",
65 content::kGuestScheme
,
66 GetOwnerSiteURL().host().c_str()));
68 GuestViewManager
* guest_view_manager
=
69 GuestViewManager::FromBrowserContext(
70 owner_web_contents()->GetBrowserContext());
71 content::SiteInstance
* guest_site_instance
=
72 guest_view_manager
->GetGuestSiteInstance(guest_site
);
73 WebContents::CreateParams
params(
74 owner_web_contents()->GetBrowserContext(),
76 params
.guest_delegate
= this;
77 callback
.Run(WebContents::Create(params
));
80 void SurfaceWorkerGuest::DidAttachToEmbedder() {
81 web_contents()->GetController().LoadURL(
82 url_
, content::Referrer(), ui::PAGE_TRANSITION_LINK
, std::string());
86 } // namespace extensions