| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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/test/chromedriver/window_commands.h" | 5 #include "chrome/test/chromedriver/window_commands.h" |
| 6 | 6 |
| 7 #include <list> | 7 #include <list> |
| 8 | 8 |
| 9 #include "base/callback.h" | 9 #include "base/callback.h" |
| 10 #include "base/string_number_conversions.h" | 10 #include "base/string_number_conversions.h" |
| 11 #include "base/stringprintf.h" | 11 #include "base/stringprintf.h" |
| 12 #include "base/values.h" | 12 #include "base/values.h" |
| 13 #include "chrome/test/chromedriver/basic_types.h" | 13 #include "chrome/test/chromedriver/basic_types.h" |
| 14 #include "chrome/test/chromedriver/chrome.h" | 14 #include "chrome/test/chromedriver/chrome.h" |
| 15 #include "chrome/test/chromedriver/element_util.h" | 15 #include "chrome/test/chromedriver/element_util.h" |
| 16 #include "chrome/test/chromedriver/js.h" | 16 #include "chrome/test/chromedriver/js.h" |
| 17 #include "chrome/test/chromedriver/session.h" | 17 #include "chrome/test/chromedriver/session.h" |
| 18 #include "chrome/test/chromedriver/status.h" | 18 #include "chrome/test/chromedriver/status.h" |
| 19 #include "chrome/test/chromedriver/ui_events.h" | 19 #include "chrome/test/chromedriver/ui_events.h" |
| 20 #include "chrome/test/chromedriver/util.h" |
| 20 #include "chrome/test/chromedriver/web_view.h" | 21 #include "chrome/test/chromedriver/web_view.h" |
| 21 | 22 |
| 22 namespace { | 23 namespace { |
| 23 | 24 |
| 24 Status GetMouseButton(const base::DictionaryValue& params, | 25 Status GetMouseButton(const base::DictionaryValue& params, |
| 25 MouseButton* button) { | 26 MouseButton* button) { |
| 26 int button_num; | 27 int button_num; |
| 27 if (!params.GetInteger("button", &button_num)) { | 28 if (!params.GetInteger("button", &button_num)) { |
| 28 button_num = 0; // Default to left mouse button. | 29 button_num = 0; // Default to left mouse button. |
| 29 } else if (button_num < 0 || button_num > 2) { | 30 } else if (button_num < 0 || button_num > 2) { |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 131 | 132 |
| 132 WebView* web_view = NULL; | 133 WebView* web_view = NULL; |
| 133 status = session->GetTargetWindow(&web_view); | 134 status = session->GetTargetWindow(&web_view); |
| 134 if (status.IsError()) | 135 if (status.IsError()) |
| 135 return status; | 136 return status; |
| 136 | 137 |
| 137 status = web_view->ConnectIfNecessary(); | 138 status = web_view->ConnectIfNecessary(); |
| 138 if (status.IsError()) | 139 if (status.IsError()) |
| 139 return status; | 140 return status; |
| 140 | 141 |
| 141 Status nav_status = web_view->WaitForPendingNavigations(session->frame); | 142 Status nav_status = |
| 143 web_view->WaitForPendingNavigations(session->GetCurrentFrameId()); |
| 142 if (nav_status.IsError()) | 144 if (nav_status.IsError()) |
| 143 return nav_status; | 145 return nav_status; |
| 144 status = command.Run(session, web_view, params, value); | 146 status = command.Run(session, web_view, params, value); |
| 145 // Switch to main frame and retry command if subframe no longer exists. | 147 // Switch to main frame and retry command if subframe no longer exists. |
| 146 if (status.code() == kNoSuchFrame) { | 148 if (status.code() == kNoSuchFrame) { |
| 147 session->frame = ""; | 149 session->SwitchToTopFrame(); |
| 148 nav_status = web_view->WaitForPendingNavigations(session->frame); | 150 nav_status = |
| 151 web_view->WaitForPendingNavigations(session->GetCurrentFrameId()); |
| 149 if (nav_status.IsError()) | 152 if (nav_status.IsError()) |
| 150 return nav_status; | 153 return nav_status; |
| 151 status = command.Run(session, web_view, params, value); | 154 status = command.Run(session, web_view, params, value); |
| 152 } | 155 } |
| 153 nav_status = web_view->WaitForPendingNavigations(session->frame); | 156 nav_status = |
| 157 web_view->WaitForPendingNavigations(session->GetCurrentFrameId()); |
| 154 if (status.IsOk() && nav_status.IsError() && | 158 if (status.IsOk() && nav_status.IsError() && |
| 155 nav_status.code() != kDisconnected) | 159 nav_status.code() != kDisconnected) |
| 156 return nav_status; | 160 return nav_status; |
| 157 return status; | 161 return status; |
| 158 } | 162 } |
| 159 | 163 |
| 160 Status ExecuteGet( | 164 Status ExecuteGet( |
| 161 Session* session, | 165 Session* session, |
| 162 WebView* web_view, | 166 WebView* web_view, |
| 163 const base::DictionaryValue& params, | 167 const base::DictionaryValue& params, |
| (...skipping 10 matching lines...) Expand all Loading... |
| 174 const base::DictionaryValue& params, | 178 const base::DictionaryValue& params, |
| 175 scoped_ptr<base::Value>* value) { | 179 scoped_ptr<base::Value>* value) { |
| 176 std::string script; | 180 std::string script; |
| 177 if (!params.GetString("script", &script)) | 181 if (!params.GetString("script", &script)) |
| 178 return Status(kUnknownError, "'script' must be a string"); | 182 return Status(kUnknownError, "'script' must be a string"); |
| 179 const base::ListValue* args; | 183 const base::ListValue* args; |
| 180 if (!params.GetList("args", &args)) | 184 if (!params.GetList("args", &args)) |
| 181 return Status(kUnknownError, "'args' must be a list"); | 185 return Status(kUnknownError, "'args' must be a list"); |
| 182 | 186 |
| 183 return web_view->CallFunction( | 187 return web_view->CallFunction( |
| 184 session->frame, "function(){" + script + "}", *args, value); | 188 session->GetCurrentFrameId(), "function(){" + script + "}", *args, value); |
| 185 } | 189 } |
| 186 | 190 |
| 187 Status ExecuteSwitchToFrame( | 191 Status ExecuteSwitchToFrame( |
| 188 Session* session, | 192 Session* session, |
| 189 WebView* web_view, | 193 WebView* web_view, |
| 190 const base::DictionaryValue& params, | 194 const base::DictionaryValue& params, |
| 191 scoped_ptr<base::Value>* value) { | 195 scoped_ptr<base::Value>* value) { |
| 192 const base::Value* id; | 196 const base::Value* id; |
| 193 if (!params.Get("id", &id)) | 197 if (!params.Get("id", &id)) |
| 194 return Status(kUnknownError, "missing 'id'"); | 198 return Status(kUnknownError, "missing 'id'"); |
| 195 | 199 |
| 196 if (id->IsType(base::Value::TYPE_NULL)) { | 200 if (id->IsType(base::Value::TYPE_NULL)) { |
| 197 session->frame = ""; | 201 session->SwitchToTopFrame(); |
| 198 return Status(kOk); | 202 return Status(kOk); |
| 199 } | 203 } |
| 200 | 204 |
| 201 std::string script; | 205 std::string script; |
| 202 base::ListValue args; | 206 base::ListValue args; |
| 203 const base::DictionaryValue* id_dict; | 207 const base::DictionaryValue* id_dict; |
| 204 if (id->GetAsDictionary(&id_dict)) { | 208 if (id->GetAsDictionary(&id_dict)) { |
| 205 script = "function(elem) { return elem; }"; | 209 script = "function(elem) { return elem; }"; |
| 206 args.Append(id_dict->DeepCopy()); | 210 args.Append(id_dict->DeepCopy()); |
| 207 } else { | 211 } else { |
| (...skipping 10 matching lines...) Expand all Loading... |
| 218 "[@name=\"%s\" or @id=\"%s\"]", id_string.c_str(), id_string.c_str()); | 222 "[@name=\"%s\" or @id=\"%s\"]", id_string.c_str(), id_string.c_str()); |
| 219 } else if (id->GetAsInteger(&id_int)) { | 223 } else if (id->GetAsInteger(&id_int)) { |
| 220 xpath += base::StringPrintf("[%d]", id_int + 1); | 224 xpath += base::StringPrintf("[%d]", id_int + 1); |
| 221 } else { | 225 } else { |
| 222 return Status(kUnknownError, "invalid 'id'"); | 226 return Status(kUnknownError, "invalid 'id'"); |
| 223 } | 227 } |
| 224 args.Append(new base::StringValue(xpath)); | 228 args.Append(new base::StringValue(xpath)); |
| 225 } | 229 } |
| 226 std::string frame; | 230 std::string frame; |
| 227 Status status = web_view->GetFrameByFunction( | 231 Status status = web_view->GetFrameByFunction( |
| 228 session->frame, script, args, &frame); | 232 session->GetCurrentFrameId(), script, args, &frame); |
| 229 if (status.IsError()) | 233 if (status.IsError()) |
| 230 return status; | 234 return status; |
| 231 session->frame = frame; | 235 |
| 236 scoped_ptr<base::Value> result; |
| 237 status = web_view->CallFunction( |
| 238 session->GetCurrentFrameId(), script, args, &result); |
| 239 if (status.IsError()) |
| 240 return status; |
| 241 const base::DictionaryValue* element; |
| 242 if (!result->GetAsDictionary(&element)) |
| 243 return Status(kUnknownError, "fail to locate the sub frame element"); |
| 244 |
| 245 std::string chrome_driver_id = GenerateId(); |
| 246 const char* kSetFrameIdentifier = |
| 247 "function(frame, id) {" |
| 248 " frame.setAttribute('cd_frame_id_', id);" |
| 249 "}"; |
| 250 base::ListValue new_args; |
| 251 new_args.Append(element->DeepCopy()); |
| 252 new_args.AppendString(chrome_driver_id); |
| 253 result.reset(NULL); |
| 254 status = web_view->CallFunction( |
| 255 session->GetCurrentFrameId(), kSetFrameIdentifier, new_args, &result); |
| 256 if (status.IsError()) |
| 257 return status; |
| 258 session->SwitchToSubFrame(frame, chrome_driver_id); |
| 232 return Status(kOk); | 259 return Status(kOk); |
| 233 } | 260 } |
| 234 | 261 |
| 235 Status ExecuteGetTitle( | 262 Status ExecuteGetTitle( |
| 236 Session* session, | 263 Session* session, |
| 237 WebView* web_view, | 264 WebView* web_view, |
| 238 const base::DictionaryValue& params, | 265 const base::DictionaryValue& params, |
| 239 scoped_ptr<base::Value>* value) { | 266 scoped_ptr<base::Value>* value) { |
| 240 const char* kGetTitleScript = | 267 const char* kGetTitleScript = |
| 241 "function() {" | 268 "function() {" |
| 242 " if (document.title)" | 269 " if (document.title)" |
| 243 " return document.title;" | 270 " return document.title;" |
| 244 " else" | 271 " else" |
| 245 " return document.URL;" | 272 " return document.URL;" |
| 246 "}"; | 273 "}"; |
| 247 base::ListValue args; | 274 base::ListValue args; |
| 248 return web_view->CallFunction(session->frame, kGetTitleScript, args, value); | 275 return web_view->CallFunction( |
| 276 session->GetCurrentFrameId(), kGetTitleScript, args, value); |
| 249 } | 277 } |
| 250 | 278 |
| 251 Status ExecuteGetPageSource( | 279 Status ExecuteGetPageSource( |
| 252 Session* session, | 280 Session* session, |
| 253 WebView* web_view, | 281 WebView* web_view, |
| 254 const base::DictionaryValue& params, | 282 const base::DictionaryValue& params, |
| 255 scoped_ptr<base::Value>* value) { | 283 scoped_ptr<base::Value>* value) { |
| 256 const char* kGetPageSource = | 284 const char* kGetPageSource = |
| 257 "function() {" | 285 "function() {" |
| 258 " return new XMLSerializer().serializeToString(document);" | 286 " return new XMLSerializer().serializeToString(document);" |
| 259 "}"; | 287 "}"; |
| 260 base::ListValue args; | 288 base::ListValue args; |
| 261 return web_view->CallFunction(session->frame, kGetPageSource, args, value); | 289 return web_view->CallFunction( |
| 290 session->GetCurrentFrameId(), kGetPageSource, args, value); |
| 262 } | 291 } |
| 263 | 292 |
| 264 Status ExecuteFindElement( | 293 Status ExecuteFindElement( |
| 265 int interval_ms, | 294 int interval_ms, |
| 266 Session* session, | 295 Session* session, |
| 267 WebView* web_view, | 296 WebView* web_view, |
| 268 const base::DictionaryValue& params, | 297 const base::DictionaryValue& params, |
| 269 scoped_ptr<base::Value>* value) { | 298 scoped_ptr<base::Value>* value) { |
| 270 return FindElement(interval_ms, true, NULL, session, web_view, params, value); | 299 return FindElement(interval_ms, true, NULL, session, web_view, params, value); |
| 271 } | 300 } |
| 272 | 301 |
| 273 Status ExecuteFindElements( | 302 Status ExecuteFindElements( |
| 274 int interval_ms, | 303 int interval_ms, |
| 275 Session* session, | 304 Session* session, |
| 276 WebView* web_view, | 305 WebView* web_view, |
| 277 const base::DictionaryValue& params, | 306 const base::DictionaryValue& params, |
| 278 scoped_ptr<base::Value>* value) { | 307 scoped_ptr<base::Value>* value) { |
| 279 return FindElement( | 308 return FindElement( |
| 280 interval_ms, false, NULL, session, web_view, params, value); | 309 interval_ms, false, NULL, session, web_view, params, value); |
| 281 } | 310 } |
| 282 | 311 |
| 283 Status ExecuteGetCurrentUrl( | 312 Status ExecuteGetCurrentUrl( |
| 284 Session* session, | 313 Session* session, |
| 285 WebView* web_view, | 314 WebView* web_view, |
| 286 const base::DictionaryValue& params, | 315 const base::DictionaryValue& params, |
| 287 scoped_ptr<base::Value>* value) { | 316 scoped_ptr<base::Value>* value) { |
| 288 std::string url; | 317 std::string url; |
| 289 Status status = GetUrl(web_view, session->frame, &url); | 318 Status status = GetUrl(web_view, session->GetCurrentFrameId(), &url); |
| 290 if (status.IsError()) | 319 if (status.IsError()) |
| 291 return status; | 320 return status; |
| 292 value->reset(new base::StringValue(url)); | 321 value->reset(new base::StringValue(url)); |
| 293 return Status(kOk); | 322 return Status(kOk); |
| 294 } | 323 } |
| 295 | 324 |
| 296 Status ExecuteGoBack( | 325 Status ExecuteGoBack( |
| 297 Session* session, | 326 Session* session, |
| 298 WebView* web_view, | 327 WebView* web_view, |
| 299 const base::DictionaryValue& params, | 328 const base::DictionaryValue& params, |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 335 if (has_element) { | 364 if (has_element) { |
| 336 Status status = ScrollElementIntoView( | 365 Status status = ScrollElementIntoView( |
| 337 session, web_view, element_id, &location); | 366 session, web_view, element_id, &location); |
| 338 if (status.IsError()) | 367 if (status.IsError()) |
| 339 return status; | 368 return status; |
| 340 } else { | 369 } else { |
| 341 location = session->mouse_position; | 370 location = session->mouse_position; |
| 342 } | 371 } |
| 343 | 372 |
| 344 if (has_offset) { | 373 if (has_offset) { |
| 345 location.offset(x_offset, y_offset); | 374 location.Offset(x_offset, y_offset); |
| 346 } else { | 375 } else { |
| 347 WebSize size; | 376 WebSize size; |
| 348 Status status = GetElementSize(session, web_view, element_id, &size); | 377 Status status = GetElementSize(session, web_view, element_id, &size); |
| 349 if (status.IsError()) | 378 if (status.IsError()) |
| 350 return status; | 379 return status; |
| 351 location.offset(size.width / 2, size.height / 2); | 380 location.Offset(size.width / 2, size.height / 2); |
| 352 } | 381 } |
| 353 | 382 |
| 354 std::list<MouseEvent> events; | 383 std::list<MouseEvent> events; |
| 355 events.push_back( | 384 events.push_back( |
| 356 MouseEvent(kMovedMouseEventType, kNoneMouseButton, | 385 MouseEvent(kMovedMouseEventType, kNoneMouseButton, |
| 357 location.x, location.y, 0)); | 386 location.x, location.y, 0)); |
| 358 Status status = web_view->DispatchMouseEvents(events); | 387 Status status = web_view->DispatchMouseEvents(events); |
| 359 if (status.IsOk()) | 388 if (status.IsOk()) |
| 360 session->mouse_position = location; | 389 session->mouse_position = location; |
| 361 return status; | 390 return status; |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 431 return web_view->DispatchMouseEvents(events); | 460 return web_view->DispatchMouseEvents(events); |
| 432 } | 461 } |
| 433 | 462 |
| 434 Status ExecuteGetActiveElement( | 463 Status ExecuteGetActiveElement( |
| 435 Session* session, | 464 Session* session, |
| 436 WebView* web_view, | 465 WebView* web_view, |
| 437 const base::DictionaryValue& params, | 466 const base::DictionaryValue& params, |
| 438 scoped_ptr<base::Value>* value) { | 467 scoped_ptr<base::Value>* value) { |
| 439 base::ListValue args; | 468 base::ListValue args; |
| 440 return web_view->CallFunction( | 469 return web_view->CallFunction( |
| 441 session->frame, | 470 session->GetCurrentFrameId(), |
| 442 "function() { return document.activeElement || document.body }", | 471 "function() { return document.activeElement || document.body }", |
| 443 args, | 472 args, |
| 444 value); | 473 value); |
| 445 } | 474 } |
| 446 | 475 |
| 447 Status ExecuteGetAppCacheStatus( | 476 Status ExecuteGetAppCacheStatus( |
| 448 Session* session, | 477 Session* session, |
| 449 WebView* web_view, | 478 WebView* web_view, |
| 450 const base::DictionaryValue& params, | 479 const base::DictionaryValue& params, |
| 451 scoped_ptr<base::Value>* value) { | 480 scoped_ptr<base::Value>* value) { |
| 452 return web_view->EvaluateScript( | 481 return web_view->EvaluateScript( |
| 453 session->frame, | 482 session->GetCurrentFrameId(), |
| 454 "applicationCache.status", | 483 "applicationCache.status", |
| 455 value); | 484 value); |
| 456 } | 485 } |
| 457 | 486 |
| 458 Status ExecuteIsBrowserOnline( | 487 Status ExecuteIsBrowserOnline( |
| 459 Session* session, | 488 Session* session, |
| 460 WebView* web_view, | 489 WebView* web_view, |
| 461 const base::DictionaryValue& params, | 490 const base::DictionaryValue& params, |
| 462 scoped_ptr<base::Value>* value) { | 491 scoped_ptr<base::Value>* value) { |
| 463 return web_view->EvaluateScript( | 492 return web_view->EvaluateScript( |
| 464 session->frame, | 493 session->GetCurrentFrameId(), |
| 465 "navigator.onLine", | 494 "navigator.onLine", |
| 466 value); | 495 value); |
| 467 } | 496 } |
| 468 | 497 |
| 469 Status ExecuteGetStorageItem( | 498 Status ExecuteGetStorageItem( |
| 470 const char* storage, | 499 const char* storage, |
| 471 Session* session, | 500 Session* session, |
| 472 WebView* web_view, | 501 WebView* web_view, |
| 473 const base::DictionaryValue& params, | 502 const base::DictionaryValue& params, |
| 474 scoped_ptr<base::Value>* value) { | 503 scoped_ptr<base::Value>* value) { |
| 475 std::string key; | 504 std::string key; |
| 476 if (!params.GetString("key", &key)) | 505 if (!params.GetString("key", &key)) |
| 477 return Status(kUnknownError, "'key' must be a string"); | 506 return Status(kUnknownError, "'key' must be a string"); |
| 478 base::ListValue args; | 507 base::ListValue args; |
| 479 args.Append(new base::StringValue(key)); | 508 args.Append(new base::StringValue(key)); |
| 480 return web_view->CallFunction( | 509 return web_view->CallFunction( |
| 481 session->frame, | 510 session->GetCurrentFrameId(), |
| 482 base::StringPrintf("function(key) { return %s[key]; }", storage), | 511 base::StringPrintf("function(key) { return %s[key]; }", storage), |
| 483 args, | 512 args, |
| 484 value); | 513 value); |
| 485 } | 514 } |
| 486 | 515 |
| 487 Status ExecuteGetStorageKeys( | 516 Status ExecuteGetStorageKeys( |
| 488 const char* storage, | 517 const char* storage, |
| 489 Session* session, | 518 Session* session, |
| 490 WebView* web_view, | 519 WebView* web_view, |
| 491 const base::DictionaryValue& params, | 520 const base::DictionaryValue& params, |
| 492 scoped_ptr<base::Value>* value) { | 521 scoped_ptr<base::Value>* value) { |
| 493 const char script[] = | 522 const char script[] = |
| 494 "var keys = [];" | 523 "var keys = [];" |
| 495 "for (var key in %s) {" | 524 "for (var key in %s) {" |
| 496 " keys.push(key);" | 525 " keys.push(key);" |
| 497 "}" | 526 "}" |
| 498 "keys"; | 527 "keys"; |
| 499 return web_view->EvaluateScript( | 528 return web_view->EvaluateScript( |
| 500 session->frame, | 529 session->GetCurrentFrameId(), |
| 501 base::StringPrintf(script, storage), | 530 base::StringPrintf(script, storage), |
| 502 value); | 531 value); |
| 503 } | 532 } |
| 504 | 533 |
| 505 Status ExecuteSetStorageItem( | 534 Status ExecuteSetStorageItem( |
| 506 const char* storage, | 535 const char* storage, |
| 507 Session* session, | 536 Session* session, |
| 508 WebView* web_view, | 537 WebView* web_view, |
| 509 const base::DictionaryValue& params, | 538 const base::DictionaryValue& params, |
| 510 scoped_ptr<base::Value>* value) { | 539 scoped_ptr<base::Value>* value) { |
| 511 std::string key; | 540 std::string key; |
| 512 if (!params.GetString("key", &key)) | 541 if (!params.GetString("key", &key)) |
| 513 return Status(kUnknownError, "'key' must be a string"); | 542 return Status(kUnknownError, "'key' must be a string"); |
| 514 std::string storage_value; | 543 std::string storage_value; |
| 515 if (!params.GetString("value", &storage_value)) | 544 if (!params.GetString("value", &storage_value)) |
| 516 return Status(kUnknownError, "'value' must be a string"); | 545 return Status(kUnknownError, "'value' must be a string"); |
| 517 base::ListValue args; | 546 base::ListValue args; |
| 518 args.Append(new base::StringValue(key)); | 547 args.Append(new base::StringValue(key)); |
| 519 args.Append(new base::StringValue(storage_value)); | 548 args.Append(new base::StringValue(storage_value)); |
| 520 return web_view->CallFunction( | 549 return web_view->CallFunction( |
| 521 session->frame, | 550 session->GetCurrentFrameId(), |
| 522 base::StringPrintf("function(key, value) { %s[key] = value; }", storage), | 551 base::StringPrintf("function(key, value) { %s[key] = value; }", storage), |
| 523 args, | 552 args, |
| 524 value); | 553 value); |
| 525 } | 554 } |
| 526 | 555 |
| 527 Status ExecuteRemoveStorageItem( | 556 Status ExecuteRemoveStorageItem( |
| 528 const char* storage, | 557 const char* storage, |
| 529 Session* session, | 558 Session* session, |
| 530 WebView* web_view, | 559 WebView* web_view, |
| 531 const base::DictionaryValue& params, | 560 const base::DictionaryValue& params, |
| 532 scoped_ptr<base::Value>* value) { | 561 scoped_ptr<base::Value>* value) { |
| 533 std::string key; | 562 std::string key; |
| 534 if (!params.GetString("key", &key)) | 563 if (!params.GetString("key", &key)) |
| 535 return Status(kUnknownError, "'key' must be a string"); | 564 return Status(kUnknownError, "'key' must be a string"); |
| 536 base::ListValue args; | 565 base::ListValue args; |
| 537 args.Append(new base::StringValue(key)); | 566 args.Append(new base::StringValue(key)); |
| 538 return web_view->CallFunction( | 567 return web_view->CallFunction( |
| 539 session->frame, | 568 session->GetCurrentFrameId(), |
| 540 base::StringPrintf("function(key) { %s.removeItem(key) }", storage), | 569 base::StringPrintf("function(key) { %s.removeItem(key) }", storage), |
| 541 args, | 570 args, |
| 542 value); | 571 value); |
| 543 } | 572 } |
| 544 | 573 |
| 545 Status ExecuteClearStorage( | 574 Status ExecuteClearStorage( |
| 546 const char* storage, | 575 const char* storage, |
| 547 Session* session, | 576 Session* session, |
| 548 WebView* web_view, | 577 WebView* web_view, |
| 549 const base::DictionaryValue& params, | 578 const base::DictionaryValue& params, |
| 550 scoped_ptr<base::Value>* value) { | 579 scoped_ptr<base::Value>* value) { |
| 551 return web_view->EvaluateScript( | 580 return web_view->EvaluateScript( |
| 552 session->frame, | 581 session->GetCurrentFrameId(), |
| 553 base::StringPrintf("%s.clear()", storage), | 582 base::StringPrintf("%s.clear()", storage), |
| 554 value); | 583 value); |
| 555 } | 584 } |
| 556 | 585 |
| 557 Status ExecuteGetStorageSize( | 586 Status ExecuteGetStorageSize( |
| 558 const char* storage, | 587 const char* storage, |
| 559 Session* session, | 588 Session* session, |
| 560 WebView* web_view, | 589 WebView* web_view, |
| 561 const base::DictionaryValue& params, | 590 const base::DictionaryValue& params, |
| 562 scoped_ptr<base::Value>* value) { | 591 scoped_ptr<base::Value>* value) { |
| 563 return web_view->EvaluateScript( | 592 return web_view->EvaluateScript( |
| 564 session->frame, | 593 session->GetCurrentFrameId(), |
| 565 base::StringPrintf("%s.length", storage), | 594 base::StringPrintf("%s.length", storage), |
| 566 value); | 595 value); |
| 567 } | 596 } |
| 568 | 597 |
| 569 Status ExecuteScreenshot( | 598 Status ExecuteScreenshot( |
| 570 Session* session, | 599 Session* session, |
| 571 WebView* web_view, | 600 WebView* web_view, |
| 572 const base::DictionaryValue& params, | 601 const base::DictionaryValue& params, |
| 573 scoped_ptr<base::Value>* value) { | 602 scoped_ptr<base::Value>* value) { |
| 574 std::string screenshot; | 603 std::string screenshot; |
| (...skipping 27 matching lines...) Expand all Loading... |
| 602 WebView* web_view, | 631 WebView* web_view, |
| 603 const base::DictionaryValue& params, | 632 const base::DictionaryValue& params, |
| 604 scoped_ptr<base::Value>* value) { | 633 scoped_ptr<base::Value>* value) { |
| 605 const base::DictionaryValue* cookie; | 634 const base::DictionaryValue* cookie; |
| 606 if (!params.GetDictionary("cookie", &cookie)) | 635 if (!params.GetDictionary("cookie", &cookie)) |
| 607 return Status(kUnknownError, "missing 'cookie'"); | 636 return Status(kUnknownError, "missing 'cookie'"); |
| 608 base::ListValue args; | 637 base::ListValue args; |
| 609 args.Append(cookie->DeepCopy()); | 638 args.Append(cookie->DeepCopy()); |
| 610 scoped_ptr<base::Value> result; | 639 scoped_ptr<base::Value> result; |
| 611 return web_view->CallFunction( | 640 return web_view->CallFunction( |
| 612 session->frame, kAddCookieScript, args, &result); | 641 session->GetCurrentFrameId(), kAddCookieScript, args, &result); |
| 613 } | 642 } |
| 614 | 643 |
| 615 Status ExecuteDeleteCookie( | 644 Status ExecuteDeleteCookie( |
| 616 Session* session, | 645 Session* session, |
| 617 WebView* web_view, | 646 WebView* web_view, |
| 618 const base::DictionaryValue& params, | 647 const base::DictionaryValue& params, |
| 619 scoped_ptr<base::Value>* value) { | 648 scoped_ptr<base::Value>* value) { |
| 620 std::string name; | 649 std::string name; |
| 621 if (!params.GetString("name", &name)) | 650 if (!params.GetString("name", &name)) |
| 622 return Status(kUnknownError, "missing 'name'"); | 651 return Status(kUnknownError, "missing 'name'"); |
| 623 base::DictionaryValue params_url; | 652 base::DictionaryValue params_url; |
| 624 scoped_ptr<base::Value> value_url; | 653 scoped_ptr<base::Value> value_url; |
| 625 std::string url; | 654 std::string url; |
| 626 Status status = GetUrl(web_view, session->frame, &url); | 655 Status status = GetUrl(web_view, session->GetCurrentFrameId(), &url); |
| 627 if (status.IsError()) | 656 if (status.IsError()) |
| 628 return status; | 657 return status; |
| 629 return web_view->DeleteCookie(name, url); | 658 return web_view->DeleteCookie(name, url); |
| 630 } | 659 } |
| 631 | 660 |
| 632 Status ExecuteDeleteAllCookies( | 661 Status ExecuteDeleteAllCookies( |
| 633 Session* session, | 662 Session* session, |
| 634 WebView* web_view, | 663 WebView* web_view, |
| 635 const base::DictionaryValue& params, | 664 const base::DictionaryValue& params, |
| 636 scoped_ptr<base::Value>* value) { | 665 scoped_ptr<base::Value>* value) { |
| 637 std::list<Cookie> cookies; | 666 std::list<Cookie> cookies; |
| 638 Status status = GetVisibleCookies(web_view, &cookies); | 667 Status status = GetVisibleCookies(web_view, &cookies); |
| 639 if (status.IsError()) | 668 if (status.IsError()) |
| 640 return status; | 669 return status; |
| 641 | 670 |
| 642 if (!cookies.empty()) { | 671 if (!cookies.empty()) { |
| 643 base::DictionaryValue params_url; | 672 base::DictionaryValue params_url; |
| 644 scoped_ptr<base::Value> value_url; | 673 scoped_ptr<base::Value> value_url; |
| 645 std::string url; | 674 std::string url; |
| 646 status = GetUrl(web_view, session->frame, &url); | 675 status = GetUrl(web_view, session->GetCurrentFrameId(), &url); |
| 647 if (status.IsError()) | 676 if (status.IsError()) |
| 648 return status; | 677 return status; |
| 649 for (std::list<Cookie>::const_iterator it = cookies.begin(); | 678 for (std::list<Cookie>::const_iterator it = cookies.begin(); |
| 650 it != cookies.end(); ++it) { | 679 it != cookies.end(); ++it) { |
| 651 status = web_view->DeleteCookie(it->name, url); | 680 status = web_view->DeleteCookie(it->name, url); |
| 652 if (status.IsError()) | 681 if (status.IsError()) |
| 653 return status; | 682 return status; |
| 654 } | 683 } |
| 655 } | 684 } |
| 656 | 685 |
| 657 return Status(kOk); | 686 return Status(kOk); |
| 658 } | 687 } |
| OLD | NEW |