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

Unified Diff: webkit/tools/test_shell/plain_text_controller.cc

Issue 243032: First implementation of PlainTextController. (Closed)
Patch Set: '' Created 11 years, 1 month 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
« no previous file with comments | « webkit/tools/test_shell/plain_text_controller.h ('k') | webkit/tools/test_shell/test_shell.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: webkit/tools/test_shell/plain_text_controller.cc
===================================================================
--- webkit/tools/test_shell/plain_text_controller.cc (revision 0)
+++ webkit/tools/test_shell/plain_text_controller.cc (revision 0)
@@ -0,0 +1,66 @@
+// Copyright (c) 2006-2009 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// This file contains the definition for PlainTextController.
+
+#include "webkit/tools/test_shell/plain_text_controller.h"
+#include "webkit/tools/test_shell/test_shell.h"
+
+#include "webkit/api/public/WebBindings.h"
+#include "webkit/api/public/WebRange.h"
+#include "webkit/api/public/WebString.h"
+
+using WebKit::WebBindings;
+using WebKit::WebRange;
+using WebKit::WebString;
+
+TestShell* PlainTextController::shell_ = NULL;
+
+PlainTextController::PlainTextController(TestShell* shell) {
+ // Set static shell_ variable.
+ if (!shell_)
+ shell_ = shell;
+
+ // Initialize the map that associates methods of this class with the names
+ // they will use when called by JavaScript. The actual binding of those
+ // names to their methods will be done by calling BindToJavaScript() (defined
+ // by CppBoundClass, the parent to EventSendingController).
+ BindMethod("plainText", &PlainTextController::plainText);
+
+ // The fallback method is called when an unknown method is invoked.
+ BindFallbackMethod(&PlainTextController::fallbackMethod);
+}
+
+void PlainTextController::plainText(
+ const CppArgumentList& args, CppVariant* result) {
+ result->SetNull();
+
+ if (args.size() < 1 || !args[0].isObject())
+ return;
+
+ // Check that passed-in object is, in fact, a range.
+ NPObject* npobject = NPVARIANT_TO_OBJECT(args[0]);
+ if (!npobject)
+ return;
+ WebRange range;
+ if (!WebBindings::getRange(npobject, &range))
+ return;
+
+ // Extract the text using the Range's text() method
+ WebString text = range.toPlainText();
+ result->Set(text.utf8());
+}
+
+void PlainTextController::fallbackMethod(
+ const CppArgumentList& args, CppVariant* result) {
+ std::wstring message(
+ L"JavaScript ERROR: unknown method called on PlainTextController");
+ if (!shell_->layout_test_mode()) {
+ logging::LogMessage("CONSOLE:", 0).stream() << message;
+ } else {
+ printf("CONSOLE MESSAGE: %S\n", message.c_str());
+ }
+ result->SetNull();
+}
+
Property changes on: webkit\tools\test_shell\plain_text_controller.cc
___________________________________________________________________
Added: svn:eol-style
+ LF
« no previous file with comments | « webkit/tools/test_shell/plain_text_controller.h ('k') | webkit/tools/test_shell/test_shell.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698