OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #include "blimp/engine/browser/blimp_engine_session.h" | |
6 | |
7 #include "blimp/common/proto/blimp_message.pb.h" | |
8 #include "blimp/common/proto/control.pb.h" | |
9 #include "blimp/engine/browser/blimp_browser_context.h" | |
10 #include "blimp/engine/ui/blimp_screen.h" | |
11 #include "blimp/net/blimp_client_session.h" | |
12 #include "content/public/browser/browser_context.h" | |
13 #include "content/public/browser/navigation_controller.h" | |
14 #include "content/public/browser/navigation_entry.h" | |
15 #include "content/public/browser/render_view_host.h" | |
16 #include "content/public/browser/render_widget_host.h" | |
17 #include "content/public/browser/web_contents.h" | |
18 | |
19 namespace blimp { | |
20 namespace engine { | |
21 | |
22 BlimpEngineSession::BlimpEngineSession( | |
23 scoped_ptr<BlimpBrowserContext> browser_context) | |
24 : browser_context_(browser_context.Pass()), screen_(new BlimpScreen) {} | |
25 | |
26 BlimpEngineSession::~BlimpEngineSession() {} | |
27 | |
28 void BlimpEngineSession::Initialize() { | |
29 DCHECK(!gfx::Screen::GetScreenByType(gfx::SCREEN_TYPE_NATIVE)); | |
30 gfx::Screen::SetScreenInstance(gfx::SCREEN_TYPE_NATIVE, screen_.get()); | |
31 } | |
32 | |
33 void BlimpEngineSession::AttachClientSession( | |
34 scoped_ptr<BlimpClientSession> client_session) { | |
35 // TODO(haibinlu): auto detaches existing client session. | |
36 if (!client_session) { | |
37 NOTIMPLEMENTED(); | |
38 return; | |
39 } | |
40 | |
41 client_session_ = client_session.Pass(); | |
42 | |
43 // TODO(haibinlu): remove this once we can use client session to send in | |
44 // a navigation message. | |
45 BlimpMessage message; | |
46 message.set_type(BlimpMessage::CONTROL); | |
47 message.mutable_control()->set_type(ControlMessage::CREATE_TAB); | |
48 OnBlimpMessage(message); | |
49 message.mutable_control()->set_type(ControlMessage::LOAD_URL); | |
50 message.mutable_control()->mutable_load_url()->set_url( | |
51 "https://www.google.com/"); | |
52 OnBlimpMessage(message); | |
53 } | |
54 | |
55 void BlimpEngineSession::CreateWebContents(const int target_tab_id) { | |
56 if (web_contents_) { | |
57 // only one web_contents is supported for blimp 0.5 | |
58 NOTIMPLEMENTED(); | |
59 return; | |
60 } | |
61 | |
62 content::WebContents::CreateParams create_params(browser_context_.get(), | |
63 nullptr); | |
64 scoped_ptr<content::WebContents> new_contents = | |
65 make_scoped_ptr(content::WebContents::Create(create_params)); | |
66 PlatformSetContents(new_contents.Pass()); | |
67 } | |
68 | |
69 void BlimpEngineSession::LoadUrl(const int target_tab_id, const GURL& url) { | |
70 if (url.is_empty() || !web_contents_) | |
71 return; | |
72 | |
73 content::NavigationController::LoadURLParams params(url); | |
74 params.transition_type = ui::PageTransitionFromInt( | |
75 ui::PAGE_TRANSITION_TYPED | ui::PAGE_TRANSITION_FROM_ADDRESS_BAR); | |
76 web_contents_->GetController().LoadURLWithParams(params); | |
77 web_contents_->Focus(); | |
78 } | |
79 | |
80 net::Error BlimpEngineSession::OnBlimpMessage(const BlimpMessage& message) { | |
81 if (message.type() != BlimpMessage::CONTROL) | |
Kevin M
2015/10/15 22:01:56
DCHECK(message.type() != BlimpMessage::CONTROL)
I
haibinlu
2015/10/15 22:12:32
Done.
| |
82 return net::ERR_INVALID_ARGUMENT; | |
83 | |
84 switch (message.control().type()) { | |
85 case ControlMessage::CREATE_TAB: | |
86 CreateWebContents(message.target_tab_id()); | |
87 break; | |
88 case ControlMessage::LOAD_URL: | |
89 LoadUrl(message.target_tab_id(), | |
90 GURL(message.control().load_url().url())); | |
91 break; | |
92 default: | |
93 NOTIMPLEMENTED(); | |
94 } | |
95 | |
96 return net::OK; | |
97 } | |
98 | |
99 void BlimpEngineSession::AddNewContents(content::WebContents* source, | |
100 content::WebContents* new_contents, | |
101 WindowOpenDisposition disposition, | |
102 const gfx::Rect& initial_rect, | |
103 bool user_gesture, | |
104 bool* was_blocked) { | |
105 NOTIMPLEMENTED(); | |
106 } | |
107 | |
108 content::WebContents* BlimpEngineSession::OpenURLFromTab( | |
109 content::WebContents* source, | |
110 const content::OpenURLParams& params) { | |
111 // CURRENT_TAB is the only one we implement for now. | |
112 if (params.disposition != CURRENT_TAB) { | |
113 // TODO(haibinlu): handle other disposition properly. | |
114 NOTIMPLEMENTED(); | |
115 return nullptr; | |
116 } | |
117 // TOOD(haibinlu): add helper method to get LoadURLParams from OpenURLParams. | |
118 content::NavigationController::LoadURLParams load_url_params(params.url); | |
119 load_url_params.source_site_instance = params.source_site_instance; | |
120 load_url_params.referrer = params.referrer; | |
121 load_url_params.frame_tree_node_id = params.frame_tree_node_id; | |
122 load_url_params.transition_type = params.transition; | |
123 load_url_params.extra_headers = params.extra_headers; | |
124 load_url_params.should_replace_current_entry = | |
125 params.should_replace_current_entry; | |
126 | |
127 if (params.transferred_global_request_id != content::GlobalRequestID()) { | |
128 // The navigation as being transferred from one RVH to another. | |
129 // Copies the request ID of the old request. | |
130 load_url_params.is_renderer_initiated = params.is_renderer_initiated; | |
131 load_url_params.transferred_global_request_id = | |
132 params.transferred_global_request_id; | |
133 } else if (params.is_renderer_initiated) { | |
134 load_url_params.is_renderer_initiated = true; | |
135 } | |
136 | |
137 source->GetController().LoadURLWithParams(load_url_params); | |
138 return source; | |
139 } | |
140 | |
141 void BlimpEngineSession::RequestToLockMouse(content::WebContents* web_contents, | |
142 bool user_gesture, | |
143 bool last_unlocked_by_target) { | |
144 web_contents->GotResponseToLockMouseRequest(true); | |
145 } | |
146 | |
147 void BlimpEngineSession::CloseContents(content::WebContents* source) { | |
148 if (source == web_contents_) | |
149 web_contents_.reset(); | |
150 } | |
151 | |
152 void BlimpEngineSession::ActivateContents(content::WebContents* contents) { | |
153 contents->GetRenderViewHost()->GetWidget()->Focus(); | |
154 } | |
155 | |
156 void BlimpEngineSession::DeactivateContents(content::WebContents* contents) { | |
157 contents->GetRenderViewHost()->GetWidget()->Blur(); | |
158 } | |
159 | |
160 void BlimpEngineSession::PlatformSetContents( | |
161 scoped_ptr<content::WebContents> new_contents) { | |
162 new_contents->SetDelegate(this); | |
163 web_contents_ = new_contents.Pass(); | |
164 } | |
165 | |
166 } // namespace engine | |
167 } // namespace blimp | |
OLD | NEW |