| 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/app_window.h" |
| 8 #include "apps/shell_window_registry.h" | 8 #include "apps/app_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" |
| 11 #include "chrome/browser/extensions/window_controller.h" | 11 #include "chrome/browser/extensions/window_controller.h" |
| 12 #include "chrome/browser/extensions/window_controller_list.h" | 12 #include "chrome/browser/extensions/window_controller_list.h" |
| 13 #include "chrome/browser/profiles/profile.h" | 13 #include "chrome/browser/profiles/profile.h" |
| 14 #include "chrome/browser/sessions/session_id.h" | 14 #include "chrome/browser/sessions/session_id.h" |
| 15 #include "chrome/browser/ui/browser.h" | 15 #include "chrome/browser/ui/browser.h" |
| 16 #include "chrome/browser/ui/browser_finder.h" | 16 #include "chrome/browser/ui/browser_finder.h" |
| 17 #include "chrome/browser/ui/browser_iterator.h" | 17 #include "chrome/browser/ui/browser_iterator.h" |
| 18 #include "chrome/browser/ui/browser_window.h" | 18 #include "chrome/browser/ui/browser_window.h" |
| 19 #include "chrome/browser/ui/scoped_tabbed_browser_displayer.h" | 19 #include "chrome/browser/ui/scoped_tabbed_browser_displayer.h" |
| 20 #include "chrome/browser/ui/tab_contents/tab_contents_iterator.h" | 20 #include "chrome/browser/ui/tab_contents/tab_contents_iterator.h" |
| 21 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 21 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| 22 #include "chrome/common/extensions/manifest_url_handler.h" | 22 #include "chrome/common/extensions/manifest_url_handler.h" |
| 23 #include "chrome/common/net/url_fixer_upper.h" | 23 #include "chrome/common/net/url_fixer_upper.h" |
| 24 #include "chrome/common/url_constants.h" | 24 #include "chrome/common/url_constants.h" |
| 25 #include "content/public/browser/favicon_status.h" | 25 #include "content/public/browser/favicon_status.h" |
| 26 #include "content/public/browser/navigation_entry.h" | 26 #include "content/public/browser/navigation_entry.h" |
| 27 #include "content/public/browser/web_contents.h" | 27 #include "content/public/browser/web_contents.h" |
| 28 #include "content/public/browser/web_contents_view.h" | 28 #include "content/public/browser/web_contents_view.h" |
| 29 #include "extensions/common/extension.h" | 29 #include "extensions/common/extension.h" |
| 30 #include "extensions/common/manifest_constants.h" | 30 #include "extensions/common/manifest_constants.h" |
| 31 #include "extensions/common/permissions/api_permission.h" | 31 #include "extensions/common/permissions/api_permission.h" |
| 32 #include "extensions/common/permissions/permissions_data.h" | 32 #include "extensions/common/permissions/permissions_data.h" |
| 33 #include "url/gurl.h" | 33 #include "url/gurl.h" |
| 34 | 34 |
| 35 using apps::ShellWindow; | 35 using apps::AppWindow; |
| 36 using content::NavigationEntry; | 36 using content::NavigationEntry; |
| 37 using content::WebContents; | 37 using content::WebContents; |
| 38 | 38 |
| 39 namespace extensions { | 39 namespace extensions { |
| 40 | 40 |
| 41 namespace { | 41 namespace { |
| 42 | 42 |
| 43 namespace keys = tabs_constants; | 43 namespace keys = tabs_constants; |
| 44 | 44 |
| 45 WindowController* GetShellWindowController(const WebContents* contents) { | 45 WindowController* GetAppWindowController(const WebContents* contents) { |
| 46 Profile* profile = Profile::FromBrowserContext(contents->GetBrowserContext()); | 46 Profile* profile = Profile::FromBrowserContext(contents->GetBrowserContext()); |
| 47 apps::ShellWindowRegistry* registry = | 47 apps::AppWindowRegistry* registry = apps::AppWindowRegistry::Get(profile); |
| 48 apps::ShellWindowRegistry::Get(profile); | |
| 49 if (!registry) | 48 if (!registry) |
| 50 return NULL; | 49 return NULL; |
| 51 ShellWindow* shell_window = | 50 AppWindow* app_window = |
| 52 registry->GetShellWindowForRenderViewHost(contents->GetRenderViewHost()); | 51 registry->GetAppWindowForRenderViewHost(contents->GetRenderViewHost()); |
| 53 if (!shell_window) | 52 if (!app_window) |
| 54 return NULL; | 53 return NULL; |
| 55 return WindowControllerList::GetInstance()->FindWindowById( | 54 return WindowControllerList::GetInstance()->FindWindowById( |
| 56 shell_window->session_id().id()); | 55 app_window->session_id().id()); |
| 57 } | 56 } |
| 58 | 57 |
| 59 } // namespace | 58 } // namespace |
| 60 | 59 |
| 61 int ExtensionTabUtil::GetWindowId(const Browser* browser) { | 60 int ExtensionTabUtil::GetWindowId(const Browser* browser) { |
| 62 return browser->session_id().id(); | 61 return browser->session_id().id(); |
| 63 } | 62 } |
| 64 | 63 |
| 65 int ExtensionTabUtil::GetWindowIdOfTabStripModel( | 64 int ExtensionTabUtil::GetWindowIdOfTabStripModel( |
| 66 const TabStripModel* tab_strip_model) { | 65 const TabStripModel* tab_strip_model) { |
| (...skipping 14 matching lines...) Expand all Loading... |
| 81 | 80 |
| 82 int ExtensionTabUtil::GetWindowIdOfTab(const WebContents* web_contents) { | 81 int ExtensionTabUtil::GetWindowIdOfTab(const WebContents* web_contents) { |
| 83 return SessionID::IdForWindowContainingTab(web_contents); | 82 return SessionID::IdForWindowContainingTab(web_contents); |
| 84 } | 83 } |
| 85 | 84 |
| 86 base::DictionaryValue* ExtensionTabUtil::CreateTabValue( | 85 base::DictionaryValue* ExtensionTabUtil::CreateTabValue( |
| 87 const WebContents* contents, | 86 const WebContents* contents, |
| 88 TabStripModel* tab_strip, | 87 TabStripModel* tab_strip, |
| 89 int tab_index, | 88 int tab_index, |
| 90 const Extension* extension) { | 89 const Extension* extension) { |
| 91 // If we have a matching ShellWindow with a controller, get the tab value | 90 // If we have a matching AppWindow with a controller, get the tab value |
| 92 // from its controller instead. | 91 // from its controller instead. |
| 93 WindowController* controller = GetShellWindowController(contents); | 92 WindowController* controller = GetAppWindowController(contents); |
| 94 if (controller && | 93 if (controller && |
| 95 (!extension || controller->IsVisibleToExtension(extension))) { | 94 (!extension || controller->IsVisibleToExtension(extension))) { |
| 96 return controller->CreateTabValue(extension, tab_index); | 95 return controller->CreateTabValue(extension, tab_index); |
| 97 } | 96 } |
| 98 base::DictionaryValue* result = | 97 base::DictionaryValue* result = |
| 99 CreateTabValue(contents, tab_strip, tab_index); | 98 CreateTabValue(contents, tab_strip, tab_index); |
| 100 ScrubTabValueForExtension(contents, extension, result); | 99 ScrubTabValueForExtension(contents, extension, result); |
| 101 return result; | 100 return result; |
| 102 } | 101 } |
| 103 | 102 |
| 104 base::ListValue* ExtensionTabUtil::CreateTabList( | 103 base::ListValue* ExtensionTabUtil::CreateTabList( |
| 105 const Browser* browser, | 104 const Browser* browser, |
| 106 const Extension* extension) { | 105 const Extension* extension) { |
| 107 base::ListValue* tab_list = new base::ListValue(); | 106 base::ListValue* tab_list = new base::ListValue(); |
| 108 TabStripModel* tab_strip = browser->tab_strip_model(); | 107 TabStripModel* tab_strip = browser->tab_strip_model(); |
| 109 for (int i = 0; i < tab_strip->count(); ++i) { | 108 for (int i = 0; i < tab_strip->count(); ++i) { |
| 110 tab_list->Append(CreateTabValue(tab_strip->GetWebContentsAt(i), | 109 tab_list->Append(CreateTabValue(tab_strip->GetWebContentsAt(i), |
| 111 tab_strip, | 110 tab_strip, |
| 112 i, | 111 i, |
| 113 extension)); | 112 extension)); |
| 114 } | 113 } |
| 115 | 114 |
| 116 return tab_list; | 115 return tab_list; |
| 117 } | 116 } |
| 118 | 117 |
| 119 base::DictionaryValue* ExtensionTabUtil::CreateTabValue( | 118 base::DictionaryValue* ExtensionTabUtil::CreateTabValue( |
| 120 const WebContents* contents, | 119 const WebContents* contents, |
| 121 TabStripModel* tab_strip, | 120 TabStripModel* tab_strip, |
| 122 int tab_index) { | 121 int tab_index) { |
| 123 // If we have a matching ShellWindow with a controller, get the tab value | 122 // If we have a matching AppWindow with a controller, get the tab value |
| 124 // from its controller instead. | 123 // from its controller instead. |
| 125 WindowController* controller = GetShellWindowController(contents); | 124 WindowController* controller = GetAppWindowController(contents); |
| 126 if (controller) | 125 if (controller) |
| 127 return controller->CreateTabValue(NULL, tab_index); | 126 return controller->CreateTabValue(NULL, tab_index); |
| 128 | 127 |
| 129 if (!tab_strip) | 128 if (!tab_strip) |
| 130 ExtensionTabUtil::GetTabStripModel(contents, &tab_strip, &tab_index); | 129 ExtensionTabUtil::GetTabStripModel(contents, &tab_strip, &tab_index); |
| 131 | 130 |
| 132 base::DictionaryValue* result = new base::DictionaryValue(); | 131 base::DictionaryValue* result = new base::DictionaryValue(); |
| 133 bool is_loading = contents->IsLoading(); | 132 bool is_loading = contents->IsLoading(); |
| 134 result->SetInteger(keys::kIdKey, GetTabId(contents)); | 133 result->SetInteger(keys::kIdKey, GetTabId(contents)); |
| 135 result->SetInteger(keys::kIndexKey, tab_index); | 134 result->SetInteger(keys::kIndexKey, tab_index); |
| (...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 355 content::PAGE_TRANSITION_LINK, | 354 content::PAGE_TRANSITION_LINK, |
| 356 false); | 355 false); |
| 357 browser->OpenURL(params); | 356 browser->OpenURL(params); |
| 358 browser->window()->Show(); | 357 browser->window()->Show(); |
| 359 WebContents* web_contents = | 358 WebContents* web_contents = |
| 360 browser->tab_strip_model()->GetActiveWebContents(); | 359 browser->tab_strip_model()->GetActiveWebContents(); |
| 361 web_contents->GetDelegate()->ActivateContents(web_contents); | 360 web_contents->GetDelegate()->ActivateContents(web_contents); |
| 362 } | 361 } |
| 363 | 362 |
| 364 } // namespace extensions | 363 } // namespace extensions |
| OLD | NEW |