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

Side by Side Diff: chrome/renderer/plugins/chrome_plugin_placeholder.cc

Issue 2855123003: Remove rendundant WebLocalFrame parameter in various plugin code. (Closed)
Patch Set: Fix Android Created 3 years, 7 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
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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/chrome_plugin_placeholder.h" 5 #include "chrome/renderer/plugins/chrome_plugin_placeholder.h"
6 6
7 #include <memory> 7 #include <memory>
8 #include <utility> 8 #include <utility>
9 9
10 #include "base/command_line.h" 10 #include "base/command_line.h"
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
42 #include "ui/base/webui/jstemplate_builder.h" 42 #include "ui/base/webui/jstemplate_builder.h"
43 #include "ui/gfx/geometry/size.h" 43 #include "ui/gfx/geometry/size.h"
44 #include "url/origin.h" 44 #include "url/origin.h"
45 #include "url/url_util.h" 45 #include "url/url_util.h"
46 46
47 using base::UserMetricsAction; 47 using base::UserMetricsAction;
48 using content::RenderThread; 48 using content::RenderThread;
49 using content::RenderView; 49 using content::RenderView;
50 50
51 namespace { 51 namespace {
52 const ChromePluginPlaceholder* g_last_active_menu = NULL; 52 const ChromePluginPlaceholder* g_last_active_menu = nullptr;
53 } // namespace 53 } // namespace
54 54
55 gin::WrapperInfo ChromePluginPlaceholder::kWrapperInfo = { 55 gin::WrapperInfo ChromePluginPlaceholder::kWrapperInfo = {
56 gin::kEmbedderNativeGin}; 56 gin::kEmbedderNativeGin};
57 57
58 ChromePluginPlaceholder::ChromePluginPlaceholder( 58 ChromePluginPlaceholder::ChromePluginPlaceholder(
59 content::RenderFrame* render_frame, 59 content::RenderFrame* render_frame,
60 blink::WebLocalFrame* frame,
61 const blink::WebPluginParams& params, 60 const blink::WebPluginParams& params,
62 const std::string& html_data, 61 const std::string& html_data,
63 const base::string16& title) 62 const base::string16& title)
64 : plugins::LoadablePluginPlaceholder(render_frame, 63 : plugins::LoadablePluginPlaceholder(render_frame,
65 frame,
66 params, 64 params,
67 html_data), 65 html_data),
68 status_(ChromeViewHostMsg_GetPluginInfo_Status::kAllowed), 66 status_(ChromeViewHostMsg_GetPluginInfo_Status::kAllowed),
69 title_(title), 67 title_(title),
70 context_menu_request_id_(0), 68 context_menu_request_id_(0),
71 did_send_blocked_content_notification_(false) { 69 did_send_blocked_content_notification_(false) {
72 RenderThread::Get()->AddObserver(this); 70 RenderThread::Get()->AddObserver(this);
73 } 71 }
74 72
75 ChromePluginPlaceholder::~ChromePluginPlaceholder() { 73 ChromePluginPlaceholder::~ChromePluginPlaceholder() {
76 RenderThread::Get()->RemoveObserver(this); 74 RenderThread::Get()->RemoveObserver(this);
77 if (context_menu_request_id_ && render_frame()) 75 if (context_menu_request_id_ && render_frame())
78 render_frame()->CancelContextMenu(context_menu_request_id_); 76 render_frame()->CancelContextMenu(context_menu_request_id_);
79 77
80 if (placeholder_routing_id_ == MSG_ROUTING_NONE) 78 if (placeholder_routing_id_ == MSG_ROUTING_NONE)
81 return; 79 return;
82 RenderThread::Get()->RemoveRoute(placeholder_routing_id_); 80 RenderThread::Get()->RemoveRoute(placeholder_routing_id_);
83 } 81 }
84 82
85 // TODO(bauerb): Move this method to NonLoadablePluginPlaceholder? 83 // TODO(bauerb): Move this method to NonLoadablePluginPlaceholder?
86 // static 84 // static
87 ChromePluginPlaceholder* ChromePluginPlaceholder::CreateLoadableMissingPlugin( 85 ChromePluginPlaceholder* ChromePluginPlaceholder::CreateLoadableMissingPlugin(
88 content::RenderFrame* render_frame, 86 content::RenderFrame* render_frame,
89 blink::WebLocalFrame* frame,
90 const blink::WebPluginParams& params) { 87 const blink::WebPluginParams& params) {
91 const base::StringPiece template_html( 88 const base::StringPiece template_html(
92 ResourceBundle::GetSharedInstance().GetRawDataResource( 89 ResourceBundle::GetSharedInstance().GetRawDataResource(
93 IDR_BLOCKED_PLUGIN_HTML)); 90 IDR_BLOCKED_PLUGIN_HTML));
94 91
95 base::DictionaryValue values; 92 base::DictionaryValue values;
96 values.SetString("message", 93 values.SetString("message",
97 l10n_util::GetStringUTF8(IDS_PLUGIN_NOT_SUPPORTED)); 94 l10n_util::GetStringUTF8(IDS_PLUGIN_NOT_SUPPORTED));
98 95
99 std::string html_data = webui::GetI18nTemplateHtml(template_html, &values); 96 std::string html_data = webui::GetI18nTemplateHtml(template_html, &values);
100 97
101 // Will destroy itself when its WebViewPlugin is going away. 98 // Will destroy itself when its WebViewPlugin is going away.
102 return new ChromePluginPlaceholder(render_frame, frame, params, html_data, 99 return new ChromePluginPlaceholder(render_frame, params, html_data,
103 params.mime_type.Utf16()); 100 params.mime_type.Utf16());
104 } 101 }
105 102
106 // static 103 // static
107 ChromePluginPlaceholder* ChromePluginPlaceholder::CreateBlockedPlugin( 104 ChromePluginPlaceholder* ChromePluginPlaceholder::CreateBlockedPlugin(
108 content::RenderFrame* render_frame, 105 content::RenderFrame* render_frame,
109 blink::WebLocalFrame* frame,
110 const blink::WebPluginParams& params, 106 const blink::WebPluginParams& params,
111 const content::WebPluginInfo& info, 107 const content::WebPluginInfo& info,
112 const std::string& identifier, 108 const std::string& identifier,
113 const base::string16& name, 109 const base::string16& name,
114 int template_id, 110 int template_id,
115 const base::string16& message, 111 const base::string16& message,
116 const PowerSaverInfo& power_saver_info) { 112 const PowerSaverInfo& power_saver_info) {
117 base::DictionaryValue values; 113 base::DictionaryValue values;
118 values.SetString("message", message); 114 values.SetString("message", message);
119 values.SetString("name", name); 115 values.SetString("name", name);
120 values.SetString("hide", l10n_util::GetStringUTF8(IDS_PLUGIN_HIDE)); 116 values.SetString("hide", l10n_util::GetStringUTF8(IDS_PLUGIN_HIDE));
121 values.SetString( 117 values.SetString(
122 "pluginType", 118 "pluginType",
123 frame->View()->MainFrame()->IsWebLocalFrame() && 119 render_frame->IsMainFrame() &&
124 frame->View()->MainFrame()->GetDocument().IsPluginDocument() 120 render_frame->GetWebFrame()->GetDocument().IsPluginDocument()
125 ? "document" 121 ? "document"
126 : "embedded"); 122 : "embedded");
127 123
128 if (!power_saver_info.poster_attribute.empty()) { 124 if (!power_saver_info.poster_attribute.empty()) {
129 values.SetString("poster", power_saver_info.poster_attribute); 125 values.SetString("poster", power_saver_info.poster_attribute);
130 values.SetString("baseurl", power_saver_info.base_url.spec()); 126 values.SetString("baseurl", power_saver_info.base_url.spec());
131 127
132 if (!power_saver_info.custom_poster_size.IsEmpty()) { 128 if (!power_saver_info.custom_poster_size.IsEmpty()) {
133 float zoom_factor = 129 float zoom_factor = blink::WebView::ZoomLevelToZoomFactor(
134 blink::WebView::ZoomLevelToZoomFactor(frame->View()->ZoomLevel()); 130 render_frame->GetWebFrame()->View()->ZoomLevel());
135 int width = 131 int width =
136 roundf(power_saver_info.custom_poster_size.width() / zoom_factor); 132 roundf(power_saver_info.custom_poster_size.width() / zoom_factor);
137 int height = 133 int height =
138 roundf(power_saver_info.custom_poster_size.height() / zoom_factor); 134 roundf(power_saver_info.custom_poster_size.height() / zoom_factor);
139 values.SetString("visibleWidth", base::IntToString(width) + "px"); 135 values.SetString("visibleWidth", base::IntToString(width) + "px");
140 values.SetString("visibleHeight", base::IntToString(height) + "px"); 136 values.SetString("visibleHeight", base::IntToString(height) + "px");
141 } 137 }
142 } 138 }
143 139
144 const base::StringPiece template_html( 140 const base::StringPiece template_html(
145 ResourceBundle::GetSharedInstance().GetRawDataResource(template_id)); 141 ResourceBundle::GetSharedInstance().GetRawDataResource(template_id));
146 142
147 DCHECK(!template_html.empty()) << "unable to load template. ID: " 143 DCHECK(!template_html.empty()) << "unable to load template. ID: "
148 << template_id; 144 << template_id;
149 std::string html_data = webui::GetI18nTemplateHtml(template_html, &values); 145 std::string html_data = webui::GetI18nTemplateHtml(template_html, &values);
150 146
151 // |blocked_plugin| will destroy itself when its WebViewPlugin is going away. 147 // |blocked_plugin| will destroy itself when its WebViewPlugin is going away.
152 ChromePluginPlaceholder* blocked_plugin = new ChromePluginPlaceholder( 148 ChromePluginPlaceholder* blocked_plugin =
153 render_frame, frame, params, html_data, name); 149 new ChromePluginPlaceholder(render_frame, params, html_data, name);
154 150
155 if (!power_saver_info.poster_attribute.empty()) 151 if (!power_saver_info.poster_attribute.empty())
156 blocked_plugin->BlockForPowerSaverPoster(); 152 blocked_plugin->BlockForPowerSaverPoster();
157 blocked_plugin->SetPluginInfo(info); 153 blocked_plugin->SetPluginInfo(info);
158 blocked_plugin->SetIdentifier(identifier); 154 blocked_plugin->SetIdentifier(identifier);
159 155
160 blocked_plugin->set_power_saver_enabled(power_saver_info.power_saver_enabled); 156 blocked_plugin->set_power_saver_enabled(power_saver_info.power_saver_enabled);
161 blocked_plugin->set_blocked_for_background_tab( 157 blocked_plugin->set_blocked_for_background_tab(
162 power_saver_info.blocked_for_background_tab); 158 power_saver_info.blocked_for_background_tab);
163 159
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
223 SetMessage(l10n_util::GetStringFUTF16(IDS_PLUGIN_DOWNLOAD_ERROR_SHORT, 219 SetMessage(l10n_util::GetStringFUTF16(IDS_PLUGIN_DOWNLOAD_ERROR_SHORT,
224 plugin_name_)); 220 plugin_name_));
225 } 221 }
226 222
227 void ChromePluginPlaceholder::OnSetPrerenderMode( 223 void ChromePluginPlaceholder::OnSetPrerenderMode(
228 prerender::PrerenderMode mode) { 224 prerender::PrerenderMode mode) {
229 OnSetIsPrerendering(mode != prerender::NO_PRERENDER); 225 OnSetIsPrerendering(mode != prerender::NO_PRERENDER);
230 } 226 }
231 227
232 void ChromePluginPlaceholder::PluginListChanged() { 228 void ChromePluginPlaceholder::PluginListChanged() {
233 if (!GetFrame() || !plugin()) 229 if (!render_frame() || !plugin())
234 return; 230 return;
235 231
236 // Checking with GetFrame() is equivalent to checking render_frame().
237 DCHECK(render_frame());
238
239 ChromeViewHostMsg_GetPluginInfo_Output output; 232 ChromeViewHostMsg_GetPluginInfo_Output output;
240 std::string mime_type(GetPluginParams().mime_type.Utf8()); 233 std::string mime_type(GetPluginParams().mime_type.Utf8());
241 render_frame()->Send(new ChromeViewHostMsg_GetPluginInfo( 234 render_frame()->Send(new ChromeViewHostMsg_GetPluginInfo(
242 routing_id(), GURL(GetPluginParams().url), 235 routing_id(), GURL(GetPluginParams().url),
243 GetFrame()->Top()->GetSecurityOrigin(), mime_type, &output)); 236 render_frame()->GetWebFrame()->Top()->GetSecurityOrigin(), mime_type,
237 &output));
244 if (output.status == status_) 238 if (output.status == status_)
245 return; 239 return;
246 blink::WebPlugin* new_plugin = ChromeContentRendererClient::CreatePlugin( 240 blink::WebPlugin* new_plugin = ChromeContentRendererClient::CreatePlugin(
247 render_frame(), GetFrame(), GetPluginParams(), output); 241 render_frame(), GetPluginParams(), output);
248 ReplacePlugin(new_plugin); 242 ReplacePlugin(new_plugin);
249 if (!new_plugin) { 243 if (!new_plugin) {
250 PluginUMAReporter::GetInstance()->ReportPluginMissing( 244 PluginUMAReporter::GetInstance()->ReportPluginMissing(
251 GetPluginParams().mime_type.Utf8(), GURL(GetPluginParams().url)); 245 GetPluginParams().mime_type.Utf8(), GURL(GetPluginParams().url));
252 } 246 }
253 } 247 }
254 248
255 void ChromePluginPlaceholder::OnMenuAction(int request_id, unsigned action) { 249 void ChromePluginPlaceholder::OnMenuAction(int request_id, unsigned action) {
256 DCHECK_EQ(context_menu_request_id_, request_id); 250 DCHECK_EQ(context_menu_request_id_, request_id);
257 if (g_last_active_menu != this) 251 if (g_last_active_menu != this)
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
323 enable_flash_item.action = chrome::MENU_COMMAND_ENABLE_FLASH; 317 enable_flash_item.action = chrome::MENU_COMMAND_ENABLE_FLASH;
324 enable_flash_item.enabled = true; 318 enable_flash_item.enabled = true;
325 enable_flash_item.label = 319 enable_flash_item.label =
326 l10n_util::GetStringUTF16(IDS_CONTENT_CONTEXT_ENABLE_FLASH); 320 l10n_util::GetStringUTF16(IDS_CONTENT_CONTEXT_ENABLE_FLASH);
327 params.custom_items.push_back(enable_flash_item); 321 params.custom_items.push_back(enable_flash_item);
328 } 322 }
329 323
330 content::MenuItem hide_item; 324 content::MenuItem hide_item;
331 hide_item.action = chrome::MENU_COMMAND_PLUGIN_HIDE; 325 hide_item.action = chrome::MENU_COMMAND_PLUGIN_HIDE;
332 bool is_main_frame_plugin_document = 326 bool is_main_frame_plugin_document =
333 GetFrame()->View()->MainFrame()->IsWebLocalFrame() && 327 render_frame()->IsMainFrame() &&
334 GetFrame()->View()->MainFrame()->GetDocument().IsPluginDocument(); 328 render_frame()->GetWebFrame()->GetDocument().IsPluginDocument();
335 hide_item.enabled = !is_main_frame_plugin_document; 329 hide_item.enabled = !is_main_frame_plugin_document;
336 hide_item.label = l10n_util::GetStringUTF16(IDS_CONTENT_CONTEXT_PLUGIN_HIDE); 330 hide_item.label = l10n_util::GetStringUTF16(IDS_CONTENT_CONTEXT_PLUGIN_HIDE);
337 params.custom_items.push_back(hide_item); 331 params.custom_items.push_back(hide_item);
338 332
339 blink::WebPoint point(event.PositionInWidget().x, event.PositionInWidget().y); 333 blink::WebPoint point(event.PositionInWidget().x, event.PositionInWidget().y);
340 if (plugin() && plugin()->Container()) 334 if (plugin() && plugin()->Container())
341 point = plugin()->Container()->LocalToRootFramePoint(point); 335 point = plugin()->Container()->LocalToRootFramePoint(point);
342 336
343 params.x = point.x; 337 params.x = point.x;
344 params.y = point.y; 338 params.y = point.y;
345 339
346 context_menu_request_id_ = render_frame()->ShowContextMenu(this, params); 340 context_menu_request_id_ = render_frame()->ShowContextMenu(this, params);
347 g_last_active_menu = this; 341 g_last_active_menu = this;
348 } 342 }
349 343
350 blink::WebPlugin* ChromePluginPlaceholder::CreatePlugin() { 344 blink::WebPlugin* ChromePluginPlaceholder::CreatePlugin() {
351 std::unique_ptr<content::PluginInstanceThrottler> throttler; 345 std::unique_ptr<content::PluginInstanceThrottler> throttler;
352 // If the plugin has already been marked essential in its placeholder form, 346 // If the plugin has already been marked essential in its placeholder form,
353 // we shouldn't create a new throttler and start the process all over again. 347 // we shouldn't create a new throttler and start the process all over again.
354 if (power_saver_enabled()) { 348 if (power_saver_enabled()) {
355 throttler = content::PluginInstanceThrottler::Create( 349 throttler = content::PluginInstanceThrottler::Create(
356 heuristic_run_before_ ? content::RenderFrame::DONT_RECORD_DECISION 350 heuristic_run_before_ ? content::RenderFrame::DONT_RECORD_DECISION
357 : content::RenderFrame::RECORD_DECISION); 351 : content::RenderFrame::RECORD_DECISION);
358 // PluginPreroller manages its own lifetime. 352 // PluginPreroller manages its own lifetime.
359 new PluginPreroller(render_frame(), GetFrame(), GetPluginParams(), 353 new PluginPreroller(render_frame(), GetPluginParams(), GetPluginInfo(),
360 GetPluginInfo(), GetIdentifier(), title_, 354 GetIdentifier(), title_,
361 l10n_util::GetStringFUTF16(IDS_PLUGIN_BLOCKED, title_), 355 l10n_util::GetStringFUTF16(IDS_PLUGIN_BLOCKED, title_),
362 throttler.get()); 356 throttler.get());
363 } 357 }
364 return render_frame()->CreatePlugin(GetFrame(), GetPluginInfo(), 358 return render_frame()->CreatePlugin(GetPluginInfo(), GetPluginParams(),
365 GetPluginParams(), std::move(throttler)); 359 std::move(throttler));
366 } 360 }
367 361
368 void ChromePluginPlaceholder::OnBlockedTinyContent() { 362 void ChromePluginPlaceholder::OnBlockedTinyContent() {
369 DCHECK(render_frame()); 363 DCHECK(render_frame());
370 if (did_send_blocked_content_notification_) 364 if (did_send_blocked_content_notification_)
371 return; 365 return;
372 366
373 did_send_blocked_content_notification_ = true; 367 did_send_blocked_content_notification_ = true;
374 ContentSettingsObserver::Get(render_frame()) 368 ContentSettingsObserver::Get(render_frame())
375 ->DidBlockContentType(CONTENT_SETTINGS_TYPE_PLUGINS, title_); 369 ->DidBlockContentType(CONTENT_SETTINGS_TYPE_PLUGINS, title_);
(...skipping 15 matching lines...) Expand all
391 385
392 if (base::CommandLine::ForCurrentProcess()->HasSwitch( 386 if (base::CommandLine::ForCurrentProcess()->HasSwitch(
393 switches::kEnablePluginPlaceholderTesting)) { 387 switches::kEnablePluginPlaceholderTesting)) {
394 builder.SetMethod<void (ChromePluginPlaceholder::*)()>( 388 builder.SetMethod<void (ChromePluginPlaceholder::*)()>(
395 "didFinishIconRepositionForTesting", 389 "didFinishIconRepositionForTesting",
396 &ChromePluginPlaceholder::DidFinishIconRepositionForTestingCallback); 390 &ChromePluginPlaceholder::DidFinishIconRepositionForTestingCallback);
397 } 391 }
398 392
399 return builder; 393 return builder;
400 } 394 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698