Chromium Code Reviews| 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 "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 10 matching lines...) Expand all Loading... | |
| 21 const base::string16& name, | 21 const base::string16& name, |
| 22 const base::string16& message, | 22 const base::string16& message, |
| 23 content::PluginInstanceThrottler* throttler) | 23 content::PluginInstanceThrottler* throttler) |
| 24 : RenderFrameObserver(render_frame), | 24 : RenderFrameObserver(render_frame), |
| 25 frame_(frame), | 25 frame_(frame), |
| 26 params_(params), | 26 params_(params), |
| 27 info_(info), | 27 info_(info), |
| 28 identifier_(identifier), | 28 identifier_(identifier), |
| 29 name_(name), | 29 name_(name), |
| 30 message_(message), | 30 message_(message), |
| 31 throttler_(throttler) { | 31 throttler_(throttler), |
| 32 keyframe_width_(0), | |
| 33 keyframe_height_(0) { | |
| 32 DCHECK(throttler); | 34 DCHECK(throttler); |
| 33 throttler_->AddObserver(this); | 35 throttler_->AddObserver(this); |
| 34 } | 36 } |
| 35 | 37 |
| 36 PluginPreroller::~PluginPreroller() { | 38 PluginPreroller::~PluginPreroller() { |
| 37 if (throttler_) | 39 if (throttler_) |
| 38 throttler_->RemoveObserver(this); | 40 throttler_->RemoveObserver(this); |
| 39 } | 41 } |
| 40 | 42 |
| 41 void PluginPreroller::OnKeyframeExtracted(const SkBitmap* bitmap) { | 43 void PluginPreroller::OnKeyframeExtracted(const SkBitmap* bitmap) { |
| 42 std::vector<unsigned char> png_data; | 44 std::vector<unsigned char> png_data; |
| 43 if (!gfx::PNGCodec::EncodeBGRASkBitmap(*bitmap, false, &png_data)) { | 45 if (!gfx::PNGCodec::EncodeBGRASkBitmap(*bitmap, false, &png_data)) { |
| 44 DLOG(ERROR) << "Provided keyframe could not be encoded as PNG."; | 46 DLOG(ERROR) << "Provided keyframe could not be encoded as PNG."; |
| 45 return; | 47 return; |
| 46 } | 48 } |
| 47 | 49 |
| 48 base::StringPiece png_as_string(reinterpret_cast<char*>(&png_data[0]), | 50 base::StringPiece png_as_string(reinterpret_cast<char*>(&png_data[0]), |
| 49 png_data.size()); | 51 png_data.size()); |
| 50 | 52 |
| 51 std::string data_url_header = "data:image/png;base64,"; | 53 std::string data_url_header = "data:image/png;base64,"; |
| 52 std::string data_url_body; | 54 std::string data_url_body; |
| 53 base::Base64Encode(png_as_string, &data_url_body); | 55 base::Base64Encode(png_as_string, &data_url_body); |
| 54 keyframe_data_url_ = GURL(data_url_header + data_url_body); | 56 keyframe_data_url_ = GURL(data_url_header + data_url_body); |
| 57 keyframe_width_ = bitmap->width(); | |
|
Lei Zhang
2015/03/18 00:19:32
This is gfx::Size::SetToMin(), right?
tommycli
2015/03/18 00:39:33
Done.
| |
| 58 keyframe_height_ = bitmap->height(); | |
| 55 } | 59 } |
| 56 | 60 |
| 57 void PluginPreroller::OnThrottleStateChange() { | 61 void PluginPreroller::OnThrottleStateChange() { |
| 58 if (!throttler_->IsThrottled()) | 62 if (!throttler_->IsThrottled()) |
| 59 return; | 63 return; |
| 60 | 64 |
| 65 int width = std::min(keyframe_width_, throttler_->GetWidth()); | |
|
Lei Zhang
2015/03/18 00:19:32
This is gfx::Size::SetToMin() right?
tommycli
2015/03/18 00:39:33
Done.
| |
| 66 int height = std::min(keyframe_height_, throttler_->GetHeight()); | |
| 67 | |
| 61 ChromePluginPlaceholder* placeholder = | 68 ChromePluginPlaceholder* placeholder = |
| 62 ChromePluginPlaceholder::CreateBlockedPlugin( | 69 ChromePluginPlaceholder::CreateBlockedPlugin( |
| 63 render_frame(), frame_, params_, info_, identifier_, name_, | 70 render_frame(), frame_, params_, info_, identifier_, name_, |
| 64 IDR_PLUGIN_POSTER_HTML, message_, keyframe_data_url_.spec(), GURL()); | 71 IDR_PLUGIN_POSTER_HTML, message_, keyframe_data_url_.spec(), GURL(), |
| 72 width, height); | |
| 65 placeholder->SetPremadePlugin(throttler_); | 73 placeholder->SetPremadePlugin(throttler_); |
| 66 placeholder->set_power_saver_enabled(true); | 74 placeholder->set_power_saver_enabled(true); |
| 67 placeholder->set_allow_loading(true); | 75 placeholder->set_allow_loading(true); |
| 68 | 76 |
| 69 blink::WebPluginContainer* container = | 77 blink::WebPluginContainer* container = |
| 70 throttler_->GetWebPlugin()->container(); | 78 throttler_->GetWebPlugin()->container(); |
| 71 container->setPlugin(placeholder->plugin()); | 79 container->setPlugin(placeholder->plugin()); |
| 72 | 80 |
| 73 bool success = placeholder->plugin()->initialize(container); | 81 bool success = placeholder->plugin()->initialize(container); |
| 74 DCHECK(success); | 82 DCHECK(success); |
| 75 | 83 |
| 76 container->invalidate(); | 84 container->invalidate(); |
| 77 container->reportGeometry(); | 85 container->reportGeometry(); |
| 78 | 86 |
| 79 delete this; | 87 delete this; |
| 80 } | 88 } |
| 81 | 89 |
| 82 void PluginPreroller::OnThrottlerDestroyed() { | 90 void PluginPreroller::OnThrottlerDestroyed() { |
| 83 throttler_ = nullptr; | 91 throttler_ = nullptr; |
| 84 delete this; | 92 delete this; |
| 85 } | 93 } |
| OLD | NEW |