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

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

Issue 8761020: Only create chromeHidden object when needed. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Move GetChromeHidden to ChromeV8Context Created 9 years 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
« no previous file with comments | « chrome/renderer/extensions/chrome_v8_extension.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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_extension.h" 5 #include "chrome/renderer/extensions/chrome_v8_extension.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "base/lazy_instance.h" 8 #include "base/lazy_instance.h"
9 #include "base/stringprintf.h" 9 #include "base/stringprintf.h"
10 #include "base/string_util.h" 10 #include "base/string_util.h"
11 #include "chrome/common/extensions/extension.h" 11 #include "chrome/common/extensions/extension.h"
12 #include "chrome/common/extensions/extension_set.h" 12 #include "chrome/common/extensions/extension_set.h"
13 #include "chrome/common/extensions/api/extension_api.h" 13 #include "chrome/common/extensions/api/extension_api.h"
14 #include "chrome/renderer/extensions/chrome_v8_context.h" 14 #include "chrome/renderer/extensions/chrome_v8_context.h"
15 #include "chrome/renderer/extensions/extension_dispatcher.h" 15 #include "chrome/renderer/extensions/extension_dispatcher.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/WebDocument.h" 17 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDocument.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 "ui/base/resource/resource_bundle.h" 20 #include "ui/base/resource/resource_bundle.h"
21 21
22 using extensions::ExtensionAPI; 22 using extensions::ExtensionAPI;
23 using WebKit::WebFrame; 23 using WebKit::WebFrame;
24 using WebKit::WebView; 24 using WebKit::WebView;
25 25
26 namespace { 26 namespace {
27 27
28 const char kChromeHidden[] = "chromeHidden";
29
30 #ifndef NDEBUG
31 const char kValidateCallbacks[] = "validateCallbacks";
32 #endif
33
34 static base::LazyInstance<ChromeV8Extension::InstanceSet> g_instances = 28 static base::LazyInstance<ChromeV8Extension::InstanceSet> g_instances =
35 LAZY_INSTANCE_INITIALIZER; 29 LAZY_INSTANCE_INITIALIZER;
36 30
37 } // namespace 31 } // namespace
38 32
39 33
40 // static 34 // static
41 base::StringPiece ChromeV8Extension::GetStringResource(int resource_id) { 35 base::StringPiece ChromeV8Extension::GetStringResource(int resource_id) {
42 return ResourceBundle::GetSharedInstance().GetRawDataResource(resource_id); 36 return ResourceBundle::GetSharedInstance().GetRawDataResource(resource_id);
43 } 37 }
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after
191 return handler->HandleNativeFunction(name, arguments); 185 return handler->HandleNativeFunction(name, arguments);
192 } 186 }
193 187
194 ChromeV8ExtensionHandler* ChromeV8Extension::CreateHandler( 188 ChromeV8ExtensionHandler* ChromeV8Extension::CreateHandler(
195 ChromeV8Context* context) { 189 ChromeV8Context* context) {
196 return NULL; 190 return NULL;
197 } 191 }
198 192
199 v8::Handle<v8::Value> ChromeV8Extension::GetChromeHidden( 193 v8::Handle<v8::Value> ChromeV8Extension::GetChromeHidden(
200 const v8::Arguments& args) { 194 const v8::Arguments& args) {
201 return GetChromeHidden(v8::Context::GetCurrent()); 195 return ChromeV8Context::GetOrCreateChromeHidden(v8::Context::GetCurrent());
202 }
203
204 v8::Handle<v8::Value> ChromeV8Extension::GetChromeHidden(
205 const v8::Handle<v8::Context>& context) {
206 v8::Local<v8::Object> global = context->Global();
207 v8::Local<v8::Value> hidden = global->GetHiddenValue(
208 v8::String::New(kChromeHidden));
209
210 if (hidden.IsEmpty() || hidden->IsUndefined()) {
211 hidden = v8::Object::New();
212 global->SetHiddenValue(v8::String::New(kChromeHidden), hidden);
213
214 #ifndef NDEBUG
215 // Tell schema_generated_bindings.js to validate callbacks and events
216 // against their schema definitions in api/extension_api.json.
217 v8::Local<v8::Object>::Cast(hidden)
218 ->Set(v8::String::New(kValidateCallbacks), v8::True());
219 #endif
220 }
221
222 DCHECK(hidden->IsObject());
223 return v8::Local<v8::Object>::Cast(hidden);
224 } 196 }
225 197
226 v8::Handle<v8::Value> ChromeV8Extension::Print(const v8::Arguments& args) { 198 v8::Handle<v8::Value> ChromeV8Extension::Print(const v8::Arguments& args) {
227 if (args.Length() < 1) 199 if (args.Length() < 1)
228 return v8::Undefined(); 200 return v8::Undefined();
229 201
230 std::vector<std::string> components; 202 std::vector<std::string> components;
231 for (int i = 0; i < args.Length(); ++i) 203 for (int i = 0; i < args.Length(); ++i)
232 components.push_back(*v8::String::Utf8Value(args[i]->ToString())); 204 components.push_back(*v8::String::Utf8Value(args[i]->ToString()));
233 205
234 LOG(ERROR) << JoinString(components, ','); 206 LOG(ERROR) << JoinString(components, ',');
235 return v8::Undefined(); 207 return v8::Undefined();
236 } 208 }
OLDNEW
« no previous file with comments | « chrome/renderer/extensions/chrome_v8_extension.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698