| 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/logging.h" | 7 #include "base/logging.h" |
| 8 #include "base/string_split.h" | 8 #include "base/string_split.h" |
| 9 #include "base/values.h" | 9 #include "base/values.h" |
| 10 #include "chrome/common/extensions/extension_set.h" | 10 #include "chrome/common/extensions/extension_set.h" |
| 11 #include "chrome/renderer/extensions/chrome_v8_extension.h" | 11 #include "chrome/renderer/extensions/chrome_v8_extension.h" |
| 12 #include "content/public/renderer/render_view.h" | 12 #include "content/public/renderer/render_view.h" |
| 13 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" | 13 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" |
| 14 #include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h" | 14 #include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h" |
| 15 #include "v8/include/v8.h" | 15 #include "v8/include/v8.h" |
| 16 | 16 |
| 17 namespace { | 17 namespace { |
| 18 | 18 |
| 19 const char kChromeHidden[] = "chromeHidden"; | 19 const char kChromeHidden[] = "chromeHidden"; |
| 20 | 20 |
| 21 #ifndef NDEBUG | 21 #ifndef NDEBUG |
| 22 const char kValidateCallbacks[] = "validateCallbacks"; | 22 const char kValidateCallbacks[] = "validateCallbacks"; |
| 23 #endif | 23 #endif |
| 24 | 24 |
| 25 std::string GetContextTypeDescription( |
| 26 ChromeV8Context::ContextType context_type) { |
| 27 switch (context_type) { |
| 28 case ChromeV8Context::OTHER: return "other"; |
| 29 case ChromeV8Context::CONTENT_SCRIPT: return "content script"; |
| 30 } |
| 31 NOTREACHED(); |
| 32 return ""; |
| 33 } |
| 34 |
| 25 } // namespace | 35 } // namespace |
| 26 | 36 |
| 27 | |
| 28 ChromeV8Context::ChromeV8Context(v8::Handle<v8::Context> v8_context, | 37 ChromeV8Context::ChromeV8Context(v8::Handle<v8::Context> v8_context, |
| 29 WebKit::WebFrame* web_frame, | 38 WebKit::WebFrame* web_frame, |
| 30 const std::string& extension_id) | 39 const std::string& extension_id, |
| 40 ChromeV8Context::ContextType context_type) |
| 31 : v8_context_(v8::Persistent<v8::Context>::New(v8_context)), | 41 : v8_context_(v8::Persistent<v8::Context>::New(v8_context)), |
| 32 web_frame_(web_frame), | 42 web_frame_(web_frame), |
| 33 extension_id_(extension_id) { | 43 extension_id_(extension_id), |
| 44 context_type_(context_type) { |
| 34 VLOG(1) << "Created context for extension\n" | 45 VLOG(1) << "Created context for extension\n" |
| 35 << " id: " << extension_id << "\n" | 46 << " id: " << extension_id << "\n" |
| 36 << " frame: " << web_frame_; | 47 << " frame: " << web_frame_ << "\n" |
| 48 << " context type: " << GetContextTypeDescription(context_type); |
| 37 } | 49 } |
| 38 | 50 |
| 39 ChromeV8Context::~ChromeV8Context() { | 51 ChromeV8Context::~ChromeV8Context() { |
| 40 VLOG(1) << "Destroyed context for extension\n" | 52 VLOG(1) << "Destroyed context for extension\n" |
| 41 << " id: " << extension_id_; | 53 << " id: " << extension_id_; |
| 42 v8_context_.Dispose(); | 54 v8_context_.Dispose(); |
| 43 } | 55 } |
| 44 | 56 |
| 45 // static | 57 // static |
| 46 v8::Handle<v8::Value> ChromeV8Context::GetOrCreateChromeHidden( | 58 v8::Handle<v8::Value> ChromeV8Context::GetOrCreateChromeHidden( |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 120 argv[1] = v8::Boolean::New(is_extension_process); | 132 argv[1] = v8::Boolean::New(is_extension_process); |
| 121 argv[2] = v8::Boolean::New(is_incognito_process); | 133 argv[2] = v8::Boolean::New(is_incognito_process); |
| 122 argv[3] = v8::Integer::New(manifest_version); | 134 argv[3] = v8::Integer::New(manifest_version); |
| 123 CallChromeHiddenMethod("dispatchOnLoad", arraysize(argv), argv, NULL); | 135 CallChromeHiddenMethod("dispatchOnLoad", arraysize(argv), argv, NULL); |
| 124 } | 136 } |
| 125 | 137 |
| 126 void ChromeV8Context::DispatchOnUnloadEvent() const { | 138 void ChromeV8Context::DispatchOnUnloadEvent() const { |
| 127 v8::HandleScope handle_scope; | 139 v8::HandleScope handle_scope; |
| 128 CallChromeHiddenMethod("dispatchOnUnload", 0, NULL, NULL); | 140 CallChromeHiddenMethod("dispatchOnUnload", 0, NULL, NULL); |
| 129 } | 141 } |
| OLD | NEW |