Rename vector icon header files.
[chromium-blink-merge.git] / chrome / browser / sessions / session_tab_helper.cc
blob6b996d60fd8ac9f8a2b03c63d889037eab61982c
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/profiles/profile.h"
8 #include "chrome/browser/sessions/session_service.h"
9 #include "chrome/browser/sessions/session_service_factory.h"
10 #include "content/public/browser/web_contents.h"
12 #if defined(ENABLE_EXTENSIONS)
13 #include "extensions/common/extension_messages.h"
14 #endif
16 DEFINE_WEB_CONTENTS_USER_DATA_KEY(SessionTabHelper);
18 SessionTabHelper::SessionTabHelper(content::WebContents* contents)
19 : content::WebContentsObserver(contents) {
22 SessionTabHelper::~SessionTabHelper() {
25 void SessionTabHelper::SetWindowID(const SessionID& id) {
26 window_id_ = id;
28 #if defined(ENABLE_EXTENSIONS)
29 // Extension code in the renderer holds the ID of the window that hosts it.
30 // Notify it that the window ID changed.
31 web_contents()->SendToAllFrames(
32 new ExtensionMsg_UpdateBrowserWindowId(MSG_ROUTING_NONE, id.id()));
33 #endif
36 // static
37 SessionID::id_type SessionTabHelper::IdForTab(const content::WebContents* tab) {
38 const SessionTabHelper* session_tab_helper =
39 tab ? SessionTabHelper::FromWebContents(tab) : NULL;
40 return session_tab_helper ? session_tab_helper->session_id().id() : -1;
43 // static
44 SessionID::id_type SessionTabHelper::IdForWindowContainingTab(
45 const content::WebContents* tab) {
46 const SessionTabHelper* session_tab_helper =
47 tab ? SessionTabHelper::FromWebContents(tab) : NULL;
48 return session_tab_helper ? session_tab_helper->window_id().id() : -1;
51 void SessionTabHelper::UserAgentOverrideSet(const std::string& user_agent) {
52 #if defined(ENABLE_SESSION_SERVICE)
53 Profile* profile =
54 Profile::FromBrowserContext(web_contents()->GetBrowserContext());
55 SessionService* session = SessionServiceFactory::GetForProfile(profile);
56 if (session)
57 session->SetTabUserAgentOverride(window_id(), session_id(), user_agent);
58 #endif