loadable_plugin_placeholder.h 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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. #ifndef COMPONENTS_PLUGINS_RENDERER_LOADABLE_PLUGIN_PLACEHOLDER_H_
  5. #define COMPONENTS_PLUGINS_RENDERER_LOADABLE_PLUGIN_PLACEHOLDER_H_
  6. #include <memory>
  7. #include "base/memory/weak_ptr.h"
  8. #include "base/timer/timer.h"
  9. #include "components/plugins/renderer/plugin_placeholder.h"
  10. #include "content/public/common/webplugininfo.h"
  11. #include "content/public/renderer/render_frame.h"
  12. #include "content/public/renderer/render_thread.h"
  13. namespace plugins {
  14. // Placeholders can be used if a plugin is missing or not available
  15. // (blocked or disabled).
  16. class LoadablePluginPlaceholder : public PluginPlaceholderBase {
  17. public:
  18. LoadablePluginPlaceholder(const LoadablePluginPlaceholder&) = delete;
  19. LoadablePluginPlaceholder& operator=(const LoadablePluginPlaceholder&) =
  20. delete;
  21. void set_blocked_for_prerendering(bool blocked_for_prerendering) {
  22. is_blocked_for_prerendering_ = blocked_for_prerendering;
  23. }
  24. void AllowLoading() { allow_loading_ = true; }
  25. // Load the blocked plugin if the identifier matches (or is empty).
  26. void MaybeLoadBlockedPlugin(const std::string& identifier);
  27. protected:
  28. LoadablePluginPlaceholder(content::RenderFrame* render_frame,
  29. const blink::WebPluginParams& params,
  30. const std::string& html_data);
  31. ~LoadablePluginPlaceholder() override;
  32. void OnSetIsPrerendering(bool is_prerendering);
  33. void SetMessage(const std::u16string& message);
  34. void SetPluginInfo(const content::WebPluginInfo& plugin_info);
  35. const content::WebPluginInfo& GetPluginInfo() const;
  36. void SetIdentifier(const std::string& identifier);
  37. const std::string& GetIdentifier() const;
  38. bool LoadingAllowed() const { return allow_loading_; }
  39. // Replace this placeholder with a different plugin (which could be
  40. // a placeholder again).
  41. void ReplacePlugin(blink::WebPlugin* new_plugin);
  42. // Load the blocked plugin.
  43. void LoadPlugin();
  44. // Javascript callbacks:
  45. void LoadCallback();
  46. void DidFinishLoadingCallback();
  47. private:
  48. // WebViewPlugin::Delegate methods:
  49. bool IsErrorPlaceholder() override;
  50. void UpdateMessage();
  51. bool LoadingBlocked() const;
  52. // Plugin creation is embedder-specific.
  53. virtual blink::WebPlugin* CreatePlugin() = 0;
  54. // Embedder-specific behavior. This will only be called once per placeholder.
  55. virtual void OnBlockedContent(
  56. content::RenderFrame::PeripheralContentStatus status,
  57. bool is_same_origin) = 0;
  58. content::WebPluginInfo plugin_info_;
  59. std::u16string message_;
  60. // True if the plugin was blocked because the page was being prerendered.
  61. // Plugin may be automatically be loaded when the page is displayed.
  62. bool is_blocked_for_prerendering_;
  63. bool allow_loading_;
  64. bool finished_loading_;
  65. std::string identifier_;
  66. base::WeakPtrFactory<LoadablePluginPlaceholder> weak_factory_{this};
  67. };
  68. } // namespace plugins
  69. #endif // COMPONENTS_PLUGINS_RENDERER_LOADABLE_PLUGIN_PLACEHOLDER_H_