| 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/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 Loading... |
| 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 plugin()->container()->reportGeometry(); | |
| 277 } | 273 } |
| 278 | 274 |
| 279 void LoadablePluginPlaceholder::DidFinishIconRepositionForTestingCallback() { | 275 void LoadablePluginPlaceholder::DidFinishIconRepositionForTestingCallback() { |
| 280 // Set an attribute and post an event, so browser tests can wait for the | 276 // Set an attribute and post an event, so browser tests can wait for the |
| 281 // placeholder to be ready to receive simulated user input. | 277 // placeholder to be ready to receive simulated user input. |
| 282 blink::WebElement element = plugin()->container()->element(); | 278 blink::WebElement element = plugin()->container()->element(); |
| 283 element.setAttribute("placeholderReady", "true"); | 279 element.setAttribute("placeholderReady", "true"); |
| 284 | 280 |
| 285 scoped_ptr<content::V8ValueConverter> converter( | 281 scoped_ptr<content::V8ValueConverter> converter( |
| 286 content::V8ValueConverter::create()); | 282 content::V8ValueConverter::create()); |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 344 int x = roundf(unobscured_rect_.x() / zoom_factor); | 340 int x = roundf(unobscured_rect_.x() / zoom_factor); |
| 345 int y = roundf(unobscured_rect_.y() / zoom_factor); | 341 int y = roundf(unobscured_rect_.y() / zoom_factor); |
| 346 std::string script = base::StringPrintf( | 342 std::string script = base::StringPrintf( |
| 347 "window.resizePoster('%dpx', '%dpx', '%dpx', '%dpx')", x, y, width, | 343 "window.resizePoster('%dpx', '%dpx', '%dpx', '%dpx')", x, y, width, |
| 348 height); | 344 height); |
| 349 plugin()->web_view()->mainFrame()->executeScript( | 345 plugin()->web_view()->mainFrame()->executeScript( |
| 350 blink::WebScriptSource(base::UTF8ToUTF16(script))); | 346 blink::WebScriptSource(base::UTF8ToUTF16(script))); |
| 351 | 347 |
| 352 // On a size update check if we now qualify as a essential plugin. | 348 // On a size update check if we now qualify as a essential plugin. |
| 353 url::Origin content_origin = url::Origin(GetPluginParams().url); | 349 url::Origin content_origin = url::Origin(GetPluginParams().url); |
| 354 auto status = render_frame()->GetPeripheralContentStatus( | 350 bool cross_origin_main_content = false; |
| 355 render_frame()->GetWebFrame()->top()->securityOrigin(), content_origin, | 351 if (!render_frame()->ShouldThrottleContent( |
| 356 gfx::Size(width, height)); | 352 render_frame()->GetWebFrame()->top()->securityOrigin(), |
| 357 if (status != content::RenderFrame::CONTENT_STATUS_PERIPHERAL) { | 353 content_origin, width, height, &cross_origin_main_content)) { |
| 358 MarkPluginEssential( | 354 MarkPluginEssential( |
| 359 heuristic_run_before_ | 355 heuristic_run_before_ |
| 360 ? PluginInstanceThrottler::UNTHROTTLE_METHOD_BY_SIZE_CHANGE | 356 ? PluginInstanceThrottler::UNTHROTTLE_METHOD_BY_SIZE_CHANGE |
| 361 : PluginInstanceThrottler::UNTHROTTLE_METHOD_DO_NOT_RECORD); | 357 : PluginInstanceThrottler::UNTHROTTLE_METHOD_DO_NOT_RECORD); |
| 362 | 358 |
| 363 if (!heuristic_run_before_ && | 359 if (cross_origin_main_content && !heuristic_run_before_) |
| 364 status == | |
| 365 content::RenderFrame::CONTENT_STATUS_ESSENTIAL_CROSS_ORIGIN_BIG) { | |
| 366 render_frame()->WhitelistContentOrigin(content_origin); | 360 render_frame()->WhitelistContentOrigin(content_origin); |
| 367 } | |
| 368 } | 361 } |
| 369 | 362 |
| 370 heuristic_run_before_ = true; | 363 heuristic_run_before_ = true; |
| 371 } | 364 } |
| 372 } | 365 } |
| 373 | 366 |
| 374 } // namespace plugins | 367 } // namespace plugins |
| OLD | NEW |