OLD | NEW |
(Empty) | |
| 1 // Copyright 2015 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. |
| 4 |
| 5 #include "components/framelet/browser/framelet_guest.h" |
| 6 |
| 7 #include "base/strings/stringprintf.h" |
| 8 #include "components/framelet/common/framelet_constants.h" |
| 9 #include "components/guest_view/browser/guest_view_manager.h" |
| 10 #include "content/public/browser/site_instance.h" |
| 11 #include "content/public/common/url_constants.h" |
| 12 |
| 13 |
| 14 namespace guest_view { |
| 15 |
| 16 // static. |
| 17 const char FrameletGuest::Type[] = "framelet"; |
| 18 |
| 19 GuestViewBase* FrameletGuest::Create(content::WebContents* owner_web_contents) { |
| 20 return new FrameletGuest(owner_web_contents); |
| 21 } |
| 22 |
| 23 FrameletGuest::FrameletGuest(content::WebContents* owner_web_contents) |
| 24 : GuestView<FrameletGuest>(owner_web_contents) {} |
| 25 |
| 26 FrameletGuest::~FrameletGuest() {} |
| 27 |
| 28 // content::WebContentsDelegate implementation. |
| 29 bool FrameletGuest::HandleContextMenu( |
| 30 const content::ContextMenuParams& params) { |
| 31 return false; |
| 32 } |
| 33 |
| 34 const char* FrameletGuest::GetAPINamespace() const { |
| 35 return framelet::kEmbedderAPINamespace; |
| 36 } |
| 37 |
| 38 int FrameletGuest::GetTaskPrefix() const { |
| 39 return 0; // TODO(wjmaclean): implement this. |
| 40 } |
| 41 |
| 42 void FrameletGuest::CreateWebContents( |
| 43 const base::DictionaryValue& create_params, |
| 44 const GuestViewBase::WebContentsCreatedCallback& callback) { |
| 45 std::string url; |
| 46 if (!create_params.GetString(framelet::kURL, &url)) { |
| 47 callback.Run(nullptr); |
| 48 return; |
| 49 } |
| 50 |
| 51 url_ = GURL(url); |
| 52 if (!url_.is_valid()) { |
| 53 callback.Run(nullptr); |
| 54 return; |
| 55 } |
| 56 |
| 57 // TODO(wjmaclean): modify this so the framelets instances are unique to a |
| 58 // given embedder process. |
| 59 GURL guest_site(base::StringPrintf("%s://framelet-%s", |
| 60 content::kGuestScheme, |
| 61 GetOwnerSiteURL().host().c_str())); |
| 62 |
| 63 GuestViewManager* guest_view_manager = GuestViewManager::FromBrowserContext( |
| 64 owner_web_contents()->GetBrowserContext()); |
| 65 content::SiteInstance* guest_site_instance = |
| 66 guest_view_manager->GetGuestSiteInstance(guest_site); |
| 67 content::WebContents::CreateParams params( |
| 68 owner_web_contents()->GetBrowserContext(), |
| 69 guest_site_instance); |
| 70 params.guest_delegate = this; |
| 71 callback.Run(content::WebContents::Create(params)); |
| 72 } |
| 73 |
| 74 void FrameletGuest::DidAttachToEmbedder() { |
| 75 web_contents()->GetController().LoadURL( |
| 76 url_, content::Referrer(), ui::PAGE_TRANSITION_LINK, std::string()); |
| 77 url_ = GURL(); |
| 78 } |
| 79 |
| 80 } // namespace guest_view |
OLD | NEW |