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 "components/guest_view/browser/guest_view_manager.h"
8 #include "content/public/common/url_constants.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
;
15 using guest_view::GuestViewBase
;
16 using guest_view::GuestViewManager
;
18 namespace extensions
{
21 const char SurfaceWorkerGuest::Type
[] = "surfaceview";
24 GuestViewBase
* SurfaceWorkerGuest::Create(
25 content::WebContents
* owner_web_contents
) {
26 return new SurfaceWorkerGuest(owner_web_contents
);
29 SurfaceWorkerGuest::SurfaceWorkerGuest(
30 content::WebContents
* owner_web_contents
)
31 : GuestView
<SurfaceWorkerGuest
>(owner_web_contents
),
32 weak_ptr_factory_(this) {
35 SurfaceWorkerGuest::~SurfaceWorkerGuest() {
38 bool SurfaceWorkerGuest::HandleContextMenu(
39 const content::ContextMenuParams
& params
) {
43 const char* SurfaceWorkerGuest::GetAPINamespace() const {
44 return surface_worker::kEmbedderAPINamespace
;
47 int SurfaceWorkerGuest::GetTaskPrefix() const {
48 return IDS_EXTENSION_TASK_MANAGER_SURFACEWORKER_TAG_PREFIX
;
51 void SurfaceWorkerGuest::CreateWebContents(
52 const base::DictionaryValue
& create_params
,
53 const WebContentsCreatedCallback
& callback
) {
55 if (!create_params
.GetString(surface_worker::kURL
, &url
)) {
61 if (!url_
.is_valid()) {
66 GURL
guest_site(base::StringPrintf("%s://surface-%s",
67 content::kGuestScheme
,
68 GetOwnerSiteURL().host().c_str()));
70 GuestViewManager
* guest_view_manager
= GuestViewManager::FromBrowserContext(
71 owner_web_contents()->GetBrowserContext());
72 content::SiteInstance
* guest_site_instance
=
73 guest_view_manager
->GetGuestSiteInstance(guest_site
);
74 WebContents::CreateParams
params(
75 owner_web_contents()->GetBrowserContext(),
77 params
.guest_delegate
= this;
78 callback
.Run(WebContents::Create(params
));
81 void SurfaceWorkerGuest::DidAttachToEmbedder() {
82 web_contents()->GetController().LoadURL(
83 url_
, content::Referrer(), ui::PAGE_TRANSITION_LINK
, std::string());
87 } // namespace extensions