| 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/threading/platform_thread.h" | 12 #include "base/threading/platform_thread.h" |
| 13 #include "base/time.h" | 13 #include "base/time.h" |
| 14 #include "base/values.h" | 14 #include "base/values.h" |
| 15 #include "chrome/test/chromedriver/basic_types.h" | 15 #include "chrome/test/chromedriver/basic_types.h" |
| 16 #include "chrome/test/chromedriver/chrome.h" | 16 #include "chrome/test/chromedriver/chrome.h" |
| 17 #include "chrome/test/chromedriver/element_util.h" | 17 #include "chrome/test/chromedriver/element_util.h" |
| 18 #include "chrome/test/chromedriver/js.h" | 18 #include "chrome/test/chromedriver/js.h" |
| 19 #include "chrome/test/chromedriver/session.h" | 19 #include "chrome/test/chromedriver/session.h" |
| 20 #include "chrome/test/chromedriver/status.h" | 20 #include "chrome/test/chromedriver/status.h" |
| 21 #include "chrome/test/chromedriver/ui_events.h" | 21 #include "chrome/test/chromedriver/ui_events.h" |
| 22 #include "chrome/test/chromedriver/util.h" |
| 22 #include "chrome/test/chromedriver/web_view.h" | 23 #include "chrome/test/chromedriver/web_view.h" |
| 23 | 24 |
| 24 namespace { | 25 namespace { |
| 25 | 26 |
| 26 Status GetMouseButton(const base::DictionaryValue& params, | 27 Status GetMouseButton(const base::DictionaryValue& params, |
| 27 MouseButton* button) { | 28 MouseButton* button) { |
| 28 int button_num; | 29 int button_num; |
| 29 if (!params.GetInteger("button", &button_num)) { | 30 if (!params.GetInteger("button", &button_num)) { |
| 30 button_num = 0; // Default to left mouse button. | 31 button_num = 0; // Default to left mouse button. |
| 31 } else if (button_num < 0 || button_num > 2) { | 32 } else if (button_num < 0 || button_num > 2) { |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 133 | 134 |
| 134 WebView* web_view = NULL; | 135 WebView* web_view = NULL; |
| 135 status = session->GetTargetWindow(&web_view); | 136 status = session->GetTargetWindow(&web_view); |
| 136 if (status.IsError()) | 137 if (status.IsError()) |
| 137 return status; | 138 return status; |
| 138 | 139 |
| 139 status = web_view->ConnectIfNecessary(); | 140 status = web_view->ConnectIfNecessary(); |
| 140 if (status.IsError()) | 141 if (status.IsError()) |
| 141 return status; | 142 return status; |
| 142 | 143 |
| 143 Status nav_status = web_view->WaitForPendingNavigations(session->frame); | 144 Status nav_status = |
| 145 web_view->WaitForPendingNavigations(session->GetCurrentFrameId()); |
| 144 if (nav_status.IsError()) | 146 if (nav_status.IsError()) |
| 145 return nav_status; | 147 return nav_status; |
| 146 status = command.Run(session, web_view, params, value); | 148 status = command.Run(session, web_view, params, value); |
| 147 // Switch to main frame and retry command if subframe no longer exists. | 149 // Switch to main frame and retry command if subframe no longer exists. |
| 148 if (status.code() == kNoSuchFrame) { | 150 if (status.code() == kNoSuchFrame) { |
| 149 session->frame = ""; | 151 session->SwitchToTopFrame(); |
| 150 nav_status = web_view->WaitForPendingNavigations(session->frame); | 152 nav_status = |
| 153 web_view->WaitForPendingNavigations(session->GetCurrentFrameId()); |
| 151 if (nav_status.IsError()) | 154 if (nav_status.IsError()) |
| 152 return nav_status; | 155 return nav_status; |
| 153 status = command.Run(session, web_view, params, value); | 156 status = command.Run(session, web_view, params, value); |
| 154 } | 157 } |
| 155 nav_status = web_view->WaitForPendingNavigations(session->frame); | 158 nav_status = |
| 159 web_view->WaitForPendingNavigations(session->GetCurrentFrameId()); |
| 156 if (status.IsOk() && nav_status.IsError() && | 160 if (status.IsOk() && nav_status.IsError() && |
| 157 nav_status.code() != kDisconnected) | 161 nav_status.code() != kDisconnected) |
| 158 return nav_status; | 162 return nav_status; |
| 159 return status; | 163 return status; |
| 160 } | 164 } |
| 161 | 165 |
| 162 Status ExecuteGet( | 166 Status ExecuteGet( |
| 163 Session* session, | 167 Session* session, |
| 164 WebView* web_view, | 168 WebView* web_view, |
| 165 const base::DictionaryValue& params, | 169 const base::DictionaryValue& params, |
| (...skipping 10 matching lines...) Expand all Loading... |
| 176 const base::DictionaryValue& params, | 180 const base::DictionaryValue& params, |
| 177 scoped_ptr<base::Value>* value) { | 181 scoped_ptr<base::Value>* value) { |
| 178 std::string script; | 182 std::string script; |
| 179 if (!params.GetString("script", &script)) | 183 if (!params.GetString("script", &script)) |
| 180 return Status(kUnknownError, "'script' must be a string"); | 184 return Status(kUnknownError, "'script' must be a string"); |
| 181 const base::ListValue* args; | 185 const base::ListValue* args; |
| 182 if (!params.GetList("args", &args)) | 186 if (!params.GetList("args", &args)) |
| 183 return Status(kUnknownError, "'args' must be a list"); | 187 return Status(kUnknownError, "'args' must be a list"); |
| 184 | 188 |
| 185 return web_view->CallFunction( | 189 return web_view->CallFunction( |
| 186 session->frame, "function(){" + script + "}", *args, value); | 190 session->GetCurrentFrameId(), "function(){" + script + "}", *args, value); |
| 187 } | 191 } |
| 188 | 192 |
| 189 Status ExecuteExecuteAsyncScript( | 193 Status ExecuteExecuteAsyncScript( |
| 190 Session* session, | 194 Session* session, |
| 191 WebView* web_view, | 195 WebView* web_view, |
| 192 const base::DictionaryValue& params, | 196 const base::DictionaryValue& params, |
| 193 scoped_ptr<base::Value>* value) { | 197 scoped_ptr<base::Value>* value) { |
| 194 std::string script; | 198 std::string script; |
| 195 if (!params.GetString("script", &script)) | 199 if (!params.GetString("script", &script)) |
| 196 return Status(kUnknownError, "'script' must be a string"); | 200 return Status(kUnknownError, "'script' must be a string"); |
| 197 const base::ListValue* script_args; | 201 const base::ListValue* script_args; |
| 198 if (!params.GetList("args", &script_args)) | 202 if (!params.GetList("args", &script_args)) |
| 199 return Status(kUnknownError, "'args' must be a list"); | 203 return Status(kUnknownError, "'args' must be a list"); |
| 200 | 204 |
| 201 base::ListValue args; | 205 base::ListValue args; |
| 202 args.AppendString(script); | 206 args.AppendString(script); |
| 203 args.Append(script_args->DeepCopy()); | 207 args.Append(script_args->DeepCopy()); |
| 204 args.AppendInteger(session->script_timeout); | 208 args.AppendInteger(session->script_timeout); |
| 205 scoped_ptr<base::Value> tmp; | 209 scoped_ptr<base::Value> tmp; |
| 206 Status status = web_view->CallFunction( | 210 Status status = web_view->CallFunction( |
| 207 session->frame, kExecuteAsyncScriptScript, args, &tmp); | 211 session->GetCurrentFrameId(), kExecuteAsyncScriptScript, args, &tmp); |
| 208 if (status.IsError()) | 212 if (status.IsError()) |
| 209 return status; | 213 return status; |
| 210 | 214 |
| 211 base::Time start_time = base::Time::Now(); | 215 base::Time start_time = base::Time::Now(); |
| 212 base::ListValue args_tmp; | 216 base::ListValue args_tmp; |
| 213 const char* kGetAndClearResult = | 217 const char* kGetAndClearResult = |
| 214 "function() {" | 218 "function() {" |
| 215 " var toReturn = {};" | 219 " var toReturn = {};" |
| 216 " var info = document.chromedriverAsyncScriptInfo;" | 220 " var info = document.chromedriverAsyncScriptInfo;" |
| 217 " toReturn.finished = info.finished;" | 221 " toReturn.finished = info.finished;" |
| 218 " if (info.finished) {" | 222 " if (info.finished) {" |
| 219 " toReturn.result = info.result;" | 223 " toReturn.result = info.result;" |
| 220 " delete info.result;" | 224 " delete info.result;" |
| 221 " }" | 225 " }" |
| 222 " return toReturn;" | 226 " return toReturn;" |
| 223 "}"; | 227 "}"; |
| 224 while (true) { | 228 while (true) { |
| 225 scoped_ptr<base::Value> result; | 229 scoped_ptr<base::Value> result; |
| 226 status = web_view->CallFunction( | 230 status = web_view->CallFunction( |
| 227 session->frame, kGetAndClearResult, args_tmp, &result); | 231 session->GetCurrentFrameId(), kGetAndClearResult, args_tmp, &result); |
| 228 if (status.IsError()) { | 232 if (status.IsError()) { |
| 229 if (status.code() == kNoSuchFrame) | 233 if (status.code() == kNoSuchFrame) |
| 230 return Status(kJavaScriptError, "page or frame unload", status); | 234 return Status(kJavaScriptError, "page or frame unload", status); |
| 231 return status; | 235 return status; |
| 232 } | 236 } |
| 233 const base::DictionaryValue* dict; | 237 const base::DictionaryValue* dict; |
| 234 if (!result->GetAsDictionary(&dict)) | 238 if (!result->GetAsDictionary(&dict)) |
| 235 return Status(kUnknownError, "failed to tell if script has finished"); | 239 return Status(kUnknownError, "failed to tell if script has finished"); |
| 236 bool finished = false; | 240 bool finished = false; |
| 237 if (!dict->GetBoolean("finished", &finished)) | 241 if (!dict->GetBoolean("finished", &finished)) |
| (...skipping 15 matching lines...) Expand all Loading... |
| 253 | 257 |
| 254 base::PlatformThread::Sleep(base::TimeDelta::FromMilliseconds(50)); | 258 base::PlatformThread::Sleep(base::TimeDelta::FromMilliseconds(50)); |
| 255 } | 259 } |
| 256 | 260 |
| 257 // Clear the result if it is set, otherwise prevent the script to set result | 261 // Clear the result if it is set, otherwise prevent the script to set result |
| 258 // by increasing the id. | 262 // by increasing the id. |
| 259 const char* kClearResultForTimeoutScript = | 263 const char* kClearResultForTimeoutScript = |
| 260 "var info = document.chromedriverAsyncScriptInfo;" | 264 "var info = document.chromedriverAsyncScriptInfo;" |
| 261 "info.id++;" | 265 "info.id++;" |
| 262 "delete info.result;"; | 266 "delete info.result;"; |
| 263 web_view->EvaluateScript(session->frame, kClearResultForTimeoutScript, &tmp); | 267 web_view->EvaluateScript( |
| 268 session->GetCurrentFrameId(), kClearResultForTimeoutScript, &tmp); |
| 264 | 269 |
| 265 return Status( | 270 return Status( |
| 266 kScriptTimeout, | 271 kScriptTimeout, |
| 267 base::StringPrintf("timed out waiting for result after %d ms", | 272 base::StringPrintf("timed out waiting for result after %d ms", |
| 268 session->script_timeout)); | 273 session->script_timeout)); |
| 269 } | 274 } |
| 270 | 275 |
| 271 Status ExecuteSwitchToFrame( | 276 Status ExecuteSwitchToFrame( |
| 272 Session* session, | 277 Session* session, |
| 273 WebView* web_view, | 278 WebView* web_view, |
| 274 const base::DictionaryValue& params, | 279 const base::DictionaryValue& params, |
| 275 scoped_ptr<base::Value>* value) { | 280 scoped_ptr<base::Value>* value) { |
| 276 const base::Value* id; | 281 const base::Value* id; |
| 277 if (!params.Get("id", &id)) | 282 if (!params.Get("id", &id)) |
| 278 return Status(kUnknownError, "missing 'id'"); | 283 return Status(kUnknownError, "missing 'id'"); |
| 279 | 284 |
| 280 if (id->IsType(base::Value::TYPE_NULL)) { | 285 if (id->IsType(base::Value::TYPE_NULL)) { |
| 281 session->frame = ""; | 286 session->SwitchToTopFrame(); |
| 282 return Status(kOk); | 287 return Status(kOk); |
| 283 } | 288 } |
| 284 | 289 |
| 285 std::string script; | 290 std::string script; |
| 286 base::ListValue args; | 291 base::ListValue args; |
| 287 const base::DictionaryValue* id_dict; | 292 const base::DictionaryValue* id_dict; |
| 288 if (id->GetAsDictionary(&id_dict)) { | 293 if (id->GetAsDictionary(&id_dict)) { |
| 289 script = "function(elem) { return elem; }"; | 294 script = "function(elem) { return elem; }"; |
| 290 args.Append(id_dict->DeepCopy()); | 295 args.Append(id_dict->DeepCopy()); |
| 291 } else { | 296 } else { |
| (...skipping 10 matching lines...) Expand all Loading... |
| 302 "[@name=\"%s\" or @id=\"%s\"]", id_string.c_str(), id_string.c_str()); | 307 "[@name=\"%s\" or @id=\"%s\"]", id_string.c_str(), id_string.c_str()); |
| 303 } else if (id->GetAsInteger(&id_int)) { | 308 } else if (id->GetAsInteger(&id_int)) { |
| 304 xpath += base::StringPrintf("[%d]", id_int + 1); | 309 xpath += base::StringPrintf("[%d]", id_int + 1); |
| 305 } else { | 310 } else { |
| 306 return Status(kUnknownError, "invalid 'id'"); | 311 return Status(kUnknownError, "invalid 'id'"); |
| 307 } | 312 } |
| 308 args.Append(new base::StringValue(xpath)); | 313 args.Append(new base::StringValue(xpath)); |
| 309 } | 314 } |
| 310 std::string frame; | 315 std::string frame; |
| 311 Status status = web_view->GetFrameByFunction( | 316 Status status = web_view->GetFrameByFunction( |
| 312 session->frame, script, args, &frame); | 317 session->GetCurrentFrameId(), script, args, &frame); |
| 313 if (status.IsError()) | 318 if (status.IsError()) |
| 314 return status; | 319 return status; |
| 315 session->frame = frame; | 320 |
| 321 scoped_ptr<base::Value> result; |
| 322 status = web_view->CallFunction( |
| 323 session->GetCurrentFrameId(), script, args, &result); |
| 324 if (status.IsError()) |
| 325 return status; |
| 326 const base::DictionaryValue* element; |
| 327 if (!result->GetAsDictionary(&element)) |
| 328 return Status(kUnknownError, "fail to locate the sub frame element"); |
| 329 |
| 330 std::string chrome_driver_id = GenerateId(); |
| 331 const char* kSetFrameIdentifier = |
| 332 "function(frame, id) {" |
| 333 " frame.setAttribute('cd_frame_id_', id);" |
| 334 "}"; |
| 335 base::ListValue new_args; |
| 336 new_args.Append(element->DeepCopy()); |
| 337 new_args.AppendString(chrome_driver_id); |
| 338 result.reset(NULL); |
| 339 status = web_view->CallFunction( |
| 340 session->GetCurrentFrameId(), kSetFrameIdentifier, new_args, &result); |
| 341 if (status.IsError()) |
| 342 return status; |
| 343 session->SwitchToSubFrame(frame, chrome_driver_id); |
| 316 return Status(kOk); | 344 return Status(kOk); |
| 317 } | 345 } |
| 318 | 346 |
| 319 Status ExecuteGetTitle( | 347 Status ExecuteGetTitle( |
| 320 Session* session, | 348 Session* session, |
| 321 WebView* web_view, | 349 WebView* web_view, |
| 322 const base::DictionaryValue& params, | 350 const base::DictionaryValue& params, |
| 323 scoped_ptr<base::Value>* value) { | 351 scoped_ptr<base::Value>* value) { |
| 324 const char* kGetTitleScript = | 352 const char* kGetTitleScript = |
| 325 "function() {" | 353 "function() {" |
| 326 " if (document.title)" | 354 " if (document.title)" |
| 327 " return document.title;" | 355 " return document.title;" |
| 328 " else" | 356 " else" |
| 329 " return document.URL;" | 357 " return document.URL;" |
| 330 "}"; | 358 "}"; |
| 331 base::ListValue args; | 359 base::ListValue args; |
| 332 return web_view->CallFunction(session->frame, kGetTitleScript, args, value); | 360 return web_view->CallFunction( |
| 361 session->GetCurrentFrameId(), kGetTitleScript, args, value); |
| 333 } | 362 } |
| 334 | 363 |
| 335 Status ExecuteGetPageSource( | 364 Status ExecuteGetPageSource( |
| 336 Session* session, | 365 Session* session, |
| 337 WebView* web_view, | 366 WebView* web_view, |
| 338 const base::DictionaryValue& params, | 367 const base::DictionaryValue& params, |
| 339 scoped_ptr<base::Value>* value) { | 368 scoped_ptr<base::Value>* value) { |
| 340 const char* kGetPageSource = | 369 const char* kGetPageSource = |
| 341 "function() {" | 370 "function() {" |
| 342 " return new XMLSerializer().serializeToString(document);" | 371 " return new XMLSerializer().serializeToString(document);" |
| 343 "}"; | 372 "}"; |
| 344 base::ListValue args; | 373 base::ListValue args; |
| 345 return web_view->CallFunction(session->frame, kGetPageSource, args, value); | 374 return web_view->CallFunction( |
| 375 session->GetCurrentFrameId(), kGetPageSource, args, value); |
| 346 } | 376 } |
| 347 | 377 |
| 348 Status ExecuteFindElement( | 378 Status ExecuteFindElement( |
| 349 int interval_ms, | 379 int interval_ms, |
| 350 Session* session, | 380 Session* session, |
| 351 WebView* web_view, | 381 WebView* web_view, |
| 352 const base::DictionaryValue& params, | 382 const base::DictionaryValue& params, |
| 353 scoped_ptr<base::Value>* value) { | 383 scoped_ptr<base::Value>* value) { |
| 354 return FindElement(interval_ms, true, NULL, session, web_view, params, value); | 384 return FindElement(interval_ms, true, NULL, session, web_view, params, value); |
| 355 } | 385 } |
| 356 | 386 |
| 357 Status ExecuteFindElements( | 387 Status ExecuteFindElements( |
| 358 int interval_ms, | 388 int interval_ms, |
| 359 Session* session, | 389 Session* session, |
| 360 WebView* web_view, | 390 WebView* web_view, |
| 361 const base::DictionaryValue& params, | 391 const base::DictionaryValue& params, |
| 362 scoped_ptr<base::Value>* value) { | 392 scoped_ptr<base::Value>* value) { |
| 363 return FindElement( | 393 return FindElement( |
| 364 interval_ms, false, NULL, session, web_view, params, value); | 394 interval_ms, false, NULL, session, web_view, params, value); |
| 365 } | 395 } |
| 366 | 396 |
| 367 Status ExecuteGetCurrentUrl( | 397 Status ExecuteGetCurrentUrl( |
| 368 Session* session, | 398 Session* session, |
| 369 WebView* web_view, | 399 WebView* web_view, |
| 370 const base::DictionaryValue& params, | 400 const base::DictionaryValue& params, |
| 371 scoped_ptr<base::Value>* value) { | 401 scoped_ptr<base::Value>* value) { |
| 372 std::string url; | 402 std::string url; |
| 373 Status status = GetUrl(web_view, session->frame, &url); | 403 Status status = GetUrl(web_view, session->GetCurrentFrameId(), &url); |
| 374 if (status.IsError()) | 404 if (status.IsError()) |
| 375 return status; | 405 return status; |
| 376 value->reset(new base::StringValue(url)); | 406 value->reset(new base::StringValue(url)); |
| 377 return Status(kOk); | 407 return Status(kOk); |
| 378 } | 408 } |
| 379 | 409 |
| 380 Status ExecuteGoBack( | 410 Status ExecuteGoBack( |
| 381 Session* session, | 411 Session* session, |
| 382 WebView* web_view, | 412 WebView* web_view, |
| 383 const base::DictionaryValue& params, | 413 const base::DictionaryValue& params, |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 419 if (has_element) { | 449 if (has_element) { |
| 420 Status status = ScrollElementIntoView( | 450 Status status = ScrollElementIntoView( |
| 421 session, web_view, element_id, &location); | 451 session, web_view, element_id, &location); |
| 422 if (status.IsError()) | 452 if (status.IsError()) |
| 423 return status; | 453 return status; |
| 424 } else { | 454 } else { |
| 425 location = session->mouse_position; | 455 location = session->mouse_position; |
| 426 } | 456 } |
| 427 | 457 |
| 428 if (has_offset) { | 458 if (has_offset) { |
| 429 location.offset(x_offset, y_offset); | 459 location.Offset(x_offset, y_offset); |
| 430 } else { | 460 } else { |
| 431 WebSize size; | 461 WebSize size; |
| 432 Status status = GetElementSize(session, web_view, element_id, &size); | 462 Status status = GetElementSize(session, web_view, element_id, &size); |
| 433 if (status.IsError()) | 463 if (status.IsError()) |
| 434 return status; | 464 return status; |
| 435 location.offset(size.width / 2, size.height / 2); | 465 location.Offset(size.width / 2, size.height / 2); |
| 436 } | 466 } |
| 437 | 467 |
| 438 std::list<MouseEvent> events; | 468 std::list<MouseEvent> events; |
| 439 events.push_back( | 469 events.push_back( |
| 440 MouseEvent(kMovedMouseEventType, kNoneMouseButton, | 470 MouseEvent(kMovedMouseEventType, kNoneMouseButton, |
| 441 location.x, location.y, 0)); | 471 location.x, location.y, 0)); |
| 442 Status status = web_view->DispatchMouseEvents(events); | 472 Status status = web_view->DispatchMouseEvents(events); |
| 443 if (status.IsOk()) | 473 if (status.IsOk()) |
| 444 session->mouse_position = location; | 474 session->mouse_position = location; |
| 445 return status; | 475 return status; |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 515 return web_view->DispatchMouseEvents(events); | 545 return web_view->DispatchMouseEvents(events); |
| 516 } | 546 } |
| 517 | 547 |
| 518 Status ExecuteGetActiveElement( | 548 Status ExecuteGetActiveElement( |
| 519 Session* session, | 549 Session* session, |
| 520 WebView* web_view, | 550 WebView* web_view, |
| 521 const base::DictionaryValue& params, | 551 const base::DictionaryValue& params, |
| 522 scoped_ptr<base::Value>* value) { | 552 scoped_ptr<base::Value>* value) { |
| 523 base::ListValue args; | 553 base::ListValue args; |
| 524 return web_view->CallFunction( | 554 return web_view->CallFunction( |
| 525 session->frame, | 555 session->GetCurrentFrameId(), |
| 526 "function() { return document.activeElement || document.body }", | 556 "function() { return document.activeElement || document.body }", |
| 527 args, | 557 args, |
| 528 value); | 558 value); |
| 529 } | 559 } |
| 530 | 560 |
| 531 Status ExecuteGetAppCacheStatus( | 561 Status ExecuteGetAppCacheStatus( |
| 532 Session* session, | 562 Session* session, |
| 533 WebView* web_view, | 563 WebView* web_view, |
| 534 const base::DictionaryValue& params, | 564 const base::DictionaryValue& params, |
| 535 scoped_ptr<base::Value>* value) { | 565 scoped_ptr<base::Value>* value) { |
| 536 return web_view->EvaluateScript( | 566 return web_view->EvaluateScript( |
| 537 session->frame, | 567 session->GetCurrentFrameId(), |
| 538 "applicationCache.status", | 568 "applicationCache.status", |
| 539 value); | 569 value); |
| 540 } | 570 } |
| 541 | 571 |
| 542 Status ExecuteIsBrowserOnline( | 572 Status ExecuteIsBrowserOnline( |
| 543 Session* session, | 573 Session* session, |
| 544 WebView* web_view, | 574 WebView* web_view, |
| 545 const base::DictionaryValue& params, | 575 const base::DictionaryValue& params, |
| 546 scoped_ptr<base::Value>* value) { | 576 scoped_ptr<base::Value>* value) { |
| 547 return web_view->EvaluateScript( | 577 return web_view->EvaluateScript( |
| 548 session->frame, | 578 session->GetCurrentFrameId(), |
| 549 "navigator.onLine", | 579 "navigator.onLine", |
| 550 value); | 580 value); |
| 551 } | 581 } |
| 552 | 582 |
| 553 Status ExecuteGetStorageItem( | 583 Status ExecuteGetStorageItem( |
| 554 const char* storage, | 584 const char* storage, |
| 555 Session* session, | 585 Session* session, |
| 556 WebView* web_view, | 586 WebView* web_view, |
| 557 const base::DictionaryValue& params, | 587 const base::DictionaryValue& params, |
| 558 scoped_ptr<base::Value>* value) { | 588 scoped_ptr<base::Value>* value) { |
| 559 std::string key; | 589 std::string key; |
| 560 if (!params.GetString("key", &key)) | 590 if (!params.GetString("key", &key)) |
| 561 return Status(kUnknownError, "'key' must be a string"); | 591 return Status(kUnknownError, "'key' must be a string"); |
| 562 base::ListValue args; | 592 base::ListValue args; |
| 563 args.Append(new base::StringValue(key)); | 593 args.Append(new base::StringValue(key)); |
| 564 return web_view->CallFunction( | 594 return web_view->CallFunction( |
| 565 session->frame, | 595 session->GetCurrentFrameId(), |
| 566 base::StringPrintf("function(key) { return %s[key]; }", storage), | 596 base::StringPrintf("function(key) { return %s[key]; }", storage), |
| 567 args, | 597 args, |
| 568 value); | 598 value); |
| 569 } | 599 } |
| 570 | 600 |
| 571 Status ExecuteGetStorageKeys( | 601 Status ExecuteGetStorageKeys( |
| 572 const char* storage, | 602 const char* storage, |
| 573 Session* session, | 603 Session* session, |
| 574 WebView* web_view, | 604 WebView* web_view, |
| 575 const base::DictionaryValue& params, | 605 const base::DictionaryValue& params, |
| 576 scoped_ptr<base::Value>* value) { | 606 scoped_ptr<base::Value>* value) { |
| 577 const char script[] = | 607 const char script[] = |
| 578 "var keys = [];" | 608 "var keys = [];" |
| 579 "for (var key in %s) {" | 609 "for (var key in %s) {" |
| 580 " keys.push(key);" | 610 " keys.push(key);" |
| 581 "}" | 611 "}" |
| 582 "keys"; | 612 "keys"; |
| 583 return web_view->EvaluateScript( | 613 return web_view->EvaluateScript( |
| 584 session->frame, | 614 session->GetCurrentFrameId(), |
| 585 base::StringPrintf(script, storage), | 615 base::StringPrintf(script, storage), |
| 586 value); | 616 value); |
| 587 } | 617 } |
| 588 | 618 |
| 589 Status ExecuteSetStorageItem( | 619 Status ExecuteSetStorageItem( |
| 590 const char* storage, | 620 const char* storage, |
| 591 Session* session, | 621 Session* session, |
| 592 WebView* web_view, | 622 WebView* web_view, |
| 593 const base::DictionaryValue& params, | 623 const base::DictionaryValue& params, |
| 594 scoped_ptr<base::Value>* value) { | 624 scoped_ptr<base::Value>* value) { |
| 595 std::string key; | 625 std::string key; |
| 596 if (!params.GetString("key", &key)) | 626 if (!params.GetString("key", &key)) |
| 597 return Status(kUnknownError, "'key' must be a string"); | 627 return Status(kUnknownError, "'key' must be a string"); |
| 598 std::string storage_value; | 628 std::string storage_value; |
| 599 if (!params.GetString("value", &storage_value)) | 629 if (!params.GetString("value", &storage_value)) |
| 600 return Status(kUnknownError, "'value' must be a string"); | 630 return Status(kUnknownError, "'value' must be a string"); |
| 601 base::ListValue args; | 631 base::ListValue args; |
| 602 args.Append(new base::StringValue(key)); | 632 args.Append(new base::StringValue(key)); |
| 603 args.Append(new base::StringValue(storage_value)); | 633 args.Append(new base::StringValue(storage_value)); |
| 604 return web_view->CallFunction( | 634 return web_view->CallFunction( |
| 605 session->frame, | 635 session->GetCurrentFrameId(), |
| 606 base::StringPrintf("function(key, value) { %s[key] = value; }", storage), | 636 base::StringPrintf("function(key, value) { %s[key] = value; }", storage), |
| 607 args, | 637 args, |
| 608 value); | 638 value); |
| 609 } | 639 } |
| 610 | 640 |
| 611 Status ExecuteRemoveStorageItem( | 641 Status ExecuteRemoveStorageItem( |
| 612 const char* storage, | 642 const char* storage, |
| 613 Session* session, | 643 Session* session, |
| 614 WebView* web_view, | 644 WebView* web_view, |
| 615 const base::DictionaryValue& params, | 645 const base::DictionaryValue& params, |
| 616 scoped_ptr<base::Value>* value) { | 646 scoped_ptr<base::Value>* value) { |
| 617 std::string key; | 647 std::string key; |
| 618 if (!params.GetString("key", &key)) | 648 if (!params.GetString("key", &key)) |
| 619 return Status(kUnknownError, "'key' must be a string"); | 649 return Status(kUnknownError, "'key' must be a string"); |
| 620 base::ListValue args; | 650 base::ListValue args; |
| 621 args.Append(new base::StringValue(key)); | 651 args.Append(new base::StringValue(key)); |
| 622 return web_view->CallFunction( | 652 return web_view->CallFunction( |
| 623 session->frame, | 653 session->GetCurrentFrameId(), |
| 624 base::StringPrintf("function(key) { %s.removeItem(key) }", storage), | 654 base::StringPrintf("function(key) { %s.removeItem(key) }", storage), |
| 625 args, | 655 args, |
| 626 value); | 656 value); |
| 627 } | 657 } |
| 628 | 658 |
| 629 Status ExecuteClearStorage( | 659 Status ExecuteClearStorage( |
| 630 const char* storage, | 660 const char* storage, |
| 631 Session* session, | 661 Session* session, |
| 632 WebView* web_view, | 662 WebView* web_view, |
| 633 const base::DictionaryValue& params, | 663 const base::DictionaryValue& params, |
| 634 scoped_ptr<base::Value>* value) { | 664 scoped_ptr<base::Value>* value) { |
| 635 return web_view->EvaluateScript( | 665 return web_view->EvaluateScript( |
| 636 session->frame, | 666 session->GetCurrentFrameId(), |
| 637 base::StringPrintf("%s.clear()", storage), | 667 base::StringPrintf("%s.clear()", storage), |
| 638 value); | 668 value); |
| 639 } | 669 } |
| 640 | 670 |
| 641 Status ExecuteGetStorageSize( | 671 Status ExecuteGetStorageSize( |
| 642 const char* storage, | 672 const char* storage, |
| 643 Session* session, | 673 Session* session, |
| 644 WebView* web_view, | 674 WebView* web_view, |
| 645 const base::DictionaryValue& params, | 675 const base::DictionaryValue& params, |
| 646 scoped_ptr<base::Value>* value) { | 676 scoped_ptr<base::Value>* value) { |
| 647 return web_view->EvaluateScript( | 677 return web_view->EvaluateScript( |
| 648 session->frame, | 678 session->GetCurrentFrameId(), |
| 649 base::StringPrintf("%s.length", storage), | 679 base::StringPrintf("%s.length", storage), |
| 650 value); | 680 value); |
| 651 } | 681 } |
| 652 | 682 |
| 653 Status ExecuteScreenshot( | 683 Status ExecuteScreenshot( |
| 654 Session* session, | 684 Session* session, |
| 655 WebView* web_view, | 685 WebView* web_view, |
| 656 const base::DictionaryValue& params, | 686 const base::DictionaryValue& params, |
| 657 scoped_ptr<base::Value>* value) { | 687 scoped_ptr<base::Value>* value) { |
| 658 std::string screenshot; | 688 std::string screenshot; |
| (...skipping 27 matching lines...) Expand all Loading... |
| 686 WebView* web_view, | 716 WebView* web_view, |
| 687 const base::DictionaryValue& params, | 717 const base::DictionaryValue& params, |
| 688 scoped_ptr<base::Value>* value) { | 718 scoped_ptr<base::Value>* value) { |
| 689 const base::DictionaryValue* cookie; | 719 const base::DictionaryValue* cookie; |
| 690 if (!params.GetDictionary("cookie", &cookie)) | 720 if (!params.GetDictionary("cookie", &cookie)) |
| 691 return Status(kUnknownError, "missing 'cookie'"); | 721 return Status(kUnknownError, "missing 'cookie'"); |
| 692 base::ListValue args; | 722 base::ListValue args; |
| 693 args.Append(cookie->DeepCopy()); | 723 args.Append(cookie->DeepCopy()); |
| 694 scoped_ptr<base::Value> result; | 724 scoped_ptr<base::Value> result; |
| 695 return web_view->CallFunction( | 725 return web_view->CallFunction( |
| 696 session->frame, kAddCookieScript, args, &result); | 726 session->GetCurrentFrameId(), kAddCookieScript, args, &result); |
| 697 } | 727 } |
| 698 | 728 |
| 699 Status ExecuteDeleteCookie( | 729 Status ExecuteDeleteCookie( |
| 700 Session* session, | 730 Session* session, |
| 701 WebView* web_view, | 731 WebView* web_view, |
| 702 const base::DictionaryValue& params, | 732 const base::DictionaryValue& params, |
| 703 scoped_ptr<base::Value>* value) { | 733 scoped_ptr<base::Value>* value) { |
| 704 std::string name; | 734 std::string name; |
| 705 if (!params.GetString("name", &name)) | 735 if (!params.GetString("name", &name)) |
| 706 return Status(kUnknownError, "missing 'name'"); | 736 return Status(kUnknownError, "missing 'name'"); |
| 707 base::DictionaryValue params_url; | 737 base::DictionaryValue params_url; |
| 708 scoped_ptr<base::Value> value_url; | 738 scoped_ptr<base::Value> value_url; |
| 709 std::string url; | 739 std::string url; |
| 710 Status status = GetUrl(web_view, session->frame, &url); | 740 Status status = GetUrl(web_view, session->GetCurrentFrameId(), &url); |
| 711 if (status.IsError()) | 741 if (status.IsError()) |
| 712 return status; | 742 return status; |
| 713 return web_view->DeleteCookie(name, url); | 743 return web_view->DeleteCookie(name, url); |
| 714 } | 744 } |
| 715 | 745 |
| 716 Status ExecuteDeleteAllCookies( | 746 Status ExecuteDeleteAllCookies( |
| 717 Session* session, | 747 Session* session, |
| 718 WebView* web_view, | 748 WebView* web_view, |
| 719 const base::DictionaryValue& params, | 749 const base::DictionaryValue& params, |
| 720 scoped_ptr<base::Value>* value) { | 750 scoped_ptr<base::Value>* value) { |
| 721 std::list<Cookie> cookies; | 751 std::list<Cookie> cookies; |
| 722 Status status = GetVisibleCookies(web_view, &cookies); | 752 Status status = GetVisibleCookies(web_view, &cookies); |
| 723 if (status.IsError()) | 753 if (status.IsError()) |
| 724 return status; | 754 return status; |
| 725 | 755 |
| 726 if (!cookies.empty()) { | 756 if (!cookies.empty()) { |
| 727 base::DictionaryValue params_url; | 757 base::DictionaryValue params_url; |
| 728 scoped_ptr<base::Value> value_url; | 758 scoped_ptr<base::Value> value_url; |
| 729 std::string url; | 759 std::string url; |
| 730 status = GetUrl(web_view, session->frame, &url); | 760 status = GetUrl(web_view, session->GetCurrentFrameId(), &url); |
| 731 if (status.IsError()) | 761 if (status.IsError()) |
| 732 return status; | 762 return status; |
| 733 for (std::list<Cookie>::const_iterator it = cookies.begin(); | 763 for (std::list<Cookie>::const_iterator it = cookies.begin(); |
| 734 it != cookies.end(); ++it) { | 764 it != cookies.end(); ++it) { |
| 735 status = web_view->DeleteCookie(it->name, url); | 765 status = web_view->DeleteCookie(it->name, url); |
| 736 if (status.IsError()) | 766 if (status.IsError()) |
| 737 return status; | 767 return status; |
| 738 } | 768 } |
| 739 } | 769 } |
| 740 | 770 |
| 741 return Status(kOk); | 771 return Status(kOk); |
| 742 } | 772 } |
| OLD | NEW |