Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(482)

Side by Side Diff: chrome/browser/extensions/api/tabs/tabs.cc

Issue 10702029: Move tab functions off Browser into browser_tabstrip and browser_tabrestore. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 8 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 20 matching lines...) Expand all
31 #include "chrome/browser/extensions/script_executor.h" 31 #include "chrome/browser/extensions/script_executor.h"
32 #include "chrome/browser/prefs/incognito_mode_prefs.h" 32 #include "chrome/browser/prefs/incognito_mode_prefs.h"
33 #include "chrome/browser/profiles/profile.h" 33 #include "chrome/browser/profiles/profile.h"
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_commands.h" 37 #include "chrome/browser/ui/browser_commands.h"
38 #include "chrome/browser/ui/browser_finder.h" 38 #include "chrome/browser/ui/browser_finder.h"
39 #include "chrome/browser/ui/browser_list.h" 39 #include "chrome/browser/ui/browser_list.h"
40 #include "chrome/browser/ui/browser_navigator.h" 40 #include "chrome/browser/ui/browser_navigator.h"
41 #include "chrome/browser/ui/browser_tabstrip.h"
41 #include "chrome/browser/ui/browser_window.h" 42 #include "chrome/browser/ui/browser_window.h"
42 #include "chrome/browser/ui/extensions/shell_window.h" 43 #include "chrome/browser/ui/extensions/shell_window.h"
43 #include "chrome/browser/ui/panels/panel_manager.h" 44 #include "chrome/browser/ui/panels/panel_manager.h"
44 #include "chrome/browser/ui/snapshot_tab_helper.h" 45 #include "chrome/browser/ui/snapshot_tab_helper.h"
45 #include "chrome/browser/ui/tab_contents/tab_contents.h" 46 #include "chrome/browser/ui/tab_contents/tab_contents.h"
46 #include "chrome/browser/ui/tabs/tab_strip_model.h" 47 #include "chrome/browser/ui/tabs/tab_strip_model.h"
47 #include "chrome/browser/ui/window_sizer/window_sizer.h" 48 #include "chrome/browser/ui/window_sizer/window_sizer.h"
48 #include "chrome/browser/web_applications/web_app.h" 49 #include "chrome/browser/web_applications/web_app.h"
49 #include "chrome/common/chrome_notification_types.h" 50 #include "chrome/common/chrome_notification_types.h"
50 #include "chrome/common/chrome_switches.h" 51 #include "chrome/common/chrome_switches.h"
(...skipping 567 matching lines...) Expand 10 before | Expand all | Expand 10 after
618 web_app::GenerateApplicationNameFromExtensionId(extension_id), 619 web_app::GenerateApplicationNameFromExtensionId(extension_id),
619 (window_type == Browser::TYPE_PANEL ? panel_bounds : popup_bounds), 620 (window_type == Browser::TYPE_PANEL ? panel_bounds : popup_bounds),
620 window_profile); 621 window_profile);
621 } 622 }
622 create_params.initial_show_state = ui::SHOW_STATE_NORMAL; 623 create_params.initial_show_state = ui::SHOW_STATE_NORMAL;
623 624
624 Browser* new_window = CreateBrowserWindow(create_params, window_profile, 625 Browser* new_window = CreateBrowserWindow(create_params, window_profile,
625 extension_id); 626 extension_id);
626 627
627 for (std::vector<GURL>::iterator i = urls.begin(); i != urls.end(); ++i) { 628 for (std::vector<GURL>::iterator i = urls.begin(); i != urls.end(); ++i) {
628 TabContents* tab = new_window->AddSelectedTabWithURL( 629 TabContents* tab = chrome::AddSelectedTabWithURL(
629 *i, content::PAGE_TRANSITION_LINK); 630 new_window, *i, content::PAGE_TRANSITION_LINK);
630 if (window_type == Browser::TYPE_PANEL) 631 if (window_type == Browser::TYPE_PANEL)
631 tab->extension_tab_helper()->SetExtensionAppIconById(extension_id); 632 tab->extension_tab_helper()->SetExtensionAppIconById(extension_id);
632 } 633 }
633 if (contents) { 634 if (contents) {
634 TabStripModel* target_tab_strip = new_window->tab_strip_model(); 635 TabStripModel* target_tab_strip = new_window->tab_strip_model();
635 target_tab_strip->InsertTabContentsAt(urls.size(), contents, 636 target_tab_strip->InsertTabContentsAt(urls.size(), contents,
636 TabStripModel::ADD_NONE); 637 TabStripModel::ADD_NONE);
637 } else if (urls.empty()) { 638 } else if (urls.empty()) {
638 chrome::NewTab(new_window); 639 chrome::NewTab(new_window);
639 } 640 }
(...skipping 753 matching lines...) Expand 10 before | Expand all | Expand 10 after
1393 Browser* source_browser = NULL; 1394 Browser* source_browser = NULL;
1394 TabStripModel* source_tab_strip = NULL; 1395 TabStripModel* source_tab_strip = NULL;
1395 TabContents* contents = NULL; 1396 TabContents* contents = NULL;
1396 int tab_index = -1; 1397 int tab_index = -1;
1397 if (!GetTabById(tab_ids[i], profile(), include_incognito(), 1398 if (!GetTabById(tab_ids[i], profile(), include_incognito(),
1398 &source_browser, &source_tab_strip, &contents, 1399 &source_browser, &source_tab_strip, &contents,
1399 &tab_index, &error_)) 1400 &tab_index, &error_))
1400 return false; 1401 return false;
1401 1402
1402 // Don't let the extension move the tab if the user is dragging tabs. 1403 // Don't let the extension move the tab if the user is dragging tabs.
1403 if (!source_browser->IsTabStripEditable()) { 1404 if (!chrome::IsTabStripEditable(source_browser)) {
1404 error_ = keys::kTabStripNotEditableError; 1405 error_ = keys::kTabStripNotEditableError;
1405 return false; 1406 return false;
1406 } 1407 }
1407 1408
1408 // Insert the tabs one after another. 1409 // Insert the tabs one after another.
1409 new_index += i; 1410 new_index += i;
1410 1411
1411 if (update_props->HasKey(keys::kWindowIdKey)) { 1412 if (update_props->HasKey(keys::kWindowIdKey)) {
1412 Browser* target_browser = NULL; 1413 Browser* target_browser = NULL;
1413 int window_id = extension_misc::kUnknownWindowId; 1414 int window_id = extension_misc::kUnknownWindowId;
1414 EXTENSION_FUNCTION_VALIDATE(update_props->GetInteger( 1415 EXTENSION_FUNCTION_VALIDATE(update_props->GetInteger(
1415 keys::kWindowIdKey, &window_id)); 1416 keys::kWindowIdKey, &window_id));
1416 1417
1417 if (!GetBrowserFromWindowID(this, window_id, &target_browser)) 1418 if (!GetBrowserFromWindowID(this, window_id, &target_browser))
1418 return false; 1419 return false;
1419 1420
1420 if (!target_browser->IsTabStripEditable()) { 1421 if (!chrome::IsTabStripEditable(target_browser)) {
1421 error_ = keys::kTabStripNotEditableError; 1422 error_ = keys::kTabStripNotEditableError;
1422 return false; 1423 return false;
1423 } 1424 }
1424 1425
1425 if (!target_browser->is_type_tabbed()) { 1426 if (!target_browser->is_type_tabbed()) {
1426 error_ = keys::kCanOnlyMoveTabsWithinNormalWindowsError; 1427 error_ = keys::kCanOnlyMoveTabsWithinNormalWindowsError;
1427 return false; 1428 return false;
1428 } 1429 }
1429 1430
1430 if (target_browser->profile() != source_browser->profile()) { 1431 if (target_browser->profile() != source_browser->profile()) {
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
1554 tab_value, &tab_ids)); 1555 tab_value, &tab_ids));
1555 1556
1556 for (size_t i = 0; i < tab_ids.size(); ++i) { 1557 for (size_t i = 0; i < tab_ids.size(); ++i) {
1557 Browser* browser = NULL; 1558 Browser* browser = NULL;
1558 TabContents* contents = NULL; 1559 TabContents* contents = NULL;
1559 if (!GetTabById(tab_ids[i], profile(), include_incognito(), 1560 if (!GetTabById(tab_ids[i], profile(), include_incognito(),
1560 &browser, NULL, &contents, NULL, &error_)) 1561 &browser, NULL, &contents, NULL, &error_))
1561 return false; 1562 return false;
1562 1563
1563 // Don't let the extension remove a tab if the user is dragging tabs around. 1564 // Don't let the extension remove a tab if the user is dragging tabs around.
1564 if (!browser->IsTabStripEditable()) { 1565 if (!chrome::IsTabStripEditable(browser)) {
1565 error_ = keys::kTabStripNotEditableError; 1566 error_ = keys::kTabStripNotEditableError;
1566 return false; 1567 return false;
1567 } 1568 }
1568 1569
1569 // There's a chance that the tab is being dragged, or we're in some other 1570 // There's a chance that the tab is being dragged, or we're in some other
1570 // nested event loop. This code path ensures that the tab is safely closed 1571 // nested event loop. This code path ensures that the tab is safely closed
1571 // under such circumstances, whereas |Browser::CloseTabContents()| does not. 1572 // under such circumstances, whereas |chrome::CloseWebContents()| does not.
1572 contents->web_contents()->Close(); 1573 contents->web_contents()->Close();
1573 } 1574 }
1574 return true; 1575 return true;
1575 } 1576 }
1576 1577
1577 bool CaptureVisibleTabFunction::GetTabToCapture( 1578 bool CaptureVisibleTabFunction::GetTabToCapture(
1578 WebContents** web_contents, TabContents** tab_contents) { 1579 WebContents** web_contents, TabContents** tab_contents) {
1579 Browser* browser = NULL; 1580 Browser* browser = NULL;
1580 // windowId defaults to "current" window. 1581 // windowId defaults to "current" window.
1581 int window_id = extension_misc::kCurrentWindowId; 1582 int window_id = extension_misc::kCurrentWindowId;
1582 1583
1583 if (HasOptionalArgument(0)) 1584 if (HasOptionalArgument(0))
1584 EXTENSION_FUNCTION_VALIDATE(args_->GetInteger(0, &window_id)); 1585 EXTENSION_FUNCTION_VALIDATE(args_->GetInteger(0, &window_id));
1585 1586
1586 if (!GetBrowserFromWindowID(this, window_id, &browser)) 1587 if (!GetBrowserFromWindowID(this, window_id, &browser))
1587 return false; 1588 return false;
1588 1589
1589 *web_contents = browser->GetActiveWebContents(); 1590 *web_contents = chrome::GetActiveWebContents(browser);
1590 if (*web_contents == NULL) { 1591 if (*web_contents == NULL) {
1591 error_ = keys::kInternalVisibleTabCaptureError; 1592 error_ = keys::kInternalVisibleTabCaptureError;
1592 return false; 1593 return false;
1593 } 1594 }
1594 1595
1595 *tab_contents = browser->GetActiveTabContents(); 1596 *tab_contents = chrome::GetActiveTabContents(browser);
1596 1597
1597 return true; 1598 return true;
1598 }; 1599 };
1599 1600
1600 bool CaptureVisibleTabFunction::RunImpl() { 1601 bool CaptureVisibleTabFunction::RunImpl() {
1601 WebContents* web_contents = NULL; 1602 WebContents* web_contents = NULL;
1602 TabContents* tab_contents = NULL; 1603 TabContents* tab_contents = NULL;
1603 if (!GetTabToCapture(&web_contents, &tab_contents)) 1604 if (!GetTabToCapture(&web_contents, &tab_contents))
1604 return false; 1605 return false;
1605 1606
(...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after
1825 // called for every API call the extension made. 1826 // called for every API call the extension made.
1826 GotLanguage(language); 1827 GotLanguage(language);
1827 } 1828 }
1828 1829
1829 void DetectTabLanguageFunction::GotLanguage(const std::string& language) { 1830 void DetectTabLanguageFunction::GotLanguage(const std::string& language) {
1830 result_.reset(Value::CreateStringValue(language.c_str())); 1831 result_.reset(Value::CreateStringValue(language.c_str()));
1831 SendResponse(true); 1832 SendResponse(true);
1832 1833
1833 Release(); // Balanced in Run() 1834 Release(); // Balanced in Run()
1834 } 1835 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698