Revert of Add button to add new FSP services to Files app. (patchset #8 id:140001...
[chromium-blink-merge.git] / chrome / browser / sessions / session_tab_helper.cc
blob467ed22d5f67c0beb13f6c5c6343a144e6c395ec
1 // Copyright (c) 2012 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.
5 #include "chrome/browser/sessions/session_tab_helper.h"
7 #include "chrome/browser/chrome_notification_types.h"
8 #include "chrome/browser/profiles/profile.h"
9 #include "chrome/browser/sessions/session_service.h"
10 #include "chrome/browser/sessions/session_service_factory.h"
11 #include "content/public/browser/notification_service.h"
12 #include "content/public/browser/render_view_host.h"
13 #include "content/public/browser/web_contents.h"
15 #if defined(ENABLE_EXTENSIONS)
16 #include "extensions/common/extension_messages.h"
17 #endif
19 DEFINE_WEB_CONTENTS_USER_DATA_KEY(SessionTabHelper);
21 SessionTabHelper::SessionTabHelper(content::WebContents* contents)
22 : content::WebContentsObserver(contents) {
25 SessionTabHelper::~SessionTabHelper() {
28 void SessionTabHelper::SetWindowID(const SessionID& id) {
29 window_id_ = id;
31 #if defined(ENABLE_EXTENSIONS)
32 // Extension code in the renderer holds the ID of the window that hosts it.
33 // Notify it that the window ID changed.
34 web_contents()->GetRenderViewHost()->Send(
35 new ExtensionMsg_UpdateBrowserWindowId(
36 web_contents()->GetRenderViewHost()->GetRoutingID(), id.id()));
37 #endif
40 // static
41 SessionID::id_type SessionTabHelper::IdForTab(const content::WebContents* tab) {
42 const SessionTabHelper* session_tab_helper =
43 tab ? SessionTabHelper::FromWebContents(tab) : NULL;
44 return session_tab_helper ? session_tab_helper->session_id().id() : -1;
47 // static
48 SessionID::id_type SessionTabHelper::IdForWindowContainingTab(
49 const content::WebContents* tab) {
50 const SessionTabHelper* session_tab_helper =
51 tab ? SessionTabHelper::FromWebContents(tab) : NULL;
52 return session_tab_helper ? session_tab_helper->window_id().id() : -1;
55 #if defined(ENABLE_EXTENSIONS)
56 void SessionTabHelper::RenderViewCreated(
57 content::RenderViewHost* render_view_host) {
58 render_view_host->Send(
59 new ExtensionMsg_UpdateBrowserWindowId(render_view_host->GetRoutingID(),
60 window_id_.id()));
62 #endif
64 void SessionTabHelper::UserAgentOverrideSet(const std::string& user_agent) {
65 #if defined(ENABLE_SESSION_SERVICE)
66 Profile* profile =
67 Profile::FromBrowserContext(web_contents()->GetBrowserContext());
68 SessionService* session = SessionServiceFactory::GetForProfile(profile);
69 if (session)
70 session->SetTabUserAgentOverride(window_id(), session_id(), user_agent);
71 #endif