2013-03-27 14:33:00 +00:00
|
|
|
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
|
|
|
|
// Copyright (c) 2013 Adam Roben <adam@roben.org>. All rights reserved.
|
|
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
|
|
// found in the LICENSE-CHROMIUM file.
|
|
|
|
|
2013-03-14 13:03:50 +00:00
|
|
|
#include "browser/inspectable_web_contents_impl.h"
|
|
|
|
|
2013-03-27 14:33:00 +00:00
|
|
|
#include "browser/browser_client.h"
|
2013-04-08 17:53:53 +00:00
|
|
|
#include "browser/browser_context.h"
|
2013-03-27 14:33:00 +00:00
|
|
|
#include "browser/browser_main_parts.h"
|
2014-03-04 08:12:02 +00:00
|
|
|
#include "browser/inspectable_web_contents_delegate.h"
|
2013-03-14 13:03:50 +00:00
|
|
|
#include "browser/inspectable_web_contents_view.h"
|
|
|
|
|
2014-07-09 07:34:10 +00:00
|
|
|
#include "base/json/json_reader.h"
|
2015-06-05 03:03:47 +00:00
|
|
|
#include "base/json/json_writer.h"
|
|
|
|
#include "base/metrics/histogram.h"
|
2013-04-08 17:53:53 +00:00
|
|
|
#include "base/prefs/pref_registry_simple.h"
|
|
|
|
#include "base/prefs/pref_service.h"
|
2013-10-07 19:16:49 +00:00
|
|
|
#include "base/strings/stringprintf.h"
|
2013-08-23 20:56:30 +00:00
|
|
|
#include "base/strings/utf_string_conversions.h"
|
2014-07-04 13:34:47 +00:00
|
|
|
#include "base/values.h"
|
2015-06-05 03:20:20 +00:00
|
|
|
#include "content/public/browser/browser_thread.h"
|
2013-03-27 14:33:00 +00:00
|
|
|
#include "content/public/browser/devtools_http_handler.h"
|
2014-08-26 07:06:51 +00:00
|
|
|
#include "content/public/browser/host_zoom_map.h"
|
2014-07-09 07:34:10 +00:00
|
|
|
#include "content/public/browser/render_frame_host.h"
|
2013-03-27 15:19:15 +00:00
|
|
|
#include "content/public/browser/render_view_host.h"
|
2015-06-05 03:20:20 +00:00
|
|
|
#include "net/http/http_response_headers.h"
|
|
|
|
#include "net/url_request/url_fetcher.h"
|
|
|
|
#include "net/url_request/url_fetcher_response_writer.h"
|
2013-03-27 14:33:00 +00:00
|
|
|
|
2013-03-14 13:03:50 +00:00
|
|
|
namespace brightray {
|
|
|
|
|
2013-04-08 17:53:53 +00:00
|
|
|
namespace {
|
|
|
|
|
2014-08-26 07:06:51 +00:00
|
|
|
const double kPresetZoomFactors[] = { 0.25, 0.333, 0.5, 0.666, 0.75, 0.9, 1.0,
|
|
|
|
1.1, 1.25, 1.5, 1.75, 2.0, 2.5, 3.0, 4.0,
|
|
|
|
5.0 };
|
|
|
|
|
2014-08-11 02:42:50 +00:00
|
|
|
const char kChromeUIDevToolsURL[] = "chrome-devtools://devtools/devtools.html?"
|
2014-11-03 13:32:11 +00:00
|
|
|
"can_dock=%s&"
|
2014-09-09 10:28:02 +00:00
|
|
|
"toolbarColor=rgba(223,223,223,1)&"
|
|
|
|
"textColor=rgba(0,0,0,1)&"
|
2014-08-11 02:42:50 +00:00
|
|
|
"experiments=true";
|
2014-07-04 13:34:47 +00:00
|
|
|
const char kDevToolsBoundsPref[] = "brightray.devtools.bounds";
|
2013-04-08 17:53:53 +00:00
|
|
|
|
2014-07-09 07:34:10 +00:00
|
|
|
const char kFrontendHostId[] = "id";
|
|
|
|
const char kFrontendHostMethod[] = "method";
|
|
|
|
const char kFrontendHostParams[] = "params";
|
|
|
|
|
2015-06-05 03:03:47 +00:00
|
|
|
const char kDevToolsActionTakenHistogram[] = "DevTools.ActionTaken";
|
|
|
|
const int kDevToolsActionTakenBoundary = 100;
|
|
|
|
const char kDevToolsPanelShownHistogram[] = "DevTools.PanelShown";
|
|
|
|
const int kDevToolsPanelShownBoundary = 20;
|
|
|
|
|
2014-07-04 13:34:47 +00:00
|
|
|
void RectToDictionary(const gfx::Rect& bounds, base::DictionaryValue* dict) {
|
|
|
|
dict->SetInteger("x", bounds.x());
|
|
|
|
dict->SetInteger("y", bounds.y());
|
|
|
|
dict->SetInteger("width", bounds.width());
|
|
|
|
dict->SetInteger("height", bounds.height());
|
2013-04-08 17:53:53 +00:00
|
|
|
}
|
|
|
|
|
2014-07-04 13:34:47 +00:00
|
|
|
void DictionaryToRect(const base::DictionaryValue& dict, gfx::Rect* bounds) {
|
|
|
|
int x = 0, y = 0, width = 800, height = 600;
|
|
|
|
dict.GetInteger("x", &x);
|
|
|
|
dict.GetInteger("y", &y);
|
|
|
|
dict.GetInteger("width", &width);
|
|
|
|
dict.GetInteger("height", &height);
|
|
|
|
*bounds = gfx::Rect(x, y, width, height);
|
|
|
|
}
|
|
|
|
|
2014-08-26 07:06:51 +00:00
|
|
|
double GetZoomLevelForWebContents(content::WebContents* web_contents) {
|
2014-12-05 22:31:02 +00:00
|
|
|
return content::HostZoomMap::GetZoomLevel(web_contents);
|
2014-08-26 07:06:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void SetZoomLevelForWebContents(content::WebContents* web_contents, double level) {
|
2014-12-05 22:31:02 +00:00
|
|
|
content::HostZoomMap::SetZoomLevel(web_contents, level);
|
2014-08-26 07:06:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
double GetNextZoomLevel(double level, bool out) {
|
|
|
|
double factor = content::ZoomLevelToZoomFactor(level);
|
|
|
|
size_t size = arraysize(kPresetZoomFactors);
|
|
|
|
for (size_t i = 0; i < size; ++i) {
|
|
|
|
if (!content::ZoomValuesEqual(kPresetZoomFactors[i], factor))
|
|
|
|
continue;
|
|
|
|
if (out && i > 0)
|
|
|
|
return content::ZoomFactorToZoomLevel(kPresetZoomFactors[i - 1]);
|
|
|
|
if (!out && i != size - 1)
|
|
|
|
return content::ZoomFactorToZoomLevel(kPresetZoomFactors[i + 1]);
|
|
|
|
}
|
|
|
|
return level;
|
|
|
|
}
|
|
|
|
|
2015-06-05 03:20:20 +00:00
|
|
|
// ResponseWriter -------------------------------------------------------------
|
|
|
|
|
|
|
|
class ResponseWriter : public net::URLFetcherResponseWriter {
|
|
|
|
public:
|
|
|
|
ResponseWriter(base::WeakPtr<InspectableWebContentsImpl> bindings, int stream_id);
|
|
|
|
~ResponseWriter() override;
|
|
|
|
|
|
|
|
// URLFetcherResponseWriter overrides:
|
|
|
|
int Initialize(const net::CompletionCallback& callback) override;
|
|
|
|
int Write(net::IOBuffer* buffer,
|
|
|
|
int num_bytes,
|
|
|
|
const net::CompletionCallback& callback) override;
|
|
|
|
int Finish(const net::CompletionCallback& callback) override;
|
|
|
|
|
|
|
|
private:
|
|
|
|
base::WeakPtr<InspectableWebContentsImpl> bindings_;
|
|
|
|
int stream_id_;
|
|
|
|
|
|
|
|
DISALLOW_COPY_AND_ASSIGN(ResponseWriter);
|
|
|
|
};
|
|
|
|
|
|
|
|
ResponseWriter::ResponseWriter(base::WeakPtr<InspectableWebContentsImpl> bindings,
|
|
|
|
int stream_id)
|
|
|
|
: bindings_(bindings),
|
|
|
|
stream_id_(stream_id) {
|
|
|
|
}
|
|
|
|
|
|
|
|
ResponseWriter::~ResponseWriter() {
|
|
|
|
}
|
|
|
|
|
|
|
|
int ResponseWriter::Initialize(const net::CompletionCallback& callback) {
|
|
|
|
return net::OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
int ResponseWriter::Write(net::IOBuffer* buffer,
|
|
|
|
int num_bytes,
|
|
|
|
const net::CompletionCallback& callback) {
|
|
|
|
base::FundamentalValue* id = new base::FundamentalValue(stream_id_);
|
|
|
|
base::StringValue* chunk =
|
|
|
|
new base::StringValue(std::string(buffer->data(), num_bytes));
|
|
|
|
|
|
|
|
content::BrowserThread::PostTask(
|
|
|
|
content::BrowserThread::UI, FROM_HERE,
|
|
|
|
base::Bind(&InspectableWebContentsImpl::CallClientFunction,
|
|
|
|
bindings_, "DevToolsAPI.streamWrite",
|
|
|
|
base::Owned(id), base::Owned(chunk), nullptr));
|
|
|
|
return num_bytes;
|
|
|
|
}
|
|
|
|
|
|
|
|
int ResponseWriter::Finish(const net::CompletionCallback& callback) {
|
|
|
|
return net::OK;
|
|
|
|
}
|
|
|
|
|
2014-07-04 13:34:47 +00:00
|
|
|
} // namespace
|
|
|
|
|
2013-03-14 13:03:50 +00:00
|
|
|
// Implemented separately on each platform.
|
2013-11-17 23:08:34 +00:00
|
|
|
InspectableWebContentsView* CreateInspectableContentsView(
|
|
|
|
InspectableWebContentsImpl* inspectable_web_contents_impl);
|
2013-03-14 13:03:50 +00:00
|
|
|
|
2013-04-08 17:53:53 +00:00
|
|
|
void InspectableWebContentsImpl::RegisterPrefs(PrefRegistrySimple* registry) {
|
2014-07-11 13:55:57 +00:00
|
|
|
auto bounds_dict = make_scoped_ptr(new base::DictionaryValue);
|
2014-07-04 13:34:47 +00:00
|
|
|
RectToDictionary(gfx::Rect(0, 0, 800, 600), bounds_dict.get());
|
|
|
|
registry->RegisterDictionaryPref(kDevToolsBoundsPref, bounds_dict.release());
|
2013-04-08 17:53:53 +00:00
|
|
|
}
|
|
|
|
|
2013-11-17 23:08:34 +00:00
|
|
|
InspectableWebContentsImpl::InspectableWebContentsImpl(
|
|
|
|
content::WebContents* web_contents)
|
2014-03-04 08:12:02 +00:00
|
|
|
: web_contents_(web_contents),
|
2014-11-03 13:32:11 +00:00
|
|
|
can_dock_(true),
|
2015-06-05 03:03:47 +00:00
|
|
|
delegate_(nullptr),
|
|
|
|
weak_factory_(this) {
|
2014-07-04 13:34:47 +00:00
|
|
|
auto context = static_cast<BrowserContext*>(web_contents_->GetBrowserContext());
|
|
|
|
auto bounds_dict = context->prefs()->GetDictionary(kDevToolsBoundsPref);
|
|
|
|
if (bounds_dict)
|
|
|
|
DictionaryToRect(*bounds_dict, &devtools_bounds_);
|
|
|
|
|
2013-03-14 13:03:50 +00:00
|
|
|
view_.reset(CreateInspectableContentsView(this));
|
|
|
|
}
|
|
|
|
|
|
|
|
InspectableWebContentsImpl::~InspectableWebContentsImpl() {
|
|
|
|
}
|
|
|
|
|
|
|
|
InspectableWebContentsView* InspectableWebContentsImpl::GetView() const {
|
|
|
|
return view_.get();
|
|
|
|
}
|
|
|
|
|
|
|
|
content::WebContents* InspectableWebContentsImpl::GetWebContents() const {
|
|
|
|
return web_contents_.get();
|
|
|
|
}
|
|
|
|
|
2014-11-03 13:32:11 +00:00
|
|
|
void InspectableWebContentsImpl::SetCanDock(bool can_dock) {
|
|
|
|
can_dock_ = can_dock;
|
|
|
|
}
|
|
|
|
|
2013-03-14 13:03:50 +00:00
|
|
|
void InspectableWebContentsImpl::ShowDevTools() {
|
2014-07-02 08:21:47 +00:00
|
|
|
// Show devtools only after it has done loading, this is to make sure the
|
|
|
|
// SetIsDocked is called *BEFORE* ShowDevTools.
|
2013-03-27 14:33:00 +00:00
|
|
|
if (!devtools_web_contents_) {
|
2013-12-02 17:38:24 +00:00
|
|
|
embedder_message_dispatcher_.reset(
|
2015-06-05 03:03:47 +00:00
|
|
|
DevToolsEmbedderMessageDispatcher::CreateForDevToolsFrontend(this));
|
2013-12-02 17:38:24 +00:00
|
|
|
|
2014-08-31 10:43:01 +00:00
|
|
|
content::WebContents::CreateParams create_params(web_contents_->GetBrowserContext());
|
2013-11-17 23:08:34 +00:00
|
|
|
devtools_web_contents_.reset(content::WebContents::Create(create_params));
|
2013-10-10 18:07:20 +00:00
|
|
|
|
2013-03-27 14:33:00 +00:00
|
|
|
Observe(devtools_web_contents_.get());
|
|
|
|
devtools_web_contents_->SetDelegate(this);
|
|
|
|
|
2014-10-11 08:38:27 +00:00
|
|
|
agent_host_ = content::DevToolsAgentHost::GetOrCreateFor(web_contents_.get());
|
2014-10-11 11:00:30 +00:00
|
|
|
frontend_host_.reset(content::DevToolsFrontendHost::Create(
|
2015-03-09 02:38:40 +00:00
|
|
|
web_contents_->GetMainFrame(), this));
|
2014-12-05 22:31:02 +00:00
|
|
|
agent_host_->AttachClient(this);
|
2013-03-27 14:33:00 +00:00
|
|
|
|
2014-11-03 13:32:11 +00:00
|
|
|
GURL devtools_url(base::StringPrintf(kChromeUIDevToolsURL, can_dock_ ? "true" : ""));
|
2013-11-17 23:08:34 +00:00
|
|
|
devtools_web_contents_->GetController().LoadURL(
|
|
|
|
devtools_url,
|
|
|
|
content::Referrer(),
|
2014-12-05 22:31:02 +00:00
|
|
|
ui::PAGE_TRANSITION_AUTO_TOPLEVEL,
|
2013-11-17 23:08:34 +00:00
|
|
|
std::string());
|
2014-07-02 08:21:47 +00:00
|
|
|
} else {
|
|
|
|
view_->ShowDevTools();
|
2013-03-27 14:33:00 +00:00
|
|
|
}
|
2013-03-14 13:03:50 +00:00
|
|
|
}
|
|
|
|
|
2014-03-20 01:26:21 +00:00
|
|
|
void InspectableWebContentsImpl::CloseDevTools() {
|
2014-07-02 08:21:47 +00:00
|
|
|
if (devtools_web_contents_) {
|
2014-03-20 01:26:21 +00:00
|
|
|
view_->CloseDevTools();
|
|
|
|
devtools_web_contents_.reset();
|
2014-07-27 10:44:58 +00:00
|
|
|
web_contents_->Focus();
|
2014-03-20 01:26:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-12-09 12:34:44 +00:00
|
|
|
bool InspectableWebContentsImpl::IsDevToolsViewShowing() {
|
|
|
|
return devtools_web_contents_ && view_->IsDevToolsViewShowing();
|
2013-11-05 02:29:53 +00:00
|
|
|
}
|
|
|
|
|
2015-05-18 13:56:03 +00:00
|
|
|
void InspectableWebContentsImpl::AttachTo(const scoped_refptr<content::DevToolsAgentHost>& host) {
|
|
|
|
if (agent_host_.get())
|
|
|
|
Detach();
|
|
|
|
agent_host_ = host;
|
|
|
|
agent_host_->AttachClient(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
void InspectableWebContentsImpl::Detach() {
|
|
|
|
agent_host_->DetachClient();
|
|
|
|
agent_host_ = nullptr;
|
|
|
|
}
|
|
|
|
|
2015-06-05 03:03:47 +00:00
|
|
|
void InspectableWebContentsImpl::CallClientFunction(const std::string& function_name,
|
|
|
|
const base::Value* arg1,
|
|
|
|
const base::Value* arg2,
|
|
|
|
const base::Value* arg3) {
|
|
|
|
std::string javascript = function_name + "(";
|
|
|
|
if (arg1) {
|
|
|
|
std::string json;
|
|
|
|
base::JSONWriter::Write(arg1, &json);
|
|
|
|
javascript.append(json);
|
|
|
|
if (arg2) {
|
|
|
|
base::JSONWriter::Write(arg2, &json);
|
|
|
|
javascript.append(", ").append(json);
|
|
|
|
if (arg3) {
|
|
|
|
base::JSONWriter::Write(arg3, &json);
|
|
|
|
javascript.append(", ").append(json);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
javascript.append(");");
|
|
|
|
devtools_web_contents_->GetMainFrame()->ExecuteJavaScript(
|
|
|
|
base::UTF8ToUTF16(javascript));
|
|
|
|
}
|
|
|
|
|
2014-07-04 13:34:47 +00:00
|
|
|
gfx::Rect InspectableWebContentsImpl::GetDevToolsBounds() const {
|
|
|
|
return devtools_bounds_;
|
|
|
|
}
|
|
|
|
|
|
|
|
void InspectableWebContentsImpl::SaveDevToolsBounds(const gfx::Rect& bounds) {
|
|
|
|
auto context = static_cast<BrowserContext*>(web_contents_->GetBrowserContext());
|
|
|
|
base::DictionaryValue bounds_dict;
|
|
|
|
RectToDictionary(bounds, &bounds_dict);
|
|
|
|
context->prefs()->Set(kDevToolsBoundsPref, bounds_dict);
|
|
|
|
devtools_bounds_ = bounds;
|
|
|
|
}
|
|
|
|
|
2013-03-27 14:33:00 +00:00
|
|
|
void InspectableWebContentsImpl::ActivateWindow() {
|
|
|
|
}
|
|
|
|
|
|
|
|
void InspectableWebContentsImpl::CloseWindow() {
|
2014-07-27 11:18:15 +00:00
|
|
|
devtools_web_contents()->DispatchBeforeUnload(false);
|
2013-03-27 14:33:00 +00:00
|
|
|
}
|
|
|
|
|
2015-06-05 03:03:47 +00:00
|
|
|
void InspectableWebContentsImpl::LoadCompleted() {
|
|
|
|
}
|
|
|
|
|
2014-09-01 11:15:07 +00:00
|
|
|
void InspectableWebContentsImpl::SetInspectedPageBounds(const gfx::Rect& rect) {
|
|
|
|
DevToolsContentsResizingStrategy strategy(rect);
|
2014-07-02 08:21:47 +00:00
|
|
|
if (contents_resizing_strategy_.Equals(strategy))
|
|
|
|
return;
|
|
|
|
|
|
|
|
contents_resizing_strategy_.CopyFrom(strategy);
|
|
|
|
view_->SetContentsResizingStrategy(contents_resizing_strategy_);
|
2013-03-27 14:33:00 +00:00
|
|
|
}
|
|
|
|
|
2014-07-08 07:58:38 +00:00
|
|
|
void InspectableWebContentsImpl::InspectElementCompleted() {
|
|
|
|
}
|
|
|
|
|
2015-06-05 03:03:47 +00:00
|
|
|
void InspectableWebContentsImpl::InspectedURLChanged(const std::string& url) {
|
|
|
|
}
|
|
|
|
|
|
|
|
void InspectableWebContentsImpl::LoadNetworkResource(
|
|
|
|
const DispatchCallback& callback,
|
|
|
|
const std::string& url,
|
|
|
|
const std::string& headers,
|
|
|
|
int stream_id) {
|
2015-06-05 03:20:20 +00:00
|
|
|
GURL gurl(url);
|
|
|
|
if (!gurl.is_valid()) {
|
|
|
|
base::DictionaryValue response;
|
|
|
|
response.SetInteger("statusCode", 404);
|
|
|
|
callback.Run(&response);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
auto browser_context = static_cast<BrowserContext*>(devtools_web_contents_->GetBrowserContext());
|
|
|
|
|
|
|
|
net::URLFetcher* fetcher =
|
|
|
|
net::URLFetcher::Create(gurl, net::URLFetcher::GET, this);
|
|
|
|
pending_requests_[fetcher] = callback;
|
|
|
|
fetcher->SetRequestContext(browser_context->url_request_context_getter());
|
|
|
|
fetcher->SetExtraRequestHeaders(headers);
|
|
|
|
fetcher->SaveResponseWithWriter(scoped_ptr<net::URLFetcherResponseWriter>(
|
|
|
|
new ResponseWriter(weak_factory_.GetWeakPtr(), stream_id)));
|
|
|
|
fetcher->Start();
|
2014-07-02 08:21:47 +00:00
|
|
|
}
|
2013-03-27 15:19:15 +00:00
|
|
|
|
2015-06-05 03:03:47 +00:00
|
|
|
void InspectableWebContentsImpl::SetIsDocked(const DispatchCallback& callback,
|
|
|
|
bool docked) {
|
2014-07-02 08:21:47 +00:00
|
|
|
view_->SetIsDocked(docked);
|
2015-06-05 03:03:47 +00:00
|
|
|
if (!callback.is_null())
|
|
|
|
callback.Run(nullptr);
|
2013-03-27 14:33:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void InspectableWebContentsImpl::OpenInNewTab(const std::string& url) {
|
|
|
|
}
|
|
|
|
|
2013-11-17 23:08:34 +00:00
|
|
|
void InspectableWebContentsImpl::SaveToFile(
|
|
|
|
const std::string& url, const std::string& content, bool save_as) {
|
2014-04-04 16:10:09 +00:00
|
|
|
if (delegate_)
|
|
|
|
delegate_->DevToolsSaveToFile(url, content, save_as);
|
2013-03-27 14:33:00 +00:00
|
|
|
}
|
|
|
|
|
2013-11-17 23:08:34 +00:00
|
|
|
void InspectableWebContentsImpl::AppendToFile(
|
|
|
|
const std::string& url, const std::string& content) {
|
2014-04-04 16:10:09 +00:00
|
|
|
if (delegate_)
|
|
|
|
delegate_->DevToolsAppendToFile(url, content);
|
2013-03-27 14:33:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void InspectableWebContentsImpl::RequestFileSystems() {
|
2014-07-09 07:34:10 +00:00
|
|
|
devtools_web_contents()->GetMainFrame()->ExecuteJavaScript(
|
2015-03-11 21:51:37 +00:00
|
|
|
base::ASCIIToUTF16("DevToolsAPI.fileSystemsLoaded([])"));
|
2013-03-27 14:33:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void InspectableWebContentsImpl::AddFileSystem() {
|
2015-06-04 16:51:23 +00:00
|
|
|
if (delegate_)
|
|
|
|
delegate_->DevToolsAddFileSystem();
|
2013-03-27 14:33:00 +00:00
|
|
|
}
|
|
|
|
|
2013-11-17 23:08:34 +00:00
|
|
|
void InspectableWebContentsImpl::RemoveFileSystem(
|
|
|
|
const std::string& file_system_path) {
|
2015-06-04 16:51:23 +00:00
|
|
|
if (delegate_)
|
|
|
|
delegate_->DevToolsRemoveFileSystem(file_system_path);
|
2013-03-27 14:33:00 +00:00
|
|
|
}
|
|
|
|
|
2014-07-08 07:58:38 +00:00
|
|
|
void InspectableWebContentsImpl::UpgradeDraggedFileSystemPermissions(
|
|
|
|
const std::string& file_system_url) {
|
|
|
|
}
|
|
|
|
|
2013-11-17 23:08:34 +00:00
|
|
|
void InspectableWebContentsImpl::IndexPath(
|
|
|
|
int request_id, const std::string& file_system_path) {
|
2013-10-07 19:29:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void InspectableWebContentsImpl::StopIndexing(int request_id) {
|
|
|
|
}
|
|
|
|
|
2013-11-17 23:08:34 +00:00
|
|
|
void InspectableWebContentsImpl::SearchInPath(
|
|
|
|
int request_id,
|
|
|
|
const std::string& file_system_path,
|
|
|
|
const std::string& query) {
|
2013-10-07 19:29:17 +00:00
|
|
|
}
|
|
|
|
|
2015-06-05 03:03:47 +00:00
|
|
|
void InspectableWebContentsImpl::SetWhitelistedShortcuts(const std::string& message) {
|
|
|
|
}
|
|
|
|
|
2014-07-08 07:58:38 +00:00
|
|
|
void InspectableWebContentsImpl::ZoomIn() {
|
2014-08-26 07:06:51 +00:00
|
|
|
double level = GetZoomLevelForWebContents(devtools_web_contents());
|
|
|
|
SetZoomLevelForWebContents(devtools_web_contents(), GetNextZoomLevel(level, false));
|
2014-07-08 07:58:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void InspectableWebContentsImpl::ZoomOut() {
|
2014-08-26 07:06:51 +00:00
|
|
|
double level = GetZoomLevelForWebContents(devtools_web_contents());
|
|
|
|
SetZoomLevelForWebContents(devtools_web_contents(), GetNextZoomLevel(level, true));
|
2014-07-08 07:58:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void InspectableWebContentsImpl::ResetZoom() {
|
2014-08-26 07:06:51 +00:00
|
|
|
SetZoomLevelForWebContents(devtools_web_contents(), 0.);
|
2014-07-08 07:58:38 +00:00
|
|
|
}
|
|
|
|
|
2015-06-05 03:03:47 +00:00
|
|
|
void InspectableWebContentsImpl::SetDevicesUpdatesEnabled(bool enabled) {
|
|
|
|
}
|
|
|
|
|
|
|
|
void InspectableWebContentsImpl::SendMessageToBrowser(const std::string& message) {
|
|
|
|
if (agent_host_.get())
|
|
|
|
agent_host_->DispatchProtocolMessage(message);
|
|
|
|
}
|
|
|
|
|
|
|
|
void InspectableWebContentsImpl::RecordActionUMA(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 InspectableWebContentsImpl::SendJsonRequest(const DispatchCallback& callback,
|
|
|
|
const std::string& browser_id,
|
|
|
|
const std::string& url) {
|
|
|
|
callback.Run(nullptr);
|
|
|
|
}
|
|
|
|
|
2014-10-11 08:38:27 +00:00
|
|
|
void InspectableWebContentsImpl::HandleMessageFromDevToolsFrontend(const std::string& message) {
|
2014-07-09 07:34:10 +00:00
|
|
|
std::string method;
|
2015-06-05 03:03:47 +00:00
|
|
|
base::ListValue empty_params;
|
|
|
|
base::ListValue* params = &empty_params;
|
|
|
|
|
|
|
|
base::DictionaryValue* dict = NULL;
|
|
|
|
scoped_ptr<base::Value> parsed_message(base::JSONReader::Read(message));
|
|
|
|
if (!parsed_message ||
|
|
|
|
!parsed_message->GetAsDictionary(&dict) ||
|
|
|
|
!dict->GetString(kFrontendHostMethod, &method) ||
|
|
|
|
(dict->HasKey(kFrontendHostParams) &&
|
|
|
|
!dict->GetList(kFrontendHostParams, ¶ms))) {
|
2014-07-09 07:34:10 +00:00
|
|
|
LOG(ERROR) << "Invalid message was sent to embedder: " << message;
|
|
|
|
return;
|
|
|
|
}
|
2015-06-05 03:03:47 +00:00
|
|
|
int id = 0;
|
|
|
|
dict->GetInteger(kFrontendHostId, &id);
|
|
|
|
embedder_message_dispatcher_->Dispatch(
|
|
|
|
base::Bind(&InspectableWebContentsImpl::SendMessageAck,
|
|
|
|
weak_factory_.GetWeakPtr(),
|
|
|
|
id),
|
|
|
|
method,
|
|
|
|
params);
|
2013-12-02 17:38:24 +00:00
|
|
|
}
|
|
|
|
|
2014-10-11 08:38:27 +00:00
|
|
|
void InspectableWebContentsImpl::HandleMessageFromDevToolsFrontendToBackend(
|
|
|
|
const std::string& message) {
|
2015-06-05 03:03:47 +00:00
|
|
|
if (agent_host_.get())
|
|
|
|
agent_host_->DispatchProtocolMessage(message);
|
2014-10-11 08:38:27 +00:00
|
|
|
}
|
|
|
|
|
2014-12-05 22:31:02 +00:00
|
|
|
void InspectableWebContentsImpl::DispatchProtocolMessage(
|
|
|
|
content::DevToolsAgentHost* agent_host, const std::string& message) {
|
2015-03-11 21:51:37 +00:00
|
|
|
std::string code = "DevToolsAPI.dispatchMessage(" + message + ");";
|
2014-10-11 08:38:27 +00:00
|
|
|
base::string16 javascript = base::UTF8ToUTF16(code);
|
2014-12-05 22:31:02 +00:00
|
|
|
web_contents()->GetMainFrame()->ExecuteJavaScript(javascript);
|
2013-03-27 14:33:00 +00:00
|
|
|
}
|
|
|
|
|
2014-12-05 22:31:02 +00:00
|
|
|
void InspectableWebContentsImpl::AgentHostClosed(
|
|
|
|
content::DevToolsAgentHost* agent_host, bool replaced) {
|
2013-03-27 14:33:00 +00:00
|
|
|
}
|
|
|
|
|
2015-03-09 02:13:17 +00:00
|
|
|
void InspectableWebContentsImpl::AboutToNavigateRenderFrame(
|
2015-04-21 10:54:57 +00:00
|
|
|
content::RenderFrameHost* old_host,
|
2015-03-09 02:13:17 +00:00
|
|
|
content::RenderFrameHost* new_host) {
|
|
|
|
if (new_host->GetParent())
|
|
|
|
return;
|
|
|
|
frontend_host_.reset(content::DevToolsFrontendHost::Create(new_host, this));
|
2014-10-11 11:00:30 +00:00
|
|
|
}
|
|
|
|
|
2014-10-11 08:38:27 +00:00
|
|
|
void InspectableWebContentsImpl::DidFinishLoad(content::RenderFrameHost* render_frame_host,
|
|
|
|
const GURL& validated_url) {
|
|
|
|
if (render_frame_host->GetParent())
|
2013-04-08 17:53:53 +00:00
|
|
|
return;
|
|
|
|
|
2014-07-02 08:21:47 +00:00
|
|
|
view_->ShowDevTools();
|
2014-11-03 13:32:11 +00:00
|
|
|
|
|
|
|
// If the devtools can dock, "SetIsDocked" will be called by devtools itself.
|
|
|
|
if (!can_dock_)
|
2015-06-05 03:03:47 +00:00
|
|
|
SetIsDocked(DispatchCallback(), false);
|
2013-04-08 17:53:53 +00:00
|
|
|
}
|
|
|
|
|
2014-07-27 10:27:19 +00:00
|
|
|
void InspectableWebContentsImpl::WebContentsDestroyed() {
|
2014-12-05 22:31:02 +00:00
|
|
|
agent_host_->DetachClient();
|
2013-03-27 14:33:00 +00:00
|
|
|
Observe(nullptr);
|
|
|
|
agent_host_ = nullptr;
|
2015-06-05 03:20:20 +00:00
|
|
|
|
|
|
|
for (const auto& pair : pending_requests_)
|
|
|
|
delete pair.first;
|
2013-03-27 14:33:00 +00:00
|
|
|
}
|
|
|
|
|
2014-08-28 04:53:35 +00:00
|
|
|
bool InspectableWebContentsImpl::AddMessageToConsole(
|
|
|
|
content::WebContents* source,
|
|
|
|
int32 level,
|
|
|
|
const base::string16& message,
|
|
|
|
int32 line_no,
|
|
|
|
const base::string16& source_id) {
|
|
|
|
logging::LogMessage("CONSOLE", line_no, level).stream() << "\"" <<
|
|
|
|
message << "\", source: " << source_id << " (" << line_no << ")";
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2014-10-27 08:42:54 +00:00
|
|
|
bool InspectableWebContentsImpl::ShouldCreateWebContents(
|
|
|
|
content::WebContents* web_contents,
|
|
|
|
int route_id,
|
2015-03-09 02:13:17 +00:00
|
|
|
int main_frame_route_id,
|
2014-10-27 08:42:54 +00:00
|
|
|
WindowContainerType window_container_type,
|
|
|
|
const base::string16& frame_name,
|
|
|
|
const GURL& target_url,
|
|
|
|
const std::string& partition_id,
|
|
|
|
content::SessionStorageNamespace* session_storage_namespace) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-11-17 23:08:34 +00:00
|
|
|
void InspectableWebContentsImpl::HandleKeyboardEvent(
|
|
|
|
content::WebContents* source,
|
|
|
|
const content::NativeWebKeyboardEvent& event) {
|
2013-03-27 14:33:00 +00:00
|
|
|
auto delegate = web_contents_->GetDelegate();
|
|
|
|
if (delegate)
|
|
|
|
delegate->HandleKeyboardEvent(source, event);
|
|
|
|
}
|
|
|
|
|
2014-07-13 02:08:28 +00:00
|
|
|
void InspectableWebContentsImpl::CloseContents(content::WebContents* source) {
|
|
|
|
CloseDevTools();
|
|
|
|
}
|
|
|
|
|
2015-06-05 03:03:47 +00:00
|
|
|
void InspectableWebContentsImpl::WebContentsFocused(
|
|
|
|
content::WebContents* contents) {
|
|
|
|
if (delegate_)
|
|
|
|
delegate_->DevToolsFocused();
|
|
|
|
}
|
|
|
|
|
2015-06-05 03:20:20 +00:00
|
|
|
void InspectableWebContentsImpl::OnURLFetchComplete(const net::URLFetcher* source) {
|
|
|
|
DCHECK(source);
|
|
|
|
PendingRequestsMap::iterator it = pending_requests_.find(source);
|
|
|
|
DCHECK(it != pending_requests_.end());
|
|
|
|
|
|
|
|
base::DictionaryValue response;
|
|
|
|
base::DictionaryValue* headers = new base::DictionaryValue();
|
|
|
|
net::HttpResponseHeaders* rh = source->GetResponseHeaders();
|
|
|
|
response.SetInteger("statusCode", rh ? rh->response_code() : 200);
|
|
|
|
response.Set("headers", headers);
|
|
|
|
|
|
|
|
void* iterator = NULL;
|
|
|
|
std::string name;
|
|
|
|
std::string value;
|
|
|
|
while (rh && rh->EnumerateHeaderLines(&iterator, &name, &value))
|
|
|
|
headers->SetString(name, value);
|
|
|
|
|
|
|
|
it->second.Run(&response);
|
|
|
|
pending_requests_.erase(it);
|
|
|
|
delete source;
|
|
|
|
}
|
|
|
|
|
2015-06-05 03:03:47 +00:00
|
|
|
void InspectableWebContentsImpl::SendMessageAck(int request_id,
|
|
|
|
const base::Value* arg) {
|
|
|
|
base::FundamentalValue id_value(request_id);
|
|
|
|
CallClientFunction("DevToolsAPI.embedderMessageAck",
|
|
|
|
&id_value, arg, nullptr);
|
|
|
|
}
|
|
|
|
|
2013-11-17 23:08:34 +00:00
|
|
|
} // namespace brightray
|