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.
|
|
|
|
|
2017-05-18 22:58:12 +00:00
|
|
|
#include "brightray/browser/inspectable_web_contents_impl.h"
|
2013-03-14 13:03:50 +00:00
|
|
|
|
2016-07-04 06:06:05 +00:00
|
|
|
#include "base/json/json_reader.h"
|
|
|
|
#include "base/json/json_writer.h"
|
|
|
|
#include "base/metrics/histogram.h"
|
|
|
|
#include "base/strings/pattern.h"
|
|
|
|
#include "base/strings/stringprintf.h"
|
|
|
|
#include "base/strings/utf_string_conversions.h"
|
|
|
|
#include "base/values.h"
|
2017-05-18 22:58:12 +00:00
|
|
|
#include "brightray/browser/browser_client.h"
|
|
|
|
#include "brightray/browser/browser_context.h"
|
|
|
|
#include "brightray/browser/browser_main_parts.h"
|
|
|
|
#include "brightray/browser/inspectable_web_contents_delegate.h"
|
|
|
|
#include "brightray/browser/inspectable_web_contents_view.h"
|
|
|
|
#include "brightray/browser/inspectable_web_contents_view_delegate.h"
|
2017-05-18 22:29:22 +00:00
|
|
|
#include "components/prefs/pref_registry_simple.h"
|
2016-04-27 02:12:52 +00:00
|
|
|
#include "components/prefs/pref_service.h"
|
|
|
|
#include "components/prefs/scoped_user_pref_update.h"
|
2015-06-05 03:20:20 +00:00
|
|
|
#include "content/public/browser/browser_thread.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-09-30 10:58:46 +00:00
|
|
|
#include "content/public/common/user_agent.h"
|
2016-03-08 14:28:28 +00:00
|
|
|
#include "ipc/ipc_channel.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"
|
2016-07-04 06:06:05 +00:00
|
|
|
#include "ui/display/display.h"
|
|
|
|
#include "ui/display/screen.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 };
|
|
|
|
|
2015-09-02 10:25:59 +00:00
|
|
|
const char kChromeUIDevToolsURL[] =
|
|
|
|
"chrome-devtools://devtools/bundled/inspector.html?"
|
2015-09-30 10:58:46 +00:00
|
|
|
"remoteBase=%s&"
|
2015-09-02 10:25:59 +00:00
|
|
|
"can_dock=%s&"
|
|
|
|
"toolbarColor=rgba(223,223,223,1)&"
|
|
|
|
"textColor=rgba(0,0,0,1)&"
|
|
|
|
"experiments=true";
|
2015-09-30 10:58:46 +00:00
|
|
|
const char kChromeUIDevToolsRemoteFrontendBase[] =
|
|
|
|
"https://chrome-devtools-frontend.appspot.com/";
|
|
|
|
const char kChromeUIDevToolsRemoteFrontendPath[] = "serve_file";
|
2015-09-02 10:25:59 +00:00
|
|
|
|
2014-07-04 13:34:47 +00:00
|
|
|
const char kDevToolsBoundsPref[] = "brightray.devtools.bounds";
|
2015-07-27 14:34:21 +00:00
|
|
|
const char kDevToolsZoomPref[] = "brightray.devtools.zoom";
|
2015-08-06 05:39:23 +00:00
|
|
|
const char kDevToolsPreferences[] = "brightray.devtools.preferences";
|
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-08-07 09:00:49 +00:00
|
|
|
const char kTitleFormat[] = "Developer Tools - %s";
|
2014-07-09 07:34:10 +00:00
|
|
|
|
2015-06-05 03:58:27 +00:00
|
|
|
const size_t kMaxMessageChunkSize = IPC::Channel::kMaximumMessageSize / 4;
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2015-08-04 14:43:59 +00:00
|
|
|
bool IsPointInRect(const gfx::Point& point, const gfx::Rect& rect) {
|
|
|
|
return point.x() > rect.x() && point.x() < (rect.width() + rect.x()) &&
|
|
|
|
point.y() > rect.y() && point.y() < (rect.height() + rect.y());
|
|
|
|
}
|
|
|
|
|
2016-07-11 06:08:39 +00:00
|
|
|
bool IsPointInScreen(const gfx::Point& point) {
|
2016-07-21 12:03:11 +00:00
|
|
|
for (const auto& display : display::Screen::GetScreen()->GetAllDisplays()) {
|
2016-07-11 06:08:39 +00:00
|
|
|
if (IsPointInRect(point, display.bounds()))
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-07-27 14:34:21 +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-09-30 10:58:46 +00:00
|
|
|
GURL GetRemoteBaseURL() {
|
|
|
|
return GURL(base::StringPrintf(
|
|
|
|
"%s%s/%s/",
|
|
|
|
kChromeUIDevToolsRemoteFrontendBase,
|
|
|
|
kChromeUIDevToolsRemoteFrontendPath,
|
|
|
|
content::GetWebKitRevision().c_str()));
|
|
|
|
}
|
|
|
|
|
2016-10-06 11:59:32 +00:00
|
|
|
GURL GetDevToolsURL(bool can_dock) {
|
2016-04-19 12:43:08 +00:00
|
|
|
auto url_string =
|
|
|
|
base::StringPrintf(kChromeUIDevToolsURL,
|
|
|
|
GetRemoteBaseURL().spec().c_str(),
|
|
|
|
can_dock ? "true" : "");
|
|
|
|
return GURL(url_string);
|
|
|
|
}
|
|
|
|
|
2015-06-05 03:20:20 +00:00
|
|
|
// ResponseWriter -------------------------------------------------------------
|
|
|
|
|
|
|
|
class ResponseWriter : public net::URLFetcherResponseWriter {
|
|
|
|
public:
|
2017-03-23 22:47:30 +00:00
|
|
|
ResponseWriter(base::WeakPtr<InspectableWebContentsImpl> bindings,
|
|
|
|
int stream_id);
|
2015-06-05 03:20:20 +00:00
|
|
|
~ResponseWriter() override;
|
|
|
|
|
|
|
|
// URLFetcherResponseWriter overrides:
|
|
|
|
int Initialize(const net::CompletionCallback& callback) override;
|
|
|
|
int Write(net::IOBuffer* buffer,
|
|
|
|
int num_bytes,
|
|
|
|
const net::CompletionCallback& callback) override;
|
2017-01-23 06:27:57 +00:00
|
|
|
int Finish(int net_error, const net::CompletionCallback& callback) override;
|
2015-06-05 03:20:20 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
base::WeakPtr<InspectableWebContentsImpl> bindings_;
|
|
|
|
int stream_id_;
|
|
|
|
|
|
|
|
DISALLOW_COPY_AND_ASSIGN(ResponseWriter);
|
|
|
|
};
|
|
|
|
|
2017-03-23 22:47:30 +00:00
|
|
|
ResponseWriter::ResponseWriter(
|
|
|
|
base::WeakPtr<InspectableWebContentsImpl> bindings,
|
|
|
|
int stream_id)
|
2015-06-05 03:20:20 +00:00
|
|
|
: 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) {
|
2017-04-04 04:43:49 +00:00
|
|
|
auto* id = new base::Value(stream_id_);
|
2015-06-05 03:20:20 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2017-01-23 06:27:57 +00:00
|
|
|
int ResponseWriter::Finish(int net_error,
|
|
|
|
const net::CompletionCallback& callback) {
|
2015-06-05 03:20:20 +00:00
|
|
|
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) {
|
2016-05-23 03:28:41 +00:00
|
|
|
std::unique_ptr<base::DictionaryValue> bounds_dict(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());
|
2015-07-27 14:34:21 +00:00
|
|
|
registry->RegisterDoublePref(kDevToolsZoomPref, 0.);
|
2015-08-06 05:39:23 +00:00
|
|
|
registry->RegisterDictionaryPref(kDevToolsPreferences);
|
2013-04-08 17:53:53 +00:00
|
|
|
}
|
|
|
|
|
2013-11-17 23:08:34 +00:00
|
|
|
InspectableWebContentsImpl::InspectableWebContentsImpl(
|
|
|
|
content::WebContents* web_contents)
|
2015-06-09 02:41:25 +00:00
|
|
|
: frontend_loaded_(false),
|
2015-06-05 04:24:48 +00:00
|
|
|
can_dock_(true),
|
2015-06-05 03:03:47 +00:00
|
|
|
delegate_(nullptr),
|
2015-06-09 02:41:25 +00:00
|
|
|
web_contents_(web_contents),
|
2015-06-05 03:03:47 +00:00
|
|
|
weak_factory_(this) {
|
2017-03-23 22:47:30 +00:00
|
|
|
auto context =
|
|
|
|
static_cast<BrowserContext*>(web_contents_->GetBrowserContext());
|
2015-07-27 14:34:21 +00:00
|
|
|
pref_service_ = context->prefs();
|
|
|
|
auto bounds_dict = pref_service_->GetDictionary(kDevToolsBoundsPref);
|
2015-08-04 14:43:59 +00:00
|
|
|
if (bounds_dict) {
|
2014-07-04 13:34:47 +00:00
|
|
|
DictionaryToRect(*bounds_dict, &devtools_bounds_);
|
2015-08-04 14:43:59 +00:00
|
|
|
// Sometimes the devtools window is out of screen or has too small size.
|
|
|
|
if (devtools_bounds_.height() < 100 || devtools_bounds_.width() < 100) {
|
|
|
|
devtools_bounds_.set_height(600);
|
|
|
|
devtools_bounds_.set_width(800);
|
|
|
|
}
|
2016-07-11 06:08:39 +00:00
|
|
|
if (!IsPointInScreen(devtools_bounds_.origin())) {
|
2016-07-28 00:07:37 +00:00
|
|
|
gfx::Rect display;
|
|
|
|
if (web_contents->GetNativeView()) {
|
|
|
|
display = display::Screen::GetScreen()->
|
2016-08-04 07:35:09 +00:00
|
|
|
GetDisplayNearestWindow(web_contents->GetNativeView()).bounds();
|
2016-07-28 00:07:37 +00:00
|
|
|
} else {
|
|
|
|
display = display::Screen::GetScreen()->GetPrimaryDisplay().bounds();
|
|
|
|
}
|
2016-08-04 07:35:09 +00:00
|
|
|
|
2017-03-23 22:47:30 +00:00
|
|
|
devtools_bounds_.set_x(display.x() +
|
|
|
|
(display.width() - devtools_bounds_.width()) / 2);
|
|
|
|
devtools_bounds_.set_y(
|
|
|
|
display.y() + (display.height() - devtools_bounds_.height()) / 2);
|
2015-08-04 14:43:59 +00:00
|
|
|
}
|
|
|
|
}
|
2014-07-04 13:34:47 +00:00
|
|
|
|
2013-03-14 13:03:50 +00:00
|
|
|
view_.reset(CreateInspectableContentsView(this));
|
|
|
|
}
|
|
|
|
|
|
|
|
InspectableWebContentsImpl::~InspectableWebContentsImpl() {
|
2017-03-20 19:22:46 +00:00
|
|
|
// Unsubscribe from devtools and Clean up resources.
|
|
|
|
if (devtools_web_contents_) {
|
|
|
|
devtools_web_contents_->SetDelegate(nullptr);
|
|
|
|
// Calling this also unsubscribes the observer, so WebContentsDestroyed
|
|
|
|
// won't be called again.
|
|
|
|
WebContentsDestroyed();
|
|
|
|
}
|
|
|
|
// Let destructor destroy devtools_web_contents_.
|
2013-03-14 13:03:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
InspectableWebContentsView* InspectableWebContentsImpl::GetView() const {
|
|
|
|
return view_.get();
|
|
|
|
}
|
|
|
|
|
|
|
|
content::WebContents* InspectableWebContentsImpl::GetWebContents() const {
|
|
|
|
return web_contents_.get();
|
|
|
|
}
|
|
|
|
|
2017-03-23 22:47:30 +00:00
|
|
|
content::WebContents* InspectableWebContentsImpl::GetDevToolsWebContents()
|
|
|
|
const {
|
2015-06-05 06:33:37 +00:00
|
|
|
return devtools_web_contents_.get();
|
|
|
|
}
|
|
|
|
|
2017-01-13 08:52:45 +00:00
|
|
|
void InspectableWebContentsImpl::InspectElement(int x, int y) {
|
|
|
|
if (agent_host_.get())
|
|
|
|
agent_host_->InspectElement(this, x, y);
|
|
|
|
}
|
|
|
|
|
2017-03-23 22:47:30 +00:00
|
|
|
void InspectableWebContentsImpl::SetDelegate(
|
|
|
|
InspectableWebContentsDelegate* delegate) {
|
2015-06-05 04:24:48 +00:00
|
|
|
delegate_ = delegate;
|
|
|
|
}
|
|
|
|
|
2017-03-23 22:47:30 +00:00
|
|
|
InspectableWebContentsDelegate* InspectableWebContentsImpl::GetDelegate()
|
|
|
|
const {
|
2015-06-05 04:24:48 +00:00
|
|
|
return delegate_;
|
|
|
|
}
|
|
|
|
|
2016-04-19 12:43:08 +00:00
|
|
|
void InspectableWebContentsImpl::SetDockState(const std::string& state) {
|
|
|
|
if (state == "detach") {
|
|
|
|
can_dock_ = false;
|
|
|
|
} else {
|
|
|
|
can_dock_ = true;
|
|
|
|
dock_state_ = state;
|
|
|
|
}
|
2014-11-03 13:32:11 +00:00
|
|
|
}
|
|
|
|
|
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
|
|
|
|
2017-03-23 22:47:30 +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);
|
|
|
|
|
2017-01-12 04:06:25 +00:00
|
|
|
AttachTo(content::DevToolsAgentHost::GetOrCreateFor(web_contents_.get()));
|
2013-03-27 14:33:00 +00:00
|
|
|
|
2013-11-17 23:08:34 +00:00
|
|
|
devtools_web_contents_->GetController().LoadURL(
|
2016-10-06 11:59:32 +00:00
|
|
|
GetDevToolsURL(can_dock_),
|
2013-11-17 23:08:34 +00:00
|
|
|
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_) {
|
2017-04-17 07:10:30 +00:00
|
|
|
frontend_loaded_ = false;
|
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
|
|
|
}
|
|
|
|
|
2017-01-10 11:13:16 +00:00
|
|
|
void InspectableWebContentsImpl::AttachTo(
|
|
|
|
scoped_refptr<content::DevToolsAgentHost> host) {
|
2015-05-18 13:56:03 +00:00
|
|
|
if (agent_host_.get())
|
|
|
|
Detach();
|
2017-01-12 04:06:25 +00:00
|
|
|
agent_host_ = std::move(host);
|
2017-01-10 11:13:16 +00:00
|
|
|
// Terminate existing debugging connections and start debugging.
|
|
|
|
agent_host_->ForceAttachClient(this);
|
2015-05-18 13:56:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void InspectableWebContentsImpl::Detach() {
|
2015-06-08 15:01:07 +00:00
|
|
|
if (agent_host_.get())
|
2016-09-06 08:22:52 +00:00
|
|
|
agent_host_->DetachClient(this);
|
2015-05-18 13:56:03 +00:00
|
|
|
agent_host_ = nullptr;
|
|
|
|
}
|
|
|
|
|
2017-03-23 22:47:30 +00:00
|
|
|
void InspectableWebContentsImpl::CallClientFunction(
|
|
|
|
const std::string& function_name,
|
|
|
|
const base::Value* arg1,
|
|
|
|
const base::Value* arg2,
|
|
|
|
const base::Value* arg3) {
|
2015-09-17 07:00:14 +00:00
|
|
|
if (!devtools_web_contents_)
|
|
|
|
return;
|
|
|
|
|
2015-06-05 03:03:47 +00:00
|
|
|
std::string javascript = function_name + "(";
|
|
|
|
if (arg1) {
|
|
|
|
std::string json;
|
2015-09-02 07:16:34 +00:00
|
|
|
base::JSONWriter::Write(*arg1, &json);
|
2015-06-05 03:03:47 +00:00
|
|
|
javascript.append(json);
|
|
|
|
if (arg2) {
|
2015-09-02 07:16:34 +00:00
|
|
|
base::JSONWriter::Write(*arg2, &json);
|
2015-06-05 03:03:47 +00:00
|
|
|
javascript.append(", ").append(json);
|
|
|
|
if (arg3) {
|
2015-09-02 07:16:34 +00:00
|
|
|
base::JSONWriter::Write(*arg3, &json);
|
2015-06-05 03:03:47 +00:00
|
|
|
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) {
|
|
|
|
base::DictionaryValue bounds_dict;
|
|
|
|
RectToDictionary(bounds, &bounds_dict);
|
2015-07-27 14:34:21 +00:00
|
|
|
pref_service_->Set(kDevToolsBoundsPref, bounds_dict);
|
2014-07-04 13:34:47 +00:00
|
|
|
devtools_bounds_ = bounds;
|
|
|
|
}
|
|
|
|
|
2015-07-27 14:34:21 +00:00
|
|
|
double InspectableWebContentsImpl::GetDevToolsZoomLevel() const {
|
|
|
|
return pref_service_->GetDouble(kDevToolsZoomPref);
|
|
|
|
}
|
|
|
|
|
|
|
|
void InspectableWebContentsImpl::UpdateDevToolsZoomLevel(double level) {
|
|
|
|
pref_service_->SetDouble(kDevToolsZoomPref, level);
|
|
|
|
}
|
|
|
|
|
2013-03-27 14:33:00 +00:00
|
|
|
void InspectableWebContentsImpl::ActivateWindow() {
|
2015-07-27 14:34:21 +00:00
|
|
|
// Set the zoom level.
|
|
|
|
SetZoomLevelForWebContents(GetDevToolsWebContents(),
|
|
|
|
GetDevToolsZoomLevel());
|
2013-03-27 14:33:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void InspectableWebContentsImpl::CloseWindow() {
|
2016-07-04 06:06:05 +00:00
|
|
|
GetDevToolsWebContents()->DispatchBeforeUnload();
|
2013-03-27 14:33:00 +00:00
|
|
|
}
|
|
|
|
|
2015-06-05 03:03:47 +00:00
|
|
|
void InspectableWebContentsImpl::LoadCompleted() {
|
2015-06-05 03:58:27 +00:00
|
|
|
frontend_loaded_ = true;
|
2015-06-05 04:10:01 +00:00
|
|
|
view_->ShowDevTools();
|
|
|
|
|
|
|
|
// If the devtools can dock, "SetIsDocked" will be called by devtools itself.
|
2016-10-06 11:59:32 +00:00
|
|
|
if (!can_dock_) {
|
2015-06-05 04:10:01 +00:00
|
|
|
SetIsDocked(DispatchCallback(), false);
|
2016-10-06 11:59:32 +00:00
|
|
|
} else {
|
2016-10-11 08:17:06 +00:00
|
|
|
if (dock_state_.empty()) {
|
|
|
|
const base::DictionaryValue* prefs = pref_service_->GetDictionary(
|
|
|
|
kDevToolsPreferences);
|
|
|
|
std::string current_dock_state;
|
|
|
|
prefs->GetString("currentDockState", ¤t_dock_state);
|
|
|
|
base::RemoveChars(current_dock_state, "\"", &dock_state_);
|
|
|
|
}
|
2016-10-06 11:59:32 +00:00
|
|
|
base::string16 javascript = base::UTF8ToUTF16(
|
2017-01-24 23:43:27 +00:00
|
|
|
"Components.dockController.setDockSide(\"" + dock_state_ + "\");");
|
2016-10-06 11:59:32 +00:00
|
|
|
devtools_web_contents_->GetMainFrame()->ExecuteJavaScript(javascript);
|
|
|
|
}
|
2016-05-12 13:46:13 +00:00
|
|
|
|
|
|
|
if (view_->GetDelegate())
|
|
|
|
view_->GetDelegate()->DevToolsOpened();
|
2015-06-05 03:03:47 +00:00
|
|
|
}
|
|
|
|
|
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) {
|
2015-08-07 09:00:49 +00:00
|
|
|
view_->SetTitle(base::UTF8ToUTF16(base::StringPrintf(kTitleFormat,
|
|
|
|
url.c_str())));
|
2015-06-05 03:03:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2017-03-23 22:47:30 +00:00
|
|
|
auto browser_context =
|
|
|
|
static_cast<BrowserContext*>(devtools_web_contents_->GetBrowserContext());
|
2015-06-05 03:20:20 +00:00
|
|
|
|
|
|
|
net::URLFetcher* fetcher =
|
2015-07-23 07:00:14 +00:00
|
|
|
(net::URLFetcher::Create(gurl, net::URLFetcher::GET, this)).release();
|
2015-06-05 03:20:20 +00:00
|
|
|
pending_requests_[fetcher] = callback;
|
|
|
|
fetcher->SetRequestContext(browser_context->url_request_context_getter());
|
|
|
|
fetcher->SetExtraRequestHeaders(headers);
|
2017-03-23 22:47:30 +00:00
|
|
|
fetcher->SaveResponseWithWriter(
|
|
|
|
std::unique_ptr<net::URLFetcherResponseWriter>(
|
|
|
|
new ResponseWriter(weak_factory_.GetWeakPtr(), stream_id)));
|
2015-06-05 03:20:20 +00:00
|
|
|
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() {
|
2016-03-15 02:23:40 +00:00
|
|
|
if (delegate_)
|
|
|
|
delegate_->DevToolsRequestFileSystems();
|
2013-03-27 14:33:00 +00:00
|
|
|
}
|
|
|
|
|
2016-03-15 02:23:40 +00:00
|
|
|
void InspectableWebContentsImpl::AddFileSystem(
|
|
|
|
const std::string& file_system_path) {
|
2015-06-04 16:51:23 +00:00
|
|
|
if (delegate_)
|
2016-03-15 02:23:40 +00:00
|
|
|
delegate_->DevToolsAddFileSystem(
|
|
|
|
base::FilePath::FromUTF8Unsafe(file_system_path));
|
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_)
|
2015-07-24 09:43:36 +00:00
|
|
|
delegate_->DevToolsRemoveFileSystem(
|
|
|
|
base::FilePath::FromUTF8Unsafe(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) {
|
2016-05-06 23:06:00 +00:00
|
|
|
if (delegate_)
|
|
|
|
delegate_->DevToolsIndexPath(request_id, file_system_path);
|
2013-10-07 19:29:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void InspectableWebContentsImpl::StopIndexing(int request_id) {
|
2016-05-06 23:06:00 +00:00
|
|
|
if (delegate_)
|
|
|
|
delegate_->DevToolsStopIndexing(request_id);
|
2013-10-07 19:29:17 +00:00
|
|
|
}
|
|
|
|
|
2013-11-17 23:08:34 +00:00
|
|
|
void InspectableWebContentsImpl::SearchInPath(
|
|
|
|
int request_id,
|
|
|
|
const std::string& file_system_path,
|
|
|
|
const std::string& query) {
|
2016-05-06 23:06:00 +00:00
|
|
|
if (delegate_)
|
|
|
|
delegate_->DevToolsSearchInPath(request_id, file_system_path, query);
|
2013-10-07 19:29:17 +00:00
|
|
|
}
|
|
|
|
|
2017-03-23 22:47:30 +00:00
|
|
|
void InspectableWebContentsImpl::SetWhitelistedShortcuts(
|
|
|
|
const std::string& message) {
|
2015-06-05 03:03:47 +00:00
|
|
|
}
|
|
|
|
|
2014-07-08 07:58:38 +00:00
|
|
|
void InspectableWebContentsImpl::ZoomIn() {
|
2015-07-27 14:34:21 +00:00
|
|
|
double new_level = GetNextZoomLevel(GetDevToolsZoomLevel(), false);
|
|
|
|
SetZoomLevelForWebContents(GetDevToolsWebContents(), new_level);
|
|
|
|
UpdateDevToolsZoomLevel(new_level);
|
2014-07-08 07:58:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void InspectableWebContentsImpl::ZoomOut() {
|
2015-07-27 14:34:21 +00:00
|
|
|
double new_level = GetNextZoomLevel(GetDevToolsZoomLevel(), true);
|
|
|
|
SetZoomLevelForWebContents(GetDevToolsWebContents(), new_level);
|
|
|
|
UpdateDevToolsZoomLevel(new_level);
|
2014-07-08 07:58:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void InspectableWebContentsImpl::ResetZoom() {
|
2015-06-05 06:33:37 +00:00
|
|
|
SetZoomLevelForWebContents(GetDevToolsWebContents(), 0.);
|
2015-07-27 14:34:21 +00:00
|
|
|
UpdateDevToolsZoomLevel(0.);
|
2014-07-08 07:58:38 +00:00
|
|
|
}
|
|
|
|
|
2015-06-05 03:03:47 +00:00
|
|
|
void InspectableWebContentsImpl::SetDevicesUpdatesEnabled(bool enabled) {
|
|
|
|
}
|
|
|
|
|
2016-03-08 14:28:28 +00:00
|
|
|
void InspectableWebContentsImpl::DispatchProtocolMessageFromDevToolsFrontend(
|
|
|
|
const std::string& message) {
|
2016-04-12 07:35:35 +00:00
|
|
|
// If the devtools wants to reload the page, hijack the message and handle it
|
|
|
|
// to the delegate.
|
|
|
|
if (base::MatchPattern(message, "{\"id\":*,"
|
|
|
|
"\"method\":\"Page.reload\","
|
|
|
|
"\"params\":*}")) {
|
|
|
|
if (delegate_)
|
|
|
|
delegate_->DevToolsReloadPage();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-06-05 03:03:47 +00:00
|
|
|
if (agent_host_.get())
|
2016-09-06 08:22:52 +00:00
|
|
|
agent_host_->DispatchProtocolMessage(this, message);
|
2015-06-05 03:03:47 +00:00
|
|
|
}
|
|
|
|
|
2017-03-23 22:47:30 +00:00
|
|
|
void InspectableWebContentsImpl::SendJsonRequest(
|
|
|
|
const DispatchCallback& callback,
|
|
|
|
const std::string& browser_id,
|
|
|
|
const std::string& url) {
|
2015-06-05 03:03:47 +00:00
|
|
|
callback.Run(nullptr);
|
|
|
|
}
|
|
|
|
|
2015-08-06 05:39:23 +00:00
|
|
|
void InspectableWebContentsImpl::GetPreferences(
|
|
|
|
const DispatchCallback& callback) {
|
|
|
|
const base::DictionaryValue* prefs = pref_service_->GetDictionary(
|
|
|
|
kDevToolsPreferences);
|
|
|
|
callback.Run(prefs);
|
|
|
|
}
|
|
|
|
|
|
|
|
void InspectableWebContentsImpl::SetPreference(const std::string& name,
|
|
|
|
const std::string& value) {
|
|
|
|
DictionaryPrefUpdate update(pref_service_, kDevToolsPreferences);
|
|
|
|
update.Get()->SetStringWithoutPathExpansion(name, value);
|
|
|
|
}
|
|
|
|
|
|
|
|
void InspectableWebContentsImpl::RemovePreference(const std::string& name) {
|
|
|
|
DictionaryPrefUpdate update(pref_service_, kDevToolsPreferences);
|
|
|
|
update.Get()->RemoveWithoutPathExpansion(name, nullptr);
|
|
|
|
}
|
|
|
|
|
|
|
|
void InspectableWebContentsImpl::ClearPreferences() {
|
|
|
|
DictionaryPrefUpdate update(pref_service_, kDevToolsPreferences);
|
|
|
|
update.Get()->Clear();
|
|
|
|
}
|
|
|
|
|
2017-03-23 22:47:30 +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;
|
|
|
|
|
2015-06-05 04:24:48 +00:00
|
|
|
base::DictionaryValue* dict = nullptr;
|
2016-05-23 01:59:07 +00:00
|
|
|
std::unique_ptr<base::Value> parsed_message(base::JSONReader::Read(message));
|
2015-06-05 03:03:47 +00:00
|
|
|
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-12-05 22:31:02 +00:00
|
|
|
void InspectableWebContentsImpl::DispatchProtocolMessage(
|
|
|
|
content::DevToolsAgentHost* agent_host, const std::string& message) {
|
2015-06-05 03:58:27 +00:00
|
|
|
if (!frontend_loaded_)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (message.length() < kMaxMessageChunkSize) {
|
|
|
|
base::string16 javascript = base::UTF8ToUTF16(
|
|
|
|
"DevToolsAPI.dispatchMessage(" + message + ");");
|
|
|
|
devtools_web_contents_->GetMainFrame()->ExecuteJavaScript(javascript);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-04-04 04:43:49 +00:00
|
|
|
base::Value total_size(static_cast<int>(message.length()));
|
2015-06-05 03:58:27 +00:00
|
|
|
for (size_t pos = 0; pos < message.length(); pos += kMaxMessageChunkSize) {
|
|
|
|
base::StringValue message_value(message.substr(pos, kMaxMessageChunkSize));
|
|
|
|
CallClientFunction("DevToolsAPI.dispatchMessageChunk",
|
2015-06-05 04:24:48 +00:00
|
|
|
&message_value, pos ? nullptr : &total_size, nullptr);
|
2015-06-05 03:58:27 +00:00
|
|
|
}
|
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
|
|
|
}
|
|
|
|
|
2016-03-08 06:18:16 +00:00
|
|
|
void InspectableWebContentsImpl::RenderFrameHostChanged(
|
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;
|
2016-03-08 14:28:28 +00:00
|
|
|
frontend_host_.reset(content::DevToolsFrontendHost::Create(
|
2016-03-09 09:47:11 +00:00
|
|
|
new_host,
|
2016-03-08 14:28:28 +00:00
|
|
|
base::Bind(&InspectableWebContentsImpl::HandleMessageFromDevToolsFrontend,
|
|
|
|
base::Unretained(this))));
|
2014-10-11 11:00:30 +00:00
|
|
|
}
|
|
|
|
|
2014-07-27 10:27:19 +00:00
|
|
|
void InspectableWebContentsImpl::WebContentsDestroyed() {
|
2015-06-05 04:24:48 +00:00
|
|
|
frontend_loaded_ = false;
|
2017-03-20 19:22:46 +00:00
|
|
|
Observe(nullptr);
|
2015-06-05 03:58:27 +00:00
|
|
|
Detach();
|
2015-06-05 03:20:20 +00:00
|
|
|
|
|
|
|
for (const auto& pair : pending_requests_)
|
|
|
|
delete pair.first;
|
2016-05-12 13:46:13 +00:00
|
|
|
|
|
|
|
if (view_ && view_->GetDelegate())
|
|
|
|
view_->GetDelegate()->DevToolsClosed();
|
2013-03-27 14:33:00 +00:00
|
|
|
}
|
|
|
|
|
2017-01-23 06:27:57 +00:00
|
|
|
bool InspectableWebContentsImpl::DidAddMessageToConsole(
|
2014-08-28 04:53:35 +00:00
|
|
|
content::WebContents* source,
|
2016-03-08 05:38:56 +00:00
|
|
|
int32_t level,
|
2014-08-28 04:53:35 +00:00
|
|
|
const base::string16& message,
|
2016-03-08 05:38:56 +00:00
|
|
|
int32_t line_no,
|
2014-08-28 04:53:35 +00:00
|
|
|
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,
|
2017-04-04 04:43:49 +00:00
|
|
|
content::SiteInstance* source_site_instance,
|
2016-03-08 06:18:16 +00:00
|
|
|
int32_t route_id,
|
|
|
|
int32_t main_frame_route_id,
|
|
|
|
int32_t main_frame_widget_route_id,
|
2017-04-04 04:26:50 +00:00
|
|
|
content::mojom::WindowContainerType window_container_type,
|
2017-04-04 04:43:49 +00:00
|
|
|
const GURL& opener_url,
|
2015-09-02 07:16:34 +00:00
|
|
|
const std::string& frame_name,
|
2014-10-27 08:42:54 +00:00
|
|
|
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) {
|
2017-03-20 19:22:46 +00:00
|
|
|
// This is where the devtools closes itself (by clicking the x button).
|
2014-07-13 02:08:28 +00:00
|
|
|
CloseDevTools();
|
|
|
|
}
|
|
|
|
|
2016-07-22 13:49:42 +00:00
|
|
|
content::ColorChooser* InspectableWebContentsImpl::OpenColorChooser(
|
|
|
|
content::WebContents* source,
|
|
|
|
SkColor color,
|
|
|
|
const std::vector<content::ColorSuggestion>& suggestions) {
|
|
|
|
auto delegate = web_contents_->GetDelegate();
|
|
|
|
if (delegate)
|
|
|
|
return delegate->OpenColorChooser(source, color, suggestions);
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
void InspectableWebContentsImpl::RunFileChooser(
|
2016-09-06 08:22:52 +00:00
|
|
|
content::RenderFrameHost* render_frame_host,
|
2016-07-22 13:49:42 +00:00
|
|
|
const content::FileChooserParams& params) {
|
|
|
|
auto delegate = web_contents_->GetDelegate();
|
|
|
|
if (delegate)
|
2016-09-06 08:22:52 +00:00
|
|
|
delegate->RunFileChooser(render_frame_host, params);
|
2016-07-22 13:49:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void InspectableWebContentsImpl::EnumerateDirectory(
|
|
|
|
content::WebContents* source,
|
|
|
|
int request_id,
|
|
|
|
const base::FilePath& path) {
|
|
|
|
auto delegate = web_contents_->GetDelegate();
|
|
|
|
if (delegate)
|
|
|
|
delegate->EnumerateDirectory(source, request_id, path);
|
|
|
|
}
|
|
|
|
|
2015-07-23 07:00:14 +00:00
|
|
|
void InspectableWebContentsImpl::OnWebContentsFocused() {
|
2015-09-15 03:24:35 +00:00
|
|
|
#if defined(TOOLKIT_VIEWS)
|
2015-06-25 04:29:34 +00:00
|
|
|
if (view_->GetDelegate())
|
|
|
|
view_->GetDelegate()->DevToolsFocused();
|
2015-09-15 03:24:35 +00:00
|
|
|
#endif
|
2015-06-05 03:03:47 +00:00
|
|
|
}
|
|
|
|
|
2016-03-09 05:55:46 +00:00
|
|
|
void InspectableWebContentsImpl::DidStartNavigationToPendingEntry(
|
|
|
|
const GURL& url,
|
2017-01-23 06:27:57 +00:00
|
|
|
content::ReloadType reload_type) {
|
2017-03-23 22:47:30 +00:00
|
|
|
frontend_host_.reset(content::DevToolsFrontendHost::Create(
|
|
|
|
web_contents()->GetMainFrame(),
|
|
|
|
base::Bind(&InspectableWebContentsImpl::HandleMessageFromDevToolsFrontend,
|
|
|
|
base::Unretained(this))));
|
2016-03-09 05:55:46 +00:00
|
|
|
}
|
|
|
|
|
2017-03-23 22:47:30 +00:00
|
|
|
void InspectableWebContentsImpl::OnURLFetchComplete(
|
|
|
|
const net::URLFetcher* source) {
|
2015-06-05 03:20:20 +00:00
|
|
|
DCHECK(source);
|
2016-07-10 11:12:33 +00:00
|
|
|
auto it = pending_requests_.find(source);
|
2015-06-05 03:20:20 +00:00
|
|
|
DCHECK(it != pending_requests_.end());
|
|
|
|
|
|
|
|
base::DictionaryValue response;
|
2016-07-10 11:12:33 +00:00
|
|
|
auto* headers = new base::DictionaryValue();
|
2015-06-05 03:20:20 +00:00
|
|
|
net::HttpResponseHeaders* rh = source->GetResponseHeaders();
|
|
|
|
response.SetInteger("statusCode", rh ? rh->response_code() : 200);
|
|
|
|
response.Set("headers", headers);
|
|
|
|
|
2016-04-27 16:01:48 +00:00
|
|
|
size_t iterator = 0;
|
2015-06-05 03:20:20 +00:00
|
|
|
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) {
|
2017-04-04 04:43:49 +00:00
|
|
|
base::Value id_value(request_id);
|
2015-06-05 03:03:47 +00:00
|
|
|
CallClientFunction("DevToolsAPI.embedderMessageAck",
|
|
|
|
&id_value, arg, nullptr);
|
|
|
|
}
|
|
|
|
|
2013-11-17 23:08:34 +00:00
|
|
|
} // namespace brightray
|