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

Side by Side Diff: webkit/tools/test_shell/plain_text_controller.cc

Issue 360006: Implementation of PlainTextController.... (Closed) Base URL: http://src.chromium.org/svn/trunk/src/
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 | Annotate | Revision Log
« 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 namespace WebKit;
15
16 TestShell* PlainTextController::shell_ = NULL;
17
18 PlainTextController::PlainTextController(TestShell* shell) {
19 // Set static shell_ variable.
20 if (!shell_)
21 shell_ = shell;
22
23 // Initialize the map that associates methods of this class with the names
24 // they will use when called by JavaScript. The actual binding of those
25 // names to their methods will be done by calling BindToJavaScript() (defined
26 // by CppBoundClass, the parent to EventSendingController).
27 BindMethod("plainText", &PlainTextController::plainText);
28
29 // The fallback method is called when an unknown method is invoked.
30 BindFallbackMethod(&PlainTextController::fallbackMethod);
31 }
32
33 void PlainTextController::plainText(
34 const CppArgumentList& args, CppVariant* result) {
35 result->SetNull();
36
37 if (args.size() < 1 || !args[0].isObject())
38 return;
39
40 // Check that passed-in object is, in fact, a range.
41 NPObject* npobject = NPVARIANT_TO_OBJECT(args[0]);
42 if (!npobject)
43 return;
44 WebRange range;
45 if (!WebBindings::getRange(npobject, &range))
46 return;
47
48 // Extract the text using the Range's text() method
49 WebString text = range.text();
50 result->Set(text.utf8());
51 }
52
53 void PlainTextController::fallbackMethod(
54 const CppArgumentList& args, CppVariant* result) {
55 std::wstring message(
56 L"JavaScript ERROR: unknown method called on PlainTextController");
57 if (!shell_->layout_test_mode()) {
58 logging::LogMessage("CONSOLE:", 0).stream() << message;
59 } else {
60 printf("CONSOLE MESSAGE: %S\n", message.c_str());
61 }
62 result->SetNull();
63 }
64
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