From 826956d14dc82a38cd039ccecdce75a86ca515fa Mon Sep 17 00:00:00 2001 From: Adam Barth Date: Tue, 30 Jun 2015 14:48:32 -0700 Subject: [PATCH] Remove the ability to load ".sky" files Please use ".dart" files instead. R=ianh@google.com Review URL: https://codereview.chromium.org/1222483002. --- engine/public/web/WebView.h | 3 - engine/web/WebViewImpl.cpp | 16 +--- shell/ui/engine.cc | 105 +----------------------- shell/ui/engine.h | 19 ----- viewer/document_view.cc | 158 ++---------------------------------- viewer/document_view.h | 28 ------- viewer/internals.cc | 12 +-- 7 files changed, 11 insertions(+), 330 deletions(-) diff --git a/engine/public/web/WebView.h b/engine/public/web/WebView.h index 842015fa8e8..4ce12ad7b74 100644 --- a/engine/public/web/WebView.h +++ b/engine/public/web/WebView.h @@ -50,9 +50,6 @@ struct WebPoint; class WebView : public WebWidget { public: - // I've added this here so that it dies when WebView does. :) - static bool shouldUseWebView(const GURL& url); - // Initialization ------------------------------------------------------ // Creates a WebView that is NOT yet initialized. You will need to diff --git a/engine/web/WebViewImpl.cpp b/engine/web/WebViewImpl.cpp index 75e8929d051..861972b73a5 100644 --- a/engine/web/WebViewImpl.cpp +++ b/engine/web/WebViewImpl.cpp @@ -92,23 +92,9 @@ namespace blink { // WebView ---------------------------------------------------------------- -bool WebView::shouldUseWebView(const GURL& url) -{ - std::string filename = url.ExtractFileName(); - int hashStart = filename.find('#'); - if (hashStart != -1) - filename.resize(hashStart); - int queryStart = filename.find('?'); - if (queryStart != -1) - filename.resize(queryStart); - // For now .dart indicates we should use SkyView. Eventually we'll - // use SkyView for all urls regardless of file extension. - return !EndsWith(filename, ".dart", false) - && !EndsWith(filename, ".snapshot", false); -} - WebView* WebView::create(WebViewClient* client) { + CRASH(); // WebView is deprecated. Please use SkyView. // Pass the WebViewImpl's self-reference to the caller. return WebViewImpl::create(client); } diff --git a/shell/ui/engine.cc b/shell/ui/engine.cc index fdefa53b440..7d8bb3419dc 100644 --- a/shell/ui/engine.cc +++ b/shell/ui/engine.cc @@ -14,9 +14,6 @@ #include "sky/engine/public/platform/sky_display_metrics.h" #include "sky/engine/public/platform/sky_display_metrics.h" #include "sky/engine/public/web/Sky.h" -#include "sky/engine/public/web/WebLocalFrame.h" -#include "sky/engine/public/web/WebSettings.h" -#include "sky/engine/public/web/WebView.h" #include "sky/services/platform/platform_impl.h" #include "sky/shell/dart/dart_library_provider_files.h" #include "sky/shell/dart/dart_library_provider_network.h" @@ -43,12 +40,6 @@ mojo::ScopedDataPipeConsumerHandle Fetch(const base::FilePath& path) { return pipe.consumer_handle.Pass(); } -void ConfigureSettings(blink::WebSettings* settings) { - settings->setDefaultFixedFontSize(13); - settings->setDefaultFontSize(16); - settings->setLoadsImagesAutomatically(true); -} - PlatformImpl* g_platform_impl = nullptr; } @@ -62,15 +53,12 @@ Engine::Config::~Config() { Engine::Engine(const Config& config) : config_(config), animator_(new Animator(config, this)), - web_view_(nullptr), device_pixel_ratio_(1.0f), viewport_observer_binding_(this), weak_factory_(this) { } Engine::~Engine() { - if (web_view_) - web_view_->close(); } base::WeakPtr Engine::GetWeakPtr() { @@ -95,15 +83,6 @@ void Engine::BeginFrame(base::TimeTicks frame_time) { if (sky_view_) sky_view_->BeginFrame(frame_time); - - if (web_view_) { - double frame_time_sec = (frame_time - base::TimeTicks()).InSecondsF(); - double deadline_sec = frame_time_sec; - double interval_sec = 1.0 / 60; - blink::WebBeginFrameArgs args(frame_time_sec, deadline_sec, interval_sec); - web_view_->beginFrame(args); - web_view_->layout(); - } } skia::RefPtr Engine::Paint() { @@ -123,9 +102,6 @@ skia::RefPtr Engine::Paint() { canvas->drawPicture(picture.get()); } - if (web_view_) - web_view_->paint(canvas.get(), blink::WebRect(gfx::Rect(physical_size_))); - return skia::AdoptRef(recorder.endRecordingAsPicture()); } @@ -139,9 +115,7 @@ void Engine::OnAcceleratedWidgetAvailable(gfx::AcceleratedWidget widget) { FROM_HERE, base::Bind(&GPUDelegate::OnAcceleratedWidgetAvailable, config_.gpu_delegate, widget)); if (sky_view_) - scheduleVisualUpdate(); - if (web_view_) - scheduleVisualUpdate(); + ScheduleFrame(); } void Engine::OnOutputSurfaceDestroyed() { @@ -157,9 +131,6 @@ void Engine::OnViewportMetricsChanged(int width, int height, if (sky_view_) UpdateSkyViewSize(); - - if (web_view_) - UpdateWebViewSize(); } void Engine::UpdateSkyViewSize() { @@ -170,24 +141,6 @@ void Engine::UpdateSkyViewSize() { sky_view_->SetDisplayMetrics(metrics); } -void Engine::UpdateWebViewSize() { - CHECK(web_view_); - web_view_->setDeviceScaleFactor(device_pixel_ratio_); - gfx::SizeF size = gfx::ScaleSize(physical_size_, 1 / device_pixel_ratio_); - // FIXME: We should be able to set the size of the WebView in floating point - // because its in logical pixels. - web_view_->resize(blink::WebSize(size.width(), size.height())); -} - -// TODO(eseidel): This is likely not needed anymore. -blink::WebScreenInfo Engine::screenInfo() { - blink::WebScreenInfo screen; - screen.rect = blink::WebRect(gfx::Rect(physical_size_)); - screen.availableRect = screen.rect; - screen.deviceScaleFactor = device_pixel_ratio_; - return screen; -} - void Engine::OnInputEvent(InputEventPtr event) { TRACE_EVENT0("sky", "Engine::OnInputEvent"); scoped_ptr web_event = @@ -196,19 +149,9 @@ void Engine::OnInputEvent(InputEventPtr event) { return; if (sky_view_) sky_view_->HandleInputEvent(*web_event); - if (web_view_) - web_view_->handleInputEvent(*web_event); -} - -void Engine::CloseWebViewIfNeeded() { - if (web_view_) { - web_view_->close(); - web_view_ = nullptr; - } } void Engine::RunFromLibrary(const mojo::String& name) { - CloseWebViewIfNeeded(); sky_view_ = blink::SkyView::Create(this); sky_view_->RunFromLibrary(blink::WebString::fromUTF8(name), dart_library_provider_.get()); @@ -216,10 +159,6 @@ void Engine::RunFromLibrary(const mojo::String& name) { } void Engine::RunFromNetwork(const mojo::String& url) { - if (blink::WebView::shouldUseWebView(GURL(url))) { - LoadUsingWebView(url); - return; - } dart_library_provider_.reset( new DartLibraryProviderNetwork(g_platform_impl->networkService())); RunFromLibrary(url); @@ -233,50 +172,12 @@ void Engine::RunFromFile(const mojo::String& main, } void Engine::RunFromSnapshot(const mojo::String& path) { - CloseWebViewIfNeeded(); sky_view_ = blink::SkyView::Create(this); sky_view_->RunFromSnapshot(blink::WebString::fromUTF8(path), Fetch(base::FilePath(path))); UpdateSkyViewSize(); } -void Engine::LoadUsingWebView(const mojo::String& mojo_url) { - GURL url(mojo_url); - DCHECK(blink::WebView::shouldUseWebView(url)); - - if (sky_view_) - sky_view_ = nullptr; - - LOG(WARNING) << ".sky support is deprecated, please use .dart for main()"; - - // Something bad happens if you try to call WebView::close and replace - // the webview. So for now we just load into the existing one. :/ - if (!web_view_) - web_view_ = blink::WebView::create(this); - ConfigureSettings(web_view_->settings()); - web_view_->setMainFrame(blink::WebLocalFrame::create(this)); - UpdateWebViewSize(); - web_view_->mainFrame()->load(url); -} - -void Engine::frameDetached(blink::WebFrame* frame) { - // |frame| is invalid after here. - frame->close(); -} - -void Engine::initializeLayerTreeView() { -} - -void Engine::scheduleVisualUpdate() { - animator_->RequestFrame(); -} - -void Engine::didCreateIsolate(blink::WebLocalFrame* frame, - Dart_Isolate isolate) { - Internals::Create(isolate, - CreateServiceProvider(config_.service_provider_context)); -} - void Engine::DidCreateIsolate(Dart_Isolate isolate) { Internals::Create(isolate, CreateServiceProvider(config_.service_provider_context)); @@ -286,10 +187,6 @@ void Engine::ScheduleFrame() { animator_->RequestFrame(); } -blink::ServiceProvider* Engine::services() { - return this; -} - mojo::NavigatorHost* Engine::NavigatorHost() { return this; } diff --git a/shell/ui/engine.h b/shell/ui/engine.h index a4c50414633..4cc333022b9 100644 --- a/shell/ui/engine.h +++ b/shell/ui/engine.h @@ -17,8 +17,6 @@ #include "sky/engine/public/platform/ServiceProvider.h" #include "sky/engine/public/sky/sky_view.h" #include "sky/engine/public/sky/sky_view_client.h" -#include "sky/engine/public/web/WebFrameClient.h" -#include "sky/engine/public/web/WebViewClient.h" #include "sky/shell/gpu_delegate.h" #include "sky/shell/ui_delegate.h" #include "sky/shell/service_provider.h" @@ -34,8 +32,6 @@ class Engine : public UIDelegate, public ViewportObserver, public blink::ServiceProvider, public mojo::NavigatorHost, - public blink::WebFrameClient, - public blink::WebViewClient, public blink::SkyViewClient { public: struct Config { @@ -75,17 +71,6 @@ class Engine : public UIDelegate, const mojo::String& package_root) override; void RunFromSnapshot(const mojo::String& path) override; - // WebViewClient methods: - void frameDetached(blink::WebFrame*) override; - void initializeLayerTreeView() override; - void scheduleVisualUpdate() override; - blink::WebScreenInfo screenInfo() override; - blink::ServiceProvider* services() override; - - // WebFrameClient methods: - void didCreateIsolate(blink::WebLocalFrame* frame, - Dart_Isolate isolate) override; - // SkyViewClient methods: void ScheduleFrame() override; void DidCreateIsolate(Dart_Isolate isolate) override; @@ -100,18 +85,14 @@ class Engine : public UIDelegate, void RequestNavigateHistory(int32_t delta) override; void RunFromLibrary(const mojo::String& name); - void CloseWebViewIfNeeded(); - void LoadUsingWebView(const mojo::String& mojo_url); void UpdateSkyViewSize(); - void UpdateWebViewSize(); Config config_; scoped_ptr animator_; scoped_ptr dart_library_provider_; std::unique_ptr sky_view_; - blink::WebView* web_view_; float device_pixel_ratio_; gfx::Size physical_size_; diff --git a/viewer/document_view.cc b/viewer/document_view.cc index 8ae022c0561..17801e2d992 100644 --- a/viewer/document_view.cc +++ b/viewer/document_view.cc @@ -23,13 +23,6 @@ #include "sky/engine/public/platform/WebInputEvent.h" #include "sky/engine/public/platform/WebScreenInfo.h" #include "sky/engine/public/web/Sky.h" -#include "sky/engine/public/web/WebConsoleMessage.h" -#include "sky/engine/public/web/WebDocument.h" -#include "sky/engine/public/web/WebElement.h" -#include "sky/engine/public/web/WebLocalFrame.h" -#include "sky/engine/public/web/WebScriptSource.h" -#include "sky/engine/public/web/WebSettings.h" -#include "sky/engine/public/web/WebView.h" #include "sky/services/platform/url_request_types.h" #include "sky/viewer/compositor/layer.h" #include "sky/viewer/compositor/layer_host.h" @@ -47,27 +40,6 @@ namespace sky { namespace { -void ConfigureSettings(blink::WebSettings* settings) { - settings->setDefaultFixedFontSize(13); - settings->setDefaultFontSize(16); - settings->setLoadsImagesAutomatically(true); -} - -mojo::Target WebNavigationPolicyToNavigationTarget( - blink::WebNavigationPolicy policy) { - switch (policy) { - case blink::WebNavigationPolicyCurrentTab: - return mojo::TARGET_SOURCE_NODE; - case blink::WebNavigationPolicyNewBackgroundTab: - case blink::WebNavigationPolicyNewForegroundTab: - case blink::WebNavigationPolicyNewWindow: - case blink::WebNavigationPolicyNewPopup: - return mojo::TARGET_NEW_NODE; - default: - return mojo::TARGET_DEFAULT; - } -} - ui::EventType ConvertEventTypeToUIEventType(blink::WebInputEvent::Type type) { if (type == blink::WebInputEvent::PointerDown) return ui::ET_TOUCH_PRESSED; @@ -117,7 +89,6 @@ DocumentView::DocumentView( exported_services_(services.Pass()), imported_services_(exported_services.Pass()), shell_(shell), - web_view_(nullptr), root_(nullptr), view_manager_client_factory_(shell_, this), bitmap_rasterizer_(nullptr), @@ -127,8 +98,6 @@ DocumentView::DocumentView( } DocumentView::~DocumentView() { - if (web_view_) - web_view_->close(); if (root_) root_->RemoveObserver(this); ui::GestureRecognizer::Get()->CleanupStateForConsumer(this); @@ -159,10 +128,6 @@ void DocumentView::OnEmbed( UpdateRootSizeAndViewportMetrics(root_->bounds()); - // TODO(abarth): We should ask the view whether it is focused instead of - // assuming that we're focused. - if (web_view_) - web_view_->setFocus(true); root_->AddObserver(this); } @@ -170,34 +135,17 @@ void DocumentView::OnViewManagerDisconnected(mojo::ViewManager* view_manager) { // TODO(aa): Need to figure out how shutdown works. } void DocumentView::Load(mojo::URLResponsePtr response) { - GURL responseURL(response->url); - - if (!blink::WebView::shouldUseWebView(responseURL)) { - String name = String::fromUTF8(responseURL.spec()); - library_provider_.reset(new DartLibraryProviderImpl( - blink::Platform::current()->networkService(), - CreatePrefetchedLibraryIfNeeded(name, response.Pass()))); - sky_view_ = blink::SkyView::Create(this); - initializeLayerTreeView(); - sky_view_->RunFromLibrary(name, library_provider_.get()); - return; - } - - if (!RuntimeFlags::Get().testing()) - LOG(WARNING) << ".sky support is deprecated, please use .dart for main()"; - - web_view_ = blink::WebView::create(this); - ConfigureSettings(web_view_->settings()); - web_view_->setMainFrame(blink::WebLocalFrame::create(this)); - web_view_->mainFrame()->loadFromDataPipeWithURL( - response->body.Pass(), responseURL); -} - -void DocumentView::initializeLayerTreeView() { + String name = String::fromUTF8(response->url); + library_provider_.reset(new DartLibraryProviderImpl( + blink::Platform::current()->networkService(), + CreatePrefetchedLibraryIfNeeded(name, response.Pass()))); + sky_view_ = blink::SkyView::Create(this); layer_host_.reset(new LayerHost(this)); root_layer_ = make_scoped_refptr(new Layer(this)); root_layer_->set_rasterizer(CreateRasterizer()); layer_host_->SetRootLayer(root_layer_); + + sky_view_->RunFromLibrary(name, library_provider_.get()); } scoped_ptr DocumentView::CreateRasterizer() { @@ -241,21 +189,6 @@ void DocumentView::BeginFrame(base::TimeTicks frame_time) { sky_view_->BeginFrame(frame_time); root_layer_->SetSize(sky_view_->display_metrics().physical_size); } - if (web_view_) { - double frame_time_sec = (frame_time - base::TimeTicks()).InSecondsF(); - double deadline_sec = frame_time_sec; - double interval_sec = 1.0/60; - blink::WebBeginFrameArgs web_begin_frame_args( - frame_time_sec, deadline_sec, interval_sec); - - web_view_->beginFrame(web_begin_frame_args); - web_view_->layout(); - - blink::WebSize size = web_view_->size(); - float device_pixel_ratio = GetDevicePixelRatio(); - root_layer_->SetSize(gfx::Size(size.width * device_pixel_ratio, - size.height * device_pixel_ratio)); - } } void DocumentView::OnSurfaceIdAvailable(mojo::SurfaceIdPtr surface_id) { @@ -273,38 +206,6 @@ void DocumentView::PaintContents(SkCanvas* canvas, const gfx::Rect& clip) { if (picture) canvas->drawPicture(picture.get()); } - - if (web_view_) - web_view_->paint(canvas, rect); -} - -void DocumentView::scheduleVisualUpdate() { - layer_host_->SetNeedsAnimate(); -} - -blink::WebScreenInfo DocumentView::screenInfo() { - DCHECK(root_); - auto& metrics = root_->viewport_metrics(); - blink::WebScreenInfo screen; - screen.rect = blink::WebRect(0, 0, metrics.size->width, metrics.size->height); - screen.availableRect = screen.rect; - screen.deviceScaleFactor = metrics.device_pixel_ratio; - return screen; -} - -mojo::View* DocumentView::createChildFrame() { - if (!root_) - return nullptr; - - mojo::View* child = root_->view_manager()->CreateView(); - child->SetVisible(true); - root_->AddChild(child); - return child; -} - -void DocumentView::frameDetached(blink::WebFrame* frame) { - // |frame| is invalid after here. - frame->close(); } float DocumentView::GetDevicePixelRatio() const { @@ -313,38 +214,10 @@ float DocumentView::GetDevicePixelRatio() const { return 1.f; } -blink::WebNavigationPolicy DocumentView::decidePolicyForNavigation( - const blink::WebFrameClient::NavigationPolicyInfo& info) { - - if (navigator_host_.get()) { - navigator_host_->RequestNavigate( - WebNavigationPolicyToNavigationTarget(info.defaultPolicy), - mojo::URLRequest::From(info.urlRequest).Pass()); - } - - return blink::WebNavigationPolicyIgnore; -} - -void DocumentView::didAddMessageToConsole( - const blink::WebConsoleMessage& message, - const blink::WebString& source_name, - unsigned source_line, - const blink::WebString& stack_trace) { -} - -void DocumentView::didCreateIsolate(blink::WebLocalFrame* frame, - Dart_Isolate isolate) { - Internals::Create(isolate, this); -} - void DocumentView::DidCreateIsolate(Dart_Isolate isolate) { Internals::Create(isolate, this); } -blink::ServiceProvider* DocumentView::services() { - return this; -} - mojo::NavigatorHost* DocumentView::NavigatorHost() { return navigator_host_.get(); } @@ -362,9 +235,6 @@ void DocumentView::OnViewViewportMetricsChanged( const mojo::ViewportMetrics& new_metrics) { DCHECK_EQ(view, root_); - if (web_view_) { - web_view_->setDeviceScaleFactor(GetDevicePixelRatio()); - } UpdateRootSizeAndViewportMetrics(root_->bounds()); } @@ -380,20 +250,10 @@ void DocumentView::UpdateRootSizeAndViewportMetrics( sky_view_->SetDisplayMetrics(metrics); return; } - - web_view_->resize(blink::WebSize(new_bounds.width / device_pixel_ratio, - new_bounds.height / device_pixel_ratio)); } void DocumentView::OnViewFocusChanged(mojo::View* gained_focus, mojo::View* lost_focus) { - if (sky_view_) - return; - if (root_ == lost_focus) { - web_view_->setFocus(false); - } else if (root_ == gained_focus) { - web_view_->setFocus(true); - } } void DocumentView::OnViewDestroyed(mojo::View* view) { @@ -418,8 +278,6 @@ void DocumentView::OnViewInputEvent( bool handled = false; - if (web_view_) - handled = web_view_->handleInputEvent(*web_event); if (sky_view_) sky_view_->HandleInputEvent(*web_event); @@ -431,8 +289,6 @@ void DocumentView::OnViewInputEvent( scoped_ptr gesture_event = ConvertEvent(*gesture, device_pixel_ratio); if (gesture_event) { - if (web_view_) - web_view_->handleInputEvent(*gesture_event); if (sky_view_) sky_view_->HandleInputEvent(*gesture_event); } diff --git a/viewer/document_view.h b/viewer/document_view.h index c2dc6c5ae77..9a9a5eb81ee 100644 --- a/viewer/document_view.h +++ b/viewer/document_view.h @@ -22,8 +22,6 @@ #include "sky/engine/public/platform/ServiceProvider.h" #include "sky/engine/public/sky/sky_view.h" #include "sky/engine/public/sky/sky_view_client.h" -#include "sky/engine/public/web/WebFrameClient.h" -#include "sky/engine/public/web/WebViewClient.h" #include "sky/services/testing/test_harness.mojom.h" #include "sky/viewer/compositor/layer_client.h" #include "sky/viewer/compositor/layer_host_client.h" @@ -42,8 +40,6 @@ class LayerHost; class DartLibraryProviderImpl; class DocumentView : public blink::ServiceProvider, - public blink::WebFrameClient, - public blink::WebViewClient, public blink::SkyViewClient, public mojo::ViewManagerDelegate, public mojo::ViewObserver, @@ -59,8 +55,6 @@ class DocumentView : public blink::ServiceProvider, base::WeakPtr GetWeakPtr(); - blink::WebView* web_view() const { return web_view_; } - mojo::Shell* shell() const { return shell_; } // sky::LayerHostClient @@ -83,30 +77,9 @@ class DocumentView : public blink::ServiceProvider, mojo::ScopedMessagePipeHandle TakeServiceRegistry(); private: - // WebViewClient methods: - void initializeLayerTreeView() override; - void scheduleVisualUpdate() override; - blink::WebScreenInfo screenInfo() override; - - // WebFrameClient methods: - mojo::View* createChildFrame() override; - void frameDetached(blink::WebFrame*) override; - blink::WebNavigationPolicy decidePolicyForNavigation( - const blink::WebFrameClient::NavigationPolicyInfo& info) override; - void didAddMessageToConsole( - const blink::WebConsoleMessage& message, - const blink::WebString& source_name, - unsigned source_line, - const blink::WebString& stack_trace) override; - void didCreateIsolate(blink::WebLocalFrame* frame, - Dart_Isolate isolate) override; - // SkyViewClient methods: void DidCreateIsolate(Dart_Isolate isolate) override; - // WebViewClient methods: - blink::ServiceProvider* services() override; - // Services methods: mojo::NavigatorHost* NavigatorHost() override; @@ -146,7 +119,6 @@ class DocumentView : public blink::ServiceProvider, TestHarnessPtr test_harness_; mojo::NavigatorHostPtr navigator_host_; std::unique_ptr sky_view_; - blink::WebView* web_view_; mojo::View* root_; mojo::ViewManagerClientFactory view_manager_client_factory_; scoped_ptr library_provider_; diff --git a/viewer/internals.cc b/viewer/internals.cc index db23c818066..208f698a80b 100644 --- a/viewer/internals.cc +++ b/viewer/internals.cc @@ -6,9 +6,6 @@ #include "mojo/public/cpp/application/connect.h" #include "mojo/public/cpp/bindings/array.h" -#include "sky/engine/public/web/WebDocument.h" -#include "sky/engine/public/web/WebFrame.h" -#include "sky/engine/public/web/WebView.h" #include "sky/engine/tonic/dart_builtin.h" #include "sky/engine/tonic/dart_converter.h" #include "sky/engine/tonic/dart_error.h" @@ -112,16 +109,11 @@ Internals::~Internals() { } std::string Internals::RenderTreeAsText() { - if (!document_view_) - return std::string(); - return document_view_->web_view()->mainFrame()->renderTreeAsText().utf8(); + return std::string(); } std::string Internals::ContentAsText() { - if (!document_view_) - return std::string(); - return document_view_->web_view()->mainFrame()->contentAsText( - 1024*1024).utf8(); + return std::string(); } void Internals::NotifyTestComplete(const std::string& test_result) {