mirror of
https://github.com/flutter/flutter.git
synced 2026-02-20 02:29:02 +08:00
Add inspect command to skydb
This CL adds an "inspect" command to skydb that injects the inspector module into the page and prints some instructions for opening the inspector. R=eseidel@chromium.org Review URL: https://codereview.chromium.org/690433004
This commit is contained in:
parent
e061930d2b
commit
74db9da5e1
@ -128,6 +128,9 @@ public:
|
||||
|
||||
virtual WebFrame* mainFrame() = 0;
|
||||
|
||||
virtual void injectModule(const WebString& path) = 0;
|
||||
|
||||
|
||||
// Focus ---------------------------------------------------------------
|
||||
|
||||
virtual WebFrame* focusedFrame() = 0;
|
||||
|
||||
@ -50,6 +50,7 @@
|
||||
#include "core/frame/FrameView.h"
|
||||
#include "core/frame/LocalFrame.h"
|
||||
#include "core/frame/Settings.h"
|
||||
#include "core/html/HTMLLinkElement.h"
|
||||
#include "core/html/HTMLMediaElement.h"
|
||||
#include "core/html/ime/InputMethodContext.h"
|
||||
#include "core/loader/FrameLoader.h"
|
||||
@ -1659,6 +1660,17 @@ WebFrame* WebViewImpl::focusedFrame()
|
||||
return WebFrame::fromFrame(focusedCoreFrame());
|
||||
}
|
||||
|
||||
void WebViewImpl::injectModule(const WebString& path)
|
||||
{
|
||||
RefPtr<Document> document = m_page->mainFrame()->document();
|
||||
RefPtr<HTMLLinkElement> link = HTMLLinkElement::create(*document, false);
|
||||
link->setAttribute(HTMLNames::relAttr, "import");
|
||||
link->setAttribute(HTMLNames::hrefAttr, path);
|
||||
if (!document->documentElement())
|
||||
return;
|
||||
document->documentElement()->appendChild(link.release());
|
||||
}
|
||||
|
||||
void WebViewImpl::setFocusedFrame(WebFrame* frame)
|
||||
{
|
||||
if (!frame) {
|
||||
|
||||
@ -118,6 +118,7 @@ public:
|
||||
|
||||
// WebView methods:
|
||||
virtual void setMainFrame(WebFrame*) override;
|
||||
virtual void injectModule(const WebString&) override;
|
||||
virtual void setSpellCheckClient(WebSpellCheckClient*) override;
|
||||
virtual WebSettings* settings() override;
|
||||
virtual WebString pageEncoding() const override;
|
||||
|
||||
@ -16,6 +16,7 @@
|
||||
#include "mojo/services/window_manager/window_manager_delegate.h"
|
||||
#include "sky/tools/debugger/focus_rules.h"
|
||||
#include "sky/tools/debugger/debugger.mojom.h"
|
||||
#include "sky/viewer/services/inspector.mojom.h"
|
||||
|
||||
namespace sky {
|
||||
|
||||
@ -58,7 +59,7 @@ class SkyDebugger : public mojo::ApplicationDelegate,
|
||||
mojo::ViewManager* view_manager,
|
||||
mojo::View* root,
|
||||
mojo::ServiceProviderImpl* exported_services,
|
||||
scoped_ptr<mojo::ServiceProvider> remote_service_provider) override {
|
||||
scoped_ptr<mojo::ServiceProvider> imported_services) override {
|
||||
view_manager_ = view_manager;
|
||||
|
||||
root_ = root;
|
||||
@ -104,10 +105,19 @@ class SkyDebugger : public mojo::ApplicationDelegate,
|
||||
// We can get Navigate commands before we've actually been
|
||||
// embedded into the view and content_ created.
|
||||
// Just save the last one.
|
||||
if (content_)
|
||||
content_->Embed(url);
|
||||
else
|
||||
if (content_) {
|
||||
scoped_ptr<mojo::ServiceProviderImpl> exported_services(
|
||||
new mojo::ServiceProviderImpl());
|
||||
viewer_services_ = content_->Embed(url, exported_services.Pass());
|
||||
} else {
|
||||
pending_url_ = url;
|
||||
}
|
||||
}
|
||||
|
||||
virtual void InjectInspector() override {
|
||||
InspectorServicePtr inspector_service;
|
||||
mojo::ConnectToService(viewer_services_.get(), &inspector_service);
|
||||
inspector_service->Inject();
|
||||
}
|
||||
|
||||
scoped_ptr<mojo::WindowManagerApp> window_manager_app_;
|
||||
@ -117,6 +127,8 @@ class SkyDebugger : public mojo::ApplicationDelegate,
|
||||
mojo::View* content_;
|
||||
std::string pending_url_;
|
||||
|
||||
scoped_ptr<mojo::ServiceProvider> viewer_services_;
|
||||
|
||||
DISALLOW_COPY_AND_ASSIGN(SkyDebugger);
|
||||
};
|
||||
|
||||
|
||||
@ -6,6 +6,7 @@ module sky {
|
||||
|
||||
interface Debugger {
|
||||
NavigateToURL(string url);
|
||||
InjectInspector();
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@ -73,6 +73,10 @@ class Prompt : public mojo::ApplicationDelegate {
|
||||
Reload();
|
||||
return true;
|
||||
}
|
||||
if (command == "inspect") {
|
||||
Inspect();
|
||||
return true;
|
||||
}
|
||||
if (command.size() == 1) {
|
||||
char c = command[0];
|
||||
if (c == 'h')
|
||||
@ -111,16 +115,25 @@ class Prompt : public mojo::ApplicationDelegate {
|
||||
<< "Sky Debugger" << std::endl
|
||||
<< "============" << std::endl
|
||||
<< "Type a URL to load in the debugger, enter to reload." << std::endl
|
||||
<< "Commands: help -- Help" << std::endl
|
||||
<< " trace -- Capture a trace" << std::endl
|
||||
<< " reload -- Reload the current page" << std::endl
|
||||
<< " q -- Quit" << std::endl;
|
||||
<< "Commands: help -- Help" << std::endl
|
||||
<< " trace -- Capture a trace" << std::endl
|
||||
<< " reload -- Reload the current page" << std::endl
|
||||
<< " inspect -- Inspect the current page" << std::endl
|
||||
<< " q -- Quit" << std::endl;
|
||||
}
|
||||
|
||||
void Reload() {
|
||||
debugger_->NavigateToURL(url_);
|
||||
}
|
||||
|
||||
void Inspect() {
|
||||
debugger_->InjectInspector();
|
||||
std::cout
|
||||
<< "Open the following URL in Chrome:" << std::endl
|
||||
<< "chrome-devtools://devtools/bundled/devtools.html?ws=localhost:9898"
|
||||
<< std::endl;
|
||||
}
|
||||
|
||||
void Quit() {
|
||||
std::cout << "quitting" << std::endl;
|
||||
exit(0);
|
||||
|
||||
@ -34,6 +34,8 @@ shared_library("viewer") {
|
||||
"script/script_runner.h",
|
||||
"services/tracing_impl.cc",
|
||||
"services/tracing_impl.h",
|
||||
"services/inspector_impl.cc",
|
||||
"services/inspector_impl.h",
|
||||
"viewer.cc",
|
||||
]
|
||||
|
||||
@ -78,6 +80,7 @@ mojom("bindings") {
|
||||
sources = [
|
||||
"test_observer.mojom",
|
||||
"services/tracing.mojom",
|
||||
"services/inspector.mojom",
|
||||
]
|
||||
}
|
||||
|
||||
|
||||
@ -1,5 +1,6 @@
|
||||
include_rules = [
|
||||
"+cc",
|
||||
"+mojo/public",
|
||||
"+mojo/application",
|
||||
"+mojo/cc",
|
||||
"+mojo/converters/geometry",
|
||||
|
||||
@ -75,6 +75,7 @@ DocumentView::DocumentView(
|
||||
web_view_(NULL),
|
||||
root_(NULL),
|
||||
view_manager_client_factory_(shell, this),
|
||||
inspector_service_factory_(this),
|
||||
compositor_thread_(compositor_thread),
|
||||
weak_factory_(this) {
|
||||
mojo::ServiceProviderImpl* exported_services = new mojo::ServiceProviderImpl();
|
||||
@ -102,6 +103,7 @@ void DocumentView::OnEmbed(
|
||||
root_ = root;
|
||||
imported_services_ = imported_services.Pass();
|
||||
navigator_host_.set_service_provider(imported_services_.get());
|
||||
exported_services->AddService(&inspector_service_factory_);
|
||||
|
||||
Load(response_.Pass());
|
||||
|
||||
|
||||
@ -16,6 +16,7 @@
|
||||
#include "mojo/services/public/interfaces/network/url_loader.mojom.h"
|
||||
#include "sky/engine/public/web/WebFrameClient.h"
|
||||
#include "sky/engine/public/web/WebViewClient.h"
|
||||
#include "sky/viewer/services/inspector_impl.h"
|
||||
|
||||
namespace base {
|
||||
class MessageLoopProxy;
|
||||
@ -98,6 +99,7 @@ class DocumentView : public blink::WebViewClient,
|
||||
blink::WebView* web_view_;
|
||||
mojo::View* root_;
|
||||
mojo::ViewManagerClientFactory view_manager_client_factory_;
|
||||
InspectorServiceFactory inspector_service_factory_;
|
||||
scoped_ptr<WebLayerTreeViewImpl> web_layer_tree_view_impl_;
|
||||
scoped_refptr<base::MessageLoopProxy> compositor_thread_;
|
||||
scoped_ptr<ScriptRunner> script_runner_;
|
||||
|
||||
11
viewer/services/inspector.mojom
Normal file
11
viewer/services/inspector.mojom
Normal file
@ -0,0 +1,11 @@
|
||||
// Copyright 2014 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.
|
||||
|
||||
module sky {
|
||||
|
||||
interface InspectorService {
|
||||
Inject();
|
||||
};
|
||||
|
||||
}
|
||||
28
viewer/services/inspector_impl.cc
Normal file
28
viewer/services/inspector_impl.cc
Normal file
@ -0,0 +1,28 @@
|
||||
// Copyright 2014 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 "sky/viewer/services/inspector_impl.h"
|
||||
|
||||
#include "sky/engine/public/web/WebDocument.h"
|
||||
#include "sky/engine/public/web/WebElement.h"
|
||||
#include "sky/engine/public/web/WebFrame.h"
|
||||
#include "sky/engine/public/web/WebView.h"
|
||||
#include "sky/viewer/document_view.h"
|
||||
|
||||
namespace sky {
|
||||
|
||||
InspectorServiceImpl::InspectorServiceImpl(DocumentView* view)
|
||||
: view_(view->GetWeakPtr()) {
|
||||
}
|
||||
|
||||
InspectorServiceImpl::~InspectorServiceImpl() {
|
||||
}
|
||||
|
||||
void InspectorServiceImpl::Inject() {
|
||||
if (!view_)
|
||||
return;
|
||||
view_->web_view()->injectModule("/sky/framework/inspector/inspector.sky");
|
||||
}
|
||||
|
||||
} // namespace sky
|
||||
35
viewer/services/inspector_impl.h
Normal file
35
viewer/services/inspector_impl.h
Normal file
@ -0,0 +1,35 @@
|
||||
// Copyright 2014 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.
|
||||
|
||||
#ifndef SKY_VIEWER_SERVICES_INSPECTOR_IMPL_H_
|
||||
#define SKY_VIEWER_SERVICES_INSPECTOR_IMPL_H_
|
||||
|
||||
#include "base/basictypes.h"
|
||||
#include "base/memory/weak_ptr.h"
|
||||
#include "mojo/public/cpp/application/interface_factory_impl.h"
|
||||
#include "sky/viewer/services/inspector.mojom.h"
|
||||
|
||||
namespace sky {
|
||||
class DocumentView;
|
||||
|
||||
class InspectorServiceImpl : public mojo::InterfaceImpl<InspectorService> {
|
||||
public:
|
||||
explicit InspectorServiceImpl(DocumentView*);
|
||||
virtual ~InspectorServiceImpl();
|
||||
|
||||
private:
|
||||
// Overridden from InspectorService:
|
||||
void Inject() override;
|
||||
|
||||
base::WeakPtr<DocumentView> view_;
|
||||
|
||||
DISALLOW_COPY_AND_ASSIGN(InspectorServiceImpl);
|
||||
};
|
||||
|
||||
typedef mojo::InterfaceFactoryImplWithContext<
|
||||
InspectorServiceImpl, DocumentView> InspectorServiceFactory;
|
||||
|
||||
} // namespace sky
|
||||
|
||||
#endif // SKY_VIEWER_SERVICES_INSPECTOR_IMPL_H_
|
||||
Loading…
x
Reference in New Issue
Block a user