OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/plugins/plugin_placeholder.h" | 5 #include "chrome/renderer/plugins/plugin_placeholder.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
9 #include "base/json/string_escape.h" | 9 #include "base/json/string_escape.h" |
10 #include "base/string_piece.h" | 10 #include "base/string_piece.h" |
11 #include "base/string_util.h" | 11 #include "base/string_util.h" |
12 #include "base/utf_string_conversions.h" | 12 #include "base/utf_string_conversions.h" |
13 #include "base/values.h" | 13 #include "base/values.h" |
14 #include "chrome/common/jstemplate_builder.h" | 14 #include "chrome/common/jstemplate_builder.h" |
| 15 #include "chrome/common/prerender_messages.h" |
15 #include "chrome/common/render_messages.h" | 16 #include "chrome/common/render_messages.h" |
16 #include "chrome/common/prerender_messages.h" | |
17 #include "chrome/renderer/chrome_content_renderer_client.h" | 17 #include "chrome/renderer/chrome_content_renderer_client.h" |
18 #include "chrome/renderer/custom_menu_commands.h" | 18 #include "chrome/renderer/custom_menu_commands.h" |
19 #include "chrome/renderer/plugins/plugin_uma.h" | 19 #include "chrome/renderer/plugins/plugin_uma.h" |
20 #include "content/public/renderer/render_thread.h" | 20 #include "content/public/renderer/render_thread.h" |
21 #include "content/public/renderer/render_view.h" | 21 #include "content/public/renderer/render_view.h" |
22 #include "grit/generated_resources.h" | 22 #include "grit/generated_resources.h" |
23 #include "grit/renderer_resources.h" | 23 #include "grit/renderer_resources.h" |
24 #include "grit/webkit_strings.h" | 24 #include "grit/webkit_strings.h" |
25 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebData.h" | |
26 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebPoint.h" | |
27 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebVector.h" | |
28 #include "third_party/WebKit/Source/WebKit/chromium/public/WebContextMenuData.h" | 25 #include "third_party/WebKit/Source/WebKit/chromium/public/WebContextMenuData.h" |
29 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDocument.h" | 26 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDocument.h" |
30 #include "third_party/WebKit/Source/WebKit/chromium/public/WebElement.h" | 27 #include "third_party/WebKit/Source/WebKit/chromium/public/WebElement.h" |
31 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" | 28 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" |
32 #include "third_party/WebKit/Source/WebKit/chromium/public/WebInputEvent.h" | 29 #include "third_party/WebKit/Source/WebKit/chromium/public/WebInputEvent.h" |
33 #include "third_party/WebKit/Source/WebKit/chromium/public/WebMenuItemInfo.h" | 30 #include "third_party/WebKit/Source/WebKit/chromium/public/WebMenuItemInfo.h" |
34 #include "third_party/WebKit/Source/WebKit/chromium/public/WebPluginContainer.h" | 31 #include "third_party/WebKit/Source/WebKit/chromium/public/WebPluginContainer.h" |
35 #include "third_party/WebKit/Source/WebKit/chromium/public/WebRegularExpression.
h" | 32 #include "third_party/WebKit/Source/WebKit/chromium/public/WebRegularExpression.
h" |
36 #include "third_party/WebKit/Source/WebKit/chromium/public/WebScriptSource.h" | 33 #include "third_party/WebKit/Source/WebKit/chromium/public/WebScriptSource.h" |
37 #include "third_party/WebKit/Source/WebKit/chromium/public/WebTextCaseSensitivit
y.h" | 34 #include "third_party/WebKit/Source/WebKit/chromium/public/WebTextCaseSensitivit
y.h" |
38 #include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h" | 35 #include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h" |
| 36 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebData.h" |
| 37 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebPoint.h" |
| 38 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebVector.h" |
39 #include "ui/base/l10n/l10n_util.h" | 39 #include "ui/base/l10n/l10n_util.h" |
| 40 #include "ui/base/layout.h" |
40 #include "ui/base/resource/resource_bundle.h" | 41 #include "ui/base/resource/resource_bundle.h" |
41 #include "webkit/glue/webpreferences.h" | 42 #include "webkit/glue/webpreferences.h" |
42 #include "webkit/plugins/npapi/plugin_group.h" | 43 #include "webkit/plugins/npapi/plugin_group.h" |
43 #include "webkit/plugins/npapi/plugin_list.h" | 44 #include "webkit/plugins/npapi/plugin_list.h" |
44 #include "webkit/plugins/webview_plugin.h" | 45 #include "webkit/plugins/webview_plugin.h" |
45 | 46 |
46 using content::RenderThread; | 47 using content::RenderThread; |
47 using content::RenderView; | 48 using content::RenderView; |
48 using WebKit::WebContextMenuData; | 49 using WebKit::WebContextMenuData; |
49 using WebKit::WebDocument; | 50 using WebKit::WebDocument; |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
94 #endif | 95 #endif |
95 } | 96 } |
96 | 97 |
97 // static | 98 // static |
98 PluginPlaceholder* PluginPlaceholder::CreateMissingPlugin( | 99 PluginPlaceholder* PluginPlaceholder::CreateMissingPlugin( |
99 RenderView* render_view, | 100 RenderView* render_view, |
100 WebFrame* frame, | 101 WebFrame* frame, |
101 const WebPluginParams& params) { | 102 const WebPluginParams& params) { |
102 const base::StringPiece template_html( | 103 const base::StringPiece template_html( |
103 ResourceBundle::GetSharedInstance().GetRawDataResource( | 104 ResourceBundle::GetSharedInstance().GetRawDataResource( |
104 IDR_BLOCKED_PLUGIN_HTML)); | 105 IDR_BLOCKED_PLUGIN_HTML, ui::SCALE_FACTOR_NONE)); |
105 | 106 |
106 DictionaryValue values; | 107 DictionaryValue values; |
107 values.SetString("message", l10n_util::GetStringUTF8(IDS_PLUGIN_SEARCHING)); | 108 values.SetString("message", l10n_util::GetStringUTF8(IDS_PLUGIN_SEARCHING)); |
108 | 109 |
109 std::string html_data = | 110 std::string html_data = |
110 jstemplate_builder::GetI18nTemplateHtml(template_html, &values); | 111 jstemplate_builder::GetI18nTemplateHtml(template_html, &values); |
111 | 112 |
112 // |missing_plugin| will destroy itself when its WebViewPlugin is going away. | 113 // |missing_plugin| will destroy itself when its WebViewPlugin is going away. |
113 PluginPlaceholder* missing_plugin = new PluginPlaceholder( | 114 PluginPlaceholder* missing_plugin = new PluginPlaceholder( |
114 render_view, frame, params, html_data, params.mimeType); | 115 render_view, frame, params, html_data, params.mimeType); |
(...skipping 10 matching lines...) Expand all Loading... |
125 | 126 |
126 PluginPlaceholder* PluginPlaceholder::CreateErrorPlugin( | 127 PluginPlaceholder* PluginPlaceholder::CreateErrorPlugin( |
127 RenderView* render_view, | 128 RenderView* render_view, |
128 const FilePath& file_path) { | 129 const FilePath& file_path) { |
129 DictionaryValue values; | 130 DictionaryValue values; |
130 values.SetString("message", | 131 values.SetString("message", |
131 l10n_util::GetStringUTF8(IDS_PLUGIN_INITIALIZATION_ERROR)); | 132 l10n_util::GetStringUTF8(IDS_PLUGIN_INITIALIZATION_ERROR)); |
132 | 133 |
133 const base::StringPiece template_html( | 134 const base::StringPiece template_html( |
134 ResourceBundle::GetSharedInstance().GetRawDataResource( | 135 ResourceBundle::GetSharedInstance().GetRawDataResource( |
135 IDR_BLOCKED_PLUGIN_HTML)); | 136 IDR_BLOCKED_PLUGIN_HTML, ui::SCALE_FACTOR_NONE)); |
136 std::string html_data = | 137 std::string html_data = |
137 jstemplate_builder::GetI18nTemplateHtml(template_html, &values); | 138 jstemplate_builder::GetI18nTemplateHtml(template_html, &values); |
138 | 139 |
139 WebPluginParams params; | 140 WebPluginParams params; |
140 // |missing_plugin| will destroy itself when its WebViewPlugin is going away. | 141 // |missing_plugin| will destroy itself when its WebViewPlugin is going away. |
141 PluginPlaceholder* plugin = new PluginPlaceholder( | 142 PluginPlaceholder* plugin = new PluginPlaceholder( |
142 render_view, NULL, params, html_data, params.mimeType); | 143 render_view, NULL, params, html_data, params.mimeType); |
143 | 144 |
144 return plugin; | 145 return plugin; |
145 } | 146 } |
146 | 147 |
147 // static | 148 // static |
148 PluginPlaceholder* PluginPlaceholder::CreateBlockedPlugin( | 149 PluginPlaceholder* PluginPlaceholder::CreateBlockedPlugin( |
149 RenderView* render_view, | 150 RenderView* render_view, |
150 WebFrame* frame, | 151 WebFrame* frame, |
151 const WebPluginParams& params, | 152 const WebPluginParams& params, |
152 const WebPluginInfo& plugin, | 153 const WebPluginInfo& plugin, |
153 const std::string& identifier, | 154 const std::string& identifier, |
154 const string16& name, | 155 const string16& name, |
155 int template_id, | 156 int template_id, |
156 int message_id) { | 157 int message_id) { |
157 string16 message = l10n_util::GetStringFUTF16(message_id, name); | 158 string16 message = l10n_util::GetStringFUTF16(message_id, name); |
158 | 159 |
159 DictionaryValue values; | 160 DictionaryValue values; |
160 values.SetString("message", message); | 161 values.SetString("message", message); |
161 values.SetString("name", name); | 162 values.SetString("name", name); |
162 values.SetString("hide", l10n_util::GetStringUTF8(IDS_PLUGIN_HIDE)); | 163 values.SetString("hide", l10n_util::GetStringUTF8(IDS_PLUGIN_HIDE)); |
163 | 164 |
164 const base::StringPiece template_html( | 165 const base::StringPiece template_html( |
165 ResourceBundle::GetSharedInstance().GetRawDataResource(template_id)); | 166 ResourceBundle::GetSharedInstance().GetRawDataResource( |
| 167 template_id, ui::SCALE_FACTOR_NONE)); |
166 | 168 |
167 DCHECK(!template_html.empty()) << "unable to load template. ID: " | 169 DCHECK(!template_html.empty()) << "unable to load template. ID: " |
168 << template_id; | 170 << template_id; |
169 std::string html_data = jstemplate_builder::GetI18nTemplateHtml( | 171 std::string html_data = jstemplate_builder::GetI18nTemplateHtml( |
170 template_html, &values); | 172 template_html, &values); |
171 | 173 |
172 // |blocked_plugin| will destroy itself when its WebViewPlugin is going away. | 174 // |blocked_plugin| will destroy itself when its WebViewPlugin is going away. |
173 PluginPlaceholder* blocked_plugin = new PluginPlaceholder( | 175 PluginPlaceholder* blocked_plugin = new PluginPlaceholder( |
174 render_view, frame, params, html_data, name); | 176 render_view, frame, params, html_data, name); |
175 blocked_plugin->plugin_info_ = plugin; | 177 blocked_plugin->plugin_info_ = plugin; |
176 blocked_plugin->identifier_ = identifier; | 178 blocked_plugin->identifier_ = identifier; |
177 return blocked_plugin; | 179 return blocked_plugin; |
178 } | 180 } |
179 | 181 |
180 #if defined(ENABLE_MOBILE_YOUTUBE_PLUGIN) | 182 #if defined(ENABLE_MOBILE_YOUTUBE_PLUGIN) |
181 // static | 183 // static |
182 PluginPlaceholder* PluginPlaceholder::CreateMobileYoutubePlugin( | 184 PluginPlaceholder* PluginPlaceholder::CreateMobileYoutubePlugin( |
183 content::RenderView* render_view, | 185 content::RenderView* render_view, |
184 WebFrame* frame, | 186 WebFrame* frame, |
185 const WebPluginParams& params) { | 187 const WebPluginParams& params) { |
186 const base::StringPiece template_html( | 188 const base::StringPiece template_html( |
187 ResourceBundle::GetSharedInstance().GetRawDataResource( | 189 ResourceBundle::GetSharedInstance().GetRawDataResource( |
188 IDR_YOUTUBE_PLUGIN_HTML)); | 190 IDR_YOUTUBE_PLUGIN_HTML, ui::SCALE_FACTOR_NONE)); |
189 | 191 |
190 DictionaryValue values; | 192 DictionaryValue values; |
191 values.SetString("video_id", GetYoutubeVideoId(params)); | 193 values.SetString("video_id", GetYoutubeVideoId(params)); |
192 std::string html_data = jstemplate_builder::GetI18nTemplateHtml( | 194 std::string html_data = jstemplate_builder::GetI18nTemplateHtml( |
193 template_html, &values); | 195 template_html, &values); |
194 | 196 |
195 // |youtube_plugin| will destroy itself when its WebViewPlugin is going away. | 197 // |youtube_plugin| will destroy itself when its WebViewPlugin is going away. |
196 PluginPlaceholder* youtube_plugin = new PluginPlaceholder( | 198 PluginPlaceholder* youtube_plugin = new PluginPlaceholder( |
197 render_view, frame, params, html_data, params.mimeType); | 199 render_view, frame, params, html_data, params.mimeType); |
198 return youtube_plugin; | 200 return youtube_plugin; |
(...skipping 425 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
624 bool PluginPlaceholder::IsYouTubeURL(const GURL& url, | 626 bool PluginPlaceholder::IsYouTubeURL(const GURL& url, |
625 const std::string& mime_type) { | 627 const std::string& mime_type) { |
626 std::string host = url.host(); | 628 std::string host = url.host(); |
627 bool is_youtube = EndsWith(host, "youtube.com", true) || | 629 bool is_youtube = EndsWith(host, "youtube.com", true) || |
628 EndsWith(host, "youtube-nocookie.com", true); | 630 EndsWith(host, "youtube-nocookie.com", true); |
629 | 631 |
630 return is_youtube && IsValidYouTubeVideo(url.path()) && | 632 return is_youtube && IsValidYouTubeVideo(url.path()) && |
631 LowerCaseEqualsASCII(mime_type, "application/x-shockwave-flash"); | 633 LowerCaseEqualsASCII(mime_type, "application/x-shockwave-flash"); |
632 } | 634 } |
633 #endif | 635 #endif |
OLD | NEW |