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

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: address comments from Fady 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 "extensions/strings/grit/extensions_strings.h"
15 #include "net/base/url_util.h"
16
17 using content::WebContents;
18
19 namespace {
20 const char kMimeHandlerViewSrc[] = "src";
21 }
22
23 // static
24 const char MimeHandlerViewGuest::Type[] = "mimehandler";
25
26 // static
27 extensions::GuestViewBase* MimeHandlerViewGuest::Create(
28 content::BrowserContext* browser_context, int guest_instance_id) {
29 return new MimeHandlerViewGuest(browser_context, guest_instance_id);
30 }
31
32 MimeHandlerViewGuest::MimeHandlerViewGuest(
33 content::BrowserContext* browser_context,
34 int guest_instance_id)
35 : GuestView<MimeHandlerViewGuest>(
36 browser_context, guest_instance_id) {
37 }
38
39 MimeHandlerViewGuest::~MimeHandlerViewGuest() {
40 }
41
42 const char* MimeHandlerViewGuest::GetAPINamespace() const {
43 return "mimeHandlerViewGuestInternal";
44 }
45
46 int MimeHandlerViewGuest::GetTaskPrefix() const {
47 return IDS_EXTENSION_TASK_MANAGER_MIMEHANDLERVIEW_TAG_PREFIX;
48 }
49
50 void MimeHandlerViewGuest::CreateWebContents(
51 const std::string& embedder_extension_id,
52 int embedder_render_process_id,
53 const base::DictionaryValue& create_params,
54 const WebContentsCreatedCallback& callback) {
55 std::string orig_mime_type;
56 // TODO(lazyboy): "mimeType" in a constant.
57 DCHECK(create_params.GetString("mimeType", &orig_mime_type) &&
58 !orig_mime_type.empty());
59 std::string guest_site_str;
60 // Note that we put a prefix "mime-" before the mime type so that this
61 // can never collide with an extension ID.
62 guest_site_str = base::StringPrintf("%s://mime-%s",
63 content::kGuestScheme,
64 orig_mime_type.c_str());
65 GURL guest_site(guest_site_str);
66
67 // If we already have a webview tag in the same app using the same storage
68 // partition, we should use the same SiteInstance so the existing tag and
69 // the new tag can script each other.
70 extensions::GuestViewManager* guest_view_manager =
71 extensions::GuestViewManager::FromBrowserContext(browser_context());
72 content::SiteInstance* guest_site_instance =
73 guest_view_manager->GetGuestSiteInstance(guest_site);
74 if (!guest_site_instance) {
75 // Create the SiteInstance in a new BrowsingInstance, which will ensure
76 // that guests from different render process are not allowed to send
77 // messages to each other.
78 guest_site_instance = content::SiteInstance::CreateForURL(
79 browser_context(), guest_site);
80 }
81 WebContents::CreateParams params(browser_context(), guest_site_instance);
82 params.guest_delegate = this;
83 callback.Run(WebContents::Create(params));
84 }
85
86 void MimeHandlerViewGuest::DidAttachToEmbedder() {
87 std::string src;
88 DCHECK(attach_params()->GetString(kMimeHandlerViewSrc, &src) && !src.empty());
89 guest_web_contents()->GetController().LoadURL(
90 GURL(src),
91 content::Referrer(),
92 content::PAGE_TRANSITION_AUTO_TOPLEVEL,
93 std::string());
94 }
95
96 void MimeHandlerViewGuest::DidInitialize() {
97 AttachWebContentsHelpers(guest_web_contents());
98 }
99
100 void MimeHandlerViewGuest::AttachWebContentsHelpers(
101 content::WebContents* contents) {
102 // Required for ExtensionHostMsg_PostMessage.
103 extensions::ChromeExtensionWebContentsObserver::CreateForWebContents(
104 contents);
105 }
106
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698