| 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/api/tabs/tabs.h" | 5 #include "chrome/browser/extensions/api/tabs/tabs.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <limits> | 8 #include <limits> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| (...skipping 23 matching lines...) Expand all Loading... |
| 34 #include "chrome/browser/sessions/restore_tab_helper.h" | 34 #include "chrome/browser/sessions/restore_tab_helper.h" |
| 35 #include "chrome/browser/translate/translate_tab_helper.h" | 35 #include "chrome/browser/translate/translate_tab_helper.h" |
| 36 #include "chrome/browser/ui/browser.h" | 36 #include "chrome/browser/ui/browser.h" |
| 37 #include "chrome/browser/ui/browser_finder.h" | 37 #include "chrome/browser/ui/browser_finder.h" |
| 38 #include "chrome/browser/ui/browser_list.h" | 38 #include "chrome/browser/ui/browser_list.h" |
| 39 #include "chrome/browser/ui/browser_navigator.h" | 39 #include "chrome/browser/ui/browser_navigator.h" |
| 40 #include "chrome/browser/ui/browser_window.h" | 40 #include "chrome/browser/ui/browser_window.h" |
| 41 #include "chrome/browser/ui/extensions/shell_window.h" | 41 #include "chrome/browser/ui/extensions/shell_window.h" |
| 42 #include "chrome/browser/ui/panels/panel_manager.h" | 42 #include "chrome/browser/ui/panels/panel_manager.h" |
| 43 #include "chrome/browser/ui/snapshot_tab_helper.h" | 43 #include "chrome/browser/ui/snapshot_tab_helper.h" |
| 44 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" | 44 #include "chrome/browser/ui/tab_contents/tab_contents.h" |
| 45 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 45 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| 46 #include "chrome/browser/ui/window_sizer.h" | 46 #include "chrome/browser/ui/window_sizer.h" |
| 47 #include "chrome/browser/web_applications/web_app.h" | 47 #include "chrome/browser/web_applications/web_app.h" |
| 48 #include "chrome/common/chrome_notification_types.h" | 48 #include "chrome/common/chrome_notification_types.h" |
| 49 #include "chrome/common/chrome_switches.h" | 49 #include "chrome/common/chrome_switches.h" |
| 50 #include "chrome/common/extensions/api/windows.h" | 50 #include "chrome/common/extensions/api/windows.h" |
| 51 #include "chrome/common/extensions/extension.h" | 51 #include "chrome/common/extensions/extension.h" |
| 52 #include "chrome/common/extensions/extension_error_utils.h" | 52 #include "chrome/common/extensions/extension_error_utils.h" |
| 53 #include "chrome/common/extensions/extension_manifest_constants.h" | 53 #include "chrome/common/extensions/extension_manifest_constants.h" |
| 54 #include "chrome/common/extensions/extension_messages.h" | 54 #include "chrome/common/extensions/extension_messages.h" |
| (...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 174 } | 174 } |
| 175 return true; | 175 return true; |
| 176 } | 176 } |
| 177 // |error_message| can optionally be passed in and will be set with an | 177 // |error_message| can optionally be passed in and will be set with an |
| 178 // appropriate message if the tab cannot be found by id. | 178 // appropriate message if the tab cannot be found by id. |
| 179 bool GetTabById(int tab_id, | 179 bool GetTabById(int tab_id, |
| 180 Profile* profile, | 180 Profile* profile, |
| 181 bool include_incognito, | 181 bool include_incognito, |
| 182 Browser** browser, | 182 Browser** browser, |
| 183 TabStripModel** tab_strip, | 183 TabStripModel** tab_strip, |
| 184 TabContentsWrapper** contents, | 184 TabContents** contents, |
| 185 int* tab_index, | 185 int* tab_index, |
| 186 std::string* error_message) { | 186 std::string* error_message) { |
| 187 if (ExtensionTabUtil::GetTabById(tab_id, profile, include_incognito, | 187 if (ExtensionTabUtil::GetTabById(tab_id, profile, include_incognito, |
| 188 browser, tab_strip, contents, tab_index)) | 188 browser, tab_strip, contents, tab_index)) |
| 189 return true; | 189 return true; |
| 190 | 190 |
| 191 if (error_message) | 191 if (error_message) |
| 192 *error_message = ExtensionErrorUtils::FormatErrorMessage( | 192 *error_message = ExtensionErrorUtils::FormatErrorMessage( |
| 193 keys::kTabNotFoundError, base::IntToString(tab_id)); | 193 keys::kTabNotFoundError, base::IntToString(tab_id)); |
| 194 | 194 |
| (...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 384 *is_error = true; | 384 *is_error = true; |
| 385 return false; | 385 return false; |
| 386 } | 386 } |
| 387 } | 387 } |
| 388 return incognito; | 388 return incognito; |
| 389 } | 389 } |
| 390 | 390 |
| 391 bool CreateWindowFunction::RunImpl() { | 391 bool CreateWindowFunction::RunImpl() { |
| 392 DictionaryValue* args = NULL; | 392 DictionaryValue* args = NULL; |
| 393 std::vector<GURL> urls; | 393 std::vector<GURL> urls; |
| 394 TabContentsWrapper* contents = NULL; | 394 TabContents* contents = NULL; |
| 395 | 395 |
| 396 if (HasOptionalArgument(0)) | 396 if (HasOptionalArgument(0)) |
| 397 EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(0, &args)); | 397 EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(0, &args)); |
| 398 | 398 |
| 399 // Look for optional url. | 399 // Look for optional url. |
| 400 if (args) { | 400 if (args) { |
| 401 if (args->HasKey(keys::kUrlKey)) { | 401 if (args->HasKey(keys::kUrlKey)) { |
| 402 Value* url_value; | 402 Value* url_value; |
| 403 std::vector<std::string> url_strings; | 403 std::vector<std::string> url_strings; |
| 404 args->Get(keys::kUrlKey, &url_value); | 404 args->Get(keys::kUrlKey, &url_value); |
| (...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 598 web_app::GenerateApplicationNameFromExtensionId(extension_id), | 598 web_app::GenerateApplicationNameFromExtensionId(extension_id), |
| 599 (window_type == Browser::TYPE_PANEL ? panel_bounds : popup_bounds), | 599 (window_type == Browser::TYPE_PANEL ? panel_bounds : popup_bounds), |
| 600 window_profile); | 600 window_profile); |
| 601 } | 601 } |
| 602 create_params.initial_show_state = ui::SHOW_STATE_NORMAL; | 602 create_params.initial_show_state = ui::SHOW_STATE_NORMAL; |
| 603 | 603 |
| 604 Browser* new_window = CreateBrowserWindow(create_params, window_profile, | 604 Browser* new_window = CreateBrowserWindow(create_params, window_profile, |
| 605 extension_id); | 605 extension_id); |
| 606 | 606 |
| 607 for (std::vector<GURL>::iterator i = urls.begin(); i != urls.end(); ++i) { | 607 for (std::vector<GURL>::iterator i = urls.begin(); i != urls.end(); ++i) { |
| 608 TabContentsWrapper* tab = new_window->AddSelectedTabWithURL( | 608 TabContents* tab = new_window->AddSelectedTabWithURL( |
| 609 *i, content::PAGE_TRANSITION_LINK); | 609 *i, content::PAGE_TRANSITION_LINK); |
| 610 if (window_type == Browser::TYPE_PANEL) | 610 if (window_type == Browser::TYPE_PANEL) |
| 611 tab->extension_tab_helper()->SetExtensionAppIconById(extension_id); | 611 tab->extension_tab_helper()->SetExtensionAppIconById(extension_id); |
| 612 } | 612 } |
| 613 if (contents) { | 613 if (contents) { |
| 614 TabStripModel* target_tab_strip = new_window->tab_strip_model(); | 614 TabStripModel* target_tab_strip = new_window->tab_strip_model(); |
| 615 target_tab_strip->InsertTabContentsAt(urls.size(), contents, | 615 target_tab_strip->InsertTabContentsAt(urls.size(), contents, |
| 616 TabStripModel::ADD_NONE); | 616 TabStripModel::ADD_NONE); |
| 617 } else if (urls.empty()) { | 617 } else if (urls.empty()) { |
| 618 new_window->NewTab(); | 618 new_window->NewTab(); |
| (...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 800 int window_id = extension_misc::kCurrentWindowId; | 800 int window_id = extension_misc::kCurrentWindowId; |
| 801 | 801 |
| 802 if (HasOptionalArgument(0)) | 802 if (HasOptionalArgument(0)) |
| 803 EXTENSION_FUNCTION_VALIDATE(args_->GetInteger(0, &window_id)); | 803 EXTENSION_FUNCTION_VALIDATE(args_->GetInteger(0, &window_id)); |
| 804 | 804 |
| 805 Browser* browser = NULL; | 805 Browser* browser = NULL; |
| 806 if (!GetBrowserFromWindowID(this, window_id, &browser)) | 806 if (!GetBrowserFromWindowID(this, window_id, &browser)) |
| 807 return false; | 807 return false; |
| 808 | 808 |
| 809 TabStripModel* tab_strip = browser->tab_strip_model(); | 809 TabStripModel* tab_strip = browser->tab_strip_model(); |
| 810 TabContentsWrapper* contents = tab_strip->GetActiveTabContents(); | 810 TabContents* contents = tab_strip->GetActiveTabContents(); |
| 811 if (!contents) { | 811 if (!contents) { |
| 812 error_ = keys::kNoSelectedTabError; | 812 error_ = keys::kNoSelectedTabError; |
| 813 return false; | 813 return false; |
| 814 } | 814 } |
| 815 result_.reset(ExtensionTabUtil::CreateTabValue(contents->web_contents(), | 815 result_.reset(ExtensionTabUtil::CreateTabValue(contents->web_contents(), |
| 816 tab_strip, | 816 tab_strip, |
| 817 tab_strip->active_index())); | 817 tab_strip->active_index())); |
| 818 return true; | 818 return true; |
| 819 } | 819 } |
| 820 | 820 |
| (...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 970 return false; | 970 return false; |
| 971 | 971 |
| 972 // TODO(jstritar): Add a constant, chrome.tabs.TAB_ID_ACTIVE, that | 972 // TODO(jstritar): Add a constant, chrome.tabs.TAB_ID_ACTIVE, that |
| 973 // represents the active tab. | 973 // represents the active tab. |
| 974 content::NavigationController* opener = NULL; | 974 content::NavigationController* opener = NULL; |
| 975 if (args->HasKey(keys::kOpenerTabIdKey)) { | 975 if (args->HasKey(keys::kOpenerTabIdKey)) { |
| 976 int opener_id = -1; | 976 int opener_id = -1; |
| 977 EXTENSION_FUNCTION_VALIDATE(args->GetInteger( | 977 EXTENSION_FUNCTION_VALIDATE(args->GetInteger( |
| 978 keys::kOpenerTabIdKey, &opener_id)); | 978 keys::kOpenerTabIdKey, &opener_id)); |
| 979 | 979 |
| 980 TabContentsWrapper* opener_contents = NULL; | 980 TabContents* opener_contents = NULL; |
| 981 if (!ExtensionTabUtil::GetTabById( | 981 if (!ExtensionTabUtil::GetTabById( |
| 982 opener_id, profile(), include_incognito(), | 982 opener_id, profile(), include_incognito(), |
| 983 NULL, NULL, &opener_contents, NULL)) | 983 NULL, NULL, &opener_contents, NULL)) |
| 984 return false; | 984 return false; |
| 985 | 985 |
| 986 opener = &opener_contents->web_contents()->GetController(); | 986 opener = &opener_contents->web_contents()->GetController(); |
| 987 } | 987 } |
| 988 | 988 |
| 989 // TODO(rafaelw): handle setting remaining tab properties: | 989 // TODO(rafaelw): handle setting remaining tab properties: |
| 990 // -title | 990 // -title |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1081 } | 1081 } |
| 1082 | 1082 |
| 1083 return true; | 1083 return true; |
| 1084 } | 1084 } |
| 1085 | 1085 |
| 1086 bool GetTabFunction::RunImpl() { | 1086 bool GetTabFunction::RunImpl() { |
| 1087 int tab_id = -1; | 1087 int tab_id = -1; |
| 1088 EXTENSION_FUNCTION_VALIDATE(args_->GetInteger(0, &tab_id)); | 1088 EXTENSION_FUNCTION_VALIDATE(args_->GetInteger(0, &tab_id)); |
| 1089 | 1089 |
| 1090 TabStripModel* tab_strip = NULL; | 1090 TabStripModel* tab_strip = NULL; |
| 1091 TabContentsWrapper* contents = NULL; | 1091 TabContents* contents = NULL; |
| 1092 int tab_index = -1; | 1092 int tab_index = -1; |
| 1093 if (!GetTabById(tab_id, profile(), include_incognito(), | 1093 if (!GetTabById(tab_id, profile(), include_incognito(), |
| 1094 NULL, &tab_strip, &contents, &tab_index, &error_)) | 1094 NULL, &tab_strip, &contents, &tab_index, &error_)) |
| 1095 return false; | 1095 return false; |
| 1096 | 1096 |
| 1097 result_.reset(ExtensionTabUtil::CreateTabValue(contents->web_contents(), | 1097 result_.reset(ExtensionTabUtil::CreateTabValue(contents->web_contents(), |
| 1098 tab_strip, | 1098 tab_strip, |
| 1099 tab_index)); | 1099 tab_index)); |
| 1100 return true; | 1100 return true; |
| 1101 } | 1101 } |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1172 bool UpdateTabFunction::RunImpl() { | 1172 bool UpdateTabFunction::RunImpl() { |
| 1173 DictionaryValue* update_props = NULL; | 1173 DictionaryValue* update_props = NULL; |
| 1174 EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(1, &update_props)); | 1174 EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(1, &update_props)); |
| 1175 | 1175 |
| 1176 Value* tab_value = NULL; | 1176 Value* tab_value = NULL; |
| 1177 if (HasOptionalArgument(0)) { | 1177 if (HasOptionalArgument(0)) { |
| 1178 EXTENSION_FUNCTION_VALIDATE(args_->Get(0, &tab_value)); | 1178 EXTENSION_FUNCTION_VALIDATE(args_->Get(0, &tab_value)); |
| 1179 } | 1179 } |
| 1180 | 1180 |
| 1181 int tab_id = -1; | 1181 int tab_id = -1; |
| 1182 TabContentsWrapper* contents = NULL; | 1182 TabContents* contents = NULL; |
| 1183 if (tab_value == NULL || tab_value->IsType(Value::TYPE_NULL)) { | 1183 if (tab_value == NULL || tab_value->IsType(Value::TYPE_NULL)) { |
| 1184 Browser* browser = GetCurrentBrowser(); | 1184 Browser* browser = GetCurrentBrowser(); |
| 1185 if (!browser) { | 1185 if (!browser) { |
| 1186 error_ = keys::kNoCurrentWindowError; | 1186 error_ = keys::kNoCurrentWindowError; |
| 1187 return false; | 1187 return false; |
| 1188 } | 1188 } |
| 1189 contents = browser->tab_strip_model()->GetActiveTabContents(); | 1189 contents = browser->tab_strip_model()->GetActiveTabContents(); |
| 1190 if (!contents) { | 1190 if (!contents) { |
| 1191 error_ = keys::kNoSelectedTabError; | 1191 error_ = keys::kNoSelectedTabError; |
| 1192 return false; | 1192 return false; |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1250 | 1250 |
| 1251 // Update the tab index because it may move when being pinned. | 1251 // Update the tab index because it may move when being pinned. |
| 1252 tab_index = tab_strip->GetIndexOfTabContents(contents); | 1252 tab_index = tab_strip->GetIndexOfTabContents(contents); |
| 1253 } | 1253 } |
| 1254 | 1254 |
| 1255 if (update_props->HasKey(keys::kOpenerTabIdKey)) { | 1255 if (update_props->HasKey(keys::kOpenerTabIdKey)) { |
| 1256 int opener_id = -1; | 1256 int opener_id = -1; |
| 1257 EXTENSION_FUNCTION_VALIDATE(update_props->GetInteger( | 1257 EXTENSION_FUNCTION_VALIDATE(update_props->GetInteger( |
| 1258 keys::kOpenerTabIdKey, &opener_id)); | 1258 keys::kOpenerTabIdKey, &opener_id)); |
| 1259 | 1259 |
| 1260 TabContentsWrapper* opener_contents = NULL; | 1260 TabContents* opener_contents = NULL; |
| 1261 if (!ExtensionTabUtil::GetTabById( | 1261 if (!ExtensionTabUtil::GetTabById( |
| 1262 opener_id, profile(), include_incognito(), | 1262 opener_id, profile(), include_incognito(), |
| 1263 NULL, NULL, &opener_contents, NULL)) | 1263 NULL, NULL, &opener_contents, NULL)) |
| 1264 return false; | 1264 return false; |
| 1265 | 1265 |
| 1266 tab_strip->SetOpenerOfTabContentsAt( | 1266 tab_strip->SetOpenerOfTabContentsAt( |
| 1267 tab_index, &opener_contents->web_contents()->GetController()); | 1267 tab_index, &opener_contents->web_contents()->GetController()); |
| 1268 } | 1268 } |
| 1269 | 1269 |
| 1270 if (!is_async) { | 1270 if (!is_async) { |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1365 DictionaryValue* update_props = NULL; | 1365 DictionaryValue* update_props = NULL; |
| 1366 int new_index; | 1366 int new_index; |
| 1367 EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(1, &update_props)); | 1367 EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(1, &update_props)); |
| 1368 EXTENSION_FUNCTION_VALIDATE(update_props->GetInteger(keys::kIndexKey, | 1368 EXTENSION_FUNCTION_VALIDATE(update_props->GetInteger(keys::kIndexKey, |
| 1369 &new_index)); | 1369 &new_index)); |
| 1370 | 1370 |
| 1371 ListValue tab_values; | 1371 ListValue tab_values; |
| 1372 for (size_t i = 0; i < tab_ids.size(); ++i) { | 1372 for (size_t i = 0; i < tab_ids.size(); ++i) { |
| 1373 Browser* source_browser = NULL; | 1373 Browser* source_browser = NULL; |
| 1374 TabStripModel* source_tab_strip = NULL; | 1374 TabStripModel* source_tab_strip = NULL; |
| 1375 TabContentsWrapper* contents = NULL; | 1375 TabContents* contents = NULL; |
| 1376 int tab_index = -1; | 1376 int tab_index = -1; |
| 1377 if (!GetTabById(tab_ids[i], profile(), include_incognito(), | 1377 if (!GetTabById(tab_ids[i], profile(), include_incognito(), |
| 1378 &source_browser, &source_tab_strip, &contents, | 1378 &source_browser, &source_tab_strip, &contents, |
| 1379 &tab_index, &error_)) | 1379 &tab_index, &error_)) |
| 1380 return false; | 1380 return false; |
| 1381 | 1381 |
| 1382 // Don't let the extension move the tab if the user is dragging tabs. | 1382 // Don't let the extension move the tab if the user is dragging tabs. |
| 1383 if (!source_browser->IsTabStripEditable()) { | 1383 if (!source_browser->IsTabStripEditable()) { |
| 1384 error_ = keys::kTabStripNotEditableError; | 1384 error_ = keys::kTabStripNotEditableError; |
| 1385 return false; | 1385 return false; |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1475 DictionaryValue* reload_props = NULL; | 1475 DictionaryValue* reload_props = NULL; |
| 1476 EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(1, &reload_props)); | 1476 EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(1, &reload_props)); |
| 1477 | 1477 |
| 1478 if (reload_props->HasKey(keys::kBypassCache)) { | 1478 if (reload_props->HasKey(keys::kBypassCache)) { |
| 1479 EXTENSION_FUNCTION_VALIDATE(reload_props->GetBoolean( | 1479 EXTENSION_FUNCTION_VALIDATE(reload_props->GetBoolean( |
| 1480 keys::kBypassCache, | 1480 keys::kBypassCache, |
| 1481 &bypass_cache)); | 1481 &bypass_cache)); |
| 1482 } | 1482 } |
| 1483 } | 1483 } |
| 1484 | 1484 |
| 1485 TabContentsWrapper* contents = NULL; | 1485 TabContents* contents = NULL; |
| 1486 | 1486 |
| 1487 // If |tab_id| is specified, look for it. Otherwise default to selected tab | 1487 // If |tab_id| is specified, look for it. Otherwise default to selected tab |
| 1488 // in the current window. | 1488 // in the current window. |
| 1489 Value* tab_value = NULL; | 1489 Value* tab_value = NULL; |
| 1490 if (HasOptionalArgument(0)) | 1490 if (HasOptionalArgument(0)) |
| 1491 EXTENSION_FUNCTION_VALIDATE(args_->Get(0, &tab_value)); | 1491 EXTENSION_FUNCTION_VALIDATE(args_->Get(0, &tab_value)); |
| 1492 | 1492 |
| 1493 if (tab_value == NULL || tab_value->IsType(Value::TYPE_NULL)) { | 1493 if (tab_value == NULL || tab_value->IsType(Value::TYPE_NULL)) { |
| 1494 Browser* browser = GetCurrentBrowser(); | 1494 Browser* browser = GetCurrentBrowser(); |
| 1495 if (!browser) { | 1495 if (!browser) { |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1528 bool RemoveTabsFunction::RunImpl() { | 1528 bool RemoveTabsFunction::RunImpl() { |
| 1529 Value* tab_value = NULL; | 1529 Value* tab_value = NULL; |
| 1530 EXTENSION_FUNCTION_VALIDATE(args_->Get(0, &tab_value)); | 1530 EXTENSION_FUNCTION_VALIDATE(args_->Get(0, &tab_value)); |
| 1531 | 1531 |
| 1532 std::vector<int> tab_ids; | 1532 std::vector<int> tab_ids; |
| 1533 EXTENSION_FUNCTION_VALIDATE(extensions::ReadOneOrMoreIntegers( | 1533 EXTENSION_FUNCTION_VALIDATE(extensions::ReadOneOrMoreIntegers( |
| 1534 tab_value, &tab_ids)); | 1534 tab_value, &tab_ids)); |
| 1535 | 1535 |
| 1536 for (size_t i = 0; i < tab_ids.size(); ++i) { | 1536 for (size_t i = 0; i < tab_ids.size(); ++i) { |
| 1537 Browser* browser = NULL; | 1537 Browser* browser = NULL; |
| 1538 TabContentsWrapper* contents = NULL; | 1538 TabContents* contents = NULL; |
| 1539 if (!GetTabById(tab_ids[i], profile(), include_incognito(), | 1539 if (!GetTabById(tab_ids[i], profile(), include_incognito(), |
| 1540 &browser, NULL, &contents, NULL, &error_)) | 1540 &browser, NULL, &contents, NULL, &error_)) |
| 1541 return false; | 1541 return false; |
| 1542 | 1542 |
| 1543 // Don't let the extension remove a tab if the user is dragging tabs around. | 1543 // Don't let the extension remove a tab if the user is dragging tabs around. |
| 1544 if (!browser->IsTabStripEditable()) { | 1544 if (!browser->IsTabStripEditable()) { |
| 1545 error_ = keys::kTabStripNotEditableError; | 1545 error_ = keys::kTabStripNotEditableError; |
| 1546 return false; | 1546 return false; |
| 1547 } | 1547 } |
| 1548 | 1548 |
| 1549 // There's a chance that the tab is being dragged, or we're in some other | 1549 // There's a chance that the tab is being dragged, or we're in some other |
| 1550 // nested event loop. This code path ensures that the tab is safely closed | 1550 // nested event loop. This code path ensures that the tab is safely closed |
| 1551 // under such circumstances, whereas |Browser::CloseTabContents()| does not. | 1551 // under such circumstances, whereas |Browser::CloseTabContents()| does not. |
| 1552 contents->web_contents()->Close(); | 1552 contents->web_contents()->Close(); |
| 1553 } | 1553 } |
| 1554 return true; | 1554 return true; |
| 1555 } | 1555 } |
| 1556 | 1556 |
| 1557 bool CaptureVisibleTabFunction::GetTabToCapture( | 1557 bool CaptureVisibleTabFunction::GetTabToCapture( |
| 1558 WebContents** web_contents, TabContentsWrapper** wrapper) { | 1558 WebContents** web_contents, TabContents** tab_contents) { |
| 1559 Browser* browser = NULL; | 1559 Browser* browser = NULL; |
| 1560 // windowId defaults to "current" window. | 1560 // windowId defaults to "current" window. |
| 1561 int window_id = extension_misc::kCurrentWindowId; | 1561 int window_id = extension_misc::kCurrentWindowId; |
| 1562 | 1562 |
| 1563 if (HasOptionalArgument(0)) | 1563 if (HasOptionalArgument(0)) |
| 1564 EXTENSION_FUNCTION_VALIDATE(args_->GetInteger(0, &window_id)); | 1564 EXTENSION_FUNCTION_VALIDATE(args_->GetInteger(0, &window_id)); |
| 1565 | 1565 |
| 1566 if (!GetBrowserFromWindowID(this, window_id, &browser)) | 1566 if (!GetBrowserFromWindowID(this, window_id, &browser)) |
| 1567 return false; | 1567 return false; |
| 1568 | 1568 |
| 1569 *web_contents = browser->GetSelectedWebContents(); | 1569 *web_contents = browser->GetActiveWebContents(); |
| 1570 if (*web_contents == NULL) { | 1570 if (*web_contents == NULL) { |
| 1571 error_ = keys::kInternalVisibleTabCaptureError; | 1571 error_ = keys::kInternalVisibleTabCaptureError; |
| 1572 return false; | 1572 return false; |
| 1573 } | 1573 } |
| 1574 | 1574 |
| 1575 *wrapper = browser->GetSelectedTabContentsWrapper(); | 1575 *tab_contents = browser->GetActiveTabContents(); |
| 1576 | 1576 |
| 1577 return true; | 1577 return true; |
| 1578 }; | 1578 }; |
| 1579 | 1579 |
| 1580 bool CaptureVisibleTabFunction::RunImpl() { | 1580 bool CaptureVisibleTabFunction::RunImpl() { |
| 1581 WebContents* web_contents = NULL; | 1581 WebContents* web_contents = NULL; |
| 1582 TabContentsWrapper* wrapper = NULL; | 1582 TabContents* tab_contents = NULL; |
| 1583 if (!GetTabToCapture(&web_contents, &wrapper)) | 1583 if (!GetTabToCapture(&web_contents, &tab_contents)) |
| 1584 return false; | 1584 return false; |
| 1585 | 1585 |
| 1586 image_format_ = FORMAT_JPEG; // Default format is JPEG. | 1586 image_format_ = FORMAT_JPEG; // Default format is JPEG. |
| 1587 image_quality_ = kDefaultQuality; // Default quality setting. | 1587 image_quality_ = kDefaultQuality; // Default quality setting. |
| 1588 | 1588 |
| 1589 if (HasOptionalArgument(1)) { | 1589 if (HasOptionalArgument(1)) { |
| 1590 DictionaryValue* options = NULL; | 1590 DictionaryValue* options = NULL; |
| 1591 EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(1, &options)); | 1591 EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(1, &options)); |
| 1592 | 1592 |
| 1593 if (options->HasKey(keys::kFormatKey)) { | 1593 if (options->HasKey(keys::kFormatKey)) { |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1637 void CaptureVisibleTabFunction::CopyFromBackingStoreComplete( | 1637 void CaptureVisibleTabFunction::CopyFromBackingStoreComplete( |
| 1638 skia::PlatformCanvas* canvas, | 1638 skia::PlatformCanvas* canvas, |
| 1639 bool succeeded) { | 1639 bool succeeded) { |
| 1640 if (succeeded) { | 1640 if (succeeded) { |
| 1641 VLOG(1) << "captureVisibleTab() got image from backing store."; | 1641 VLOG(1) << "captureVisibleTab() got image from backing store."; |
| 1642 SendResultFromBitmap(skia::GetTopDevice(*canvas)->accessBitmap(false)); | 1642 SendResultFromBitmap(skia::GetTopDevice(*canvas)->accessBitmap(false)); |
| 1643 return; | 1643 return; |
| 1644 } | 1644 } |
| 1645 | 1645 |
| 1646 WebContents* web_contents = NULL; | 1646 WebContents* web_contents = NULL; |
| 1647 TabContentsWrapper* wrapper = NULL; | 1647 TabContents* tab_contents = NULL; |
| 1648 if (!GetTabToCapture(&web_contents, &wrapper)) { | 1648 if (!GetTabToCapture(&web_contents, &tab_contents)) { |
| 1649 error_ = keys::kInternalVisibleTabCaptureError; | 1649 error_ = keys::kInternalVisibleTabCaptureError; |
| 1650 SendResponse(false); | 1650 SendResponse(false); |
| 1651 return; | 1651 return; |
| 1652 } | 1652 } |
| 1653 | 1653 |
| 1654 // Ask the renderer for a snapshot of the tab. | 1654 // Ask the renderer for a snapshot of the tab. |
| 1655 registrar_.Add(this, | 1655 registrar_.Add(this, |
| 1656 chrome::NOTIFICATION_TAB_SNAPSHOT_TAKEN, | 1656 chrome::NOTIFICATION_TAB_SNAPSHOT_TAKEN, |
| 1657 content::Source<WebContents>(web_contents)); | 1657 content::Source<WebContents>(web_contents)); |
| 1658 AddRef(); // Balanced in CaptureVisibleTabFunction::Observe(). | 1658 AddRef(); // Balanced in CaptureVisibleTabFunction::Observe(). |
| 1659 wrapper->snapshot_tab_helper()->CaptureSnapshot(); | 1659 tab_contents->snapshot_tab_helper()->CaptureSnapshot(); |
| 1660 } | 1660 } |
| 1661 | 1661 |
| 1662 // If a backing store was not available in CaptureVisibleTabFunction::RunImpl, | 1662 // If a backing store was not available in CaptureVisibleTabFunction::RunImpl, |
| 1663 // than the renderer was asked for a snapshot. Listen for a notification | 1663 // than the renderer was asked for a snapshot. Listen for a notification |
| 1664 // that the snapshot is available. | 1664 // that the snapshot is available. |
| 1665 void CaptureVisibleTabFunction::Observe( | 1665 void CaptureVisibleTabFunction::Observe( |
| 1666 int type, | 1666 int type, |
| 1667 const content::NotificationSource& source, | 1667 const content::NotificationSource& source, |
| 1668 const content::NotificationDetails& details) { | 1668 const content::NotificationDetails& details) { |
| 1669 DCHECK(type == chrome::NOTIFICATION_TAB_SNAPSHOT_TAKEN); | 1669 DCHECK(type == chrome::NOTIFICATION_TAB_SNAPSHOT_TAKEN); |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1727 base::Base64Encode(stream_as_string, &base64_result); | 1727 base::Base64Encode(stream_as_string, &base64_result); |
| 1728 base64_result.insert(0, base::StringPrintf("data:%s;base64,", | 1728 base64_result.insert(0, base::StringPrintf("data:%s;base64,", |
| 1729 mime_type.c_str())); | 1729 mime_type.c_str())); |
| 1730 result_.reset(new StringValue(base64_result)); | 1730 result_.reset(new StringValue(base64_result)); |
| 1731 SendResponse(true); | 1731 SendResponse(true); |
| 1732 } | 1732 } |
| 1733 | 1733 |
| 1734 bool DetectTabLanguageFunction::RunImpl() { | 1734 bool DetectTabLanguageFunction::RunImpl() { |
| 1735 int tab_id = 0; | 1735 int tab_id = 0; |
| 1736 Browser* browser = NULL; | 1736 Browser* browser = NULL; |
| 1737 TabContentsWrapper* contents = NULL; | 1737 TabContents* contents = NULL; |
| 1738 | 1738 |
| 1739 // If |tab_id| is specified, look for it. Otherwise default to selected tab | 1739 // If |tab_id| is specified, look for it. Otherwise default to selected tab |
| 1740 // in the current window. | 1740 // in the current window. |
| 1741 if (HasOptionalArgument(0)) { | 1741 if (HasOptionalArgument(0)) { |
| 1742 EXTENSION_FUNCTION_VALIDATE(args_->GetInteger(0, &tab_id)); | 1742 EXTENSION_FUNCTION_VALIDATE(args_->GetInteger(0, &tab_id)); |
| 1743 if (!GetTabById(tab_id, profile(), include_incognito(), | 1743 if (!GetTabById(tab_id, profile(), include_incognito(), |
| 1744 &browser, NULL, &contents, NULL, &error_)) { | 1744 &browser, NULL, &contents, NULL, &error_)) { |
| 1745 return false; | 1745 return false; |
| 1746 } | 1746 } |
| 1747 if (!browser || !contents) | 1747 if (!browser || !contents) |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1801 // called for every API call the extension made. | 1801 // called for every API call the extension made. |
| 1802 GotLanguage(language); | 1802 GotLanguage(language); |
| 1803 } | 1803 } |
| 1804 | 1804 |
| 1805 void DetectTabLanguageFunction::GotLanguage(const std::string& language) { | 1805 void DetectTabLanguageFunction::GotLanguage(const std::string& language) { |
| 1806 result_.reset(Value::CreateStringValue(language.c_str())); | 1806 result_.reset(Value::CreateStringValue(language.c_str())); |
| 1807 SendResponse(true); | 1807 SendResponse(true); |
| 1808 | 1808 |
| 1809 Release(); // Balanced in Run() | 1809 Release(); // Balanced in Run() |
| 1810 } | 1810 } |
| OLD | NEW |