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