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/extensions/extension_tab_util.h" | 5 #include "chrome/browser/extensions/extension_tab_util.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "base/values.h" | 8 #include "base/values.h" |
9 #include "chrome/browser/extensions/api/tabs/tabs_constants.h" | 9 #include "chrome/browser/extensions/api/tabs/tabs_constants.h" |
| 10 #include "chrome/browser/extensions/window_controller.h" |
| 11 #include "chrome/browser/extensions/window_controller_list.h" |
| 12 #include "chrome/browser/sessions/session_tab_helper.h" |
| 13 #include "content/public/browser/browser_context.h" |
| 14 #include "content/public/browser/favicon_status.h" |
| 15 #include "content/public/browser/navigation_entry.h" |
| 16 #include "extensions/browser/app_window/app_window.h" |
| 17 #include "extensions/browser/app_window/app_window_registry.h" |
10 #include "url/gurl.h" | 18 #include "url/gurl.h" |
11 | 19 |
| 20 using content::NavigationEntry; |
12 using content::WebContents; | 21 using content::WebContents; |
13 | 22 |
14 namespace extensions { | 23 namespace extensions { |
15 | 24 |
16 namespace keys = tabs_constants; | 25 namespace keys = tabs_constants; |
17 | 26 |
| 27 namespace { |
| 28 |
| 29 WindowController* GetAppWindowController(const WebContents* contents) { |
| 30 AppWindowRegistry* registry = |
| 31 AppWindowRegistry::Get(contents->GetBrowserContext()); |
| 32 if (!registry) |
| 33 return NULL; |
| 34 AppWindow* app_window = |
| 35 registry->GetAppWindowForRenderViewHost(contents->GetRenderViewHost()); |
| 36 if (!app_window) |
| 37 return NULL; |
| 38 return WindowControllerList::GetInstance()->FindWindowById( |
| 39 app_window->session_id().id()); |
| 40 } |
| 41 |
| 42 } // namespace |
| 43 |
18 ExtensionTabUtil::OpenTabParams::OpenTabParams() | 44 ExtensionTabUtil::OpenTabParams::OpenTabParams() |
19 : create_browser_if_needed(false) { | 45 : create_browser_if_needed(false) { |
20 } | 46 } |
21 | 47 |
22 ExtensionTabUtil::OpenTabParams::~OpenTabParams() { | 48 ExtensionTabUtil::OpenTabParams::~OpenTabParams() { |
23 } | 49 } |
24 | 50 |
25 // Opens a new tab for a given extension. Returns NULL and sets |error| if an | 51 // Opens a new tab for a given extension. Returns NULL and sets |error| if an |
26 // error occurs. | 52 // error occurs. |
27 base::DictionaryValue* ExtensionTabUtil::OpenTab( | 53 base::DictionaryValue* ExtensionTabUtil::OpenTab( |
(...skipping 25 matching lines...) Expand all Loading... |
53 return -1; | 79 return -1; |
54 } | 80 } |
55 | 81 |
56 int ExtensionTabUtil::GetWindowIdOfTabStripModel( | 82 int ExtensionTabUtil::GetWindowIdOfTabStripModel( |
57 const TabStripModel* tab_strip_model) { | 83 const TabStripModel* tab_strip_model) { |
58 NOTREACHED(); | 84 NOTREACHED(); |
59 return -1; | 85 return -1; |
60 } | 86 } |
61 | 87 |
62 int ExtensionTabUtil::GetTabId(const WebContents* web_contents) { | 88 int ExtensionTabUtil::GetTabId(const WebContents* web_contents) { |
63 NOTIMPLEMENTED(); | 89 return SessionTabHelper::IdForTab(web_contents); |
64 return -1; | |
65 } | 90 } |
66 | 91 |
67 std::string ExtensionTabUtil::GetTabStatusText(bool is_loading) { | 92 std::string ExtensionTabUtil::GetTabStatusText(bool is_loading) { |
68 NOTIMPLEMENTED(); | 93 return is_loading ? keys::kStatusValueLoading : keys::kStatusValueComplete; |
69 return keys::kStatusValueComplete; | |
70 } | 94 } |
71 | 95 |
72 int ExtensionTabUtil::GetWindowIdOfTab(const WebContents* web_contents) { | 96 int ExtensionTabUtil::GetWindowIdOfTab(const WebContents* web_contents) { |
73 NOTIMPLEMENTED(); | 97 return SessionTabHelper::IdForWindowContainingTab(web_contents); |
74 return -1; | |
75 } | 98 } |
76 | 99 |
77 base::DictionaryValue* ExtensionTabUtil::CreateTabValue( | 100 base::DictionaryValue* ExtensionTabUtil::CreateTabValue( |
78 WebContents* contents, | 101 WebContents* contents, |
79 TabStripModel* tab_strip, | 102 TabStripModel* tab_strip, |
80 int tab_index, | 103 int tab_index, |
81 const Extension* extension) { | 104 const Extension* extension) { |
82 NOTREACHED(); | 105 NOTREACHED(); |
83 return NULL; | 106 return NULL; |
84 } | 107 } |
85 | 108 |
86 base::ListValue* ExtensionTabUtil::CreateTabList( | 109 base::ListValue* ExtensionTabUtil::CreateTabList( |
87 const Browser* browser, | 110 const Browser* browser, |
88 const Extension* extension) { | 111 const Extension* extension) { |
89 return new base::ListValue(); | 112 return new base::ListValue(); |
90 } | 113 } |
91 | 114 |
92 base::DictionaryValue* ExtensionTabUtil::CreateTabValue( | 115 base::DictionaryValue* ExtensionTabUtil::CreateTabValue( |
93 WebContents* contents, | 116 WebContents* contents, |
94 TabStripModel* tab_strip, | 117 TabStripModel* tab_strip, |
95 int tab_index) { | 118 int tab_index) { |
96 NOTREACHED(); | 119 // There's no TabStrip in Athena. |
97 return NULL; | 120 DCHECK(!tab_strip); |
| 121 |
| 122 // If we have a matching AppWindow with a controller, get the tab value |
| 123 // from its controller instead. |
| 124 WindowController* controller = GetAppWindowController(contents); |
| 125 if (controller) |
| 126 return controller->CreateTabValue(NULL, tab_index); |
| 127 |
| 128 base::DictionaryValue* result = new base::DictionaryValue(); |
| 129 bool is_loading = contents->IsLoading(); |
| 130 result->SetInteger(keys::kIdKey, GetTabId(contents)); |
| 131 result->SetInteger(keys::kIndexKey, tab_index); |
| 132 result->SetInteger(keys::kWindowIdKey, GetWindowIdOfTab(contents)); |
| 133 result->SetString(keys::kStatusKey, GetTabStatusText(is_loading)); |
| 134 result->SetBoolean(keys::kActiveKey, false); |
| 135 result->SetBoolean(keys::kSelectedKey, false); |
| 136 result->SetBoolean(keys::kHighlightedKey, false); |
| 137 result->SetBoolean(keys::kPinnedKey, false); |
| 138 result->SetBoolean(keys::kIncognitoKey, |
| 139 contents->GetBrowserContext()->IsOffTheRecord()); |
| 140 result->SetInteger(keys::kWidthKey, |
| 141 contents->GetContainerBounds().size().width()); |
| 142 result->SetInteger(keys::kHeightKey, |
| 143 contents->GetContainerBounds().size().height()); |
| 144 |
| 145 // Privacy-sensitive fields: these should be stripped off by |
| 146 // ScrubTabValueForExtension if the extension should not see them. |
| 147 result->SetString(keys::kUrlKey, contents->GetURL().spec()); |
| 148 result->SetString(keys::kTitleKey, contents->GetTitle()); |
| 149 if (!is_loading) { |
| 150 NavigationEntry* entry = contents->GetController().GetVisibleEntry(); |
| 151 if (entry && entry->GetFavicon().valid) |
| 152 result->SetString(keys::kFaviconUrlKey, entry->GetFavicon().url.spec()); |
| 153 } |
| 154 |
| 155 return result; |
98 } | 156 } |
99 | 157 |
100 void ExtensionTabUtil::ScrubTabValueForExtension( | 158 void ExtensionTabUtil::ScrubTabValueForExtension( |
101 WebContents* contents, | 159 WebContents* contents, |
102 const Extension* extension, | 160 const Extension* extension, |
103 base::DictionaryValue* tab_info) { | 161 base::DictionaryValue* tab_info) { |
104 // TODO(oshima): Move this to common impl. | 162 // TODO(oshima): Move this to common impl. |
105 } | 163 } |
106 | 164 |
107 void ExtensionTabUtil::ScrubTabForExtension(const Extension* extension, | 165 void ExtensionTabUtil::ScrubTabForExtension(const Extension* extension, |
108 api::tabs::Tab* tab) { | 166 api::tabs::Tab* tab) { |
109 | 167 |
110 // TODO(oshima): Move this to common impl. | 168 // TODO(oshima): Move this to common impl. |
111 } | 169 } |
112 | 170 |
113 bool ExtensionTabUtil::GetTabStripModel(const WebContents* web_contents, | 171 bool ExtensionTabUtil::GetTabStripModel(const WebContents* web_contents, |
114 TabStripModel** tab_strip_model, | 172 TabStripModel** tab_strip_model, |
115 int* tab_index) { | 173 int* tab_index) { |
116 NOTIMPLEMENTED(); | 174 NOTIMPLEMENTED(); |
| 175 |
117 return false; | 176 return false; |
118 } | 177 } |
119 | 178 |
120 bool ExtensionTabUtil::GetDefaultTab(Browser* browser, | 179 bool ExtensionTabUtil::GetDefaultTab(Browser* browser, |
121 WebContents** contents, | 180 WebContents** contents, |
122 int* tab_id) { | 181 int* tab_id) { |
123 NOTREACHED(); | 182 NOTREACHED(); |
124 return false; | 183 return false; |
125 } | 184 } |
126 | 185 |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
161 | 220 |
162 // static | 221 // static |
163 WindowController* ExtensionTabUtil::GetWindowControllerOfTab( | 222 WindowController* ExtensionTabUtil::GetWindowControllerOfTab( |
164 const WebContents* web_contents) { | 223 const WebContents* web_contents) { |
165 NOTIMPLEMENTED(); | 224 NOTIMPLEMENTED(); |
166 return NULL; | 225 return NULL; |
167 } | 226 } |
168 | 227 |
169 void ExtensionTabUtil::OpenOptionsPage(const Extension* extension, | 228 void ExtensionTabUtil::OpenOptionsPage(const Extension* extension, |
170 Browser* browser) { | 229 Browser* browser) { |
171 // NOTIMPLEMENTED(); | 230 NOTIMPLEMENTED(); |
172 } | 231 } |
173 | 232 |
174 } // namespace extensions | 233 } // namespace extensions |
OLD | NEW |