Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(304)

Side by Side Diff: chrome/browser/extensions/extension_tab_util_athena.cc

Issue 642693003: [Athena] Copy implementation of some ExtensionTabUtil methods. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "chrome/browser/ui/browser.h"
14 #include "chrome/browser/ui/browser_iterator.h"
15 #include "chrome/browser/ui/tabs/tab_strip_model.h"
16 #include "content/public/browser/browser_context.h"
17 #include "content/public/browser/favicon_status.h"
18 #include "content/public/browser/navigation_entry.h"
19 #include "extensions/browser/app_window/app_window.h"
20 #include "extensions/browser/app_window/app_window_registry.h"
10 #include "url/gurl.h" 21 #include "url/gurl.h"
11 22
23 using content::NavigationEntry;
12 using content::WebContents; 24 using content::WebContents;
13 25
14 namespace extensions { 26 namespace extensions {
15 27
16 namespace keys = tabs_constants; 28 namespace keys = tabs_constants;
17 29
30 namespace {
31
32 WindowController* GetAppWindowController(const WebContents* contents) {
33 AppWindowRegistry* registry =
34 AppWindowRegistry::Get(contents->GetBrowserContext());
35 if (!registry)
36 return NULL;
37 AppWindow* app_window =
38 registry->GetAppWindowForRenderViewHost(contents->GetRenderViewHost());
39 if (!app_window)
40 return NULL;
41 return WindowControllerList::GetInstance()->FindWindowById(
42 app_window->session_id().id());
43 }
44
45 } // namespace
46
18 ExtensionTabUtil::OpenTabParams::OpenTabParams() 47 ExtensionTabUtil::OpenTabParams::OpenTabParams()
19 : create_browser_if_needed(false) { 48 : create_browser_if_needed(false) {
20 } 49 }
21 50
22 ExtensionTabUtil::OpenTabParams::~OpenTabParams() { 51 ExtensionTabUtil::OpenTabParams::~OpenTabParams() {
23 } 52 }
24 53
25 // Opens a new tab for a given extension. Returns NULL and sets |error| if an 54 // Opens a new tab for a given extension. Returns NULL and sets |error| if an
26 // error occurs. 55 // error occurs.
27 base::DictionaryValue* ExtensionTabUtil::OpenTab( 56 base::DictionaryValue* ExtensionTabUtil::OpenTab(
(...skipping 25 matching lines...) Expand all
53 return -1; 82 return -1;
54 } 83 }
55 84
56 int ExtensionTabUtil::GetWindowIdOfTabStripModel( 85 int ExtensionTabUtil::GetWindowIdOfTabStripModel(
57 const TabStripModel* tab_strip_model) { 86 const TabStripModel* tab_strip_model) {
58 NOTREACHED(); 87 NOTREACHED();
59 return -1; 88 return -1;
60 } 89 }
61 90
62 int ExtensionTabUtil::GetTabId(const WebContents* web_contents) { 91 int ExtensionTabUtil::GetTabId(const WebContents* web_contents) {
63 NOTIMPLEMENTED(); 92 return SessionTabHelper::IdForTab(web_contents);
64 return -1;
65 } 93 }
66 94
67 std::string ExtensionTabUtil::GetTabStatusText(bool is_loading) { 95 std::string ExtensionTabUtil::GetTabStatusText(bool is_loading) {
68 NOTIMPLEMENTED(); 96 return is_loading ? keys::kStatusValueLoading : keys::kStatusValueComplete;
69 return keys::kStatusValueComplete;
70 } 97 }
71 98
72 int ExtensionTabUtil::GetWindowIdOfTab(const WebContents* web_contents) { 99 int ExtensionTabUtil::GetWindowIdOfTab(const WebContents* web_contents) {
73 NOTIMPLEMENTED(); 100 return SessionTabHelper::IdForWindowContainingTab(web_contents);
74 return -1;
75 } 101 }
76 102
77 base::DictionaryValue* ExtensionTabUtil::CreateTabValue( 103 base::DictionaryValue* ExtensionTabUtil::CreateTabValue(
78 WebContents* contents, 104 WebContents* contents,
79 TabStripModel* tab_strip, 105 TabStripModel* tab_strip,
80 int tab_index, 106 int tab_index,
81 const Extension* extension) { 107 const Extension* extension) {
82 NOTREACHED(); 108 // If we have a matching AppWindow with a controller, get the tab value
83 return NULL; 109 // from its controller instead.
110 WindowController* controller = GetAppWindowController(contents);
Nikita (slow) 2014/10/27 10:56:50 I've removed impl for this method as well cause it
111 if (controller)
112 return controller->CreateTabValue(NULL, tab_index);
113
114 if (!tab_strip)
115 ExtensionTabUtil::GetTabStripModel(contents, &tab_strip, &tab_index);
116
117 base::DictionaryValue* result = new base::DictionaryValue();
118 bool is_loading = contents->IsLoading();
119 result->SetInteger(keys::kIdKey, GetTabId(contents));
120 result->SetInteger(keys::kIndexKey, tab_index);
121 result->SetInteger(keys::kWindowIdKey, GetWindowIdOfTab(contents));
122 result->SetString(keys::kStatusKey, GetTabStatusText(is_loading));
123 result->SetBoolean(keys::kActiveKey,
124 tab_strip && tab_index == tab_strip->active_index());
125 result->SetBoolean(keys::kSelectedKey,
126 tab_strip && tab_index == tab_strip->active_index());
127 result->SetBoolean(keys::kHighlightedKey,
128 tab_strip && tab_strip->IsTabSelected(tab_index));
129 result->SetBoolean(keys::kPinnedKey,
130 tab_strip && tab_strip->IsTabPinned(tab_index));
131 result->SetBoolean(keys::kIncognitoKey,
132 contents->GetBrowserContext()->IsOffTheRecord());
133 result->SetInteger(keys::kWidthKey,
134 contents->GetContainerBounds().size().width());
135 result->SetInteger(keys::kHeightKey,
136 contents->GetContainerBounds().size().height());
137
138 // Privacy-sensitive fields: these should be stripped off by
139 // ScrubTabValueForExtension if the extension should not see them.
140 result->SetString(keys::kUrlKey, contents->GetURL().spec());
141 result->SetString(keys::kTitleKey, contents->GetTitle());
142 if (!is_loading) {
143 NavigationEntry* entry = contents->GetController().GetVisibleEntry();
144 if (entry && entry->GetFavicon().valid)
145 result->SetString(keys::kFaviconUrlKey, entry->GetFavicon().url.spec());
146 }
147
148 if (tab_strip) {
149 WebContents* opener = tab_strip->GetOpenerOfWebContentsAt(tab_index);
150 if (opener)
151 result->SetInteger(keys::kOpenerTabIdKey, GetTabId(opener));
152 }
153
154 return result;
84 } 155 }
85 156
86 base::ListValue* ExtensionTabUtil::CreateTabList( 157 base::ListValue* ExtensionTabUtil::CreateTabList(
87 const Browser* browser, 158 const Browser* browser,
88 const Extension* extension) { 159 const Extension* extension) {
89 return new base::ListValue(); 160 return new base::ListValue();
90 } 161 }
91 162
92 base::DictionaryValue* ExtensionTabUtil::CreateTabValue( 163 base::DictionaryValue* ExtensionTabUtil::CreateTabValue(
93 WebContents* contents, 164 WebContents* contents,
94 TabStripModel* tab_strip, 165 TabStripModel* tab_strip,
95 int tab_index) { 166 int tab_index) {
96 NOTREACHED(); 167 // If we have a matching AppWindow with a controller, get the tab value
97 return NULL; 168 // from its controller instead.
169 WindowController* controller = GetAppWindowController(contents);
170 if (controller)
171 return controller->CreateTabValue(NULL, tab_index);
172
173 if (!tab_strip)
174 ExtensionTabUtil::GetTabStripModel(contents, &tab_strip, &tab_index);
175
176 base::DictionaryValue* result = new base::DictionaryValue();
177 bool is_loading = contents->IsLoading();
178 result->SetInteger(keys::kIdKey, GetTabId(contents));
179 result->SetInteger(keys::kIndexKey, tab_index);
180 result->SetInteger(keys::kWindowIdKey, GetWindowIdOfTab(contents));
181 result->SetString(keys::kStatusKey, GetTabStatusText(is_loading));
182 result->SetBoolean(keys::kActiveKey,
183 tab_strip && tab_index == tab_strip->active_index());
184 result->SetBoolean(keys::kSelectedKey,
185 tab_strip && tab_index == tab_strip->active_index());
186 result->SetBoolean(keys::kHighlightedKey,
187 tab_strip && tab_strip->IsTabSelected(tab_index));
188 result->SetBoolean(keys::kPinnedKey,
189 tab_strip && tab_strip->IsTabPinned(tab_index));
190 result->SetBoolean(keys::kIncognitoKey,
191 contents->GetBrowserContext()->IsOffTheRecord());
192 result->SetInteger(keys::kWidthKey,
193 contents->GetContainerBounds().size().width());
194 result->SetInteger(keys::kHeightKey,
195 contents->GetContainerBounds().size().height());
196
197 // Privacy-sensitive fields: these should be stripped off by
198 // ScrubTabValueForExtension if the extension should not see them.
199 result->SetString(keys::kUrlKey, contents->GetURL().spec());
200 result->SetString(keys::kTitleKey, contents->GetTitle());
201 if (!is_loading) {
202 NavigationEntry* entry = contents->GetController().GetVisibleEntry();
203 if (entry && entry->GetFavicon().valid)
204 result->SetString(keys::kFaviconUrlKey, entry->GetFavicon().url.spec());
205 }
206
207 if (tab_strip) {
208 WebContents* opener = tab_strip->GetOpenerOfWebContentsAt(tab_index);
209 if (opener)
210 result->SetInteger(keys::kOpenerTabIdKey, GetTabId(opener));
211 }
212
213 return result;
98 } 214 }
99 215
100 void ExtensionTabUtil::ScrubTabValueForExtension( 216 void ExtensionTabUtil::ScrubTabValueForExtension(
101 WebContents* contents, 217 WebContents* contents,
102 const Extension* extension, 218 const Extension* extension,
103 base::DictionaryValue* tab_info) { 219 base::DictionaryValue* tab_info) {
104 // TODO(oshima): Move this to common impl. 220 // TODO(oshima): Move this to common impl.
105 } 221 }
106 222
107 void ExtensionTabUtil::ScrubTabForExtension(const Extension* extension, 223 void ExtensionTabUtil::ScrubTabForExtension(const Extension* extension,
108 api::tabs::Tab* tab) { 224 api::tabs::Tab* tab) {
109 225
110 // TODO(oshima): Move this to common impl. 226 // TODO(oshima): Move this to common impl.
111 } 227 }
112 228
113 bool ExtensionTabUtil::GetTabStripModel(const WebContents* web_contents, 229 bool ExtensionTabUtil::GetTabStripModel(const WebContents* web_contents,
114 TabStripModel** tab_strip_model, 230 TabStripModel** tab_strip_model,
115 int* tab_index) { 231 int* tab_index) {
116 NOTIMPLEMENTED(); 232 DCHECK(web_contents);
233 DCHECK(tab_strip_model);
234 DCHECK(tab_index);
235
236 for (chrome::BrowserIterator it; !it.done(); it.Next()) {
oshima 2014/10/24 14:41:26 there is no browser / tabstrip in athena. how doe
Nikita (slow) 2014/10/24 15:10:47 I need to double check, maybe this method is not n
Nikita (slow) 2014/10/27 10:56:50 This method is not really needed for a fix, remove
237 TabStripModel* tab_strip = it->tab_strip_model();
238 int index = tab_strip->GetIndexOfWebContents(web_contents);
239 if (index != -1) {
240 *tab_strip_model = tab_strip;
241 *tab_index = index;
242 return true;
243 }
244 }
245
117 return false; 246 return false;
118 } 247 }
119 248
120 bool ExtensionTabUtil::GetDefaultTab(Browser* browser, 249 bool ExtensionTabUtil::GetDefaultTab(Browser* browser,
121 WebContents** contents, 250 WebContents** contents,
122 int* tab_id) { 251 int* tab_id) {
123 NOTREACHED(); 252 NOTREACHED();
124 return false; 253 return false;
125 } 254 }
126 255
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
161 290
162 // static 291 // static
163 WindowController* ExtensionTabUtil::GetWindowControllerOfTab( 292 WindowController* ExtensionTabUtil::GetWindowControllerOfTab(
164 const WebContents* web_contents) { 293 const WebContents* web_contents) {
165 NOTIMPLEMENTED(); 294 NOTIMPLEMENTED();
166 return NULL; 295 return NULL;
167 } 296 }
168 297
169 void ExtensionTabUtil::OpenOptionsPage(const Extension* extension, 298 void ExtensionTabUtil::OpenOptionsPage(const Extension* extension,
170 Browser* browser) { 299 Browser* browser) {
171 // NOTIMPLEMENTED(); 300 NOTIMPLEMENTED();
172 } 301 }
173 302
174 } // namespace extensions 303 } // namespace extensions
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698