Chromium Code Reviews| Index: chrome/browser/guest_view/mime_handler_view/mime_handler_view_guest.cc |
| diff --git a/chrome/browser/guest_view/mime_handler_view/mime_handler_view_guest.cc b/chrome/browser/guest_view/mime_handler_view/mime_handler_view_guest.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..8fc0b1b18c80eb75c9edfd110f20c052b247644f |
| --- /dev/null |
| +++ b/chrome/browser/guest_view/mime_handler_view/mime_handler_view_guest.cc |
| @@ -0,0 +1,101 @@ |
| +// Copyright 2014 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "chrome/browser/guest_view/mime_handler_view/mime_handler_view_guest.h" |
| + |
| +#include "base/strings/stringprintf.h" |
| +#include "chrome/browser/extensions/chrome_extension_web_contents_observer.h" |
| +#include "content/public/browser/browser_thread.h" |
| +#include "content/public/browser/render_process_host.h" |
| +#include "content/public/common/url_constants.h" |
| +#include "extensions/browser/guest_view/guest_view_constants.h" |
| +#include "extensions/browser/guest_view/guest_view_manager.h" |
| +#include "net/base/url_util.h" |
| + |
| +using content::WebContents; |
| + |
| +namespace { |
| +const char kMimeHandlerViewSrc[] = "src"; |
| +} |
| + |
| +// static |
| +const char MimeHandlerViewGuest::Type[] = "mimehandler"; |
| + |
| +// static |
| +extensions::GuestViewBase* MimeHandlerViewGuest::Create( |
| + content::BrowserContext* browser_context, int guest_instance_id) { |
| + return new MimeHandlerViewGuest(browser_context, guest_instance_id); |
| +} |
| + |
| +MimeHandlerViewGuest::MimeHandlerViewGuest( |
| + content::BrowserContext* browser_context, |
| + int guest_instance_id) |
| + : GuestView<MimeHandlerViewGuest>( |
| + browser_context, guest_instance_id) { |
| +} |
| + |
| +MimeHandlerViewGuest::~MimeHandlerViewGuest() { |
| +} |
| + |
| +const char* MimeHandlerViewGuest::GetAPINamespace() { |
| + return "guestViewInternal"; |
|
Fady Samuel
2014/09/02 15:08:24
You can create a new API namespace in _api_feature
lazyboy
2014/09/02 20:17:21
Done.
|
| +} |
| + |
| +void MimeHandlerViewGuest::CreateWebContents( |
| + const std::string& embedder_extension_id, |
| + int embedder_render_process_id, |
| + const base::DictionaryValue& create_params, |
| + const WebContentsCreatedCallback& callback) { |
| + std::string orig_mime_type; |
| + // TODO(lazyboy): "mimeType" in a constant. |
| + DCHECK(create_params.GetString("mimeType", &orig_mime_type) && |
| + !orig_mime_type.empty()); |
| + std::string guest_site_str; |
| + // Note that we put a prefix "mime-" before the mime type so that this |
| + // can never collide with an extension ID. |
| + guest_site_str = base::StringPrintf("%s://mime-%s", |
| + content::kGuestScheme, |
| + orig_mime_type.c_str()); |
| + GURL guest_site(guest_site_str); |
| + |
| + // If we already have a webview tag in the same app using the same storage |
| + // partition, we should use the same SiteInstance so the existing tag and |
| + // the new tag can script each other. |
| + extensions::GuestViewManager* guest_view_manager = |
| + extensions::GuestViewManager::FromBrowserContext(browser_context()); |
| + content::SiteInstance* guest_site_instance = |
| + guest_view_manager->GetGuestSiteInstance(guest_site); |
| + if (!guest_site_instance) { |
| + // Create the SiteInstance in a new BrowsingInstance, which will ensure |
| + // that guests from different render process are not allowed to send |
| + // messages to each other. |
| + guest_site_instance = content::SiteInstance::CreateForURL( |
| + browser_context(), guest_site); |
| + } |
| + WebContents::CreateParams params(browser_context(), guest_site_instance); |
| + params.guest_delegate = this; |
| + callback.Run(WebContents::Create(params)); |
| +} |
| + |
| +void MimeHandlerViewGuest::DidAttachToEmbedder() { |
| + std::string src; |
| + DCHECK(attach_params()->GetString(kMimeHandlerViewSrc, &src) && !src.empty()); |
| + guest_web_contents()->GetController().LoadURL( |
| + GURL(src), |
| + content::Referrer(), |
| + content::PAGE_TRANSITION_AUTO_TOPLEVEL, |
| + std::string()); |
| +} |
| + |
| +void MimeHandlerViewGuest::DidInitialize() { |
| + AttachWebContentsHelpers(guest_web_contents()); |
| +} |
| + |
| +void MimeHandlerViewGuest::AttachWebContentsHelpers( |
| + content::WebContents* contents) { |
| + // Required for ExtensionHostMsg_PostMessage. |
| + extensions::ChromeExtensionWebContentsObserver::CreateForWebContents( |
| + contents); |
| +} |
| + |