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

Unified Diff: src/trusted/plugin/npapi/browser_impl_npapi.cc

Issue 3119028: Use console.log to report NaCl errors in Chrome instead of alerts (Closed) Base URL: http://nativeclient.googlecode.com/svn/trunk/src/native_client/
Patch Set: '' Created 10 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 side-by-side diff with in-line comments
Download patch
Index: src/trusted/plugin/npapi/browser_impl_npapi.cc
===================================================================
--- src/trusted/plugin/npapi/browser_impl_npapi.cc (revision 3042)
+++ src/trusted/plugin/npapi/browser_impl_npapi.cc (working copy)
@@ -110,6 +110,54 @@
return true;
}
+bool BrowserImplNpapi::AddToConsole(InstanceIdentifier instance_id,
+ const nacl::string& text) {
+#if defined(NACL_STANDALONE)
+ // We cannot be sure whether console.log is supported by the browser,
+ // so we use alerts instead.
+ return Alert(instance_id, text);
+#else
+ bool success = false;
+ // Usually these messages are important enough to call attention to them.
+ puts(text.c_str());
+
+ NPObject* window = NULL;
+ NPP npp = InstanceIdentifierToNPP(instance_id);
+ if (NPN_GetValue(npp, NPNVWindowNPObject, &window) != NPERR_NO_ERROR) {
+ return false;
+ }
+
+ NPVariant console_variant;
+ VOID_TO_NPVARIANT(console_variant);
Mark Seaborn 2010/08/20 18:45:32 If you're using gotos for cleanup you don't need t
+ if (!NPN_GetProperty(npp, window, NPN_GetStringIdentifier("console"),
+ &console_variant)) {
+ goto cleanup_window;
+ }
+ if (!NPVARIANT_IS_OBJECT(console_variant)) {
+ goto cleanup_console_variant;
+ }
+ NPObject* console_object = NPVARIANT_TO_OBJECT(console_variant);
+
+ NPVariant message; // doesn't hold its own string data, so don't release
+ STRINGN_TO_NPVARIANT(text.c_str(),
+ static_cast<uint32_t>(text.size()),
+ message);
+
+ NPVariant result;
+ VOID_TO_NPVARIANT(result);
+ success = NPN_Invoke(npp, console_object, NPN_GetStringIdentifier("log"),
+ &message, 1, &result);
+ if (success) {
+ NPN_ReleaseVariantValue(&result);
+ }
+cleanup_console_variant:
+ NPN_ReleaseVariantValue(&console_variant);
+cleanup_window:
+ NPN_ReleaseObject(window);
+ return success;
+#endif
+}
+
bool BrowserImplNpapi::Alert(InstanceIdentifier instance_id,
const nacl::string& text) {
// Usually these messages are important enough to call attention to them.
@@ -131,7 +179,7 @@
bool ok = NPN_Invoke(npp, window, NPN_GetStringIdentifier("alert"),
&message, 1, &result);
if (ok) NPN_ReleaseVariantValue(&result);
- // TODO(adonovan): NPN_ReleaseObject(window) needed?
+ NPN_ReleaseObject(window);
return ok;
}

Powered by Google App Engine
This is Rietveld 408576698