Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(853)

Side by Side Diff: mojo/services/html_viewer/html_viewer.cc

Issue 489493004: Update view manager to support content handling. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: blah to the blizzah Created 6 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "base/message_loop/message_loop.h" 5 #include "base/message_loop/message_loop.h"
6 #include "mojo/public/c/system/main.h" 6 #include "mojo/public/c/system/main.h"
7 #include "mojo/public/cpp/application/application_connection.h" 7 #include "mojo/public/cpp/application/application_connection.h"
8 #include "mojo/public/cpp/application/application_delegate.h" 8 #include "mojo/public/cpp/application/application_delegate.h"
9 #include "mojo/public/cpp/application/application_impl.h" 9 #include "mojo/public/cpp/application/application_impl.h"
10 #include "mojo/public/cpp/application/application_runner_chromium.h" 10 #include "mojo/public/cpp/application/application_runner_chromium.h"
11 #include "mojo/public/cpp/application/interface_factory_impl.h" 11 #include "mojo/public/cpp/application/interface_factory_impl.h"
12 #include "mojo/public/cpp/application/service_provider_impl.h"
12 #include "mojo/services/html_viewer/blink_platform_impl.h" 13 #include "mojo/services/html_viewer/blink_platform_impl.h"
13 #include "mojo/services/html_viewer/html_document_view.h" 14 #include "mojo/services/html_viewer/html_document_view.h"
14 #include "mojo/services/public/cpp/view_manager/types.h" 15 #include "mojo/services/public/interfaces/content_handler/content_handler.mojom. h"
15 #include "mojo/services/public/cpp/view_manager/view.h"
16 #include "mojo/services/public/cpp/view_manager/view_manager.h"
17 #include "mojo/services/public/cpp/view_manager/view_manager_client_factory.h"
18 #include "mojo/services/public/cpp/view_manager/view_manager_delegate.h"
19 #include "mojo/services/public/interfaces/navigation/navigation.mojom.h"
20 #include "third_party/WebKit/public/web/WebKit.h" 16 #include "third_party/WebKit/public/web/WebKit.h"
21 17
22 namespace mojo { 18 namespace mojo {
23 19
24 class HTMLViewer; 20 class HTMLViewer;
25 21
26 class NavigatorImpl : public InterfaceImpl<Navigator> { 22 class ContentHandlerImpl : public InterfaceImpl<ContentHandler> {
27 public: 23 public:
28 explicit NavigatorImpl(HTMLViewer* viewer) : viewer_(viewer) {} 24 explicit ContentHandlerImpl(ApplicationConnection* application_connection)
29 virtual ~NavigatorImpl() {} 25 : application_connection_(application_connection) {
26 }
27 virtual ~ContentHandlerImpl() {}
30 28
31 private: 29 private:
32 // Overridden from Navigator: 30 // Overridden from ContentHandler:
33 virtual void Navigate( 31 virtual void OnConnect(
34 uint32_t view_id, 32 const mojo::String& url,
35 NavigationDetailsPtr navigation_details, 33 ContentHandlerResponsePtr response,
36 ResponseDetailsPtr response_details) OVERRIDE; 34 InterfaceRequest<ServiceProvider> service_provider) OVERRIDE {
35 ServiceProviderImpl* exported_services =
36 new ServiceProviderImpl(application_connection_);
37 BindToRequest(exported_services, &service_provider);
38 scoped_ptr<ServiceProvider> remote(
39 exported_services->CreateRemoteServiceProvider());
40 new HTMLDocumentView(response.Pass(), remote.Pass(), exported_services,
41 application_connection_);
42 }
37 43
38 HTMLViewer* viewer_; 44 ApplicationConnection* application_connection_;
39 45
40 DISALLOW_COPY_AND_ASSIGN(NavigatorImpl); 46 DISALLOW_COPY_AND_ASSIGN(ContentHandlerImpl);
41 }; 47 };
42 48
43 class HTMLViewer : public ApplicationDelegate, public ViewManagerDelegate { 49 class HTMLViewer : public ApplicationDelegate {
44 public: 50 public:
45 HTMLViewer() 51 HTMLViewer()
46 : application_impl_(NULL), 52 : content_handler_factory_(NULL) {
47 document_view_(NULL), 53 }
48 navigator_factory_(this), 54
49 view_manager_client_factory_(this) {}
50 virtual ~HTMLViewer() { 55 virtual ~HTMLViewer() {
51 blink::shutdown(); 56 blink::shutdown();
52 } 57 }
53 58
54 void Load(ResponseDetailsPtr response_details) {
55 // Need to wait for OnEmbed.
56 response_details_ = response_details.Pass();
57 MaybeLoad();
58 }
59
60 private: 59 private:
61 // Overridden from ApplicationDelegate: 60 // Overridden from ApplicationDelegate:
62 virtual void Initialize(ApplicationImpl* app) OVERRIDE { 61 virtual void Initialize(ApplicationImpl* app) OVERRIDE {
63 application_impl_ = app;
64 blink_platform_impl_.reset(new BlinkPlatformImpl(app)); 62 blink_platform_impl_.reset(new BlinkPlatformImpl(app));
65 blink::initialize(blink_platform_impl_.get()); 63 blink::initialize(blink_platform_impl_.get());
66 } 64 }
67 65
68 virtual bool ConfigureIncomingConnection(ApplicationConnection* connection) 66 virtual bool ConfigureIncomingConnection(ApplicationConnection* connection)
69 OVERRIDE { 67 OVERRIDE {
70 connection->AddService(&navigator_factory_); 68 content_handler_factory_.set_context(connection);
71 connection->AddService(&view_manager_client_factory_); 69 connection->AddService(&content_handler_factory_);
72 return true; 70 return true;
73 } 71 }
74 72
75 // Overridden from ViewManagerDelegate:
76 virtual void OnEmbed(ViewManager* view_manager,
77 View* root,
78 ServiceProviderImpl* exported_services,
79 scoped_ptr<ServiceProvider> imported_services) OVERRIDE {
80 document_view_ = new HTMLDocumentView(
81 application_impl_->ConnectToApplication("mojo://mojo_window_manager/")->
82 GetServiceProvider(),
83 view_manager);
84 document_view_->AttachToView(root);
85 MaybeLoad();
86 }
87 virtual void OnViewManagerDisconnected(ViewManager* view_manager) OVERRIDE {
88 base::MessageLoop::current()->Quit();
89 }
90
91 void MaybeLoad() {
92 if (document_view_ && response_details_ && response_details_->response)
93 document_view_->Load(response_details_->response.Pass());
94 }
95
96 scoped_ptr<BlinkPlatformImpl> blink_platform_impl_; 73 scoped_ptr<BlinkPlatformImpl> blink_platform_impl_;
97 ApplicationImpl* application_impl_; 74 InterfaceFactoryImplWithContext<ContentHandlerImpl, ApplicationConnection>
98 75 content_handler_factory_;
99 // TODO(darin): Figure out proper ownership of this instance.
100 HTMLDocumentView* document_view_;
101 ResponseDetailsPtr response_details_;
102 InterfaceFactoryImplWithContext<NavigatorImpl, HTMLViewer> navigator_factory_;
103 ViewManagerClientFactory view_manager_client_factory_;
104 76
105 DISALLOW_COPY_AND_ASSIGN(HTMLViewer); 77 DISALLOW_COPY_AND_ASSIGN(HTMLViewer);
106 }; 78 };
107 79
108 void NavigatorImpl::Navigate(
109 uint32_t view_id,
110 NavigationDetailsPtr navigation_details,
111 ResponseDetailsPtr response_details) {
112 viewer_->Load(response_details.Pass());
113 }
114
115 } // namespace mojo 80 } // namespace mojo
116 81
117 MojoResult MojoMain(MojoHandle shell_handle) { 82 MojoResult MojoMain(MojoHandle shell_handle) {
118 mojo::ApplicationRunnerChromium runner(new mojo::HTMLViewer); 83 mojo::ApplicationRunnerChromium runner(new mojo::HTMLViewer);
119 return runner.Run(shell_handle); 84 return runner.Run(shell_handle);
120 } 85 }
OLDNEW
« no previous file with comments | « mojo/services/html_viewer/html_document_view.cc ('k') | mojo/services/public/interfaces/content_handler/content_handler.mojom » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698