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 "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 "chrome/browser/guest_view/guest_view_manager.h" | |
10 #include "chrome/browser/guest_view/web_view/web_view_renderer_state.h" | |
11 #include "content/public/browser/browser_thread.h" | |
12 #include "content/public/browser/render_process_host.h" | |
13 #include "content/public/common/url_constants.h" | |
14 | |
15 using content::WebContents; | |
16 | |
17 // static | |
18 const char MimeHandlerViewGuest::Type[] = "mimehandler"; | |
19 | |
20 MimeHandlerViewGuest::MimeHandlerViewGuest( | |
21 content::BrowserContext* browser_context, | |
22 int guest_instance_id) | |
23 : GuestView<MimeHandlerViewGuest>( | |
24 browser_context, guest_instance_id), | |
25 has_navigated_(false) { | |
Fady Samuel
2014/07/21 14:47:35
Get rid of this flag.
lazyboy
2014/07/21 17:28:21
Done.
| |
26 } | |
27 | |
28 MimeHandlerViewGuest::~MimeHandlerViewGuest() { | |
29 } | |
30 | |
31 bool MimeHandlerViewGuest::CanEmbedderUseGuestView( | |
32 const std::string& embedder_extension_id) { | |
33 return true; | |
34 } | |
35 void MimeHandlerViewGuest::CreateWebContents( | |
36 const std::string& embedder_extension_id, | |
37 int embedder_render_process_id, | |
38 const base::DictionaryValue& create_params, | |
39 const WebContentsCreatedCallback& callback) { | |
40 content::RenderProcessHost* embedder_render_process_host = | |
Fady Samuel
2014/07/21 14:47:35
This doesn't seem necessary, you can simply use br
lazyboy
2014/07/21 17:28:21
Done.
| |
41 content::RenderProcessHost::FromID(embedder_render_process_id); | |
42 | |
43 GURL guest_site(base::StringPrintf("%s://%s/", | |
44 content::kGuestScheme, | |
45 embedder_extension_id.c_str())); | |
46 | |
47 // If we already have a webview tag in the same app using the same storage | |
48 // partition, we should use the same SiteInstance so the existing tag and | |
49 // the new tag can script each other. | |
50 GuestViewManager* guest_view_manager = | |
51 GuestViewManager::FromBrowserContext( | |
52 embedder_render_process_host->GetBrowserContext()); | |
53 content::SiteInstance* guest_site_instance = | |
54 guest_view_manager->GetGuestSiteInstance(guest_site); | |
55 if (!guest_site_instance) { | |
56 // Create the SiteInstance in a new BrowsingInstance, which will ensure | |
57 // that webview tags are also not allowed to send messages across | |
Fady Samuel
2014/07/21 14:47:35
This comment doesn't make sense for MimeHandlerVie
lazyboy
2014/07/21 17:28:21
I've reworded the comments.
| |
58 // different partitions. | |
59 guest_site_instance = content::SiteInstance::CreateForURL( | |
60 embedder_render_process_host->GetBrowserContext(), guest_site); | |
61 } | |
62 WebContents::CreateParams params( | |
63 embedder_render_process_host->GetBrowserContext(), | |
64 guest_site_instance); | |
65 params.guest_delegate = this; | |
66 callback.Run(WebContents::Create(params)); | |
67 } | |
68 | |
69 void MimeHandlerViewGuest::DidAttachToEmbedder() { | |
70 has_navigated_ = false; | |
Fady Samuel
2014/07/21 14:47:35
This flag seems unnecessary.
lazyboy
2014/07/21 17:28:21
Done.
| |
71 std::string src; | |
72 if (extra_params()->GetString("src", &src) && !src.empty()) | |
Fady Samuel
2014/07/21 14:47:35
Make src a constant.
lazyboy
2014/07/21 17:28:20
Done.
| |
73 NavigateGuest(src); | |
74 | |
75 DCHECK(!GetOpener()); | |
Fady Samuel
2014/07/21 14:47:35
Why is this DCHECK important?
lazyboy
2014/07/21 17:28:20
It's not, copy paste stuff, removed.
| |
76 } | |
77 | |
78 void MimeHandlerViewGuest::DidInitialize() { | |
79 AttachWebContentsHelpers(guest_web_contents()); | |
80 } | |
81 | |
82 void MimeHandlerViewGuest::AttachWebContentsHelpers( | |
83 content::WebContents* contents) { | |
84 // Required for ExtensionHostMsg_PostMessage. | |
85 extensions::ChromeExtensionWebContentsObserver::CreateForWebContents( | |
86 contents); | |
87 } | |
88 | |
89 void MimeHandlerViewGuest::NavigateGuest(const std::string& src) { | |
90 if (has_navigated_) | |
91 return; | |
92 | |
93 has_navigated_ = true; | |
94 GURL validated_url(src); | |
95 guest_web_contents()->GetRenderProcessHost()-> | |
96 FilterURL(false, &validated_url); | |
97 // As guests do not swap processes on navigation, only navigations to | |
98 // normal web URLs are supported. No protocol handlers are installed for | |
99 // other schemes (e.g., WebUI or extensions), and no permissions or bindings | |
100 // can be granted to the guest process. | |
101 content::NavigationController::LoadURLParams load_url_params(validated_url); | |
102 load_url_params.referrer = content::Referrer(); | |
103 load_url_params.transition_type = content::PAGE_TRANSITION_AUTO_TOPLEVEL; | |
104 load_url_params.extra_headers = std::string(); | |
105 guest_web_contents()->GetController().LoadURLWithParams(load_url_params); | |
Fady Samuel
2014/07/21 14:47:35
This seems unnecessary. Why can't it be something
lazyboy
2014/07/21 17:28:21
That's simpler, thanks.
Done.
| |
106 } | |
OLD | NEW |