diff options
author | jam@chromium.org <jam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-03-18 19:08:25 +0000 |
---|---|---|
committer | jam@chromium.org <jam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-03-18 19:08:25 +0000 |
commit | 21d61e5f00a2a709e6f7216525c3be4dc75b7029 (patch) | |
tree | 20f5c8972cf7c10433779dccdeedd16d7d1bfd17 | |
parent | a69e947d721537cba9a2e50e634d2432d0834d24 (diff) | |
download | chromium_src-21d61e5f00a2a709e6f7216525c3be4dc75b7029.zip chromium_src-21d61e5f00a2a709e6f7216525c3be4dc75b7029.tar.gz chromium_src-21d61e5f00a2a709e6f7216525c3be4dc75b7029.tar.bz2 |
Allow the embedder to try to create a plugin first. Also get the html error page from it. This removes the depenency on grd from RenderView, so that it can be moved to content. We want this change anyways in the future, although the API will probably change as we'll most likely have a RenderView wrapper of some sort.
TBR=avi
Review URL: http://codereview.chromium.org/6712033
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@78729 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | chrome/renderer/chrome_content_renderer_client.cc | 180 | ||||
-rw-r--r-- | chrome/renderer/chrome_content_renderer_client.h | 23 | ||||
-rw-r--r-- | chrome/renderer/render_view.cc | 183 | ||||
-rw-r--r-- | chrome/renderer/render_view.h | 19 | ||||
-rw-r--r-- | content/renderer/content_renderer_client.cc | 13 | ||||
-rw-r--r-- | content/renderer/content_renderer_client.h | 19 |
6 files changed, 252 insertions, 185 deletions
diff --git a/chrome/renderer/chrome_content_renderer_client.cc b/chrome/renderer/chrome_content_renderer_client.cc index a44cc58..10a1ccf 100644 --- a/chrome/renderer/chrome_content_renderer_client.cc +++ b/chrome/renderer/chrome_content_renderer_client.cc @@ -4,10 +4,37 @@ #include "chrome/renderer/chrome_content_renderer_client.h" +#include "base/command_line.h" +#include "base/values.h" +#include "chrome/common/chrome_switches.h" +#include "chrome/common/jstemplate_builder.h" +#include "chrome/common/render_messages.h" +#include "chrome/common/url_constants.h" +#include "chrome/renderer/blocked_plugin.h" +#include "chrome/renderer/localized_error.h" +#include "chrome/renderer/render_thread.h" +#include "chrome/renderer/render_view.h" +#include "grit/generated_resources.h" #include "grit/locale_settings.h" #include "grit/renderer_resources.h" +#include "net/base/net_errors.h" +#include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" +#include "third_party/WebKit/Source/WebKit/chromium/public/WebPluginParams.h" +#include "third_party/WebKit/Source/WebKit/chromium/public/WebURL.h" +#include "third_party/WebKit/Source/WebKit/chromium/public/WebURLError.h" +#include "third_party/WebKit/Source/WebKit/chromium/public/WebURLRequest.h" #include "ui/base/l10n/l10n_util.h" #include "ui/base/resource/resource_bundle.h" +#include "webkit/plugins/npapi/plugin_list.h" +#include "webkit/plugins/ppapi/plugin_module.h" + +using WebKit::WebFrame; +using WebKit::WebPlugin; +using WebKit::WebPluginParams; +using WebKit::WebString; +using WebKit::WebURLError; +using WebKit::WebURLRequest; +using WebKit::WebURLResponse; namespace chrome { @@ -18,4 +45,157 @@ SkBitmap* ChromeContentRendererClient::GetSadPluginBitmap() { std::string ChromeContentRendererClient::GetDefaultEncoding() { return l10n_util::GetStringUTF8(IDS_DEFAULT_ENCODING); } + +WebPlugin* ChromeContentRendererClient::CreatePlugin( + RenderView* render_view, + WebFrame* frame, + const WebPluginParams& params) { + bool found = false; + ContentSetting plugin_setting = CONTENT_SETTING_DEFAULT; + CommandLine* cmd = CommandLine::ForCurrentProcess(); + webkit::npapi::WebPluginInfo info; + GURL url(params.url); + std::string actual_mime_type; + render_view->Send(new ViewHostMsg_GetPluginInfo( + render_view->routing_id(), url, frame->top()->url(), + params.mimeType.utf8(), &found, &info, &plugin_setting, + &actual_mime_type)); + + if (!found) + return NULL; + DCHECK(plugin_setting != CONTENT_SETTING_DEFAULT); + if (!webkit::npapi::IsPluginEnabled(info)) + return NULL; + + const webkit::npapi::PluginGroup* group = + webkit::npapi::PluginList::Singleton()->GetPluginGroup(info); + DCHECK(group != NULL); + + if (group->IsVulnerable() && + !cmd->HasSwitch(switches::kAllowOutdatedPlugins)) { + render_view->Send(new ViewHostMsg_BlockedOutdatedPlugin( + render_view->routing_id(), group->GetGroupName(), + GURL(group->GetUpdateURL()))); + return CreatePluginPlaceholder( + render_view, frame, params, *group, IDR_BLOCKED_PLUGIN_HTML, + IDS_PLUGIN_OUTDATED, false); + } + + ContentSetting host_setting = render_view->current_content_settings_. + settings[CONTENT_SETTINGS_TYPE_PLUGINS]; + + if (group->RequiresAuthorization() && + !cmd->HasSwitch(switches::kAlwaysAuthorizePlugins) && + (plugin_setting == CONTENT_SETTING_ALLOW || + plugin_setting == CONTENT_SETTING_ASK) && + host_setting == CONTENT_SETTING_DEFAULT) { + render_view->Send(new ViewHostMsg_BlockedOutdatedPlugin( + render_view->routing_id(), group->GetGroupName(), GURL())); + return CreatePluginPlaceholder( + render_view, frame, params, *group, IDR_BLOCKED_PLUGIN_HTML, + IDS_PLUGIN_NOT_AUTHORIZED, false); + } + + if (info.path.value() == webkit::npapi::kDefaultPluginLibraryName || + plugin_setting == CONTENT_SETTING_ALLOW || + host_setting == CONTENT_SETTING_ALLOW) { + // Delay loading plugins if prerendering. + if (render_view->is_prerendering_) { + return CreatePluginPlaceholder( + render_view, frame, params, *group, IDR_CLICK_TO_PLAY_PLUGIN_HTML, + IDS_PLUGIN_LOAD, true); + } + + scoped_refptr<webkit::ppapi::PluginModule> pepper_module( + render_view->pepper_delegate_.CreatePepperPlugin(info.path)); + if (pepper_module) { + return render_view->CreatePepperPlugin( + frame, params, info.path, pepper_module.get()); + } + + return render_view->CreateNPAPIPlugin( + frame, params, info.path, actual_mime_type); + } + + std::string resource; + if (cmd->HasSwitch(switches::kEnableResourceContentSettings)) + resource = group->identifier(); + render_view->DidBlockContentType(CONTENT_SETTINGS_TYPE_PLUGINS, resource); + if (plugin_setting == CONTENT_SETTING_ASK) { + return CreatePluginPlaceholder( + render_view, frame, params, *group, IDR_CLICK_TO_PLAY_PLUGIN_HTML, + IDS_PLUGIN_LOAD, false); + } else { + return CreatePluginPlaceholder( + render_view, frame, params, *group, IDR_BLOCKED_PLUGIN_HTML, + IDS_PLUGIN_BLOCKED, false); + } +} + +WebPlugin* ChromeContentRendererClient::CreatePluginPlaceholder( + RenderView* render_view, + WebFrame* frame, + const WebPluginParams& params, + const webkit::npapi::PluginGroup& group, + int resource_id, + int message_id, + bool is_blocked_for_prerendering) { + // |blocked_plugin| will delete itself when the WebViewPlugin + // is destroyed. + BlockedPlugin* blocked_plugin = + new BlockedPlugin(render_view, + frame, + group, + params, + render_view->webkit_preferences(), + resource_id, + l10n_util::GetStringFUTF16(message_id, + group.GetGroupName()), + is_blocked_for_prerendering); + return blocked_plugin->plugin(); +} + +std::string ChromeContentRendererClient::GetNavigationErrorHtml( + const WebURLRequest& failed_request, + const WebURLError& error) { + GURL failed_url = error.unreachableURL; + std::string html; + const Extension* extension = NULL; + + // Use a local error page. + int resource_id; + DictionaryValue error_strings; + if (failed_url.is_valid() && !failed_url.SchemeIs(chrome::kExtensionScheme)) + extension = RenderThread::current()->GetExtensions()->GetByURL(failed_url); + if (extension) { + LocalizedError::GetAppErrorStrings(error, failed_url, extension, + &error_strings); + + // TODO(erikkay): Should we use a different template for different + // error messages? + resource_id = IDR_ERROR_APP_HTML; + } else { + if (error.domain == WebString::fromUTF8(net::kErrorDomain) && + error.reason == net::ERR_CACHE_MISS && + EqualsASCII(failed_request.httpMethod(), "POST")) { + LocalizedError::GetFormRepostStrings(failed_url, &error_strings); + } else { + LocalizedError::GetStrings(error, &error_strings); + } + resource_id = IDR_NET_ERROR_HTML; + } + + const base::StringPiece template_html( + ResourceBundle::GetSharedInstance().GetRawDataResource(resource_id)); + if (template_html.empty()) { + NOTREACHED() << "unable to load template. ID: " << resource_id; + } else { + // "t" is the id of the templates root node. + html = jstemplate_builder::GetTemplatesHtml( + template_html, &error_strings, "t"); + } + + return html; +} + } // namespace chrome diff --git a/chrome/renderer/chrome_content_renderer_client.h b/chrome/renderer/chrome_content_renderer_client.h index 9e3206a..81ec074 100644 --- a/chrome/renderer/chrome_content_renderer_client.h +++ b/chrome/renderer/chrome_content_renderer_client.h @@ -8,12 +8,35 @@ #include "content/renderer/content_renderer_client.h" +namespace webkit { +namespace npapi { +class PluginGroup; +} +} + namespace chrome { class ChromeContentRendererClient : public content::ContentRendererClient { public: virtual SkBitmap* GetSadPluginBitmap(); virtual std::string GetDefaultEncoding(); + virtual WebKit::WebPlugin* CreatePlugin( + RenderView* render_view, + WebKit::WebFrame* frame, + const WebKit::WebPluginParams& params); + virtual std::string GetNavigationErrorHtml( + const WebKit::WebURLRequest& failed_request, + const WebKit::WebURLError& error); + + private: + WebKit::WebPlugin* CreatePluginPlaceholder( + RenderView* render_view, + WebKit::WebFrame* frame, + const WebKit::WebPluginParams& params, + const webkit::npapi::PluginGroup& group, + int resource_id, + int message_id, + bool is_blocked_for_prerendering); }; } // namespace chrome diff --git a/chrome/renderer/render_view.cc b/chrome/renderer/render_view.cc index a1f408a..3ed2c34 100644 --- a/chrome/renderer/render_view.cc +++ b/chrome/renderer/render_view.cc @@ -32,7 +32,6 @@ #include "chrome/common/extensions/extension_constants.h" #include "chrome/common/extensions/extension_set.h" #include "chrome/common/json_value_serializer.h" -#include "chrome/common/jstemplate_builder.h" #include "chrome/common/pepper_plugin_registry.h" #include "chrome/common/render_messages.h" #include "chrome/common/render_messages_params.h" @@ -47,7 +46,6 @@ #include "chrome/renderer/autofill/form_manager.h" #include "chrome/renderer/autofill/password_autofill_manager.h" #include "chrome/renderer/automation/dom_automation_controller.h" -#include "chrome/renderer/blocked_plugin.h" #include "chrome/renderer/devtools_agent.h" #include "chrome/renderer/devtools_client.h" #include "chrome/renderer/extension_groups.h" @@ -85,6 +83,7 @@ #include "content/common/page_zoom.h" #include "content/common/pepper_messages.h" #include "content/renderer/audio_message_filter.h" +#include "content/renderer/content_renderer_client.h" #include "content/renderer/device_orientation_dispatcher.h" #include "content/renderer/geolocation_dispatcher.h" #include "content/renderer/ggl.h" @@ -105,8 +104,6 @@ #include "content/renderer/websharedworker_proxy.h" #include "content/renderer/webworker_proxy.h" #include "content/renderer/web_ui_bindings.h" -#include "grit/generated_resources.h" -#include "grit/renderer_resources.h" #include "media/base/filter_collection.h" #include "media/base/media_switches.h" #include "media/base/message_loop_factory_impl.h" @@ -166,9 +163,7 @@ #include "third_party/WebKit/Source/WebKit/chromium/public/WebWindowFeatures.h" #include "third_party/cld/encodings/compact_lang_det/win/cld_unicodetext.h" #include "third_party/skia/include/core/SkBitmap.h" -#include "ui/base/l10n/l10n_util.h" #include "ui/base/message_box_flags.h" -#include "ui/base/resource/resource_bundle.h" #include "ui/gfx/color_utils.h" #include "ui/gfx/favicon_size.h" #include "ui/gfx/native_widget_types.h" @@ -1892,42 +1887,12 @@ void RenderView::LoadNavigationErrorPage(WebFrame* frame, const WebURLError& error, const std::string& html, bool replace) { - GURL failed_url = error.unreachableURL; - std::string alt_html; - const Extension* extension = NULL; - if (html.empty()) { - // Use a local error page. - int resource_id; - DictionaryValue error_strings; - - if (failed_url.is_valid() && !failed_url.SchemeIs(chrome::kExtensionScheme)) - extension = render_thread_->GetExtensions()->GetByURL(failed_url); - if (extension) { - LocalizedError::GetAppErrorStrings(error, failed_url, extension, - &error_strings); - - // TODO(erikkay): Should we use a different template for different - // error messages? - resource_id = IDR_ERROR_APP_HTML; - } else { - if (error.domain == WebString::fromUTF8(net::kErrorDomain) && - error.reason == net::ERR_CACHE_MISS && - EqualsASCII(failed_request.httpMethod(), "POST")) { - LocalizedError::GetFormRepostStrings(failed_url, &error_strings); - } else { - LocalizedError::GetStrings(error, &error_strings); - } - resource_id = IDR_NET_ERROR_HTML; - } - - alt_html = GetAltHTMLForTemplate(error_strings, resource_id); - } else { - alt_html = html; - } - + std::string alt_html = !html.empty() ? html : + content::GetContentClient()->renderer()->GetNavigationErrorHtml( + failed_request, error); frame->loadHTMLString(alt_html, GURL(chrome::kUnreachableWebDataURL), - failed_url, + error.unreachableURL, replace); } @@ -2690,101 +2655,11 @@ void RenderView::runModal() { WebPlugin* RenderView::createPlugin(WebFrame* frame, const WebPluginParams& params) { - bool found = false; - ContentSetting plugin_setting = CONTENT_SETTING_DEFAULT; - CommandLine* cmd = CommandLine::ForCurrentProcess(); - webkit::npapi::WebPluginInfo info; - GURL url(params.url); - std::string actual_mime_type; - Send(new ViewHostMsg_GetPluginInfo(routing_id_, - url, - frame->top()->url(), - params.mimeType.utf8(), - &found, - &info, - &plugin_setting, - &actual_mime_type)); - - if (!found) - return NULL; - DCHECK(plugin_setting != CONTENT_SETTING_DEFAULT); - if (!webkit::npapi::IsPluginEnabled(info)) - return NULL; - - const webkit::npapi::PluginGroup* group = - webkit::npapi::PluginList::Singleton()->GetPluginGroup(info); - DCHECK(group != NULL); - - if (group->IsVulnerable() && - !cmd->HasSwitch(switches::kAllowOutdatedPlugins)) { - Send(new ViewHostMsg_BlockedOutdatedPlugin(routing_id_, - group->GetGroupName(), - GURL(group->GetUpdateURL()))); - return CreatePluginPlaceholder(frame, - params, - *group, - IDR_BLOCKED_PLUGIN_HTML, - IDS_PLUGIN_OUTDATED, - false); - } - - ContentSetting host_setting = - current_content_settings_.settings[CONTENT_SETTINGS_TYPE_PLUGINS]; - - if (group->RequiresAuthorization() && - !cmd->HasSwitch(switches::kAlwaysAuthorizePlugins) && - (plugin_setting == CONTENT_SETTING_ALLOW || - plugin_setting == CONTENT_SETTING_ASK) && - host_setting == CONTENT_SETTING_DEFAULT) { - Send(new ViewHostMsg_BlockedOutdatedPlugin(routing_id_, - group->GetGroupName(), - GURL())); - return CreatePluginPlaceholder(frame, - params, - *group, - IDR_BLOCKED_PLUGIN_HTML, - IDS_PLUGIN_NOT_AUTHORIZED, - false); - } - - if (info.path.value() == webkit::npapi::kDefaultPluginLibraryName || - plugin_setting == CONTENT_SETTING_ALLOW || - host_setting == CONTENT_SETTING_ALLOW) { - // Delay loading plugins if prerendering. - if (is_prerendering_) { - return CreatePluginPlaceholder(frame, - params, - *group, - IDR_CLICK_TO_PLAY_PLUGIN_HTML, - IDS_PLUGIN_LOAD, - true); - } - - scoped_refptr<webkit::ppapi::PluginModule> pepper_module( - pepper_delegate_.CreatePepperPlugin(info.path)); - if (pepper_module) - return CreatePepperPlugin(frame, params, info.path, pepper_module.get()); - return CreateNPAPIPlugin(frame, params, info.path, actual_mime_type); - } - std::string resource; - if (cmd->HasSwitch(switches::kEnableResourceContentSettings)) - resource = group->identifier(); - DidBlockContentType(CONTENT_SETTINGS_TYPE_PLUGINS, resource); - if (plugin_setting == CONTENT_SETTING_ASK) { - return CreatePluginPlaceholder(frame, - params, - *group, - IDR_CLICK_TO_PLAY_PLUGIN_HTML, - IDS_PLUGIN_LOAD, - false); - } else { - return CreatePluginPlaceholder(frame, - params, - *group, - IDR_BLOCKED_PLUGIN_HTML, - IDS_PLUGIN_BLOCKED, - false); - } + WebPlugin* plugin = content::GetContentClient()->renderer()->CreatePlugin( + this, frame, params); + if (!plugin) + plugin = CreatePluginNoCheck(frame, params); + return plugin; } WebWorker* RenderView::createWorker(WebFrame* frame, WebWorkerClient* client) { @@ -4354,28 +4229,6 @@ WebPlugin* RenderView::CreateNPAPIPlugin( frame, params, path, mime_type, AsWeakPtr()); } -WebPlugin* RenderView::CreatePluginPlaceholder( - WebFrame* frame, - const WebPluginParams& params, - const webkit::npapi::PluginGroup& group, - int resource_id, - int message_id, - bool is_blocked_for_prerendering) { - // |blocked_plugin| will delete itself when the WebViewPlugin - // is destroyed. - BlockedPlugin* blocked_plugin = - new BlockedPlugin(this, - frame, - group, - params, - webkit_preferences_, - resource_id, - l10n_util::GetStringFUTF16(message_id, - group.GetGroupName()), - is_blocked_for_prerendering); - return blocked_plugin->plugin(); -} - void RenderView::OnZoom(PageZoom::Function function) { if (!webview()) // Not sure if this can happen, but no harm in being safe. return; @@ -4956,22 +4809,6 @@ bool RenderView::MaybeLoadAlternateErrorPage(WebFrame* frame, return true; } -std::string RenderView::GetAltHTMLForTemplate( - const DictionaryValue& error_strings, int template_resource_id) const { - const base::StringPiece template_html( - ResourceBundle::GetSharedInstance().GetRawDataResource( - template_resource_id)); - - if (template_html.empty()) { - NOTREACHED() << "unable to load template. ID: " << template_resource_id; - return ""; - } - - // "t" is the id of the templates root node. - return jstemplate_builder::GetTemplatesHtml( - template_html, &error_strings, "t"); -} - void RenderView::AltErrorPageFinished(WebFrame* frame, const WebURLError& original_error, const std::string& html) { diff --git a/chrome/renderer/render_view.h b/chrome/renderer/render_view.h index 0b32c1c..f2327df 100644 --- a/chrome/renderer/render_view.h +++ b/chrome/renderer/render_view.h @@ -55,7 +55,6 @@ class AudioMessageFilter; class BlockedPlugin; -class DictionaryValue; class DeviceOrientationDispatcher; class DevToolsAgent; class DevToolsClient; @@ -99,6 +98,10 @@ namespace base { class WaitableEvent; } +namespace chrome { +class ChromeContentRendererClient; +} + namespace gfx { class Point; class Rect; @@ -657,6 +660,9 @@ class RenderView : public RenderWidget, virtual void OnWasRestored(bool needs_repainting); private: + // TODO(jam): temporary friend class to ease with the file move. Remove soon. + friend class chrome::ChromeContentRendererClient; + // For unit tests. friend class ExternalPopupMenuTest; friend class PepperDeviceTest; @@ -964,14 +970,6 @@ class RenderView : public RenderWidget, const FilePath& path, webkit::ppapi::PluginModule* pepper_module); - WebKit::WebPlugin* CreatePluginPlaceholder( - WebKit::WebFrame* frame, - const WebKit::WebPluginParams& params, - const webkit::npapi::PluginGroup& group, - int resource_id, - int message_id, - bool is_blocked_for_prerendering); - // Sends an IPC notification that the specified content type was blocked. // If the content type requires it, |resource_identifier| names the specific // resource that was blocked (the plugin path in the case of plugins), @@ -1017,9 +1015,6 @@ class RenderView : public RenderWidget, GURL GetAlternateErrorPageURL(const GURL& failed_url, ErrorPageType error_type); - std::string GetAltHTMLForTemplate(const DictionaryValue& error_strings, - int template_resource_id) const; - // Locates a sub frame with given xpath WebKit::WebFrame* GetChildFrame(const std::wstring& frame_xpath) const; diff --git a/content/renderer/content_renderer_client.cc b/content/renderer/content_renderer_client.cc index a247b3c..61ec4ce 100644 --- a/content/renderer/content_renderer_client.cc +++ b/content/renderer/content_renderer_client.cc @@ -14,4 +14,17 @@ std::string ContentRendererClient::GetDefaultEncoding() { return std::string(); } +WebKit::WebPlugin* ContentRendererClient::CreatePlugin( + RenderView* render_view, + WebKit::WebFrame* frame, + const WebKit::WebPluginParams& params) { + return NULL; +} + +std::string ContentRendererClient::GetNavigationErrorHtml( + const WebKit::WebURLRequest& failed_request, + const WebKit::WebURLError& error) { + return std::string(); +} + } // namespace content diff --git a/content/renderer/content_renderer_client.h b/content/renderer/content_renderer_client.h index dac0af8..2950026 100644 --- a/content/renderer/content_renderer_client.h +++ b/content/renderer/content_renderer_client.h @@ -10,8 +10,17 @@ #include "content/common/content_client.h" +class RenderView; class SkBitmap; +namespace WebKit { +class WebFrame; +class WebPlugin; +class WebURLRequest; +struct WebPluginParams; +struct WebURLError; +} + namespace content { // Embedder API for participating in renderer logic. @@ -19,6 +28,16 @@ class ContentRendererClient { public: virtual SkBitmap* GetSadPluginBitmap(); virtual std::string GetDefaultEncoding(); + // Create a plugin in the given frame. Can return NULL, in which case + // RenderView will create a plugin itself. + virtual WebKit::WebPlugin* CreatePlugin( + RenderView* render_view, + WebKit::WebFrame* frame, + const WebKit::WebPluginParams& params); + // Returns the html to display when a navigation error occurs. + virtual std::string GetNavigationErrorHtml( + const WebKit::WebURLRequest& failed_request, + const WebKit::WebURLError& error); }; } // namespace content |