Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef EXTENSIONS_RENDERER_SCRIPT_CONTEXT_SET_H_ | 5 #ifndef EXTENSIONS_RENDERER_SCRIPT_CONTEXT_SET_H_ |
| 6 #define EXTENSIONS_RENDERER_SCRIPT_CONTEXT_SET_H_ | 6 #define EXTENSIONS_RENDERER_SCRIPT_CONTEXT_SET_H_ |
| 7 | 7 |
| 8 #include <stddef.h> | 8 #include <stddef.h> |
| 9 | 9 |
| 10 #include <set> | 10 #include <set> |
| (...skipping 22 matching lines...) Expand all Loading... | |
| 33 class ScriptContext; | 33 class ScriptContext; |
| 34 | 34 |
| 35 // A container of ScriptContexts, responsible for both creating and managing | 35 // A container of ScriptContexts, responsible for both creating and managing |
| 36 // them. | 36 // them. |
| 37 // | 37 // |
| 38 // Since calling JavaScript within a context can cause any number of contexts | 38 // Since calling JavaScript within a context can cause any number of contexts |
| 39 // to be created or destroyed, this has additional smarts to help with the set | 39 // to be created or destroyed, this has additional smarts to help with the set |
| 40 // changing underneath callers. | 40 // changing underneath callers. |
| 41 class ScriptContextSet { | 41 class ScriptContextSet { |
| 42 public: | 42 public: |
| 43 ScriptContextSet( | 43 explicit ScriptContextSet( |
| 44 // Set of the IDs of extensions that are active in this process. | 44 // Set of the IDs of extensions that are active in this process. |
| 45 // Must outlive this. TODO(kalman): Combine this and |extensions|. | 45 // Must outlive this. TODO(kalman): Combine this and |extensions|. |
| 46 ExtensionIdSet* active_extension_ids); | 46 ExtensionIdSet* active_extension_ids); |
| 47 | 47 |
| 48 ~ScriptContextSet(); | 48 ~ScriptContextSet(); |
| 49 | 49 |
| 50 // Returns the number of contexts being tracked by this set. | 50 // Returns the number of contexts being tracked by this set. |
| 51 // This may also include invalid contexts. TODO(kalman): Useful? | 51 // This may also include invalid contexts. TODO(kalman): Useful? |
| 52 size_t size() const { return contexts_.size(); } | 52 size_t size() const { return contexts_.size(); } |
| 53 | 53 |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 99 } | 99 } |
| 100 // ForEach which matches all render views. | 100 // ForEach which matches all render views. |
| 101 void ForEach(const std::string& extension_id, | 101 void ForEach(const std::string& extension_id, |
| 102 const base::Callback<void(ScriptContext*)>& callback) const { | 102 const base::Callback<void(ScriptContext*)>& callback) const { |
| 103 ForEach(extension_id, nullptr, callback); | 103 ForEach(extension_id, nullptr, callback); |
| 104 } | 104 } |
| 105 | 105 |
| 106 // Cleans up contexts belonging to an unloaded extension. | 106 // Cleans up contexts belonging to an unloaded extension. |
| 107 void OnExtensionUnloaded(const std::string& extension_id); | 107 void OnExtensionUnloaded(const std::string& extension_id); |
| 108 | 108 |
| 109 void set_lock_screen_context(bool lock_screen_context) { | |
|
Devlin
2017/06/01 22:17:58
nit: prefer set_*is*_lock_screen_context (to diffe
tbarzic
2017/06/02 00:49:05
Done.
| |
| 110 lock_screen_context_ = lock_screen_context; | |
| 111 } | |
| 112 | |
| 109 // Adds the given |context| for testing purposes. | 113 // Adds the given |context| for testing purposes. |
| 110 void AddForTesting(std::unique_ptr<ScriptContext> context); | 114 void AddForTesting(std::unique_ptr<ScriptContext> context); |
| 111 | 115 |
| 112 private: | 116 private: |
| 113 // Finds the extension for the JavaScript context associated with the | 117 // Finds the extension for the JavaScript context associated with the |
| 114 // specified |frame| and isolated world. If |world_id| is zero, finds the | 118 // specified |frame| and isolated world. If |world_id| is zero, finds the |
| 115 // extension ID associated with the main world's JavaScript context. If the | 119 // extension ID associated with the main world's JavaScript context. If the |
| 116 // JavaScript context isn't from an extension, returns empty string. | 120 // JavaScript context isn't from an extension, returns empty string. |
| 117 const Extension* GetExtensionFromFrameAndWorld( | 121 const Extension* GetExtensionFromFrameAndWorld( |
| 118 const blink::WebLocalFrame* frame, | 122 const blink::WebLocalFrame* frame, |
| 119 int world_id, | 123 int world_id, |
| 120 bool use_effective_url); | 124 bool use_effective_url); |
| 121 | 125 |
| 122 // Returns the Feature::Context type of context for a JavaScript context. | 126 // Returns the Feature::Context type of context for a JavaScript context. |
| 123 Feature::Context ClassifyJavaScriptContext( | 127 Feature::Context ClassifyJavaScriptContext( |
| 124 const Extension* extension, | 128 const Extension* extension, |
| 125 int world_id, | 129 int world_id, |
| 126 const GURL& url, | 130 const GURL& url, |
| 127 const blink::WebSecurityOrigin& origin); | 131 const blink::WebSecurityOrigin& origin); |
| 128 | 132 |
| 129 // Weak reference to all installed Extensions that are also active in this | 133 // Weak reference to all installed Extensions that are also active in this |
| 130 // process. | 134 // process. |
| 131 ExtensionIdSet* active_extension_ids_; | 135 ExtensionIdSet* active_extension_ids_; |
| 132 | 136 |
| 133 // The set of all ScriptContexts we own. | 137 // The set of all ScriptContexts we own. |
| 134 std::set<ScriptContext*> contexts_; | 138 std::set<ScriptContext*> contexts_; |
| 135 | 139 |
| 140 // Whether the script context set is associated with the renderer active on | |
| 141 // the Chrome OS lock screen. | |
| 142 bool lock_screen_context_ = false; | |
| 143 | |
| 136 DISALLOW_COPY_AND_ASSIGN(ScriptContextSet); | 144 DISALLOW_COPY_AND_ASSIGN(ScriptContextSet); |
| 137 }; | 145 }; |
| 138 | 146 |
| 139 } // namespace extensions | 147 } // namespace extensions |
| 140 | 148 |
| 141 #endif // EXTENSIONS_RENDERER_SCRIPT_CONTEXT_SET_H_ | 149 #endif // EXTENSIONS_RENDERER_SCRIPT_CONTEXT_SET_H_ |
| OLD | NEW |