From 8aa3caf350c37d65871ebf6bd9b9f0e2b60bc9ed Mon Sep 17 00:00:00 2001 From: Eric Seidel Date: Fri, 22 May 2015 12:59:21 -0700 Subject: [PATCH] Make SkyView vs. WebView controlable via url path We're currently in a transition between using main.sky and main.dart files as our main() entry point for Sky applications. This CL makes this runtime controlable by path name. If it finds a .dart in the path name it will use SkyView, otherwise it will fall back to the existing WebView codepath. SkyView does not expose a window object and much of the existing Sky Engine is not initialized when main() is run. Clients should be transitioning away from main.sky towards main.dart in the near future, however main.dart is probably not ready for general consumption at this point. R=ianh@google.com Review URL: https://codereview.chromium.org/1152313002 --- engine/public/web/WebView.h | 5 +++++ engine/web/WebViewImpl.cpp | 15 +++++++++++++++ shell/ui/engine.cc | 5 +++-- viewer/document_view.cc | 13 ++++++++----- 4 files changed, 31 insertions(+), 7 deletions(-) diff --git a/engine/public/web/WebView.h b/engine/public/web/WebView.h index 19dcc8dbe52..842015fa8e8 100644 --- a/engine/public/web/WebView.h +++ b/engine/public/web/WebView.h @@ -37,6 +37,8 @@ #include "sky/engine/public/web/WebPageVisibilityState.h" #include "sky/engine/public/web/WebWidget.h" +class GURL; + namespace blink { class WebFrame; @@ -48,6 +50,9 @@ 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 342bd53d669..10ae28b364b 100644 --- a/engine/web/WebViewImpl.cpp +++ b/engine/web/WebViewImpl.cpp @@ -83,6 +83,7 @@ #include "sky/engine/wtf/CurrentTime.h" #include "sky/engine/wtf/RefPtr.h" #include "sky/engine/wtf/TemporaryChange.h" +#include "url/gurl.h" // Get rid of WTF's pow define so we can use std::pow. #undef pow @@ -92,6 +93,20 @@ 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); +} + WebView* WebView::create(WebViewClient* client) { // Pass the WebViewImpl's self-reference to the caller. diff --git a/shell/ui/engine.cc b/shell/ui/engine.cc index b16d44e6733..e3df08d99b7 100644 --- a/shell/ui/engine.cc +++ b/shell/ui/engine.cc @@ -171,13 +171,14 @@ void Engine::OnInputEvent(InputEventPtr event) { } void Engine::LoadURL(const mojo::String& url) { - // Enable SkyView here. - if (false) { + if (!WebView::shouldUseWebView(responseURL)) { sky_view_ = blink::SkyView::Create(this); sky_view_->Load(GURL(url)); return; } + 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_) diff --git a/viewer/document_view.cc b/viewer/document_view.cc index f9fe5de87d6..e8eda02094c 100644 --- a/viewer/document_view.cc +++ b/viewer/document_view.cc @@ -158,21 +158,24 @@ void DocumentView::OnEmbed( void DocumentView::OnViewManagerDisconnected(mojo::ViewManager* view_manager) { // TODO(aa): Need to figure out how shutdown works. } - void DocumentView::Load(mojo::URLResponsePtr response) { - // Enable SkyView here. - if (false) { + GURL responseURL(response->url); + + if (!blink::WebView::shouldUseWebView(responseURL)) { sky_view_ = blink::SkyView::Create(this); initializeLayerTreeView(); - sky_view_->Load(GURL(response->url), response.Pass()); + sky_view_->Load(responseURL, response.Pass()); 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(), GURL(response->url)); + response->body.Pass(), responseURL); } void DocumentView::initializeLayerTreeView() {