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 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140
|
// Copyright 2014 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef EXTENSIONS_RENDERER_EXTENSIONS_RENDERER_CLIENT_H_
#define EXTENSIONS_RENDERER_EXTENSIONS_RENDERER_CLIENT_H_
#include <memory>
#include <string>
#include "extensions/common/extension_id.h"
#include "extensions/renderer/extensions_renderer_api_provider.h"
#include "extensions/renderer/resource_request_policy.h"
#include "services/service_manager/public/cpp/binder_registry.h"
#include "ui/base/page_transition_types.h"
#include "v8/include/v8-local-handle.h"
namespace content {
class RenderFrame;
} // namespace content
namespace blink {
enum class ProtocolHandlerSecurityLevel;
class WebElement;
class WebFrame;
class WebLocalFrame;
struct WebPluginParams;
class WebURL;
class WebView;
} // namespace blink
namespace net {
class SiteForCookies;
}
namespace url {
class Origin;
}
namespace v8 {
class Isolate;
class Object;
} // namespace v8
namespace extensions {
class Extension;
class ExtensionsRendererAPIProvider;
class Dispatcher;
// Interface to allow the extensions module to make render-process-specific
// queries of the embedder. Should be Set() once in the render process.
//
// NOTE: Methods that do not require knowledge of renderer concepts should be
// added in ExtensionsClient (extensions/common/extensions_client.h) even if
// they are only used in the renderer process.
class ExtensionsRendererClient {
public:
ExtensionsRendererClient();
virtual ~ExtensionsRendererClient();
// Returns true if the current render process was launched incognito.
virtual bool IsIncognitoProcess() const = 0;
// Returns the lowest isolated world ID available to extensions.
// Must be greater than 0. See blink::WebFrame::executeScriptInIsolatedWorld
// (third_party/WebKit/public/web/WebFrame.h) for additional context.
virtual int GetLowestIsolatedWorldId() const = 0;
// Notifies the client when an extension is added or removed.
// TODO(devlin): Make a RendererExtensionRegistryObserver?
void OnExtensionLoaded(const Extension& extension);
void OnExtensionUnloaded(const ExtensionId& extension);
// Adds an API provider that can extend the behavior of extension's renderer
// side. API providers need to be added before `Dispatcher` is created.
void AddAPIProvider(
std::unique_ptr<ExtensionsRendererAPIProvider> api_provider);
// The following methods mirror the ContentRendererClient methods of the same
// names.
void RenderThreadStarted();
void WebViewCreated(blink::WebView* web_view,
const url::Origin* outermost_origin);
void RenderFrameCreated(content::RenderFrame* render_frame,
service_manager::BinderRegistry* registry);
bool OverrideCreatePlugin(content::RenderFrame* render_frame,
const blink::WebPluginParams& params);
bool AllowPopup();
blink::ProtocolHandlerSecurityLevel GetProtocolHandlerSecurityLevel();
v8::Local<v8::Object> GetScriptableObject(
const blink::WebElement& plugin_element,
v8::Isolate* isolate);
static blink::WebFrame* FindFrame(blink::WebLocalFrame* relative_to_frame,
const std::string& name);
void RunScriptsAtDocumentStart(content::RenderFrame* render_frame);
void RunScriptsAtDocumentEnd(content::RenderFrame* render_frame);
void RunScriptsAtDocumentIdle(content::RenderFrame* render_frame);
void WillSendRequest(blink::WebLocalFrame* frame,
ui::PageTransition transition_type,
const blink::WebURL& upstream_url,
const blink::WebURL& target_url,
const net::SiteForCookies& site_for_cookies,
const url::Origin* initiator_origin,
GURL* new_url);
// Returns the single instance of `this`.
static ExtensionsRendererClient* Get();
// Initialize the single instance.
static void Set(ExtensionsRendererClient* client);
Dispatcher* dispatcher() { return dispatcher_.get(); }
void SetDispatcherForTesting(std::unique_ptr<Dispatcher> dispatcher);
private:
// Called to allow embedders to finish any initialization as part of
// RenderThreadStarted().
virtual void FinishInitialization() {}
// Allows embedders to create a delegate for the ResourceRequestPolicy.
// By default, returns null.
virtual std::unique_ptr<ResourceRequestPolicy::Delegate>
CreateResourceRequestPolicyDelegate();
// Allows embedders to record metrics when a request is being sent to
// `target_url`.
virtual void RecordMetricsForURLRequest(blink::WebLocalFrame* frame,
const blink::WebURL& target_url) {}
std::vector<std::unique_ptr<const ExtensionsRendererAPIProvider>>
api_providers_;
std::unique_ptr<Dispatcher> dispatcher_;
std::unique_ptr<ResourceRequestPolicy> resource_request_policy_;
};
} // namespace extensions
#endif // EXTENSIONS_RENDERER_EXTENSIONS_RENDERER_CLIENT_H_
|