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*
d->RegisterHandler("resetZoom", &Delegate::ResetZoom, delegate);
d->RegisterHandler("openUrlOnRemoteDeviceAndInspect",
&Delegate::OpenUrlOnRemoteDeviceAndInspect, delegate);
d->RegisterHandler(
"subscribe", &Delegate::Subscribe, delegate);
d->RegisterHandler(
"unsubscribe", &Delegate::Unsubscribe, delegate);
d->RegisterHandler("setDeviceCountUpdatesEnabled",
&Delegate::SetDeviceCountUpdatesEnabled, delegate);
d->RegisterHandler("setDevicesUpdatesEnabled",
&Delegate::SetDevicesUpdatesEnabled, delegate);
return d;
}
......@@ -62,8 +62,8 @@ class DevToolsEmbedderMessageDispatcher {
virtual void OpenUrlOnRemoteDeviceAndInspect(const std::string& browser_id,
const std::string& url) = 0;
virtual void Subscribe(const std::string& event_type) = 0;
virtual void Unsubscribe(const std::string& event_type) = 0;
virtual void SetDeviceCountUpdatesEnabled(bool enabled) = 0;
virtual void SetDevicesUpdatesEnabled(bool enabled) = 0;
};
virtual ~DevToolsEmbedderMessageDispatcher() {}
......
......@@ -63,9 +63,6 @@ static const char kFrontendHostMethod[] = "method";
static const char kFrontendHostParams[] = "params";
static const char kTitleFormat[] = "Developer Tools - %s";
static const char kDevicesChanged[] = "DevicesChanged";
static const char kDeviceCountChanged[] = "DeviceCountChanged";
std::string SkColorToRGBAString(SkColor color) {
// We avoid StringPrintf because it will use locale specific formatters for
// the double (e.g. ',' instead of '.' in German).
......@@ -307,7 +304,8 @@ DevToolsUIBindings::DevToolsUIBindings(content::WebContents* web_contents,
: profile_(Profile::FromBrowserContext(web_contents->GetBrowserContext())),
web_contents_(web_contents),
delegate_(new DefaultBindingsDelegate(web_contents_)),
device_listener_enabled_(false),
device_count_updates_enabled_(false),
devices_updates_enabled_(false),
url_(url),
weak_factory_(this) {
frontend_contents_observer_.reset(new FrontendWebContentsObserver(this));
......@@ -349,9 +347,8 @@ DevToolsUIBindings::~DevToolsUIBindings() {
jobs_it->second->Stop();
}
indexing_jobs_.clear();
while (!subscribers_.empty())
Unsubscribe(*subscribers_.begin());
SetDeviceCountUpdatesEnabled(false);
SetDevicesUpdatesEnabled(false);
}
void DevToolsUIBindings::InspectedContentsClosing() {
......@@ -571,65 +568,46 @@ void DevToolsUIBindings::OpenUrlOnRemoteDeviceAndInspect(
}
}
void DevToolsUIBindings::Subscribe(const std::string& event_type) {
if (subscribers_.find(event_type) != subscribers_.end()) {
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 << "]";
void DevToolsUIBindings::SetDeviceCountUpdatesEnabled(bool enabled) {
if (device_count_updates_enabled_ == enabled)
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::Factory::GetForProfile(profile_);
if (!adb_bridge)
return;
DCHECK(device_listener_enabled_ != enable);
device_listener_enabled_ = enable;
if (enable)
device_count_updates_enabled_ = enabled;
if (enabled)
adb_bridge->AddDeviceCountListener(this);
else
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) {
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 base::ListValue& targets) {
DispatchEventOnFrontend(kDevicesChanged, targets);
CallClientFunction("InspectorFrontendAPI.devicesUpdated", &targets, NULL,
NULL);
}
void DevToolsUIBindings::FileSavedAs(const std::string& url) {
......@@ -793,18 +771,6 @@ void DevToolsUIBindings::CallClientFunction(const std::string& function_name,
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() {
// Call delegate first - it seeds importants bit of information.
delegate_->OnLoadCompleted();
......
......@@ -116,8 +116,8 @@ class DevToolsUIBindings : public content::NotificationObserver,
virtual void ResetZoom() OVERRIDE;
virtual void OpenUrlOnRemoteDeviceAndInspect(const std::string& browser_id,
const std::string& url) OVERRIDE;
virtual void Subscribe(const std::string& event_type) OVERRIDE;
virtual void Unsubscribe(const std::string& event_type) OVERRIDE;
virtual void SetDeviceCountUpdatesEnabled(bool enabled) OVERRIDE;
virtual void SetDevicesUpdatesEnabled(bool enabled) OVERRIDE;
void EnableRemoteDeviceCounter(bool enable);
......@@ -125,8 +125,8 @@ class DevToolsUIBindings : public content::NotificationObserver,
virtual void DeviceCountChanged(int count) OVERRIDE;
// Forwards discovered devices to frontend.
virtual void PopulateRemoteDevices(const std::string& source,
const base::ListValue& targets);
virtual void DevicesUpdated(const std::string& source,
const base::ListValue& targets);
void DocumentOnLoadCompletedInMainFrame();
......@@ -155,9 +155,6 @@ class DevToolsUIBindings : public content::NotificationObserver,
void UpdateTheme();
void AddDevToolsExtensionsToClient();
void DispatchEventOnFrontend(const std::string& event_type,
const base::Value& event_data);
class FrontendWebContentsObserver;
friend class FrontendWebContentsObserver;
scoped_ptr<FrontendWebContentsObserver> frontend_contents_observer_;
......@@ -165,7 +162,6 @@ class DevToolsUIBindings : public content::NotificationObserver,
Profile* profile_;
content::WebContents* web_contents_;
scoped_ptr<Delegate> delegate_;
bool device_listener_enabled_;
content::NotificationRegistrar registrar_;
scoped_ptr<content::DevToolsClientHost> frontend_host_;
scoped_ptr<DevToolsFileHelper> file_helper_;
......@@ -176,8 +172,8 @@ class DevToolsUIBindings : public content::NotificationObserver,
IndexingJobsMap;
IndexingJobsMap indexing_jobs_;
typedef std::set<std::string> Subscribers;
Subscribers subscribers_;
bool device_count_updates_enabled_;
bool devices_updates_enabled_;
scoped_ptr<DevToolsTargetsUIHandler> remote_targets_handler_;
scoped_ptr<DevToolsEmbedderMessageDispatcher> embedder_message_dispatcher_;
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