OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/sessions/session_tab_helper.h" | 5 #include "chrome/browser/sessions/session_tab_helper.h" |
6 | 6 |
7 #include "chrome/browser/profiles/profile.h" | 7 #include "chrome/browser/profiles/profile.h" |
8 #include "chrome/browser/sessions/session_service.h" | 8 #include "chrome/browser/sessions/session_service.h" |
9 #include "chrome/browser/sessions/session_service_factory.h" | 9 #include "chrome/browser/sessions/session_service_factory.h" |
10 #include "chrome/common/features.h" | 10 #include "chrome/common/features.h" |
11 #include "content/public/browser/web_contents.h" | 11 #include "content/public/browser/web_contents.h" |
| 12 #include "extensions/features/features.h" |
12 | 13 |
13 #if defined(ENABLE_EXTENSIONS) | 14 #if BUILDFLAG(ENABLE_EXTENSIONS) |
14 #include "extensions/common/extension_messages.h" | 15 #include "extensions/common/extension_messages.h" |
15 #endif | 16 #endif |
16 | 17 |
17 DEFINE_WEB_CONTENTS_USER_DATA_KEY(SessionTabHelper); | 18 DEFINE_WEB_CONTENTS_USER_DATA_KEY(SessionTabHelper); |
18 | 19 |
19 SessionTabHelper::SessionTabHelper(content::WebContents* contents) | 20 SessionTabHelper::SessionTabHelper(content::WebContents* contents) |
20 : content::WebContentsObserver(contents) { | 21 : content::WebContentsObserver(contents) { |
21 } | 22 } |
22 | 23 |
23 SessionTabHelper::~SessionTabHelper() { | 24 SessionTabHelper::~SessionTabHelper() { |
24 } | 25 } |
25 | 26 |
26 void SessionTabHelper::SetWindowID(const SessionID& id) { | 27 void SessionTabHelper::SetWindowID(const SessionID& id) { |
27 window_id_ = id; | 28 window_id_ = id; |
28 | 29 |
29 #if defined(ENABLE_EXTENSIONS) | 30 #if BUILDFLAG(ENABLE_EXTENSIONS) |
30 // Extension code in the renderer holds the ID of the window that hosts it. | 31 // Extension code in the renderer holds the ID of the window that hosts it. |
31 // Notify it that the window ID changed. | 32 // Notify it that the window ID changed. |
32 web_contents()->SendToAllFrames( | 33 web_contents()->SendToAllFrames( |
33 new ExtensionMsg_UpdateBrowserWindowId(MSG_ROUTING_NONE, id.id())); | 34 new ExtensionMsg_UpdateBrowserWindowId(MSG_ROUTING_NONE, id.id())); |
34 #endif | 35 #endif |
35 } | 36 } |
36 | 37 |
37 // static | 38 // static |
38 SessionID::id_type SessionTabHelper::IdForTab(const content::WebContents* tab) { | 39 SessionID::id_type SessionTabHelper::IdForTab(const content::WebContents* tab) { |
39 const SessionTabHelper* session_tab_helper = | 40 const SessionTabHelper* session_tab_helper = |
(...skipping 11 matching lines...) Expand all Loading... |
51 | 52 |
52 void SessionTabHelper::UserAgentOverrideSet(const std::string& user_agent) { | 53 void SessionTabHelper::UserAgentOverrideSet(const std::string& user_agent) { |
53 #if BUILDFLAG(ENABLE_SESSION_SERVICE) | 54 #if BUILDFLAG(ENABLE_SESSION_SERVICE) |
54 Profile* profile = | 55 Profile* profile = |
55 Profile::FromBrowserContext(web_contents()->GetBrowserContext()); | 56 Profile::FromBrowserContext(web_contents()->GetBrowserContext()); |
56 SessionService* session = SessionServiceFactory::GetForProfile(profile); | 57 SessionService* session = SessionServiceFactory::GetForProfile(profile); |
57 if (session) | 58 if (session) |
58 session->SetTabUserAgentOverride(window_id(), session_id(), user_agent); | 59 session->SetTabUserAgentOverride(window_id(), session_id(), user_agent); |
59 #endif | 60 #endif |
60 } | 61 } |
OLD | NEW |