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

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

Issue 7990005: Use a placeholder instead of the default plugin for missing plug-ins on Mac and Linux. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: '' Created 9 years, 2 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 | 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/message_loop.h" 10 #include "base/message_loop.h"
(...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after
258 258
259 SkBitmap* ChromeContentRendererClient::GetSadPluginBitmap() { 259 SkBitmap* ChromeContentRendererClient::GetSadPluginBitmap() {
260 return ResourceBundle::GetSharedInstance().GetBitmapNamed(IDR_SAD_PLUGIN); 260 return ResourceBundle::GetSharedInstance().GetBitmapNamed(IDR_SAD_PLUGIN);
261 } 261 }
262 262
263 std::string ChromeContentRendererClient::GetDefaultEncoding() { 263 std::string ChromeContentRendererClient::GetDefaultEncoding() {
264 return l10n_util::GetStringUTF8(IDS_DEFAULT_ENCODING); 264 return l10n_util::GetStringUTF8(IDS_DEFAULT_ENCODING);
265 } 265 }
266 266
267 bool ChromeContentRendererClient::OverrideCreatePlugin( 267 bool ChromeContentRendererClient::OverrideCreatePlugin(
268 RenderView* render_view, 268 RenderView* render_view,
269 WebFrame* frame, 269 WebFrame* frame,
270 const WebPluginParams& params, 270 const WebPluginParams& params,
271 WebKit::WebPlugin** plugin) { 271 WebKit::WebPlugin** plugin) {
272 bool is_default_plugin; 272 *plugin = CreatePlugin(render_view, frame, params);
273 *plugin = CreatePlugin(render_view, frame, params, &is_default_plugin);
274 if (!*plugin || is_default_plugin)
275 MissingPluginReporter::GetInstance()->ReportPluginMissing(
276 params.mimeType.utf8(), params.url);
277 return true; 273 return true;
278 } 274 }
279 275
280 WebPlugin* ChromeContentRendererClient::CreatePlugin( 276 WebPlugin* ChromeContentRendererClient::CreatePlugin(
281 RenderView* render_view, 277 RenderView* render_view,
282 WebFrame* frame, 278 WebFrame* frame,
283 const WebPluginParams& original_params, 279 const WebPluginParams& original_params) {
284 bool* is_default_plugin) {
285 *is_default_plugin = false;
286 CommandLine* cmd = CommandLine::ForCurrentProcess(); 280 CommandLine* cmd = CommandLine::ForCurrentProcess();
287 webkit::WebPluginInfo info;
288 GURL url(original_params.url); 281 GURL url(original_params.url);
289 std::string orig_mime_type = original_params.mimeType.utf8(); 282 std::string orig_mime_type = original_params.mimeType.utf8();
283 std::vector<webkit::WebPluginInfo> plugins;
284 std::vector<std::string> mime_types;
285 std::vector<bool> allowed;
286 render_view->GetMatchingPlugins(
287 url, frame->top()->document().url(), orig_mime_type,
288 &plugins, &mime_types, &allowed);
289
290 webkit::WebPluginInfo info;
290 std::string actual_mime_type; 291 std::string actual_mime_type;
292 if (plugins.empty()) {
293 MissingPluginReporter::GetInstance()->ReportPluginMissing(
294 orig_mime_type, url);
295 return CreatePluginPlaceholder(
296 render_view, frame, original_params, NULL, IDR_BLOCKED_PLUGIN_HTML,
297 IDS_PLUGIN_NOT_FOUND, false, false);
298 } else {
299 bool plugin_allowed = false;
300 for (size_t i = 0; i < plugins.size(); ++i) {
301 plugin_allowed = allowed[i];
302 if (i == 0 || plugin_allowed) {
jam 2011/09/27 16:51:34 it's not clear to me why you do this, i.e. why the
Bernhard Bauer 2011/09/27 21:21:39 I want to differentiate between the case where the
jam 2011/09/29 01:03:32 Since content's renderer side doesn't care about g
Bernhard Bauer 2011/09/29 13:20:47 Ok, that sounds good. Then we can also do addition
jam 2011/09/29 16:31:10 yep sounds good.
303 info = plugins[i];
304 actual_mime_type = mime_types[i];
305 }
306 if (plugin_allowed)
307 break;
308 }
309 if (!plugin_allowed)
310 return NULL; // TODO(bauerb): Show placeholder for disabled plug-in.
311 }
291 312
292 bool found = render_view->GetPluginInfo( 313 if (info.path.value() == webkit::npapi::kDefaultPluginLibraryName) {
293 url, frame->top()->document().url(), orig_mime_type, &info, 314 MissingPluginReporter::GetInstance()->ReportPluginMissing(
294 &actual_mime_type); 315 orig_mime_type, url);
295 316 }
296 if (!found)
297 return NULL;
298
299 *is_default_plugin =
300 info.path.value() == webkit::npapi::kDefaultPluginLibraryName;
301 317
302 if (orig_mime_type == actual_mime_type) { 318 if (orig_mime_type == actual_mime_type) {
303 UMA_HISTOGRAM_ENUMERATION(kPluginTypeMismatch, 319 UMA_HISTOGRAM_ENUMERATION(kPluginTypeMismatch,
304 PLUGIN_TYPE_MISMATCH_NONE, 320 PLUGIN_TYPE_MISMATCH_NONE,
305 PLUGIN_TYPE_MISMATCH_NUM_EVENTS); 321 PLUGIN_TYPE_MISMATCH_NUM_EVENTS);
306 } else if (orig_mime_type.empty()) { 322 } else if (orig_mime_type.empty()) {
307 UMA_HISTOGRAM_ENUMERATION(kPluginTypeMismatch, 323 UMA_HISTOGRAM_ENUMERATION(kPluginTypeMismatch,
308 PLUGIN_TYPE_MISMATCH_ORIG_EMPTY, 324 PLUGIN_TYPE_MISMATCH_ORIG_EMPTY,
309 PLUGIN_TYPE_MISMATCH_NUM_EVENTS); 325 PLUGIN_TYPE_MISMATCH_NUM_EVENTS);
310 } else if (orig_mime_type == kApplicationOctetStream) { 326 } else if (orig_mime_type == kApplicationOctetStream) {
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
357 373
358 if (group->IsVulnerable(info)) { 374 if (group->IsVulnerable(info)) {
359 if (outdated_policy == CONTENT_SETTING_ASK || 375 if (outdated_policy == CONTENT_SETTING_ASK ||
360 outdated_policy == CONTENT_SETTING_BLOCK) { 376 outdated_policy == CONTENT_SETTING_BLOCK) {
361 if (outdated_policy == CONTENT_SETTING_ASK) { 377 if (outdated_policy == CONTENT_SETTING_ASK) {
362 render_view->Send(new ChromeViewHostMsg_BlockedOutdatedPlugin( 378 render_view->Send(new ChromeViewHostMsg_BlockedOutdatedPlugin(
363 render_view->routing_id(), group->GetGroupName(), 379 render_view->routing_id(), group->GetGroupName(),
364 GURL(group->GetUpdateURL()))); 380 GURL(group->GetUpdateURL())));
365 } 381 }
366 return CreatePluginPlaceholder( 382 return CreatePluginPlaceholder(
367 render_view, frame, params, *group, IDR_BLOCKED_PLUGIN_HTML, 383 render_view, frame, params, group.get(), IDR_BLOCKED_PLUGIN_HTML,
368 IDS_PLUGIN_OUTDATED, false, outdated_policy == CONTENT_SETTING_ASK); 384 IDS_PLUGIN_OUTDATED, false, outdated_policy == CONTENT_SETTING_ASK);
369 } else { 385 } else {
370 DCHECK(outdated_policy == CONTENT_SETTING_ALLOW); 386 DCHECK(outdated_policy == CONTENT_SETTING_ALLOW);
371 } 387 }
372 } 388 }
373 389
374 ContentSettingsObserver* observer = ContentSettingsObserver::Get(render_view); 390 ContentSettingsObserver* observer = ContentSettingsObserver::Get(render_view);
375 ContentSetting host_setting = 391 ContentSetting host_setting =
376 observer->GetContentSetting(CONTENT_SETTINGS_TYPE_PLUGINS); 392 observer->GetContentSetting(CONTENT_SETTINGS_TYPE_PLUGINS);
377 393
378 if (group->RequiresAuthorization(info) && 394 if (group->RequiresAuthorization(info) &&
379 authorize_policy == CONTENT_SETTING_ASK && 395 authorize_policy == CONTENT_SETTING_ASK &&
380 (plugin_setting == CONTENT_SETTING_ALLOW || 396 (plugin_setting == CONTENT_SETTING_ALLOW ||
381 plugin_setting == CONTENT_SETTING_ASK) && 397 plugin_setting == CONTENT_SETTING_ASK) &&
382 host_setting == CONTENT_SETTING_DEFAULT) { 398 host_setting == CONTENT_SETTING_DEFAULT) {
383 render_view->Send(new ChromeViewHostMsg_BlockedOutdatedPlugin( 399 render_view->Send(new ChromeViewHostMsg_BlockedOutdatedPlugin(
384 render_view->routing_id(), group->GetGroupName(), GURL())); 400 render_view->routing_id(), group->GetGroupName(), GURL()));
385 return CreatePluginPlaceholder( 401 return CreatePluginPlaceholder(
386 render_view, frame, params, *group, IDR_BLOCKED_PLUGIN_HTML, 402 render_view, frame, params, group.get(), IDR_BLOCKED_PLUGIN_HTML,
387 IDS_PLUGIN_NOT_AUTHORIZED, false, true); 403 IDS_PLUGIN_NOT_AUTHORIZED, false, true);
388 } 404 }
389 405
390 // Treat Native Client invocations like Javascript. 406 // Treat Native Client invocations like Javascript.
391 bool is_nacl_plugin = 407 bool is_nacl_plugin =
392 info.name == ASCIIToUTF16(ChromeContentClient::kNaClPluginName); 408 info.name == ASCIIToUTF16(ChromeContentClient::kNaClPluginName);
393 if (is_nacl_plugin) { 409 if (is_nacl_plugin) {
394 plugin_setting = 410 plugin_setting =
395 observer->GetContentSetting(CONTENT_SETTINGS_TYPE_JAVASCRIPT); 411 observer->GetContentSetting(CONTENT_SETTINGS_TYPE_JAVASCRIPT);
396 } 412 }
397 413
398 if (plugin_setting == CONTENT_SETTING_ALLOW || 414 if (plugin_setting == CONTENT_SETTING_ALLOW ||
399 host_setting == CONTENT_SETTING_ALLOW || 415 host_setting == CONTENT_SETTING_ALLOW ||
400 info.path.value() == webkit::npapi::kDefaultPluginLibraryName) { 416 info.path.value() == webkit::npapi::kDefaultPluginLibraryName) {
401 // Delay loading plugins if prerendering. 417 // Delay loading plugins if prerendering.
402 if (prerender::PrerenderHelper::IsPrerendering(render_view)) { 418 if (prerender::PrerenderHelper::IsPrerendering(render_view)) {
403 return CreatePluginPlaceholder( 419 return CreatePluginPlaceholder(
404 render_view, frame, params, *group, IDR_CLICK_TO_PLAY_PLUGIN_HTML, 420 render_view, frame, params, group.get(),
405 IDS_PLUGIN_LOAD, true, true); 421 IDR_CLICK_TO_PLAY_PLUGIN_HTML, IDS_PLUGIN_LOAD, true, true);
406 } 422 }
407 423
408 // Enforce the Chrome WebStore restriction on the Native Client plugin. 424 // Enforce the Chrome WebStore restriction on the Native Client plugin.
409 if (is_nacl_plugin) { 425 if (is_nacl_plugin) {
410 bool allow_nacl = cmd->HasSwitch(switches::kEnableNaCl); 426 bool allow_nacl = cmd->HasSwitch(switches::kEnableNaCl);
411 if (!allow_nacl) { 427 if (!allow_nacl) {
412 const char* kNaClPluginMimeType = "application/x-nacl"; 428 const char* kNaClPluginMimeType = "application/x-nacl";
413 const char* kNaClPluginManifestAttribute = "nacl"; 429 const char* kNaClPluginManifestAttribute = "nacl";
414 430
415 GURL nexe_url; 431 GURL nexe_url;
(...skipping 27 matching lines...) Expand all
443 allow_nacl = extension && 459 allow_nacl = extension &&
444 (extension->from_webstore() || 460 (extension->from_webstore() ||
445 extension->location() == Extension::COMPONENT || 461 extension->location() == Extension::COMPONENT ||
446 extension->location() == Extension::LOAD); 462 extension->location() == Extension::LOAD);
447 } 463 }
448 464
449 if (!allow_nacl) { 465 if (!allow_nacl) {
450 // TODO(bbudge) Webkit will crash if this is a full-frame plug-in and 466 // TODO(bbudge) Webkit will crash if this is a full-frame plug-in and
451 // we return NULL. Prepare a patch to fix that, and return NULL here. 467 // we return NULL. Prepare a patch to fix that, and return NULL here.
452 return CreatePluginPlaceholder( 468 return CreatePluginPlaceholder(
453 render_view, frame, params, *group, IDR_BLOCKED_PLUGIN_HTML, 469 render_view, frame, params, group.get(), IDR_BLOCKED_PLUGIN_HTML,
454 IDS_PLUGIN_BLOCKED, false, false); 470 IDS_PLUGIN_BLOCKED, false, false);
455 } 471 }
456 } 472 }
457 473
458 bool pepper_plugin_was_registered = false; 474 bool pepper_plugin_was_registered = false;
459 scoped_refptr<webkit::ppapi::PluginModule> pepper_module( 475 scoped_refptr<webkit::ppapi::PluginModule> pepper_module(
460 render_view->pepper_delegate()->CreatePepperPluginModule( 476 render_view->pepper_delegate()->CreatePepperPluginModule(
461 info, &pepper_plugin_was_registered)); 477 info, &pepper_plugin_was_registered));
462 if (pepper_plugin_was_registered) { 478 if (pepper_plugin_was_registered) {
463 if (pepper_module) { 479 if (pepper_module) {
464 return render_view->CreatePepperPlugin( 480 return render_view->CreatePepperPlugin(
465 frame, params, info.path, pepper_module.get()); 481 frame, params, info.path, pepper_module.get());
466 } 482 }
467 return NULL; 483 return NULL;
468 } 484 }
469 485
470 return render_view->CreateNPAPIPlugin( 486 return render_view->CreateNPAPIPlugin(
471 frame, params, info.path, actual_mime_type); 487 frame, params, info.path, actual_mime_type);
472 } 488 }
473 489
474 observer->DidBlockContentType(CONTENT_SETTINGS_TYPE_PLUGINS, resource); 490 observer->DidBlockContentType(CONTENT_SETTINGS_TYPE_PLUGINS, resource);
475 if (plugin_setting == CONTENT_SETTING_ASK) { 491 if (plugin_setting == CONTENT_SETTING_ASK) {
476 RenderThread::RecordUserMetrics("Plugin_ClickToPlay"); 492 RenderThread::RecordUserMetrics("Plugin_ClickToPlay");
477 return CreatePluginPlaceholder( 493 return CreatePluginPlaceholder(
478 render_view, frame, params, *group, IDR_CLICK_TO_PLAY_PLUGIN_HTML, 494 render_view, frame, params, group.get(), IDR_CLICK_TO_PLAY_PLUGIN_HTML,
479 IDS_PLUGIN_LOAD, false, true); 495 IDS_PLUGIN_LOAD, false, true);
480 } else { 496 } else {
481 RenderThread::RecordUserMetrics("Plugin_Blocked"); 497 RenderThread::RecordUserMetrics("Plugin_Blocked");
482 return CreatePluginPlaceholder( 498 return CreatePluginPlaceholder(
483 render_view, frame, params, *group, IDR_BLOCKED_PLUGIN_HTML, 499 render_view, frame, params, group.get(), IDR_BLOCKED_PLUGIN_HTML,
484 IDS_PLUGIN_BLOCKED, false, true); 500 IDS_PLUGIN_BLOCKED, false, true);
485 } 501 }
486 } 502 }
487 503
488 WebPlugin* ChromeContentRendererClient::CreatePluginPlaceholder( 504 WebPlugin* ChromeContentRendererClient::CreatePluginPlaceholder(
489 RenderView* render_view, 505 RenderView* render_view,
490 WebFrame* frame, 506 WebFrame* frame,
491 const WebPluginParams& params, 507 const WebPluginParams& params,
492 const webkit::npapi::PluginGroup& group, 508 const webkit::npapi::PluginGroup* group,
493 int resource_id, 509 int resource_id,
494 int message_id, 510 int message_id,
495 bool is_blocked_for_prerendering, 511 bool is_blocked_for_prerendering,
496 bool allow_loading) { 512 bool allow_loading) {
497 // |blocked_plugin| will delete itself when the WebViewPlugin 513 // |blocked_plugin| will delete itself when the WebViewPlugin
498 // is destroyed. 514 // is destroyed.
515 string16 name;
516 string16 message;
517 if (group) {
518 name = group->GetGroupName();
519 message = l10n_util::GetStringFUTF16(message_id, name);
520 } else {
521 message = l10n_util::GetStringUTF16(message_id);
522 }
523
499 BlockedPlugin* blocked_plugin = 524 BlockedPlugin* blocked_plugin =
500 new BlockedPlugin(render_view, 525 new BlockedPlugin(render_view,
501 frame, 526 frame,
502 group,
503 params, 527 params,
504 render_view->webkit_preferences(), 528 render_view->webkit_preferences(),
505 resource_id, 529 resource_id,
506 l10n_util::GetStringFUTF16(message_id, 530 name,
507 group.GetGroupName()), 531 message,
508 is_blocked_for_prerendering, 532 is_blocked_for_prerendering,
509 allow_loading); 533 allow_loading);
510 return blocked_plugin->plugin(); 534 return blocked_plugin->plugin();
511 } 535 }
512 536
513 void ChromeContentRendererClient::ShowErrorPage(RenderView* render_view, 537 void ChromeContentRendererClient::ShowErrorPage(RenderView* render_view,
514 WebKit::WebFrame* frame, 538 WebKit::WebFrame* frame,
515 int http_status_code) { 539 int http_status_code) {
516 // Use an internal error page, if we have one for the status code. 540 // Use an internal error page, if we have one for the status code.
517 if (LocalizedError::HasStrings(LocalizedError::kHttpErrorDomain, 541 if (LocalizedError::HasStrings(LocalizedError::kHttpErrorDomain,
(...skipping 248 matching lines...) Expand 10 before | Expand all | Expand 10 after
766 if (spellcheck_.get()) 790 if (spellcheck_.get())
767 thread->RemoveObserver(spellcheck_.get()); 791 thread->RemoveObserver(spellcheck_.get());
768 SpellCheck* new_spellcheck = new SpellCheck(); 792 SpellCheck* new_spellcheck = new SpellCheck();
769 if (spellcheck_provider_) 793 if (spellcheck_provider_)
770 spellcheck_provider_->SetSpellCheck(new_spellcheck); 794 spellcheck_provider_->SetSpellCheck(new_spellcheck);
771 spellcheck_.reset(new_spellcheck); 795 spellcheck_.reset(new_spellcheck);
772 thread->AddObserver(new_spellcheck); 796 thread->AddObserver(new_spellcheck);
773 } 797 }
774 798
775 } // namespace chrome 799 } // namespace chrome
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698