OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/plugins/plugin_info_message_filter.h" | 5 #include "chrome/browser/plugins/plugin_info_message_filter.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
9 #include "base/metrics/histogram.h" | 9 #include "base/metrics/histogram.h" |
10 #include "base/prefs/pref_service.h" | 10 #include "base/prefs/pref_service.h" |
11 #include "base/strings/utf_string_conversions.h" | 11 #include "base/strings/utf_string_conversions.h" |
12 #include "chrome/browser/content_settings/content_settings_utils.h" | 12 #include "chrome/browser/content_settings/content_settings_utils.h" |
13 #include "chrome/browser/content_settings/host_content_settings_map.h" | 13 #include "chrome/browser/content_settings/host_content_settings_map.h" |
14 #include "chrome/browser/guest_view/guest_view_manager.h" | |
15 #include "chrome/browser/guest_view/mime_handler_view/mime_handler_view_guest.h" | |
16 #include "chrome/browser/guest_view/web_view/web_view_guest.h" | |
14 #include "chrome/browser/plugins/chrome_plugin_service_filter.h" | 17 #include "chrome/browser/plugins/chrome_plugin_service_filter.h" |
15 #include "chrome/browser/plugins/plugin_finder.h" | 18 #include "chrome/browser/plugins/plugin_finder.h" |
16 #include "chrome/browser/plugins/plugin_metadata.h" | 19 #include "chrome/browser/plugins/plugin_metadata.h" |
17 #include "chrome/browser/plugins/plugin_prefs.h" | 20 #include "chrome/browser/plugins/plugin_prefs.h" |
18 #include "chrome/browser/profiles/profile.h" | 21 #include "chrome/browser/profiles/profile.h" |
19 #include "chrome/common/chrome_content_client.h" | 22 #include "chrome/common/chrome_content_client.h" |
20 #include "chrome/common/content_settings.h" | 23 #include "chrome/common/content_settings.h" |
21 #include "chrome/common/pref_names.h" | 24 #include "chrome/common/pref_names.h" |
22 #include "chrome/common/render_messages.h" | 25 #include "chrome/common/render_messages.h" |
26 #include "content/common/browser_plugin/browser_plugin_constants.h" | |
23 #include "content/public/browser/browser_thread.h" | 27 #include "content/public/browser/browser_thread.h" |
24 #include "content/public/browser/plugin_service.h" | 28 #include "content/public/browser/plugin_service.h" |
25 #include "content/public/browser/plugin_service_filter.h" | 29 #include "content/public/browser/plugin_service_filter.h" |
30 #include "content/public/common/webplugininfo.h" | |
26 #include "url/gurl.h" | 31 #include "url/gurl.h" |
27 | 32 |
28 #include "widevine_cdm_version.h" // In SHARED_INTERMEDIATE_DIR. | 33 #include "widevine_cdm_version.h" // In SHARED_INTERMEDIATE_DIR. |
29 | 34 |
30 #if defined(ENABLE_EXTENSIONS) | 35 #if defined(ENABLE_EXTENSIONS) |
31 #include "chrome/browser/guest_view/web_view/web_view_renderer_state.h" | 36 #include "chrome/browser/guest_view/web_view/web_view_renderer_state.h" |
32 #endif | 37 #endif |
33 | 38 |
34 #if defined(OS_WIN) | 39 #if defined(OS_WIN) |
35 #include "base/win/metro.h" | 40 #include "base/win/metro.h" |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
83 } | 88 } |
84 | 89 |
85 PluginInfoMessageFilter::Context::~Context() { | 90 PluginInfoMessageFilter::Context::~Context() { |
86 } | 91 } |
87 | 92 |
88 PluginInfoMessageFilter::PluginInfoMessageFilter( | 93 PluginInfoMessageFilter::PluginInfoMessageFilter( |
89 int render_process_id, | 94 int render_process_id, |
90 Profile* profile) | 95 Profile* profile) |
91 : BrowserMessageFilter(ChromeMsgStart), | 96 : BrowserMessageFilter(ChromeMsgStart), |
92 context_(render_process_id, profile), | 97 context_(render_process_id, profile), |
98 profile_(profile), | |
93 weak_ptr_factory_(this) { | 99 weak_ptr_factory_(this) { |
94 } | 100 } |
95 | 101 |
96 bool PluginInfoMessageFilter::OnMessageReceived(const IPC::Message& message) { | 102 bool PluginInfoMessageFilter::OnMessageReceived(const IPC::Message& message) { |
97 IPC_BEGIN_MESSAGE_MAP(PluginInfoMessageFilter, message) | 103 IPC_BEGIN_MESSAGE_MAP(PluginInfoMessageFilter, message) |
98 IPC_MESSAGE_HANDLER_DELAY_REPLY(ChromeViewHostMsg_GetPluginInfo, | 104 IPC_MESSAGE_HANDLER_DELAY_REPLY(ChromeViewHostMsg_GetPluginInfo, |
99 OnGetPluginInfo) | 105 OnGetPluginInfo) |
100 #if defined(ENABLE_PEPPER_CDMS) | 106 #if defined(ENABLE_PEPPER_CDMS) |
101 IPC_MESSAGE_HANDLER( | 107 IPC_MESSAGE_HANDLER( |
102 ChromeViewHostMsg_IsInternalPluginRegisteredForMimeType, | 108 ChromeViewHostMsg_IsInternalPluginRegisteredForMimeType, |
(...skipping 14 matching lines...) Expand all Loading... | |
117 | 123 |
118 PluginInfoMessageFilter::~PluginInfoMessageFilter() {} | 124 PluginInfoMessageFilter::~PluginInfoMessageFilter() {} |
119 | 125 |
120 struct PluginInfoMessageFilter::GetPluginInfo_Params { | 126 struct PluginInfoMessageFilter::GetPluginInfo_Params { |
121 int render_frame_id; | 127 int render_frame_id; |
122 GURL url; | 128 GURL url; |
123 GURL top_origin_url; | 129 GURL top_origin_url; |
124 std::string mime_type; | 130 std::string mime_type; |
125 }; | 131 }; |
126 | 132 |
133 void PluginInfoMessageFilter::CreateGuestOnUI( | |
134 Profile* profile, | |
135 int render_process_id, | |
136 GURL top_origin_url, | |
137 scoped_ptr<ChromeViewHostMsg_GetPluginInfo_Output> output, | |
138 IPC::Message* reply_msg) { | |
139 GuestViewManager* guest_view_manager = | |
140 GuestViewManager::FromBrowserContext(profile); | |
141 DCHECK(guest_view_manager); | |
142 base::DictionaryValue create_params; | |
143 guest_view_manager->CreateGuest( | |
144 MimeHandlerViewGuest::Type, | |
145 // TODO(lazyboy): CreateGuest should take GURL instead of std::string. | |
146 top_origin_url.possibly_invalid_spec(), | |
Fady Samuel
2014/07/21 14:47:35
CreateGuest doesn't take a URL. It takes in an ext
lazyboy
2014/07/21 17:28:21
Right.
For mime handler view, we don't have an ext
| |
147 render_process_id, | |
148 create_params, | |
149 base::Bind(&PluginInfoMessageFilter::GuestCreatedOnUICallback, | |
150 weak_ptr_factory_.GetWeakPtr(), | |
151 base::Passed(&output), | |
152 reply_msg)); | |
153 } | |
154 | |
155 void PluginInfoMessageFilter::GuestCreatedOnUICallback( | |
156 scoped_ptr<ChromeViewHostMsg_GetPluginInfo_Output> output, | |
157 IPC::Message* reply_msg, | |
158 content::WebContents* guest_web_contents) { | |
159 int plugin_instance_id = content::browser_plugin::kInstanceIDNone; | |
160 MimeHandlerViewGuest* guest = MimeHandlerViewGuest::FromWebContents( | |
161 guest_web_contents); | |
162 if (guest) | |
163 plugin_instance_id = guest->GetGuestInstanceID(); | |
164 | |
165 // Set the instance ID so content/ can call attach. | |
166 output->instance_id = plugin_instance_id; | |
167 | |
168 content::BrowserThread::PostTask( | |
169 content::BrowserThread::IO, | |
170 FROM_HERE, | |
171 base::Bind(&PluginInfoMessageFilter::GuestCreatedOnIO, | |
172 this, base::Passed(&output), reply_msg)); | |
173 } | |
174 | |
175 void PluginInfoMessageFilter::GuestCreatedOnIO( | |
176 const scoped_ptr<ChromeViewHostMsg_GetPluginInfo_Output>& output, | |
177 IPC::Message* reply_msg) { | |
178 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO)); | |
179 ChromeViewHostMsg_GetPluginInfo::WriteReplyParams(reply_msg, *output); | |
180 Send(reply_msg); | |
181 } | |
182 | |
127 void PluginInfoMessageFilter::OnGetPluginInfo( | 183 void PluginInfoMessageFilter::OnGetPluginInfo( |
128 int render_frame_id, | 184 int render_frame_id, |
129 const GURL& url, | 185 const GURL& url, |
130 const GURL& top_origin_url, | 186 const GURL& top_origin_url, |
131 const std::string& mime_type, | 187 const std::string& mime_type, |
132 IPC::Message* reply_msg) { | 188 IPC::Message* reply_msg) { |
133 GetPluginInfo_Params params = { | 189 GetPluginInfo_Params params = { |
134 render_frame_id, | 190 render_frame_id, |
135 url, | 191 url, |
136 top_origin_url, | 192 top_origin_url, |
137 mime_type | 193 mime_type |
138 }; | 194 }; |
139 PluginService::GetInstance()->GetPlugins( | 195 PluginService::GetInstance()->GetPlugins( |
140 base::Bind(&PluginInfoMessageFilter::PluginsLoaded, | 196 base::Bind(&PluginInfoMessageFilter::PluginsLoaded, |
141 weak_ptr_factory_.GetWeakPtr(), | 197 weak_ptr_factory_.GetWeakPtr(), |
142 params, reply_msg)); | 198 params, reply_msg)); |
143 } | 199 } |
144 | 200 |
145 void PluginInfoMessageFilter::PluginsLoaded( | 201 void PluginInfoMessageFilter::PluginsLoaded( |
146 const GetPluginInfo_Params& params, | 202 const GetPluginInfo_Params& params, |
147 IPC::Message* reply_msg, | 203 IPC::Message* reply_msg, |
148 const std::vector<WebPluginInfo>& plugins) { | 204 const std::vector<WebPluginInfo>& plugins) { |
149 ChromeViewHostMsg_GetPluginInfo_Output output; | 205 scoped_ptr<ChromeViewHostMsg_GetPluginInfo_Output> output( |
206 new ChromeViewHostMsg_GetPluginInfo_Output); | |
150 // This also fills in |actual_mime_type|. | 207 // This also fills in |actual_mime_type|. |
151 scoped_ptr<PluginMetadata> plugin_metadata; | 208 scoped_ptr<PluginMetadata> plugin_metadata; |
152 if (context_.FindEnabledPlugin(params.render_frame_id, params.url, | 209 if (context_.FindEnabledPlugin(params.render_frame_id, params.url, |
153 params.top_origin_url, params.mime_type, | 210 params.top_origin_url, params.mime_type, |
154 &output.status, &output.plugin, | 211 &output->status, &output->plugin, |
155 &output.actual_mime_type, | 212 &output->actual_mime_type, |
156 &plugin_metadata)) { | 213 &plugin_metadata)) { |
157 context_.DecidePluginStatus(params, output.plugin, plugin_metadata.get(), | 214 context_.DecidePluginStatus(params, output->plugin, plugin_metadata.get(), |
158 &output.status); | 215 &output->status); |
159 } | 216 } |
160 | 217 |
161 if (plugin_metadata) { | 218 if (plugin_metadata) { |
162 output.group_identifier = plugin_metadata->identifier(); | 219 output->group_identifier = plugin_metadata->identifier(); |
163 output.group_name = plugin_metadata->name(); | 220 output->group_name = plugin_metadata->name(); |
164 } | 221 } |
165 | 222 |
166 context_.MaybeGrantAccess(output.status, output.plugin.path); | 223 context_.MaybeGrantAccess(output->status, output->plugin.path); |
167 | 224 |
168 ChromeViewHostMsg_GetPluginInfo::WriteReplyParams(reply_msg, output); | 225 if (output->plugin.type == |
226 content::WebPluginInfo::PluginType::PLUGIN_TYPE_BROWSER_PLUGIN) { | |
227 content::BrowserThread::PostTask( | |
228 content::BrowserThread::UI, | |
229 FROM_HERE, | |
230 base::Bind(&PluginInfoMessageFilter::CreateGuestOnUI, | |
231 this, | |
232 profile_, | |
233 context_.render_process_id(), | |
234 params.top_origin_url, | |
235 base::Passed(&output), | |
236 reply_msg)); | |
237 return; | |
238 } | |
239 | |
240 ChromeViewHostMsg_GetPluginInfo::WriteReplyParams(reply_msg, *output); | |
169 Send(reply_msg); | 241 Send(reply_msg); |
170 } | 242 } |
171 | 243 |
172 #if defined(ENABLE_PEPPER_CDMS) | 244 #if defined(ENABLE_PEPPER_CDMS) |
173 void PluginInfoMessageFilter::OnIsInternalPluginRegisteredForMimeType( | 245 void PluginInfoMessageFilter::OnIsInternalPluginRegisteredForMimeType( |
174 const std::string& mime_type, | 246 const std::string& mime_type, |
175 bool* is_registered, | 247 bool* is_registered, |
176 std::vector<base::string16>* additional_param_names, | 248 std::vector<base::string16>* additional_param_names, |
177 std::vector<base::string16>* additional_param_values) { | 249 std::vector<base::string16>* additional_param_values) { |
178 std::vector<WebPluginInfo> plugins; | 250 std::vector<WebPluginInfo> plugins; |
(...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
396 void PluginInfoMessageFilter::Context::MaybeGrantAccess( | 468 void PluginInfoMessageFilter::Context::MaybeGrantAccess( |
397 const ChromeViewHostMsg_GetPluginInfo_Status& status, | 469 const ChromeViewHostMsg_GetPluginInfo_Status& status, |
398 const base::FilePath& path) const { | 470 const base::FilePath& path) const { |
399 if (status.value == ChromeViewHostMsg_GetPluginInfo_Status::kAllowed || | 471 if (status.value == ChromeViewHostMsg_GetPluginInfo_Status::kAllowed || |
400 status.value == ChromeViewHostMsg_GetPluginInfo_Status::kClickToPlay) { | 472 status.value == ChromeViewHostMsg_GetPluginInfo_Status::kClickToPlay) { |
401 ChromePluginServiceFilter::GetInstance()->AuthorizePlugin( | 473 ChromePluginServiceFilter::GetInstance()->AuthorizePlugin( |
402 render_process_id_, path); | 474 render_process_id_, path); |
403 } | 475 } |
404 } | 476 } |
405 | 477 |
OLD | NEW |