| 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/web_view/web_view_internal_api.h" | 5 #include "extensions/browser/api/web_view/web_view_internal_api.h" |
| 6 | 6 |
| 7 #include "base/strings/stringprintf.h" | 7 #include "base/strings/stringprintf.h" |
| 8 #include "base/strings/utf_string_conversions.h" | 8 #include "base/strings/utf_string_conversions.h" |
| 9 #include "content/public/browser/render_process_host.h" | 9 #include "content/public/browser/render_process_host.h" |
| 10 #include "content/public/browser/render_view_host.h" | 10 #include "content/public/browser/render_view_host.h" |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 63 bool WebViewInternalNavigateFunction::RunAsyncSafe(WebViewGuest* guest) { | 63 bool WebViewInternalNavigateFunction::RunAsyncSafe(WebViewGuest* guest) { |
| 64 scoped_ptr<webview::Navigate::Params> params( | 64 scoped_ptr<webview::Navigate::Params> params( |
| 65 webview::Navigate::Params::Create(*args_)); | 65 webview::Navigate::Params::Create(*args_)); |
| 66 EXTENSION_FUNCTION_VALIDATE(params.get()); | 66 EXTENSION_FUNCTION_VALIDATE(params.get()); |
| 67 std::string src = params->src; | 67 std::string src = params->src; |
| 68 guest->NavigateGuest(src, true /* force_navigation */); | 68 guest->NavigateGuest(src, true /* force_navigation */); |
| 69 return true; | 69 return true; |
| 70 } | 70 } |
| 71 | 71 |
| 72 WebViewInternalExecuteCodeFunction::WebViewInternalExecuteCodeFunction() | 72 WebViewInternalExecuteCodeFunction::WebViewInternalExecuteCodeFunction() |
| 73 : guest_instance_id_(0), guest_src_(GURL::EmptyGURL()) { | 73 : guest_instance_id_(0), |
| 74 guest_src_(GURL::EmptyGURL()), |
| 75 script_injection_instance_id_(0) { |
| 74 } | 76 } |
| 75 | 77 |
| 76 WebViewInternalExecuteCodeFunction::~WebViewInternalExecuteCodeFunction() { | 78 WebViewInternalExecuteCodeFunction::~WebViewInternalExecuteCodeFunction() { |
| 77 } | 79 } |
| 78 | 80 |
| 79 bool WebViewInternalExecuteCodeFunction::Init() { | 81 bool WebViewInternalExecuteCodeFunction::Init() { |
| 80 if (details_.get()) | 82 if (details_.get()) |
| 81 return true; | 83 return true; |
| 82 | 84 |
| 83 if (!args_->GetInteger(0, &guest_instance_id_)) | 85 if (!args_->GetInteger(0, &guest_instance_id_)) |
| (...skipping 11 matching lines...) Expand all Loading... |
| 95 return false; | 97 return false; |
| 96 | 98 |
| 97 base::DictionaryValue* details_value = NULL; | 99 base::DictionaryValue* details_value = NULL; |
| 98 if (!args_->GetDictionary(2, &details_value)) | 100 if (!args_->GetDictionary(2, &details_value)) |
| 99 return false; | 101 return false; |
| 100 scoped_ptr<InjectDetails> details(new InjectDetails()); | 102 scoped_ptr<InjectDetails> details(new InjectDetails()); |
| 101 if (!InjectDetails::Populate(*details_value, details.get())) | 103 if (!InjectDetails::Populate(*details_value, details.get())) |
| 102 return false; | 104 return false; |
| 103 | 105 |
| 104 details_ = details.Pass(); | 106 details_ = details.Pass(); |
| 107 script_injection_instance_id_ = |
| 108 WebViewGuest::GetOrGenerateScriptInjectionInstanceID( |
| 109 render_view_host()->GetProcess()->GetID(), guest_instance_id_); |
| 110 |
| 105 return true; | 111 return true; |
| 106 } | 112 } |
| 107 | 113 |
| 108 bool WebViewInternalExecuteCodeFunction::ShouldInsertCSS() const { | 114 bool WebViewInternalExecuteCodeFunction::ShouldInsertCSS() const { |
| 109 return false; | 115 return false; |
| 110 } | 116 } |
| 111 | 117 |
| 112 bool WebViewInternalExecuteCodeFunction::CanExecuteScriptOnPage() { | 118 bool WebViewInternalExecuteCodeFunction::CanExecuteScriptOnPage() { |
| 113 return true; | 119 return true; |
| 114 } | 120 } |
| (...skipping 11 matching lines...) Expand all Loading... |
| 126 } | 132 } |
| 127 | 133 |
| 128 bool WebViewInternalExecuteCodeFunction::IsWebView() const { | 134 bool WebViewInternalExecuteCodeFunction::IsWebView() const { |
| 129 return true; | 135 return true; |
| 130 } | 136 } |
| 131 | 137 |
| 132 const GURL& WebViewInternalExecuteCodeFunction::GetWebViewSrc() const { | 138 const GURL& WebViewInternalExecuteCodeFunction::GetWebViewSrc() const { |
| 133 return guest_src_; | 139 return guest_src_; |
| 134 } | 140 } |
| 135 | 141 |
| 142 int WebViewInternalExecuteCodeFunction:: GetScriptInjectionInstanceId() const { |
| 143 return script_injection_instance_id_; |
| 144 } |
| 145 |
| 136 WebViewInternalExecuteScriptFunction::WebViewInternalExecuteScriptFunction() { | 146 WebViewInternalExecuteScriptFunction::WebViewInternalExecuteScriptFunction() { |
| 137 } | 147 } |
| 138 | 148 |
| 139 void WebViewInternalExecuteScriptFunction::OnExecuteCodeFinished( | 149 void WebViewInternalExecuteScriptFunction::OnExecuteCodeFinished( |
| 140 const std::string& error, | 150 const std::string& error, |
| 141 const GURL& on_url, | 151 const GURL& on_url, |
| 142 const base::ListValue& result) { | 152 const base::ListValue& result) { |
| 143 if (error.empty()) | 153 if (error.empty()) |
| 144 SetResult(result.DeepCopy()); | 154 SetResult(result.DeepCopy()); |
| 145 WebViewInternalExecuteCodeFunction::OnExecuteCodeFinished( | 155 WebViewInternalExecuteCodeFunction::OnExecuteCodeFinished( |
| (...skipping 347 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 493 // Will finish asynchronously. | 503 // Will finish asynchronously. |
| 494 return true; | 504 return true; |
| 495 } | 505 } |
| 496 | 506 |
| 497 void WebViewInternalClearDataFunction::ClearDataDone() { | 507 void WebViewInternalClearDataFunction::ClearDataDone() { |
| 498 Release(); // Balanced in RunAsync(). | 508 Release(); // Balanced in RunAsync(). |
| 499 SendResponse(true); | 509 SendResponse(true); |
| 500 } | 510 } |
| 501 | 511 |
| 502 } // namespace extensions | 512 } // namespace extensions |
| OLD | NEW |