| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "chrome/browser/devtools/devtools_embedder_message_dispatcher.h" | 5 #include "chrome/browser/devtools/devtools_embedder_message_dispatcher.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/values.h" | 8 #include "base/values.h" |
| 9 | 9 |
| 10 namespace { | 10 namespace { |
| 11 | 11 |
| 12 bool GetValue(const base::ListValue& list, int pos, std::string& value) { | 12 bool GetValue(const base::ListValue& list, int pos, std::string& value) { |
| 13 return list.GetString(pos, &value); | 13 return list.GetString(pos, &value); |
| 14 } | 14 } |
| 15 | 15 |
| 16 bool GetValue(const base::ListValue& list, int pos, int& value) { | 16 bool GetValue(const base::ListValue& list, int pos, int& value) { |
| 17 return list.GetInteger(pos, &value); | 17 return list.GetInteger(pos, &value); |
| 18 } | 18 } |
| 19 | 19 |
| 20 bool GetValue(const base::ListValue& list, int pos, bool& value) { | 20 bool GetValue(const base::ListValue& list, int pos, bool& value) { |
| 21 return list.GetBoolean(pos, &value); | 21 return list.GetBoolean(pos, &value); |
| 22 } | 22 } |
| 23 | 23 |
| 24 bool GetValue(const base::ListValue& list, int pos, gfx::Insets& insets) { |
| 25 const base::DictionaryValue* dict; |
| 26 if (!list.GetDictionary(pos, &dict)) |
| 27 return false; |
| 28 int top = 0; |
| 29 int left = 0; |
| 30 int bottom = 0; |
| 31 int right = 0; |
| 32 if (!dict->GetInteger("top", &top) || |
| 33 !dict->GetInteger("left", &left) || |
| 34 !dict->GetInteger("bottom", &bottom) || |
| 35 !dict->GetInteger("right", &right)) |
| 36 return false; |
| 37 insets.Set(top, left, bottom, right); |
| 38 return true; |
| 39 } |
| 40 |
| 41 bool GetValue(const base::ListValue& list, int pos, gfx::Size& size) { |
| 42 const base::DictionaryValue* dict; |
| 43 if (!list.GetDictionary(pos, &dict)) |
| 44 return false; |
| 45 int width = 0; |
| 46 int height = 0; |
| 47 if (!dict->GetInteger("width", &width) || |
| 48 !dict->GetInteger("height", &height)) |
| 49 return false; |
| 50 size.SetSize(width, height); |
| 51 return true; |
| 52 } |
| 53 |
| 24 template <typename T> | 54 template <typename T> |
| 25 struct StorageTraits { | 55 struct StorageTraits { |
| 26 typedef T StorageType; | 56 typedef T StorageType; |
| 27 }; | 57 }; |
| 28 | 58 |
| 29 template <typename T> | 59 template <typename T> |
| 30 struct StorageTraits<const T&> { | 60 struct StorageTraits<const T&> { |
| 31 typedef T StorageType; | 61 typedef T StorageType; |
| 32 }; | 62 }; |
| 33 | 63 |
| (...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 154 Delegate* delegate) { | 184 Delegate* delegate) { |
| 155 RegisterHandler("bringToFront", | 185 RegisterHandler("bringToFront", |
| 156 BindToListParser(base::Bind(&Delegate::ActivateWindow, | 186 BindToListParser(base::Bind(&Delegate::ActivateWindow, |
| 157 base::Unretained(delegate)))); | 187 base::Unretained(delegate)))); |
| 158 RegisterHandler("closeWindow", | 188 RegisterHandler("closeWindow", |
| 159 BindToListParser(base::Bind(&Delegate::CloseWindow, | 189 BindToListParser(base::Bind(&Delegate::CloseWindow, |
| 160 base::Unretained(delegate)))); | 190 base::Unretained(delegate)))); |
| 161 RegisterHandler("setContentsInsets", | 191 RegisterHandler("setContentsInsets", |
| 162 BindToListParser(base::Bind(&Delegate::SetContentsInsets, | 192 BindToListParser(base::Bind(&Delegate::SetContentsInsets, |
| 163 base::Unretained(delegate)))); | 193 base::Unretained(delegate)))); |
| 194 RegisterHandler("setContentsResizingStrategy", |
| 195 BindToListParser(base::Bind(&Delegate::SetContentsResizingStrategy, |
| 196 base::Unretained(delegate)))); |
| 164 RegisterHandler("inspectElementCompleted", | 197 RegisterHandler("inspectElementCompleted", |
| 165 BindToListParser(base::Bind(&Delegate::InspectElementCompleted, | 198 BindToListParser(base::Bind(&Delegate::InspectElementCompleted, |
| 166 base::Unretained(delegate)))); | 199 base::Unretained(delegate)))); |
| 167 RegisterHandler("moveWindowBy", | 200 RegisterHandler("moveWindowBy", |
| 168 BindToListParser(base::Bind(&Delegate::MoveWindow, | 201 BindToListParser(base::Bind(&Delegate::MoveWindow, |
| 169 base::Unretained(delegate)))); | 202 base::Unretained(delegate)))); |
| 170 RegisterHandler("setIsDocked", | 203 RegisterHandler("setIsDocked", |
| 171 BindToListParser(base::Bind(&Delegate::SetIsDocked, | 204 BindToListParser(base::Bind(&Delegate::SetIsDocked, |
| 172 base::Unretained(delegate)))); | 205 base::Unretained(delegate)))); |
| 173 RegisterHandler("openInNewTab", | 206 RegisterHandler("openInNewTab", |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 213 | 246 |
| 214 if (!it->second.Run(*params)) | 247 if (!it->second.Run(*params)) |
| 215 return "Invalid frontend host message parameters: " + method; | 248 return "Invalid frontend host message parameters: " + method; |
| 216 return ""; | 249 return ""; |
| 217 } | 250 } |
| 218 | 251 |
| 219 void DevToolsEmbedderMessageDispatcher::RegisterHandler( | 252 void DevToolsEmbedderMessageDispatcher::RegisterHandler( |
| 220 const std::string& method, const Handler& handler) { | 253 const std::string& method, const Handler& handler) { |
| 221 handlers_[method] = handler; | 254 handlers_[method] = handler; |
| 222 } | 255 } |
| OLD | NEW |