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.h" | 5 #include "chrome/renderer/extensions/chrome_v8_context.h" |
6 | 6 |
7 #include "base/debug/trace_event.h" | 7 #include "base/debug/trace_event.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "base/strings/string_split.h" | 9 #include "base/strings/string_split.h" |
10 #include "base/values.h" | 10 #include "base/values.h" |
11 #include "chrome/common/extensions/api/extension_api.h" | 11 #include "chrome/common/extensions/api/extension_api.h" |
12 #include "chrome/common/extensions/extension.h" | 12 #include "chrome/common/extensions/extension.h" |
13 #include "chrome/common/extensions/extension_set.h" | 13 #include "chrome/common/extensions/extension_set.h" |
14 #include "chrome/renderer/extensions/chrome_v8_extension.h" | 14 #include "chrome/renderer/extensions/chrome_v8_extension.h" |
15 #include "chrome/renderer/extensions/module_system.h" | 15 #include "chrome/renderer/extensions/module_system.h" |
16 #include "chrome/renderer/extensions/user_script_slave.h" | 16 #include "chrome/renderer/extensions/user_script_slave.h" |
17 #include "content/public/renderer/render_view.h" | 17 #include "content/public/renderer/render_view.h" |
18 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" | 18 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" |
19 #include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h" | 19 #include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h" |
20 #include "v8/include/v8.h" | 20 #include "v8/include/v8.h" |
21 | 21 |
22 namespace extensions { | 22 namespace extensions { |
23 | 23 |
24 namespace { | 24 namespace { |
25 | 25 |
26 const char kChromeHidden[] = "chromeHidden"; | 26 const char kChromeHidden[] = "chromeHidden"; |
27 const char kUnavailableMessage[] = "You do not have permission to access this " | |
28 "API. Ensure that the required permission " | |
29 "or manifest property is included in your " | |
30 "manifest.json."; | |
31 | |
32 const char kValidateCallbacks[] = "validateCallbacks"; | 27 const char kValidateCallbacks[] = "validateCallbacks"; |
33 const char kValidateAPI[] = "validateAPI"; | 28 const char kValidateAPI[] = "validateAPI"; |
34 | 29 |
35 } // namespace | 30 } // namespace |
36 | 31 |
37 ChromeV8Context::ChromeV8Context(v8::Handle<v8::Context> v8_context, | 32 ChromeV8Context::ChromeV8Context(v8::Handle<v8::Context> v8_context, |
38 WebKit::WebFrame* web_frame, | 33 WebKit::WebFrame* web_frame, |
39 const Extension* extension, | 34 const Extension* extension, |
40 Feature::Context context_type) | 35 Feature::Context context_type) |
41 : v8_context_(v8_context), | 36 : v8_context_(v8_context), |
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
149 argc, | 144 argc, |
150 argv); | 145 argv); |
151 if (result) | 146 if (result) |
152 *result = result_temp; | 147 *result = result_temp; |
153 | 148 |
154 return true; | 149 return true; |
155 } | 150 } |
156 | 151 |
157 const std::set<std::string>& ChromeV8Context::GetAvailableExtensionAPIs() { | 152 const std::set<std::string>& ChromeV8Context::GetAvailableExtensionAPIs() { |
158 if (!available_extension_apis_initialized_) { | 153 if (!available_extension_apis_initialized_) { |
154 // TODO(cduvall): Change this because Stubs probably fails. | |
not at google - send to devlin
2013/03/14 19:16:46
you have permission to change stubs if reasonable
cduvall
2013/03/21 22:27:55
Ended up just having to change getApiDefinitions i
| |
159 available_extension_apis_ = | 155 available_extension_apis_ = |
160 ExtensionAPI::GetSharedInstance()->GetAPIsForContext( | 156 ExtensionAPI::GetSharedInstance()->GetAllAPINames(); |
161 context_type_, | |
162 extension_, | |
163 UserScriptSlave::GetDataSourceURLForFrame(web_frame_)); | |
164 available_extension_apis_initialized_ = true; | 157 available_extension_apis_initialized_ = true; |
165 } | 158 } |
166 return available_extension_apis_; | 159 return available_extension_apis_; |
167 } | 160 } |
168 | 161 |
169 Feature::Availability ChromeV8Context::GetAvailability( | 162 Feature::Availability ChromeV8Context::GetAvailability( |
170 const std::string& api_name) { | 163 const std::string& api_name) { |
171 const std::set<std::string>& available_apis = GetAvailableExtensionAPIs(); | 164 return ExtensionAPI::GetSharedInstance()->IsAvailable( |
172 | 165 api_name, |
173 // TODO(cduvall/kalman): Switch to ExtensionAPI::IsAvailable() once Features | 166 extension_, |
174 // are complete. | 167 context_type_, |
175 if (available_apis.find(api_name) != available_apis.end()) | 168 UserScriptSlave::GetDataSourceURLForFrame(web_frame_)); |
176 return Feature::CreateAvailability(Feature::IS_AVAILABLE, ""); | |
177 | |
178 return Feature::CreateAvailability(Feature::INVALID_CONTEXT, | |
179 kUnavailableMessage); | |
180 } | 169 } |
181 | 170 |
182 void ChromeV8Context::DispatchOnLoadEvent(bool is_incognito_process, | 171 void ChromeV8Context::DispatchOnLoadEvent(bool is_incognito_process, |
183 int manifest_version) { | 172 int manifest_version) { |
184 v8::HandleScope handle_scope; | 173 v8::HandleScope handle_scope; |
185 v8::Handle<v8::Value> argv[] = { | 174 v8::Handle<v8::Value> argv[] = { |
186 v8::String::New(GetExtensionID().c_str()), | 175 v8::String::New(GetExtensionID().c_str()), |
187 v8::String::New(GetContextTypeDescription().c_str()), | 176 v8::String::New(GetContextTypeDescription().c_str()), |
188 v8::Boolean::New(is_incognito_process), | 177 v8::Boolean::New(is_incognito_process), |
189 v8::Integer::New(manifest_version), | 178 v8::Integer::New(manifest_version), |
(...skipping 12 matching lines...) Expand all Loading... | |
202 case Feature::BLESSED_EXTENSION_CONTEXT: return "BLESSED_EXTENSION"; | 191 case Feature::BLESSED_EXTENSION_CONTEXT: return "BLESSED_EXTENSION"; |
203 case Feature::UNBLESSED_EXTENSION_CONTEXT: return "UNBLESSED_EXTENSION"; | 192 case Feature::UNBLESSED_EXTENSION_CONTEXT: return "UNBLESSED_EXTENSION"; |
204 case Feature::CONTENT_SCRIPT_CONTEXT: return "CONTENT_SCRIPT"; | 193 case Feature::CONTENT_SCRIPT_CONTEXT: return "CONTENT_SCRIPT"; |
205 case Feature::WEB_PAGE_CONTEXT: return "WEB_PAGE"; | 194 case Feature::WEB_PAGE_CONTEXT: return "WEB_PAGE"; |
206 } | 195 } |
207 NOTREACHED(); | 196 NOTREACHED(); |
208 return ""; | 197 return ""; |
209 } | 198 } |
210 | 199 |
211 } // namespace extensions | 200 } // namespace extensions |
OLD | NEW |