Commit a912e290 authored by pfeldman@chromium.org's avatar pfeldman@chromium.org

DevTools: factor out InspectorFrontendHost/API as a separate entity (chrome)

TBR=tsepez (no changes to semantics)

Review URL: https://codereview.chromium.org/375393002

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@282234 0039d316-1c4b-4281-b951-d872f2087c98
parent 941b8911
...@@ -285,9 +285,9 @@ DevToolsEmbedderMessageDispatcher* ...@@ -285,9 +285,9 @@ DevToolsEmbedderMessageDispatcher*
d->RegisterHandler("resetZoom", &Delegate::ResetZoom, delegate); d->RegisterHandler("resetZoom", &Delegate::ResetZoom, delegate);
d->RegisterHandler("openUrlOnRemoteDeviceAndInspect", d->RegisterHandler("openUrlOnRemoteDeviceAndInspect",
&Delegate::OpenUrlOnRemoteDeviceAndInspect, delegate); &Delegate::OpenUrlOnRemoteDeviceAndInspect, delegate);
d->RegisterHandler( d->RegisterHandler("setDeviceCountUpdatesEnabled",
"subscribe", &Delegate::Subscribe, delegate); &Delegate::SetDeviceCountUpdatesEnabled, delegate);
d->RegisterHandler( d->RegisterHandler("setDevicesUpdatesEnabled",
"unsubscribe", &Delegate::Unsubscribe, delegate); &Delegate::SetDevicesUpdatesEnabled, delegate);
return d; return d;
} }
...@@ -62,8 +62,8 @@ class DevToolsEmbedderMessageDispatcher { ...@@ -62,8 +62,8 @@ class DevToolsEmbedderMessageDispatcher {
virtual void OpenUrlOnRemoteDeviceAndInspect(const std::string& browser_id, virtual void OpenUrlOnRemoteDeviceAndInspect(const std::string& browser_id,
const std::string& url) = 0; const std::string& url) = 0;
virtual void Subscribe(const std::string& event_type) = 0; virtual void SetDeviceCountUpdatesEnabled(bool enabled) = 0;
virtual void Unsubscribe(const std::string& event_type) = 0; virtual void SetDevicesUpdatesEnabled(bool enabled) = 0;
}; };
virtual ~DevToolsEmbedderMessageDispatcher() {} virtual ~DevToolsEmbedderMessageDispatcher() {}
......
...@@ -63,9 +63,6 @@ static const char kFrontendHostMethod[] = "method"; ...@@ -63,9 +63,6 @@ static const char kFrontendHostMethod[] = "method";
static const char kFrontendHostParams[] = "params"; static const char kFrontendHostParams[] = "params";
static const char kTitleFormat[] = "Developer Tools - %s"; static const char kTitleFormat[] = "Developer Tools - %s";
static const char kDevicesChanged[] = "DevicesChanged";
static const char kDeviceCountChanged[] = "DeviceCountChanged";
std::string SkColorToRGBAString(SkColor color) { std::string SkColorToRGBAString(SkColor color) {
// We avoid StringPrintf because it will use locale specific formatters for // We avoid StringPrintf because it will use locale specific formatters for
// the double (e.g. ',' instead of '.' in German). // the double (e.g. ',' instead of '.' in German).
...@@ -307,7 +304,8 @@ DevToolsUIBindings::DevToolsUIBindings(content::WebContents* web_contents, ...@@ -307,7 +304,8 @@ DevToolsUIBindings::DevToolsUIBindings(content::WebContents* web_contents,
: profile_(Profile::FromBrowserContext(web_contents->GetBrowserContext())), : profile_(Profile::FromBrowserContext(web_contents->GetBrowserContext())),
web_contents_(web_contents), web_contents_(web_contents),
delegate_(new DefaultBindingsDelegate(web_contents_)), delegate_(new DefaultBindingsDelegate(web_contents_)),
device_listener_enabled_(false), device_count_updates_enabled_(false),
devices_updates_enabled_(false),
url_(url), url_(url),
weak_factory_(this) { weak_factory_(this) {
frontend_contents_observer_.reset(new FrontendWebContentsObserver(this)); frontend_contents_observer_.reset(new FrontendWebContentsObserver(this));
...@@ -349,9 +347,8 @@ DevToolsUIBindings::~DevToolsUIBindings() { ...@@ -349,9 +347,8 @@ DevToolsUIBindings::~DevToolsUIBindings() {
jobs_it->second->Stop(); jobs_it->second->Stop();
} }
indexing_jobs_.clear(); indexing_jobs_.clear();
SetDeviceCountUpdatesEnabled(false);
while (!subscribers_.empty()) SetDevicesUpdatesEnabled(false);
Unsubscribe(*subscribers_.begin());
} }
void DevToolsUIBindings::InspectedContentsClosing() { void DevToolsUIBindings::InspectedContentsClosing() {
...@@ -571,65 +568,46 @@ void DevToolsUIBindings::OpenUrlOnRemoteDeviceAndInspect( ...@@ -571,65 +568,46 @@ void DevToolsUIBindings::OpenUrlOnRemoteDeviceAndInspect(
} }
} }
void DevToolsUIBindings::Subscribe(const std::string& event_type) { void DevToolsUIBindings::SetDeviceCountUpdatesEnabled(bool enabled) {
if (subscribers_.find(event_type) != subscribers_.end()) { if (device_count_updates_enabled_ == enabled)
LOG(ERROR) << "Already subscribed for [" << event_type << "].";
return;
}
subscribers_.insert(event_type);
if (event_type == kDevicesChanged) {
remote_targets_handler_ = DevToolsTargetsUIHandler::CreateForAdb(
base::Bind(&DevToolsUIBindings::PopulateRemoteDevices,
base::Unretained(this)),
profile_);
} else if (event_type == kDeviceCountChanged) {
EnableRemoteDeviceCounter(true);
} else {
LOG(ERROR) << "Attempt to start unknown event listener " << event_type;
}
}
void DevToolsUIBindings::Unsubscribe(const std::string& event_type) {
if (subscribers_.find(event_type) == subscribers_.end()) {
LOG(ERROR) << "Not yet subscribed for [" << event_type << "]";
return; return;
}
if (event_type == kDevicesChanged) {
remote_targets_handler_.reset();
} else if (event_type == kDeviceCountChanged) {
EnableRemoteDeviceCounter(false);
} else {
LOG(ERROR) << "Attempt to stop unknown event listener " << event_type;
}
subscribers_.erase(event_type);
}
void DevToolsUIBindings::EnableRemoteDeviceCounter(bool enable) {
DevToolsAndroidBridge* adb_bridge = DevToolsAndroidBridge* adb_bridge =
DevToolsAndroidBridge::Factory::GetForProfile(profile_); DevToolsAndroidBridge::Factory::GetForProfile(profile_);
if (!adb_bridge) if (!adb_bridge)
return; return;
DCHECK(device_listener_enabled_ != enable); device_count_updates_enabled_ = enabled;
device_listener_enabled_ = enable; if (enabled)
if (enable)
adb_bridge->AddDeviceCountListener(this); adb_bridge->AddDeviceCountListener(this);
else else
adb_bridge->RemoveDeviceCountListener(this); adb_bridge->RemoveDeviceCountListener(this);
} }
void DevToolsUIBindings::SetDevicesUpdatesEnabled(bool enabled) {
if (devices_updates_enabled_ == enabled)
return;
devices_updates_enabled_ = enabled;
if (enabled) {
remote_targets_handler_ = DevToolsTargetsUIHandler::CreateForAdb(
base::Bind(&DevToolsUIBindings::DevicesUpdated,
base::Unretained(this)),
profile_);
} else {
remote_targets_handler_.reset();
}
}
void DevToolsUIBindings::DeviceCountChanged(int count) { void DevToolsUIBindings::DeviceCountChanged(int count) {
DispatchEventOnFrontend(kDeviceCountChanged, base::FundamentalValue(count)); base::FundamentalValue value(count);
CallClientFunction("InspectorFrontendAPI.deviceCountUpdated", &value, NULL,
NULL);
} }
void DevToolsUIBindings::PopulateRemoteDevices( void DevToolsUIBindings::DevicesUpdated(
const std::string& source, const std::string& source,
const base::ListValue& targets) { const base::ListValue& targets) {
DispatchEventOnFrontend(kDevicesChanged, targets); CallClientFunction("InspectorFrontendAPI.devicesUpdated", &targets, NULL,
NULL);
} }
void DevToolsUIBindings::FileSavedAs(const std::string& url) { void DevToolsUIBindings::FileSavedAs(const std::string& url) {
...@@ -793,18 +771,6 @@ void DevToolsUIBindings::CallClientFunction(const std::string& function_name, ...@@ -793,18 +771,6 @@ void DevToolsUIBindings::CallClientFunction(const std::string& function_name,
web_contents_->GetMainFrame()->ExecuteJavaScript(javascript); web_contents_->GetMainFrame()->ExecuteJavaScript(javascript);
} }
void DevToolsUIBindings::DispatchEventOnFrontend(
const std::string& event_type,
const base::Value& event_data) {
if (subscribers_.find(event_type) == subscribers_.end())
return;
base::StringValue event_type_value(event_type);
CallClientFunction("InspectorFrontendAPI.dispatchEventToListeners",
&event_type_value,
&event_data,
NULL);
}
void DevToolsUIBindings::DocumentOnLoadCompletedInMainFrame() { void DevToolsUIBindings::DocumentOnLoadCompletedInMainFrame() {
// Call delegate first - it seeds importants bit of information. // Call delegate first - it seeds importants bit of information.
delegate_->OnLoadCompleted(); delegate_->OnLoadCompleted();
......
...@@ -116,8 +116,8 @@ class DevToolsUIBindings : public content::NotificationObserver, ...@@ -116,8 +116,8 @@ class DevToolsUIBindings : public content::NotificationObserver,
virtual void ResetZoom() OVERRIDE; virtual void ResetZoom() OVERRIDE;
virtual void OpenUrlOnRemoteDeviceAndInspect(const std::string& browser_id, virtual void OpenUrlOnRemoteDeviceAndInspect(const std::string& browser_id,
const std::string& url) OVERRIDE; const std::string& url) OVERRIDE;
virtual void Subscribe(const std::string& event_type) OVERRIDE; virtual void SetDeviceCountUpdatesEnabled(bool enabled) OVERRIDE;
virtual void Unsubscribe(const std::string& event_type) OVERRIDE; virtual void SetDevicesUpdatesEnabled(bool enabled) OVERRIDE;
void EnableRemoteDeviceCounter(bool enable); void EnableRemoteDeviceCounter(bool enable);
...@@ -125,7 +125,7 @@ class DevToolsUIBindings : public content::NotificationObserver, ...@@ -125,7 +125,7 @@ class DevToolsUIBindings : public content::NotificationObserver,
virtual void DeviceCountChanged(int count) OVERRIDE; virtual void DeviceCountChanged(int count) OVERRIDE;
// Forwards discovered devices to frontend. // Forwards discovered devices to frontend.
virtual void PopulateRemoteDevices(const std::string& source, virtual void DevicesUpdated(const std::string& source,
const base::ListValue& targets); const base::ListValue& targets);
void DocumentOnLoadCompletedInMainFrame(); void DocumentOnLoadCompletedInMainFrame();
...@@ -155,9 +155,6 @@ class DevToolsUIBindings : public content::NotificationObserver, ...@@ -155,9 +155,6 @@ class DevToolsUIBindings : public content::NotificationObserver,
void UpdateTheme(); void UpdateTheme();
void AddDevToolsExtensionsToClient(); void AddDevToolsExtensionsToClient();
void DispatchEventOnFrontend(const std::string& event_type,
const base::Value& event_data);
class FrontendWebContentsObserver; class FrontendWebContentsObserver;
friend class FrontendWebContentsObserver; friend class FrontendWebContentsObserver;
scoped_ptr<FrontendWebContentsObserver> frontend_contents_observer_; scoped_ptr<FrontendWebContentsObserver> frontend_contents_observer_;
...@@ -165,7 +162,6 @@ class DevToolsUIBindings : public content::NotificationObserver, ...@@ -165,7 +162,6 @@ class DevToolsUIBindings : public content::NotificationObserver,
Profile* profile_; Profile* profile_;
content::WebContents* web_contents_; content::WebContents* web_contents_;
scoped_ptr<Delegate> delegate_; scoped_ptr<Delegate> delegate_;
bool device_listener_enabled_;
content::NotificationRegistrar registrar_; content::NotificationRegistrar registrar_;
scoped_ptr<content::DevToolsClientHost> frontend_host_; scoped_ptr<content::DevToolsClientHost> frontend_host_;
scoped_ptr<DevToolsFileHelper> file_helper_; scoped_ptr<DevToolsFileHelper> file_helper_;
...@@ -176,8 +172,8 @@ class DevToolsUIBindings : public content::NotificationObserver, ...@@ -176,8 +172,8 @@ class DevToolsUIBindings : public content::NotificationObserver,
IndexingJobsMap; IndexingJobsMap;
IndexingJobsMap indexing_jobs_; IndexingJobsMap indexing_jobs_;
typedef std::set<std::string> Subscribers; bool device_count_updates_enabled_;
Subscribers subscribers_; bool devices_updates_enabled_;
scoped_ptr<DevToolsTargetsUIHandler> remote_targets_handler_; scoped_ptr<DevToolsTargetsUIHandler> remote_targets_handler_;
scoped_ptr<DevToolsEmbedderMessageDispatcher> embedder_message_dispatcher_; scoped_ptr<DevToolsEmbedderMessageDispatcher> embedder_message_dispatcher_;
GURL url_; GURL url_;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment