| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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_tabs_module.h" | 5 #include "chrome/browser/extensions/extension_tabs_module.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/base64.h" | 10 #include "base/base64.h" |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 71 | 71 |
| 72 if (error_message) | 72 if (error_message) |
| 73 *error_message = ExtensionErrorUtils::FormatErrorMessage( | 73 *error_message = ExtensionErrorUtils::FormatErrorMessage( |
| 74 keys::kWindowNotFoundError, base::IntToString(window_id)); | 74 keys::kWindowNotFoundError, base::IntToString(window_id)); |
| 75 | 75 |
| 76 return NULL; | 76 return NULL; |
| 77 } | 77 } |
| 78 | 78 |
| 79 // |error_message| can optionally be passed in and will be set with an | 79 // |error_message| can optionally be passed in and will be set with an |
| 80 // appropriate message if the tab cannot be found by id. | 80 // appropriate message if the tab cannot be found by id. |
| 81 bool GetTabById(int tab_id, Profile* profile, | 81 bool GetTabById(int tab_id, |
| 82 Profile* profile, |
| 82 bool include_incognito, | 83 bool include_incognito, |
| 83 Browser** browser, | 84 Browser** browser, |
| 84 TabStripModel** tab_strip, | 85 TabStripModel** tab_strip, |
| 85 TabContentsWrapper** contents, | 86 TabContentsWrapper** contents, |
| 86 int* tab_index, | 87 int* tab_index, |
| 87 std::string* error_message) { | 88 std::string* error_message) { |
| 88 if (ExtensionTabUtil::GetTabById(tab_id, profile, include_incognito, | 89 if (ExtensionTabUtil::GetTabById(tab_id, profile, include_incognito, |
| 89 browser, tab_strip, contents, tab_index)) | 90 browser, tab_strip, contents, tab_index)) |
| 90 return true; | 91 return true; |
| 91 | 92 |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 157 ListValue* tab_list = new ListValue(); | 158 ListValue* tab_list = new ListValue(); |
| 158 TabStripModel* tab_strip = browser->tabstrip_model(); | 159 TabStripModel* tab_strip = browser->tabstrip_model(); |
| 159 for (int i = 0; i < tab_strip->count(); ++i) { | 160 for (int i = 0; i < tab_strip->count(); ++i) { |
| 160 tab_list->Append(ExtensionTabUtil::CreateTabValue( | 161 tab_list->Append(ExtensionTabUtil::CreateTabValue( |
| 161 tab_strip->GetTabContentsAt(i)->tab_contents(), tab_strip, i)); | 162 tab_strip->GetTabContentsAt(i)->tab_contents(), tab_strip, i)); |
| 162 } | 163 } |
| 163 | 164 |
| 164 return tab_list; | 165 return tab_list; |
| 165 } | 166 } |
| 166 | 167 |
| 167 DictionaryValue* ExtensionTabUtil::CreateTabValue( | 168 DictionaryValue* ExtensionTabUtil::CreateTabValue(const TabContents* contents, |
| 168 const TabContents* contents, TabStripModel* tab_strip, int tab_index) { | 169 TabStripModel* tab_strip, |
| 170 int tab_index) { |
| 169 DictionaryValue* result = new DictionaryValue(); | 171 DictionaryValue* result = new DictionaryValue(); |
| 170 result->SetInteger(keys::kIdKey, ExtensionTabUtil::GetTabId(contents)); | 172 result->SetInteger(keys::kIdKey, ExtensionTabUtil::GetTabId(contents)); |
| 171 result->SetInteger(keys::kIndexKey, tab_index); | 173 result->SetInteger(keys::kIndexKey, tab_index); |
| 172 result->SetInteger(keys::kWindowIdKey, | 174 result->SetInteger(keys::kWindowIdKey, |
| 173 ExtensionTabUtil::GetWindowIdOfTab(contents)); | 175 ExtensionTabUtil::GetWindowIdOfTab(contents)); |
| 174 result->SetString(keys::kUrlKey, contents->GetURL().spec()); | 176 result->SetString(keys::kUrlKey, contents->GetURL().spec()); |
| 175 result->SetString(keys::kStatusKey, GetTabStatusText(contents->is_loading())); | 177 result->SetString(keys::kStatusKey, GetTabStatusText(contents->is_loading())); |
| 176 result->SetBoolean(keys::kSelectedKey, | 178 result->SetBoolean(keys::kSelectedKey, |
| 177 tab_strip && tab_index == tab_strip->active_index()); | 179 tab_strip && tab_index == tab_strip->active_index()); |
| 178 result->SetBoolean(keys::kPinnedKey, | 180 result->SetBoolean(keys::kPinnedKey, |
| 179 tab_strip && tab_strip->IsTabPinned(tab_index)); | 181 tab_strip && tab_strip->IsTabPinned(tab_index)); |
| 180 result->SetString(keys::kTitleKey, contents->GetTitle()); | 182 result->SetString(keys::kTitleKey, contents->GetTitle()); |
| 181 result->SetBoolean(keys::kIncognitoKey, | 183 result->SetBoolean(keys::kIncognitoKey, |
| 182 contents->profile()->IsOffTheRecord()); | 184 contents->profile()->IsOffTheRecord()); |
| 183 | 185 |
| 184 if (!contents->is_loading()) { | 186 if (!contents->is_loading()) { |
| 185 NavigationEntry* entry = contents->controller().GetActiveEntry(); | 187 NavigationEntry* entry = contents->controller().GetActiveEntry(); |
| 186 if (entry) { | 188 if (entry) { |
| 187 if (entry->favicon().is_valid()) | 189 if (entry->favicon().is_valid()) |
| 188 result->SetString(keys::kFaviconUrlKey, entry->favicon().url().spec()); | 190 result->SetString(keys::kFaviconUrlKey, entry->favicon().url().spec()); |
| 189 } | 191 } |
| 190 } | 192 } |
| 191 | 193 |
| 192 return result; | 194 return result; |
| 193 } | 195 } |
| 194 | 196 |
| 197 DictionaryValue* ExtensionTabUtil::CreateTabValueActive( |
| 198 const TabContents* contents, |
| 199 bool active) { |
| 200 DictionaryValue* result = ExtensionTabUtil::CreateTabValue(contents); |
| 201 result->SetBoolean(keys::kSelectedKey, active); |
| 202 return result; |
| 203 } |
| 204 |
| 195 // if |populate| is true, each window gets a list property |tabs| which contains | 205 // if |populate| is true, each window gets a list property |tabs| which contains |
| 196 // fully populated tab objects. | 206 // fully populated tab objects. |
| 197 DictionaryValue* ExtensionTabUtil::CreateWindowValue(const Browser* browser, | 207 DictionaryValue* ExtensionTabUtil::CreateWindowValue(const Browser* browser, |
| 198 bool populate_tabs) { | 208 bool populate_tabs) { |
| 199 DCHECK(browser); | 209 DCHECK(browser); |
| 200 DCHECK(browser->window()); | 210 DCHECK(browser->window()); |
| 201 DictionaryValue* result = new DictionaryValue(); | 211 DictionaryValue* result = new DictionaryValue(); |
| 202 result->SetInteger(keys::kIdKey, ExtensionTabUtil::GetWindowId(browser)); | 212 result->SetInteger(keys::kIdKey, ExtensionTabUtil::GetWindowId(browser)); |
| 203 result->SetBoolean(keys::kIncognitoKey, | 213 result->SetBoolean(keys::kIncognitoKey, |
| 204 browser->profile()->IsOffTheRecord()); | 214 browser->profile()->IsOffTheRecord()); |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 253 *contents = browser->GetSelectedTabContentsWrapper(); | 263 *contents = browser->GetSelectedTabContentsWrapper(); |
| 254 if (*contents) { | 264 if (*contents) { |
| 255 if (tab_id) | 265 if (tab_id) |
| 256 *tab_id = ExtensionTabUtil::GetTabId((*contents)->tab_contents()); | 266 *tab_id = ExtensionTabUtil::GetTabId((*contents)->tab_contents()); |
| 257 return true; | 267 return true; |
| 258 } | 268 } |
| 259 | 269 |
| 260 return false; | 270 return false; |
| 261 } | 271 } |
| 262 | 272 |
| 263 bool ExtensionTabUtil::GetTabById(int tab_id, Profile* profile, | 273 bool ExtensionTabUtil::GetTabById(int tab_id, |
| 274 Profile* profile, |
| 264 bool include_incognito, | 275 bool include_incognito, |
| 265 Browser** browser, | 276 Browser** browser, |
| 266 TabStripModel** tab_strip, | 277 TabStripModel** tab_strip, |
| 267 TabContentsWrapper** contents, | 278 TabContentsWrapper** contents, |
| 268 int* tab_index) { | 279 int* tab_index) { |
| 269 Profile* incognito_profile = | 280 Profile* incognito_profile = |
| 270 include_incognito && profile->HasOffTheRecordProfile() ? | 281 include_incognito && profile->HasOffTheRecordProfile() ? |
| 271 profile->GetOffTheRecordProfile() : NULL; | 282 profile->GetOffTheRecordProfile() : NULL; |
| 272 for (BrowserList::const_iterator iter = BrowserList::begin(); | 283 for (BrowserList::const_iterator iter = BrowserList::begin(); |
| 273 iter != BrowserList::end(); ++iter) { | 284 iter != BrowserList::end(); ++iter) { |
| (...skipping 339 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 613 if (update_props->HasKey(keys::kHeightKey)) { | 624 if (update_props->HasKey(keys::kHeightKey)) { |
| 614 EXTENSION_FUNCTION_VALIDATE(update_props->GetInteger( | 625 EXTENSION_FUNCTION_VALIDATE(update_props->GetInteger( |
| 615 keys::kHeightKey, | 626 keys::kHeightKey, |
| 616 &bounds_val)); | 627 &bounds_val)); |
| 617 bounds.set_height(bounds_val); | 628 bounds.set_height(bounds_val); |
| 618 set_bounds = true; | 629 set_bounds = true; |
| 619 } | 630 } |
| 620 if (set_bounds) | 631 if (set_bounds) |
| 621 browser->window()->SetBounds(bounds); | 632 browser->window()->SetBounds(bounds); |
| 622 | 633 |
| 623 bool selected_val = false; | 634 bool active_val = false; |
| 624 if (update_props->HasKey(keys::kFocusedKey)) { | 635 if (update_props->HasKey(keys::kFocusedKey)) { |
| 625 EXTENSION_FUNCTION_VALIDATE(update_props->GetBoolean( | 636 EXTENSION_FUNCTION_VALIDATE(update_props->GetBoolean( |
| 626 keys::kFocusedKey, &selected_val)); | 637 keys::kFocusedKey, &active_val)); |
| 627 if (selected_val) | 638 if (active_val) |
| 628 browser->window()->Activate(); | 639 browser->window()->Activate(); |
| 629 else | 640 else |
| 630 browser->window()->Deactivate(); | 641 browser->window()->Deactivate(); |
| 631 } | 642 } |
| 632 | 643 |
| 633 result_.reset(ExtensionTabUtil::CreateWindowValue(browser, false)); | 644 result_.reset(ExtensionTabUtil::CreateWindowValue(browser, false)); |
| 634 | 645 |
| 635 return true; | 646 return true; |
| 636 } | 647 } |
| 637 | 648 |
| (...skipping 705 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1343 // called for every API call the extension made. | 1354 // called for every API call the extension made. |
| 1344 GotLanguage(language); | 1355 GotLanguage(language); |
| 1345 } | 1356 } |
| 1346 | 1357 |
| 1347 void DetectTabLanguageFunction::GotLanguage(const std::string& language) { | 1358 void DetectTabLanguageFunction::GotLanguage(const std::string& language) { |
| 1348 result_.reset(Value::CreateStringValue(language.c_str())); | 1359 result_.reset(Value::CreateStringValue(language.c_str())); |
| 1349 SendResponse(true); | 1360 SendResponse(true); |
| 1350 | 1361 |
| 1351 Release(); // Balanced in Run() | 1362 Release(); // Balanced in Run() |
| 1352 } | 1363 } |
| OLD | NEW |