summaryrefslogtreecommitdiffstats
path: root/chromium/content/renderer/pepper/plugin_power_saver_helper.h
blob: b89e911c4f1f48a7d80c09bc96a21b6543f239f0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef CONTENT_RENDERER_PEPPER_PLUGIN_POWER_SAVER_HELPER_H_
#define CONTENT_RENDERER_PEPPER_PLUGIN_POWER_SAVER_HELPER_H_

#include <set>
#include <vector>

#include "base/callback.h"
#include "base/macros.h"
#include "content/common/content_export.h"
#include "content/public/renderer/render_frame.h"
#include "content/public/renderer/render_frame_observer.h"
#include "url/origin.h"

namespace gfx {
class Size;
}

namespace content {

class CONTENT_EXPORT PluginPowerSaverHelper : public RenderFrameObserver {
 public:
  explicit PluginPowerSaverHelper(RenderFrame* render_frame);
  ~PluginPowerSaverHelper() override;

 private:
  friend class RenderFrameImpl;

  struct PeripheralPlugin {
    PeripheralPlugin(const url::Origin& content_origin,
                     const base::Closure& unthrottle_callback);
    PeripheralPlugin(const PeripheralPlugin& other);
    ~PeripheralPlugin();

    url::Origin content_origin;
    base::Closure unthrottle_callback;
  };

  // See RenderFrame for documentation.
  void RegisterPeripheralPlugin(const url::Origin& content_origin,
                                const base::Closure& unthrottle_callback);
  RenderFrame::PeripheralContentStatus GetPeripheralContentStatus(
      const url::Origin& main_frame_origin,
      const url::Origin& content_origin,
      const gfx::Size& unobscured_size,
      RenderFrame::RecordPeripheralDecision record_decision) const;
  void WhitelistContentOrigin(const url::Origin& content_origin);

  // RenderFrameObserver implementation.
  void DidCommitProvisionalLoad(bool is_new_navigation,
                                bool is_same_document_navigation) override;
  bool OnMessageReceived(const IPC::Message& message) override;
  void OnDestruct() override;

  void OnUpdatePluginContentOriginWhitelist(
      const std::set<url::Origin>& origin_whitelist);

  // Local copy of the whitelist for the entire tab.
  std::set<url::Origin> origin_whitelist_;

  // Set of peripheral plugins eligible to be unthrottled ex post facto.
  std::vector<PeripheralPlugin> peripheral_plugins_;

  DISALLOW_COPY_AND_ASSIGN(PluginPowerSaverHelper);
};

}  // namespace content

#endif  // CONTENT_RENDERER_PEPPER_PLUGIN_POWER_SAVER_HELPER_H_