OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "content/shell/renderer/ipc_echo.h" | 5 #include "content/shell/renderer/ipc_echo.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "content/shell/common/shell_messages.h" | 8 #include "content/shell/common/shell_messages.h" |
9 #include "content/shell/renderer/binding_helpers.h" | 9 #include "content/shell/renderer/binding_helpers.h" |
10 #include "gin/object_template_builder.h" | 10 #include "gin/object_template_builder.h" |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
75 blink::WebFrame* frame) { | 75 blink::WebFrame* frame) { |
76 std::vector<std::string> names; | 76 std::vector<std::string> names; |
77 names.push_back("ipcEcho"); | 77 names.push_back("ipcEcho"); |
78 return InstallAsWindowProperties( | 78 return InstallAsWindowProperties( |
79 new IPCEchoBindings(echo), frame, names); | 79 new IPCEchoBindings(echo), frame, names); |
80 } | 80 } |
81 | 81 |
82 IPCEcho::IPCEcho(blink::WebDocument document, | 82 IPCEcho::IPCEcho(blink::WebDocument document, |
83 IPC::Sender* sender, | 83 IPC::Sender* sender, |
84 int routing_id) | 84 int routing_id) |
85 : weak_factory_(this), | 85 : document_(document), sender_(sender), routing_id_(routing_id), |
86 document_(document), sender_(sender), routing_id_(routing_id), | 86 last_echo_id_(0), |
87 last_echo_id_(0) { | 87 weak_factory_(this) { |
88 } | 88 } |
89 | 89 |
90 IPCEcho::~IPCEcho() { | 90 IPCEcho::~IPCEcho() { |
91 } | 91 } |
92 | 92 |
93 void IPCEcho::RequestEcho(int id, int size) { | 93 void IPCEcho::RequestEcho(int id, int size) { |
94 sender_->Send(new ShellViewHostMsg_EchoPing( | 94 sender_->Send(new ShellViewHostMsg_EchoPing( |
95 routing_id_, id, std::string(size, '*'))); | 95 routing_id_, id, std::string(size, '*'))); |
96 } | 96 } |
97 | 97 |
98 void IPCEcho::DidRespondEcho(int id, int size) { | 98 void IPCEcho::DidRespondEcho(int id, int size) { |
99 last_echo_id_ = id; | 99 last_echo_id_ = id; |
100 last_echo_size_ = size; | 100 last_echo_size_ = size; |
101 blink::WebString eventName = blink::WebString::fromUTF8("CustomEvent"); | 101 blink::WebString eventName = blink::WebString::fromUTF8("CustomEvent"); |
102 blink::WebString eventType = blink::WebString::fromUTF8("pong"); | 102 blink::WebString eventType = blink::WebString::fromUTF8("pong"); |
103 blink::WebDOMEvent event = document_.createEvent(eventName); | 103 blink::WebDOMEvent event = document_.createEvent(eventName); |
104 event.to<blink::WebDOMCustomEvent>().initCustomEvent( | 104 event.to<blink::WebDOMCustomEvent>().initCustomEvent( |
105 eventType, false, false, blink::WebSerializedScriptValue()); | 105 eventType, false, false, blink::WebSerializedScriptValue()); |
106 document_.dispatchEvent(event); | 106 document_.dispatchEvent(event); |
107 } | 107 } |
108 | 108 |
109 void IPCEcho::Install(blink::WebFrame* frame) { | 109 void IPCEcho::Install(blink::WebFrame* frame) { |
110 IPCEchoBindings::Install(weak_factory_.GetWeakPtr(), frame); | 110 IPCEchoBindings::Install(weak_factory_.GetWeakPtr(), frame); |
111 } | 111 } |
112 | 112 |
113 } // namespace content | 113 } // namespace content |
OLD | NEW |