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

Side by Side Diff: chrome/browser/extensions/extension_tabs_module.cc

Issue 8892011: Clean up TCW, make it solely a hub for 1:1 observer/helper objects. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 9 years 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) 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 878 matching lines...) Expand 10 before | Expand all | Expand 10 after
889 add_types |= TabStripModel::ADD_FORCE_INDEX; 889 add_types |= TabStripModel::ADD_FORCE_INDEX;
890 if (pinned) 890 if (pinned)
891 add_types |= TabStripModel::ADD_PINNED; 891 add_types |= TabStripModel::ADD_PINNED;
892 browser::NavigateParams params(browser, url, content::PAGE_TRANSITION_LINK); 892 browser::NavigateParams params(browser, url, content::PAGE_TRANSITION_LINK);
893 params.disposition = active ? NEW_FOREGROUND_TAB : NEW_BACKGROUND_TAB; 893 params.disposition = active ? NEW_FOREGROUND_TAB : NEW_BACKGROUND_TAB;
894 params.tabstrip_index = index; 894 params.tabstrip_index = index;
895 params.tabstrip_add_types = add_types; 895 params.tabstrip_add_types = add_types;
896 browser::Navigate(&params); 896 browser::Navigate(&params);
897 897
898 if (active) 898 if (active)
899 params.target_contents->view()->SetInitialFocus(); 899 params.target_contents->tab_contents()->view()->SetInitialFocus();
900 900
901 // Return data about the newly created tab. 901 // Return data about the newly created tab.
902 if (has_callback()) { 902 if (has_callback()) {
903 result_.reset(ExtensionTabUtil::CreateTabValue( 903 result_.reset(ExtensionTabUtil::CreateTabValue(
904 params.target_contents->tab_contents(), 904 params.target_contents->tab_contents(),
905 params.browser->tabstrip_model(), 905 params.browser->tabstrip_model(),
906 params.browser->tabstrip_model()->GetIndexOfTabContents( 906 params.browser->tabstrip_model()->GetIndexOfTabContents(
907 params.target_contents))); 907 params.target_contents)));
908 } 908 }
909 909
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
1024 } else { 1024 } else {
1025 EXTENSION_FUNCTION_VALIDATE(tab_value->GetAsInteger(&tab_id)); 1025 EXTENSION_FUNCTION_VALIDATE(tab_value->GetAsInteger(&tab_id));
1026 } 1026 }
1027 1027
1028 int tab_index = -1; 1028 int tab_index = -1;
1029 TabStripModel* tab_strip = NULL; 1029 TabStripModel* tab_strip = NULL;
1030 if (!GetTabById(tab_id, profile(), include_incognito(), 1030 if (!GetTabById(tab_id, profile(), include_incognito(),
1031 NULL, &tab_strip, &contents, &tab_index, &error_)) { 1031 NULL, &tab_strip, &contents, &tab_index, &error_)) {
1032 return false; 1032 return false;
1033 } 1033 }
1034 NavigationController& controller = contents->controller(); 1034 NavigationController& controller = contents->tab_contents()->controller();
1035 1035
1036 // TODO(rafaelw): handle setting remaining tab properties: 1036 // TODO(rafaelw): handle setting remaining tab properties:
1037 // -title 1037 // -title
1038 // -favIconUrl 1038 // -favIconUrl
1039 1039
1040 // Navigate the tab to a new location if the url is different. 1040 // Navigate the tab to a new location if the url is different.
1041 std::string url_string; 1041 std::string url_string;
1042 if (update_props->HasKey(keys::kUrlKey)) { 1042 if (update_props->HasKey(keys::kUrlKey)) {
1043 EXTENSION_FUNCTION_VALIDATE(update_props->GetString( 1043 EXTENSION_FUNCTION_VALIDATE(update_props->GetString(
1044 keys::kUrlKey, &url_string)); 1044 keys::kUrlKey, &url_string));
(...skipping 322 matching lines...) Expand 10 before | Expand all | Expand 10 after
1367 // Don't let the extension remove a tab if the user is dragging tabs around. 1367 // Don't let the extension remove a tab if the user is dragging tabs around.
1368 if (!browser->IsTabStripEditable()) { 1368 if (!browser->IsTabStripEditable()) {
1369 error_ = keys::kTabStripNotEditableError; 1369 error_ = keys::kTabStripNotEditableError;
1370 return false; 1370 return false;
1371 } 1371 }
1372 1372
1373 // Close the tab in this convoluted way, since there's a chance that the tab 1373 // Close the tab in this convoluted way, since there's a chance that the tab
1374 // is being dragged, or we're in some other nested event loop. This code 1374 // is being dragged, or we're in some other nested event loop. This code
1375 // path should ensure that the tab is safely closed under such 1375 // path should ensure that the tab is safely closed under such
1376 // circumstances, whereas |Browser::CloseTabContents()| does not. 1376 // circumstances, whereas |Browser::CloseTabContents()| does not.
1377 RenderViewHost* render_view_host = contents->render_view_host(); 1377 RenderViewHost* render_view_host =
1378 contents->tab_contents()->render_view_host();
1378 render_view_host->delegate()->Close(render_view_host); 1379 render_view_host->delegate()->Close(render_view_host);
1379 } 1380 }
1380 return true; 1381 return true;
1381 } 1382 }
1382 1383
1383 bool CaptureVisibleTabFunction::RunImpl() { 1384 bool CaptureVisibleTabFunction::RunImpl() {
1384 Browser* browser; 1385 Browser* browser;
1385 // windowId defaults to "current" window. 1386 // windowId defaults to "current" window.
1386 int window_id = -1; 1387 int window_id = -1;
1387 1388
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after
1565 return false; 1566 return false;
1566 } else { 1567 } else {
1567 browser = GetCurrentBrowser(); 1568 browser = GetCurrentBrowser();
1568 if (!browser) 1569 if (!browser)
1569 return false; 1570 return false;
1570 contents = browser->tabstrip_model()->GetActiveTabContents(); 1571 contents = browser->tabstrip_model()->GetActiveTabContents();
1571 if (!contents) 1572 if (!contents)
1572 return false; 1573 return false;
1573 } 1574 }
1574 1575
1575 if (contents->controller().needs_reload()) { 1576 if (contents->tab_contents()->controller().needs_reload()) {
1576 // If the tab hasn't been loaded, don't wait for the tab to load. 1577 // If the tab hasn't been loaded, don't wait for the tab to load.
1577 error_ = keys::kCannotDetermineLanguageOfUnloadedTab; 1578 error_ = keys::kCannotDetermineLanguageOfUnloadedTab;
1578 return false; 1579 return false;
1579 } 1580 }
1580 1581
1581 AddRef(); // Balanced in GotLanguage() 1582 AddRef(); // Balanced in GotLanguage()
1582 1583
1583 TranslateTabHelper* helper = contents->translate_tab_helper(); 1584 TranslateTabHelper* helper = contents->translate_tab_helper();
1584 if (!helper->language_state().original_language().empty()) { 1585 if (!helper->language_state().original_language().empty()) {
1585 // Delay the callback invocation until after the current JS call has 1586 // Delay the callback invocation until after the current JS call has
1586 // returned. 1587 // returned.
1587 MessageLoop::current()->PostTask(FROM_HERE, base::Bind( 1588 MessageLoop::current()->PostTask(FROM_HERE, base::Bind(
1588 &DetectTabLanguageFunction::GotLanguage, this, 1589 &DetectTabLanguageFunction::GotLanguage, this,
1589 helper->language_state().original_language())); 1590 helper->language_state().original_language()));
1590 return true; 1591 return true;
1591 } 1592 }
1592 // The tab contents does not know its language yet. Let's wait until it 1593 // The tab contents does not know its language yet. Let's wait until it
1593 // receives it, or until the tab is closed/navigates to some other page. 1594 // receives it, or until the tab is closed/navigates to some other page.
1594 registrar_.Add(this, chrome::NOTIFICATION_TAB_LANGUAGE_DETERMINED, 1595 registrar_.Add(this, chrome::NOTIFICATION_TAB_LANGUAGE_DETERMINED,
1595 content::Source<TabContents>(contents->tab_contents())); 1596 content::Source<TabContents>(contents->tab_contents()));
1596 registrar_.Add( 1597 registrar_.Add(
1597 this, content::NOTIFICATION_TAB_CLOSING, 1598 this, content::NOTIFICATION_TAB_CLOSING,
1598 content::Source<NavigationController>(&(contents->controller()))); 1599 content::Source<NavigationController>(
1600 &(contents->tab_contents()->controller())));
1599 registrar_.Add( 1601 registrar_.Add(
1600 this, content::NOTIFICATION_NAV_ENTRY_COMMITTED, 1602 this, content::NOTIFICATION_NAV_ENTRY_COMMITTED,
1601 content::Source<NavigationController>(&(contents->controller()))); 1603 content::Source<NavigationController>(
1604 &(contents->tab_contents()->controller())));
1602 return true; 1605 return true;
1603 } 1606 }
1604 1607
1605 void DetectTabLanguageFunction::Observe( 1608 void DetectTabLanguageFunction::Observe(
1606 int type, 1609 int type,
1607 const content::NotificationSource& source, 1610 const content::NotificationSource& source,
1608 const content::NotificationDetails& details) { 1611 const content::NotificationDetails& details) {
1609 std::string language; 1612 std::string language;
1610 if (type == chrome::NOTIFICATION_TAB_LANGUAGE_DETERMINED) 1613 if (type == chrome::NOTIFICATION_TAB_LANGUAGE_DETERMINED)
1611 language = *content::Details<std::string>(details).ptr(); 1614 language = *content::Details<std::string>(details).ptr();
1612 1615
1613 registrar_.RemoveAll(); 1616 registrar_.RemoveAll();
1614 1617
1615 // Call GotLanguage in all cases as we want to guarantee the callback is 1618 // Call GotLanguage in all cases as we want to guarantee the callback is
1616 // called for every API call the extension made. 1619 // called for every API call the extension made.
1617 GotLanguage(language); 1620 GotLanguage(language);
1618 } 1621 }
1619 1622
1620 void DetectTabLanguageFunction::GotLanguage(const std::string& language) { 1623 void DetectTabLanguageFunction::GotLanguage(const std::string& language) {
1621 result_.reset(Value::CreateStringValue(language.c_str())); 1624 result_.reset(Value::CreateStringValue(language.c_str()));
1622 SendResponse(true); 1625 SendResponse(true);
1623 1626
1624 Release(); // Balanced in Run() 1627 Release(); // Balanced in Run()
1625 } 1628 }
OLDNEW
« no previous file with comments | « chrome/browser/extensions/extension_tab_id_map.cc ('k') | chrome/browser/extensions/isolated_app_browsertest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698