| 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/extension_set.h" | 11 #include "chrome/common/extensions/extension_set.h" |
| 12 #include "chrome/renderer/extensions/chrome_v8_extension.h" | 12 #include "chrome/renderer/extensions/chrome_v8_extension.h" |
| 13 #include "content/public/renderer/render_view.h" | 13 #include "content/public/renderer/render_view.h" |
| 14 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" | 14 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" |
| 15 #include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h" | 15 #include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h" |
| 16 #include "v8/include/v8.h" | 16 #include "v8/include/v8.h" |
| 17 | 17 |
| 18 using extensions::Feature; |
| 19 |
| 18 namespace { | 20 namespace { |
| 19 | 21 |
| 20 const char kChromeHidden[] = "chromeHidden"; | 22 const char kChromeHidden[] = "chromeHidden"; |
| 21 | 23 |
| 22 #ifndef NDEBUG | 24 #ifndef NDEBUG |
| 23 const char kValidateCallbacks[] = "validateCallbacks"; | 25 const char kValidateCallbacks[] = "validateCallbacks"; |
| 24 #endif | 26 #endif |
| 25 | 27 |
| 26 std::string GetContextTypeDescription( | 28 std::string GetContextTypeDescription(Feature::Context context_type) { |
| 27 ChromeV8Context::ContextType context_type) { | |
| 28 switch (context_type) { | 29 switch (context_type) { |
| 29 case ChromeV8Context::OTHER: return "other"; | 30 case Feature::UNSPECIFIED_CONTEXT: return "unspecified"; |
| 30 case ChromeV8Context::CONTENT_SCRIPT: return "content script"; | 31 case Feature::PRIVILEGED_CONTEXT: return "privileged"; |
| 32 case Feature::UNPRIVILEGED_CONTEXT: return "unprivileged"; |
| 33 case Feature::CONTENT_SCRIPT_CONTEXT: return "content script"; |
| 34 case Feature::WEB_PAGE_CONTEXT: return "web page"; |
| 31 } | 35 } |
| 32 NOTREACHED(); | 36 NOTREACHED(); |
| 33 return ""; | 37 return ""; |
| 34 } | 38 } |
| 35 | 39 |
| 36 } // namespace | 40 } // namespace |
| 37 | 41 |
| 38 ChromeV8Context::ChromeV8Context(v8::Handle<v8::Context> v8_context, | 42 ChromeV8Context::ChromeV8Context(v8::Handle<v8::Context> v8_context, |
| 39 WebKit::WebFrame* web_frame, | 43 WebKit::WebFrame* web_frame, |
| 40 const std::string& extension_id, | 44 const std::string& extension_id, |
| 41 ChromeV8Context::ContextType context_type) | 45 Feature::Context context_type) |
| 42 : v8_context_(v8::Persistent<v8::Context>::New(v8_context)), | 46 : v8_context_(v8::Persistent<v8::Context>::New(v8_context)), |
| 43 web_frame_(web_frame), | 47 web_frame_(web_frame), |
| 44 extension_id_(extension_id), | 48 extension_id_(extension_id), |
| 45 context_type_(context_type) { | 49 context_type_(context_type) { |
| 46 VLOG(1) << "Created context for extension\n" | 50 VLOG(1) << "Created context for extension\n" |
| 47 << " id: " << extension_id << "\n" | 51 << " id: " << extension_id << "\n" |
| 48 << " frame: " << web_frame_ << "\n" | 52 << " frame: " << web_frame_ << "\n" |
| 49 << " context type: " << GetContextTypeDescription(context_type); | 53 << " context type: " << GetContextTypeDescription(context_type); |
| 50 } | 54 } |
| 51 | 55 |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 136 argv[1] = v8::Boolean::New(is_extension_process); | 140 argv[1] = v8::Boolean::New(is_extension_process); |
| 137 argv[2] = v8::Boolean::New(is_incognito_process); | 141 argv[2] = v8::Boolean::New(is_incognito_process); |
| 138 argv[3] = v8::Integer::New(manifest_version); | 142 argv[3] = v8::Integer::New(manifest_version); |
| 139 CallChromeHiddenMethod("dispatchOnLoad", arraysize(argv), argv, NULL); | 143 CallChromeHiddenMethod("dispatchOnLoad", arraysize(argv), argv, NULL); |
| 140 } | 144 } |
| 141 | 145 |
| 142 void ChromeV8Context::DispatchOnUnloadEvent() const { | 146 void ChromeV8Context::DispatchOnUnloadEvent() const { |
| 143 v8::HandleScope handle_scope; | 147 v8::HandleScope handle_scope; |
| 144 CallChromeHiddenMethod("dispatchOnUnload", 0, NULL, NULL); | 148 CallChromeHiddenMethod("dispatchOnUnload", 0, NULL, NULL); |
| 145 } | 149 } |
| OLD | NEW |