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

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: add (c) header 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";
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.
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 // TODO(lazyboy): "mimeType" in a constant.
52 DCHECK(create_params.GetString("mimeType", &orig_mime_type) &&
53 !orig_mime_type.empty());
54 std::string guest_site_str;
55 // Note that we put a prefix "mime-" before the mime type so that this
56 // can never collide with an extension ID.
57 guest_site_str = base::StringPrintf("%s://mime-%s",
58 content::kGuestScheme,
59 orig_mime_type.c_str());
60 GURL guest_site(guest_site_str);
61
62 // If we already have a webview tag in the same app using the same storage
63 // partition, we should use the same SiteInstance so the existing tag and
64 // the new tag can script each other.
65 extensions::GuestViewManager* guest_view_manager =
66 extensions::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 = content::SiteInstance::CreateForURL(
74 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(kMimeHandlerViewSrc, &src) && !src.empty());
84 guest_web_contents()->GetController().LoadURL(
85 GURL(src),
86 content::Referrer(),
87 content::PAGE_TRANSITION_AUTO_TOPLEVEL,
88 std::string());
89 }
90
91 void MimeHandlerViewGuest::DidInitialize() {
92 AttachWebContentsHelpers(guest_web_contents());
93 }
94
95 void MimeHandlerViewGuest::AttachWebContentsHelpers(
96 content::WebContents* contents) {
97 // Required for ExtensionHostMsg_PostMessage.
98 extensions::ChromeExtensionWebContentsObserver::CreateForWebContents(
99 contents);
100 }
101
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698