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

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

Issue 514063003: Update view_manager and window_manager to make use of content handling. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@viewman2
Patch Set: rebase 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
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(Shell* shell)
29 virtual ~NavigatorImpl() {} 25 : shell_(shell) {
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 URLResponsePtr response,
36 ResponseDetailsPtr response_details) OVERRIDE; 34 InterfaceRequest<ServiceProvider> service_provider) OVERRIDE {
35 ServiceProviderImpl* exported_services = new ServiceProviderImpl();
36 BindToRequest(exported_services, &service_provider);
37 scoped_ptr<ServiceProvider> remote(
38 exported_services->CreateRemoteServiceProvider());
39 new HTMLDocumentView(response.Pass(), remote.Pass(), exported_services,
40 shell_);
41 }
37 42
38 HTMLViewer* viewer_; 43 Shell* shell_;
39 44
40 DISALLOW_COPY_AND_ASSIGN(NavigatorImpl); 45 DISALLOW_COPY_AND_ASSIGN(ContentHandlerImpl);
41 }; 46 };
42 47
43 class HTMLViewer : public ApplicationDelegate, public ViewManagerDelegate { 48 class HTMLViewer : public ApplicationDelegate {
44 public: 49 public:
45 HTMLViewer() 50 HTMLViewer() {
46 : application_impl_(NULL), 51 }
47 document_view_(NULL), 52
48 navigator_factory_(this),
49 view_manager_client_factory_(this) {}
50 virtual ~HTMLViewer() { 53 virtual ~HTMLViewer() {
51 blink::shutdown(); 54 blink::shutdown();
52 } 55 }
53 56
54 void Load(ResponseDetailsPtr response_details) {
55 // Need to wait for OnEmbed.
56 response_details_ = response_details.Pass();
57 MaybeLoad();
58 }
59
60 private: 57 private:
61 // Overridden from ApplicationDelegate: 58 // Overridden from ApplicationDelegate:
62 virtual void Initialize(ApplicationImpl* app) OVERRIDE { 59 virtual void Initialize(ApplicationImpl* app) OVERRIDE {
63 application_impl_ = app; 60 content_handler_factory_.reset(
darin (slow to review) 2014/09/04 21:33:51 InterfaceFactoryImplWithContext could also have an
Aaron Boodman 2014/09/04 22:31:43 Yeah, I mean personally I like to avoid the separa
61 new InterfaceFactoryImplWithContext<ContentHandlerImpl, Shell>(
62 app->shell()));
64 blink_platform_impl_.reset(new BlinkPlatformImpl(app)); 63 blink_platform_impl_.reset(new BlinkPlatformImpl(app));
65 blink::initialize(blink_platform_impl_.get()); 64 blink::initialize(blink_platform_impl_.get());
66 } 65 }
67 66
68 virtual bool ConfigureIncomingConnection(ApplicationConnection* connection) 67 virtual bool ConfigureIncomingConnection(ApplicationConnection* connection)
69 OVERRIDE { 68 OVERRIDE {
70 connection->AddService(&navigator_factory_); 69 connection->AddService(content_handler_factory_.get());
71 connection->AddService(&view_manager_client_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 scoped_ptr<InterfaceFactoryImplWithContext<ContentHandlerImpl, Shell> >
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

Powered by Google App Engine
This is Rietveld 408576698