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 // TODO(lazyboy): "mimeType" in a constant. | |
Fady Samuel
2014/09/02 21:53:25
Stale comment? Remove?
lazyboy
2014/09/02 22:03:19
Done.
| |
55 DCHECK(create_params.GetString(mimehandlerview::kMimeType, &orig_mime_type) && | |
56 !orig_mime_type.empty()); | |
57 std::string guest_site_str; | |
58 // Note that we put a prefix "mime-" before the mime type so that this | |
59 // can never collide with an extension ID. | |
60 guest_site_str = base::StringPrintf( | |
61 "%s://mime-%s", content::kGuestScheme, orig_mime_type.c_str()); | |
62 GURL guest_site(guest_site_str); | |
63 | |
64 // If we already have a webview tag in the same app using the same storage | |
Fady Samuel
2014/09/02 21:53:25
Update comment. It says webview here.
lazyboy
2014/09/02 22:03:19
Done.
| |
65 // partition, we should use the same SiteInstance so the existing tag and | |
66 // the new tag can script each other. | |
67 GuestViewManager* guest_view_manager = | |
68 GuestViewManager::FromBrowserContext(browser_context()); | |
69 content::SiteInstance* guest_site_instance = | |
70 guest_view_manager->GetGuestSiteInstance(guest_site); | |
71 if (!guest_site_instance) { | |
72 // Create the SiteInstance in a new BrowsingInstance, which will ensure | |
73 // that guests from different render process are not allowed to send | |
74 // messages to each other. | |
75 guest_site_instance = | |
76 content::SiteInstance::CreateForURL(browser_context(), guest_site); | |
77 } | |
78 WebContents::CreateParams params(browser_context(), guest_site_instance); | |
79 params.guest_delegate = this; | |
80 callback.Run(WebContents::Create(params)); | |
81 } | |
82 | |
83 void MimeHandlerViewGuest::DidAttachToEmbedder() { | |
84 std::string src; | |
85 DCHECK(attach_params()->GetString(mimehandlerview::kSrc, &src) && | |
86 !src.empty()); | |
87 guest_web_contents()->GetController().LoadURL( | |
88 GURL(src), | |
89 content::Referrer(), | |
90 content::PAGE_TRANSITION_AUTO_TOPLEVEL, | |
91 std::string()); | |
92 } | |
93 | |
94 } // namespace extensions | |
OLD | NEW |