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

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

Issue 1015023002: Plugin Power Saver: Throttle 'large' plugins that appear small. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: use gfx::Size Created 5 years, 9 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 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 "chrome/renderer/plugins/plugin_preroller.h" 5 #include "chrome/renderer/plugins/plugin_preroller.h"
6 6
7 #include "base/base64.h" 7 #include "base/base64.h"
8 #include "chrome/grit/renderer_resources.h" 8 #include "chrome/grit/renderer_resources.h"
9 #include "chrome/renderer/plugins/chrome_plugin_placeholder.h" 9 #include "chrome/renderer/plugins/chrome_plugin_placeholder.h"
10 #include "third_party/WebKit/public/platform/WebRect.h" 10 #include "third_party/WebKit/public/platform/WebRect.h"
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
45 return; 45 return;
46 } 46 }
47 47
48 base::StringPiece png_as_string(reinterpret_cast<char*>(&png_data[0]), 48 base::StringPiece png_as_string(reinterpret_cast<char*>(&png_data[0]),
49 png_data.size()); 49 png_data.size());
50 50
51 std::string data_url_header = "data:image/png;base64,"; 51 std::string data_url_header = "data:image/png;base64,";
52 std::string data_url_body; 52 std::string data_url_body;
53 base::Base64Encode(png_as_string, &data_url_body); 53 base::Base64Encode(png_as_string, &data_url_body);
54 keyframe_data_url_ = GURL(data_url_header + data_url_body); 54 keyframe_data_url_ = GURL(data_url_header + data_url_body);
55 keyframe_size_.SetSize(bitmap->width(), bitmap->height());
55 } 56 }
56 57
57 void PluginPreroller::OnThrottleStateChange() { 58 void PluginPreroller::OnThrottleStateChange() {
58 if (!throttler_->IsThrottled()) 59 if (!throttler_->IsThrottled())
59 return; 60 return;
60 61
62 keyframe_size_.SetToMin(throttler_->GetSize());
63
61 ChromePluginPlaceholder* placeholder = 64 ChromePluginPlaceholder* placeholder =
62 ChromePluginPlaceholder::CreateBlockedPlugin( 65 ChromePluginPlaceholder::CreateBlockedPlugin(
63 render_frame(), frame_, params_, info_, identifier_, name_, 66 render_frame(), frame_, params_, info_, identifier_, name_,
64 IDR_PLUGIN_POSTER_HTML, message_, keyframe_data_url_.spec(), GURL()); 67 IDR_PLUGIN_POSTER_HTML, message_, keyframe_data_url_.spec(), GURL(),
68 keyframe_size_);
65 placeholder->SetPremadePlugin(throttler_); 69 placeholder->SetPremadePlugin(throttler_);
66 placeholder->set_power_saver_enabled(true); 70 placeholder->set_power_saver_enabled(true);
67 placeholder->set_allow_loading(true); 71 placeholder->set_allow_loading(true);
68 72
69 blink::WebPluginContainer* container = 73 blink::WebPluginContainer* container =
70 throttler_->GetWebPlugin()->container(); 74 throttler_->GetWebPlugin()->container();
71 container->setPlugin(placeholder->plugin()); 75 container->setPlugin(placeholder->plugin());
72 76
73 bool success = placeholder->plugin()->initialize(container); 77 bool success = placeholder->plugin()->initialize(container);
74 DCHECK(success); 78 DCHECK(success);
75 79
76 container->invalidate(); 80 container->invalidate();
77 container->reportGeometry(); 81 container->reportGeometry();
78 82
79 delete this; 83 delete this;
80 } 84 }
81 85
82 void PluginPreroller::OnThrottlerDestroyed() { 86 void PluginPreroller::OnThrottlerDestroyed() {
83 throttler_ = nullptr; 87 throttler_ = nullptr;
84 delete this; 88 delete this;
85 } 89 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698