blob: e0698e74d5425ea899a7e492608813a060a04af2 [file] [log] [blame]
[email protected]c078968a2010-08-05 21:53:131// Copyright (c) 2010 The Chromium Authors. All rights reserved.
[email protected]ea0f18b2009-07-27 22:16:112// 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_
[email protected]32b76ef2010-07-26 23:08:247#pragma once
[email protected]811bfe372009-07-01 08:46:258
[email protected]b27257562009-11-16 23:28:269#include <string>
10
[email protected]811bfe372009-07-01 08:46:2511#include "base/scoped_ptr.h"
12#include "chrome/browser/dom_ui/dom_ui.h"
[email protected]ced90ae12010-02-20 02:06:1613#include "chrome/browser/extensions/extension_bookmark_manager_api.h"
[email protected]811bfe372009-07-01 08:46:2514#include "chrome/browser/extensions/extension_function_dispatcher.h"
[email protected]4b91f1f2010-07-14 20:01:0415#include "chrome/browser/favicon_service.h"
[email protected]d3cfa482009-10-17 13:54:5716#include "chrome/common/extensions/extension.h"
[email protected]811bfe372009-07-01 08:46:2517
[email protected]86c008e82009-08-28 20:26:0518class ListValue;
19class PrefService;
[email protected]591948962010-03-12 19:37:5220class Profile;
[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,
28 public ExtensionFunctionDispatcher::Delegate {
29 public:
[email protected]e2194742010-08-12 05:54:3430 static const char kExtensionURLOverrides[];
[email protected]c5b8ab42010-04-14 22:06:5031
[email protected]811bfe372009-07-01 08:46:2532 explicit ExtensionDOMUI(TabContents* tab_contents);
[email protected]86c008e82009-08-28 20:26:0533
[email protected]811bfe372009-07-01 08:46:2534 ExtensionFunctionDispatcher* extension_function_dispatcher() const {
35 return extension_function_dispatcher_.get();
36 }
37
38 // DOMUI
39 virtual void RenderViewCreated(RenderViewHost* render_view_host);
[email protected]cf430e22009-07-16 18:04:3640 virtual void RenderViewReused(RenderViewHost* render_view_host);
[email protected]811bfe372009-07-01 08:46:2541 virtual void ProcessDOMUIMessage(const std::string& message,
[email protected]438c97d2010-05-21 23:30:1542 const ListValue* content,
[email protected]bb64b512010-04-02 21:01:3943 const GURL& source_url,
[email protected]811bfe372009-07-01 08:46:2544 int request_id,
45 bool has_callback);
46
47 // ExtensionFunctionDispatcher::Delegate
[email protected]0ec92032010-03-24 19:59:4148 virtual Browser* GetBrowser() const;
[email protected]2db27be2010-02-10 22:46:4749 virtual gfx::NativeView GetNativeViewOfHost();
[email protected]0ec92032010-03-24 19:59:4150 virtual gfx::NativeWindow GetCustomFrameNativeWindow();
[email protected]9aa2eaa2010-04-15 19:05:0751 virtual TabContents* associated_tab_contents() { return tab_contents(); }
[email protected]0ec92032010-03-24 19:59:4152 virtual Profile* GetProfile();
[email protected]811bfe372009-07-01 08:46:2553
[email protected]ced90ae12010-02-20 02:06:1654 virtual ExtensionBookmarkManagerEventRouter*
55 extension_bookmark_manager_event_router() {
56 return extension_bookmark_manager_event_router_.get();
57 }
58
[email protected]86c008e82009-08-28 20:26:0559 // BrowserURLHandler
60 static bool HandleChromeURLOverride(GURL* url, Profile* profile);
61
62 // Register and unregister a dictionary of one or more overrides.
63 // Page names are the keys, and chrome-extension: URLs are the values.
64 // (e.g. { "newtab": "chrome-extension://<id>/my_new_tab.html" }
65 static void RegisterChromeURLOverrides(Profile* profile,
[email protected]ced90ae12010-02-20 02:06:1666 const Extension::URLOverrideMap& overrides);
[email protected]86c008e82009-08-28 20:26:0567 static void UnregisterChromeURLOverrides(Profile* profile,
[email protected]ced90ae12010-02-20 02:06:1668 const Extension::URLOverrideMap& overrides);
[email protected]86c008e82009-08-28 20:26:0569 static void UnregisterChromeURLOverride(const std::string& page,
70 Profile* profile,
71 Value* override);
72
73 // Called from BrowserPrefs
74 static void RegisterUserPrefs(PrefService* prefs);
75
[email protected]4b91f1f2010-07-14 20:01:0476 // Get the favicon for the extension by getting an icon from the manifest.
77 static void GetFaviconForURL(Profile* profile,
78 FaviconService::GetFaviconRequest* request,
79 const GURL& page_url);
[email protected]591948962010-03-12 19:37:5280
[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_