OLD | NEW |
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/v8_value_converter.h" | 15 #include "content/public/renderer/v8_value_converter.h" |
16 #include "content/public/renderer/render_view.h" | 16 #include "content/public/renderer/render_view.h" |
17 #include "v8/include/v8.h" | 17 #include "v8/include/v8.h" |
18 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDocument.h" | 18 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDocument.h" |
19 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" | 19 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" |
20 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebURL.h" | 20 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebURL.h" |
21 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebURLReques
t.h" | 21 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebURLReques
t.h" |
22 #include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h" | 22 #include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h" |
23 | 23 |
24 using content::RenderThread; | 24 using content::RenderThread; |
25 using content::V8ValueConverter; | 25 using content::V8ValueConverter; |
26 | 26 |
| 27 namespace extensions { |
| 28 |
27 namespace { | 29 namespace { |
28 | 30 |
29 // Returns true if the extension running in the given |render_view| has | 31 // Returns true if the extension running in the given |render_view| has |
30 // sufficient permissions to access the data. | 32 // sufficient permissions to access the data. |
31 // | 33 // |
32 // TODO(aa): This looks super suspicious. Is it correct? Can we use something | 34 // TODO(aa): This looks super suspicious. Is it correct? Can we use something |
33 // else already in the system? Should it be moved elsewhere? | 35 // else already in the system? Should it be moved elsewhere? |
34 bool HasSufficientPermissions(content::RenderView* render_view, | 36 bool HasSufficientPermissions(content::RenderView* render_view, |
35 const GURL& event_url) { | 37 const GURL& event_url) { |
36 // During unit tests, we might be invoked without a v8 context. In these | 38 // During unit tests, we might be invoked without a v8 context. In these |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
112 // out from under us. | 114 // out from under us. |
113 ContextSet contexts = GetAll(); | 115 ContextSet contexts = GetAll(); |
114 | 116 |
115 scoped_ptr<V8ValueConverter> converter(V8ValueConverter::create()); | 117 scoped_ptr<V8ValueConverter> converter(V8ValueConverter::create()); |
116 for (ContextSet::iterator it = contexts.begin(); it != contexts.end(); | 118 for (ContextSet::iterator it = contexts.begin(); it != contexts.end(); |
117 ++it) { | 119 ++it) { |
118 if ((*it)->v8_context().IsEmpty()) | 120 if ((*it)->v8_context().IsEmpty()) |
119 continue; | 121 continue; |
120 | 122 |
121 if (!extension_id.empty()) { | 123 if (!extension_id.empty()) { |
122 const extensions::Extension* extension = (*it)->extension(); | 124 const Extension* extension = (*it)->extension(); |
123 if (!extension || (extension_id != extension->id())) | 125 if (!extension || (extension_id != extension->id())) |
124 continue; | 126 continue; |
125 } | 127 } |
126 | 128 |
127 content::RenderView* context_render_view = (*it)->GetRenderView(); | 129 content::RenderView* context_render_view = (*it)->GetRenderView(); |
128 if (!context_render_view) | 130 if (!context_render_view) |
129 continue; | 131 continue; |
130 | 132 |
131 if (render_view && render_view != context_render_view) | 133 if (render_view && render_view != context_render_view) |
132 continue; | 134 continue; |
133 | 135 |
134 if (!HasSufficientPermissions(context_render_view, event_url)) | 136 if (!HasSufficientPermissions(context_render_view, event_url)) |
135 continue; | 137 continue; |
136 | 138 |
137 v8::Local<v8::Context> context(*((*it)->v8_context())); | 139 v8::Local<v8::Context> context(*((*it)->v8_context())); |
138 std::vector<v8::Handle<v8::Value> > v8_arguments; | 140 std::vector<v8::Handle<v8::Value> > v8_arguments; |
139 for (size_t i = 0; i < arguments.GetSize(); ++i) { | 141 for (size_t i = 0; i < arguments.GetSize(); ++i) { |
140 const base::Value* item = NULL; | 142 const base::Value* item = NULL; |
141 CHECK(arguments.Get(i, &item)); | 143 CHECK(arguments.Get(i, &item)); |
142 v8_arguments.push_back(converter->ToV8Value(item, context)); | 144 v8_arguments.push_back(converter->ToV8Value(item, context)); |
143 } | 145 } |
144 | 146 |
145 v8::Handle<v8::Value> retval; | 147 v8::Handle<v8::Value> retval; |
146 (*it)->CallChromeHiddenMethod( | 148 (*it)->CallChromeHiddenMethod( |
147 method_name, v8_arguments.size(), &v8_arguments[0], &retval); | 149 method_name, v8_arguments.size(), &v8_arguments[0], &retval); |
148 } | 150 } |
149 } | 151 } |
| 152 |
| 153 } // namespace extensions |
OLD | NEW |