blob: fd98355851657bf564ff98c9af1309e4e6756e0d [file] [log] [blame]
[email protected]ea0f18b2009-07-27 22:16:111// Copyright (c) 2009 The Chromium Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
[email protected]811bfe372009-07-01 08:46:255#ifndef CHROME_BROWSER_EXTENSIONS_EXTENSION_DOM_UI_H_
6#define CHROME_BROWSER_EXTENSIONS_EXTENSION_DOM_UI_H_
7
[email protected]b27257562009-11-16 23:28:268#include <string>
9
[email protected]811bfe372009-07-01 08:46:2510#include "base/scoped_ptr.h"
11#include "chrome/browser/dom_ui/dom_ui.h"
[email protected]ced90ae12010-02-20 02:06:1612#include "chrome/browser/extensions/extension_bookmark_manager_api.h"
[email protected]811bfe372009-07-01 08:46:2513#include "chrome/browser/extensions/extension_function_dispatcher.h"
[email protected]b27257562009-11-16 23:28:2614#include "chrome/browser/extensions/extension_popup_host.h"
[email protected]d3cfa482009-10-17 13:54:5715#include "chrome/common/extensions/extension.h"
[email protected]811bfe372009-07-01 08:46:2516
[email protected]86c008e82009-08-28 20:26:0517class ListValue;
18class PrefService;
[email protected]591948962010-03-12 19:37:5219class Profile;
[email protected]6404197b2010-03-03 00:40:4020class RefCountedMemory;
[email protected]b27257562009-11-16 23:28:2621class RenderViewHost;
[email protected]86c008e82009-08-28 20:26:0522class TabContents;
23
[email protected]811bfe372009-07-01 08:46:2524// This class implements DOMUI for extensions and allows extensions to put UI in
25// the main tab contents area.
[email protected]d3cfa482009-10-17 13:54:5726class ExtensionDOMUI
[email protected]811bfe372009-07-01 08:46:2527 : public DOMUI,
[email protected]b27257562009-11-16 23:28:2628 public ExtensionPopupHost::PopupDelegate,
[email protected]811bfe372009-07-01 08:46:2529 public ExtensionFunctionDispatcher::Delegate {
30 public:
31 explicit ExtensionDOMUI(TabContents* tab_contents);
[email protected]86c008e82009-08-28 20:26:0532
[email protected]811bfe372009-07-01 08:46:2533 ExtensionFunctionDispatcher* extension_function_dispatcher() const {
34 return extension_function_dispatcher_.get();
35 }
36
37 // DOMUI
38 virtual void RenderViewCreated(RenderViewHost* render_view_host);
[email protected]cf430e22009-07-16 18:04:3639 virtual void RenderViewReused(RenderViewHost* render_view_host);
[email protected]811bfe372009-07-01 08:46:2540 virtual void ProcessDOMUIMessage(const std::string& message,
[email protected]e4dad9fb2009-10-06 18:15:5841 const Value* content,
[email protected]811bfe372009-07-01 08:46:2542 int request_id,
43 bool has_callback);
44
45 // ExtensionFunctionDispatcher::Delegate
[email protected]db7331a2010-02-25 22:10:5046 virtual Browser* GetBrowser(bool include_incognito) const;
[email protected]b27257562009-11-16 23:28:2647 virtual ExtensionDOMUI* GetExtensionDOMUI() { return this; }
[email protected]a95631cb2009-12-10 01:59:1148 virtual gfx::NativeWindow GetFrameNativeWindow();
[email protected]b27257562009-11-16 23:28:2649
50 // ExtensionPopupHost::Delegate
[email protected]db7331a2010-02-25 22:10:5051 virtual Browser* GetBrowser() const { return GetBrowser(true); }
[email protected]b27257562009-11-16 23:28:2652 virtual RenderViewHost* GetRenderViewHost();
[email protected]a95631cb2009-12-10 01:59:1153 virtual Profile* GetProfile();
[email protected]2db27be2010-02-10 22:46:4754 virtual gfx::NativeView GetNativeViewOfHost();
[email protected]811bfe372009-07-01 08:46:2555
[email protected]ced90ae12010-02-20 02:06:1656 virtual ExtensionBookmarkManagerEventRouter*
57 extension_bookmark_manager_event_router() {
58 return extension_bookmark_manager_event_router_.get();
59 }
60
[email protected]86c008e82009-08-28 20:26:0561 // BrowserURLHandler
62 static bool HandleChromeURLOverride(GURL* url, Profile* profile);
63
64 // Register and unregister a dictionary of one or more overrides.
65 // Page names are the keys, and chrome-extension: URLs are the values.
66 // (e.g. { "newtab": "chrome-extension://<id>/my_new_tab.html" }
67 static void RegisterChromeURLOverrides(Profile* profile,
[email protected]ced90ae12010-02-20 02:06:1668 const Extension::URLOverrideMap& overrides);
[email protected]86c008e82009-08-28 20:26:0569 static void UnregisterChromeURLOverrides(Profile* profile,
[email protected]ced90ae12010-02-20 02:06:1670 const Extension::URLOverrideMap& overrides);
[email protected]86c008e82009-08-28 20:26:0571 static void UnregisterChromeURLOverride(const std::string& page,
72 Profile* profile,
73 Value* override);
74
75 // Called from BrowserPrefs
76 static void RegisterUserPrefs(PrefService* prefs);
77
[email protected]591948962010-03-12 19:37:5278 static RefCountedMemory* GetFaviconResourceBytes(Profile* profile,
79 GURL page_url);
80
[email protected]811bfe372009-07-01 08:46:2581 private:
[email protected]86c008e82009-08-28 20:26:0582 // Unregister the specified override, and if it's the currently active one,
83 // ensure that something takes its place.
84 static void UnregisterAndReplaceOverride(const std::string& page,
85 Profile* profile,
86 ListValue* list,
87 Value* override);
88
89 // When the RenderViewHost changes (RenderViewCreated and RenderViewReused),
90 // we need to reset the ExtensionFunctionDispatcher so it's talking to the
91 // right one, as well as being linked to the correct URL.
92 void ResetExtensionFunctionDispatcher(RenderViewHost* render_view_host);
93
[email protected]ced90ae12010-02-20 02:06:1694 void ResetExtensionBookmarkManagerEventRouter();
95
[email protected]811bfe372009-07-01 08:46:2596 scoped_ptr<ExtensionFunctionDispatcher> extension_function_dispatcher_;
[email protected]ced90ae12010-02-20 02:06:1697
98 scoped_ptr<ExtensionBookmarkManagerEventRouter>
99 extension_bookmark_manager_event_router_;
[email protected]811bfe372009-07-01 08:46:25100};
101
102#endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_DOM_UI_H_