| 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 667 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 678 include_incognito(), &error_); | 678 include_incognito(), &error_); |
| 679 } else { | 679 } else { |
| 680 browser = GetCurrentBrowser(); | 680 browser = GetCurrentBrowser(); |
| 681 if (!browser) | 681 if (!browser) |
| 682 error_ = keys::kNoCurrentWindowError; | 682 error_ = keys::kNoCurrentWindowError; |
| 683 } | 683 } |
| 684 if (!browser) | 684 if (!browser) |
| 685 return false; | 685 return false; |
| 686 | 686 |
| 687 TabStripModel* tab_strip = browser->tabstrip_model(); | 687 TabStripModel* tab_strip = browser->tabstrip_model(); |
| 688 TabContentsWrapper* contents = tab_strip->GetSelectedTabContents(); | 688 TabContentsWrapper* contents = tab_strip->GetActiveTabContents(); |
| 689 if (!contents) { | 689 if (!contents) { |
| 690 error_ = keys::kNoSelectedTabError; | 690 error_ = keys::kNoSelectedTabError; |
| 691 return false; | 691 return false; |
| 692 } | 692 } |
| 693 result_.reset(ExtensionTabUtil::CreateTabValue(contents->tab_contents(), | 693 result_.reset(ExtensionTabUtil::CreateTabValue(contents->tab_contents(), |
| 694 tab_strip, | 694 tab_strip, |
| 695 tab_strip->active_index())); | 695 tab_strip->active_index())); |
| 696 return true; | 696 return true; |
| 697 } | 697 } |
| 698 | 698 |
| (...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 929 bool selected = false; | 929 bool selected = false; |
| 930 // TODO(rafaelw): Setting |selected| from js doesn't make much sense. | 930 // TODO(rafaelw): Setting |selected| from js doesn't make much sense. |
| 931 // Move tab selection management up to window. | 931 // Move tab selection management up to window. |
| 932 if (update_props->HasKey(keys::kSelectedKey)) { | 932 if (update_props->HasKey(keys::kSelectedKey)) { |
| 933 EXTENSION_FUNCTION_VALIDATE(update_props->GetBoolean( | 933 EXTENSION_FUNCTION_VALIDATE(update_props->GetBoolean( |
| 934 keys::kSelectedKey, | 934 keys::kSelectedKey, |
| 935 &selected)); | 935 &selected)); |
| 936 if (selected) { | 936 if (selected) { |
| 937 if (tab_strip->active_index() != tab_index) { | 937 if (tab_strip->active_index() != tab_index) { |
| 938 tab_strip->ActivateTabAt(tab_index, false); | 938 tab_strip->ActivateTabAt(tab_index, false); |
| 939 DCHECK_EQ(contents, tab_strip->GetSelectedTabContents()); | 939 DCHECK_EQ(contents, tab_strip->GetActiveTabContents()); |
| 940 } | 940 } |
| 941 contents->tab_contents()->Focus(); | 941 contents->tab_contents()->Focus(); |
| 942 } | 942 } |
| 943 } | 943 } |
| 944 | 944 |
| 945 bool pinned = false; | 945 bool pinned = false; |
| 946 if (update_props->HasKey(keys::kPinnedKey)) { | 946 if (update_props->HasKey(keys::kPinnedKey)) { |
| 947 EXTENSION_FUNCTION_VALIDATE(update_props->GetBoolean(keys::kPinnedKey, | 947 EXTENSION_FUNCTION_VALIDATE(update_props->GetBoolean(keys::kPinnedKey, |
| 948 &pinned)); | 948 &pinned)); |
| 949 tab_strip->SetTabPinned(tab_index, pinned); | 949 tab_strip->SetTabPinned(tab_index, pinned); |
| (...skipping 347 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1297 if (!GetTabById(tab_id, profile(), include_incognito(), | 1297 if (!GetTabById(tab_id, profile(), include_incognito(), |
| 1298 &browser, NULL, &contents, NULL, &error_)) { | 1298 &browser, NULL, &contents, NULL, &error_)) { |
| 1299 return false; | 1299 return false; |
| 1300 } | 1300 } |
| 1301 if (!browser || !contents) | 1301 if (!browser || !contents) |
| 1302 return false; | 1302 return false; |
| 1303 } else { | 1303 } else { |
| 1304 browser = GetCurrentBrowser(); | 1304 browser = GetCurrentBrowser(); |
| 1305 if (!browser) | 1305 if (!browser) |
| 1306 return false; | 1306 return false; |
| 1307 contents = browser->tabstrip_model()->GetSelectedTabContents(); | 1307 contents = browser->tabstrip_model()->GetActiveTabContents(); |
| 1308 if (!contents) | 1308 if (!contents) |
| 1309 return false; | 1309 return false; |
| 1310 } | 1310 } |
| 1311 | 1311 |
| 1312 if (contents->controller().needs_reload()) { | 1312 if (contents->controller().needs_reload()) { |
| 1313 // If the tab hasn't been loaded, don't wait for the tab to load. | 1313 // If the tab hasn't been loaded, don't wait for the tab to load. |
| 1314 error_ = keys::kCannotDetermineLanguageOfUnloadedTab; | 1314 error_ = keys::kCannotDetermineLanguageOfUnloadedTab; |
| 1315 return false; | 1315 return false; |
| 1316 } | 1316 } |
| 1317 | 1317 |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1350 // called for every API call the extension made. | 1350 // called for every API call the extension made. |
| 1351 GotLanguage(language); | 1351 GotLanguage(language); |
| 1352 } | 1352 } |
| 1353 | 1353 |
| 1354 void DetectTabLanguageFunction::GotLanguage(const std::string& language) { | 1354 void DetectTabLanguageFunction::GotLanguage(const std::string& language) { |
| 1355 result_.reset(Value::CreateStringValue(language.c_str())); | 1355 result_.reset(Value::CreateStringValue(language.c_str())); |
| 1356 SendResponse(true); | 1356 SendResponse(true); |
| 1357 | 1357 |
| 1358 Release(); // Balanced in Run() | 1358 Release(); // Balanced in Run() |
| 1359 } | 1359 } |
| OLD | NEW |