Commit f5478b31 authored by bauerb@chromium.org's avatar bauerb@chromium.org

Clean up plug-in placeholders:

* Add separate class for missing plug-in placeholder, and factor out a common base class
* Move plug-in related classes to plugins/ subdirectory
* Move custom menu command IDs to a separate header file.

TBR=darin@chromium.org
BUG=62079
TEST=none

Review URL: http://codereview.chromium.org/8461011

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@111589 0039d316-1c4b-4281-b951-d872f2087c98
parent 8ba31633
...@@ -109,8 +109,6 @@ ...@@ -109,8 +109,6 @@
'renderer/resources/extensions/schema_generated_bindings.js', 'renderer/resources/extensions/schema_generated_bindings.js',
'renderer/about_handler.cc', 'renderer/about_handler.cc',
'renderer/about_handler.h', 'renderer/about_handler.h',
'renderer/blocked_plugin.cc',
'renderer/blocked_plugin.h',
'renderer/chrome_content_renderer_client.cc', 'renderer/chrome_content_renderer_client.cc',
'renderer/chrome_content_renderer_client.h', 'renderer/chrome_content_renderer_client.h',
'renderer/chrome_ppapi_interfaces.cc', 'renderer/chrome_ppapi_interfaces.cc',
...@@ -123,6 +121,7 @@ ...@@ -123,6 +121,7 @@
'renderer/chrome_render_view_observer.h', 'renderer/chrome_render_view_observer.h',
'renderer/content_settings_observer.cc', 'renderer/content_settings_observer.cc',
'renderer/content_settings_observer.h', 'renderer/content_settings_observer.h',
'renderer/custom_menu_commands.h',
'renderer/external_host_bindings.cc', 'renderer/external_host_bindings.cc',
'renderer/external_host_bindings.h', 'renderer/external_host_bindings.h',
'renderer/external_extension.cc', 'renderer/external_extension.cc',
...@@ -134,8 +133,14 @@ ...@@ -134,8 +133,14 @@
'renderer/page_click_tracker.h', 'renderer/page_click_tracker.h',
'renderer/page_load_histograms.cc', 'renderer/page_load_histograms.cc',
'renderer/page_load_histograms.h', 'renderer/page_load_histograms.h',
'renderer/plugin_uma.cc', 'renderer/plugins/blocked_plugin.cc',
'renderer/plugin_uma.h', 'renderer/plugins/blocked_plugin.h',
'renderer/plugins/missing_plugin.cc',
'renderer/plugins/missing_plugin.h',
'renderer/plugins/plugin_placeholder.cc',
'renderer/plugins/plugin_placeholder.h',
'renderer/plugins/plugin_uma.cc',
'renderer/plugins/plugin_uma.h',
'renderer/prerender/prerender_helper.cc', 'renderer/prerender/prerender_helper.cc',
'renderer/prerender/prerender_helper.h', 'renderer/prerender/prerender_helper.h',
'renderer/print_web_view_helper.cc', 'renderer/print_web_view_helper.cc',
......
...@@ -1978,7 +1978,7 @@ ...@@ -1978,7 +1978,7 @@
'renderer/extensions/json_schema_unittest.cc', 'renderer/extensions/json_schema_unittest.cc',
'renderer/net/predictor_queue_unittest.cc', 'renderer/net/predictor_queue_unittest.cc',
'renderer/net/renderer_predictor_unittest.cc', 'renderer/net/renderer_predictor_unittest.cc',
'renderer/plugin_uma_unittest.cc', 'renderer/plugins/plugin_uma_unittest.cc',
'renderer/renderer_about_handler_unittest.cc', 'renderer/renderer_about_handler_unittest.cc',
'renderer/safe_browsing/features_unittest.cc', 'renderer/safe_browsing/features_unittest.cc',
'renderer/safe_browsing/murmurhash3_util_unittest.cc', 'renderer/safe_browsing/murmurhash3_util_unittest.cc',
......
...@@ -28,7 +28,6 @@ ...@@ -28,7 +28,6 @@
#include "chrome/renderer/autofill/password_autofill_manager.h" #include "chrome/renderer/autofill/password_autofill_manager.h"
#include "chrome/renderer/automation/automation_renderer_helper.h" #include "chrome/renderer/automation/automation_renderer_helper.h"
#include "chrome/renderer/benchmarking_extension.h" #include "chrome/renderer/benchmarking_extension.h"
#include "chrome/renderer/blocked_plugin.h"
#include "chrome/renderer/chrome_ppapi_interfaces.h" #include "chrome/renderer/chrome_ppapi_interfaces.h"
#include "chrome/renderer/chrome_render_process_observer.h" #include "chrome/renderer/chrome_render_process_observer.h"
#include "chrome/renderer/chrome_render_view_observer.h" #include "chrome/renderer/chrome_render_view_observer.h"
...@@ -46,7 +45,9 @@ ...@@ -46,7 +45,9 @@
#include "chrome/renderer/net/renderer_net_predictor.h" #include "chrome/renderer/net/renderer_net_predictor.h"
#include "chrome/renderer/page_click_tracker.h" #include "chrome/renderer/page_click_tracker.h"
#include "chrome/renderer/page_load_histograms.h" #include "chrome/renderer/page_load_histograms.h"
#include "chrome/renderer/plugin_uma.h" #include "chrome/renderer/plugins/blocked_plugin.h"
#include "chrome/renderer/plugins/missing_plugin.h"
#include "chrome/renderer/plugins/plugin_uma.h"
#include "chrome/renderer/prerender/prerender_helper.h" #include "chrome/renderer/prerender/prerender_helper.h"
#include "chrome/renderer/print_web_view_helper.h" #include "chrome/renderer/print_web_view_helper.h"
#include "chrome/renderer/renderer_histogram_snapshots.h" #include "chrome/renderer/renderer_histogram_snapshots.h"
...@@ -290,9 +291,7 @@ WebPlugin* ChromeContentRendererClient::CreatePlugin( ...@@ -290,9 +291,7 @@ WebPlugin* ChromeContentRendererClient::CreatePlugin(
if (status.value == ChromeViewHostMsg_GetPluginInfo_Status::kNotFound) { if (status.value == ChromeViewHostMsg_GetPluginInfo_Status::kNotFound) {
MissingPluginReporter::GetInstance()->ReportPluginMissing( MissingPluginReporter::GetInstance()->ReportPluginMissing(
orig_mime_type, url); orig_mime_type, url);
return CreatePluginPlaceholder( return MissingPlugin::Create(render_view, frame, original_params);
render_view, frame, plugin, original_params, NULL,
IDR_BLOCKED_PLUGIN_HTML, IDS_PLUGIN_NOT_FOUND, false, false);
} }
if (plugin.path.value() == webkit::npapi::kDefaultPluginLibraryName) { if (plugin.path.value() == webkit::npapi::kDefaultPluginLibraryName) {
MissingPluginReporter::GetInstance()->ReportPluginMissing( MissingPluginReporter::GetInstance()->ReportPluginMissing(
...@@ -303,8 +302,8 @@ WebPlugin* ChromeContentRendererClient::CreatePlugin( ...@@ -303,8 +302,8 @@ WebPlugin* ChromeContentRendererClient::CreatePlugin(
webkit::npapi::PluginList::Singleton()->GetPluginGroup(plugin)); webkit::npapi::PluginList::Singleton()->GetPluginGroup(plugin));
if (status.value == ChromeViewHostMsg_GetPluginInfo_Status::kDisabled) { if (status.value == ChromeViewHostMsg_GetPluginInfo_Status::kDisabled) {
return CreatePluginPlaceholder( return BlockedPlugin::Create(
render_view, frame, plugin, original_params, group.get(), render_view, frame, original_params, plugin, group.get(),
IDR_DISABLED_PLUGIN_HTML, IDS_PLUGIN_DISABLED, false, false); IDR_DISABLED_PLUGIN_HTML, IDS_PLUGIN_DISABLED, false, false);
} }
...@@ -326,14 +325,14 @@ WebPlugin* ChromeContentRendererClient::CreatePlugin( ...@@ -326,14 +325,14 @@ WebPlugin* ChromeContentRendererClient::CreatePlugin(
GURL(group->GetUpdateURL()))); GURL(group->GetUpdateURL())));
} }
if (status.value == if (status.value ==
ChromeViewHostMsg_GetPluginInfo_Status::kOutdatedBlocked || ChromeViewHostMsg_GetPluginInfo_Status::kOutdatedBlocked ||
status.value == status.value ==
ChromeViewHostMsg_GetPluginInfo_Status::kOutdatedDisallowed) { ChromeViewHostMsg_GetPluginInfo_Status::kOutdatedDisallowed) {
return CreatePluginPlaceholder( return BlockedPlugin::Create(
render_view, frame, plugin, params, group.get(), render_view, frame, params, plugin, group.get(),
IDR_BLOCKED_PLUGIN_HTML, IDS_PLUGIN_OUTDATED, false, IDR_BLOCKED_PLUGIN_HTML, IDS_PLUGIN_OUTDATED, false,
status.value == status.value ==
ChromeViewHostMsg_GetPluginInfo_Status::kOutdatedBlocked); ChromeViewHostMsg_GetPluginInfo_Status::kOutdatedBlocked);
} }
ContentSettingsObserver* observer = ContentSettingsObserver::Get(render_view); ContentSettingsObserver* observer = ContentSettingsObserver::Get(render_view);
...@@ -343,8 +342,8 @@ WebPlugin* ChromeContentRendererClient::CreatePlugin( ...@@ -343,8 +342,8 @@ WebPlugin* ChromeContentRendererClient::CreatePlugin(
!observer->plugins_temporarily_allowed()) { !observer->plugins_temporarily_allowed()) {
render_view->Send(new ChromeViewHostMsg_BlockedOutdatedPlugin( render_view->Send(new ChromeViewHostMsg_BlockedOutdatedPlugin(
render_view->GetRoutingId(), group->GetGroupName(), GURL())); render_view->GetRoutingId(), group->GetGroupName(), GURL()));
return CreatePluginPlaceholder( return BlockedPlugin::Create(
render_view, frame, plugin, params, group.get(), render_view, frame, params, plugin, group.get(),
IDR_BLOCKED_PLUGIN_HTML, IDS_PLUGIN_NOT_AUTHORIZED, false, true); IDR_BLOCKED_PLUGIN_HTML, IDS_PLUGIN_NOT_AUTHORIZED, false, true);
} }
...@@ -355,8 +354,8 @@ WebPlugin* ChromeContentRendererClient::CreatePlugin( ...@@ -355,8 +354,8 @@ WebPlugin* ChromeContentRendererClient::CreatePlugin(
plugin.path.value() == webkit::npapi::kDefaultPluginLibraryName) { plugin.path.value() == webkit::npapi::kDefaultPluginLibraryName) {
// Delay loading plugins if prerendering. // Delay loading plugins if prerendering.
if (prerender::PrerenderHelper::IsPrerendering(render_view)) { if (prerender::PrerenderHelper::IsPrerendering(render_view)) {
return CreatePluginPlaceholder( return BlockedPlugin::Create(
render_view, frame, plugin, params, group.get(), render_view, frame, params, plugin, group.get(),
IDR_CLICK_TO_PLAY_PLUGIN_HTML, IDS_PLUGIN_LOAD, true, true); IDR_CLICK_TO_PLAY_PLUGIN_HTML, IDS_PLUGIN_LOAD, true, true);
} }
...@@ -381,8 +380,8 @@ WebPlugin* ChromeContentRendererClient::CreatePlugin( ...@@ -381,8 +380,8 @@ WebPlugin* ChromeContentRendererClient::CreatePlugin(
is_nacl_mime_type, is_nacl_mime_type,
is_nacl_enabled, is_nacl_enabled,
params)) { params)) {
return CreatePluginPlaceholder( return BlockedPlugin::Create(
render_view, frame, plugin, params, group.get(), render_view, frame, params, plugin, group.get(),
IDR_BLOCKED_PLUGIN_HTML, IDS_PLUGIN_BLOCKED, false, false); IDR_BLOCKED_PLUGIN_HTML, IDS_PLUGIN_BLOCKED, false, false);
} }
} }
...@@ -396,14 +395,14 @@ WebPlugin* ChromeContentRendererClient::CreatePlugin( ...@@ -396,14 +395,14 @@ WebPlugin* ChromeContentRendererClient::CreatePlugin(
group->identifier()); group->identifier());
if (status.value == ChromeViewHostMsg_GetPluginInfo_Status::kClickToPlay) { if (status.value == ChromeViewHostMsg_GetPluginInfo_Status::kClickToPlay) {
RenderThread::Get()->RecordUserMetrics("Plugin_ClickToPlay"); RenderThread::Get()->RecordUserMetrics("Plugin_ClickToPlay");
return CreatePluginPlaceholder( return BlockedPlugin::Create(
render_view, frame, plugin, params, group.get(), render_view, frame, params, plugin, group.get(),
IDR_CLICK_TO_PLAY_PLUGIN_HTML, IDS_PLUGIN_LOAD, false, true); IDR_CLICK_TO_PLAY_PLUGIN_HTML, IDS_PLUGIN_LOAD, false, true);
} else { } else {
DCHECK(status.value == ChromeViewHostMsg_GetPluginInfo_Status::kBlocked); DCHECK(status.value == ChromeViewHostMsg_GetPluginInfo_Status::kBlocked);
RenderThread::Get()->RecordUserMetrics("Plugin_Blocked"); RenderThread::Get()->RecordUserMetrics("Plugin_Blocked");
return CreatePluginPlaceholder( return BlockedPlugin::Create(
render_view, frame, plugin, params, group.get(), render_view, frame, params, plugin, group.get(),
IDR_BLOCKED_PLUGIN_HTML, IDS_PLUGIN_BLOCKED, false, true); IDR_BLOCKED_PLUGIN_HTML, IDS_PLUGIN_BLOCKED, false, true);
} }
} }
...@@ -489,41 +488,6 @@ bool ChromeContentRendererClient::IsNaClAllowed( ...@@ -489,41 +488,6 @@ bool ChromeContentRendererClient::IsNaClAllowed(
return true; return true;
} }
WebPlugin* ChromeContentRendererClient::CreatePluginPlaceholder(
content::RenderView* render_view,
WebFrame* frame,
const webkit::WebPluginInfo& plugin,
const WebPluginParams& params,
const webkit::npapi::PluginGroup* group,
int resource_id,
int message_id,
bool is_blocked_for_prerendering,
bool allow_loading) {
// |blocked_plugin| will delete itself when the WebViewPlugin
// is destroyed.
string16 name;
string16 message;
if (group) {
name = group->GetGroupName();
message = l10n_util::GetStringFUTF16(message_id, name);
} else {
message = l10n_util::GetStringUTF16(message_id);
}
BlockedPlugin* blocked_plugin =
new BlockedPlugin(render_view,
frame,
plugin,
params,
render_view->GetWebkitPreferences(),
resource_id,
name,
message,
is_blocked_for_prerendering,
allow_loading);
return blocked_plugin->plugin();
}
bool ChromeContentRendererClient::HasErrorPage(int http_status_code, bool ChromeContentRendererClient::HasErrorPage(int http_status_code,
std::string* error_domain) { std::string* error_domain) {
// Use an internal error page, if we have one for the status code. // Use an internal error page, if we have one for the status code.
......
...@@ -116,17 +116,6 @@ class ChromeContentRendererClient : public content::ContentRendererClient { ...@@ -116,17 +116,6 @@ class ChromeContentRendererClient : public content::ContentRendererClient {
WebKit::WebFrame* frame, WebKit::WebFrame* frame,
const WebKit::WebPluginParams& params); const WebKit::WebPluginParams& params);
WebKit::WebPlugin* CreatePluginPlaceholder(
content::RenderView* render_view,
WebKit::WebFrame* frame,
const webkit::WebPluginInfo& plugin,
const WebKit::WebPluginParams& params,
const webkit::npapi::PluginGroup* group,
int resource_id,
int message_id,
bool is_blocked_for_prerendering,
bool allow_loading);
// Returns the extension for the given URL. Excludes extension objects for // Returns the extension for the given URL. Excludes extension objects for
// bookmark apps, which do not use the app process model. // bookmark apps, which do not use the app process model.
const Extension* GetNonBookmarkAppExtension(const ExtensionSet* extensions, const Extension* GetNonBookmarkAppExtension(const ExtensionSet* extensions,
......
// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CHROME_RENDERER_CUSTOM_MENU_COMMANDS_H_
#define CHROME_RENDERER_CUSTOM_MENU_COMMANDS_H_
#pragma once
namespace chrome {
enum MenuCommands {
MENU_COMMAND_PLUGIN_RUN = 1,
MENU_COMMAND_PLUGIN_HIDE = 2,
};
} // namespace chrome
#endif // CHROME_RENDERER_CUSTOM_MENU_COMMANDS_H_
...@@ -2,41 +2,47 @@ ...@@ -2,41 +2,47 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
#ifndef CHROME_RENDERER_BLOCKED_PLUGIN_H_ #ifndef CHROME_RENDERER_PLUGINS_BLOCKED_PLUGIN_H_
#define CHROME_RENDERER_BLOCKED_PLUGIN_H_ #define CHROME_RENDERER_PLUGINS_BLOCKED_PLUGIN_H_
#pragma once #pragma once
#include "content/public/renderer/render_view_observer.h" #include "chrome/renderer/plugins/plugin_placeholder.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/WebPluginParams.h"
#include "webkit/glue/cpp_bound_class.h"
#include "webkit/plugins/npapi/webview_plugin.h"
#include "webkit/plugins/webplugininfo.h" #include "webkit/plugins/webplugininfo.h"
class BlockedPlugin : public content::RenderViewObserver, namespace webkit {
public CppBoundClass, namespace npapi {
public webkit::npapi::WebViewPlugin::Delegate { class PluginGroup;
}
}
class BlockedPlugin : public PluginPlaceholder {
public: public:
// Creates a new WebViewPlugin with a BlockedPlugin as a delegate.
static webkit::WebViewPlugin* Create(content::RenderView* render_view,
WebKit::WebFrame* frame,
const WebKit::WebPluginParams& params,
const webkit::WebPluginInfo& info,
const webkit::npapi::PluginGroup* group,
int resource_id,
int message_id,
bool is_blocked_for_prerendering,
bool allow_loading);
private:
BlockedPlugin(content::RenderView* render_view, BlockedPlugin(content::RenderView* render_view,
WebKit::WebFrame* frame, WebKit::WebFrame* frame,
const webkit::WebPluginInfo& info,
const WebKit::WebPluginParams& params, const WebKit::WebPluginParams& params,
const WebPreferences& settings, const std::string& html_data,
int template_id, const webkit::WebPluginInfo& info,
const string16& name, const string16& name,
const string16& message,
bool is_blocked_for_prerendering, bool is_blocked_for_prerendering,
bool allow_loading); bool allow_loading);
virtual ~BlockedPlugin();
webkit::npapi::WebViewPlugin* plugin() { return plugin_; }
// WebViewPlugin::Delegate methods: // WebViewPlugin::Delegate methods:
virtual void BindWebFrame(WebKit::WebFrame* frame) OVERRIDE; virtual void BindWebFrame(WebKit::WebFrame* frame) OVERRIDE;
virtual void WillDestroyPlugin() OVERRIDE;
virtual void ShowContextMenu(const WebKit::WebMouseEvent&) OVERRIDE; virtual void ShowContextMenu(const WebKit::WebMouseEvent&) OVERRIDE;
private:
virtual ~BlockedPlugin();
// RenderViewObserver methods: // RenderViewObserver methods:
virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE;
virtual void ContextMenuAction(unsigned id) OVERRIDE; virtual void ContextMenuAction(unsigned id) OVERRIDE;
...@@ -63,10 +69,7 @@ class BlockedPlugin : public content::RenderViewObserver, ...@@ -63,10 +69,7 @@ class BlockedPlugin : public content::RenderViewObserver,
// Hide the blocked plugin. // Hide the blocked plugin.
void HidePlugin(); void HidePlugin();
WebKit::WebFrame* frame_;
webkit::WebPluginInfo plugin_info_; webkit::WebPluginInfo plugin_info_;
WebKit::WebPluginParams plugin_params_;
webkit::npapi::WebViewPlugin* plugin_;
// The name of the plugin that was blocked. // The name of the plugin that was blocked.
string16 name_; string16 name_;
// True iff the plugin was blocked because the page was being prerendered. // True iff the plugin was blocked because the page was being prerendered.
...@@ -76,4 +79,4 @@ class BlockedPlugin : public content::RenderViewObserver, ...@@ -76,4 +79,4 @@ class BlockedPlugin : public content::RenderViewObserver,
bool allow_loading_; bool allow_loading_;
}; };
#endif // CHROME_RENDERER_BLOCKED_PLUGIN_H_ #endif // CHROME_RENDERER_PLUGINS_BLOCKED_PLUGIN_H_
// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/renderer/plugins/missing_plugin.h"
#include "base/string_piece.h"
#include "base/string_util.h"
#include "base/values.h"
#include "chrome/common/jstemplate_builder.h"
#include "chrome/renderer/custom_menu_commands.h"
#include "content/public/renderer/render_thread.h"
#include "content/public/renderer/render_view.h"
#include "grit/generated_resources.h"
#include "grit/renderer_resources.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/WebContextMenuData.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/WebInputEvent.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/WebMenuItemInfo.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/WebPoint.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/WebVector.h"
#include "ui/base/l10n/l10n_util.h"
#include "ui/base/resource/resource_bundle.h"
#include "webkit/plugins/npapi/plugin_group.h"
using WebKit::WebContextMenuData;
using WebKit::WebFrame;
using WebKit::WebMenuItemInfo;
using WebKit::WebPlugin;
using WebKit::WebPluginParams;
using WebKit::WebPoint;
using WebKit::WebString;
using WebKit::WebVector;
using content::RenderThread;
using webkit::WebViewPlugin;
namespace {
const MissingPlugin* g_last_active_menu = NULL;
}
// static
WebViewPlugin* MissingPlugin::Create(content::RenderView* render_view,
WebFrame* frame,
const WebPluginParams& params) {
const base::StringPiece template_html(
ResourceBundle::GetSharedInstance().GetRawDataResource(
IDR_BLOCKED_PLUGIN_HTML));
DictionaryValue values;
values.SetString("message", l10n_util::GetStringUTF8(IDS_PLUGIN_NOT_FOUND));
// "t" is the id of the templates root node.
std::string html_data =
jstemplate_builder::GetI18nTemplateHtml(template_html, &values);
// |missing_plugin| will destroy itself when its WebViewPlugin is going away.
MissingPlugin* missing_plugin = new MissingPlugin(render_view, frame, params,
html_data);
return missing_plugin->plugin();
}
MissingPlugin::MissingPlugin(content::RenderView* render_view,
WebFrame* frame,
const WebPluginParams& params,
const std::string& html_data)
: PluginPlaceholder(render_view, frame, params, html_data),
mime_type_(params.mimeType) {
}
MissingPlugin::~MissingPlugin() {
}
void MissingPlugin::BindWebFrame(WebFrame* frame) {
PluginPlaceholder::BindWebFrame(frame);
BindMethod("hide", &MissingPlugin::HideCallback);
}
void MissingPlugin::HideCallback(const CppArgumentList& args,
CppVariant* result) {
RenderThread::Get()->RecordUserMetrics("MissingPlugin_Hide_Click");
HidePluginInternal();
}
void MissingPlugin::ShowContextMenu(const WebKit::WebMouseEvent& event) {
WebContextMenuData menu_data;
WebVector<WebMenuItemInfo> custom_items(static_cast<size_t>(3));
size_t i = 0;
WebMenuItemInfo mime_type_item;
mime_type_item.label = mime_type_;
mime_type_item.hasTextDirectionOverride = false;
mime_type_item.textDirection = WebKit::WebTextDirectionDefault;
custom_items[i++] = mime_type_item;
WebMenuItemInfo separator_item;
separator_item.type = WebMenuItemInfo::Separator;
custom_items[i++] = separator_item;
WebMenuItemInfo hide_item;
hide_item.action = chrome::MENU_COMMAND_PLUGIN_HIDE;
hide_item.enabled = true;
hide_item.label = WebString::fromUTF8(
l10n_util::GetStringUTF8(IDS_CONTENT_CONTEXT_PLUGIN_HIDE).c_str());
hide_item.hasTextDirectionOverride = false;
hide_item.textDirection = WebKit::WebTextDirectionDefault;
custom_items[i++] = hide_item;
menu_data.customItems.swap(custom_items);
menu_data.mousePosition = WebPoint(event.windowX, event.windowY);
render_view()->ShowContextMenu(NULL, menu_data);
g_last_active_menu = this;
}
void MissingPlugin::ContextMenuAction(unsigned id) {
if (g_last_active_menu != this)
return;
if (id == chrome::MENU_COMMAND_PLUGIN_HIDE) {
RenderThread::Get()->RecordUserMetrics("MissingPlugin_Hide_Menu");
HidePluginInternal();
} else {
NOTREACHED();
}
}
// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CHROME_RENDERER_PLUGINS_MISSING_PLUGIN_H_
#define CHROME_RENDERER_PLUGINS_MISSING_PLUGIN_H_
#pragma once
#include "chrome/renderer/plugins/plugin_placeholder.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/WebString.h"
class MissingPlugin : public PluginPlaceholder {
public:
// Creates a new WebViewPlugin with a MissingPlugin as a delegate.
static webkit::WebViewPlugin* Create(
content::RenderView* render_view,
WebKit::WebFrame* frame,
const WebKit::WebPluginParams& params);
private:
MissingPlugin(content::RenderView* render_view,
WebKit::WebFrame* frame,
const WebKit::WebPluginParams& params,
const std::string& html_data);
virtual ~MissingPlugin();
// WebViewPlugin::Delegate methods:
virtual void BindWebFrame(WebKit::WebFrame* frame) OVERRIDE;
virtual void ShowContextMenu(const WebKit::WebMouseEvent&) OVERRIDE;
// content::RenderViewObserver methods:
virtual void ContextMenuAction(unsigned id) OVERRIDE;
void HideCallback(const CppArgumentList& args, CppVariant* result);
WebKit::WebString mime_type_;
DISALLOW_COPY_AND_ASSIGN(MissingPlugin);
};
#endif // CHROME_RENDERER_PLUGINS_MISSING_PLUGIN_H_
// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/renderer/plugins/plugin_placeholder.h"
#include "base/string_util.h"
#include "chrome/renderer/plugins/plugin_uma.h"
#include "content/public/renderer/render_view.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/WebData.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/WebDocument.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/WebElement.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/WebPluginContainer.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/WebRegularExpression.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/WebTextCaseSensitivity.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h"
using WebKit::WebElement;
using WebKit::WebFrame;
using WebKit::WebMouseEvent;
using WebKit::WebNode;
using WebKit::WebPlugin;
using WebKit::WebPluginContainer;
using WebKit::WebPluginParams;
using WebKit::WebRegularExpression;
using WebKit::WebString;
using webkit::WebPluginInfo;
using webkit::WebViewPlugin;
static const char* const kPluginPlaceholderDataURL =
"chrome://pluginplaceholderdata/";
PluginPlaceholder::PluginPlaceholder(content::RenderView* render_view,
WebFrame* frame,
const WebPluginParams& params,
const std::string& html_data)
: content::RenderViewObserver(render_view),
frame_(frame),
plugin_params_(params),
plugin_(WebViewPlugin::Create(
this, render_view->GetWebkitPreferences(), html_data,
GURL(kPluginPlaceholderDataURL))) {
}
PluginPlaceholder::~PluginPlaceholder() {
}
void PluginPlaceholder::BindWebFrame(WebFrame* frame) {
BindToJavascript(frame, "plugin");
}
void PluginPlaceholder::LoadPluginInternal(const WebPluginInfo& plugin_info) {
CHECK(plugin_);
WebPluginContainer* container = plugin_->container();
WebPlugin* new_plugin =
render_view()->CreatePlugin(frame_, plugin_info, plugin_params_);
if (new_plugin && new_plugin->initialize(container)) {
plugin_->RestoreTitleText();
container->setPlugin(new_plugin);
container->invalidate();
container->reportGeometry();
plugin_->ReplayReceivedData(new_plugin);
plugin_->destroy();
} else {
MissingPluginReporter::GetInstance()->ReportPluginMissing(
plugin_params_.mimeType.utf8(),
plugin_params_.url);
}
}
void PluginPlaceholder::HidePluginInternal() {
WebPluginContainer* container = plugin_->container();
WebElement element = container->element();
element.setAttribute("style", "display: none;");
// If we have a width and height, search for a parent (often <div>) with the
// same dimensions. If we find such a parent, hide that as well.
// This makes much more uncovered page content usable (including clickable)
// as opposed to merely visible.
// TODO(cevans) -- it's a foul heurisitc but we're going to tolerate it for
// now for these reasons:
// 1) Makes the user experience better.
// 2) Foulness is encapsulated within this single function.
// 3) Confidence in no fasle positives.
// 4) Seems to have a good / low false negative rate at this time.
if (element.hasAttribute("width") && element.hasAttribute("height")) {
std::string width_str("width:[\\s]*");
width_str += element.getAttribute("width").utf8().data();
if (EndsWith(width_str, "px", false)) {
width_str = width_str.substr(0, width_str.length() - 2);
}
TrimWhitespace(width_str, TRIM_TRAILING, &width_str);
width_str += "[\\s]*px";
WebRegularExpression width_regex(WebString::fromUTF8(width_str.c_str()),
WebKit::WebTextCaseSensitive);
std::string height_str("height:[\\s]*");
height_str += element.getAttribute("height").utf8().data();
if (EndsWith(height_str, "px", false)) {
height_str = height_str.substr(0, height_str.length() - 2);
}
TrimWhitespace(height_str, TRIM_TRAILING, &height_str);
height_str += "[\\s]*px";
WebRegularExpression height_regex(WebString::fromUTF8(height_str.c_str()),
WebKit::WebTextCaseSensitive);
WebNode parent = element;
while (!parent.parentNode().isNull()) {
parent = parent.parentNode();
if (!parent.isElementNode())
continue;
element = parent.toConst<WebElement>();
if (element.hasAttribute("style")) {
WebString style_str = element.getAttribute("style");
if (width_regex.match(style_str) >= 0 &&
height_regex.match(style_str) >= 0)
element.setAttribute("style", "display: none;");
}
}
}
}
void PluginPlaceholder::WillDestroyPlugin() {
delete this;
}
void PluginPlaceholder::ShowContextMenu(const WebMouseEvent& event) {
}
// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CHROME_RENDERER_PLUGINS_PLUGIN_PLACEHOLDER_H_
#define CHROME_RENDERER_PLUGINS_PLUGIN_PLACEHOLDER_H_
#pragma once
#include "content/public/renderer/render_view_observer.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/WebPluginParams.h"
#include "webkit/glue/cpp_bound_class.h"
#include "webkit/plugins/webview_plugin.h"
namespace webkit {
struct WebPluginInfo;
}
// Base class to share code between different plug-in placeholders
// used in Chrome. Placeholders can be used if a plug-in is missing or not
// available (blocked or disabled).
class PluginPlaceholder : public content::RenderViewObserver,
public CppBoundClass,
public webkit::WebViewPlugin::Delegate {
protected:
// |render_view| and |frame| are weak pointers. If either one is going away,
// our |plugin_| will be destroyed as well and will notify us.
PluginPlaceholder(content::RenderView* render_view,
WebKit::WebFrame* frame,
const WebKit::WebPluginParams& params,
const std::string& html_data);
virtual ~PluginPlaceholder();
webkit::WebViewPlugin* plugin() { return plugin_; }
WebKit::WebFrame* frame() { return frame_; }
// Can be called by a subclass to replace this placeholder with an actual
// plugin from |plugin_info|.
void LoadPluginInternal(const webkit::WebPluginInfo& plugin_info);
// WebViewPlugin::Delegate methods:
// Can be called by a subclass to hide this placeholder.
void HidePluginInternal();
virtual void BindWebFrame(WebKit::WebFrame* frame) OVERRIDE;
virtual void WillDestroyPlugin() OVERRIDE;
virtual void ShowContextMenu(const WebKit::WebMouseEvent& event) OVERRIDE;
private:
WebKit::WebFrame* frame_;
WebKit::WebPluginParams plugin_params_;
webkit::WebViewPlugin* plugin_;
DISALLOW_COPY_AND_ASSIGN(PluginPlaceholder);
};
#endif // CHROME_RENDERER_PLUGINS_PLUGIN_PLACEHOLDER_H_
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
#include "chrome/renderer/plugin_uma.h" #include "chrome/renderer/plugins/plugin_uma.h"
#include <algorithm> #include <algorithm>
#include <cstring> #include <cstring>
......
...@@ -2,8 +2,8 @@ ...@@ -2,8 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
#ifndef CHROME_RENDERER_PLUGIN_UMA_H_ #ifndef CHROME_RENDERER_PLUGINS_PLUGIN_UMA_H_
#define CHROME_RENDERER_PLUGIN_UMA_H_ #define CHROME_RENDERER_PLUGINS_PLUGIN_UMA_H_
#include <string> #include <string>
...@@ -66,5 +66,5 @@ class MissingPluginReporter { ...@@ -66,5 +66,5 @@ class MissingPluginReporter {
DISALLOW_COPY_AND_ASSIGN(MissingPluginReporter); DISALLOW_COPY_AND_ASSIGN(MissingPluginReporter);
}; };
#endif // CHROME_RENDERER_PLUGIN_UMA_H_ #endif // CHROME_RENDERER_PLUGINS_PLUGIN_UMA_H_
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
#include <gmock/gmock.h> #include <gmock/gmock.h>
#include <gtest/gtest.h> #include <gtest/gtest.h>
#include "chrome/renderer/plugin_uma.h" #include "chrome/renderer/plugins/plugin_uma.h"
using ::testing::_; using ::testing::_;
......
...@@ -147,12 +147,10 @@ ...@@ -147,12 +147,10 @@
#include "webkit/glue/weburlloader_impl.h" #include "webkit/glue/weburlloader_impl.h"
#include "webkit/media/video_renderer_impl.h" #include "webkit/media/video_renderer_impl.h"
#include "webkit/media/webmediaplayer_impl.h" #include "webkit/media/webmediaplayer_impl.h"
#include "webkit/plugins/npapi/default_plugin_shared.h"
#include "webkit/plugins/npapi/plugin_list.h" #include "webkit/plugins/npapi/plugin_list.h"
#include "webkit/plugins/npapi/webplugin_delegate.h" #include "webkit/plugins/npapi/webplugin_delegate.h"
#include "webkit/plugins/npapi/webplugin_delegate_impl.h" #include "webkit/plugins/npapi/webplugin_delegate_impl.h"
#include "webkit/plugins/npapi/webplugin_impl.h" #include "webkit/plugins/npapi/webplugin_impl.h"
#include "webkit/plugins/npapi/webview_plugin.h"
#include "webkit/plugins/ppapi/ppapi_webplugin_impl.h" #include "webkit/plugins/ppapi/ppapi_webplugin_impl.h"
#if defined(OS_WIN) #if defined(OS_WIN)
......
...@@ -190,8 +190,6 @@ ...@@ -190,8 +190,6 @@
'../plugins/npapi/webplugin_ime_win.h', '../plugins/npapi/webplugin_ime_win.h',
'../plugins/npapi/webplugin_impl.cc', '../plugins/npapi/webplugin_impl.cc',
'../plugins/npapi/webplugin_impl.h', '../plugins/npapi/webplugin_impl.h',
'../plugins/npapi/webview_plugin.cc',
'../plugins/npapi/webview_plugin.h',
'../plugins/plugin_constants.cc', '../plugins/plugin_constants.cc',
'../plugins/plugin_constants.h', '../plugins/plugin_constants.h',
'../plugins/plugin_switches.cc', '../plugins/plugin_switches.cc',
...@@ -325,6 +323,8 @@ ...@@ -325,6 +323,8 @@
'../plugins/sad_plugin.h', '../plugins/sad_plugin.h',
'../plugins/webplugininfo.cc', '../plugins/webplugininfo.cc',
'../plugins/webplugininfo.h', '../plugins/webplugininfo.h',
'../plugins/webview_plugin.cc',
'../plugins/webview_plugin.h',
'alt_error_page_resource_fetcher.cc', 'alt_error_page_resource_fetcher.cc',
'alt_error_page_resource_fetcher.h', 'alt_error_page_resource_fetcher.h',
'context_menu.cc', 'context_menu.cc',
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
#include "webkit/plugins/npapi/webview_plugin.h" #include "webkit/plugins/webview_plugin.h"
#include "base/message_loop.h" #include "base/message_loop.h"
#include "base/metrics/histogram.h" #include "base/metrics/histogram.h"
...@@ -45,7 +45,6 @@ using WebKit::WebVector; ...@@ -45,7 +45,6 @@ using WebKit::WebVector;
using WebKit::WebView; using WebKit::WebView;
namespace webkit { namespace webkit {
namespace npapi {
WebViewPlugin::WebViewPlugin(WebViewPlugin::Delegate* delegate) WebViewPlugin::WebViewPlugin(WebViewPlugin::Delegate* delegate)
: delegate_(delegate), : delegate_(delegate),
...@@ -250,5 +249,4 @@ void WebViewPlugin::didReceiveResponse(WebFrame* frame, ...@@ -250,5 +249,4 @@ void WebViewPlugin::didReceiveResponse(WebFrame* frame,
WebFrameClient::didReceiveResponse(frame, identifier, response); WebFrameClient::didReceiveResponse(frame, identifier, response);
} }
} // namespace npapi
} // namespace webkit } // namespace webkit
...@@ -2,8 +2,8 @@ ...@@ -2,8 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
#ifndef WEBKIT_PLUGINS_NPAPI_WEBVIEW_PLUGIN_H_ #ifndef WEBKIT_PLUGINS_WEBVIEW_PLUGIN_H_
#define WEBKIT_PLUGINS_NPAPI_WEBVIEW_PLUGIN_H_ #define WEBKIT_PLUGINS_WEBVIEW_PLUGIN_H_
#include <list> #include <list>
...@@ -13,7 +13,6 @@ ...@@ -13,7 +13,6 @@
#include "third_party/WebKit/Source/WebKit/chromium/public/WebFrameClient.h" #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrameClient.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/WebPlugin.h" #include "third_party/WebKit/Source/WebKit/chromium/public/WebPlugin.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/WebString.h" #include "third_party/WebKit/Source/WebKit/chromium/public/WebString.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/WebTextDirection.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/WebURLResponse.h" #include "third_party/WebKit/Source/WebKit/chromium/public/WebURLResponse.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/WebViewClient.h" #include "third_party/WebKit/Source/WebKit/chromium/public/WebViewClient.h"
...@@ -23,7 +22,6 @@ class WebMouseEvent; ...@@ -23,7 +22,6 @@ class WebMouseEvent;
struct WebPreferences; struct WebPreferences;
namespace webkit { namespace webkit {
namespace npapi {
// This class implements the WebPlugin interface by forwarding drawing and // This class implements the WebPlugin interface by forwarding drawing and
// handling input events to a WebView. // handling input events to a WebView.
...@@ -141,8 +139,11 @@ class WebViewPlugin: public WebKit::WebPlugin, public WebKit::WebViewClient, ...@@ -141,8 +139,11 @@ class WebViewPlugin: public WebKit::WebPlugin, public WebKit::WebViewClient,
virtual ~WebViewPlugin(); virtual ~WebViewPlugin();
Delegate* delegate_; Delegate* delegate_;
// Destroys itself.
WebKit::WebCursorInfo current_cursor_; WebKit::WebCursorInfo current_cursor_;
// Owns us.
WebKit::WebPluginContainer* container_; WebKit::WebPluginContainer* container_;
// Owned by us, deleted via |close()|.
WebKit::WebView* web_view_; WebKit::WebView* web_view_;
gfx::Rect rect_; gfx::Rect rect_;
...@@ -153,7 +154,6 @@ class WebViewPlugin: public WebKit::WebPlugin, public WebKit::WebViewClient, ...@@ -153,7 +154,6 @@ class WebViewPlugin: public WebKit::WebPlugin, public WebKit::WebViewClient,
WebKit::WebString old_title_; WebKit::WebString old_title_;
}; };
} // namespace npapi
} // namespace webkit } // namespace webkit
#endif // WEBKIT_PLUGINS_NPAPI_WEBVIEW_PLUGIN_H_ #endif // WEBKIT_PLUGINS_WEBVIEW_PLUGIN_H_
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment