OLD | NEW |
(Empty) | |
| 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. |
| 4 |
| 5 #include "extensions/browser/guest_view/mime_handler_view/mime_handler_view_gues
t.h" |
| 6 |
| 7 #include "base/strings/stringprintf.h" |
| 8 #include "content/public/browser/browser_thread.h" |
| 9 #include "content/public/browser/render_process_host.h" |
| 10 #include "content/public/common/url_constants.h" |
| 11 #include "extensions/browser/guest_view/guest_view_constants.h" |
| 12 #include "extensions/browser/guest_view/guest_view_manager.h" |
| 13 #include "extensions/browser/guest_view/mime_handler_view/mime_handler_view_cons
tants.h" |
| 14 #include "extensions/strings/grit/extensions_strings.h" |
| 15 #include "net/base/url_util.h" |
| 16 |
| 17 using content::WebContents; |
| 18 |
| 19 namespace extensions { |
| 20 |
| 21 // static |
| 22 const char MimeHandlerViewGuest::Type[] = "mimehandler"; |
| 23 |
| 24 // static |
| 25 GuestViewBase* MimeHandlerViewGuest::Create( |
| 26 content::BrowserContext* browser_context, |
| 27 int guest_instance_id) { |
| 28 return new MimeHandlerViewGuest(browser_context, guest_instance_id); |
| 29 } |
| 30 |
| 31 MimeHandlerViewGuest::MimeHandlerViewGuest( |
| 32 content::BrowserContext* browser_context, |
| 33 int guest_instance_id) |
| 34 : GuestView<MimeHandlerViewGuest>(browser_context, guest_instance_id) { |
| 35 } |
| 36 |
| 37 MimeHandlerViewGuest::~MimeHandlerViewGuest() { |
| 38 } |
| 39 |
| 40 const char* MimeHandlerViewGuest::GetAPINamespace() const { |
| 41 return "mimeHandlerViewGuestInternal"; |
| 42 } |
| 43 |
| 44 int MimeHandlerViewGuest::GetTaskPrefix() const { |
| 45 return IDS_EXTENSION_TASK_MANAGER_MIMEHANDLERVIEW_TAG_PREFIX; |
| 46 } |
| 47 |
| 48 void MimeHandlerViewGuest::CreateWebContents( |
| 49 const std::string& embedder_extension_id, |
| 50 int embedder_render_process_id, |
| 51 const base::DictionaryValue& create_params, |
| 52 const WebContentsCreatedCallback& callback) { |
| 53 std::string orig_mime_type; |
| 54 DCHECK(create_params.GetString(mimehandlerview::kMimeType, &orig_mime_type) && |
| 55 !orig_mime_type.empty()); |
| 56 std::string guest_site_str; |
| 57 // Note that we put a prefix "mime-" before the mime type so that this |
| 58 // can never collide with an extension ID. |
| 59 guest_site_str = base::StringPrintf( |
| 60 "%s://mime-%s", content::kGuestScheme, orig_mime_type.c_str()); |
| 61 GURL guest_site(guest_site_str); |
| 62 |
| 63 // If we already have a mime handler view for the same mime type, we should |
| 64 // use the same SiteInstance so they go under same process. |
| 65 GuestViewManager* guest_view_manager = |
| 66 GuestViewManager::FromBrowserContext(browser_context()); |
| 67 content::SiteInstance* guest_site_instance = |
| 68 guest_view_manager->GetGuestSiteInstance(guest_site); |
| 69 if (!guest_site_instance) { |
| 70 // Create the SiteInstance in a new BrowsingInstance, which will ensure |
| 71 // that guests from different render process are not allowed to send |
| 72 // messages to each other. |
| 73 guest_site_instance = |
| 74 content::SiteInstance::CreateForURL(browser_context(), guest_site); |
| 75 } |
| 76 WebContents::CreateParams params(browser_context(), guest_site_instance); |
| 77 params.guest_delegate = this; |
| 78 callback.Run(WebContents::Create(params)); |
| 79 } |
| 80 |
| 81 void MimeHandlerViewGuest::DidAttachToEmbedder() { |
| 82 std::string src; |
| 83 DCHECK(attach_params()->GetString(mimehandlerview::kSrc, &src) && |
| 84 !src.empty()); |
| 85 guest_web_contents()->GetController().LoadURL( |
| 86 GURL(src), |
| 87 content::Referrer(), |
| 88 content::PAGE_TRANSITION_AUTO_TOPLEVEL, |
| 89 std::string()); |
| 90 } |
| 91 |
| 92 } // namespace extensions |
OLD | NEW |