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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: blimp/engine/browser/blimp_engine_session.cc
diff --git a/blimp/engine/browser/blimp_engine_session.cc b/blimp/engine/browser/blimp_engine_session.cc
new file mode 100644
index 0000000000000000000000000000000000000000..289eda8370895378641ed93d08414165224f0924
--- /dev/null
+++ b/blimp/engine/browser/blimp_engine_session.cc
@@ -0,0 +1,128 @@
+// Copyright 2015 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "blimp/engine/browser/blimp_engine_session.h"
+
+#include "blimp/engine/browser/blimp_browser_context.h"
+#include "blimp/engine/browser/blimp_client_session.h"
+#include "blimp/engine/ui/blimp_screen.h"
+#include "content/public/browser/browser_context.h"
+#include "content/public/browser/navigation_controller.h"
+#include "content/public/browser/navigation_entry.h"
+#include "content/public/browser/render_view_host.h"
+#include "content/public/browser/web_contents.h"
+
+namespace blimp {
+namespace engine {
+
+BlimpEngineSession::BlimpEngineSession(
+ scoped_ptr<BlimpBrowserContext> browser_context)
+ : browser_context_(browser_context.Pass()), screen_(new BlimpScreen) {}
+
+BlimpEngineSession::~BlimpEngineSession() {}
+
+void BlimpEngineSession::Initialize() {
+ DCHECK(!gfx::Screen::GetScreenByType(gfx::SCREEN_TYPE_NATIVE));
+ gfx::Screen::SetScreenInstance(gfx::SCREEN_TYPE_NATIVE, screen_.get());
+}
+
+void BlimpEngineSession::CreateWebContents(const GURL& url) {
+ content::WebContents::CreateParams create_params(browser_context_.get(),
+ nullptr);
+ content::WebContents* new_contents =
+ content::WebContents::Create(create_params);
+ PlatformSetContents(new_contents);
+ if (!url.is_empty()) {
+ content::NavigationController::LoadURLParams params(url);
+ params.transition_type = ui::PageTransitionFromInt(
+ ui::PAGE_TRANSITION_TYPED | ui::PAGE_TRANSITION_FROM_ADDRESS_BAR);
+ new_contents->GetController().LoadURLWithParams(params);
+ new_contents->Focus();
+ }
+}
+
+void BlimpEngineSession::AttachClientSession(
+ BlimpClientSession* client_session) {
+ DCHECK(!client_session_);
+ client_session_ = client_session;
+ if (screen_->GetPrimaryDisplay().size() != client_session->screen_size()) {
+ screen_->UpdateDisplaySize(client_session->screen_size());
+ }
+ if (!client_session->url_to_load().is_empty())
+ CreateWebContents(client_session->url_to_load());
+}
+
+void BlimpEngineSession::DetachClientSession(
+ BlimpClientSession* client_session) {
+ DCHECK(client_session_ == client_session);
+ client_session_ = nullptr;
+}
+
+void BlimpEngineSession::AddNewContents(content::WebContents* source,
+ content::WebContents* new_contents,
+ WindowOpenDisposition disposition,
+ const gfx::Rect& initial_rect,
+ bool user_gesture,
+ bool* was_blocked) {
+ // Ignore |initial_rect|. Always use client screen size.
+ PlatformSetContents(new_contents);
+}
+
+content::WebContents* BlimpEngineSession::OpenURLFromTab(
+ content::WebContents* source,
+ const content::OpenURLParams& params) {
+ // CURRENT_TAB is the only one we implement for now.
+ if (params.disposition != CURRENT_TAB)
+ return nullptr;
+ // TOOD(haibinlu): add helper method to get LoadURLParams from OpenURLParams.
+ content::NavigationController::LoadURLParams load_url_params(params.url);
+ load_url_params.source_site_instance = params.source_site_instance;
+ load_url_params.referrer = params.referrer;
+ load_url_params.frame_tree_node_id = params.frame_tree_node_id;
+ load_url_params.transition_type = params.transition;
+ load_url_params.extra_headers = params.extra_headers;
+ load_url_params.should_replace_current_entry =
+ params.should_replace_current_entry;
+
+ if (params.transferred_global_request_id != content::GlobalRequestID()) {
+ load_url_params.is_renderer_initiated = params.is_renderer_initiated;
+ load_url_params.transferred_global_request_id =
+ params.transferred_global_request_id;
+ } else if (params.is_renderer_initiated) {
+ load_url_params.is_renderer_initiated = true;
+ }
+
+ source->GetController().LoadURLWithParams(load_url_params);
+ return source;
+}
+
+void BlimpEngineSession::RequestToLockMouse(content::WebContents* web_contents,
+ bool user_gesture,
+ bool last_unlocked_by_target) {
+ web_contents->GotResponseToLockMouseRequest(true);
+}
+
+void BlimpEngineSession::CloseContents(content::WebContents* source) {
+ ScopedVector<content::WebContents>::iterator it(
+ std::find(contents_list_.begin(), contents_list_.end(), source));
+ DCHECK(it != contents_list_.end());
+ contents_list_.erase(it);
+}
+
+void BlimpEngineSession::ActivateContents(content::WebContents* contents) {
+ contents->GetRenderViewHost()->Focus();
+}
+
+void BlimpEngineSession::DeactivateContents(content::WebContents* contents) {
+ contents->GetRenderViewHost()->Blur();
+}
+
+void BlimpEngineSession::PlatformSetContents(
+ content::WebContents* new_contents) {
+ contents_list_.push_back(new_contents);
+ new_contents->SetDelegate(this);
+}
+
+} // namespace engine
+} // namespace blimp

Powered by Google App Engine
This is Rietveld 408576698