Index: chrome/browser/devtools/devtools_ui_bindings.cc |
diff --git a/chrome/browser/devtools/devtools_ui_bindings.cc b/chrome/browser/devtools/devtools_ui_bindings.cc |
index 982842db17ca0f9d74691d4c97b0eef1240385c2..e646078d2614be0ed2f512d16e9c8f54f12a222a 100644 |
--- a/chrome/browser/devtools/devtools_ui_bindings.cc |
+++ b/chrome/browser/devtools/devtools_ui_bindings.cc |
@@ -47,6 +47,7 @@ |
#include "content/public/common/url_constants.h" |
#include "extensions/browser/extension_registry.h" |
#include "extensions/common/permissions/permissions_data.h" |
+#include "net/base/net_errors.h" |
#include "ui/base/l10n/l10n_util.h" |
#include "ui/base/page_transition_types.h" |
@@ -103,7 +104,7 @@ Browser* FindBrowser(content::WebContents* web_contents) { |
if (tab_index != TabStripModel::kNoTab) |
return *it; |
} |
- return NULL; |
+ return nullptr; |
} |
// DevToolsConfirmInfoBarDelegate --------------------------------------------- |
@@ -112,7 +113,7 @@ typedef base::Callback<void(bool)> InfoBarCallback; |
class DevToolsConfirmInfoBarDelegate : public ConfirmInfoBarDelegate { |
public: |
- // If |infobar_service| is NULL, runs |callback| with a single argument with |
+ // If |infobar_service| is null, runs |callback| with a single argument with |
// value "false". Otherwise, creates a dev tools confirm infobar and delegate |
// and adds the infobar to |infobar_service|. |
static void Create(InfoBarService* infobar_service, |
@@ -312,15 +313,14 @@ void DevToolsUIBindings::FrontendWebContentsObserver:: |
DevToolsUIBindings* DevToolsUIBindings::ForWebContents( |
content::WebContents* web_contents) { |
- if (g_instances == NULL) |
- return NULL; |
+ if (g_instances == nullptr) |
+ return nullptr; |
DevToolsUIBindingsList* instances = g_instances.Pointer(); |
- for (DevToolsUIBindingsList::iterator it(instances->begin()); |
- it != instances->end(); ++it) { |
- if ((*it)->web_contents() == web_contents) |
- return *it; |
+ for (DevToolsUIBindings* bindings : *instances) { |
+ if (bindings->web_contents() == web_contents) |
+ return bindings; |
} |
- return NULL; |
+ return nullptr; |
} |
// static |
@@ -376,7 +376,7 @@ DevToolsUIBindings::DevToolsUIBindings(content::WebContents* web_contents) |
ThemeServiceFactory::GetForProfile(profile_))); |
embedder_message_dispatcher_.reset( |
- DevToolsEmbedderMessageDispatcher::createForDevToolsFrontend(this)); |
+ DevToolsEmbedderMessageDispatcher::CreateForDevToolsFrontend(this)); |
frontend_host_.reset(content::DevToolsFrontendHost::Create( |
web_contents_->GetMainFrame(), this)); |
@@ -386,13 +386,12 @@ DevToolsUIBindings::~DevToolsUIBindings() { |
if (agent_host_.get()) |
agent_host_->DetachClient(); |
- for (IndexingJobsMap::const_iterator jobs_it(indexing_jobs_.begin()); |
- jobs_it != indexing_jobs_.end(); ++jobs_it) { |
- jobs_it->second->Stop(); |
+ for (const auto& job : indexing_jobs_) { |
+ job.second->Stop(); |
} |
indexing_jobs_.clear(); |
- SetDeviceCountUpdatesEnabled(false); |
- SetDevicesUpdatesEnabled(false); |
+ SetDeviceCountUpdatesEnabled(0, false); |
+ SetDevicesUpdatesEnabled(0, false); |
// Remove self from global list. |
DevToolsUIBindingsList* instances = g_instances.Pointer(); |
@@ -417,7 +416,7 @@ void DevToolsUIBindings::HandleMessageFromDevToolsFrontend( |
base::ListValue empty_params; |
base::ListValue* params = &empty_params; |
- base::DictionaryValue* dict = NULL; |
+ base::DictionaryValue* dict = nullptr; |
scoped_ptr<base::Value> parsed_message(base::JSONReader::Read(message)); |
if (!parsed_message || |
!parsed_message->GetAsDictionary(&dict) || |
@@ -427,18 +426,9 @@ void DevToolsUIBindings::HandleMessageFromDevToolsFrontend( |
LOG(ERROR) << "Invalid message was sent to embedder: " << message; |
return; |
} |
- |
int id = 0; |
dict->GetInteger(kFrontendHostId, &id); |
- |
- std::string error; |
- embedder_message_dispatcher_->Dispatch(method, params, &error); |
- if (id) { |
- base::FundamentalValue id_value(id); |
- base::StringValue error_value(error); |
- CallClientFunction("DevToolsAPI.embedderMessageAck", |
- &id_value, &error_value, NULL); |
- } |
+ embedder_message_dispatcher_->Dispatch(id, method, params); |
} |
void DevToolsUIBindings::HandleMessageFromDevToolsFrontendToBackend( |
@@ -463,7 +453,7 @@ void DevToolsUIBindings::DispatchProtocolMessage( |
for (size_t pos = 0; pos < message.length(); pos += kMaxMessageChunkSize) { |
base::StringValue message_value(message.substr(pos, kMaxMessageChunkSize)); |
CallClientFunction("DevToolsAPI.dispatchMessageChunk", |
- &message_value, pos ? NULL : &total_size, NULL); |
+ &message_value, pos ? nullptr : &total_size, nullptr); |
} |
} |
@@ -471,36 +461,41 @@ void DevToolsUIBindings::AgentHostClosed( |
content::DevToolsAgentHost* agent_host, |
bool replaced_with_another_client) { |
DCHECK(agent_host == agent_host_.get()); |
- agent_host_ = NULL; |
+ agent_host_ = nullptr; |
delegate_->InspectedContentsClosing(); |
} |
// DevToolsEmbedderMessageDispatcher::Delegate implementation ----------------- |
-void DevToolsUIBindings::ActivateWindow() { |
+void DevToolsUIBindings::ActivateWindow(int request_id) { |
delegate_->ActivateWindow(); |
} |
-void DevToolsUIBindings::CloseWindow() { |
+void DevToolsUIBindings::CloseWindow(int request_id) { |
delegate_->CloseWindow(); |
} |
-void DevToolsUIBindings::LoadCompleted() { |
+void DevToolsUIBindings::LoadCompleted(int request_id) { |
FrontendLoaded(); |
} |
-void DevToolsUIBindings::SetInspectedPageBounds(const gfx::Rect& rect) { |
+void DevToolsUIBindings::SetInspectedPageBounds(int request_id, |
+ const gfx::Rect& rect) { |
delegate_->SetInspectedPageBounds(rect); |
} |
-void DevToolsUIBindings::SetIsDocked(bool dock_requested) { |
+void DevToolsUIBindings::SetIsDocked(int request_id, bool dock_requested) { |
delegate_->SetIsDocked(dock_requested); |
+ base::FundamentalValue id_value(request_id); |
+ CallClientFunction("DevToolsAPI.embedderMessageAck", |
dgozman
2015/02/12 10:20:36
You should make a separate function for this, e.g.
vkuzkokov
2015/02/27 14:00:05
Done.
|
+ &id_value, nullptr, nullptr); |
} |
-void DevToolsUIBindings::InspectElementCompleted() { |
+void DevToolsUIBindings::InspectElementCompleted(int request_id) { |
delegate_->InspectElementCompleted(); |
} |
-void DevToolsUIBindings::InspectedURLChanged(const std::string& url) { |
+void DevToolsUIBindings::InspectedURLChanged(int request_id, |
+ const std::string& url) { |
content::NavigationController& controller = web_contents()->GetController(); |
content::NavigationEntry* entry = controller.GetActiveEntry(); |
// DevTools UI is not localized. |
@@ -509,11 +504,12 @@ void DevToolsUIBindings::InspectedURLChanged(const std::string& url) { |
web_contents()->NotifyNavigationStateChanged(content::INVALIDATE_TYPE_TITLE); |
} |
-void DevToolsUIBindings::OpenInNewTab(const std::string& url) { |
+void DevToolsUIBindings::OpenInNewTab(int request_id, const std::string& url) { |
delegate_->OpenInNewTab(url); |
} |
-void DevToolsUIBindings::SaveToFile(const std::string& url, |
+void DevToolsUIBindings::SaveToFile(int request_id, |
+ const std::string& url, |
const std::string& content, |
bool save_as) { |
file_helper_->Save(url, content, save_as, |
@@ -523,20 +519,21 @@ void DevToolsUIBindings::SaveToFile(const std::string& url, |
weak_factory_.GetWeakPtr(), url)); |
} |
-void DevToolsUIBindings::AppendToFile(const std::string& url, |
+void DevToolsUIBindings::AppendToFile(int request_id, |
+ const std::string& url, |
const std::string& content) { |
file_helper_->Append(url, content, |
base::Bind(&DevToolsUIBindings::AppendedTo, |
weak_factory_.GetWeakPtr(), url)); |
} |
-void DevToolsUIBindings::RequestFileSystems() { |
+void DevToolsUIBindings::RequestFileSystems(int request_id) { |
CHECK(web_contents_->GetURL().SchemeIs(content::kChromeDevToolsScheme)); |
file_helper_->RequestFileSystems(base::Bind( |
&DevToolsUIBindings::FileSystemsLoaded, weak_factory_.GetWeakPtr())); |
} |
-void DevToolsUIBindings::AddFileSystem() { |
+void DevToolsUIBindings::AddFileSystem(int request_id) { |
CHECK(web_contents_->GetURL().SchemeIs(content::kChromeDevToolsScheme)); |
file_helper_->AddFileSystem( |
base::Bind(&DevToolsUIBindings::FileSystemAdded, |
@@ -545,16 +542,17 @@ void DevToolsUIBindings::AddFileSystem() { |
weak_factory_.GetWeakPtr())); |
} |
-void DevToolsUIBindings::RemoveFileSystem( |
- const std::string& file_system_path) { |
+void DevToolsUIBindings::RemoveFileSystem(int request_id, |
+ const std::string& file_system_path) { |
CHECK(web_contents_->GetURL().SchemeIs(content::kChromeDevToolsScheme)); |
file_helper_->RemoveFileSystem(file_system_path); |
base::StringValue file_system_path_value(file_system_path); |
CallClientFunction("DevToolsAPI.fileSystemRemoved", |
- &file_system_path_value, NULL, NULL); |
+ &file_system_path_value, nullptr, nullptr); |
} |
void DevToolsUIBindings::UpgradeDraggedFileSystemPermissions( |
+ int request_id, |
const std::string& file_system_url) { |
CHECK(web_contents_->GetURL().SchemeIs(content::kChromeDevToolsScheme)); |
file_helper_->UpgradeDraggedFileSystemPermissions( |
@@ -566,34 +564,35 @@ void DevToolsUIBindings::UpgradeDraggedFileSystemPermissions( |
} |
void DevToolsUIBindings::IndexPath(int request_id, |
+ int index_request_id, |
const std::string& file_system_path) { |
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
CHECK(web_contents_->GetURL().SchemeIs(content::kChromeDevToolsScheme)); |
if (!file_helper_->IsFileSystemAdded(file_system_path)) { |
- IndexingDone(request_id, file_system_path); |
+ IndexingDone(index_request_id, file_system_path); |
return; |
} |
- indexing_jobs_[request_id] = |
+ indexing_jobs_[index_request_id] = |
scoped_refptr<DevToolsFileSystemIndexer::FileSystemIndexingJob>( |
file_system_indexer_->IndexPath( |
file_system_path, |
Bind(&DevToolsUIBindings::IndexingTotalWorkCalculated, |
weak_factory_.GetWeakPtr(), |
- request_id, |
+ index_request_id, |
file_system_path), |
Bind(&DevToolsUIBindings::IndexingWorked, |
weak_factory_.GetWeakPtr(), |
- request_id, |
+ index_request_id, |
file_system_path), |
Bind(&DevToolsUIBindings::IndexingDone, |
weak_factory_.GetWeakPtr(), |
- request_id, |
+ index_request_id, |
file_system_path))); |
} |
-void DevToolsUIBindings::StopIndexing(int request_id) { |
+void DevToolsUIBindings::StopIndexing(int request_id, int index_request_id) { |
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
- IndexingJobsMap::iterator it = indexing_jobs_.find(request_id); |
+ IndexingJobsMap::iterator it = indexing_jobs_.find(index_request_id); |
if (it == indexing_jobs_.end()) |
return; |
it->second->Stop(); |
@@ -601,36 +600,39 @@ void DevToolsUIBindings::StopIndexing(int request_id) { |
} |
void DevToolsUIBindings::SearchInPath(int request_id, |
+ int search_request_id, |
const std::string& file_system_path, |
const std::string& query) { |
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
CHECK(web_contents_->GetURL().SchemeIs(content::kChromeDevToolsScheme)); |
if (!file_helper_->IsFileSystemAdded(file_system_path)) { |
- SearchCompleted(request_id, file_system_path, std::vector<std::string>()); |
+ SearchCompleted(search_request_id, |
+ file_system_path, |
+ std::vector<std::string>()); |
return; |
} |
file_system_indexer_->SearchInPath(file_system_path, |
query, |
Bind(&DevToolsUIBindings::SearchCompleted, |
weak_factory_.GetWeakPtr(), |
- request_id, |
+ search_request_id, |
file_system_path)); |
} |
-void DevToolsUIBindings::SetWhitelistedShortcuts( |
- const std::string& message) { |
+void DevToolsUIBindings::SetWhitelistedShortcuts(int request_id, |
+ const std::string& message) { |
delegate_->SetWhitelistedShortcuts(message); |
} |
-void DevToolsUIBindings::ZoomIn() { |
+void DevToolsUIBindings::ZoomIn(int request_id) { |
ui_zoom::PageZoom::Zoom(web_contents(), content::PAGE_ZOOM_IN); |
} |
-void DevToolsUIBindings::ZoomOut() { |
+void DevToolsUIBindings::ZoomOut(int request_id) { |
ui_zoom::PageZoom::Zoom(web_contents(), content::PAGE_ZOOM_OUT); |
} |
-void DevToolsUIBindings::ResetZoom() { |
+void DevToolsUIBindings::ResetZoom(int request_id) { |
ui_zoom::PageZoom::Zoom(web_contents(), content::PAGE_ZOOM_RESET); |
} |
@@ -640,6 +642,7 @@ static void InspectTarget(Profile* profile, DevToolsTargetImpl* target) { |
} |
void DevToolsUIBindings::OpenUrlOnRemoteDeviceAndInspect( |
+ int request_id, |
const std::string& browser_id, |
const std::string& url) { |
if (remote_targets_handler_) { |
@@ -648,7 +651,8 @@ void DevToolsUIBindings::OpenUrlOnRemoteDeviceAndInspect( |
} |
} |
-void DevToolsUIBindings::SetDeviceCountUpdatesEnabled(bool enabled) { |
+void DevToolsUIBindings::SetDeviceCountUpdatesEnabled(int request_id, |
+ bool enabled) { |
if (device_count_updates_enabled_ == enabled) |
return; |
DevToolsAndroidBridge* adb_bridge = |
@@ -663,7 +667,8 @@ void DevToolsUIBindings::SetDeviceCountUpdatesEnabled(bool enabled) { |
adb_bridge->RemoveDeviceCountListener(this); |
} |
-void DevToolsUIBindings::SetDevicesUpdatesEnabled(bool enabled) { |
+void DevToolsUIBindings::SetDevicesUpdatesEnabled(int request_id, |
+ bool enabled) { |
if (devices_updates_enabled_ == enabled) |
return; |
devices_updates_enabled_ = enabled; |
@@ -677,55 +682,80 @@ void DevToolsUIBindings::SetDevicesUpdatesEnabled(bool enabled) { |
} |
} |
-void DevToolsUIBindings::SendMessageToBrowser(const std::string& message) { |
+void DevToolsUIBindings::SendMessageToBrowser(int request_id, |
+ const std::string& message) { |
if (agent_host_.get()) |
agent_host_->DispatchProtocolMessage(message); |
} |
-void DevToolsUIBindings::RecordActionUMA(const std::string& name, int action) { |
+void DevToolsUIBindings::RecordActionUMA(int request_id, |
+ const std::string& name, |
+ int action) { |
if (name == kDevToolsActionTakenHistogram) |
UMA_HISTOGRAM_ENUMERATION(name, action, kDevToolsActionTakenBoundary); |
else if (name == kDevToolsPanelShownHistogram) |
UMA_HISTOGRAM_ENUMERATION(name, action, kDevToolsPanelShownBoundary); |
} |
+void DevToolsUIBindings::SendJsonRequest(int request_id, |
+ const std::string& browser_id, |
+ const std::string& url) { |
+ remote_targets_handler_->SendJsonRequest(browser_id, url, |
+ base::Bind(&DevToolsUIBindings::JsonReceived, |
+ weak_factory_.GetWeakPtr(), |
+ request_id)); |
+} |
+ |
+void DevToolsUIBindings::JsonReceived(int request_id, |
+ int result, |
+ const std::string& message) { |
+ base::FundamentalValue request_id_value(request_id); |
+ if (result != net::OK) { |
+ CallClientFunction("DevToolsAPI.embedderMessageAck", |
+ &request_id_value, nullptr, nullptr); |
+ return; |
+ } |
+ base::StringValue message_value(message); |
+ CallClientFunction("DevToolsAPI.embedderMessageAck", |
+ &request_id_value, &message_value, nullptr); |
+} |
+ |
void DevToolsUIBindings::DeviceCountChanged(int count) { |
base::FundamentalValue value(count); |
- CallClientFunction("DevToolsAPI.deviceCountUpdated", &value, NULL, |
- NULL); |
+ CallClientFunction("DevToolsAPI.deviceCountUpdated", |
+ &value, nullptr, nullptr); |
} |
void DevToolsUIBindings::DevicesUpdated( |
const std::string& source, |
const base::ListValue& targets) { |
- CallClientFunction("DevToolsAPI.devicesUpdated", &targets, NULL, |
- NULL); |
+ CallClientFunction("DevToolsAPI.devicesUpdated", &targets, nullptr, nullptr); |
} |
void DevToolsUIBindings::FileSavedAs(const std::string& url) { |
base::StringValue url_value(url); |
- CallClientFunction("DevToolsAPI.savedURL", &url_value, NULL, NULL); |
+ CallClientFunction("DevToolsAPI.savedURL", &url_value, nullptr, nullptr); |
} |
void DevToolsUIBindings::CanceledFileSaveAs(const std::string& url) { |
base::StringValue url_value(url); |
CallClientFunction("DevToolsAPI.canceledSaveURL", |
- &url_value, NULL, NULL); |
+ &url_value, nullptr, nullptr); |
} |
void DevToolsUIBindings::AppendedTo(const std::string& url) { |
base::StringValue url_value(url); |
- CallClientFunction("DevToolsAPI.appendedToURL", &url_value, NULL, |
- NULL); |
+ CallClientFunction("DevToolsAPI.appendedToURL", &url_value, nullptr, nullptr); |
} |
void DevToolsUIBindings::FileSystemsLoaded( |
const std::vector<DevToolsFileHelper::FileSystem>& file_systems) { |
base::ListValue file_systems_value; |
- for (size_t i = 0; i < file_systems.size(); ++i) |
- file_systems_value.Append(CreateFileSystemValue(file_systems[i])); |
+ for (const DevToolsFileHelper::FileSystem& file_system : file_systems) { |
+ file_systems_value.Append(CreateFileSystemValue(file_system)); |
+ } |
CallClientFunction("DevToolsAPI.fileSystemsLoaded", |
- &file_systems_value, NULL, NULL); |
+ &file_systems_value, nullptr, nullptr); |
} |
void DevToolsUIBindings::FileSystemAdded( |
@@ -735,8 +765,8 @@ void DevToolsUIBindings::FileSystemAdded( |
scoped_ptr<base::DictionaryValue> file_system_value; |
if (!file_system.file_system_path.empty()) |
file_system_value.reset(CreateFileSystemValue(file_system)); |
- CallClientFunction("DevToolsAPI.fileSystemAdded", |
- error_string_value.get(), file_system_value.get(), NULL); |
+ CallClientFunction("DevToolsAPI.fileSystemAdded", error_string_value.get(), |
+ file_system_value.get(), nullptr); |
} |
void DevToolsUIBindings::IndexingTotalWorkCalculated( |
@@ -770,7 +800,7 @@ void DevToolsUIBindings::IndexingDone(int request_id, |
base::FundamentalValue request_id_value(request_id); |
base::StringValue file_system_path_value(file_system_path); |
CallClientFunction("DevToolsAPI.indexingDone", &request_id_value, |
- &file_system_path_value, NULL); |
+ &file_system_path_value, nullptr); |
} |
void DevToolsUIBindings::SearchCompleted( |
@@ -779,9 +809,8 @@ void DevToolsUIBindings::SearchCompleted( |
const std::vector<std::string>& file_paths) { |
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
base::ListValue file_paths_value; |
- for (std::vector<std::string>::const_iterator it(file_paths.begin()); |
- it != file_paths.end(); ++it) { |
- file_paths_value.AppendString(*it); |
+ for (const std::string& file_path : file_paths) { |
+ file_paths_value.AppendString(file_path); |
} |
base::FundamentalValue request_id_value(request_id); |
base::StringValue file_system_path_value(file_system_path); |
@@ -821,19 +850,16 @@ void DevToolsUIBindings::AddDevToolsExtensionsToClient() { |
.is_empty()) |
continue; |
base::DictionaryValue* extension_info = new base::DictionaryValue(); |
- extension_info->Set( |
- "startPage", |
- new base::StringValue(extensions::chrome_manifest_urls::GetDevToolsPage( |
- extension.get()).spec())); |
- extension_info->Set("name", new base::StringValue(extension->name())); |
- extension_info->Set("exposeExperimentalAPIs", |
- new base::FundamentalValue( |
- extension->permissions_data()->HasAPIPermission( |
- extensions::APIPermission::kExperimental))); |
+ extension_info->SetString("startPage", |
+ extensions::chrome_manifest_urls::GetDevToolsPage( |
+ extension.get()).spec()); |
+ extension_info->SetString("name", extension->name()); |
+ extension_info->SetBoolean("exposeExperimentalAPIs", |
+ extension->permissions_data()->HasAPIPermission( |
+ extensions::APIPermission::kExperimental)); |
results.Append(extension_info); |
} |
- CallClientFunction("DevToolsAPI.addExtensions", |
- &results, NULL, NULL); |
+ CallClientFunction("DevToolsAPI.addExtensions", &results, nullptr, nullptr); |
} |
void DevToolsUIBindings::SetDelegate(Delegate* delegate) { |
@@ -857,7 +883,7 @@ void DevToolsUIBindings::Reattach() { |
void DevToolsUIBindings::Detach() { |
if (agent_host_.get()) |
agent_host_->DetachClient(); |
- agent_host_ = NULL; |
+ agent_host_ = nullptr; |
} |
bool DevToolsUIBindings::IsAttachedTo(content::DevToolsAgentHost* agent_host) { |