tabs_api.h revision 1e9bf3e0803691d0a228da41fc608347b6db4340
12a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// Copyright (c) 2012 The Chromium Authors. All rights reserved. 22a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be 32a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// found in the LICENSE file. 42a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 52a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#ifndef CHROME_BROWSER_EXTENSIONS_API_TABS_TABS_API_H_ 62a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#define CHROME_BROWSER_EXTENSIONS_API_TABS_TABS_API_H_ 72a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 82a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include <string> 92a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include <vector> 102a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 112a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "base/compiler_specific.h" 12a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)#include "chrome/browser/extensions/api/execute_code_function.h" 131e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)#include "chrome/browser/extensions/chrome_extension_function.h" 14b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)#include "chrome/common/extensions/api/tabs.h" 152a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "content/public/browser/notification_observer.h" 162a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "content/public/browser/notification_registrar.h" 172a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "extensions/common/extension_resource.h" 18ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch#include "extensions/common/user_script.h" 197dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch#include "url/gurl.h" 202a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 212a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)class BackingStore; 222a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)class GURL; 232a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)class SkBitmap; 24b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)class TabStripModel; 252a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 262a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)namespace base { 272a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)class DictionaryValue; 282a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} 292a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 302a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)namespace content { 312a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)class WebContents; 322a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} 332a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 34b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)namespace ui { 35b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)class ListSelectionModel; 36b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)} 372a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 38c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)namespace user_prefs { 39c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)class PrefRegistrySyncable; 40c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)} 41c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 42b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)namespace extensions { 43b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles) 442a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// Windows 451e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)class WindowsGetFunction : public ChromeSyncExtensionFunction { 462a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) virtual ~WindowsGetFunction() {} 472a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) virtual bool RunImpl() OVERRIDE; 482a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) DECLARE_EXTENSION_FUNCTION("windows.get", WINDOWS_GET) 492a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)}; 501e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)class WindowsGetCurrentFunction : public ChromeSyncExtensionFunction { 512a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) virtual ~WindowsGetCurrentFunction() {} 522a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) virtual bool RunImpl() OVERRIDE; 532a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) DECLARE_EXTENSION_FUNCTION("windows.getCurrent", WINDOWS_GETCURRENT) 542a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)}; 551e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)class WindowsGetLastFocusedFunction : public ChromeSyncExtensionFunction { 562a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) virtual ~WindowsGetLastFocusedFunction() {} 572a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) virtual bool RunImpl() OVERRIDE; 582a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) DECLARE_EXTENSION_FUNCTION("windows.getLastFocused", WINDOWS_GETLASTFOCUSED) 592a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)}; 601e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)class WindowsGetAllFunction : public ChromeSyncExtensionFunction { 612a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) virtual ~WindowsGetAllFunction() {} 622a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) virtual bool RunImpl() OVERRIDE; 632a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) DECLARE_EXTENSION_FUNCTION("windows.getAll", WINDOWS_GETALL) 642a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)}; 651e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)class WindowsCreateFunction : public ChromeSyncExtensionFunction { 662a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) virtual ~WindowsCreateFunction() {} 672a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) virtual bool RunImpl() OVERRIDE; 682a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // Returns whether the window should be created in incognito mode. 69424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) // |create_data| are the options passed by the extension. It may be NULL. 702a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // |urls| is the list of urls to open. If we are creating an incognito window, 712a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // the function will remove these urls which may not be opened in incognito 722a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // mode. If window creation leads the browser into an erroneous state, 732a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // |is_error| is set to true (also, error_ member variable is assigned 742a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // the proper error message). 75424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) bool ShouldOpenIncognitoWindow( 76424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) const api::windows::Create::Params::CreateData* create_data, 77424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) std::vector<GURL>* urls, 78424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) bool* is_error); 792a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) DECLARE_EXTENSION_FUNCTION("windows.create", WINDOWS_CREATE) 802a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)}; 811e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)class WindowsUpdateFunction : public ChromeSyncExtensionFunction { 822a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) virtual ~WindowsUpdateFunction() {} 832a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) virtual bool RunImpl() OVERRIDE; 842a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) DECLARE_EXTENSION_FUNCTION("windows.update", WINDOWS_UPDATE) 852a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)}; 861e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)class WindowsRemoveFunction : public ChromeSyncExtensionFunction { 872a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) virtual ~WindowsRemoveFunction() {} 882a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) virtual bool RunImpl() OVERRIDE; 892a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) DECLARE_EXTENSION_FUNCTION("windows.remove", WINDOWS_REMOVE) 902a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)}; 912a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 922a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// Tabs 931e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)class TabsGetFunction : public ChromeSyncExtensionFunction { 942a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) virtual ~TabsGetFunction() {} 952a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) virtual bool RunImpl() OVERRIDE; 962a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) DECLARE_EXTENSION_FUNCTION("tabs.get", TABS_GET) 972a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)}; 981e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)class TabsGetCurrentFunction : public ChromeSyncExtensionFunction { 992a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) virtual ~TabsGetCurrentFunction() {} 1002a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) virtual bool RunImpl() OVERRIDE; 1012a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) DECLARE_EXTENSION_FUNCTION("tabs.getCurrent", TABS_GETCURRENT) 1022a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)}; 1031e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)class TabsGetSelectedFunction : public ChromeSyncExtensionFunction { 1042a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) virtual ~TabsGetSelectedFunction() {} 1052a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) virtual bool RunImpl() OVERRIDE; 1062a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) DECLARE_EXTENSION_FUNCTION("tabs.getSelected", TABS_GETSELECTED) 1072a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)}; 1081e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)class TabsGetAllInWindowFunction : public ChromeSyncExtensionFunction { 1092a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) virtual ~TabsGetAllInWindowFunction() {} 1102a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) virtual bool RunImpl() OVERRIDE; 1112a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) DECLARE_EXTENSION_FUNCTION("tabs.getAllInWindow", TABS_GETALLINWINDOW) 1122a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)}; 1131e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)class TabsQueryFunction : public ChromeSyncExtensionFunction { 1142a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) virtual ~TabsQueryFunction() {} 1152a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) virtual bool RunImpl() OVERRIDE; 1162a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) DECLARE_EXTENSION_FUNCTION("tabs.query", TABS_QUERY) 1172a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)}; 1181e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)class TabsCreateFunction : public ChromeSyncExtensionFunction { 1192a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) virtual ~TabsCreateFunction() {} 1202a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) virtual bool RunImpl() OVERRIDE; 1212a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) DECLARE_EXTENSION_FUNCTION("tabs.create", TABS_CREATE) 1222a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)}; 1231e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)class TabsDuplicateFunction : public ChromeSyncExtensionFunction { 1242a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) virtual ~TabsDuplicateFunction() {} 1252a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) virtual bool RunImpl() OVERRIDE; 1262a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) DECLARE_EXTENSION_FUNCTION("tabs.duplicate", TABS_DUPLICATE) 1272a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)}; 1281e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)class TabsHighlightFunction : public ChromeSyncExtensionFunction { 1292a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) virtual ~TabsHighlightFunction() {} 1302a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) virtual bool RunImpl() OVERRIDE; 131b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles) bool HighlightTab(TabStripModel* tabstrip, 132b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles) ui::ListSelectionModel* selection, 133b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles) int *active_index, 134b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles) int index); 1352a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) DECLARE_EXTENSION_FUNCTION("tabs.highlight", TABS_HIGHLIGHT) 1362a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)}; 1371e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)class TabsUpdateFunction : public ChromeAsyncExtensionFunction { 1382a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) public: 1392a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) TabsUpdateFunction(); 1402a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 1412a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) protected: 1422a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) virtual ~TabsUpdateFunction() {} 143b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles) virtual bool UpdateURL(const std::string& url, 144b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles) int tab_id, 145b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles) bool* is_async); 1462a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) virtual void PopulateResult(); 1472a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 1482a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) content::WebContents* web_contents_; 1492a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 1502a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) private: 1512a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) virtual bool RunImpl() OVERRIDE; 1522a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) void OnExecuteCodeFinished(const std::string& error, 1532a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) int32 on_page_id, 1542a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) const GURL& on_url, 155eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch const base::ListValue& script_result); 1562a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 1572a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) DECLARE_EXTENSION_FUNCTION("tabs.update", TABS_UPDATE) 1582a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)}; 1591e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)class TabsMoveFunction : public ChromeSyncExtensionFunction { 1602a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) virtual ~TabsMoveFunction() {} 1612a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) virtual bool RunImpl() OVERRIDE; 162b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles) bool MoveTab(int tab_id, 163b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles) int* new_index, 164b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles) int iteration, 165eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch base::ListValue* tab_values, 166b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles) int* window_id); 1672a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) DECLARE_EXTENSION_FUNCTION("tabs.move", TABS_MOVE) 1682a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)}; 1691e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)class TabsReloadFunction : public ChromeSyncExtensionFunction { 1702a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) virtual ~TabsReloadFunction() {} 1712a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) virtual bool RunImpl() OVERRIDE; 1722a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) DECLARE_EXTENSION_FUNCTION("tabs.reload", TABS_RELOAD) 1732a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)}; 1741e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)class TabsRemoveFunction : public ChromeSyncExtensionFunction { 1752a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) virtual ~TabsRemoveFunction() {} 1762a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) virtual bool RunImpl() OVERRIDE; 177b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles) bool RemoveTab(int tab_id); 1782a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) DECLARE_EXTENSION_FUNCTION("tabs.remove", TABS_REMOVE) 1792a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)}; 1801e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)class TabsDetectLanguageFunction : public ChromeAsyncExtensionFunction, 1811e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) public content::NotificationObserver { 1822a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) private: 1832a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) virtual ~TabsDetectLanguageFunction() {} 1842a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) virtual bool RunImpl() OVERRIDE; 1852a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 1862a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) virtual void Observe(int type, 1872a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) const content::NotificationSource& source, 1882a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) const content::NotificationDetails& details) OVERRIDE; 1892a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) void GotLanguage(const std::string& language); 1902a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) content::NotificationRegistrar registrar_; 1912a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) DECLARE_EXTENSION_FUNCTION("tabs.detectLanguage", TABS_DETECTLANGUAGE) 1922a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)}; 1931e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)class TabsCaptureVisibleTabFunction : public ChromeAsyncExtensionFunction { 1942a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) public: 1957dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch static void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry); 1962a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 1972a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) protected: 198b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles) typedef api::tabs::CaptureVisibleTab::Params::Options::Format ImageFormat; 1992a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 2002a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // The default quality setting used when encoding jpegs. 2012a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) static const int kDefaultQuality; 2022a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 2032a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) virtual ~TabsCaptureVisibleTabFunction() {} 2042a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) virtual bool RunImpl() OVERRIDE; 2052a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) virtual bool GetTabToCapture(content::WebContents** web_contents); 2062a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) void SendResultFromBitmap(const SkBitmap& screen_capture); 2072a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 2082a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) private: 2092a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // Callback for the RWH::CopyFromBackingStore call. 2102a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) void CopyFromBackingStoreComplete(bool succeeded, 2112a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) const SkBitmap& bitmap); 2122a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 2132a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // Callback for the RWH::GetSnapshotFromRenderer call. This path is used if 2142a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // CopyFromBackingStore fails for some reason. 2152a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) void GetSnapshotFromRendererComplete(bool succeeded, 2162a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) const SkBitmap& bitmap); 2172a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) void SendInternalError(); 2182a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 2192a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // The format (JPEG vs PNG) of the resulting image. Set in RunImpl(). 2202a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) ImageFormat image_format_; 2212a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 2222a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // Quality setting to use when encoding jpegs. Set in RunImpl(). 2232a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) int image_quality_; 2242a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 2252a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) DECLARE_EXTENSION_FUNCTION("tabs.captureVisibleTab", TABS_CAPTUREVISIBLETAB) 2262a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)}; 2272a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 2282a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// Implement API call tabs.executeScript and tabs.insertCSS. 229a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)class ExecuteCodeInTabFunction : public ExecuteCodeFunction { 2302a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) public: 2312a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) ExecuteCodeInTabFunction(); 2322a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 2332a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) protected: 2342a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) virtual ~ExecuteCodeInTabFunction(); 2352a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 2362a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // ExtensionFunction: 2372a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) virtual bool HasPermission() OVERRIDE; 2382a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 2392a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // Initialize the |execute_tab_id_| and |details_| if they haven't already 2402a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // been. Returns whether initialization was successful. 241a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles) virtual bool Init() OVERRIDE; 242a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles) virtual bool CanExecuteScriptOnPage() OVERRIDE; 243a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles) virtual ScriptExecutor* GetScriptExecutor() OVERRIDE; 244a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles) virtual bool IsWebView() const OVERRIDE; 2452a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 246a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles) private: 2472a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // Id of tab which executes code. 2482a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) int execute_tab_id_; 2492a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)}; 2502a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 2512a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)class TabsExecuteScriptFunction : public ExecuteCodeInTabFunction { 252a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles) protected: 253a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles) virtual bool ShouldInsertCSS() const OVERRIDE; 254a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles) 2552a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) private: 2562a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) virtual ~TabsExecuteScriptFunction() {} 2572a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 258eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch virtual void OnExecuteCodeFinished( 259eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch const std::string& error, 260eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch int32 on_page_id, 261eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch const GURL& on_url, 262eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch const base::ListValue& script_result) OVERRIDE; 2632a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 2642a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) DECLARE_EXTENSION_FUNCTION("tabs.executeScript", TABS_EXECUTESCRIPT) 2652a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)}; 2662a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 2672a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)class TabsInsertCSSFunction : public ExecuteCodeInTabFunction { 2682a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) private: 2692a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) virtual ~TabsInsertCSSFunction() {} 2702a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 271a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles) virtual bool ShouldInsertCSS() const OVERRIDE; 272a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles) 2732a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) DECLARE_EXTENSION_FUNCTION("tabs.insertCSS", TABS_INSERTCSS) 2742a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)}; 2752a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 276b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)} // namespace extensions 277b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles) 2782a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#endif // CHROME_BROWSER_EXTENSIONS_API_TABS_TABS_API_H_ 279