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 "chrome/browser/devtools/devtools_ui_bindings.h" | 5 #include "chrome/browser/devtools/devtools_ui_bindings.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include <memory> | 9 #include <memory> |
10 #include <utility> | 10 #include <utility> |
(...skipping 272 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
283 int num_bytes, | 283 int num_bytes, |
284 const net::CompletionCallback& callback) { | 284 const net::CompletionCallback& callback) { |
285 std::string chunk = std::string(buffer->data(), num_bytes); | 285 std::string chunk = std::string(buffer->data(), num_bytes); |
286 bool encoded = false; | 286 bool encoded = false; |
287 if (!base::IsStringUTF8(chunk)) { | 287 if (!base::IsStringUTF8(chunk)) { |
288 encoded = true; | 288 encoded = true; |
289 base::Base64Encode(chunk, &chunk); | 289 base::Base64Encode(chunk, &chunk); |
290 } | 290 } |
291 | 291 |
292 base::Value* id = new base::Value(stream_id_); | 292 base::Value* id = new base::Value(stream_id_); |
293 base::StringValue* chunkValue = new base::StringValue(chunk); | 293 base::Value* chunkValue = new base::Value(chunk); |
294 base::Value* encodedValue = new base::Value(encoded); | 294 base::Value* encodedValue = new base::Value(encoded); |
295 | 295 |
296 content::BrowserThread::PostTask( | 296 content::BrowserThread::PostTask( |
297 content::BrowserThread::UI, FROM_HERE, | 297 content::BrowserThread::UI, FROM_HERE, |
298 base::Bind(&DevToolsUIBindings::CallClientFunction, bindings_, | 298 base::Bind(&DevToolsUIBindings::CallClientFunction, bindings_, |
299 "DevToolsAPI.streamWrite", base::Owned(id), | 299 "DevToolsAPI.streamWrite", base::Owned(id), |
300 base::Owned(chunkValue), base::Owned(encodedValue))); | 300 base::Owned(chunkValue), base::Owned(encodedValue))); |
301 return num_bytes; | 301 return num_bytes; |
302 } | 302 } |
303 | 303 |
(...skipping 322 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
626 std::string param; | 626 std::string param; |
627 base::EscapeJSONString(message, true, ¶m); | 627 base::EscapeJSONString(message, true, ¶m); |
628 base::string16 javascript = | 628 base::string16 javascript = |
629 base::UTF8ToUTF16("DevToolsAPI.dispatchMessage(" + param + ");"); | 629 base::UTF8ToUTF16("DevToolsAPI.dispatchMessage(" + param + ");"); |
630 web_contents_->GetMainFrame()->ExecuteJavaScript(javascript); | 630 web_contents_->GetMainFrame()->ExecuteJavaScript(javascript); |
631 return; | 631 return; |
632 } | 632 } |
633 | 633 |
634 base::Value total_size(static_cast<int>(message.length())); | 634 base::Value total_size(static_cast<int>(message.length())); |
635 for (size_t pos = 0; pos < message.length(); pos += kMaxMessageChunkSize) { | 635 for (size_t pos = 0; pos < message.length(); pos += kMaxMessageChunkSize) { |
636 base::StringValue message_value(message.substr(pos, kMaxMessageChunkSize)); | 636 base::Value message_value(message.substr(pos, kMaxMessageChunkSize)); |
637 CallClientFunction("DevToolsAPI.dispatchMessageChunk", | 637 CallClientFunction("DevToolsAPI.dispatchMessageChunk", |
638 &message_value, pos ? NULL : &total_size, NULL); | 638 &message_value, pos ? NULL : &total_size, NULL); |
639 } | 639 } |
640 } | 640 } |
641 | 641 |
642 void DevToolsUIBindings::AgentHostClosed( | 642 void DevToolsUIBindings::AgentHostClosed( |
643 content::DevToolsAgentHost* agent_host, | 643 content::DevToolsAgentHost* agent_host, |
644 bool replaced_with_another_client) { | 644 bool replaced_with_another_client) { |
645 DCHECK(agent_host == agent_host_.get()); | 645 DCHECK(agent_host == agent_host_.get()); |
646 agent_host_ = NULL; | 646 agent_host_ = NULL; |
(...skipping 436 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1083 callback)); | 1083 callback)); |
1084 } | 1084 } |
1085 | 1085 |
1086 void DevToolsUIBindings::JsonReceived(const DispatchCallback& callback, | 1086 void DevToolsUIBindings::JsonReceived(const DispatchCallback& callback, |
1087 int result, | 1087 int result, |
1088 const std::string& message) { | 1088 const std::string& message) { |
1089 if (result != net::OK) { | 1089 if (result != net::OK) { |
1090 callback.Run(nullptr); | 1090 callback.Run(nullptr); |
1091 return; | 1091 return; |
1092 } | 1092 } |
1093 base::StringValue message_value(message); | 1093 base::Value message_value(message); |
1094 callback.Run(&message_value); | 1094 callback.Run(&message_value); |
1095 } | 1095 } |
1096 | 1096 |
1097 void DevToolsUIBindings::OnURLFetchComplete(const net::URLFetcher* source) { | 1097 void DevToolsUIBindings::OnURLFetchComplete(const net::URLFetcher* source) { |
1098 DCHECK(source); | 1098 DCHECK(source); |
1099 PendingRequestsMap::iterator it = pending_requests_.find(source); | 1099 PendingRequestsMap::iterator it = pending_requests_.find(source); |
1100 DCHECK(it != pending_requests_.end()); | 1100 DCHECK(it != pending_requests_.end()); |
1101 | 1101 |
1102 base::DictionaryValue response; | 1102 base::DictionaryValue response; |
1103 base::DictionaryValue* headers = new base::DictionaryValue(); | 1103 base::DictionaryValue* headers = new base::DictionaryValue(); |
(...skipping 19 matching lines...) Expand all Loading... |
1123 } | 1123 } |
1124 | 1124 |
1125 void DevToolsUIBindings::DevicesUpdated( | 1125 void DevToolsUIBindings::DevicesUpdated( |
1126 const std::string& source, | 1126 const std::string& source, |
1127 const base::ListValue& targets) { | 1127 const base::ListValue& targets) { |
1128 CallClientFunction("DevToolsAPI.devicesUpdated", &targets, NULL, | 1128 CallClientFunction("DevToolsAPI.devicesUpdated", &targets, NULL, |
1129 NULL); | 1129 NULL); |
1130 } | 1130 } |
1131 | 1131 |
1132 void DevToolsUIBindings::FileSavedAs(const std::string& url) { | 1132 void DevToolsUIBindings::FileSavedAs(const std::string& url) { |
1133 base::StringValue url_value(url); | 1133 base::Value url_value(url); |
1134 CallClientFunction("DevToolsAPI.savedURL", &url_value, NULL, NULL); | 1134 CallClientFunction("DevToolsAPI.savedURL", &url_value, NULL, NULL); |
1135 } | 1135 } |
1136 | 1136 |
1137 void DevToolsUIBindings::CanceledFileSaveAs(const std::string& url) { | 1137 void DevToolsUIBindings::CanceledFileSaveAs(const std::string& url) { |
1138 base::StringValue url_value(url); | 1138 base::Value url_value(url); |
1139 CallClientFunction("DevToolsAPI.canceledSaveURL", | 1139 CallClientFunction("DevToolsAPI.canceledSaveURL", |
1140 &url_value, NULL, NULL); | 1140 &url_value, NULL, NULL); |
1141 } | 1141 } |
1142 | 1142 |
1143 void DevToolsUIBindings::AppendedTo(const std::string& url) { | 1143 void DevToolsUIBindings::AppendedTo(const std::string& url) { |
1144 base::StringValue url_value(url); | 1144 base::Value url_value(url); |
1145 CallClientFunction("DevToolsAPI.appendedToURL", &url_value, NULL, | 1145 CallClientFunction("DevToolsAPI.appendedToURL", &url_value, NULL, |
1146 NULL); | 1146 NULL); |
1147 } | 1147 } |
1148 | 1148 |
1149 void DevToolsUIBindings::FileSystemAdded( | 1149 void DevToolsUIBindings::FileSystemAdded( |
1150 const DevToolsFileHelper::FileSystem& file_system) { | 1150 const DevToolsFileHelper::FileSystem& file_system) { |
1151 std::unique_ptr<base::DictionaryValue> file_system_value( | 1151 std::unique_ptr<base::DictionaryValue> file_system_value( |
1152 CreateFileSystemValue(file_system)); | 1152 CreateFileSystemValue(file_system)); |
1153 CallClientFunction("DevToolsAPI.fileSystemAdded", | 1153 CallClientFunction("DevToolsAPI.fileSystemAdded", |
1154 file_system_value.get(), NULL, NULL); | 1154 file_system_value.get(), NULL, NULL); |
1155 } | 1155 } |
1156 | 1156 |
1157 void DevToolsUIBindings::FileSystemRemoved( | 1157 void DevToolsUIBindings::FileSystemRemoved( |
1158 const std::string& file_system_path) { | 1158 const std::string& file_system_path) { |
1159 base::StringValue file_system_path_value(file_system_path); | 1159 base::Value file_system_path_value(file_system_path); |
1160 CallClientFunction("DevToolsAPI.fileSystemRemoved", | 1160 CallClientFunction("DevToolsAPI.fileSystemRemoved", |
1161 &file_system_path_value, NULL, NULL); | 1161 &file_system_path_value, NULL, NULL); |
1162 } | 1162 } |
1163 | 1163 |
1164 void DevToolsUIBindings::FilePathsChanged( | 1164 void DevToolsUIBindings::FilePathsChanged( |
1165 const std::vector<std::string>& changed_paths, | 1165 const std::vector<std::string>& changed_paths, |
1166 const std::vector<std::string>& added_paths, | 1166 const std::vector<std::string>& added_paths, |
1167 const std::vector<std::string>& removed_paths) { | 1167 const std::vector<std::string>& removed_paths) { |
1168 base::ListValue changed, added, removed; | 1168 base::ListValue changed, added, removed; |
1169 changed.AppendStrings(changed_paths); | 1169 changed.AppendStrings(changed_paths); |
1170 added.AppendStrings(added_paths); | 1170 added.AppendStrings(added_paths); |
1171 removed.AppendStrings(removed_paths); | 1171 removed.AppendStrings(removed_paths); |
1172 | 1172 |
1173 CallClientFunction("DevToolsAPI.fileSystemFilesChangedAddedRemoved", &changed, | 1173 CallClientFunction("DevToolsAPI.fileSystemFilesChangedAddedRemoved", &changed, |
1174 &added, &removed); | 1174 &added, &removed); |
1175 } | 1175 } |
1176 | 1176 |
1177 void DevToolsUIBindings::IndexingTotalWorkCalculated( | 1177 void DevToolsUIBindings::IndexingTotalWorkCalculated( |
1178 int request_id, | 1178 int request_id, |
1179 const std::string& file_system_path, | 1179 const std::string& file_system_path, |
1180 int total_work) { | 1180 int total_work) { |
1181 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 1181 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
1182 base::Value request_id_value(request_id); | 1182 base::Value request_id_value(request_id); |
1183 base::StringValue file_system_path_value(file_system_path); | 1183 base::Value file_system_path_value(file_system_path); |
1184 base::Value total_work_value(total_work); | 1184 base::Value total_work_value(total_work); |
1185 CallClientFunction("DevToolsAPI.indexingTotalWorkCalculated", | 1185 CallClientFunction("DevToolsAPI.indexingTotalWorkCalculated", |
1186 &request_id_value, &file_system_path_value, | 1186 &request_id_value, &file_system_path_value, |
1187 &total_work_value); | 1187 &total_work_value); |
1188 } | 1188 } |
1189 | 1189 |
1190 void DevToolsUIBindings::IndexingWorked(int request_id, | 1190 void DevToolsUIBindings::IndexingWorked(int request_id, |
1191 const std::string& file_system_path, | 1191 const std::string& file_system_path, |
1192 int worked) { | 1192 int worked) { |
1193 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 1193 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
1194 base::Value request_id_value(request_id); | 1194 base::Value request_id_value(request_id); |
1195 base::StringValue file_system_path_value(file_system_path); | 1195 base::Value file_system_path_value(file_system_path); |
1196 base::Value worked_value(worked); | 1196 base::Value worked_value(worked); |
1197 CallClientFunction("DevToolsAPI.indexingWorked", &request_id_value, | 1197 CallClientFunction("DevToolsAPI.indexingWorked", &request_id_value, |
1198 &file_system_path_value, &worked_value); | 1198 &file_system_path_value, &worked_value); |
1199 } | 1199 } |
1200 | 1200 |
1201 void DevToolsUIBindings::IndexingDone(int request_id, | 1201 void DevToolsUIBindings::IndexingDone(int request_id, |
1202 const std::string& file_system_path) { | 1202 const std::string& file_system_path) { |
1203 indexing_jobs_.erase(request_id); | 1203 indexing_jobs_.erase(request_id); |
1204 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 1204 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
1205 base::Value request_id_value(request_id); | 1205 base::Value request_id_value(request_id); |
1206 base::StringValue file_system_path_value(file_system_path); | 1206 base::Value file_system_path_value(file_system_path); |
1207 CallClientFunction("DevToolsAPI.indexingDone", &request_id_value, | 1207 CallClientFunction("DevToolsAPI.indexingDone", &request_id_value, |
1208 &file_system_path_value, NULL); | 1208 &file_system_path_value, NULL); |
1209 } | 1209 } |
1210 | 1210 |
1211 void DevToolsUIBindings::SearchCompleted( | 1211 void DevToolsUIBindings::SearchCompleted( |
1212 int request_id, | 1212 int request_id, |
1213 const std::string& file_system_path, | 1213 const std::string& file_system_path, |
1214 const std::vector<std::string>& file_paths) { | 1214 const std::vector<std::string>& file_paths) { |
1215 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 1215 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
1216 base::ListValue file_paths_value; | 1216 base::ListValue file_paths_value; |
1217 for (std::vector<std::string>::const_iterator it(file_paths.begin()); | 1217 for (std::vector<std::string>::const_iterator it(file_paths.begin()); |
1218 it != file_paths.end(); ++it) { | 1218 it != file_paths.end(); ++it) { |
1219 file_paths_value.AppendString(*it); | 1219 file_paths_value.AppendString(*it); |
1220 } | 1220 } |
1221 base::Value request_id_value(request_id); | 1221 base::Value request_id_value(request_id); |
1222 base::StringValue file_system_path_value(file_system_path); | 1222 base::Value file_system_path_value(file_system_path); |
1223 CallClientFunction("DevToolsAPI.searchCompleted", &request_id_value, | 1223 CallClientFunction("DevToolsAPI.searchCompleted", &request_id_value, |
1224 &file_system_path_value, &file_paths_value); | 1224 &file_system_path_value, &file_paths_value); |
1225 } | 1225 } |
1226 | 1226 |
1227 void DevToolsUIBindings::ShowDevToolsConfirmInfoBar( | 1227 void DevToolsUIBindings::ShowDevToolsConfirmInfoBar( |
1228 const base::string16& message, | 1228 const base::string16& message, |
1229 const InfoBarCallback& callback) { | 1229 const InfoBarCallback& callback) { |
1230 if (!delegate_->GetInfoBarService()) { | 1230 if (!delegate_->GetInfoBarService()) { |
1231 callback.Run(false); | 1231 callback.Run(false); |
1232 return; | 1232 return; |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1267 // process. Grant each specific extension's origin permission to load | 1267 // process. Grant each specific extension's origin permission to load |
1268 // documents. | 1268 // documents. |
1269 content::ChildProcessSecurityPolicy::GetInstance()->GrantOrigin( | 1269 content::ChildProcessSecurityPolicy::GetInstance()->GrantOrigin( |
1270 web_contents_->GetMainFrame()->GetProcess()->GetID(), | 1270 web_contents_->GetMainFrame()->GetProcess()->GetID(), |
1271 url::Origin(extension->url())); | 1271 url::Origin(extension->url())); |
1272 | 1272 |
1273 std::unique_ptr<base::DictionaryValue> extension_info( | 1273 std::unique_ptr<base::DictionaryValue> extension_info( |
1274 new base::DictionaryValue()); | 1274 new base::DictionaryValue()); |
1275 extension_info->Set( | 1275 extension_info->Set( |
1276 "startPage", | 1276 "startPage", |
1277 new base::StringValue(extensions::chrome_manifest_urls::GetDevToolsPage( | 1277 new base::Value( |
1278 extension.get()).spec())); | 1278 extensions::chrome_manifest_urls::GetDevToolsPage(extension.get()) |
1279 extension_info->Set("name", new base::StringValue(extension->name())); | 1279 .spec())); |
| 1280 extension_info->Set("name", new base::Value(extension->name())); |
1280 extension_info->Set( | 1281 extension_info->Set( |
1281 "exposeExperimentalAPIs", | 1282 "exposeExperimentalAPIs", |
1282 new base::Value(extension->permissions_data()->HasAPIPermission( | 1283 new base::Value(extension->permissions_data()->HasAPIPermission( |
1283 extensions::APIPermission::kExperimental))); | 1284 extensions::APIPermission::kExperimental))); |
1284 results.Append(std::move(extension_info)); | 1285 results.Append(std::move(extension_info)); |
1285 } | 1286 } |
1286 | 1287 |
1287 CallClientFunction("DevToolsAPI.addExtensions", | 1288 CallClientFunction("DevToolsAPI.addExtensions", |
1288 &results, NULL, NULL); | 1289 &results, NULL, NULL); |
1289 } | 1290 } |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1369 void DevToolsUIBindings::FrontendLoaded() { | 1370 void DevToolsUIBindings::FrontendLoaded() { |
1370 if (frontend_loaded_) | 1371 if (frontend_loaded_) |
1371 return; | 1372 return; |
1372 frontend_loaded_ = true; | 1373 frontend_loaded_ = true; |
1373 | 1374 |
1374 // Call delegate first - it seeds importants bit of information. | 1375 // Call delegate first - it seeds importants bit of information. |
1375 delegate_->OnLoadCompleted(); | 1376 delegate_->OnLoadCompleted(); |
1376 | 1377 |
1377 AddDevToolsExtensionsToClient(); | 1378 AddDevToolsExtensionsToClient(); |
1378 } | 1379 } |
OLD | NEW |