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

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..85be4fbd44f56bde3be2575eb38912461791ec94
--- /dev/null
+++ b/blimp/engine/browser/blimp_engine_session.cc
@@ -0,0 +1,140 @@
+// 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/common/proto/blimp_message.pb.h"
+#include "blimp/common/proto/client_control.pb.h"
+#include "blimp/engine/browser/blimp_browser_context.h"
+#include "blimp/engine/ui/blimp_screen.h"
+#include "blimp/net/blimp_client_session.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::AttachClientSession(
+ scoped_ptr<BlimpClientSession> client_session) {
+ // TODO(haibinlu): auto detaches existing client session.
+ if (!client_session)
Kevin M 2015/10/15 17:14:03 Add NOTIMPLEMENTED() here
haibinlu 2015/10/15 21:17:53 Done.
+ return;
+ 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.
+
+ // TODO(haibinlu): remove this once we can use client session to send in
+ // a navigation message.
+ BlimpMessage message;
+ message.set_type(BlimpMessage::CLIENT_CONTROL);
+ message.mutable_client_control()->set_type(ClientControlMessage::NEW_TAB);
+ message.mutable_client_control()->mutable_navigate()->set_url(
+ "https://www.google.com/");
+ OnBlimpMessage(message);
+}
+
+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();
+ }
+}
+
+net::Error BlimpEngineSession::OnBlimpMessage(const BlimpMessage& message) {
+ if (message.type() != BlimpMessage::CLIENT_CONTROL)
+ return net::ERR_INVALID_ARGUMENT;
+
+ 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.
+ CreateWebContents(GURL(message.client_control().navigate().url()));
+
+ return net::OK;
+}
+
+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)
Kevin M 2015/10/15 17:14:03 Add TODO and NOTIMPLEMENTED
haibinlu 2015/10/15 21:17:53 Done.
+ 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()) {
Kevin M 2015/10/15 17:14:03 What does this block do? Comment plz
haibinlu 2015/10/15 21:17:53 Done.
+ 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) {
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.
+ contents_list_.push_back(new_contents);
+ new_contents->SetDelegate(this);
+}
+
+} // namespace engine
+} // namespace blimp

Powered by Google App Engine
This is Rietveld 408576698