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

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

Issue 7640005: Add a Print() method to bindings JS for last resort debugging. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 9 years, 4 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) 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/bindings_utils.h" 5 #include "chrome/renderer/extensions/bindings_utils.h"
6 6
7 #include "base/logging.h"
7 #include "base/lazy_instance.h" 8 #include "base/lazy_instance.h"
8 #include "base/stringprintf.h" 9 #include "base/stringprintf.h"
9 #include "base/string_split.h" 10 #include "base/string_split.h"
11 #include "base/string_util.h"
10 #include "chrome/common/extensions/extension.h" 12 #include "chrome/common/extensions/extension.h"
11 #include "chrome/common/extensions/extension_set.h" 13 #include "chrome/common/extensions/extension_set.h"
12 #include "chrome/renderer/extensions/extension_dispatcher.h" 14 #include "chrome/renderer/extensions/extension_dispatcher.h"
13 #include "content/renderer/render_view.h" 15 #include "content/renderer/render_view.h"
14 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDocument.h" 16 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDocument.h"
15 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" 17 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h"
16 #include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h" 18 #include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h"
17 #include "v8/include/v8.h" 19 #include "v8/include/v8.h"
18 20
19 using WebKit::WebFrame; 21 using WebKit::WebFrame;
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
77 v8::ThrowException(v8::Exception::Error(v8::String::New(error_msg.c_str()))); 79 v8::ThrowException(v8::Exception::Error(v8::String::New(error_msg.c_str())));
78 return false; 80 return false;
79 } 81 }
80 82
81 v8::Handle<v8::FunctionTemplate> 83 v8::Handle<v8::FunctionTemplate>
82 ExtensionBase::GetNativeFunction(v8::Handle<v8::String> name) { 84 ExtensionBase::GetNativeFunction(v8::Handle<v8::String> name) {
83 if (name->Equals(v8::String::New("GetChromeHidden"))) { 85 if (name->Equals(v8::String::New("GetChromeHidden"))) {
84 return v8::FunctionTemplate::New(GetChromeHidden); 86 return v8::FunctionTemplate::New(GetChromeHidden);
85 } 87 }
86 88
89 if (name->Equals(v8::String::New("Print"))) {
90 return v8::FunctionTemplate::New(Print);
91 }
92
87 return v8::Handle<v8::FunctionTemplate>(); 93 return v8::Handle<v8::FunctionTemplate>();
88 } 94 }
89 95
90 v8::Handle<v8::Value> ExtensionBase::GetChromeHidden( 96 v8::Handle<v8::Value> ExtensionBase::GetChromeHidden(
91 const v8::Arguments& args) { 97 const v8::Arguments& args) {
92 v8::Local<v8::Context> context = v8::Context::GetCurrent(); 98 v8::Local<v8::Context> context = v8::Context::GetCurrent();
93 v8::Local<v8::Object> global = context->Global(); 99 v8::Local<v8::Object> global = context->Global();
94 v8::Local<v8::Value> hidden = global->GetHiddenValue( 100 v8::Local<v8::Value> hidden = global->GetHiddenValue(
95 v8::String::New(kChromeHidden)); 101 v8::String::New(kChromeHidden));
96 102
97 if (hidden.IsEmpty() || hidden->IsUndefined()) { 103 if (hidden.IsEmpty() || hidden->IsUndefined()) {
98 hidden = v8::Object::New(); 104 hidden = v8::Object::New();
99 global->SetHiddenValue(v8::String::New(kChromeHidden), hidden); 105 global->SetHiddenValue(v8::String::New(kChromeHidden), hidden);
100 106
101 #ifndef NDEBUG 107 #ifndef NDEBUG
102 // Tell extension_process_bindings.js to validate callbacks and events 108 // Tell extension_process_bindings.js to validate callbacks and events
103 // against their schema definitions in api/extension_api.json. 109 // against their schema definitions in api/extension_api.json.
104 v8::Local<v8::Object>::Cast(hidden) 110 v8::Local<v8::Object>::Cast(hidden)
105 ->Set(v8::String::New(kValidateCallbacks), v8::True()); 111 ->Set(v8::String::New(kValidateCallbacks), v8::True());
106 #endif 112 #endif
107 } 113 }
108 114
109 DCHECK(hidden->IsObject()); 115 DCHECK(hidden->IsObject());
110 return hidden; 116 return hidden;
111 } 117 }
112 118
119 v8::Handle<v8::Value> ExtensionBase::Print(const v8::Arguments& args) {
120 if (args.Length() < 1)
121 return v8::Undefined();
122
123 std::vector<std::string> components;
124 for (int i = 0; i < args.Length(); ++i)
125 components.push_back(*v8::String::Utf8Value(args[i]->ToString()));
126
127 LOG(ERROR) << JoinString(components, ',');
128 return v8::Undefined();
129 }
130
113 ContextInfo::ContextInfo(v8::Persistent<v8::Context> context, 131 ContextInfo::ContextInfo(v8::Persistent<v8::Context> context,
114 const std::string& extension_id, 132 const std::string& extension_id,
115 WebKit::WebFrame* parent_frame, 133 WebKit::WebFrame* parent_frame,
116 RenderView* render_view) 134 RenderView* render_view)
117 : context(context), 135 : context(context),
118 extension_id(extension_id), 136 extension_id(extension_id),
119 parent_frame(parent_frame), 137 parent_frame(parent_frame),
120 render_view(render_view), 138 render_view(render_view),
121 num_connected_events(0) { 139 num_connected_events(0) {
122 } 140 }
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
213 } 231 }
214 232
215 v8::Local<v8::Function> function = v8::Local<v8::Function>::Cast(value); 233 v8::Local<v8::Function> function = v8::Local<v8::Function>::Cast(value);
216 if (!function.IsEmpty()) 234 if (!function.IsEmpty())
217 return function->Call(v8::Object::New(), argc, argv); 235 return function->Call(v8::Object::New(), argc, argv);
218 236
219 return v8::Undefined(); 237 return v8::Undefined();
220 } 238 }
221 239
222 } // namespace bindings_utils 240 } // namespace bindings_utils
OLDNEW
« no previous file with comments | « chrome/renderer/extensions/bindings_utils.h ('k') | chrome/renderer/resources/event_bindings.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698