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

Side by Side 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 unified diff | 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 »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Property Changes:
Added: svn:eol-style
+ LF
OLDNEW
(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 "webkit/api/public/WebBindings.h"
11 #include "webkit/api/public/WebRange.h"
12 #include "webkit/api/public/WebString.h"
13
14 using WebKit::WebBindings;
15 using WebKit::WebRange;
16 using WebKit::WebString;
17
18 TestShell* PlainTextController::shell_ = NULL;
19
20 PlainTextController::PlainTextController(TestShell* shell) {
21 // Set static shell_ variable.
22 if (!shell_)
23 shell_ = shell;
24
25 // Initialize the map that associates methods of this class with the names
26 // they will use when called by JavaScript. The actual binding of those
27 // names to their methods will be done by calling BindToJavaScript() (defined
28 // by CppBoundClass, the parent to EventSendingController).
29 BindMethod("plainText", &PlainTextController::plainText);
30
31 // The fallback method is called when an unknown method is invoked.
32 BindFallbackMethod(&PlainTextController::fallbackMethod);
33 }
34
35 void PlainTextController::plainText(
36 const CppArgumentList& args, CppVariant* result) {
37 result->SetNull();
38
39 if (args.size() < 1 || !args[0].isObject())
40 return;
41
42 // Check that passed-in object is, in fact, a range.
43 NPObject* npobject = NPVARIANT_TO_OBJECT(args[0]);
44 if (!npobject)
45 return;
46 WebRange range;
47 if (!WebBindings::getRange(npobject, &range))
48 return;
49
50 // Extract the text using the Range's text() method
51 WebString text = range.toPlainText();
52 result->Set(text.utf8());
53 }
54
55 void PlainTextController::fallbackMethod(
56 const CppArgumentList& args, CppVariant* result) {
57 std::wstring message(
58 L"JavaScript ERROR: unknown method called on PlainTextController");
59 if (!shell_->layout_test_mode()) {
60 logging::LogMessage("CONSOLE:", 0).stream() << message;
61 } else {
62 printf("CONSOLE MESSAGE: %S\n", message.c_str());
63 }
64 result->SetNull();
65 }
66
OLDNEW
« 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