| Index: content/browser/devtools/devtools_target_descriptor_impl.cc
|
| diff --git a/content/browser/devtools/devtools_target_descriptor_impl.cc b/content/browser/devtools/devtools_target_descriptor_impl.cc
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..fa022f707445495a98a79b40a21c23781d5216b8
|
| --- /dev/null
|
| +++ b/content/browser/devtools/devtools_target_descriptor_impl.cc
|
| @@ -0,0 +1,134 @@
|
| +// Copyright (c) 2013 The Chromium Authors. All rights reserved.
|
| +// Use of this source code is governed by a BSD-style license that can be
|
| +// found in the LICENSE file.
|
| +
|
| +#include "content/public/browser/devtools_target_descriptor.h"
|
| +
|
| +#include "base/strings/stringprintf.h"
|
| +#include "base/strings/utf_string_conversions.h"
|
| +#include "base/values.h"
|
| +#include "content/public/browser/devtools_agent_host.h"
|
| +#include "content/public/browser/favicon_status.h"
|
| +#include "content/public/browser/navigation_entry.h"
|
| +#include "content/public/browser/web_contents.h"
|
| +#include "net/base/escape.h"
|
| +
|
| +namespace content {
|
| +
|
| +namespace {
|
| +
|
| +const char kTargetIdField[] = "id";
|
| +const char kTargetTypeField[] = "type";
|
| +const char kTargetTitleField[] = "title";
|
| +const char kTargetDescriptionField[] = "description";
|
| +const char kTargetUrlField[] = "url";
|
| +const char kTargetThumbnailUrlField[] = "thumbnailUrl";
|
| +const char kTargetFaviconUrlField[] = "faviconUrl";
|
| +const char kTargetLastActivityTimeField[] = "lastActivityTime";
|
| +
|
| +const char kTargetTypePage[] = "page";
|
| +const char kTargetTypeOther[] = "other";
|
| +
|
| +class DevToolsTargetDescriptorImpl : public content::DevToolsTargetDescriptor {
|
| + public:
|
| + explicit DevToolsTargetDescriptorImpl(content::WebContents* web_contents);
|
| +
|
| + explicit DevToolsTargetDescriptorImpl(
|
| + const WorkerService::WorkerInfo& worker);
|
| +
|
| + virtual std::string GetId() const OVERRIDE { return id_; }
|
| +
|
| + virtual std::string GetType() const OVERRIDE { return type_; }
|
| +
|
| + virtual std::string GetTitle() const OVERRIDE { return title_; };
|
| +
|
| + virtual std::string GetDescription() const OVERRIDE { return description_; }
|
| +
|
| + virtual std::string GetUrl() const OVERRIDE { return url_; }
|
| +
|
| + virtual std::string GetFaviconUrl() const OVERRIDE { return favicon_url_; }
|
| +
|
| + virtual base::TimeTicks GetLastActivityTime() const OVERRIDE {
|
| + return last_activity_time_;
|
| + }
|
| +
|
| + virtual base::DictionaryValue* Serialize() const OVERRIDE;
|
| +
|
| + virtual void OverrideType(const std::string& type) OVERRIDE {
|
| + type_ = type;
|
| + }
|
| +
|
| + virtual void OverrideDescription(const std::string& description) OVERRIDE {
|
| + description_ = description;
|
| + }
|
| +
|
| + private:
|
| + std::string id_;
|
| + std::string type_;
|
| + std::string title_;
|
| + std::string description_;
|
| + std::string url_;
|
| + std::string favicon_url_;
|
| + base::TimeTicks last_activity_time_;
|
| +};
|
| +
|
| +DevToolsTargetDescriptorImpl::DevToolsTargetDescriptorImpl(
|
| + WebContents* web_contents) {
|
| + scoped_refptr<DevToolsAgentHost> agent(DevToolsAgentHost::GetOrCreateFor(
|
| + web_contents->GetRenderViewHost()));
|
| + id_ = agent->GetId();
|
| + type_ = kTargetTypePage;
|
| + title_ = UTF16ToUTF8(net::EscapeForHTML(web_contents->GetTitle()));
|
| + url_ = web_contents->GetURL().spec();
|
| +
|
| + NavigationController& controller = web_contents->GetController();
|
| + NavigationEntry* entry = controller.GetActiveEntry();
|
| + if (entry != NULL && entry->GetURL().is_valid())
|
| + favicon_url_ = entry->GetFavicon().url.spec();
|
| +
|
| + last_activity_time_ = web_contents->GetLastSelectedTime();
|
| +}
|
| +
|
| +DevToolsTargetDescriptorImpl::DevToolsTargetDescriptorImpl(
|
| + const WorkerService::WorkerInfo& worker) {
|
| + scoped_refptr<DevToolsAgentHost> agent(DevToolsAgentHost::GetForWorker(
|
| + worker.process_id, worker.route_id));
|
| + id_ = agent->GetId();
|
| + type_ = kTargetTypeOther;
|
| + title_ = UTF16ToUTF8(net::EscapeForHTML(worker.name));
|
| + url_ = worker.url.spec();
|
| + description_ =
|
| + base::StringPrintf("Worker pid:%d", base::GetProcId(worker.handle));
|
| +}
|
| +
|
| +base::DictionaryValue* DevToolsTargetDescriptorImpl::Serialize() const {
|
| + base::DictionaryValue* dict = new base::DictionaryValue;
|
| +
|
| + dict->SetString(kTargetIdField, id_);
|
| + dict->SetString(kTargetTypeField, type_);
|
| + dict->SetString(kTargetTitleField, title_);
|
| + dict->SetString(kTargetDescriptionField, description_);
|
| + dict->SetString(kTargetUrlField, url_);
|
| + dict->SetString(kTargetFaviconUrlField, favicon_url_);
|
| + dict->SetDouble(kTargetLastActivityTimeField,
|
| + last_activity_time_.ToInternalValue());
|
| +
|
| + return dict;
|
| +}
|
| +
|
| +}
|
| +
|
| +// static
|
| +DevToolsTargetDescriptor*
|
| +DevToolsTargetDescriptor::FromWebContents(WebContents* web_contents) {
|
| + return new DevToolsTargetDescriptorImpl(web_contents);
|
| +}
|
| +
|
| +// static
|
| +DevToolsTargetDescriptor*
|
| +DevToolsTargetDescriptor::FromWorkerInfo(
|
| + const WorkerService::WorkerInfo& worker) {
|
| + return new DevToolsTargetDescriptorImpl(worker);
|
| +}
|
| +
|
| +} // namespace content
|
|
|