app_list: Re-enable people search.
[chromium-blink-merge.git] / chrome / browser / extensions / extension_tab_util_athena.cc
blob02dd4c621101b9fb9de9d89c3ebc34de62a8cfe2
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/extensions/extension_tab_util.h"
7 #include "base/logging.h"
8 #include "base/values.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"
18 #include "url/gurl.h"
20 using content::NavigationEntry;
21 using content::WebContents;
23 namespace extensions {
25 namespace keys = tabs_constants;
27 namespace {
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());
42 } // namespace
44 ExtensionTabUtil::OpenTabParams::OpenTabParams()
45 : create_browser_if_needed(false) {
48 ExtensionTabUtil::OpenTabParams::~OpenTabParams() {
51 // Opens a new tab for a given extension. Returns NULL and sets |error| if an
52 // error occurs.
53 base::DictionaryValue* ExtensionTabUtil::OpenTab(
54 ChromeUIThreadExtensionFunction* function,
55 const OpenTabParams& params,
56 std::string* error) {
57 NOTIMPLEMENTED();
58 return NULL;
61 Browser* ExtensionTabUtil::GetBrowserFromWindowID(
62 ChromeUIThreadExtensionFunction* function,
63 int window_id,
64 std::string* error) {
65 NOTREACHED();
66 return NULL;
69 Browser* ExtensionTabUtil::GetBrowserFromWindowID(
70 const ChromeExtensionFunctionDetails& details,
71 int window_id,
72 std::string* error) {
73 NOTREACHED();
74 return NULL;
77 int ExtensionTabUtil::GetWindowId(const Browser* browser) {
78 NOTREACHED();
79 return -1;
82 int ExtensionTabUtil::GetWindowIdOfTabStripModel(
83 const TabStripModel* tab_strip_model) {
84 NOTREACHED();
85 return -1;
88 int ExtensionTabUtil::GetTabId(const WebContents* web_contents) {
89 return SessionTabHelper::IdForTab(web_contents);
92 std::string ExtensionTabUtil::GetTabStatusText(bool is_loading) {
93 return is_loading ? keys::kStatusValueLoading : keys::kStatusValueComplete;
96 int ExtensionTabUtil::GetWindowIdOfTab(const WebContents* web_contents) {
97 return SessionTabHelper::IdForWindowContainingTab(web_contents);
100 base::DictionaryValue* ExtensionTabUtil::CreateTabValue(
101 WebContents* contents,
102 TabStripModel* tab_strip,
103 int tab_index,
104 const Extension* extension) {
105 NOTREACHED();
106 return NULL;
109 base::ListValue* ExtensionTabUtil::CreateTabList(
110 const Browser* browser,
111 const Extension* extension) {
112 return new base::ListValue();
115 base::DictionaryValue* ExtensionTabUtil::CreateTabValue(
116 WebContents* contents,
117 TabStripModel* tab_strip,
118 int tab_index) {
119 // There's no TabStrip in Athena.
120 DCHECK(!tab_strip);
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);
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());
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());
155 return result;
158 void ExtensionTabUtil::ScrubTabValueForExtension(
159 WebContents* contents,
160 const Extension* extension,
161 base::DictionaryValue* tab_info) {
162 // TODO(oshima): Move this to common impl.
165 void ExtensionTabUtil::ScrubTabForExtension(const Extension* extension,
166 api::tabs::Tab* tab) {
168 // TODO(oshima): Move this to common impl.
171 bool ExtensionTabUtil::GetTabStripModel(const WebContents* web_contents,
172 TabStripModel** tab_strip_model,
173 int* tab_index) {
174 NOTIMPLEMENTED();
176 return false;
179 bool ExtensionTabUtil::GetDefaultTab(Browser* browser,
180 WebContents** contents,
181 int* tab_id) {
182 NOTIMPLEMENTED();
183 return false;
186 bool ExtensionTabUtil::GetTabById(int tab_id,
187 content::BrowserContext* browser_context,
188 bool include_incognito,
189 Browser** browser,
190 TabStripModel** tab_strip,
191 WebContents** contents,
192 int* tab_index) {
193 NOTIMPLEMENTED();
194 return false;
197 GURL ExtensionTabUtil::ResolvePossiblyRelativeURL(const std::string& url_string,
198 const Extension* extension) {
199 // TODO(oshima): Move this to common impl.
200 return GURL(url_string);
203 bool ExtensionTabUtil::IsCrashURL(const GURL& url) {
204 // TODO(oshima): Move this to common impl.
205 return false;
208 void ExtensionTabUtil::CreateTab(WebContents* web_contents,
209 const std::string& extension_id,
210 WindowOpenDisposition disposition,
211 const gfx::Rect& initial_pos,
212 bool user_gesture) {
213 NOTIMPLEMENTED();
216 // static
217 void ExtensionTabUtil::ForEachTab(
218 const base::Callback<void(WebContents*)>& callback) {
219 // TODO(oshima): Move this to common impl.
222 // static
223 WindowController* ExtensionTabUtil::GetWindowControllerOfTab(
224 const WebContents* web_contents) {
225 NOTIMPLEMENTED();
226 return NULL;
229 void ExtensionTabUtil::OpenOptionsPage(const Extension* extension,
230 Browser* browser) {
231 NOTIMPLEMENTED();
234 } // namespace extensions