| 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/guest_view/web_view/web_view_internal_api.h" | 5 #include "extensions/browser/api/guest_view/web_view/web_view_internal_api.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/guid.h" | 9 #include "base/guid.h" |
| 10 #include "base/memory/ptr_util.h" | 10 #include "base/memory/ptr_util.h" |
| (...skipping 347 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 358 guest_->NavigateGuest(src, true /* force_navigation */); | 358 guest_->NavigateGuest(src, true /* force_navigation */); |
| 359 return RespondNow(NoArguments()); | 359 return RespondNow(NoArguments()); |
| 360 } | 360 } |
| 361 | 361 |
| 362 WebViewInternalExecuteCodeFunction::WebViewInternalExecuteCodeFunction() | 362 WebViewInternalExecuteCodeFunction::WebViewInternalExecuteCodeFunction() |
| 363 : guest_instance_id_(0) {} | 363 : guest_instance_id_(0) {} |
| 364 | 364 |
| 365 WebViewInternalExecuteCodeFunction::~WebViewInternalExecuteCodeFunction() { | 365 WebViewInternalExecuteCodeFunction::~WebViewInternalExecuteCodeFunction() { |
| 366 } | 366 } |
| 367 | 367 |
| 368 bool WebViewInternalExecuteCodeFunction::Init() { | 368 ExecuteCodeFunction::InitResult WebViewInternalExecuteCodeFunction::Init() { |
| 369 if (details_.get()) | 369 if (init_result_) |
| 370 return true; | 370 return init_result_.value(); |
| 371 | 371 |
| 372 if (!args_->GetInteger(0, &guest_instance_id_)) | 372 if (!args_->GetInteger(0, &guest_instance_id_) || !guest_instance_id_) |
| 373 return false; | 373 return set_init_result(VALIDATION_FAILURE); |
| 374 | |
| 375 if (!guest_instance_id_) | |
| 376 return false; | |
| 377 | 374 |
| 378 std::string src; | 375 std::string src; |
| 379 if (!args_->GetString(1, &src)) | 376 if (!args_->GetString(1, &src)) |
| 380 return false; | 377 return set_init_result(VALIDATION_FAILURE); |
| 381 | 378 |
| 382 // Set |guest_src_| here, but do not return false if it is invalid. | 379 // Set |guest_src_| here, but do not return false if it is invalid. |
| 383 // Instead, let it continue with the normal page load sequence, | 380 // Instead, let it continue with the normal page load sequence, |
| 384 // which will result in the usual LOAD_ABORT event in the case where | 381 // which will result in the usual LOAD_ABORT event in the case where |
| 385 // the URL is invalid. | 382 // the URL is invalid. |
| 386 guest_src_ = GURL(src); | 383 guest_src_ = GURL(src); |
| 387 | 384 |
| 388 base::DictionaryValue* details_value = NULL; | 385 base::DictionaryValue* details_value = NULL; |
| 389 if (!args_->GetDictionary(2, &details_value)) | 386 if (!args_->GetDictionary(2, &details_value)) |
| 390 return false; | 387 return set_init_result(VALIDATION_FAILURE); |
| 391 std::unique_ptr<InjectDetails> details(new InjectDetails()); | 388 std::unique_ptr<InjectDetails> details(new InjectDetails()); |
| 392 if (!InjectDetails::Populate(*details_value, details.get())) | 389 if (!InjectDetails::Populate(*details_value, details.get())) |
| 393 return false; | 390 return set_init_result(VALIDATION_FAILURE); |
| 394 | 391 |
| 395 details_ = std::move(details); | 392 details_ = std::move(details); |
| 396 | 393 |
| 397 if (extension()) { | 394 if (extension()) { |
| 398 set_host_id(HostID(HostID::EXTENSIONS, extension()->id())); | 395 set_host_id(HostID(HostID::EXTENSIONS, extension()->id())); |
| 399 return true; | 396 return set_init_result(SUCCESS); |
| 400 } | 397 } |
| 401 | 398 |
| 402 WebContents* web_contents = GetSenderWebContents(); | 399 WebContents* web_contents = GetSenderWebContents(); |
| 403 if (web_contents && web_contents->GetWebUI()) { | 400 if (web_contents && web_contents->GetWebUI()) { |
| 404 const GURL& url = render_frame_host()->GetSiteInstance()->GetSiteURL(); | 401 const GURL& url = render_frame_host()->GetSiteInstance()->GetSiteURL(); |
| 405 set_host_id(HostID(HostID::WEBUI, url.spec())); | 402 set_host_id(HostID(HostID::WEBUI, url.spec())); |
| 406 return true; | 403 return set_init_result(SUCCESS); |
| 407 } | 404 } |
| 408 return false; | 405 return set_init_result_error(""); // TODO(lazyboy): error? |
| 409 } | 406 } |
| 410 | 407 |
| 411 bool WebViewInternalExecuteCodeFunction::ShouldInsertCSS() const { | 408 bool WebViewInternalExecuteCodeFunction::ShouldInsertCSS() const { |
| 412 return false; | 409 return false; |
| 413 } | 410 } |
| 414 | 411 |
| 415 bool WebViewInternalExecuteCodeFunction::CanExecuteScriptOnPage() { | 412 bool WebViewInternalExecuteCodeFunction::CanExecuteScriptOnPage() { |
| 416 return true; | 413 return true; |
| 417 } | 414 } |
| 418 | 415 |
| (...skipping 559 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 978 // Will finish asynchronously. | 975 // Will finish asynchronously. |
| 979 return true; | 976 return true; |
| 980 } | 977 } |
| 981 | 978 |
| 982 void WebViewInternalClearDataFunction::ClearDataDone() { | 979 void WebViewInternalClearDataFunction::ClearDataDone() { |
| 983 Release(); // Balanced in RunAsync(). | 980 Release(); // Balanced in RunAsync(). |
| 984 SendResponse(true); | 981 SendResponse(true); |
| 985 } | 982 } |
| 986 | 983 |
| 987 } // namespace extensions | 984 } // namespace extensions |
| OLD | NEW |