| OLD | NEW |
| 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/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/strings/string_piece.h" | 10 #include "base/strings/string_piece.h" |
| (...skipping 251 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 262 | 262 |
| 263 void LoadablePluginPlaceholder::DidFinishLoadingCallback() { | 263 void LoadablePluginPlaceholder::DidFinishLoadingCallback() { |
| 264 finished_loading_ = true; | 264 finished_loading_ = true; |
| 265 if (message_.length() > 0) | 265 if (message_.length() > 0) |
| 266 UpdateMessage(); | 266 UpdateMessage(); |
| 267 | 267 |
| 268 // Wait for the placeholder to finish loading to hide the premade plugin. | 268 // Wait for the placeholder to finish loading to hide the premade plugin. |
| 269 // This is necessary to prevent a flicker. | 269 // This is necessary to prevent a flicker. |
| 270 if (premade_throttler_ && power_saver_enabled_) | 270 if (premade_throttler_ && power_saver_enabled_) |
| 271 premade_throttler_->SetHiddenForPlaceholder(true /* hidden */); | 271 premade_throttler_->SetHiddenForPlaceholder(true /* hidden */); |
| 272 |
| 273 // In case our initial geometry was reported before the placeholder finished |
| 274 // loading, request another one. Needed for correct large poster unthrottling. |
| 275 plugin()->container()->reportGeometry(); |
| 272 } | 276 } |
| 273 | 277 |
| 274 void LoadablePluginPlaceholder::DidFinishIconRepositionForTestingCallback() { | 278 void LoadablePluginPlaceholder::DidFinishIconRepositionForTestingCallback() { |
| 275 // Set an attribute and post an event, so browser tests can wait for the | 279 // Set an attribute and post an event, so browser tests can wait for the |
| 276 // placeholder to be ready to receive simulated user input. | 280 // placeholder to be ready to receive simulated user input. |
| 277 blink::WebElement element = plugin()->container()->element(); | 281 blink::WebElement element = plugin()->container()->element(); |
| 278 element.setAttribute("placeholderReady", "true"); | 282 element.setAttribute("placeholderReady", "true"); |
| 279 | 283 |
| 280 scoped_ptr<content::V8ValueConverter> converter( | 284 scoped_ptr<content::V8ValueConverter> converter( |
| 281 content::V8ValueConverter::create()); | 285 content::V8ValueConverter::create()); |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 341 int x = roundf(unobscured_rect_.x() / zoom_factor); | 345 int x = roundf(unobscured_rect_.x() / zoom_factor); |
| 342 int y = roundf(unobscured_rect_.y() / zoom_factor); | 346 int y = roundf(unobscured_rect_.y() / zoom_factor); |
| 343 std::string script = base::StringPrintf( | 347 std::string script = base::StringPrintf( |
| 344 "window.resizePoster('%dpx', '%dpx', '%dpx', '%dpx')", x, y, width, | 348 "window.resizePoster('%dpx', '%dpx', '%dpx', '%dpx')", x, y, width, |
| 345 height); | 349 height); |
| 346 plugin()->web_view()->mainFrame()->executeScript( | 350 plugin()->web_view()->mainFrame()->executeScript( |
| 347 blink::WebScriptSource(base::UTF8ToUTF16(script))); | 351 blink::WebScriptSource(base::UTF8ToUTF16(script))); |
| 348 | 352 |
| 349 // On a size update check if we now qualify as a essential plugin. | 353 // On a size update check if we now qualify as a essential plugin. |
| 350 url::Origin content_origin = url::Origin(GetPluginParams().url); | 354 url::Origin content_origin = url::Origin(GetPluginParams().url); |
| 351 bool cross_origin_main_content = false; | 355 auto status = render_frame()->GetPeripheralContentStatus( |
| 352 if (!render_frame()->ShouldThrottleContent( | 356 render_frame()->GetWebFrame()->top()->securityOrigin(), content_origin, |
| 353 render_frame()->GetWebFrame()->top()->securityOrigin(), | 357 gfx::Size(width, height)); |
| 354 content_origin, width, height, &cross_origin_main_content)) { | 358 if (status != content::RenderFrame::CONTENT_STATUS_PERIPHERAL) { |
| 355 MarkPluginEssential( | 359 MarkPluginEssential( |
| 356 heuristic_run_before_ | 360 heuristic_run_before_ |
| 357 ? PluginInstanceThrottler::UNTHROTTLE_METHOD_BY_SIZE_CHANGE | 361 ? PluginInstanceThrottler::UNTHROTTLE_METHOD_BY_SIZE_CHANGE |
| 358 : PluginInstanceThrottler::UNTHROTTLE_METHOD_DO_NOT_RECORD); | 362 : PluginInstanceThrottler::UNTHROTTLE_METHOD_DO_NOT_RECORD); |
| 359 | 363 |
| 360 if (cross_origin_main_content && !heuristic_run_before_) | 364 if (!heuristic_run_before_ && |
| 365 status == |
| 366 content::RenderFrame::CONTENT_STATUS_ESSENTIAL_CROSS_ORIGIN_BIG) { |
| 361 render_frame()->WhitelistContentOrigin(content_origin); | 367 render_frame()->WhitelistContentOrigin(content_origin); |
| 368 } |
| 362 } | 369 } |
| 363 | 370 |
| 364 heuristic_run_before_ = true; | 371 heuristic_run_before_ = true; |
| 365 } | 372 } |
| 366 | 373 |
| 367 in_size_recheck_ = false; | 374 in_size_recheck_ = false; |
| 368 } | 375 } |
| 369 | 376 |
| 370 } // namespace plugins | 377 } // namespace plugins |
| OLD | NEW |