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/string_split.h" | 9 #include "base/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/user_script_slave.h" | 15 #include "chrome/renderer/extensions/user_script_slave.h" |
16 #include "content/public/renderer/render_view.h" | 16 #include "content/public/renderer/render_view.h" |
17 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" | 17 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" |
18 #include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h" | 18 #include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h" |
19 #include "v8/include/v8.h" | 19 #include "v8/include/v8.h" |
20 | 20 |
21 using extensions::Feature; | 21 namespace extensions { |
22 | 22 |
23 namespace { | 23 namespace { |
24 | 24 |
25 const char kChromeHidden[] = "chromeHidden"; | 25 const char kChromeHidden[] = "chromeHidden"; |
26 | 26 |
27 #ifndef NDEBUG | 27 #ifndef NDEBUG |
28 const char kValidateCallbacks[] = "validateCallbacks"; | 28 const char kValidateCallbacks[] = "validateCallbacks"; |
29 const char kValidateAPI[] = "validateAPI"; | 29 const char kValidateAPI[] = "validateAPI"; |
30 #endif | 30 #endif |
31 | 31 |
32 } // namespace | 32 } // namespace |
33 | 33 |
34 ChromeV8Context::ChromeV8Context(v8::Handle<v8::Context> v8_context, | 34 ChromeV8Context::ChromeV8Context(v8::Handle<v8::Context> v8_context, |
35 WebKit::WebFrame* web_frame, | 35 WebKit::WebFrame* web_frame, |
36 const extensions::Extension* extension, | 36 const Extension* extension, |
37 Feature::Context context_type) | 37 Feature::Context context_type) |
38 : v8_context_(v8::Persistent<v8::Context>::New(v8_context)), | 38 : v8_context_(v8::Persistent<v8::Context>::New(v8_context)), |
39 web_frame_(web_frame), | 39 web_frame_(web_frame), |
40 extension_(extension), | 40 extension_(extension), |
41 context_type_(context_type) { | 41 context_type_(context_type) { |
42 VLOG(1) << "Created context:\n" | 42 VLOG(1) << "Created context:\n" |
43 << " extension id: " << GetExtensionID() << "\n" | 43 << " extension id: " << GetExtensionID() << "\n" |
44 << " frame: " << web_frame_ << "\n" | 44 << " frame: " << web_frame_ << "\n" |
45 << " context type: " << GetContextTypeDescription(); | 45 << " context type: " << GetContextTypeDescription(); |
46 } | 46 } |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
137 argv); | 137 argv); |
138 if (result) | 138 if (result) |
139 *result = result_temp; | 139 *result = result_temp; |
140 | 140 |
141 return true; | 141 return true; |
142 } | 142 } |
143 | 143 |
144 const std::set<std::string>& ChromeV8Context::GetAvailableExtensionAPIs() { | 144 const std::set<std::string>& ChromeV8Context::GetAvailableExtensionAPIs() { |
145 if (!available_extension_apis_.get()) { | 145 if (!available_extension_apis_.get()) { |
146 available_extension_apis_ = | 146 available_extension_apis_ = |
147 extensions::ExtensionAPI::GetSharedInstance()->GetAPIsForContext( | 147 ExtensionAPI::GetSharedInstance()->GetAPIsForContext( |
148 context_type_, | 148 context_type_, |
149 extension_, | 149 extension_, |
150 extensions::UserScriptSlave::GetDataSourceURLForFrame( | 150 UserScriptSlave::GetDataSourceURLForFrame( |
151 web_frame_)).Pass(); | 151 web_frame_)).Pass(); |
152 } | 152 } |
153 return *(available_extension_apis_.get()); | 153 return *(available_extension_apis_.get()); |
154 } | 154 } |
155 | 155 |
156 void ChromeV8Context::DispatchOnLoadEvent(bool is_incognito_process, | 156 void ChromeV8Context::DispatchOnLoadEvent(bool is_incognito_process, |
157 int manifest_version) { | 157 int manifest_version) { |
158 v8::HandleScope handle_scope; | 158 v8::HandleScope handle_scope; |
159 v8::Handle<v8::Value> argv[] = { | 159 v8::Handle<v8::Value> argv[] = { |
160 v8::String::New(GetExtensionID().c_str()), | 160 v8::String::New(GetExtensionID().c_str()), |
(...skipping 13 matching lines...) Expand all Loading... |
174 switch (context_type_) { | 174 switch (context_type_) { |
175 case Feature::UNSPECIFIED_CONTEXT: return "UNSPECIFIED"; | 175 case Feature::UNSPECIFIED_CONTEXT: return "UNSPECIFIED"; |
176 case Feature::BLESSED_EXTENSION_CONTEXT: return "BLESSED_EXTENSION"; | 176 case Feature::BLESSED_EXTENSION_CONTEXT: return "BLESSED_EXTENSION"; |
177 case Feature::UNBLESSED_EXTENSION_CONTEXT: return "UNBLESSED_EXTENSION"; | 177 case Feature::UNBLESSED_EXTENSION_CONTEXT: return "UNBLESSED_EXTENSION"; |
178 case Feature::CONTENT_SCRIPT_CONTEXT: return "CONTENT_SCRIPT"; | 178 case Feature::CONTENT_SCRIPT_CONTEXT: return "CONTENT_SCRIPT"; |
179 case Feature::WEB_PAGE_CONTEXT: return "WEB_PAGE"; | 179 case Feature::WEB_PAGE_CONTEXT: return "WEB_PAGE"; |
180 } | 180 } |
181 NOTREACHED(); | 181 NOTREACHED(); |
182 return ""; | 182 return ""; |
183 } | 183 } |
| 184 |
| 185 } // namespace extensions |
OLD | NEW |