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

Side by Side Diff: chrome/renderer/extensions/chrome_v8_context_set.cc

Issue 15855010: Make ExtensionMsg_MessageInvoke run a module system function rather than a (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix test compile Created 7 years, 6 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 #include "chrome/renderer/extensions/chrome_v8_context_set.h" 5 #include "chrome/renderer/extensions/chrome_v8_context_set.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "base/message_loop.h" 8 #include "base/message_loop.h"
9 #include "base/tracked_objects.h" 9 #include "base/tracked_objects.h"
10 #include "base/values.h" 10 #include "base/values.h"
11 #include "chrome/common/extensions/extension.h" 11 #include "chrome/common/extensions/extension.h"
12 #include "chrome/common/url_constants.h" 12 #include "chrome/common/url_constants.h"
13 #include "chrome/renderer/extensions/chrome_v8_context.h" 13 #include "chrome/renderer/extensions/chrome_v8_context.h"
14 #include "content/public/renderer/render_thread.h" 14 #include "content/public/renderer/render_thread.h"
15 #include "content/public/renderer/render_view.h" 15 #include "content/public/renderer/render_view.h"
16 #include "content/public/renderer/v8_value_converter.h"
17 #include "extensions/common/constants.h" 16 #include "extensions/common/constants.h"
18 #include "third_party/WebKit/public/platform/WebURL.h" 17 #include "third_party/WebKit/public/platform/WebURL.h"
19 #include "third_party/WebKit/public/platform/WebURLRequest.h" 18 #include "third_party/WebKit/public/platform/WebURLRequest.h"
20 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDocument.h" 19 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDocument.h"
21 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" 20 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h"
22 #include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h" 21 #include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h"
23 #include "v8/include/v8.h" 22 #include "v8/include/v8.h"
24 23
25 using content::RenderThread; 24 using content::RenderThread;
26 using content::V8ValueConverter;
27 25
28 namespace extensions { 26 namespace extensions {
29 27
30 ChromeV8ContextSet::ChromeV8ContextSet() { 28 ChromeV8ContextSet::ChromeV8ContextSet() {
31 } 29 }
32 ChromeV8ContextSet::~ChromeV8ContextSet() { 30 ChromeV8ContextSet::~ChromeV8ContextSet() {
33 } 31 }
34 32
35 int ChromeV8ContextSet::size() const { 33 int ChromeV8ContextSet::size() const {
36 return static_cast<int>(contexts_.size()); 34 return static_cast<int>(contexts_.size());
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
72 v8::Handle<v8::Context> v8_context) const { 70 v8::Handle<v8::Context> v8_context) const {
73 for (ContextSet::const_iterator iter = contexts_.begin(); 71 for (ContextSet::const_iterator iter = contexts_.begin();
74 iter != contexts_.end(); ++iter) { 72 iter != contexts_.end(); ++iter) {
75 if ((*iter)->v8_context() == v8_context) 73 if ((*iter)->v8_context() == v8_context)
76 return *iter; 74 return *iter;
77 } 75 }
78 76
79 return NULL; 77 return NULL;
80 } 78 }
81 79
82 void ChromeV8ContextSet::DispatchChromeHiddenMethod( 80 void ChromeV8ContextSet::ForEach(
83 const std::string& extension_id, 81 const std::string& extension_id,
84 const std::string& method_name, 82 content::RenderView* render_view,
85 const base::ListValue& arguments, 83 const base::Callback<void(ChromeV8Context*)>& callback) const {
86 content::RenderView* render_view) const {
87 v8::HandleScope handle_scope;
88
89 // We copy the context list, because calling into javascript may modify it 84 // We copy the context list, because calling into javascript may modify it
90 // out from under us. 85 // out from under us.
91 ContextSet contexts = GetAll(); 86 ContextSet contexts = GetAll();
92 87
93 scoped_ptr<V8ValueConverter> converter(V8ValueConverter::create());
94 for (ContextSet::iterator it = contexts.begin(); it != contexts.end(); 88 for (ContextSet::iterator it = contexts.begin(); it != contexts.end();
95 ++it) { 89 ++it) {
96 if ((*it)->v8_context().IsEmpty())
97 continue;
98
99 if (!extension_id.empty()) { 90 if (!extension_id.empty()) {
100 const Extension* extension = (*it)->extension(); 91 const Extension* extension = (*it)->extension();
101 if (!extension || (extension_id != extension->id())) 92 if (!extension || (extension_id != extension->id()))
102 continue; 93 continue;
103 } 94 }
104 95
105 content::RenderView* context_render_view = (*it)->GetRenderView(); 96 content::RenderView* context_render_view = (*it)->GetRenderView();
106 if (!context_render_view) 97 if (!context_render_view)
107 continue; 98 continue;
108 99
109 if (render_view && render_view != context_render_view) 100 if (render_view && render_view != context_render_view)
110 continue; 101 continue;
111 102
112 v8::Local<v8::Context> context(*((*it)->v8_context())); 103 callback.Run(*it);
113 std::vector<v8::Handle<v8::Value> > v8_arguments;
114 for (size_t i = 0; i < arguments.GetSize(); ++i) {
115 const base::Value* item = NULL;
116 CHECK(arguments.Get(i, &item));
117 v8_arguments.push_back(converter->ToV8Value(item, context));
118 }
119
120 v8::Handle<v8::Value> retval;
121 (*it)->CallChromeHiddenMethod(
122 method_name, v8_arguments.size(), &v8_arguments[0], &retval);
123 } 104 }
124 } 105 }
125 106
126 ChromeV8ContextSet::ContextSet ChromeV8ContextSet::OnExtensionUnloaded( 107 ChromeV8ContextSet::ContextSet ChromeV8ContextSet::OnExtensionUnloaded(
127 const std::string& extension_id) { 108 const std::string& extension_id) {
128 ContextSet contexts = GetAll(); 109 ContextSet contexts = GetAll();
129 ContextSet removed; 110 ContextSet removed;
130 111
131 // Clean up contexts belonging to the unloaded extension. This is done so 112 // Clean up contexts belonging to the unloaded extension. This is done so
132 // that content scripts (which remain injected into the page) don't continue 113 // that content scripts (which remain injected into the page) don't continue
133 // receiving events and sending messages. 114 // receiving events and sending messages.
134 for (ContextSet::iterator it = contexts.begin(); it != contexts.end(); 115 for (ContextSet::iterator it = contexts.begin(); it != contexts.end();
135 ++it) { 116 ++it) {
136 if ((*it)->extension() && (*it)->extension()->id() == extension_id) { 117 if ((*it)->extension() && (*it)->extension()->id() == extension_id) {
137 (*it)->DispatchOnUnloadEvent(); 118 (*it)->DispatchOnUnloadEvent();
138 removed.insert(*it); 119 removed.insert(*it);
139 Remove(*it); 120 Remove(*it);
140 } 121 }
141 } 122 }
142 123
143 return removed; 124 return removed;
144 } 125 }
145 126
146 } // namespace extensions 127 } // namespace extensions
OLDNEW
« no previous file with comments | « chrome/renderer/extensions/chrome_v8_context_set.h ('k') | chrome/renderer/extensions/dispatcher.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698