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

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

Issue 10912156: Move SessionID, CaptureVisibleTabFunction to WebContents. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase atop the extension tab helper change Created 8 years, 3 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 1214 matching lines...) Expand 10 before | Expand all | Expand 10 after
1225 Browser* browser = GetCurrentBrowser(); 1225 Browser* browser = GetCurrentBrowser();
1226 if (!browser) { 1226 if (!browser) {
1227 error_ = keys::kNoCurrentWindowError; 1227 error_ = keys::kNoCurrentWindowError;
1228 return false; 1228 return false;
1229 } 1229 }
1230 contents = browser->tab_strip_model()->GetActiveTabContents(); 1230 contents = browser->tab_strip_model()->GetActiveTabContents();
1231 if (!contents) { 1231 if (!contents) {
1232 error_ = keys::kNoSelectedTabError; 1232 error_ = keys::kNoSelectedTabError;
1233 return false; 1233 return false;
1234 } 1234 }
1235 tab_id = SessionID::IdForTab(contents); 1235 tab_id = SessionID::IdForTab(contents->web_contents());
1236 } else { 1236 } else {
1237 EXTENSION_FUNCTION_VALIDATE(tab_value->GetAsInteger(&tab_id)); 1237 EXTENSION_FUNCTION_VALIDATE(tab_value->GetAsInteger(&tab_id));
1238 } 1238 }
1239 1239
1240 int tab_index = -1; 1240 int tab_index = -1;
1241 TabStripModel* tab_strip = NULL; 1241 TabStripModel* tab_strip = NULL;
1242 if (!GetTabById(tab_id, profile(), include_incognito(), 1242 if (!GetTabById(tab_id, profile(), include_incognito(),
1243 NULL, &tab_strip, &contents, &tab_index, &error_)) { 1243 NULL, &tab_strip, &contents, &tab_index, &error_)) {
1244 return false; 1244 return false;
1245 } 1245 }
(...skipping 348 matching lines...) Expand 10 before | Expand all | Expand 10 after
1594 } 1594 }
1595 1595
1596 // There's a chance that the tab is being dragged, or we're in some other 1596 // There's a chance that the tab is being dragged, or we're in some other
1597 // nested event loop. This code path ensures that the tab is safely closed 1597 // nested event loop. This code path ensures that the tab is safely closed
1598 // under such circumstances, whereas |chrome::CloseWebContents()| does not. 1598 // under such circumstances, whereas |chrome::CloseWebContents()| does not.
1599 contents->web_contents()->Close(); 1599 contents->web_contents()->Close();
1600 } 1600 }
1601 return true; 1601 return true;
1602 } 1602 }
1603 1603
1604 bool CaptureVisibleTabFunction::GetTabToCapture( 1604 bool CaptureVisibleTabFunction::GetTabToCapture(WebContents** web_contents) {
1605 WebContents** web_contents, TabContents** tab_contents) {
1606 Browser* browser = NULL; 1605 Browser* browser = NULL;
1607 // windowId defaults to "current" window. 1606 // windowId defaults to "current" window.
1608 int window_id = extension_misc::kCurrentWindowId; 1607 int window_id = extension_misc::kCurrentWindowId;
1609 1608
1610 if (HasOptionalArgument(0)) 1609 if (HasOptionalArgument(0))
1611 EXTENSION_FUNCTION_VALIDATE(args_->GetInteger(0, &window_id)); 1610 EXTENSION_FUNCTION_VALIDATE(args_->GetInteger(0, &window_id));
1612 1611
1613 if (!GetBrowserFromWindowID(this, window_id, &browser)) 1612 if (!GetBrowserFromWindowID(this, window_id, &browser))
1614 return false; 1613 return false;
1615 1614
1616 *web_contents = chrome::GetActiveWebContents(browser); 1615 *web_contents = chrome::GetActiveWebContents(browser);
1617 if (*web_contents == NULL) { 1616 if (*web_contents == NULL) {
1618 error_ = keys::kInternalVisibleTabCaptureError; 1617 error_ = keys::kInternalVisibleTabCaptureError;
1619 return false; 1618 return false;
1620 } 1619 }
1621 1620
1622 *tab_contents = chrome::GetActiveTabContents(browser);
1623
1624 return true; 1621 return true;
1625 }; 1622 };
1626 1623
1627 bool CaptureVisibleTabFunction::RunImpl() { 1624 bool CaptureVisibleTabFunction::RunImpl() {
1628 PrefService* service = profile()->GetPrefs(); 1625 PrefService* service = profile()->GetPrefs();
1629 if (service->GetBoolean(prefs::kDisableScreenshots)) { 1626 if (service->GetBoolean(prefs::kDisableScreenshots)) {
1630 error_ = keys::kScreenshotsDisabled; 1627 error_ = keys::kScreenshotsDisabled;
1631 return false; 1628 return false;
1632 } 1629 }
1633 1630
1634 WebContents* web_contents = NULL; 1631 WebContents* web_contents = NULL;
1635 TabContents* tab_contents = NULL; 1632 if (!GetTabToCapture(&web_contents))
1636 if (!GetTabToCapture(&web_contents, &tab_contents))
1637 return false; 1633 return false;
1638 1634
1639 image_format_ = FORMAT_JPEG; // Default format is JPEG. 1635 image_format_ = FORMAT_JPEG; // Default format is JPEG.
1640 image_quality_ = kDefaultQuality; // Default quality setting. 1636 image_quality_ = kDefaultQuality; // Default quality setting.
1641 1637
1642 if (HasOptionalArgument(1)) { 1638 if (HasOptionalArgument(1)) {
1643 DictionaryValue* options = NULL; 1639 DictionaryValue* options = NULL;
1644 EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(1, &options)); 1640 EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(1, &options));
1645 1641
1646 if (options->HasKey(keys::kFormatKey)) { 1642 if (options->HasKey(keys::kFormatKey)) {
(...skipping 15 matching lines...) Expand all
1662 EXTENSION_FUNCTION_VALIDATE( 1658 EXTENSION_FUNCTION_VALIDATE(
1663 options->GetInteger(keys::kQualityKey, &image_quality_)); 1659 options->GetInteger(keys::kQualityKey, &image_quality_));
1664 } 1660 }
1665 } 1661 }
1666 1662
1667 // captureVisibleTab() can return an image containing sensitive information 1663 // captureVisibleTab() can return an image containing sensitive information
1668 // that the browser would otherwise protect. Ensure the extension has 1664 // that the browser would otherwise protect. Ensure the extension has
1669 // permission to do this. 1665 // permission to do this.
1670 if (!GetExtension()->CanCaptureVisiblePage( 1666 if (!GetExtension()->CanCaptureVisiblePage(
1671 web_contents->GetURL(), 1667 web_contents->GetURL(),
1672 SessionID::IdForTab(tab_contents), 1668 SessionID::IdForTab(web_contents),
1673 &error_)) { 1669 &error_)) {
1674 return false; 1670 return false;
1675 } 1671 }
1676 1672
1677 RenderViewHost* render_view_host = web_contents->GetRenderViewHost(); 1673 RenderViewHost* render_view_host = web_contents->GetRenderViewHost();
1678 content::RenderWidgetHostView* view = render_view_host->GetView(); 1674 content::RenderWidgetHostView* view = render_view_host->GetView();
1679 if (!view) { 1675 if (!view) {
1680 error_ = keys::kInternalVisibleTabCaptureError; 1676 error_ = keys::kInternalVisibleTabCaptureError;
1681 return false; 1677 return false;
1682 } 1678 }
(...skipping 11 matching lines...) Expand all
1694 void CaptureVisibleTabFunction::CopyFromBackingStoreComplete( 1690 void CaptureVisibleTabFunction::CopyFromBackingStoreComplete(
1695 skia::PlatformCanvas* canvas, 1691 skia::PlatformCanvas* canvas,
1696 bool succeeded) { 1692 bool succeeded) {
1697 if (succeeded) { 1693 if (succeeded) {
1698 VLOG(1) << "captureVisibleTab() got image from backing store."; 1694 VLOG(1) << "captureVisibleTab() got image from backing store.";
1699 SendResultFromBitmap(skia::GetTopDevice(*canvas)->accessBitmap(false)); 1695 SendResultFromBitmap(skia::GetTopDevice(*canvas)->accessBitmap(false));
1700 return; 1696 return;
1701 } 1697 }
1702 1698
1703 WebContents* web_contents = NULL; 1699 WebContents* web_contents = NULL;
1704 TabContents* tab_contents = NULL; 1700 if (!GetTabToCapture(&web_contents)) {
1705 if (!GetTabToCapture(&web_contents, &tab_contents)) {
1706 error_ = keys::kInternalVisibleTabCaptureError; 1701 error_ = keys::kInternalVisibleTabCaptureError;
1707 SendResponse(false); 1702 SendResponse(false);
1708 return; 1703 return;
1709 } 1704 }
1710 1705
1711 // Ask the renderer for a snapshot of the tab. 1706 // Ask the renderer for a snapshot of the tab.
1712 registrar_.Add(this, 1707 registrar_.Add(this,
1713 chrome::NOTIFICATION_TAB_SNAPSHOT_TAKEN, 1708 chrome::NOTIFICATION_TAB_SNAPSHOT_TAKEN,
1714 content::Source<WebContents>(web_contents)); 1709 content::Source<WebContents>(web_contents));
1715 AddRef(); // Balanced in CaptureVisibleTabFunction::Observe(). 1710 AddRef(); // Balanced in CaptureVisibleTabFunction::Observe().
1716 tab_contents->snapshot_tab_helper()->CaptureSnapshot(); 1711 TabContents::FromWebContents(web_contents)->snapshot_tab_helper()->
1712 CaptureSnapshot();
1717 } 1713 }
1718 1714
1719 // If a backing store was not available in CaptureVisibleTabFunction::RunImpl, 1715 // If a backing store was not available in CaptureVisibleTabFunction::RunImpl,
1720 // than the renderer was asked for a snapshot. Listen for a notification 1716 // than the renderer was asked for a snapshot. Listen for a notification
1721 // that the snapshot is available. 1717 // that the snapshot is available.
1722 void CaptureVisibleTabFunction::Observe( 1718 void CaptureVisibleTabFunction::Observe(
1723 int type, 1719 int type,
1724 const content::NotificationSource& source, 1720 const content::NotificationSource& source,
1725 const content::NotificationDetails& details) { 1721 const content::NotificationDetails& details) {
1726 DCHECK(type == chrome::NOTIFICATION_TAB_SNAPSHOT_TAKEN); 1722 DCHECK(type == chrome::NOTIFICATION_TAB_SNAPSHOT_TAKEN);
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after
1863 // called for every API call the extension made. 1859 // called for every API call the extension made.
1864 GotLanguage(language); 1860 GotLanguage(language);
1865 } 1861 }
1866 1862
1867 void DetectTabLanguageFunction::GotLanguage(const std::string& language) { 1863 void DetectTabLanguageFunction::GotLanguage(const std::string& language) {
1868 SetResult(Value::CreateStringValue(language.c_str())); 1864 SetResult(Value::CreateStringValue(language.c_str()));
1869 SendResponse(true); 1865 SendResponse(true);
1870 1866
1871 Release(); // Balanced in Run() 1867 Release(); // Balanced in Run()
1872 } 1868 }
OLDNEW
« no previous file with comments | « chrome/browser/extensions/api/tabs/tabs.h ('k') | chrome/browser/extensions/extension_context_menu_model.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698