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/client_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/web_contents.h" | |
17 | |
18 namespace blimp { | |
19 namespace engine { | |
20 | |
21 BlimpEngineSession::BlimpEngineSession( | |
22 scoped_ptr<BlimpBrowserContext> browser_context) | |
23 : browser_context_(browser_context.Pass()), screen_(new BlimpScreen) {} | |
24 | |
25 BlimpEngineSession::~BlimpEngineSession() {} | |
26 | |
27 void BlimpEngineSession::Initialize() { | |
28 DCHECK(!gfx::Screen::GetScreenByType(gfx::SCREEN_TYPE_NATIVE)); | |
29 gfx::Screen::SetScreenInstance(gfx::SCREEN_TYPE_NATIVE, screen_.get()); | |
30 } | |
31 | |
32 void BlimpEngineSession::AttachClientSession( | |
33 scoped_ptr<BlimpClientSession> client_session) { | |
34 // TODO(haibinlu): auto detaches existing client session. | |
35 if (!client_session) | |
Kevin M
2015/10/15 17:14:03
Add NOTIMPLEMENTED() here
haibinlu
2015/10/15 21:17:53
Done.
| |
36 return; | |
37 client_session_.reset(client_session.release()); | |
Kevin M
2015/10/15 17:14:03
client_session_ = client_session.Pass() is safer/m
haibinlu
2015/10/15 21:17:53
Done.
| |
38 | |
39 // TODO(haibinlu): remove this once we can use client session to send in | |
40 // a navigation message. | |
41 BlimpMessage message; | |
42 message.set_type(BlimpMessage::CLIENT_CONTROL); | |
43 message.mutable_client_control()->set_type(ClientControlMessage::NEW_TAB); | |
44 message.mutable_client_control()->mutable_navigate()->set_url( | |
45 "https://www.google.com/"); | |
46 OnBlimpMessage(message); | |
47 } | |
48 | |
49 void BlimpEngineSession::CreateWebContents(const GURL& url) { | |
50 content::WebContents::CreateParams create_params(browser_context_.get(), | |
51 nullptr); | |
52 content::WebContents* new_contents = | |
53 content::WebContents::Create(create_params); | |
54 PlatformSetContents(new_contents); | |
55 if (!url.is_empty()) { | |
56 content::NavigationController::LoadURLParams params(url); | |
57 params.transition_type = ui::PageTransitionFromInt( | |
58 ui::PAGE_TRANSITION_TYPED | ui::PAGE_TRANSITION_FROM_ADDRESS_BAR); | |
59 new_contents->GetController().LoadURLWithParams(params); | |
60 new_contents->Focus(); | |
61 } | |
62 } | |
63 | |
64 net::Error BlimpEngineSession::OnBlimpMessage(const BlimpMessage& message) { | |
65 if (message.type() != BlimpMessage::CLIENT_CONTROL) | |
66 return net::ERR_INVALID_ARGUMENT; | |
67 | |
68 if (message.client_control().type() == ClientControlMessage::NEW_TAB) | |
Kevin M
2015/10/15 17:14:03
Put this in a switch statement - this list will gr
haibinlu
2015/10/15 21:17:53
Done.
| |
69 CreateWebContents(GURL(message.client_control().navigate().url())); | |
70 | |
71 return net::OK; | |
72 } | |
73 | |
74 void BlimpEngineSession::AddNewContents(content::WebContents* source, | |
75 content::WebContents* new_contents, | |
76 WindowOpenDisposition disposition, | |
77 const gfx::Rect& initial_rect, | |
78 bool user_gesture, | |
79 bool* was_blocked) { | |
80 // Ignore |initial_rect|. Always use client screen size. | |
81 PlatformSetContents(new_contents); | |
82 } | |
83 | |
84 content::WebContents* BlimpEngineSession::OpenURLFromTab( | |
85 content::WebContents* source, | |
86 const content::OpenURLParams& params) { | |
87 // CURRENT_TAB is the only one we implement for now. | |
88 if (params.disposition != CURRENT_TAB) | |
Kevin M
2015/10/15 17:14:03
Add TODO and NOTIMPLEMENTED
haibinlu
2015/10/15 21:17:53
Done.
| |
89 return nullptr; | |
90 // TOOD(haibinlu): add helper method to get LoadURLParams from OpenURLParams. | |
91 content::NavigationController::LoadURLParams load_url_params(params.url); | |
92 load_url_params.source_site_instance = params.source_site_instance; | |
93 load_url_params.referrer = params.referrer; | |
94 load_url_params.frame_tree_node_id = params.frame_tree_node_id; | |
95 load_url_params.transition_type = params.transition; | |
96 load_url_params.extra_headers = params.extra_headers; | |
97 load_url_params.should_replace_current_entry = | |
98 params.should_replace_current_entry; | |
99 | |
100 if (params.transferred_global_request_id != content::GlobalRequestID()) { | |
Kevin M
2015/10/15 17:14:03
What does this block do? Comment plz
haibinlu
2015/10/15 21:17:53
Done.
| |
101 load_url_params.is_renderer_initiated = params.is_renderer_initiated; | |
102 load_url_params.transferred_global_request_id = | |
103 params.transferred_global_request_id; | |
104 } else if (params.is_renderer_initiated) { | |
105 load_url_params.is_renderer_initiated = true; | |
106 } | |
107 | |
108 source->GetController().LoadURLWithParams(load_url_params); | |
109 return source; | |
110 } | |
111 | |
112 void BlimpEngineSession::RequestToLockMouse(content::WebContents* web_contents, | |
113 bool user_gesture, | |
114 bool last_unlocked_by_target) { | |
115 web_contents->GotResponseToLockMouseRequest(true); | |
116 } | |
117 | |
118 void BlimpEngineSession::CloseContents(content::WebContents* source) { | |
119 ScopedVector<content::WebContents>::iterator it( | |
120 std::find(contents_list_.begin(), contents_list_.end(), source)); | |
121 DCHECK(it != contents_list_.end()); | |
122 contents_list_.erase(it); | |
123 } | |
124 | |
125 void BlimpEngineSession::ActivateContents(content::WebContents* contents) { | |
126 contents->GetRenderViewHost()->Focus(); | |
127 } | |
128 | |
129 void BlimpEngineSession::DeactivateContents(content::WebContents* contents) { | |
130 contents->GetRenderViewHost()->Blur(); | |
131 } | |
132 | |
133 void BlimpEngineSession::PlatformSetContents( | |
134 content::WebContents* new_contents) { | |
Kevin M
2015/10/15 17:14:03
Take a scoped_ptr to make ownership transfer expli
haibinlu
2015/10/15 21:17:53
Done.
| |
135 contents_list_.push_back(new_contents); | |
136 new_contents->SetDelegate(this); | |
137 } | |
138 | |
139 } // namespace engine | |
140 } // namespace blimp | |
OLD | NEW |