tommycli | 425d6965 | 2015-06-11 22:20:14 | [diff] [blame] | 1 | // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #include "chrome/renderer/plugins/non_loadable_plugin_placeholder.h" |
| 6 | |
| 7 | #include "base/files/file_path.h" |
| 8 | #include "base/values.h" |
Nicholas Verne | 1e3c25bfd | 2017-09-07 04:24:29 | [diff] [blame] | 9 | #include "chrome/common/plugin.mojom.h" |
tommycli | 425d6965 | 2015-06-11 22:20:14 | [diff] [blame] | 10 | #include "chrome/grit/renderer_resources.h" |
| 11 | #include "components/plugins/renderer/plugin_placeholder.h" |
sdefresne | 6c550eed | 2016-02-17 18:45:47 | [diff] [blame] | 12 | #include "components/strings/grit/components_strings.h" |
tommycli | 425d6965 | 2015-06-11 22:20:14 | [diff] [blame] | 13 | #include "content/app/strings/grit/content_strings.h" |
Nicholas Verne | 1e3c25bfd | 2017-09-07 04:24:29 | [diff] [blame] | 14 | #include "content/public/renderer/render_frame.h" |
Blink Reformat | a30d423 | 2018-04-07 15:31:06 | [diff] [blame] | 15 | #include "third_party/blink/public/common/associated_interfaces/associated_interface_provider.h" |
tommycli | 425d6965 | 2015-06-11 22:20:14 | [diff] [blame] | 16 | #include "ui/base/l10n/l10n_util.h" |
| 17 | #include "ui/base/resource/resource_bundle.h" |
| 18 | #include "ui/base/webui/jstemplate_builder.h" |
| 19 | |
| 20 | // static |
| 21 | plugins::PluginPlaceholder* |
| 22 | NonLoadablePluginPlaceholder::CreateNotSupportedPlugin( |
| 23 | content::RenderFrame* render_frame, |
tommycli | 425d6965 | 2015-06-11 22:20:14 | [diff] [blame] | 24 | const blink::WebPluginParams& params) { |
| 25 | const base::StringPiece template_html( |
Lei Zhang | 7640d54 | 2017-10-03 16:26:49 | [diff] [blame] | 26 | ui::ResourceBundle::GetSharedInstance().GetRawDataResource( |
tommycli | 425d6965 | 2015-06-11 22:20:14 | [diff] [blame] | 27 | IDR_BLOCKED_PLUGIN_HTML)); |
| 28 | |
| 29 | base::DictionaryValue values; |
| 30 | values.SetString("message", |
| 31 | l10n_util::GetStringUTF8(IDS_PLUGIN_NOT_SUPPORTED)); |
| 32 | |
| 33 | std::string html_data = webui::GetI18nTemplateHtml(template_html, &values); |
| 34 | |
| 35 | // PluginPlaceholder will destroy itself when its WebViewPlugin is going away. |
thestig | f7d2fa1 | 2017-05-05 19:11:43 | [diff] [blame] | 36 | return new plugins::PluginPlaceholder(render_frame, params, html_data); |
tommycli | 425d6965 | 2015-06-11 22:20:14 | [diff] [blame] | 37 | } |
| 38 | |
| 39 | // static |
| 40 | plugins::PluginPlaceholder* NonLoadablePluginPlaceholder::CreateErrorPlugin( |
| 41 | content::RenderFrame* render_frame, |
| 42 | const base::FilePath& file_path) { |
| 43 | base::DictionaryValue values; |
| 44 | values.SetString("message", |
| 45 | l10n_util::GetStringUTF8(IDS_PLUGIN_INITIALIZATION_ERROR)); |
| 46 | |
| 47 | const base::StringPiece template_html( |
Lei Zhang | 7640d54 | 2017-10-03 16:26:49 | [diff] [blame] | 48 | ui::ResourceBundle::GetSharedInstance().GetRawDataResource( |
tommycli | 425d6965 | 2015-06-11 22:20:14 | [diff] [blame] | 49 | IDR_BLOCKED_PLUGIN_HTML)); |
| 50 | std::string html_data = webui::GetI18nTemplateHtml(template_html, &values); |
| 51 | |
| 52 | blink::WebPluginParams params; |
| 53 | // PluginPlaceholder will destroy itself when its WebViewPlugin is going away. |
| 54 | plugins::PluginPlaceholder* plugin = |
thestig | f7d2fa1 | 2017-05-05 19:11:43 | [diff] [blame] | 55 | new plugins::PluginPlaceholder(render_frame, params, html_data); |
tommycli | 425d6965 | 2015-06-11 22:20:14 | [diff] [blame] | 56 | |
Nicholas Verne | 1e3c25bfd | 2017-09-07 04:24:29 | [diff] [blame] | 57 | chrome::mojom::PluginHostAssociatedPtr plugin_host; |
| 58 | render_frame->GetRemoteAssociatedInterfaces()->GetInterface(&plugin_host); |
| 59 | plugin_host->CouldNotLoadPlugin(file_path); |
| 60 | |
tommycli | 425d6965 | 2015-06-11 22:20:14 | [diff] [blame] | 61 | return plugin; |
| 62 | } |