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

Side by Side Diff: components/plugins/renderer/loadable_plugin_placeholder.cc

Issue 1522173002: Reland: Plugin Power Saver: Improve Poster behavior for essential plugins. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix an NPE crash/race on plugin destruction Created 5 years 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
« no previous file with comments | « chrome/renderer/plugins/power_saver_info.cc ('k') | content/public/renderer/render_frame.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 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 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 "components/plugins/renderer/loadable_plugin_placeholder.h" 5 #include "components/plugins/renderer/loadable_plugin_placeholder.h"
6 6
7 #include "base/auto_reset.h" 7 #include "base/auto_reset.h"
8 #include "base/bind.h" 8 #include "base/bind.h"
9 #include "base/bind_helpers.h" 9 #include "base/bind_helpers.h"
10 #include "base/json/string_escape.h" 10 #include "base/json/string_escape.h"
(...skipping 252 matching lines...) Expand 10 before | Expand all | Expand 10 after
263 263
264 void LoadablePluginPlaceholder::DidFinishLoadingCallback() { 264 void LoadablePluginPlaceholder::DidFinishLoadingCallback() {
265 finished_loading_ = true; 265 finished_loading_ = true;
266 if (message_.length() > 0) 266 if (message_.length() > 0)
267 UpdateMessage(); 267 UpdateMessage();
268 268
269 // Wait for the placeholder to finish loading to hide the premade plugin. 269 // Wait for the placeholder to finish loading to hide the premade plugin.
270 // This is necessary to prevent a flicker. 270 // This is necessary to prevent a flicker.
271 if (premade_throttler_ && power_saver_enabled_) 271 if (premade_throttler_ && power_saver_enabled_)
272 premade_throttler_->SetHiddenForPlaceholder(true /* hidden */); 272 premade_throttler_->SetHiddenForPlaceholder(true /* hidden */);
273
274 // In case our initial geometry was reported before the placeholder finished
275 // loading, request another one. Needed for correct large poster unthrottling.
276 if (plugin()) {
277 CHECK(plugin()->container());
tommycli 2015/12/14 21:17:55 The plugin / container semantics are kind-of under
278 plugin()->container()->reportGeometry();
279 }
273 } 280 }
274 281
275 void LoadablePluginPlaceholder::DidFinishIconRepositionForTestingCallback() { 282 void LoadablePluginPlaceholder::DidFinishIconRepositionForTestingCallback() {
276 // Set an attribute and post an event, so browser tests can wait for the 283 // Set an attribute and post an event, so browser tests can wait for the
277 // placeholder to be ready to receive simulated user input. 284 // placeholder to be ready to receive simulated user input.
278 blink::WebElement element = plugin()->container()->element(); 285 blink::WebElement element = plugin()->container()->element();
279 element.setAttribute("placeholderReady", "true"); 286 element.setAttribute("placeholderReady", "true");
280 287
281 scoped_ptr<content::V8ValueConverter> converter( 288 scoped_ptr<content::V8ValueConverter> converter(
282 content::V8ValueConverter::create()); 289 content::V8ValueConverter::create());
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
340 int x = roundf(unobscured_rect_.x() / zoom_factor); 347 int x = roundf(unobscured_rect_.x() / zoom_factor);
341 int y = roundf(unobscured_rect_.y() / zoom_factor); 348 int y = roundf(unobscured_rect_.y() / zoom_factor);
342 std::string script = base::StringPrintf( 349 std::string script = base::StringPrintf(
343 "window.resizePoster('%dpx', '%dpx', '%dpx', '%dpx')", x, y, width, 350 "window.resizePoster('%dpx', '%dpx', '%dpx', '%dpx')", x, y, width,
344 height); 351 height);
345 plugin()->web_view()->mainFrame()->executeScript( 352 plugin()->web_view()->mainFrame()->executeScript(
346 blink::WebScriptSource(base::UTF8ToUTF16(script))); 353 blink::WebScriptSource(base::UTF8ToUTF16(script)));
347 354
348 // On a size update check if we now qualify as a essential plugin. 355 // On a size update check if we now qualify as a essential plugin.
349 url::Origin content_origin = url::Origin(GetPluginParams().url); 356 url::Origin content_origin = url::Origin(GetPluginParams().url);
350 bool cross_origin_main_content = false; 357 auto status = render_frame()->GetPeripheralContentStatus(
351 if (!render_frame()->ShouldThrottleContent( 358 render_frame()->GetWebFrame()->top()->securityOrigin(), content_origin,
352 render_frame()->GetWebFrame()->top()->securityOrigin(), 359 gfx::Size(width, height));
353 content_origin, width, height, &cross_origin_main_content)) { 360 if (status != content::RenderFrame::CONTENT_STATUS_PERIPHERAL) {
354 MarkPluginEssential( 361 MarkPluginEssential(
355 heuristic_run_before_ 362 heuristic_run_before_
356 ? PluginInstanceThrottler::UNTHROTTLE_METHOD_BY_SIZE_CHANGE 363 ? PluginInstanceThrottler::UNTHROTTLE_METHOD_BY_SIZE_CHANGE
357 : PluginInstanceThrottler::UNTHROTTLE_METHOD_DO_NOT_RECORD); 364 : PluginInstanceThrottler::UNTHROTTLE_METHOD_DO_NOT_RECORD);
358 365
359 if (cross_origin_main_content && !heuristic_run_before_) 366 if (!heuristic_run_before_ &&
367 status ==
368 content::RenderFrame::CONTENT_STATUS_ESSENTIAL_CROSS_ORIGIN_BIG) {
360 render_frame()->WhitelistContentOrigin(content_origin); 369 render_frame()->WhitelistContentOrigin(content_origin);
370 }
361 } 371 }
362 372
363 heuristic_run_before_ = true; 373 heuristic_run_before_ = true;
364 } 374 }
365 } 375 }
366 376
367 } // namespace plugins 377 } // namespace plugins
OLDNEW
« no previous file with comments | « chrome/renderer/plugins/power_saver_info.cc ('k') | content/public/renderer/render_frame.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698