Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(65)

Side by Side Diff: chrome/renderer/extensions/chrome_v8_context.cc

Issue 9386001: Implement a module system for the extension bindings JS. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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/stl_util.h"
8 #include "base/string_split.h" 9 #include "base/string_split.h"
9 #include "base/values.h" 10 #include "base/values.h"
10 #include "chrome/common/extensions/extension_set.h" 11 #include "chrome/common/extensions/extension_set.h"
11 #include "chrome/renderer/extensions/chrome_v8_extension.h" 12 #include "chrome/renderer/extensions/chrome_v8_extension.h"
12 #include "content/public/renderer/render_view.h" 13 #include "content/public/renderer/render_view.h"
13 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" 14 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h"
14 #include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h" 15 #include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h"
15 #include "v8/include/v8.h" 16 #include "v8/include/v8.h"
16 17
17 namespace { 18 namespace {
18 19
19 const char kChromeHidden[] = "chromeHidden"; 20 const char kChromeHidden[] = "chromeHidden";
20 21
21 #ifndef NDEBUG 22 #ifndef NDEBUG
22 const char kValidateCallbacks[] = "validateCallbacks"; 23 const char kValidateCallbacks[] = "validateCallbacks";
23 #endif 24 #endif
24 25
25 } // namespace 26 } // namespace
26 27
27 28
28 ChromeV8Context::ChromeV8Context(v8::Handle<v8::Context> v8_context, 29 ChromeV8Context::ChromeV8Context(v8::Handle<v8::Context> v8_context,
29 WebKit::WebFrame* web_frame, 30 WebKit::WebFrame* web_frame,
30 const std::string& extension_id) 31 const std::string& extension_id)
31 : v8_context_(v8::Persistent<v8::Context>::New(v8_context)), 32 : v8_context_(v8::Persistent<v8::Context>::New(v8_context)),
33 natives_(v8::Persistent<v8::Object>::New(v8::Object::New())),
Aaron Boodman 2012/02/16 01:54:42 Seems like this object should be created in v8_con
32 web_frame_(web_frame), 34 web_frame_(web_frame),
33 extension_id_(extension_id) { 35 extension_id_(extension_id) {
34 VLOG(1) << "Created context for extension\n" 36 VLOG(1) << "Created context for extension\n"
35 << " id: " << extension_id << "\n" 37 << " id: " << extension_id << "\n"
36 << " frame: " << web_frame_; 38 << " frame: " << web_frame_;
37 } 39 }
38 40
39 ChromeV8Context::~ChromeV8Context() { 41 ChromeV8Context::~ChromeV8Context() {
40 VLOG(1) << "Destroyed context for extension\n" 42 VLOG(1) << "Destroyed context for extension\n"
41 << " id: " << extension_id_; 43 << " id: " << extension_id_;
42 v8_context_.Dispose(); 44 v8_context_.Dispose();
45 STLDeleteElements(&extensions_);
Aaron Boodman 2012/02/16 01:54:42 Use base/memory/linked_ptr instead of doing this m
koz (OOO until 15th September) 2012/02/27 01:06:14 Done.
46 natives_.Dispose();
43 } 47 }
44 48
45 // static 49 // static
46 v8::Handle<v8::Value> ChromeV8Context::GetOrCreateChromeHidden( 50 v8::Handle<v8::Value> ChromeV8Context::GetOrCreateChromeHidden(
47 v8::Handle<v8::Context> context) { 51 v8::Handle<v8::Context> context) {
48 v8::Local<v8::Object> global = context->Global(); 52 v8::Local<v8::Object> global = context->Global();
49 v8::Local<v8::Value> hidden = global->GetHiddenValue( 53 v8::Local<v8::Value> hidden = global->GetHiddenValue(
50 v8::String::New(kChromeHidden)); 54 v8::String::New(kChromeHidden));
51 55
52 if (hidden.IsEmpty() || hidden->IsUndefined()) { 56 if (hidden.IsEmpty() || hidden->IsUndefined()) {
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
120 argv[1] = v8::Boolean::New(is_extension_process); 124 argv[1] = v8::Boolean::New(is_extension_process);
121 argv[2] = v8::Boolean::New(is_incognito_process); 125 argv[2] = v8::Boolean::New(is_incognito_process);
122 argv[3] = v8::Integer::New(manifest_version); 126 argv[3] = v8::Integer::New(manifest_version);
123 CallChromeHiddenMethod("dispatchOnLoad", arraysize(argv), argv, NULL); 127 CallChromeHiddenMethod("dispatchOnLoad", arraysize(argv), argv, NULL);
124 } 128 }
125 129
126 void ChromeV8Context::DispatchOnUnloadEvent() const { 130 void ChromeV8Context::DispatchOnUnloadEvent() const {
127 v8::HandleScope handle_scope; 131 v8::HandleScope handle_scope;
128 CallChromeHiddenMethod("dispatchOnUnload", 0, NULL, NULL); 132 CallChromeHiddenMethod("dispatchOnUnload", 0, NULL, NULL);
129 } 133 }
134
135 void ChromeV8Context::RegisterExtension(ChromeV8Extension* extension) {
136 extensions_.push_back(extension);
137 extension->SetNativeFunctions(natives_);
138 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698