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

Side by Side Diff: chrome/renderer/chrome_content_renderer_client.cc

Issue 8461011: Clean up plug-in placeholders: (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix Created 9 years 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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/renderer/chrome_content_renderer_client.h" 5 #include "chrome/renderer/chrome_content_renderer_client.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/command_line.h" 9 #include "base/command_line.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
(...skipping 10 matching lines...) Expand all
21 #include "chrome/common/extensions/extension.h" 21 #include "chrome/common/extensions/extension.h"
22 #include "chrome/common/extensions/extension_constants.h" 22 #include "chrome/common/extensions/extension_constants.h"
23 #include "chrome/common/extensions/extension_set.h" 23 #include "chrome/common/extensions/extension_set.h"
24 #include "chrome/common/jstemplate_builder.h" 24 #include "chrome/common/jstemplate_builder.h"
25 #include "chrome/common/render_messages.h" 25 #include "chrome/common/render_messages.h"
26 #include "chrome/common/url_constants.h" 26 #include "chrome/common/url_constants.h"
27 #include "chrome/renderer/autofill/autofill_agent.h" 27 #include "chrome/renderer/autofill/autofill_agent.h"
28 #include "chrome/renderer/autofill/password_autofill_manager.h" 28 #include "chrome/renderer/autofill/password_autofill_manager.h"
29 #include "chrome/renderer/automation/automation_renderer_helper.h" 29 #include "chrome/renderer/automation/automation_renderer_helper.h"
30 #include "chrome/renderer/benchmarking_extension.h" 30 #include "chrome/renderer/benchmarking_extension.h"
31 #include "chrome/renderer/blocked_plugin.h"
32 #include "chrome/renderer/chrome_ppapi_interfaces.h" 31 #include "chrome/renderer/chrome_ppapi_interfaces.h"
33 #include "chrome/renderer/chrome_render_process_observer.h" 32 #include "chrome/renderer/chrome_render_process_observer.h"
34 #include "chrome/renderer/chrome_render_view_observer.h" 33 #include "chrome/renderer/chrome_render_view_observer.h"
35 #include "chrome/renderer/content_settings_observer.h" 34 #include "chrome/renderer/content_settings_observer.h"
36 #include "chrome/renderer/extensions/chrome_v8_context.h" 35 #include "chrome/renderer/extensions/chrome_v8_context.h"
37 #include "chrome/renderer/extensions/chrome_v8_extension.h" 36 #include "chrome/renderer/extensions/chrome_v8_extension.h"
38 #include "chrome/renderer/extensions/extension_dispatcher.h" 37 #include "chrome/renderer/extensions/extension_dispatcher.h"
39 #include "chrome/renderer/extensions/extension_helper.h" 38 #include "chrome/renderer/extensions/extension_helper.h"
40 #include "chrome/renderer/extensions/extension_resource_request_policy.h" 39 #include "chrome/renderer/extensions/extension_resource_request_policy.h"
41 #include "chrome/renderer/extensions/miscellaneous_bindings.h" 40 #include "chrome/renderer/extensions/miscellaneous_bindings.h"
42 #include "chrome/renderer/extensions/schema_generated_bindings.h" 41 #include "chrome/renderer/extensions/schema_generated_bindings.h"
43 #include "chrome/renderer/external_extension.h" 42 #include "chrome/renderer/external_extension.h"
44 #include "chrome/renderer/loadtimes_extension_bindings.h" 43 #include "chrome/renderer/loadtimes_extension_bindings.h"
45 #include "chrome/renderer/localized_error.h" 44 #include "chrome/renderer/localized_error.h"
46 #include "chrome/renderer/net/renderer_net_predictor.h" 45 #include "chrome/renderer/net/renderer_net_predictor.h"
47 #include "chrome/renderer/page_click_tracker.h" 46 #include "chrome/renderer/page_click_tracker.h"
48 #include "chrome/renderer/page_load_histograms.h" 47 #include "chrome/renderer/page_load_histograms.h"
49 #include "chrome/renderer/plugin_uma.h" 48 #include "chrome/renderer/plugins/blocked_plugin.h"
49 #include "chrome/renderer/plugins/missing_plugin.h"
50 #include "chrome/renderer/plugins/plugin_uma.h"
50 #include "chrome/renderer/prerender/prerender_helper.h" 51 #include "chrome/renderer/prerender/prerender_helper.h"
51 #include "chrome/renderer/print_web_view_helper.h" 52 #include "chrome/renderer/print_web_view_helper.h"
52 #include "chrome/renderer/renderer_histogram_snapshots.h" 53 #include "chrome/renderer/renderer_histogram_snapshots.h"
53 #include "chrome/renderer/renderer_tracking.h" 54 #include "chrome/renderer/renderer_tracking.h"
54 #include "chrome/renderer/safe_browsing/malware_dom_details.h" 55 #include "chrome/renderer/safe_browsing/malware_dom_details.h"
55 #include "chrome/renderer/safe_browsing/phishing_classifier_delegate.h" 56 #include "chrome/renderer/safe_browsing/phishing_classifier_delegate.h"
56 #include "chrome/renderer/search_extension.h" 57 #include "chrome/renderer/search_extension.h"
57 #include "chrome/renderer/searchbox.h" 58 #include "chrome/renderer/searchbox.h"
58 #include "chrome/renderer/searchbox_extension.h" 59 #include "chrome/renderer/searchbox_extension.h"
59 #include "chrome/renderer/spellchecker/spellcheck.h" 60 #include "chrome/renderer/spellchecker/spellcheck.h"
(...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after
283 ChromeViewHostMsg_GetPluginInfo_Status status; 284 ChromeViewHostMsg_GetPluginInfo_Status status;
284 webkit::WebPluginInfo plugin; 285 webkit::WebPluginInfo plugin;
285 std::string actual_mime_type; 286 std::string actual_mime_type;
286 render_view->Send(new ChromeViewHostMsg_GetPluginInfo( 287 render_view->Send(new ChromeViewHostMsg_GetPluginInfo(
287 render_view->GetRoutingId(), url, frame->top()->document().url(), 288 render_view->GetRoutingId(), url, frame->top()->document().url(),
288 orig_mime_type, &status, &plugin, &actual_mime_type)); 289 orig_mime_type, &status, &plugin, &actual_mime_type));
289 290
290 if (status.value == ChromeViewHostMsg_GetPluginInfo_Status::kNotFound) { 291 if (status.value == ChromeViewHostMsg_GetPluginInfo_Status::kNotFound) {
291 MissingPluginReporter::GetInstance()->ReportPluginMissing( 292 MissingPluginReporter::GetInstance()->ReportPluginMissing(
292 orig_mime_type, url); 293 orig_mime_type, url);
293 return CreatePluginPlaceholder( 294 return MissingPlugin::Create(render_view, frame, original_params);
294 render_view, frame, plugin, original_params, NULL,
295 IDR_BLOCKED_PLUGIN_HTML, IDS_PLUGIN_NOT_FOUND, false, false);
296 } 295 }
297 if (plugin.path.value() == webkit::npapi::kDefaultPluginLibraryName) { 296 if (plugin.path.value() == webkit::npapi::kDefaultPluginLibraryName) {
298 MissingPluginReporter::GetInstance()->ReportPluginMissing( 297 MissingPluginReporter::GetInstance()->ReportPluginMissing(
299 orig_mime_type, url); 298 orig_mime_type, url);
300 } 299 }
301 300
302 scoped_ptr<webkit::npapi::PluginGroup> group( 301 scoped_ptr<webkit::npapi::PluginGroup> group(
303 webkit::npapi::PluginList::Singleton()->GetPluginGroup(plugin)); 302 webkit::npapi::PluginList::Singleton()->GetPluginGroup(plugin));
304 303
305 if (status.value == ChromeViewHostMsg_GetPluginInfo_Status::kDisabled) { 304 if (status.value == ChromeViewHostMsg_GetPluginInfo_Status::kDisabled) {
306 return CreatePluginPlaceholder( 305 return BlockedPlugin::Create(
307 render_view, frame, plugin, original_params, group.get(), 306 render_view, frame, original_params, plugin, group.get(),
308 IDR_DISABLED_PLUGIN_HTML, IDS_PLUGIN_DISABLED, false, false); 307 IDR_DISABLED_PLUGIN_HTML, IDS_PLUGIN_DISABLED, false, false);
309 } 308 }
310 309
311 WebPluginParams params(original_params); 310 WebPluginParams params(original_params);
312 for (size_t i = 0; i < plugin.mime_types.size(); ++i) { 311 for (size_t i = 0; i < plugin.mime_types.size(); ++i) {
313 if (plugin.mime_types[i].mime_type == actual_mime_type) { 312 if (plugin.mime_types[i].mime_type == actual_mime_type) {
314 AppendParams(plugin.mime_types[i].additional_param_names, 313 AppendParams(plugin.mime_types[i].additional_param_names,
315 plugin.mime_types[i].additional_param_values, 314 plugin.mime_types[i].additional_param_values,
316 &params.attributeNames, 315 &params.attributeNames,
317 &params.attributeValues); 316 &params.attributeValues);
318 break; 317 break;
319 } 318 }
320 } 319 }
321 320
322 if (status.value == 321 if (status.value ==
323 ChromeViewHostMsg_GetPluginInfo_Status::kOutdatedBlocked) { 322 ChromeViewHostMsg_GetPluginInfo_Status::kOutdatedBlocked) {
324 render_view->Send(new ChromeViewHostMsg_BlockedOutdatedPlugin( 323 render_view->Send(new ChromeViewHostMsg_BlockedOutdatedPlugin(
325 render_view->GetRoutingId(), group->GetGroupName(), 324 render_view->GetRoutingId(), group->GetGroupName(),
326 GURL(group->GetUpdateURL()))); 325 GURL(group->GetUpdateURL())));
327 } 326 }
328 if (status.value == 327 if (status.value ==
329 ChromeViewHostMsg_GetPluginInfo_Status::kOutdatedBlocked || 328 ChromeViewHostMsg_GetPluginInfo_Status::kOutdatedBlocked ||
330 status.value == 329 status.value ==
331 ChromeViewHostMsg_GetPluginInfo_Status::kOutdatedDisallowed) { 330 ChromeViewHostMsg_GetPluginInfo_Status::kOutdatedDisallowed) {
332 return CreatePluginPlaceholder( 331 return BlockedPlugin::Create(
333 render_view, frame, plugin, params, group.get(), 332 render_view, frame, params, plugin, group.get(),
334 IDR_BLOCKED_PLUGIN_HTML, IDS_PLUGIN_OUTDATED, false, 333 IDR_BLOCKED_PLUGIN_HTML, IDS_PLUGIN_OUTDATED, false,
335 status.value == 334 status.value ==
336 ChromeViewHostMsg_GetPluginInfo_Status::kOutdatedBlocked); 335 ChromeViewHostMsg_GetPluginInfo_Status::kOutdatedBlocked);
337 } 336 }
338 337
339 ContentSettingsObserver* observer = ContentSettingsObserver::Get(render_view); 338 ContentSettingsObserver* observer = ContentSettingsObserver::Get(render_view);
340 339
341 if (status.value == 340 if (status.value ==
342 ChromeViewHostMsg_GetPluginInfo_Status::kUnauthorized && 341 ChromeViewHostMsg_GetPluginInfo_Status::kUnauthorized &&
343 !observer->plugins_temporarily_allowed()) { 342 !observer->plugins_temporarily_allowed()) {
344 render_view->Send(new ChromeViewHostMsg_BlockedOutdatedPlugin( 343 render_view->Send(new ChromeViewHostMsg_BlockedOutdatedPlugin(
345 render_view->GetRoutingId(), group->GetGroupName(), GURL())); 344 render_view->GetRoutingId(), group->GetGroupName(), GURL()));
346 return CreatePluginPlaceholder( 345 return BlockedPlugin::Create(
347 render_view, frame, plugin, params, group.get(), 346 render_view, frame, params, plugin, group.get(),
348 IDR_BLOCKED_PLUGIN_HTML, IDS_PLUGIN_NOT_AUTHORIZED, false, true); 347 IDR_BLOCKED_PLUGIN_HTML, IDS_PLUGIN_NOT_AUTHORIZED, false, true);
349 } 348 }
350 349
351 bool is_nacl_plugin = (plugin.name == ASCIIToUTF16( 350 bool is_nacl_plugin = (plugin.name == ASCIIToUTF16(
352 chrome::ChromeContentClient::kNaClPluginName)); 351 chrome::ChromeContentClient::kNaClPluginName));
353 if (status.value == ChromeViewHostMsg_GetPluginInfo_Status::kAllowed || 352 if (status.value == ChromeViewHostMsg_GetPluginInfo_Status::kAllowed ||
354 observer->plugins_temporarily_allowed() || 353 observer->plugins_temporarily_allowed() ||
355 plugin.path.value() == webkit::npapi::kDefaultPluginLibraryName) { 354 plugin.path.value() == webkit::npapi::kDefaultPluginLibraryName) {
356 // Delay loading plugins if prerendering. 355 // Delay loading plugins if prerendering.
357 if (prerender::PrerenderHelper::IsPrerendering(render_view)) { 356 if (prerender::PrerenderHelper::IsPrerendering(render_view)) {
358 return CreatePluginPlaceholder( 357 return BlockedPlugin::Create(
359 render_view, frame, plugin, params, group.get(), 358 render_view, frame, params, plugin, group.get(),
360 IDR_CLICK_TO_PLAY_PLUGIN_HTML, IDS_PLUGIN_LOAD, true, true); 359 IDR_CLICK_TO_PLAY_PLUGIN_HTML, IDS_PLUGIN_LOAD, true, true);
361 } 360 }
362 361
363 // Determine if NaCl is allowed for both the internal plugin and 362 // Determine if NaCl is allowed for both the internal plugin and
364 // any external plugin that handles our MIME type. This is so NaCl 363 // any external plugin that handles our MIME type. This is so NaCl
365 // tests will still pass. 364 // tests will still pass.
366 const char* kNaClMimeType = "application/x-nacl"; 365 const char* kNaClMimeType = "application/x-nacl";
367 bool is_nacl_mime_type = actual_mime_type == kNaClMimeType; 366 bool is_nacl_mime_type = actual_mime_type == kNaClMimeType;
368 bool is_nacl_enabled; 367 bool is_nacl_enabled;
369 if (is_nacl_plugin) { 368 if (is_nacl_plugin) {
370 is_nacl_enabled = cmd->HasSwitch(switches::kEnableNaCl); 369 is_nacl_enabled = cmd->HasSwitch(switches::kEnableNaCl);
371 } else { 370 } else {
372 // If this is an external plugin that handles NaCl mime type, 371 // If this is an external plugin that handles NaCl mime type,
373 // we want to allow Native Client, because it's how 372 // we want to allow Native Client, because it's how
374 // NaCl tests for the plugin work. 373 // NaCl tests for the plugin work.
375 is_nacl_enabled = true; 374 is_nacl_enabled = true;
376 } 375 }
377 if (is_nacl_plugin || is_nacl_mime_type) { 376 if (is_nacl_plugin || is_nacl_mime_type) {
378 if (!IsNaClAllowed(plugin, 377 if (!IsNaClAllowed(plugin,
379 url, 378 url,
380 actual_mime_type, 379 actual_mime_type,
381 is_nacl_mime_type, 380 is_nacl_mime_type,
382 is_nacl_enabled, 381 is_nacl_enabled,
383 params)) { 382 params)) {
384 return CreatePluginPlaceholder( 383 return BlockedPlugin::Create(
385 render_view, frame, plugin, params, group.get(), 384 render_view, frame, params, plugin, group.get(),
386 IDR_BLOCKED_PLUGIN_HTML, IDS_PLUGIN_BLOCKED, false, false); 385 IDR_BLOCKED_PLUGIN_HTML, IDS_PLUGIN_BLOCKED, false, false);
387 } 386 }
388 } 387 }
389 388
390 return render_view->CreatePlugin(frame, plugin, params); 389 return render_view->CreatePlugin(frame, plugin, params);
391 } 390 }
392 391
393 observer->DidBlockContentType( 392 observer->DidBlockContentType(
394 is_nacl_plugin ? CONTENT_SETTINGS_TYPE_JAVASCRIPT : 393 is_nacl_plugin ? CONTENT_SETTINGS_TYPE_JAVASCRIPT :
395 CONTENT_SETTINGS_TYPE_PLUGINS, 394 CONTENT_SETTINGS_TYPE_PLUGINS,
396 group->identifier()); 395 group->identifier());
397 if (status.value == ChromeViewHostMsg_GetPluginInfo_Status::kClickToPlay) { 396 if (status.value == ChromeViewHostMsg_GetPluginInfo_Status::kClickToPlay) {
398 RenderThread::Get()->RecordUserMetrics("Plugin_ClickToPlay"); 397 RenderThread::Get()->RecordUserMetrics("Plugin_ClickToPlay");
399 return CreatePluginPlaceholder( 398 return BlockedPlugin::Create(
400 render_view, frame, plugin, params, group.get(), 399 render_view, frame, params, plugin, group.get(),
401 IDR_CLICK_TO_PLAY_PLUGIN_HTML, IDS_PLUGIN_LOAD, false, true); 400 IDR_CLICK_TO_PLAY_PLUGIN_HTML, IDS_PLUGIN_LOAD, false, true);
402 } else { 401 } else {
403 DCHECK(status.value == ChromeViewHostMsg_GetPluginInfo_Status::kBlocked); 402 DCHECK(status.value == ChromeViewHostMsg_GetPluginInfo_Status::kBlocked);
404 RenderThread::Get()->RecordUserMetrics("Plugin_Blocked"); 403 RenderThread::Get()->RecordUserMetrics("Plugin_Blocked");
405 return CreatePluginPlaceholder( 404 return BlockedPlugin::Create(
406 render_view, frame, plugin, params, group.get(), 405 render_view, frame, params, plugin, group.get(),
407 IDR_BLOCKED_PLUGIN_HTML, IDS_PLUGIN_BLOCKED, false, true); 406 IDR_BLOCKED_PLUGIN_HTML, IDS_PLUGIN_BLOCKED, false, true);
408 } 407 }
409 } 408 }
410 409
411 bool ChromeContentRendererClient::IsNaClAllowed( 410 bool ChromeContentRendererClient::IsNaClAllowed(
412 const webkit::WebPluginInfo& plugin, 411 const webkit::WebPluginInfo& plugin,
413 const GURL& url, 412 const GURL& url,
414 const std::string& actual_mime_type, 413 const std::string& actual_mime_type,
415 bool is_nacl_mime_type, 414 bool is_nacl_mime_type,
416 bool enable_nacl, 415 bool enable_nacl,
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
482 size_t attribute_count = params.attributeNames.size(); 481 size_t attribute_count = params.attributeNames.size();
483 for (size_t i = 0; i < attribute_count; ++i) { 482 for (size_t i = 0; i < attribute_count; ++i) {
484 if (params.attributeNames[i].equals(dev_attribute)) 483 if (params.attributeNames[i].equals(dev_attribute))
485 params.attributeNames[i] = WebString(); 484 params.attributeNames[i] = WebString();
486 } 485 }
487 } 486 }
488 487
489 return true; 488 return true;
490 } 489 }
491 490
492 WebPlugin* ChromeContentRendererClient::CreatePluginPlaceholder(
493 content::RenderView* render_view,
494 WebFrame* frame,
495 const webkit::WebPluginInfo& plugin,
496 const WebPluginParams& params,
497 const webkit::npapi::PluginGroup* group,
498 int resource_id,
499 int message_id,
500 bool is_blocked_for_prerendering,
501 bool allow_loading) {
502 // |blocked_plugin| will delete itself when the WebViewPlugin
503 // is destroyed.
504 string16 name;
505 string16 message;
506 if (group) {
507 name = group->GetGroupName();
508 message = l10n_util::GetStringFUTF16(message_id, name);
509 } else {
510 message = l10n_util::GetStringUTF16(message_id);
511 }
512
513 BlockedPlugin* blocked_plugin =
514 new BlockedPlugin(render_view,
515 frame,
516 plugin,
517 params,
518 render_view->GetWebkitPreferences(),
519 resource_id,
520 name,
521 message,
522 is_blocked_for_prerendering,
523 allow_loading);
524 return blocked_plugin->plugin();
525 }
526
527 bool ChromeContentRendererClient::HasErrorPage(int http_status_code, 491 bool ChromeContentRendererClient::HasErrorPage(int http_status_code,
528 std::string* error_domain) { 492 std::string* error_domain) {
529 // Use an internal error page, if we have one for the status code. 493 // Use an internal error page, if we have one for the status code.
530 if (!LocalizedError::HasStrings(LocalizedError::kHttpErrorDomain, 494 if (!LocalizedError::HasStrings(LocalizedError::kHttpErrorDomain,
531 http_status_code)) { 495 http_status_code)) {
532 return false; 496 return false;
533 } 497 }
534 498
535 *error_domain = LocalizedError::kHttpErrorDomain; 499 *error_domain = LocalizedError::kHttpErrorDomain;
536 return true; 500 return true;
(...skipping 278 matching lines...) Expand 10 before | Expand all | Expand 10 after
815 bool ChromeContentRendererClient::IsOtherExtensionWithWebRequestInstalled() { 779 bool ChromeContentRendererClient::IsOtherExtensionWithWebRequestInstalled() {
816 return extension_dispatcher_->IsOtherExtensionWithWebRequestInstalled(); 780 return extension_dispatcher_->IsOtherExtensionWithWebRequestInstalled();
817 } 781 }
818 782
819 void ChromeContentRendererClient::RegisterPPAPIInterfaceFactories( 783 void ChromeContentRendererClient::RegisterPPAPIInterfaceFactories(
820 webkit::ppapi::PpapiInterfaceFactoryManager* factory_manager) { 784 webkit::ppapi::PpapiInterfaceFactoryManager* factory_manager) {
821 factory_manager->RegisterFactory(ChromePPAPIInterfaceFactory); 785 factory_manager->RegisterFactory(ChromePPAPIInterfaceFactory);
822 } 786 }
823 787
824 } // namespace chrome 788 } // namespace chrome
OLDNEW
« no previous file with comments | « chrome/renderer/chrome_content_renderer_client.h ('k') | chrome/renderer/custom_menu_commands.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698