| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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_window.h" | 5 #include "chrome/browser/devtools/devtools_window.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
| 10 #include "base/json/json_reader.h" | 10 #include "base/json/json_reader.h" |
| (...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 243 | 243 |
| 244 std::string SkColorToRGBAString(SkColor color) { | 244 std::string SkColorToRGBAString(SkColor color) { |
| 245 // We avoid StringPrintf because it will use locale specific formatters for | 245 // We avoid StringPrintf because it will use locale specific formatters for |
| 246 // the double (e.g. ',' instead of '.' in German). | 246 // the double (e.g. ',' instead of '.' in German). |
| 247 return "rgba(" + base::IntToString(SkColorGetR(color)) + "," + | 247 return "rgba(" + base::IntToString(SkColorGetR(color)) + "," + |
| 248 base::IntToString(SkColorGetG(color)) + "," + | 248 base::IntToString(SkColorGetG(color)) + "," + |
| 249 base::IntToString(SkColorGetB(color)) + "," + | 249 base::IntToString(SkColorGetB(color)) + "," + |
| 250 base::DoubleToString(SkColorGetA(color) / 255.0) + ")"; | 250 base::DoubleToString(SkColorGetA(color) / 255.0) + ")"; |
| 251 } | 251 } |
| 252 | 252 |
| 253 DictionaryValue* CreateFileSystemValue( | 253 base::DictionaryValue* CreateFileSystemValue( |
| 254 DevToolsFileHelper::FileSystem file_system) { | 254 DevToolsFileHelper::FileSystem file_system) { |
| 255 DictionaryValue* file_system_value = new DictionaryValue(); | 255 base::DictionaryValue* file_system_value = new base::DictionaryValue(); |
| 256 file_system_value->SetString("fileSystemName", file_system.file_system_name); | 256 file_system_value->SetString("fileSystemName", file_system.file_system_name); |
| 257 file_system_value->SetString("rootURL", file_system.root_url); | 257 file_system_value->SetString("rootURL", file_system.root_url); |
| 258 file_system_value->SetString("fileSystemPath", file_system.file_system_path); | 258 file_system_value->SetString("fileSystemPath", file_system.file_system_path); |
| 259 return file_system_value; | 259 return file_system_value; |
| 260 } | 260 } |
| 261 | 261 |
| 262 } // namespace | 262 } // namespace |
| 263 | 263 |
| 264 const char DevToolsWindow::kDevToolsApp[] = "DevToolsApp"; | 264 const char DevToolsWindow::kDevToolsApp[] = "DevToolsApp"; |
| 265 | 265 |
| (...skipping 852 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1118 CHECK(web_contents_->GetURL().SchemeIs(chrome::kChromeDevToolsScheme)); | 1118 CHECK(web_contents_->GetURL().SchemeIs(chrome::kChromeDevToolsScheme)); |
| 1119 file_helper_->AddFileSystem( | 1119 file_helper_->AddFileSystem( |
| 1120 base::Bind(&DevToolsWindow::FileSystemAdded, weak_factory_.GetWeakPtr()), | 1120 base::Bind(&DevToolsWindow::FileSystemAdded, weak_factory_.GetWeakPtr()), |
| 1121 base::Bind(&DevToolsWindow::ShowDevToolsConfirmInfoBar, | 1121 base::Bind(&DevToolsWindow::ShowDevToolsConfirmInfoBar, |
| 1122 weak_factory_.GetWeakPtr())); | 1122 weak_factory_.GetWeakPtr())); |
| 1123 } | 1123 } |
| 1124 | 1124 |
| 1125 void DevToolsWindow::RemoveFileSystem(const std::string& file_system_path) { | 1125 void DevToolsWindow::RemoveFileSystem(const std::string& file_system_path) { |
| 1126 CHECK(web_contents_->GetURL().SchemeIs(chrome::kChromeDevToolsScheme)); | 1126 CHECK(web_contents_->GetURL().SchemeIs(chrome::kChromeDevToolsScheme)); |
| 1127 file_helper_->RemoveFileSystem(file_system_path); | 1127 file_helper_->RemoveFileSystem(file_system_path); |
| 1128 StringValue file_system_path_value(file_system_path); | 1128 base::StringValue file_system_path_value(file_system_path); |
| 1129 CallClientFunction("InspectorFrontendAPI.fileSystemRemoved", | 1129 CallClientFunction("InspectorFrontendAPI.fileSystemRemoved", |
| 1130 &file_system_path_value, NULL, NULL); | 1130 &file_system_path_value, NULL, NULL); |
| 1131 } | 1131 } |
| 1132 | 1132 |
| 1133 void DevToolsWindow::UpgradeDraggedFileSystemPermissions( | 1133 void DevToolsWindow::UpgradeDraggedFileSystemPermissions( |
| 1134 const std::string& file_system_url) { | 1134 const std::string& file_system_url) { |
| 1135 CHECK(web_contents_->GetURL().SchemeIs(chrome::kChromeDevToolsScheme)); | 1135 CHECK(web_contents_->GetURL().SchemeIs(chrome::kChromeDevToolsScheme)); |
| 1136 file_helper_->UpgradeDraggedFileSystemPermissions( | 1136 file_helper_->UpgradeDraggedFileSystemPermissions( |
| 1137 file_system_url, | 1137 file_system_url, |
| 1138 base::Bind(&DevToolsWindow::FileSystemAdded, weak_factory_.GetWeakPtr()), | 1138 base::Bind(&DevToolsWindow::FileSystemAdded, weak_factory_.GetWeakPtr()), |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1186 } | 1186 } |
| 1187 file_system_indexer_->SearchInPath(file_system_path, | 1187 file_system_indexer_->SearchInPath(file_system_path, |
| 1188 query, | 1188 query, |
| 1189 Bind(&DevToolsWindow::SearchCompleted, | 1189 Bind(&DevToolsWindow::SearchCompleted, |
| 1190 weak_factory_.GetWeakPtr(), | 1190 weak_factory_.GetWeakPtr(), |
| 1191 request_id, | 1191 request_id, |
| 1192 file_system_path)); | 1192 file_system_path)); |
| 1193 } | 1193 } |
| 1194 | 1194 |
| 1195 void DevToolsWindow::FileSavedAs(const std::string& url) { | 1195 void DevToolsWindow::FileSavedAs(const std::string& url) { |
| 1196 StringValue url_value(url); | 1196 base::StringValue url_value(url); |
| 1197 CallClientFunction("InspectorFrontendAPI.savedURL", &url_value, NULL, NULL); | 1197 CallClientFunction("InspectorFrontendAPI.savedURL", &url_value, NULL, NULL); |
| 1198 } | 1198 } |
| 1199 | 1199 |
| 1200 void DevToolsWindow::CanceledFileSaveAs(const std::string& url) { | 1200 void DevToolsWindow::CanceledFileSaveAs(const std::string& url) { |
| 1201 StringValue url_value(url); | 1201 base::StringValue url_value(url); |
| 1202 CallClientFunction("InspectorFrontendAPI.canceledSaveURL", | 1202 CallClientFunction("InspectorFrontendAPI.canceledSaveURL", |
| 1203 &url_value, NULL, NULL); | 1203 &url_value, NULL, NULL); |
| 1204 } | 1204 } |
| 1205 | 1205 |
| 1206 void DevToolsWindow::AppendedTo(const std::string& url) { | 1206 void DevToolsWindow::AppendedTo(const std::string& url) { |
| 1207 StringValue url_value(url); | 1207 base::StringValue url_value(url); |
| 1208 CallClientFunction("InspectorFrontendAPI.appendedToURL", &url_value, NULL, | 1208 CallClientFunction("InspectorFrontendAPI.appendedToURL", &url_value, NULL, |
| 1209 NULL); | 1209 NULL); |
| 1210 } | 1210 } |
| 1211 | 1211 |
| 1212 void DevToolsWindow::FileSystemsLoaded( | 1212 void DevToolsWindow::FileSystemsLoaded( |
| 1213 const std::vector<DevToolsFileHelper::FileSystem>& file_systems) { | 1213 const std::vector<DevToolsFileHelper::FileSystem>& file_systems) { |
| 1214 ListValue file_systems_value; | 1214 base::ListValue file_systems_value; |
| 1215 for (size_t i = 0; i < file_systems.size(); ++i) | 1215 for (size_t i = 0; i < file_systems.size(); ++i) |
| 1216 file_systems_value.Append(CreateFileSystemValue(file_systems[i])); | 1216 file_systems_value.Append(CreateFileSystemValue(file_systems[i])); |
| 1217 CallClientFunction("InspectorFrontendAPI.fileSystemsLoaded", | 1217 CallClientFunction("InspectorFrontendAPI.fileSystemsLoaded", |
| 1218 &file_systems_value, NULL, NULL); | 1218 &file_systems_value, NULL, NULL); |
| 1219 } | 1219 } |
| 1220 | 1220 |
| 1221 void DevToolsWindow::FileSystemAdded( | 1221 void DevToolsWindow::FileSystemAdded( |
| 1222 const DevToolsFileHelper::FileSystem& file_system) { | 1222 const DevToolsFileHelper::FileSystem& file_system) { |
| 1223 scoped_ptr<base::StringValue> error_string_value( | 1223 scoped_ptr<base::StringValue> error_string_value( |
| 1224 new base::StringValue(std::string())); | 1224 new base::StringValue(std::string())); |
| 1225 scoped_ptr<base::DictionaryValue> file_system_value; | 1225 scoped_ptr<base::DictionaryValue> file_system_value; |
| 1226 if (!file_system.file_system_path.empty()) | 1226 if (!file_system.file_system_path.empty()) |
| 1227 file_system_value.reset(CreateFileSystemValue(file_system)); | 1227 file_system_value.reset(CreateFileSystemValue(file_system)); |
| 1228 CallClientFunction("InspectorFrontendAPI.fileSystemAdded", | 1228 CallClientFunction("InspectorFrontendAPI.fileSystemAdded", |
| 1229 error_string_value.get(), file_system_value.get(), NULL); | 1229 error_string_value.get(), file_system_value.get(), NULL); |
| 1230 } | 1230 } |
| 1231 | 1231 |
| 1232 void DevToolsWindow::IndexingTotalWorkCalculated( | 1232 void DevToolsWindow::IndexingTotalWorkCalculated( |
| 1233 int request_id, | 1233 int request_id, |
| 1234 const std::string& file_system_path, | 1234 const std::string& file_system_path, |
| 1235 int total_work) { | 1235 int total_work) { |
| 1236 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 1236 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 1237 base::FundamentalValue request_id_value(request_id); | 1237 base::FundamentalValue request_id_value(request_id); |
| 1238 StringValue file_system_path_value(file_system_path); | 1238 base::StringValue file_system_path_value(file_system_path); |
| 1239 base::FundamentalValue total_work_value(total_work); | 1239 base::FundamentalValue total_work_value(total_work); |
| 1240 CallClientFunction("InspectorFrontendAPI.indexingTotalWorkCalculated", | 1240 CallClientFunction("InspectorFrontendAPI.indexingTotalWorkCalculated", |
| 1241 &request_id_value, &file_system_path_value, | 1241 &request_id_value, &file_system_path_value, |
| 1242 &total_work_value); | 1242 &total_work_value); |
| 1243 } | 1243 } |
| 1244 | 1244 |
| 1245 void DevToolsWindow::IndexingWorked(int request_id, | 1245 void DevToolsWindow::IndexingWorked(int request_id, |
| 1246 const std::string& file_system_path, | 1246 const std::string& file_system_path, |
| 1247 int worked) { | 1247 int worked) { |
| 1248 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 1248 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 1249 base::FundamentalValue request_id_value(request_id); | 1249 base::FundamentalValue request_id_value(request_id); |
| 1250 StringValue file_system_path_value(file_system_path); | 1250 base::StringValue file_system_path_value(file_system_path); |
| 1251 base::FundamentalValue worked_value(worked); | 1251 base::FundamentalValue worked_value(worked); |
| 1252 CallClientFunction("InspectorFrontendAPI.indexingWorked", &request_id_value, | 1252 CallClientFunction("InspectorFrontendAPI.indexingWorked", &request_id_value, |
| 1253 &file_system_path_value, &worked_value); | 1253 &file_system_path_value, &worked_value); |
| 1254 } | 1254 } |
| 1255 | 1255 |
| 1256 void DevToolsWindow::IndexingDone(int request_id, | 1256 void DevToolsWindow::IndexingDone(int request_id, |
| 1257 const std::string& file_system_path) { | 1257 const std::string& file_system_path) { |
| 1258 indexing_jobs_.erase(request_id); | 1258 indexing_jobs_.erase(request_id); |
| 1259 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 1259 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 1260 base::FundamentalValue request_id_value(request_id); | 1260 base::FundamentalValue request_id_value(request_id); |
| 1261 StringValue file_system_path_value(file_system_path); | 1261 base::StringValue file_system_path_value(file_system_path); |
| 1262 CallClientFunction("InspectorFrontendAPI.indexingDone", &request_id_value, | 1262 CallClientFunction("InspectorFrontendAPI.indexingDone", &request_id_value, |
| 1263 &file_system_path_value, NULL); | 1263 &file_system_path_value, NULL); |
| 1264 } | 1264 } |
| 1265 | 1265 |
| 1266 void DevToolsWindow::SearchCompleted( | 1266 void DevToolsWindow::SearchCompleted( |
| 1267 int request_id, | 1267 int request_id, |
| 1268 const std::string& file_system_path, | 1268 const std::string& file_system_path, |
| 1269 const std::vector<std::string>& file_paths) { | 1269 const std::vector<std::string>& file_paths) { |
| 1270 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 1270 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 1271 ListValue file_paths_value; | 1271 base::ListValue file_paths_value; |
| 1272 for (std::vector<std::string>::const_iterator it(file_paths.begin()); | 1272 for (std::vector<std::string>::const_iterator it(file_paths.begin()); |
| 1273 it != file_paths.end(); ++it) { | 1273 it != file_paths.end(); ++it) { |
| 1274 file_paths_value.AppendString(*it); | 1274 file_paths_value.AppendString(*it); |
| 1275 } | 1275 } |
| 1276 base::FundamentalValue request_id_value(request_id); | 1276 base::FundamentalValue request_id_value(request_id); |
| 1277 StringValue file_system_path_value(file_system_path); | 1277 base::StringValue file_system_path_value(file_system_path); |
| 1278 CallClientFunction("InspectorFrontendAPI.searchCompleted", &request_id_value, | 1278 CallClientFunction("InspectorFrontendAPI.searchCompleted", &request_id_value, |
| 1279 &file_system_path_value, &file_paths_value); | 1279 &file_system_path_value, &file_paths_value); |
| 1280 } | 1280 } |
| 1281 | 1281 |
| 1282 void DevToolsWindow::ShowDevToolsConfirmInfoBar( | 1282 void DevToolsWindow::ShowDevToolsConfirmInfoBar( |
| 1283 const base::string16& message, | 1283 const base::string16& message, |
| 1284 const InfoBarCallback& callback) { | 1284 const InfoBarCallback& callback) { |
| 1285 DevToolsConfirmInfoBarDelegate::Create( | 1285 DevToolsConfirmInfoBarDelegate::Create( |
| 1286 IsDocked() ? | 1286 IsDocked() ? |
| 1287 InfoBarService::FromWebContents(GetInspectedWebContents()) : | 1287 InfoBarService::FromWebContents(GetInspectedWebContents()) : |
| 1288 InfoBarService::FromWebContents(web_contents_), | 1288 InfoBarService::FromWebContents(web_contents_), |
| 1289 callback, message); | 1289 callback, message); |
| 1290 } | 1290 } |
| 1291 | 1291 |
| 1292 void DevToolsWindow::CreateDevToolsBrowser() { | 1292 void DevToolsWindow::CreateDevToolsBrowser() { |
| 1293 std::string wp_key = GetDevToolsWindowPlacementPrefKey(); | 1293 std::string wp_key = GetDevToolsWindowPlacementPrefKey(); |
| 1294 PrefService* prefs = profile_->GetPrefs(); | 1294 PrefService* prefs = profile_->GetPrefs(); |
| 1295 const DictionaryValue* wp_pref = prefs->GetDictionary(wp_key.c_str()); | 1295 const base::DictionaryValue* wp_pref = prefs->GetDictionary(wp_key.c_str()); |
| 1296 if (!wp_pref || wp_pref->empty()) { | 1296 if (!wp_pref || wp_pref->empty()) { |
| 1297 DictionaryPrefUpdate update(prefs, wp_key.c_str()); | 1297 DictionaryPrefUpdate update(prefs, wp_key.c_str()); |
| 1298 DictionaryValue* defaults = update.Get(); | 1298 base::DictionaryValue* defaults = update.Get(); |
| 1299 defaults->SetInteger("left", 100); | 1299 defaults->SetInteger("left", 100); |
| 1300 defaults->SetInteger("top", 100); | 1300 defaults->SetInteger("top", 100); |
| 1301 defaults->SetInteger("right", 740); | 1301 defaults->SetInteger("right", 740); |
| 1302 defaults->SetInteger("bottom", 740); | 1302 defaults->SetInteger("bottom", 740); |
| 1303 defaults->SetBoolean("maximized", false); | 1303 defaults->SetBoolean("maximized", false); |
| 1304 defaults->SetBoolean("always_on_top", false); | 1304 defaults->SetBoolean("always_on_top", false); |
| 1305 } | 1305 } |
| 1306 | 1306 |
| 1307 browser_ = new Browser(Browser::CreateParams::CreateForDevTools( | 1307 browser_ = new Browser(Browser::CreateParams::CreateForDevTools( |
| 1308 profile_, | 1308 profile_, |
| (...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1426 } | 1426 } |
| 1427 | 1427 |
| 1428 Profile* profile = | 1428 Profile* profile = |
| 1429 Profile::FromBrowserContext(web_contents_->GetBrowserContext()); | 1429 Profile::FromBrowserContext(web_contents_->GetBrowserContext()); |
| 1430 const ExtensionService* extension_service = extensions::ExtensionSystem::Get( | 1430 const ExtensionService* extension_service = extensions::ExtensionSystem::Get( |
| 1431 profile->GetOriginalProfile())->extension_service(); | 1431 profile->GetOriginalProfile())->extension_service(); |
| 1432 if (!extension_service) | 1432 if (!extension_service) |
| 1433 return; | 1433 return; |
| 1434 const extensions::ExtensionSet* extensions = extension_service->extensions(); | 1434 const extensions::ExtensionSet* extensions = extension_service->extensions(); |
| 1435 | 1435 |
| 1436 ListValue results; | 1436 base::ListValue results; |
| 1437 for (extensions::ExtensionSet::const_iterator extension(extensions->begin()); | 1437 for (extensions::ExtensionSet::const_iterator extension(extensions->begin()); |
| 1438 extension != extensions->end(); ++extension) { | 1438 extension != extensions->end(); ++extension) { |
| 1439 if (extensions::ManifestURL::GetDevToolsPage(extension->get()).is_empty()) | 1439 if (extensions::ManifestURL::GetDevToolsPage(extension->get()).is_empty()) |
| 1440 continue; | 1440 continue; |
| 1441 DictionaryValue* extension_info = new DictionaryValue(); | 1441 base::DictionaryValue* extension_info = new base::DictionaryValue(); |
| 1442 extension_info->Set( | 1442 extension_info->Set( |
| 1443 "startPage", | 1443 "startPage", |
| 1444 new StringValue( | 1444 new base::StringValue( |
| 1445 extensions::ManifestURL::GetDevToolsPage(extension->get()).spec())); | 1445 extensions::ManifestURL::GetDevToolsPage(extension->get()).spec())); |
| 1446 extension_info->Set("name", new StringValue((*extension)->name())); | 1446 extension_info->Set("name", new base::StringValue((*extension)->name())); |
| 1447 extension_info->Set( | 1447 extension_info->Set( |
| 1448 "exposeExperimentalAPIs", | 1448 "exposeExperimentalAPIs", |
| 1449 new base::FundamentalValue((*extension)->HasAPIPermission( | 1449 new base::FundamentalValue((*extension)->HasAPIPermission( |
| 1450 extensions::APIPermission::kExperimental))); | 1450 extensions::APIPermission::kExperimental))); |
| 1451 results.Append(extension_info); | 1451 results.Append(extension_info); |
| 1452 } | 1452 } |
| 1453 CallClientFunction("WebInspector.addExtensions", &results, NULL, NULL); | 1453 CallClientFunction("WebInspector.addExtensions", &results, NULL, NULL); |
| 1454 } | 1454 } |
| 1455 | 1455 |
| 1456 void DevToolsWindow::CallClientFunction(const std::string& function_name, | 1456 void DevToolsWindow::CallClientFunction(const std::string& function_name, |
| 1457 const Value* arg1, | 1457 const base::Value* arg1, |
| 1458 const Value* arg2, | 1458 const base::Value* arg2, |
| 1459 const Value* arg3) { | 1459 const base::Value* arg3) { |
| 1460 std::string params; | 1460 std::string params; |
| 1461 if (arg1) { | 1461 if (arg1) { |
| 1462 std::string json; | 1462 std::string json; |
| 1463 base::JSONWriter::Write(arg1, &json); | 1463 base::JSONWriter::Write(arg1, &json); |
| 1464 params.append(json); | 1464 params.append(json); |
| 1465 if (arg2) { | 1465 if (arg2) { |
| 1466 base::JSONWriter::Write(arg2, &json); | 1466 base::JSONWriter::Write(arg2, &json); |
| 1467 params.append(", " + json); | 1467 params.append(", " + json); |
| 1468 if (arg3) { | 1468 if (arg3) { |
| 1469 base::JSONWriter::Write(arg3, &json); | 1469 base::JSONWriter::Write(arg3, &json); |
| (...skipping 25 matching lines...) Expand all Loading... |
| 1495 return inspected_contents_observer_ ? | 1495 return inspected_contents_observer_ ? |
| 1496 inspected_contents_observer_->web_contents() : NULL; | 1496 inspected_contents_observer_->web_contents() : NULL; |
| 1497 } | 1497 } |
| 1498 | 1498 |
| 1499 void DevToolsWindow::DocumentOnLoadCompletedInMainFrame() { | 1499 void DevToolsWindow::DocumentOnLoadCompletedInMainFrame() { |
| 1500 is_loaded_ = true; | 1500 is_loaded_ = true; |
| 1501 UpdateTheme(); | 1501 UpdateTheme(); |
| 1502 DoAction(); | 1502 DoAction(); |
| 1503 AddDevToolsExtensionsToClient(); | 1503 AddDevToolsExtensionsToClient(); |
| 1504 } | 1504 } |
| OLD | NEW |