OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 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 | 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 "blimp/engine/browser/blimp_engine_session.h" | 5 #include "blimp/engine/browser/blimp_engine_session.h" |
6 | 6 |
7 #include "blimp/common/proto/blimp_message.pb.h" | 7 #include "blimp/common/proto/blimp_message.pb.h" |
8 #include "blimp/common/proto/control.pb.h" | 8 #include "blimp/common/proto/control.pb.h" |
9 #include "blimp/engine/browser/blimp_browser_context.h" | 9 #include "blimp/engine/browser/blimp_browser_context.h" |
10 #include "blimp/engine/ui/blimp_layout_manager.h" | 10 #include "blimp/engine/ui/blimp_layout_manager.h" |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
89 void BlimpEngineSession::CreateWebContents(const int target_tab_id) { | 89 void BlimpEngineSession::CreateWebContents(const int target_tab_id) { |
90 // TODO(haibinlu): Support more than one active WebContents (crbug/547231). | 90 // TODO(haibinlu): Support more than one active WebContents (crbug/547231). |
91 DCHECK(!web_contents_); | 91 DCHECK(!web_contents_); |
92 content::WebContents::CreateParams create_params(browser_context_.get(), | 92 content::WebContents::CreateParams create_params(browser_context_.get(), |
93 nullptr); | 93 nullptr); |
94 scoped_ptr<content::WebContents> new_contents = | 94 scoped_ptr<content::WebContents> new_contents = |
95 make_scoped_ptr(content::WebContents::Create(create_params)); | 95 make_scoped_ptr(content::WebContents::Create(create_params)); |
96 PlatformSetContents(new_contents.Pass()); | 96 PlatformSetContents(new_contents.Pass()); |
97 } | 97 } |
98 | 98 |
| 99 void BlimpEngineSession::CloseWebContents(const int target_tab_id) { |
| 100 DCHECK(web_contents_); |
| 101 web_contents_->Close(); |
| 102 } |
| 103 |
99 void BlimpEngineSession::LoadUrl(const int target_tab_id, const GURL& url) { | 104 void BlimpEngineSession::LoadUrl(const int target_tab_id, const GURL& url) { |
100 if (url.is_empty() || !web_contents_) | 105 if (url.is_empty() || !web_contents_) |
101 return; | 106 return; |
102 | 107 |
103 content::NavigationController::LoadURLParams params(url); | 108 content::NavigationController::LoadURLParams params(url); |
104 params.transition_type = ui::PageTransitionFromInt( | 109 params.transition_type = ui::PageTransitionFromInt( |
105 ui::PAGE_TRANSITION_TYPED | ui::PAGE_TRANSITION_FROM_ADDRESS_BAR); | 110 ui::PAGE_TRANSITION_TYPED | ui::PAGE_TRANSITION_FROM_ADDRESS_BAR); |
106 web_contents_->GetController().LoadURLWithParams(params); | 111 web_contents_->GetController().LoadURLWithParams(params); |
107 web_contents_->Focus(); | 112 web_contents_->Focus(); |
108 } | 113 } |
109 | 114 |
| 115 void BlimpEngineSession::GoBack(const int target_tab_id) { |
| 116 if (!web_contents_) |
| 117 return; |
| 118 |
| 119 web_contents_->GetController().GoBack(); |
| 120 } |
| 121 |
| 122 void BlimpEngineSession::GoForward(const int target_tab_id) { |
| 123 if (!web_contents_) |
| 124 return; |
| 125 |
| 126 web_contents_->GetController().GoForward(); |
| 127 } |
| 128 |
| 129 void BlimpEngineSession::Reload(const int target_tab_id) { |
| 130 if (!web_contents_) |
| 131 return; |
| 132 |
| 133 web_contents_->GetController().Reload(true); |
| 134 } |
| 135 |
110 net::Error BlimpEngineSession::OnBlimpMessage(const BlimpMessage& message) { | 136 net::Error BlimpEngineSession::OnBlimpMessage(const BlimpMessage& message) { |
111 DCHECK(message.type() == BlimpMessage::CONTROL); | 137 DCHECK(message.type() == BlimpMessage::CONTROL || |
| 138 message.type() == BlimpMessage::NAVIGATION); |
112 | 139 |
113 switch (message.control().type()) { | 140 if (message.type() == BlimpMessage::CONTROL) { |
114 case ControlMessage::CREATE_TAB: | 141 switch (message.control().type()) { |
115 CreateWebContents(message.target_tab_id()); | 142 case ControlMessage::CREATE_TAB: |
116 break; | 143 CreateWebContents(message.target_tab_id()); |
117 case ControlMessage::LOAD_URL: | 144 break; |
118 LoadUrl(message.target_tab_id(), | 145 case ControlMessage::CLOSE_TAB: |
119 GURL(message.control().load_url().url())); | 146 CloseWebContents(message.target_tab_id()); |
120 break; | 147 default: |
121 default: | 148 NOTIMPLEMENTED(); |
122 NOTIMPLEMENTED(); | 149 } |
| 150 } else if (message.type() == BlimpMessage::NAVIGATION && web_contents_) { |
| 151 switch (message.navigation().type()) { |
| 152 case NavigationMessage::LOAD_URL: |
| 153 LoadUrl(message.target_tab_id(), |
| 154 GURL(message.navigation().load_url().url())); |
| 155 break; |
| 156 case NavigationMessage::GO_BACK: |
| 157 GoBack(message.target_tab_id()); |
| 158 break; |
| 159 case NavigationMessage::GO_FORWARD: |
| 160 GoForward(message.target_tab_id()); |
| 161 break; |
| 162 case NavigationMessage::RELOAD: |
| 163 Reload(message.target_tab_id()); |
| 164 break; |
| 165 default: |
| 166 NOTIMPLEMENTED(); |
| 167 } |
123 } | 168 } |
124 | 169 |
125 return net::OK; | 170 return net::OK; |
126 } | 171 } |
127 | 172 |
128 void BlimpEngineSession::AddNewContents(content::WebContents* source, | 173 void BlimpEngineSession::AddNewContents(content::WebContents* source, |
129 content::WebContents* new_contents, | 174 content::WebContents* new_contents, |
130 WindowOpenDisposition disposition, | 175 WindowOpenDisposition disposition, |
131 const gfx::Rect& initial_rect, | 176 const gfx::Rect& initial_rect, |
132 bool user_gesture, | 177 bool user_gesture, |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
190 | 235 |
191 aura::Window* parent = window_tree_host_->window(); | 236 aura::Window* parent = window_tree_host_->window(); |
192 aura::Window* content = web_contents_->GetNativeView(); | 237 aura::Window* content = web_contents_->GetNativeView(); |
193 if (!parent->Contains(content)) | 238 if (!parent->Contains(content)) |
194 parent->AddChild(content); | 239 parent->AddChild(content); |
195 content->Show(); | 240 content->Show(); |
196 } | 241 } |
197 | 242 |
198 } // namespace engine | 243 } // namespace engine |
199 } // namespace blimp | 244 } // namespace blimp |
OLD | NEW |