Index: examples/pdf_viewer/pdf_viewer.cc |
diff --git a/examples/pdf_viewer/pdf_viewer.cc b/examples/pdf_viewer/pdf_viewer.cc |
index 04e37a2b5b63e89ad4a6a626c85075a09435cd5f..ed60a55bf09d646a8bcfd3bb9c30829d05957070 100644 |
--- a/examples/pdf_viewer/pdf_viewer.cc |
+++ b/examples/pdf_viewer/pdf_viewer.cc |
@@ -5,6 +5,7 @@ |
#include "base/strings/string_tokenizer.h" |
#include "examples/bitmap_uploader/bitmap_uploader.h" |
#include "mojo/application/application_runner_chromium.h" |
+#include "mojo/application/content_handler.h" |
#include "mojo/public/c/system/main.h" |
#include "mojo/public/cpp/application/application_connection.h" |
#include "mojo/public/cpp/application/application_delegate.h" |
@@ -29,32 +30,12 @@ |
namespace mojo { |
namespace examples { |
-class PDFViewer; |
- |
-class PDFView : public ViewManagerDelegate, public ViewObserver { |
+class PDFView : public ApplicationDelegate, |
+ public ViewManagerDelegate, |
+ public ViewObserver { |
public: |
- static void Spawn(URLResponsePtr response, |
- ServiceProviderImpl* exported_services, |
- scoped_ptr<ServiceProvider> imported_services, |
- Shell* shell) { |
- // PDFView deletes itself when its View is destroyed. |
- new PDFView( |
- response.Pass(), exported_services, imported_services.Pass(), shell); |
- } |
- |
- private: |
- PDFView(URLResponsePtr response, |
- ServiceProviderImpl* exported_services, |
- scoped_ptr<ServiceProvider> imported_services, |
- Shell* shell) |
- : current_page_(0), |
- page_count_(0), |
- doc_(NULL), |
- imported_services_(imported_services.Pass()), |
- shell_(shell), |
- root_(nullptr), |
- view_manager_client_factory_(shell, this) { |
- exported_services->AddService(&view_manager_client_factory_); |
+ PDFView(URLResponsePtr response) |
+ : current_page_(0), page_count_(0), doc_(NULL), root_(nullptr) { |
FetchPDF(response.Pass()); |
} |
@@ -65,6 +46,20 @@ class PDFView : public ViewManagerDelegate, public ViewObserver { |
root_->RemoveObserver(this); |
} |
+ private: |
+ // Overridden from ApplicationDelegate: |
+ virtual void Initialize(ApplicationImpl* app) override { |
+ app_ = app; |
+ view_manager_client_factory_.reset( |
+ new ViewManagerClientFactory(app->shell(), this)); |
+ } |
+ |
+ virtual bool ConfigureIncomingConnection( |
+ ApplicationConnection* connection) override { |
+ connection->AddService(view_manager_client_factory_.get()); |
+ return true; |
+ } |
+ |
// Overridden from ViewManagerDelegate: |
virtual void OnEmbed(ViewManager* view_manager, |
View* root, |
@@ -73,7 +68,7 @@ class PDFView : public ViewManagerDelegate, public ViewObserver { |
root_ = root; |
root_->AddObserver(this); |
bitmap_uploader_.reset(new BitmapUploader(root_)); |
- bitmap_uploader_->Init(shell_); |
+ bitmap_uploader_->Init(app_->shell()); |
bitmap_uploader_->SetColor(BACKGROUND_COLOR); |
DrawBitmap(); |
} |
@@ -114,7 +109,10 @@ class PDFView : public ViewManagerDelegate, public ViewObserver { |
virtual void OnViewDestroyed(View* view) override { |
DCHECK_EQ(view, root_); |
- delete this; |
+ // TODO(qsr): It should not be necessary to cleanup the uploader, but it |
+ // crashes if the GL context goes away. |
+ bitmap_uploader_.reset(); |
+ ApplicationImpl::Terminate(); |
} |
void DrawBitmap() { |
@@ -186,65 +184,33 @@ class PDFView : public ViewManagerDelegate, public ViewObserver { |
int current_page_; |
int page_count_; |
FPDF_DOCUMENT doc_; |
- scoped_ptr<ServiceProvider> imported_services_; |
- Shell* shell_; |
+ ApplicationImpl* app_; |
Aaron Boodman
2014/10/31 08:24:01
app_ needs to be initialized in ctor.
qsr
2014/10/31 12:10:44
Done.
|
View* root_; |
- ViewManagerClientFactory view_manager_client_factory_; |
+ scoped_ptr<ViewManagerClientFactory> view_manager_client_factory_; |
scoped_ptr<BitmapUploader> bitmap_uploader_; |
DISALLOW_COPY_AND_ASSIGN(PDFView); |
}; |
-class ContentHandlerImpl : public InterfaceImpl<ContentHandler> { |
+class PDFViewer : public ContentHandlerDelegate { |
public: |
- explicit ContentHandlerImpl(Shell* shell) : shell_(shell) {} |
- virtual ~ContentHandlerImpl() {} |
- |
- private: |
- // Overridden from ContentHandler: |
- virtual void OnConnect( |
- const mojo::String& requestor_url, |
- URLResponsePtr response, |
- InterfaceRequest<ServiceProvider> service_provider) override { |
- ServiceProviderImpl* exported_services = new ServiceProviderImpl(); |
- BindToRequest(exported_services, &service_provider); |
- scoped_ptr<ServiceProvider> remote( |
- exported_services->CreateRemoteServiceProvider()); |
- PDFView::Spawn(response.Pass(), exported_services, remote.Pass(), shell_); |
+ PDFViewer() { |
+ v8::V8::InitializeICU(); |
+ FPDF_InitLibrary(NULL); |
} |
- Shell* shell_; |
- |
- DISALLOW_COPY_AND_ASSIGN(ContentHandlerImpl); |
-}; |
- |
-class PDFViewer : public ApplicationDelegate { |
- public: |
- PDFViewer() {} |
virtual ~PDFViewer() { |
FPDF_DestroyLibrary(); |
} |
private: |
- // Overridden from ApplicationDelegate: |
- virtual void Initialize(ApplicationImpl* app) override { |
- content_handler_factory_.reset( |
- new InterfaceFactoryImplWithContext<ContentHandlerImpl, Shell>( |
- app->shell())); |
- |
- v8::V8::InitializeICU(); |
- FPDF_InitLibrary(NULL); |
- } |
- |
- // Overridden from ApplicationDelegate: |
- virtual bool ConfigureIncomingConnection( |
- ApplicationConnection* connection) override { |
- connection->AddService(content_handler_factory_.get()); |
- return true; |
+ // Overridden from ContentHandlerDelegate: |
+ virtual scoped_ptr<mojo::InterfaceImpl<mojo::Application>> CreateApplication( |
Aaron Boodman
2014/10/31 08:24:01
I don't think you need mojo:: for any of these. Yo
qsr
2014/10/31 12:10:44
Well, sky isn't, and I mixed the two. Thanks.
|
+ ShellPtr shell, |
+ URLResponsePtr response) override { |
+ return make_scoped_ptr(new mojo::ApplicationImpl( |
+ new PDFView(response.Pass()), shell.PassMessagePipe())); |
} |
- scoped_ptr<InterfaceFactoryImplWithContext<ContentHandlerImpl, Shell> > |
- content_handler_factory_; |
- |
DISALLOW_COPY_AND_ASSIGN(PDFViewer); |
}; |
@@ -252,6 +218,6 @@ class PDFViewer : public ApplicationDelegate { |
} // namespace mojo |
MojoResult MojoMain(MojoHandle shell_handle) { |
- mojo::ApplicationRunnerChromium runner(new mojo::examples::PDFViewer); |
- return runner.Run(shell_handle); |
+ return mojo::ContentHandlerRunner::Run( |
+ shell_handle, make_scoped_ptr(new mojo::examples::PDFViewer)); |
} |