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

Side by Side Diff: blimp/engine/browser/blimp_engine_session.cc

Issue 1403083002: [Blimp] Adds Blimp EngineSession and ClientSession skeleton (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 2 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
(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 DCHECK(message.type() == BlimpMessage::CONTROL);
82
83 switch (message.control().type()) {
84 case ControlMessage::CREATE_TAB:
85 CreateWebContents(message.target_tab_id());
86 break;
87 case ControlMessage::LOAD_URL:
88 LoadUrl(message.target_tab_id(),
89 GURL(message.control().load_url().url()));
90 break;
91 default:
92 NOTIMPLEMENTED();
93 }
94
95 return net::OK;
96 }
97
98 void BlimpEngineSession::AddNewContents(content::WebContents* source,
99 content::WebContents* new_contents,
100 WindowOpenDisposition disposition,
101 const gfx::Rect& initial_rect,
102 bool user_gesture,
103 bool* was_blocked) {
104 NOTIMPLEMENTED();
105 }
106
107 content::WebContents* BlimpEngineSession::OpenURLFromTab(
108 content::WebContents* source,
109 const content::OpenURLParams& params) {
110 // CURRENT_TAB is the only one we implement for now.
111 if (params.disposition != CURRENT_TAB) {
112 // TODO(haibinlu): handle other disposition properly.
113 NOTIMPLEMENTED();
114 return nullptr;
115 }
116 // TOOD(haibinlu): add helper method to get LoadURLParams from OpenURLParams.
117 content::NavigationController::LoadURLParams load_url_params(params.url);
118 load_url_params.source_site_instance = params.source_site_instance;
119 load_url_params.referrer = params.referrer;
120 load_url_params.frame_tree_node_id = params.frame_tree_node_id;
121 load_url_params.transition_type = params.transition;
122 load_url_params.extra_headers = params.extra_headers;
123 load_url_params.should_replace_current_entry =
124 params.should_replace_current_entry;
125
126 if (params.transferred_global_request_id != content::GlobalRequestID()) {
127 // The navigation as being transferred from one RVH to another.
128 // Copies the request ID of the old request.
129 load_url_params.is_renderer_initiated = params.is_renderer_initiated;
130 load_url_params.transferred_global_request_id =
131 params.transferred_global_request_id;
132 } else if (params.is_renderer_initiated) {
133 load_url_params.is_renderer_initiated = true;
134 }
135
136 source->GetController().LoadURLWithParams(load_url_params);
137 return source;
138 }
139
140 void BlimpEngineSession::RequestToLockMouse(content::WebContents* web_contents,
141 bool user_gesture,
142 bool last_unlocked_by_target) {
143 web_contents->GotResponseToLockMouseRequest(true);
144 }
145
146 void BlimpEngineSession::CloseContents(content::WebContents* source) {
147 if (source == web_contents_)
148 web_contents_.reset();
149 }
150
151 void BlimpEngineSession::ActivateContents(content::WebContents* contents) {
152 contents->GetRenderViewHost()->GetWidget()->Focus();
153 }
154
155 void BlimpEngineSession::DeactivateContents(content::WebContents* contents) {
156 contents->GetRenderViewHost()->GetWidget()->Blur();
157 }
158
159 void BlimpEngineSession::PlatformSetContents(
160 scoped_ptr<content::WebContents> new_contents) {
161 new_contents->SetDelegate(this);
162 web_contents_ = new_contents.Pass();
163 }
164
165 } // namespace engine
166 } // namespace blimp
OLDNEW
« no previous file with comments | « blimp/engine/browser/blimp_engine_session.h ('k') | blimp/engine/browser/blimp_url_request_context_getter.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698