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 "extensions/browser/api/messaging/native_message_host.h" | 5 #include "extensions/browser/api/messaging/native_message_host.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/bind_helpers.h" | 10 #include "base/bind_helpers.h" |
(...skipping 25 matching lines...) Expand all Loading... |
36 "chrome-extension://knldjmfmopnpolahpmmgbagdohdnhkik/"}; | 36 "chrome-extension://knldjmfmopnpolahpmmgbagdohdnhkik/"}; |
37 | 37 |
38 class EchoHost : public NativeMessageHost { | 38 class EchoHost : public NativeMessageHost { |
39 public: | 39 public: |
40 static scoped_ptr<NativeMessageHost> Create() { | 40 static scoped_ptr<NativeMessageHost> Create() { |
41 return scoped_ptr<NativeMessageHost>(new EchoHost()); | 41 return scoped_ptr<NativeMessageHost>(new EchoHost()); |
42 } | 42 } |
43 | 43 |
44 EchoHost() : message_number_(0), client_(NULL) {} | 44 EchoHost() : message_number_(0), client_(NULL) {} |
45 | 45 |
46 virtual void Start(Client* client) OVERRIDE { | 46 virtual void Start(Client* client) override { |
47 client_ = client; | 47 client_ = client; |
48 } | 48 } |
49 | 49 |
50 virtual void OnMessage(const std::string& request_string) OVERRIDE { | 50 virtual void OnMessage(const std::string& request_string) override { |
51 scoped_ptr<base::Value> request_value( | 51 scoped_ptr<base::Value> request_value( |
52 base::JSONReader::Read(request_string)); | 52 base::JSONReader::Read(request_string)); |
53 scoped_ptr<base::DictionaryValue> request( | 53 scoped_ptr<base::DictionaryValue> request( |
54 static_cast<base::DictionaryValue*>(request_value.release())); | 54 static_cast<base::DictionaryValue*>(request_value.release())); |
55 if (request_string.find("stopHostTest") != std::string::npos) { | 55 if (request_string.find("stopHostTest") != std::string::npos) { |
56 client_->CloseChannel(kNativeHostExited); | 56 client_->CloseChannel(kNativeHostExited); |
57 } else if (request_string.find("bigMessageTest") != std::string::npos) { | 57 } else if (request_string.find("bigMessageTest") != std::string::npos) { |
58 client_->CloseChannel(kHostInputOuputError); | 58 client_->CloseChannel(kHostInputOuputError); |
59 } else { | 59 } else { |
60 ProcessEcho(*request); | 60 ProcessEcho(*request); |
61 } | 61 } |
62 }; | 62 }; |
63 | 63 |
64 virtual scoped_refptr<base::SingleThreadTaskRunner> task_runner() | 64 virtual scoped_refptr<base::SingleThreadTaskRunner> task_runner() |
65 const OVERRIDE { | 65 const override { |
66 return base::MessageLoopProxy::current(); | 66 return base::MessageLoopProxy::current(); |
67 }; | 67 }; |
68 | 68 |
69 private: | 69 private: |
70 void ProcessEcho(const base::DictionaryValue& request) { | 70 void ProcessEcho(const base::DictionaryValue& request) { |
71 scoped_ptr<base::DictionaryValue> response(new base::DictionaryValue()); | 71 scoped_ptr<base::DictionaryValue> response(new base::DictionaryValue()); |
72 response->SetInteger("id", ++message_number_); | 72 response->SetInteger("id", ++message_number_); |
73 response->Set("echo", request.DeepCopy()); | 73 response->Set("echo", request.DeepCopy()); |
74 response->SetString("caller_url", kEchoHostOrigins[0]); | 74 response->SetString("caller_url", kEchoHostOrigins[0]); |
75 std::string response_string; | 75 std::string response_string; |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
140 } | 140 } |
141 *error = kForbiddenError; | 141 *error = kForbiddenError; |
142 return nullptr; | 142 return nullptr; |
143 } | 143 } |
144 } | 144 } |
145 *error = kNotFoundError; | 145 *error = kNotFoundError; |
146 return nullptr; | 146 return nullptr; |
147 } | 147 } |
148 | 148 |
149 } // namespace extensions | 149 } // namespace extensions |
OLD | NEW |