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

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

Issue 866173002: Plugin Power Saver: Add UI Overlay to throttled plugin using placeholder. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 10 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
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "chrome/renderer/plugins/plugin_preroller.h"
6
7 #include "base/base64.h"
8 #include "chrome/grit/renderer_resources.h"
9 #include "chrome/renderer/plugins/chrome_plugin_placeholder.h"
10 #include "third_party/WebKit/public/platform/WebRect.h"
11 #include "third_party/WebKit/public/web/WebElement.h"
12 #include "third_party/WebKit/public/web/WebPlugin.h"
13 #include "third_party/WebKit/public/web/WebPluginContainer.h"
14 #include "ui/gfx/codec/png_codec.h"
15
16 PluginPreroller::PluginPreroller(content::RenderFrame* render_frame,
17 blink::WebLocalFrame* frame,
18 const blink::WebPluginParams& params,
19 const content::WebPluginInfo& info,
20 const std::string& identifier,
21 const base::string16& name,
22 const base::string16& message,
23 blink::WebPlugin* plugin,
24 content::PluginInstanceThrottler* throttler)
25 : render_frame_(render_frame),
26 frame_(frame),
27 params_(params),
28 info_(info),
29 identifier_(identifier),
30 name_(name),
31 message_(message),
32 plugin_(plugin),
33 throttler_(throttler) {
34 DCHECK(plugin);
35 DCHECK(throttler);
36 throttler_->AddObserver(this);
37 }
38
39 PluginPreroller::~PluginPreroller() {
40 if (throttler_)
41 throttler_->RemoveObserver(this);
42 }
43
44 void PluginPreroller::OnKeyframeExtracted(const SkBitmap* bitmap) {
45 std::vector<unsigned char> png_data;
46 if (!gfx::PNGCodec::EncodeBGRASkBitmap(*bitmap, false, &png_data)) {
47 DLOG(ERROR) << "Provided keyframe could not be encoded as PNG.";
48 }
49
50 std::string png_as_string(reinterpret_cast<char*>(&png_data[0]),
Bernhard Bauer 2015/01/30 14:12:56 If encoding the keyframe failed, the vector will b
tommycli 2015/01/30 17:02:40 Done.
51 png_data.size());
52
53 std::string data_url_header = "data:image/png;base64,";
54 std::string data_url_body;
55 base::Base64Encode(png_as_string, &data_url_body);
Bernhard Bauer 2015/01/30 14:12:56 base::Base64Encode() takes a base::StringPiece, so
tommycli 2015/01/30 17:02:40 Done.
56 keyframe_data_url_ = data_url_header + data_url_body;
57 }
58
59 void PluginPreroller::OnThrottleStateChange() {
60 if (throttler_->IsThrottled()) {
Bernhard Bauer 2015/01/30 14:12:56 Early-return if the throttler is not throttled? Th
tommycli 2015/01/30 17:02:40 Done. But I think I only want to destroy the prero
61 ChromePluginPlaceholder* placeholder =
62 ChromePluginPlaceholder::CreateBlockedPlugin(
63 render_frame_, frame_, params_, info_, identifier_, name_,
64 IDR_PLUGIN_POSTER_HTML, message_, GURL(keyframe_data_url_), plugin_,
65 throttler_);
66 placeholder->set_power_saver_mode(
67 content::PluginPowerSaverMode::POWER_SAVER_MODE_PERIPHERAL_THROTTLED);
68 placeholder->set_allow_loading(true);
69
70 // Set the new plug-in on the container before initializing it.
Bernhard Bauer 2015/01/30 14:12:56 I don't think the order of calls is important anym
tommycli 2015/01/30 17:02:40 Done.
71 blink::WebPluginContainer* container = plugin_->container();
72 container->setPlugin(placeholder->plugin());
73
74 if (!placeholder->plugin()->initialize(container)) {
Bernhard Bauer 2015/01/30 14:12:56 WebViewPlugin::initialize() always returns true, s
tommycli 2015/01/30 17:02:40 Done.
75 // We couldn't initialize the new plug-in. Restore the old one and abort.
76 container->setPlugin(plugin_);
77 placeholder->plugin()->destroy();
78 delete this;
79 return;
80 }
81
82 placeholder->plugin()->RestoreTitleText();
Bernhard Bauer 2015/01/30 14:12:56 This is probably also not necessary, because the p
tommycli 2015/01/30 17:02:40 Done.
83 container->invalidate();
84 container->reportGeometry();
85
86 delete this;
87 }
88 }
89
90 void PluginPreroller::OnThrottlerDestroyed() {
91 throttler_ = nullptr;
92 delete this;
93 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698