diff options
author | kalman <kalman@chromium.org> | 2015-03-13 17:52:26 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2015-03-14 00:53:37 +0000 |
commit | 8ee8ee9e645596d0eabda36b30e3b99c24920940 (patch) | |
tree | ea37618c0dacfe9c6913cec03b7d668d3b5c47fe /extensions/renderer/script_context_set.h | |
parent | d9e48bc847de2cde142d0fb3ea562fd0adebe3a7 (diff) | |
download | chromium_src-8ee8ee9e645596d0eabda36b30e3b99c24920940.zip chromium_src-8ee8ee9e645596d0eabda36b30e3b99c24920940.tar.gz chromium_src-8ee8ee9e645596d0eabda36b30e3b99c24920940.tar.bz2 |
Revert of Move Extension ScriptContext creation into ScriptContextSet. (patchset #3 id:40001 of https://codereview.chromium.org/995283004/)
Reason for revert:
Broke ScriptContextTest.GinRunnerLifetime.
Original issue's description:
> Move Extension ScriptContext creation into ScriptContextSet.
>
> Previously extensions::Dispatcher was responsible for creating ScriptContexts
> then Adding them to its ScriptContextSet. Now, ScriptContextSet creates them
> itself. This prepares the Extension system for later changing to lazily or
> asynchronously creating ScriptContexts.
>
> BUG=466373
> R=rockot@chromium.org
>
> Committed: https://crrev.com/75605c7fca774b95984ba67f70ba86bb5750c0f6
> Cr-Commit-Position: refs/heads/master@{#320602}
TBR=rockot@chromium.org
NOPRESUBMIT=true
NOTREECHECKS=true
NOTRY=true
BUG=466373
Review URL: https://codereview.chromium.org/1010473002
Cr-Commit-Position: refs/heads/master@{#320626}
Diffstat (limited to 'extensions/renderer/script_context_set.h')
-rw-r--r-- | extensions/renderer/script_context_set.h | 84 |
1 files changed, 20 insertions, 64 deletions
diff --git a/extensions/renderer/script_context_set.h b/extensions/renderer/script_context_set.h index ac3cb17..aa7b253 100644 --- a/extensions/renderer/script_context_set.h +++ b/extensions/renderer/script_context_set.h @@ -8,12 +8,8 @@ #include <set> #include <string> -#include "base/macros.h" -#include "base/memory/weak_ptr.h" -#include "extensions/common/extension.h" -#include "extensions/common/extension_set.h" -#include "extensions/common/features/feature.h" -#include "url/gurl.h" +#include "base/basictypes.h" +#include "base/bind.h" #include "v8/include/v8.h" class GURL; @@ -22,50 +18,39 @@ namespace base { class ListValue; } -namespace blink { -class WebLocalFrame; -class WebSecurityOrigin; -} - namespace content { class RenderView; } +namespace v8 { +class Context; +} + namespace extensions { class ScriptContext; -// A container of ScriptContexts, responsible for both creating and managing -// them. -// -// Since calling JavaScript within a context can cause any number of contexts -// to be created or destroyed, this has additional smarts to help with the set -// changing underneath callers. +// A container of ExtensionBindingsContext. Since calling JavaScript within a +// context can cause any number of contexts to be created or destroyed, this +// has additional smarts to help with the set changing underneath callers. class ScriptContextSet { public: - ScriptContextSet( - ExtensionSet* extensions, - // Set of the IDs of extensions that are active in this process. - // Must outlive this. TODO(kalman): Combine this and |extensions|. - ExtensionIdSet* active_extension_ids); - + ScriptContextSet(); ~ScriptContextSet(); - // Returns the number of contexts being tracked by this set. - // This may also include invalid contexts. TODO(kalman): Useful? - size_t size() const { return contexts_.size(); } + int size() const; - // Creates and starts managing a new ScriptContext. Ownership is held. - // Returns a weak reference to the new ScriptContext. - ScriptContext* Register(blink::WebLocalFrame* frame, - const v8::Handle<v8::Context>& v8_context, - int extension_group, - int world_id); + // Takes ownership of |context|. + void Add(ScriptContext* context); // If the specified context is contained in this set, remove it, then delete // it asynchronously. After this call returns the context object will still // be valid, but its frame() pointer will be cleared. void Remove(ScriptContext* context); + // Returns a copy to protect against changes. + typedef std::set<ScriptContext*> ContextSet; + ContextSet GetAll() const; + // Gets the ScriptContext corresponding to v8::Context::GetCurrent(), or // NULL if no such context exists. ScriptContext* GetCurrent() const; @@ -76,7 +61,7 @@ class ScriptContextSet { // Gets the ScriptContext corresponding to the specified // v8::Context or NULL if no such context exists. - ScriptContext* GetByV8Context(const v8::Handle<v8::Context>& context) const; + ScriptContext* GetByV8Context(v8::Handle<v8::Context> context) const; // Synchronously runs |callback| with each ScriptContext that belongs to // |extension_id| in |render_view|. @@ -103,39 +88,10 @@ class ScriptContextSet { // Returns the set of ScriptContexts that were removed as a result. These // are safe to interact with until the end of the current event loop, since // they're deleted asynchronously. - std::set<ScriptContext*> OnExtensionUnloaded(const std::string& extension_id); + ContextSet OnExtensionUnloaded(const std::string& extension_id); private: - // 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. - const Extension* GetExtensionFromFrameAndWorld( - const blink::WebLocalFrame* frame, - int world_id, - bool use_effective_url); - - // Returns the Feature::Context type of context for a JavaScript context. - Feature::Context ClassifyJavaScriptContext( - const Extension* extension, - int extension_group, - const GURL& url, - const blink::WebSecurityOrigin& origin); - - // Calls Remove on |context| then appends |context| to |out|. - // This is a helper designed to be used by OnExtensionUnloaded with ForEach. - void DispatchOnUnloadEventAndRemove(std::set<ScriptContext*>* out, - ScriptContext* context); - - // Weak reference to all installed Extensions. - ExtensionSet* extensions_; - - // Weak reference to all installed Extensions that are also active in this - // process. - ExtensionIdSet* active_extension_ids_; - - // The set of all ScriptContexts we own. - std::set<ScriptContext*> contexts_; + ContextSet contexts_; DISALLOW_COPY_AND_ASSIGN(ScriptContextSet); }; |