#include <map>
#include <set>
#include <string>
+#include <utility>
#include <vector>
-#include "base/memory/shared_memory.h"
+#include "base/scoped_observer.h"
#include "base/timer/timer.h"
#include "content/public/renderer/render_process_observer.h"
#include "extensions/common/event_filter.h"
#include "extensions/renderer/resource_bundle_source_map.h"
#include "extensions/renderer/script_context.h"
#include "extensions/renderer/script_context_set.h"
+#include "extensions/renderer/user_script_set_manager.h"
#include "extensions/renderer/v8_schema_registry.h"
#include "third_party/WebKit/public/platform/WebString.h"
#include "third_party/WebKit/public/platform/WebVector.h"
class ManifestPermissionSet;
class RequestSender;
class ScriptContext;
-class UserScriptSlave;
+class ScriptInjectionManager;
struct Message;
// Dispatches extension control messages sent to the renderer and stores
// renderer extension related state.
-class Dispatcher : public content::RenderProcessObserver {
+class Dispatcher : public content::RenderProcessObserver,
+ public UserScriptSetManager::Observer {
public:
explicit Dispatcher(DispatcherDelegate* delegate);
- virtual ~Dispatcher();
+ ~Dispatcher() override;
const std::set<std::string>& function_names() const {
return function_names_;
ContentWatcher* content_watcher() { return content_watcher_.get(); }
- UserScriptSlave* user_script_slave() { return user_script_slave_.get(); }
-
RequestSender* request_sender() { return request_sender_.get(); }
+ void OnRenderViewCreated(content::RenderView* render_view);
+
bool IsExtensionActive(const std::string& extension_id) const;
- // Finds the extension ID for the JavaScript context associated with the
+ // Finds the extension for the JavaScript context associated with the
// specified |frame| and isolated world. If |world_id| is zero, finds the
// extension ID associated with the main world's JavaScript context. If the
// JavaScript context isn't from an extension, returns empty string.
- std::string GetExtensionID(const blink::WebFrame* frame, int world_id);
+ const Extension* GetExtensionFromFrameAndWorld(const blink::WebFrame* frame,
+ int world_id,
+ bool use_effective_url);
void DidCreateScriptContext(blink::WebFrame* frame,
const v8::Handle<v8::Context>& context,
void ClearPortData(int port_id);
+ // Returns a list of (module name, resource id) pairs for the JS modules to
+ // add to the source map.
+ static std::vector<std::pair<std::string, int> > GetJsResources();
+ static void RegisterNativeHandlers(ModuleSystem* module_system,
+ ScriptContext* context,
+ Dispatcher* dispatcher,
+ RequestSender* request_sender,
+ V8SchemaRegistry* v8_schema_registry);
+
+ bool WasWebRequestUsedBySomeExtensions() const { return webrequest_used_; }
+
private:
friend class ::ChromeRenderViewTest;
FRIEND_TEST_ALL_PREFIXES(RendererPermissionsPolicyDelegateTest,
CannotScriptWebstore);
// RenderProcessObserver implementation:
- virtual bool OnControlMessageReceived(const IPC::Message& message) OVERRIDE;
- virtual void WebKitInitialized() OVERRIDE;
- virtual void IdleNotification() OVERRIDE;
- virtual void OnRenderProcessShutdown() OVERRIDE;
+ bool OnControlMessageReceived(const IPC::Message& message) override;
+ void WebKitInitialized() override;
+ void IdleNotification() override;
+ void OnRenderProcessShutdown() override;
void OnActivateExtension(const std::string& extension_id);
void OnCancelSuspend(const std::string& extension_id);
const ExtensionsClient::ScriptingWhitelist& extension_ids);
void OnSetSystemFont(const std::string& font_family,
const std::string& font_size);
- void OnShouldSuspend(const std::string& extension_id, int sequence_id);
+ void OnShouldSuspend(const std::string& extension_id, uint64 sequence_id);
void OnSuspend(const std::string& extension_id);
+ void OnTransferBlobs(const std::vector<std::string>& blob_uuids);
void OnUnloaded(const std::string& id);
void OnUpdatePermissions(const ExtensionMsg_UpdatePermissions_Params& params);
- void OnUpdateTabSpecificPermissions(int page_id,
+ void OnUpdateTabSpecificPermissions(const GURL& url,
int tab_id,
const std::string& extension_id,
const URLPatternSet& origin_set);
- void OnUpdateUserScripts(base::SharedMemoryHandle scripts);
- void OnUsingWebRequestAPI(bool adblock,
- bool adblock_plus,
- bool other_webrequest);
+ void OnUsingWebRequestAPI(bool webrequest_used);
+
+ // UserScriptSetManager::Observer implementation.
+ void OnUserScriptsUpdated(const std::set<std::string>& changed_extensions,
+ const std::vector<UserScript*>& scripts) override;
void UpdateActiveExtensions();
// Sets up the host permissions for |extension|.
- void InitOriginPermissions(const Extension* extension,
- Feature::Context context_type);
- void UpdateOriginPermissions(UpdatedExtensionPermissionsInfo::Reason reason,
- const Extension* extension,
- const URLPatternSet& origins);
+ void InitOriginPermissions(const Extension* extension);
+
+ // Updates the host permissions for extension to include only those in
+ // |new_patterns|, and remove from |old_patterns| that are no longer allowed.
+ void UpdateOriginPermissions(const Extension* extension,
+ const URLPatternSet& old_patterns,
+ const URLPatternSet& new_patterns);
// Enable custom element whitelist in Apps.
void EnableCustomElementWhiteList();
scoped_ptr<ContentWatcher> content_watcher_;
- scoped_ptr<UserScriptSlave> user_script_slave_;
+ scoped_ptr<UserScriptSetManager> user_script_set_manager_;
+
+ scoped_ptr<ScriptInjectionManager> script_injection_manager_;
// Same as above, but on a longer timer and will run even if the process is
// not idle, to ensure that IdleHandle gets called eventually.
// True once WebKit has been initialized (and it is therefore safe to poke).
bool is_webkit_initialized_;
+ // It is important for this to come after the ScriptInjectionManager, so that
+ // the observer is destroyed before the UserScriptSet.
+ ScopedObserver<UserScriptSetManager, UserScriptSetManager::Observer>
+ user_script_set_manager_observer_;
+
+ // Status of webrequest usage.
+ bool webrequest_used_;
+
DISALLOW_COPY_AND_ASSIGN(Dispatcher);
};