| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2006-2009 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 // This file contains the definition for PlainTextController. | |
| 6 | |
| 7 #include "webkit/tools/test_shell/plain_text_controller.h" | |
| 8 #include "webkit/tools/test_shell/test_shell.h" | |
| 9 | |
| 10 #include "third_party/WebKit/Source/WebKit/chromium/public/WebBindings.h" | |
| 11 #include "third_party/WebKit/Source/WebKit/chromium/public/WebCString.h" | |
| 12 #include "third_party/WebKit/Source/WebKit/chromium/public/WebRange.h" | |
| 13 #include "third_party/WebKit/Source/WebKit/chromium/public/WebString.h" | |
| 14 | |
| 15 using WebKit::WebBindings; | |
| 16 using WebKit::WebRange; | |
| 17 using WebKit::WebString; | |
| 18 | |
| 19 TestShell* PlainTextController::shell_ = NULL; | |
| 20 | |
| 21 PlainTextController::PlainTextController(TestShell* shell) { | |
| 22 // Set static shell_ variable. | |
| 23 if (!shell_) | |
| 24 shell_ = shell; | |
| 25 | |
| 26 // Initialize the map that associates methods of this class with the names | |
| 27 // they will use when called by JavaScript. The actual binding of those | |
| 28 // names to their methods will be done by calling BindToJavaScript() (defined | |
| 29 // by CppBoundClass, the parent to EventSendingController). | |
| 30 BindMethod("plainText", &PlainTextController::plainText); | |
| 31 | |
| 32 // The fallback method is called when an unknown method is invoked. | |
| 33 BindFallbackMethod(&PlainTextController::fallbackMethod); | |
| 34 } | |
| 35 | |
| 36 void PlainTextController::plainText( | |
| 37 const CppArgumentList& args, CppVariant* result) { | |
| 38 result->SetNull(); | |
| 39 | |
| 40 if (args.size() < 1 || !args[0].isObject()) | |
| 41 return; | |
| 42 | |
| 43 // Check that passed-in object is, in fact, a range. | |
| 44 NPObject* npobject = NPVARIANT_TO_OBJECT(args[0]); | |
| 45 if (!npobject) | |
| 46 return; | |
| 47 WebRange range; | |
| 48 if (!WebBindings::getRange(npobject, &range)) | |
| 49 return; | |
| 50 | |
| 51 // Extract the text using the Range's text() method | |
| 52 WebString text = range.toPlainText(); | |
| 53 result->Set(text.utf8()); | |
| 54 } | |
| 55 | |
| 56 void PlainTextController::fallbackMethod( | |
| 57 const CppArgumentList& args, CppVariant* result) { | |
| 58 std::wstring message( | |
| 59 L"JavaScript ERROR: unknown method called on PlainTextController"); | |
| 60 if (!shell_->layout_test_mode()) { | |
| 61 logging::LogMessage("CONSOLE:", 0).stream() << message; | |
| 62 } else { | |
| 63 printf("CONSOLE MESSAGE: %S\n", message.c_str()); | |
| 64 } | |
| 65 result->SetNull(); | |
| 66 } | |
| 67 | |
| OLD | NEW |