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 "apps/shell_window.h" | 7 #include "apps/shell_window.h" |
8 #include "apps/shell_window_registry.h" | 8 #include "apps/shell_window_registry.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/tab_helper.h" | 10 #include "chrome/browser/extensions/tab_helper.h" |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
45 WindowController* GetShellWindowController(const WebContents* contents) { | 45 WindowController* GetShellWindowController(const WebContents* contents) { |
46 Profile* profile = Profile::FromBrowserContext(contents->GetBrowserContext()); | 46 Profile* profile = Profile::FromBrowserContext(contents->GetBrowserContext()); |
47 apps::ShellWindowRegistry* registry = | 47 apps::ShellWindowRegistry* registry = |
48 apps::ShellWindowRegistry::Get(profile); | 48 apps::ShellWindowRegistry::Get(profile); |
49 if (!registry) | 49 if (!registry) |
50 return NULL; | 50 return NULL; |
51 ShellWindow* shell_window = | 51 ShellWindow* shell_window = |
52 registry->GetShellWindowForRenderViewHost(contents->GetRenderViewHost()); | 52 registry->GetShellWindowForRenderViewHost(contents->GetRenderViewHost()); |
53 if (!shell_window) | 53 if (!shell_window) |
54 return NULL; | 54 return NULL; |
55 return WindowControllerList::GetInstance()-> | 55 return WindowControllerList::GetInstance()->FindWindowById( |
56 FindWindowById(shell_window->session_id().id()); | 56 shell_window->session_id().id()); |
57 } | 57 } |
58 | 58 |
59 } // namespace | 59 } // namespace |
60 | 60 |
61 int ExtensionTabUtil::GetWindowId(const Browser* browser) { | 61 int ExtensionTabUtil::GetWindowId(const Browser* browser) { |
62 return browser->session_id().id(); | 62 return browser->session_id().id(); |
63 } | 63 } |
64 | 64 |
65 int ExtensionTabUtil::GetWindowIdOfTabStripModel( | 65 int ExtensionTabUtil::GetWindowIdOfTabStripModel( |
66 const TabStripModel* tab_strip_model) { | 66 const TabStripModel* tab_strip_model) { |
(...skipping 21 matching lines...) Expand all Loading... |
88 TabStripModel* tab_strip, | 88 TabStripModel* tab_strip, |
89 int tab_index, | 89 int tab_index, |
90 const Extension* extension) { | 90 const Extension* extension) { |
91 // If we have a matching ShellWindow with a controller, get the tab value | 91 // If we have a matching ShellWindow with a controller, get the tab value |
92 // from its controller instead. | 92 // from its controller instead. |
93 WindowController* controller = GetShellWindowController(contents); | 93 WindowController* controller = GetShellWindowController(contents); |
94 if (controller && | 94 if (controller && |
95 (!extension || controller->IsVisibleToExtension(extension))) { | 95 (!extension || controller->IsVisibleToExtension(extension))) { |
96 return controller->CreateTabValue(extension, tab_index); | 96 return controller->CreateTabValue(extension, tab_index); |
97 } | 97 } |
98 base::DictionaryValue *result = | 98 base::DictionaryValue* result = |
99 CreateTabValue(contents, tab_strip, tab_index); | 99 CreateTabValue(contents, tab_strip, tab_index); |
100 ScrubTabValueForExtension(contents, extension, result); | 100 ScrubTabValueForExtension(contents, extension, result); |
101 return result; | 101 return result; |
102 } | 102 } |
103 | 103 |
104 base::ListValue* ExtensionTabUtil::CreateTabList( | 104 base::ListValue* ExtensionTabUtil::CreateTabList( |
105 const Browser* browser, | 105 const Browser* browser, |
106 const Extension* extension) { | 106 const Extension* extension) { |
107 base::ListValue* tab_list = new base::ListValue(); | 107 base::ListValue* tab_list = new base::ListValue(); |
108 TabStripModel* tab_strip = browser->tab_strip_model(); | 108 TabStripModel* tab_strip = browser->tab_strip_model(); |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
162 | 162 |
163 if (tab_strip) { | 163 if (tab_strip) { |
164 WebContents* opener = tab_strip->GetOpenerOfWebContentsAt(tab_index); | 164 WebContents* opener = tab_strip->GetOpenerOfWebContentsAt(tab_index); |
165 if (opener) | 165 if (opener) |
166 result->SetInteger(keys::kOpenerTabIdKey, GetTabId(opener)); | 166 result->SetInteger(keys::kOpenerTabIdKey, GetTabId(opener)); |
167 } | 167 } |
168 | 168 |
169 return result; | 169 return result; |
170 } | 170 } |
171 | 171 |
| 172 base::DictionaryValue* ExtensionTabUtil::CreateTabValueForPlatformApp( |
| 173 const WebContents* contents) { |
| 174 base::DictionaryValue* result = new base::DictionaryValue(); |
| 175 result->SetInteger(keys::kIdKey, GetTabId(contents)); |
| 176 result->SetBoolean("isPlatformApp", true); |
| 177 return result; |
| 178 } |
| 179 |
172 void ExtensionTabUtil::ScrubTabValueForExtension( | 180 void ExtensionTabUtil::ScrubTabValueForExtension( |
173 const WebContents* contents, | 181 const WebContents* contents, |
174 const Extension* extension, | 182 const Extension* extension, |
175 base::DictionaryValue* tab_info) { | 183 base::DictionaryValue* tab_info) { |
176 bool has_permission = | 184 bool has_permission = |
177 extension && | 185 extension && |
178 PermissionsData::HasAPIPermissionForTab( | 186 PermissionsData::HasAPIPermissionForTab( |
179 extension, GetTabId(contents), APIPermission::kTab); | 187 extension, GetTabId(contents), APIPermission::kTab); |
180 | 188 |
181 if (!has_permission) { | 189 if (!has_permission) { |
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
355 content::PAGE_TRANSITION_LINK, | 363 content::PAGE_TRANSITION_LINK, |
356 false); | 364 false); |
357 browser->OpenURL(params); | 365 browser->OpenURL(params); |
358 browser->window()->Show(); | 366 browser->window()->Show(); |
359 WebContents* web_contents = | 367 WebContents* web_contents = |
360 browser->tab_strip_model()->GetActiveWebContents(); | 368 browser->tab_strip_model()->GetActiveWebContents(); |
361 web_contents->GetDelegate()->ActivateContents(web_contents); | 369 web_contents->GetDelegate()->ActivateContents(web_contents); |
362 } | 370 } |
363 | 371 |
364 } // namespace extensions | 372 } // namespace extensions |
OLD | NEW |