tabs_api.h revision a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7
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"
12a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)#include "chrome/browser/extensions/api/capture_web_contents_function.h"
13a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)#include "chrome/browser/extensions/api/execute_code_function.h"
141e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)#include "chrome/browser/extensions/chrome_extension_function.h"
15b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)#include "chrome/common/extensions/api/tabs.h"
162a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "content/public/browser/notification_observer.h"
172a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "content/public/browser/notification_registrar.h"
182a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "extensions/common/extension_resource.h"
19ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch#include "extensions/common/user_script.h"
207dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch#include "url/gurl.h"
212a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
222a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)class BackingStore;
232a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)class GURL;
242a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)class SkBitmap;
25b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)class TabStripModel;
262a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
272a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)namespace base {
282a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)class DictionaryValue;
292a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)}
302a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
312a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)namespace content {
322a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)class WebContents;
332a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)}
342a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
35b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)namespace ui {
36b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)class ListSelectionModel;
37b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)}
382a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
39c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)namespace user_prefs {
40c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)class PrefRegistrySyncable;
41c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)}
42c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
43b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)namespace extensions {
44b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)
452a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// Windows
461e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)class WindowsGetFunction : public ChromeSyncExtensionFunction {
472a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  virtual ~WindowsGetFunction() {}
482a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  virtual bool RunImpl() OVERRIDE;
492a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  DECLARE_EXTENSION_FUNCTION("windows.get", WINDOWS_GET)
502a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)};
511e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)class WindowsGetCurrentFunction : public ChromeSyncExtensionFunction {
522a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  virtual ~WindowsGetCurrentFunction() {}
532a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  virtual bool RunImpl() OVERRIDE;
542a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  DECLARE_EXTENSION_FUNCTION("windows.getCurrent", WINDOWS_GETCURRENT)
552a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)};
561e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)class WindowsGetLastFocusedFunction : public ChromeSyncExtensionFunction {
572a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  virtual ~WindowsGetLastFocusedFunction() {}
582a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  virtual bool RunImpl() OVERRIDE;
592a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  DECLARE_EXTENSION_FUNCTION("windows.getLastFocused", WINDOWS_GETLASTFOCUSED)
602a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)};
611e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)class WindowsGetAllFunction : public ChromeSyncExtensionFunction {
622a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  virtual ~WindowsGetAllFunction() {}
632a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  virtual bool RunImpl() OVERRIDE;
642a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  DECLARE_EXTENSION_FUNCTION("windows.getAll", WINDOWS_GETALL)
652a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)};
661e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)class WindowsCreateFunction : public ChromeSyncExtensionFunction {
672a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  virtual ~WindowsCreateFunction() {}
682a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  virtual bool RunImpl() OVERRIDE;
692a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // Returns whether the window should be created in incognito mode.
70424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)  // |create_data| are the options passed by the extension. It may be NULL.
712a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // |urls| is the list of urls to open. If we are creating an incognito window,
722a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // the function will remove these urls which may not be opened in incognito
732a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // mode.  If window creation leads the browser into an erroneous state,
742a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // |is_error| is set to true (also, error_ member variable is assigned
752a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // the proper error message).
76424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)  bool ShouldOpenIncognitoWindow(
77424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)      const api::windows::Create::Params::CreateData* create_data,
78424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)      std::vector<GURL>* urls,
79424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)      bool* is_error);
802a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  DECLARE_EXTENSION_FUNCTION("windows.create", WINDOWS_CREATE)
812a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)};
821e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)class WindowsUpdateFunction : public ChromeSyncExtensionFunction {
832a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  virtual ~WindowsUpdateFunction() {}
842a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  virtual bool RunImpl() OVERRIDE;
852a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  DECLARE_EXTENSION_FUNCTION("windows.update", WINDOWS_UPDATE)
862a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)};
871e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)class WindowsRemoveFunction : public ChromeSyncExtensionFunction {
882a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  virtual ~WindowsRemoveFunction() {}
892a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  virtual bool RunImpl() OVERRIDE;
902a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  DECLARE_EXTENSION_FUNCTION("windows.remove", WINDOWS_REMOVE)
912a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)};
922a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
932a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// Tabs
941e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)class TabsGetFunction : public ChromeSyncExtensionFunction {
952a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  virtual ~TabsGetFunction() {}
962a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  virtual bool RunImpl() OVERRIDE;
972a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  DECLARE_EXTENSION_FUNCTION("tabs.get", TABS_GET)
982a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)};
991e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)class TabsGetCurrentFunction : public ChromeSyncExtensionFunction {
1002a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  virtual ~TabsGetCurrentFunction() {}
1012a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  virtual bool RunImpl() OVERRIDE;
1022a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  DECLARE_EXTENSION_FUNCTION("tabs.getCurrent", TABS_GETCURRENT)
1032a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)};
1041e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)class TabsGetSelectedFunction : public ChromeSyncExtensionFunction {
1052a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  virtual ~TabsGetSelectedFunction() {}
1062a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  virtual bool RunImpl() OVERRIDE;
1072a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  DECLARE_EXTENSION_FUNCTION("tabs.getSelected", TABS_GETSELECTED)
1082a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)};
1091e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)class TabsGetAllInWindowFunction : public ChromeSyncExtensionFunction {
1102a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  virtual ~TabsGetAllInWindowFunction() {}
1112a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  virtual bool RunImpl() OVERRIDE;
1122a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  DECLARE_EXTENSION_FUNCTION("tabs.getAllInWindow", TABS_GETALLINWINDOW)
1132a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)};
1141e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)class TabsQueryFunction : public ChromeSyncExtensionFunction {
1152a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  virtual ~TabsQueryFunction() {}
1162a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  virtual bool RunImpl() OVERRIDE;
1172a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  DECLARE_EXTENSION_FUNCTION("tabs.query", TABS_QUERY)
1182a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)};
1191e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)class TabsCreateFunction : public ChromeSyncExtensionFunction {
1202a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  virtual ~TabsCreateFunction() {}
1212a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  virtual bool RunImpl() OVERRIDE;
1222a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  DECLARE_EXTENSION_FUNCTION("tabs.create", TABS_CREATE)
1232a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)};
1241e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)class TabsDuplicateFunction : public ChromeSyncExtensionFunction {
1252a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  virtual ~TabsDuplicateFunction() {}
1262a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  virtual bool RunImpl() OVERRIDE;
1272a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  DECLARE_EXTENSION_FUNCTION("tabs.duplicate", TABS_DUPLICATE)
1282a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)};
1291e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)class TabsHighlightFunction : public ChromeSyncExtensionFunction {
1302a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  virtual ~TabsHighlightFunction() {}
1312a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  virtual bool RunImpl() OVERRIDE;
132b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)  bool HighlightTab(TabStripModel* tabstrip,
133b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)                    ui::ListSelectionModel* selection,
134b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)                    int *active_index,
135b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)                    int index);
1362a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  DECLARE_EXTENSION_FUNCTION("tabs.highlight", TABS_HIGHLIGHT)
1372a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)};
1381e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)class TabsUpdateFunction : public ChromeAsyncExtensionFunction {
1392a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) public:
1402a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  TabsUpdateFunction();
1412a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
1422a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) protected:
1432a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  virtual ~TabsUpdateFunction() {}
144b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)  virtual bool UpdateURL(const std::string& url,
145b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)                         int tab_id,
146b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)                         bool* is_async);
1472a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  virtual void PopulateResult();
1482a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
1492a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  content::WebContents* web_contents_;
1502a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
1512a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) private:
1522a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  virtual bool RunImpl() OVERRIDE;
1532a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  void OnExecuteCodeFinished(const std::string& error,
1542a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)                             int32 on_page_id,
1552a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)                             const GURL& on_url,
156eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch                             const base::ListValue& script_result);
1572a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
1582a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  DECLARE_EXTENSION_FUNCTION("tabs.update", TABS_UPDATE)
1592a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)};
1601e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)class TabsMoveFunction : public ChromeSyncExtensionFunction {
1612a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  virtual ~TabsMoveFunction() {}
1622a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  virtual bool RunImpl() OVERRIDE;
163b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)  bool MoveTab(int tab_id,
164b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)               int* new_index,
165b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)               int iteration,
166eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch               base::ListValue* tab_values,
167b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)               int* window_id);
1682a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  DECLARE_EXTENSION_FUNCTION("tabs.move", TABS_MOVE)
1692a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)};
1701e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)class TabsReloadFunction : public ChromeSyncExtensionFunction {
1712a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  virtual ~TabsReloadFunction() {}
1722a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  virtual bool RunImpl() OVERRIDE;
1732a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  DECLARE_EXTENSION_FUNCTION("tabs.reload", TABS_RELOAD)
1742a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)};
1751e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)class TabsRemoveFunction : public ChromeSyncExtensionFunction {
1762a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  virtual ~TabsRemoveFunction() {}
1772a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  virtual bool RunImpl() OVERRIDE;
178b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)  bool RemoveTab(int tab_id);
1792a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  DECLARE_EXTENSION_FUNCTION("tabs.remove", TABS_REMOVE)
1802a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)};
1811e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)class TabsDetectLanguageFunction : public ChromeAsyncExtensionFunction,
1821e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)                                   public content::NotificationObserver {
1832a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) private:
1842a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  virtual ~TabsDetectLanguageFunction() {}
1852a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  virtual bool RunImpl() OVERRIDE;
1862a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
1872a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  virtual void Observe(int type,
1882a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)                       const content::NotificationSource& source,
1892a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)                       const content::NotificationDetails& details) OVERRIDE;
1902a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  void GotLanguage(const std::string& language);
1912a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  content::NotificationRegistrar registrar_;
1922a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  DECLARE_EXTENSION_FUNCTION("tabs.detectLanguage", TABS_DETECTLANGUAGE)
1932a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)};
194a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)class TabsCaptureVisibleTabFunction
195a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)    : public extensions::CaptureWebContentsFunction {
1962a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) public:
1977dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch  static void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry);
1982a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
1992a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) protected:
2002a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  virtual ~TabsCaptureVisibleTabFunction() {}
2012a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
2022a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) private:
203a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  // extensions::CaptureWebContentsFunction:
204a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  virtual bool IsScreenshotEnabled() OVERRIDE;
205a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  virtual content::WebContents* GetWebContentsForID(int id) OVERRIDE;
206a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  virtual void OnCaptureFailure(FailureReason reason) OVERRIDE;
2072a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
2082a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  DECLARE_EXTENSION_FUNCTION("tabs.captureVisibleTab", TABS_CAPTUREVISIBLETAB)
2092a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)};
2102a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
2112a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// Implement API call tabs.executeScript and tabs.insertCSS.
212a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)class ExecuteCodeInTabFunction : public ExecuteCodeFunction {
2132a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) public:
2142a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  ExecuteCodeInTabFunction();
2152a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
2162a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) protected:
2172a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  virtual ~ExecuteCodeInTabFunction();
2182a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
2192a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // ExtensionFunction:
2202a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  virtual bool HasPermission() OVERRIDE;
2212a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
2222a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // Initialize the |execute_tab_id_| and |details_| if they haven't already
2232a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // been. Returns whether initialization was successful.
224a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  virtual bool Init() OVERRIDE;
225a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  virtual bool CanExecuteScriptOnPage() OVERRIDE;
226a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  virtual ScriptExecutor* GetScriptExecutor() OVERRIDE;
227a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  virtual bool IsWebView() const OVERRIDE;
2282a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
229a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles) private:
2302a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // Id of tab which executes code.
2312a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  int execute_tab_id_;
2322a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)};
2332a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
2342a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)class TabsExecuteScriptFunction : public ExecuteCodeInTabFunction {
235a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles) protected:
236a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  virtual bool ShouldInsertCSS() const OVERRIDE;
237a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)
2382a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) private:
2392a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  virtual ~TabsExecuteScriptFunction() {}
2402a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
241eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  virtual void OnExecuteCodeFinished(
242eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch      const std::string& error,
243eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch      int32 on_page_id,
244eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch      const GURL& on_url,
245eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch      const base::ListValue& script_result) OVERRIDE;
2462a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
2472a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  DECLARE_EXTENSION_FUNCTION("tabs.executeScript", TABS_EXECUTESCRIPT)
2482a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)};
2492a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
2502a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)class TabsInsertCSSFunction : public ExecuteCodeInTabFunction {
2512a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) private:
2522a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  virtual ~TabsInsertCSSFunction() {}
2532a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
254a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  virtual bool ShouldInsertCSS() const OVERRIDE;
255a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)
2562a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  DECLARE_EXTENSION_FUNCTION("tabs.insertCSS", TABS_INSERTCSS)
2572a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)};
2582a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
259b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)}  // namespace extensions
260b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)
2612a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#endif  // CHROME_BROWSER_EXTENSIONS_API_TABS_TABS_API_H_
262