* Execute content script in isolated world * Inject script into newly created extension worlds * Create new content_script_bundle for extension scripts * Initialize chrome API in content script bundle * Define Chrome extension isolated world ID range 1 << 20 was chosen as it provides a sufficiently large range of IDs for extensions, but also provides a large enough buffer for any user worlds in [1000, 1 << 20). Ultimately this range can be changed if any user application raises it as an issue. * Insert content script CSS into document This now avoids a script wrapper to inject the style sheet. This closely matches the code used by chromium in `ScriptInjection::InjectCss`. * Pass extension ID to isolated world via v8 private
		
			
				
	
	
		
			82 lines
		
	
	
	
		
			3.2 KiB
			
		
	
	
	
		
			C++
		
	
	
	
	
	
			
		
		
	
	
			82 lines
		
	
	
	
		
			3.2 KiB
			
		
	
	
	
		
			C++
		
	
	
	
	
	
// Copyright (c) 2017 GitHub, Inc.
 | 
						|
// Use of this source code is governed by the MIT license that can be
 | 
						|
// found in the LICENSE file.
 | 
						|
 | 
						|
#ifndef ATOM_RENDERER_RENDERER_CLIENT_BASE_H_
 | 
						|
#define ATOM_RENDERER_RENDERER_CLIENT_BASE_H_
 | 
						|
 | 
						|
#include <memory>
 | 
						|
#include <string>
 | 
						|
#include <vector>
 | 
						|
 | 
						|
#include "content/public/renderer/content_renderer_client.h"
 | 
						|
#include "third_party/blink/public/web/web_local_frame.h"
 | 
						|
// In SHARED_INTERMEDIATE_DIR.
 | 
						|
#include "widevine_cdm_version.h"  // NOLINT(build/include)
 | 
						|
 | 
						|
#if defined(WIDEVINE_CDM_AVAILABLE)
 | 
						|
#include "chrome/renderer/media/chrome_key_systems_provider.h"  // nogncheck
 | 
						|
#endif
 | 
						|
 | 
						|
namespace atom {
 | 
						|
 | 
						|
class PreferencesManager;
 | 
						|
 | 
						|
class RendererClientBase : public content::ContentRendererClient {
 | 
						|
 public:
 | 
						|
  RendererClientBase();
 | 
						|
  ~RendererClientBase() override;
 | 
						|
 | 
						|
  virtual void DidCreateScriptContext(v8::Handle<v8::Context> context,
 | 
						|
                                      content::RenderFrame* render_frame);
 | 
						|
  virtual void WillReleaseScriptContext(v8::Handle<v8::Context> context,
 | 
						|
                                        content::RenderFrame* render_frame) = 0;
 | 
						|
  virtual void DidClearWindowObject(content::RenderFrame* render_frame);
 | 
						|
  virtual void SetupMainWorldOverrides(v8::Handle<v8::Context> context,
 | 
						|
                                       content::RenderFrame* render_frame) = 0;
 | 
						|
  virtual void SetupExtensionWorldOverrides(v8::Handle<v8::Context> context,
 | 
						|
                                            content::RenderFrame* render_frame,
 | 
						|
                                            int world_id) = 0;
 | 
						|
 | 
						|
  bool isolated_world() const { return isolated_world_; }
 | 
						|
 | 
						|
  // Get the context that the Electron API is running in.
 | 
						|
  v8::Local<v8::Context> GetContext(blink::WebLocalFrame* frame,
 | 
						|
                                    v8::Isolate* isolate) const;
 | 
						|
  // Executes a given v8 Script
 | 
						|
  static v8::Local<v8::Value> RunScript(v8::Local<v8::Context> context,
 | 
						|
                                        v8::Local<v8::String> source);
 | 
						|
 | 
						|
 protected:
 | 
						|
  void AddRenderBindings(v8::Isolate* isolate,
 | 
						|
                         v8::Local<v8::Object> binding_object);
 | 
						|
 | 
						|
  // content::ContentRendererClient:
 | 
						|
  void RenderThreadStarted() override;
 | 
						|
  void RenderFrameCreated(content::RenderFrame*) override;
 | 
						|
  void RenderViewCreated(content::RenderView*) override;
 | 
						|
  std::unique_ptr<blink::WebSpeechSynthesizer> OverrideSpeechSynthesizer(
 | 
						|
      blink::WebSpeechSynthesizerClient* client) override;
 | 
						|
  bool OverrideCreatePlugin(content::RenderFrame* render_frame,
 | 
						|
                            const blink::WebPluginParams& params,
 | 
						|
                            blink::WebPlugin** plugin) override;
 | 
						|
  void AddSupportedKeySystems(
 | 
						|
      std::vector<std::unique_ptr<::media::KeySystemProperties>>* key_systems)
 | 
						|
      override;
 | 
						|
  bool IsKeySystemsUpdateNeeded() override;
 | 
						|
  void DidSetUserAgent(const std::string& user_agent) override;
 | 
						|
 | 
						|
 private:
 | 
						|
  std::unique_ptr<PreferencesManager> preferences_manager_;
 | 
						|
#if defined(WIDEVINE_CDM_AVAILABLE)
 | 
						|
  ChromeKeySystemsProvider key_systems_provider_;
 | 
						|
#endif
 | 
						|
  bool isolated_world_;
 | 
						|
  std::string renderer_client_id_;
 | 
						|
  // An increasing ID used for indentifying an V8 context in this process.
 | 
						|
  int64_t next_context_id_ = 0;
 | 
						|
};
 | 
						|
 | 
						|
}  // namespace atom
 | 
						|
 | 
						|
#endif  // ATOM_RENDERER_RENDERER_CLIENT_BASE_H_
 |