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/engine/browser/blimp_browser_context.h" |
| 8 #include "blimp/engine/browser/blimp_client_session.h" |
| 9 #include "blimp/engine/ui/blimp_screen.h" |
| 10 #include "content/public/browser/browser_context.h" |
| 11 #include "content/public/browser/navigation_controller.h" |
| 12 #include "content/public/browser/navigation_entry.h" |
| 13 #include "content/public/browser/render_view_host.h" |
| 14 #include "content/public/browser/web_contents.h" |
| 15 |
| 16 namespace blimp { |
| 17 namespace engine { |
| 18 |
| 19 BlimpEngineSession::BlimpEngineSession( |
| 20 scoped_ptr<BlimpBrowserContext> browser_context) |
| 21 : browser_context_(browser_context.Pass()), screen_(new BlimpScreen) {} |
| 22 |
| 23 BlimpEngineSession::~BlimpEngineSession() {} |
| 24 |
| 25 void BlimpEngineSession::Initialize() { |
| 26 DCHECK(!gfx::Screen::GetScreenByType(gfx::SCREEN_TYPE_NATIVE)); |
| 27 gfx::Screen::SetScreenInstance(gfx::SCREEN_TYPE_NATIVE, screen_.get()); |
| 28 } |
| 29 |
| 30 void BlimpEngineSession::CreateWebContents(const GURL& url) { |
| 31 content::WebContents::CreateParams create_params(browser_context_.get(), |
| 32 nullptr); |
| 33 content::WebContents* new_contents = |
| 34 content::WebContents::Create(create_params); |
| 35 PlatformSetContents(new_contents); |
| 36 if (!url.is_empty()) { |
| 37 content::NavigationController::LoadURLParams params(url); |
| 38 params.transition_type = ui::PageTransitionFromInt( |
| 39 ui::PAGE_TRANSITION_TYPED | ui::PAGE_TRANSITION_FROM_ADDRESS_BAR); |
| 40 new_contents->GetController().LoadURLWithParams(params); |
| 41 new_contents->Focus(); |
| 42 } |
| 43 } |
| 44 |
| 45 void BlimpEngineSession::AttachClientSession( |
| 46 BlimpClientSession* client_session) { |
| 47 DCHECK(!client_session_); |
| 48 client_session_ = client_session; |
| 49 if (screen_->GetPrimaryDisplay().size() != client_session->screen_size()) { |
| 50 screen_->UpdateDisplaySize(client_session->screen_size()); |
| 51 } |
| 52 if (!client_session->url_to_load().is_empty()) |
| 53 CreateWebContents(client_session->url_to_load()); |
| 54 } |
| 55 |
| 56 void BlimpEngineSession::DetachClientSession( |
| 57 BlimpClientSession* client_session) { |
| 58 DCHECK(client_session_ == client_session); |
| 59 client_session_ = nullptr; |
| 60 } |
| 61 |
| 62 void BlimpEngineSession::AddNewContents(content::WebContents* source, |
| 63 content::WebContents* new_contents, |
| 64 WindowOpenDisposition disposition, |
| 65 const gfx::Rect& initial_rect, |
| 66 bool user_gesture, |
| 67 bool* was_blocked) { |
| 68 // Ignore |initial_rect|. Always use client screen size. |
| 69 PlatformSetContents(new_contents); |
| 70 } |
| 71 |
| 72 content::WebContents* BlimpEngineSession::OpenURLFromTab( |
| 73 content::WebContents* source, |
| 74 const content::OpenURLParams& params) { |
| 75 // CURRENT_TAB is the only one we implement for now. |
| 76 if (params.disposition != CURRENT_TAB) |
| 77 return nullptr; |
| 78 // TOOD(haibinlu): add helper method to get LoadURLParams from OpenURLParams. |
| 79 content::NavigationController::LoadURLParams load_url_params(params.url); |
| 80 load_url_params.source_site_instance = params.source_site_instance; |
| 81 load_url_params.referrer = params.referrer; |
| 82 load_url_params.frame_tree_node_id = params.frame_tree_node_id; |
| 83 load_url_params.transition_type = params.transition; |
| 84 load_url_params.extra_headers = params.extra_headers; |
| 85 load_url_params.should_replace_current_entry = |
| 86 params.should_replace_current_entry; |
| 87 |
| 88 if (params.transferred_global_request_id != content::GlobalRequestID()) { |
| 89 load_url_params.is_renderer_initiated = params.is_renderer_initiated; |
| 90 load_url_params.transferred_global_request_id = |
| 91 params.transferred_global_request_id; |
| 92 } else if (params.is_renderer_initiated) { |
| 93 load_url_params.is_renderer_initiated = true; |
| 94 } |
| 95 |
| 96 source->GetController().LoadURLWithParams(load_url_params); |
| 97 return source; |
| 98 } |
| 99 |
| 100 void BlimpEngineSession::RequestToLockMouse(content::WebContents* web_contents, |
| 101 bool user_gesture, |
| 102 bool last_unlocked_by_target) { |
| 103 web_contents->GotResponseToLockMouseRequest(true); |
| 104 } |
| 105 |
| 106 void BlimpEngineSession::CloseContents(content::WebContents* source) { |
| 107 ScopedVector<content::WebContents>::iterator it( |
| 108 std::find(contents_list_.begin(), contents_list_.end(), source)); |
| 109 DCHECK(it != contents_list_.end()); |
| 110 contents_list_.erase(it); |
| 111 } |
| 112 |
| 113 void BlimpEngineSession::ActivateContents(content::WebContents* contents) { |
| 114 contents->GetRenderViewHost()->Focus(); |
| 115 } |
| 116 |
| 117 void BlimpEngineSession::DeactivateContents(content::WebContents* contents) { |
| 118 contents->GetRenderViewHost()->Blur(); |
| 119 } |
| 120 |
| 121 void BlimpEngineSession::PlatformSetContents( |
| 122 content::WebContents* new_contents) { |
| 123 contents_list_.push_back(new_contents); |
| 124 new_contents->SetDelegate(this); |
| 125 } |
| 126 |
| 127 } // namespace engine |
| 128 } // namespace blimp |
OLD | NEW |