Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(147)

Side by Side Diff: chrome/renderer/extensions/bindings_utils.h

Issue 200116: Fix bug where content scripts can get GC'd if they don't attach (Closed)
Patch Set: remove extra braces Created 11 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2009 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 CHROME_RENDERER_EXTENSIONS_BINDINGS_UTILS_H_ 5 #ifndef CHROME_RENDERER_EXTENSIONS_BINDINGS_UTILS_H_
6 #define CHROME_RENDERER_EXTENSIONS_BINDINGS_UTILS_H_ 6 #define CHROME_RENDERER_EXTENSIONS_BINDINGS_UTILS_H_
7 7
8 #include "app/resource_bundle.h" 8 #include "app/resource_bundle.h"
9 #include "base/linked_ptr.h" 9 #include "base/linked_ptr.h"
10 #include "base/singleton.h" 10 #include "base/singleton.h"
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
61 std::string extension_id; // empty if the context is not an extension 61 std::string extension_id; // empty if the context is not an extension
62 62
63 // If this context is a content script, parent will be the frame that it 63 // If this context is a content script, parent will be the frame that it
64 // was injected in. This is empty if the context is not a content script. 64 // was injected in. This is empty if the context is not a content script.
65 v8::Persistent<v8::Context> parent_context; 65 v8::Persistent<v8::Context> parent_context;
66 66
67 // The RenderView that this context belongs to. This is not guaranteed to be 67 // The RenderView that this context belongs to. This is not guaranteed to be
68 // a valid pointer, and is used for comparisons only. Do not dereference. 68 // a valid pointer, and is used for comparisons only. Do not dereference.
69 RenderView* render_view; 69 RenderView* render_view;
70 70
71 // A count of the number of events that are listening in this context. When
72 // this is zero, |context| will be a weak handle.
73 int num_connected_events;
74
71 ContextInfo(v8::Persistent<v8::Context> context, 75 ContextInfo(v8::Persistent<v8::Context> context,
72 const std::string& extension_id, 76 const std::string& extension_id,
73 v8::Persistent<v8::Context> parent_context, 77 v8::Persistent<v8::Context> parent_context,
74 RenderView* render_view) 78 RenderView* render_view)
75 : context(context), extension_id(extension_id), 79 : context(context), extension_id(extension_id),
76 parent_context(parent_context), render_view(render_view) {} 80 parent_context(parent_context), render_view(render_view),
81 num_connected_events(0) {}
77 }; 82 };
78 typedef std::list< linked_ptr<ContextInfo> > ContextList; 83 typedef std::list< linked_ptr<ContextInfo> > ContextList;
79 84
80 // Returns a mutable reference to the ContextList. 85 // Returns a mutable reference to the ContextList.
81 ContextList& GetContexts(); 86 ContextList& GetContexts();
82 87
83 // Returns a (copied) list of contexts that have the given extension_id. 88 // Returns a (copied) list of contexts that have the given extension_id.
84 ContextList GetContextsForExtension(const std::string& extension_id); 89 ContextList GetContextsForExtension(const std::string& extension_id);
85 90
86 // Returns the ContextInfo item that has the given context. 91 // Returns the ContextInfo item that has the given context.
87 ContextList::iterator FindContext(v8::Handle<v8::Context> context); 92 ContextList::iterator FindContext(v8::Handle<v8::Context> context);
88 93
94 // Returns the ContextInfo for the current v8 context.
95 ContextInfo* GetInfoForCurrentContext();
96
89 // Contains info relevant to a pending API request. 97 // Contains info relevant to a pending API request.
90 struct PendingRequest { 98 struct PendingRequest {
91 public : 99 public :
92 PendingRequest(v8::Persistent<v8::Context> context, const std::string& name) 100 PendingRequest(v8::Persistent<v8::Context> context, const std::string& name)
93 : context(context), name(name) { 101 : context(context), name(name) {
94 } 102 }
95 v8::Persistent<v8::Context> context; 103 v8::Persistent<v8::Context> context;
96 std::string name; 104 std::string name;
97 }; 105 };
98 typedef std::map<int, linked_ptr<PendingRequest> > PendingRequestMap; 106 typedef std::map<int, linked_ptr<PendingRequest> > PendingRequestMap;
(...skipping 10 matching lines...) Expand all
109 // be a sub-property like "Port.dispatchOnMessage". Returns the result of 117 // be a sub-property like "Port.dispatchOnMessage". Returns the result of
110 // the function call. If an exception is thrown an empty Handle will be 118 // the function call. If an exception is thrown an empty Handle will be
111 // returned. 119 // returned.
112 v8::Handle<v8::Value> CallFunctionInContext(v8::Handle<v8::Context> context, 120 v8::Handle<v8::Value> CallFunctionInContext(v8::Handle<v8::Context> context,
113 const std::string& function_name, int argc, 121 const std::string& function_name, int argc,
114 v8::Handle<v8::Value>* argv); 122 v8::Handle<v8::Value>* argv);
115 123
116 } // namespace bindings_utils 124 } // namespace bindings_utils
117 125
118 #endif // CHROME_RENDERER_EXTENSIONS_BINDINGS_UTILS_H_ 126 #endif // CHROME_RENDERER_EXTENSIONS_BINDINGS_UTILS_H_
OLDNEW
« no previous file with comments | « no previous file | chrome/renderer/extensions/bindings_utils.cc » ('j') | chrome/renderer/extensions/event_bindings.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698