Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(52)

Side by Side Diff: chrome/browser/guest_view/mime_handler_view/mime_handler_view_guest.cc

Issue 376033002: Adding MimeHandlerView. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@pending-zork-patch2
Patch Set: With the new attach approach Created 6 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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 "chrome/browser/guest_view/mime_handler_view/mime_handler_view_guest.h"
6
7 #include "base/strings/stringprintf.h"
8 #include "chrome/browser/extensions/chrome_extension_web_contents_observer.h"
9 #include "content/public/browser/browser_thread.h"
10 #include "content/public/browser/render_process_host.h"
11 #include "content/public/common/url_constants.h"
12 #include "extensions/browser/guest_view/guest_view_constants.h"
13 #include "extensions/browser/guest_view/guest_view_manager.h"
14 #include "net/base/url_util.h"
15
16 using content::WebContents;
17
18 namespace {
19 const char kMimeHandlerViewSrc[] = "src";
20 }
21
22 // static
23 const char MimeHandlerViewGuest::Type[] = "mimehandler";
24
25 // static
26 extensions::GuestViewBase* MimeHandlerViewGuest::Create(
27 content::BrowserContext* browser_context, 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>(
35 browser_context, guest_instance_id) {
36 }
37
38 MimeHandlerViewGuest::~MimeHandlerViewGuest() {
39 }
40
41 const char* MimeHandlerViewGuest::GetAPINamespace() {
42 return "guestViewInternal";
43 }
44
45 void MimeHandlerViewGuest::CreateWebContents(
46 const std::string& embedder_extension_id,
47 int embedder_render_process_id,
48 const base::DictionaryValue& create_params,
49 const WebContentsCreatedCallback& callback) {
50 std::string orig_mime_type;
51 DCHECK(create_params.GetString(guestview::kMimeTypeParam, &orig_mime_type) &&
52 !orig_mime_type.empty());
53 std::string guest_site_str;
54 // Note that we put a prefix "mime-" before the mime type so that this
55 // can never collide with an extension ID.
56 guest_site_str = base::StringPrintf("%s://mime-%s",
57 content::kGuestScheme,
58 orig_mime_type.c_str());
59 GURL guest_site(guest_site_str);
60
61 // If we already have a webview tag in the same app using the same storage
62 // partition, we should use the same SiteInstance so the existing tag and
63 // the new tag can script each other.
64 extensions::GuestViewManager* guest_view_manager =
65 extensions::GuestViewManager::FromBrowserContext(browser_context());
66 content::SiteInstance* guest_site_instance =
67 guest_view_manager->GetGuestSiteInstance(guest_site);
68 if (!guest_site_instance) {
69 // Create the SiteInstance in a new BrowsingInstance, which will ensure
70 // that guests from different render process are not allowed to send
71 // messages to each other.
72 guest_site_instance = content::SiteInstance::CreateForURL(
73 browser_context(), guest_site);
74 }
75 WebContents::CreateParams params(browser_context(), guest_site_instance);
76 params.guest_delegate = this;
77 callback.Run(WebContents::Create(params));
78 }
79
80 void MimeHandlerViewGuest::DidAttachToEmbedder() {
81 std::string src;
82 DCHECK(attach_params()->GetString(kMimeHandlerViewSrc, &src) && !src.empty());
83 guest_web_contents()->GetController().LoadURL(
84 GURL(src),
85 content::Referrer(),
86 content::PAGE_TRANSITION_AUTO_TOPLEVEL,
87 std::string());
88 }
89
90 void MimeHandlerViewGuest::DidInitialize() {
91 AttachWebContentsHelpers(guest_web_contents());
92 }
93
94 void MimeHandlerViewGuest::AttachWebContentsHelpers(
95 content::WebContents* contents) {
96 // Required for ExtensionHostMsg_PostMessage.
97 extensions::ChromeExtensionWebContentsObserver::CreateForWebContents(
98 contents);
99 }
100
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698